Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Core] Add right click support #302

Open
caleb-snow-cbm opened this issue Mar 4, 2025 · 1 comment · May be fixed by #303
Open

[Core] Add right click support #302

caleb-snow-cbm opened this issue Mar 4, 2025 · 1 comment · May be fixed by #303

Comments

@caleb-snow-cbm
Copy link

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.

@caleb-snow-cbm caleb-snow-cbm linked a pull request Mar 4, 2025 that will close this issue
@acrilique
Copy link

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 */ }
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants