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

sokol_nuklear.h: enable setting mouse cursor #1150

Merged
merged 1 commit into from
Nov 13, 2024

Conversation

zeozeozeo
Copy link
Contributor

@zeozeozeo zeozeozeo commented Nov 13, 2024

Add an option enable_set_mouse_cursor to enable setting OS mouse cursors with sapp_set_mouse_cursor. By default Nuklear draws its' own custom cursor.

It is the opposite of disable_set_mouse_cursor in sokol_imgui.h, to not break existing apps.

Currently this option doesn't actually disable loading the custom cursor icons, and still requires you to call nk_style_hide_cursor() to hide Nuklear's cursor.

@floooh
Copy link
Owner

floooh commented Nov 13, 2024

Interesting, I never saw for (enum ... :)

I'll let the CI complete and if everything is green I'll merge the PR (and will probably also update one of the sokol-samples to enable mouse cursors).

@floooh
Copy link
Owner

floooh commented Nov 13, 2024

Btw, I seem to remember that there was a specific reason that I'm initializing the mouse cursor before the switch with the currently active mouse cursor instead of SAPP_MOUSECURSOR_ARROW, I just don't remember what that specific situation was:

sapp_mouse_cursor cursor = sapp_get_mouse_cursor();

(if your code somehow triggers that problem then we can still fix it in a separate PR I guess)

@floooh
Copy link
Owner

floooh commented Nov 13, 2024

Hmm, somehow I hadn't noticed that the Nuklear software mouse cursor is now always active... that definitely wasn't intended... (meaning that the Nuklear mouse cursor is always active since this PR was merged: #1138)

@zeozeozeo
Copy link
Contributor Author

Hmm, somehow I hadn't noticed that the Nuklear software mouse cursor is now always active... that definitely wasn't intended...

Yeah, apparently nk_style_load_all_cursors() will always enable the software cursor. Maybe this option should be changed to disable_set_mouse_cursor, and disable loading cursors when it is not enabled?

@floooh
Copy link
Owner

floooh commented Nov 13, 2024

I think I will just modify your code to work the same as sokol_imgui.h: rename the flag to disable... and by default use the sokol_app.h mouse cursor functions, and otherwise use the Nuklear builtin mouse cursors.

PS: I will add two flags: disable_set_mouse_cursor (which works the same as sokol_imgui.h) and enable_software_mouse_cursor (which loads the software mouse cursor images).

@floooh
Copy link
Owner

floooh commented Nov 13, 2024

Hmm ok, not so simple, looks like calling nk_style_load_all_cursors() is what activates the cursor handling in the first place.

@floooh
Copy link
Owner

floooh commented Nov 13, 2024

...I think I'll go with your original code :)

@floooh
Copy link
Owner

floooh commented Nov 13, 2024

Ok, one change I'll do after playing around with it: I'll move the code from the event handler to the start of the snk_render() function. Otherwise the mouse pointer gets stuck at the end of an operation until it is moved again.

floooh added a commit that referenced this pull request Nov 13, 2024
@floooh floooh merged commit 8276829 into floooh:master Nov 13, 2024
32 checks passed
@floooh
Copy link
Owner

floooh commented Nov 13, 2024

Ooof I broke it :D (forgot about the SOKOL_NUKLEAR_NO_SOKOL_APP define, will fix that on main)

@floooh
Copy link
Owner

floooh commented Nov 13, 2024

Ok, all green now. Thanks for the PR!

@floooh
Copy link
Owner

floooh commented Nov 13, 2024

@zeozeozeo
Copy link
Contributor Author

nice :shipit:

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.

2 participants