Skip to content

mouse: Add the Back/Forward Mouse Buttons#906

Open
RobLoach wants to merge 16 commits intoImmediate-Mode-UI:masterfrom
RobLoach:mouse-buttons
Open

mouse: Add the Back/Forward Mouse Buttons#906
RobLoach wants to merge 16 commits intoImmediate-Mode-UI:masterfrom
RobLoach:mouse-buttons

Conversation

@RobLoach
Copy link
Contributor

@RobLoach RobLoach commented Mar 6, 2026

Found I wanted to allow use of the back/forward 4/5 butons on the mouse.

@RobLoach RobLoach changed the title input: Add Back/Foreward Mouse buttons mouse: Add the Back/Foreward Mouse Buttons Mar 6, 2026
@sleeptightAnsiC
Copy link
Contributor

sleeptightAnsiC commented Mar 6, 2026

What these will be used for? Asking out of curiosity.

You may want to add an example usage somewhere to demo/common/overview.c, just to have some place to test these. You could also add one for NK_BUTTON_MIDDLE and NK_BUTTON_DOUBLE in order to address #848 at the same time. I could quickly write this and send you a diff, if you're interested.

EDIT: Also, how about other backends? Pretty sure most of them support mouse 4/5

@RobLoach
Copy link
Contributor Author

RobLoach commented Mar 6, 2026

Mostly for nuklear_console to allow going back in the menu. Do have to figure out a history in it though. https://github.com/RobLoach/nuklear_console/

@rswinkle
Copy link
Contributor

rswinkle commented Mar 8, 2026

This looks good. I just tested a couple backends but it seems fine. Interesting X1 is the back button and X2 is the forward button (both in physical positioning and what they trigger). I wonder how they decided that. Maybe just that back is the more common action, and on mine a least it's the larger button.

src/nuklear.h Outdated
Comment on lines +603 to +604
NK_BUTTON_X1,
NK_BUTTON_X2,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RobLoach maybe this should be reverted back to:

NK_BUTTON_BACK
NK_BUTTON_FORWARD

I feel like X1/X2 is a bit too ambiguous for a name.
Most people understand what Left/Right/Middle/Double click means and does,
but mouse4/5/X1/X2 doesn't really suggest how this could be used by the library.

Copy link
Contributor Author

@RobLoach RobLoach Mar 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I switched to it X1 and X2 because back/forewards that may not be their intended function. None of the renderers also refer to them as Back/Forwards. Majority call it X1/X2, which is likely safer to use.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In review, only raylib refers to them as Back/Forwards

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because back/forewards that may not be their intended function

What was your use case in nuklear_console?

It feels odd that core library would ever use these for something else than navigation. Many desktop applications reuse those buttons for going back and forward (aka reverse-back) to some spots in the UI. In web browser it causes the tab to go back/forward in the page history.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In games, I use it for the Melee button, and Specials... In nuklear_console, I'll be using it for...

  1. Navigation within the UI
  2. Allowing the user to use it as an input button:
Screenshot from 2026-03-08 20-21-16

Copy link
Contributor

@sleeptightAnsiC sleeptightAnsiC Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll be using it for... 1. Navigation within the UI

Not sure if I understand right. This will be a different kind of navigation to what most apps do? genuinely asking what's the plan here

I found those keys quite strange. It's hard to mentally imagine which one exactly is it based on raw 4/5/X1/X2. The buttons appear on actual physical mice as closer to you (Back/X2) and further from you (Forward/X1) so I thought the previous naming makes some sense.

I'm just afraid we won't understand what's going on when seeing something like mouse.buttons[NK_BUTTON_X2].down in the code. The backend library (like SDL/GLFW) doesn't care about actual name, it only serves the input and expects the app/user to treat it in any possible way, but Nuklear associates "common sense behavior" with each key/button

@rswinkle Any thoughts? You mentioned in #906 (comment) that X1/X2 are "reversed" to what you initially expected. [EDIT: or at least this was my impression when I read your comment.] Would BUTTON_BACK/FORWARD (or any other naming really) make a difference?

I don't want to pressure on changing anything. Just want to ensure the decision about those names is fully aware.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm using SDL3 as a modal for all of them here...

  • SDL_BUTTON_X1: NK_BUTTON_X1
  • SDL_BUTTON_X2: NK_BUTTON_X2

The button that hits the same button as SDL3's X1 is hitting the same NK_BUTTON_X1 across all other renderers I've tested.

Copy link
Contributor

@sleeptightAnsiC sleeptightAnsiC Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright. We've talked about it, and figured out this will be resolved with doc comment: 929db27 / https://discord.com/channels/922234432071548968/934963188011773952/1480391263613223043

@RobLoach Feel free to resolve this thread, unless you wish to wait for rswinkle's opinion

RobLoach and others added 2 commits March 8, 2026 20:01
Co-authored-by: sleeptightAnsiC <91839286+sleeptightAnsiC@users.noreply.github.com>
Co-authored-by: sleeptightAnsiC <91839286+sleeptightAnsiC@users.noreply.github.com>
@RobLoach RobLoach changed the title mouse: Add the Back/Foreward Mouse Buttons mouse: Add the Back/Forward Mouse Buttons Mar 9, 2026
Comment on lines +1373 to +1380
if (nk_input_is_mouse_pressed(in, i))
nk_label(ctx, "Pressed", NK_TEXT_LEFT);
else if (nk_input_is_mouse_down(in, i))
nk_label(ctx, "Down", NK_TEXT_LEFT);
else if (nk_input_is_mouse_released(in, i))
nk_label(ctx, "Released", NK_TEXT_LEFT);
else
nk_label(ctx, "Up", NK_TEXT_LEFT);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of how Nuklear serves those events, it's almost impossible to see Pressed/Released appearing. I even had hard time to capture recording of this (because my display is 75Hz) and I haven't seen it ever appearing in some demos (not sure if that was a bug in specific demo or not)

Any ideas on improving this? My first one was to split Down/Up and Pressed/Released events into two columns, but I don't think this would help much anyway.

This can be fixed as follow up PR but maybe you see any quick solution now?

Copy link
Contributor Author

@RobLoach RobLoach Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's true. Pressed is only displayed for 1 frame. Same with Released. Unsure of a good way to ensure that's clear without some timers and gross code. Maybe a follow up.

Copy link
Contributor

@sleeptightAnsiC sleeptightAnsiC Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably just split it and then make the text slowly fade away. This file already uses delta time in few places, but yea, it might become ugly.

I'll enter a task for it, right after this PR gets merged.

Copy link
Contributor

@sleeptightAnsiC sleeptightAnsiC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RobLoach
Alright, everything that was possible to test, was tested.
I would suggest to wait a day or two, and then merge.
A lot of changes happened today, maybe we missed something in a rush.

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 this pull request may close these issues.

3 participants