clay
clay copied to clipboard
[Core] Add right click support
It would be helpful to capture right clicks (and possibly more mouse buttons) in the same way as left.
I assume it was a design decision to have omitted this ability, but I thought I would raise the issue just in case it wasn't.
This can be done in user code, my assumption is also that the library does not probably want to handle this stuff. I suspect you should be using a property of the event that sets the pointer state in order to check what button causes it. This could be different depending on the library that you're using for rendering. For instance with clay+SDL3:
SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event)
{
SDL_AppResult ret_val = SDL_APP_CONTINUE;
switch (event->type) {
case SDL_EVENT_MOUSE_BUTTON_DOWN:
Clay_SetPointerState((Clay_Vector2) { event->button.x, event->button.y },
event->button.button == SDL_BUTTON_LEFT);
if (event->button.button == SDL_BUTTON_RIGHT) {
app_state->context_menu.x = event->button.x;
app_state->context_menu.y = event->button.y;
app_state->context_menu.visible = true;
} else app_state->context_menu.visible = false;
break;
};
return ret_val;
}
// Then use that to show something in SDL_AppIterate:
Clay_BeginLayout();
CLAY({
.id = CLAY_ID("MainContainer")
}) {
// Context menu
if (app_state->context_menu.visible) {
CLAY({
.id = CLAY_ID("ContextMenu"),
.floating = {
.attachTo = CLAY_ATTACH_TO_PARENT,
.attachPoints = {
.parent = CLAY_ATTACH_POINT_LEFT_TOP
},
},
}) { /* Contents of the menu here */ }
}