floooh / sokol

minimal cross-platform standalone C headers
https://floooh.github.io/sokol-html5
zlib License
7.12k stars 501 forks source link

sokol_nuklear.h: enable setting mouse cursor #1150

Closed zeozeozeo closed 2 weeks ago

zeozeozeo commented 2 weeks ago

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 commented 2 weeks ago

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 commented 2 weeks ago

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:

https://github.com/floooh/sokol/blob/7e50f80495dbe7f38cb66e033eb02b463970cf21/util/sokol_imgui.h#L3007

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

floooh commented 2 weeks ago

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: https://github.com/floooh/sokol/pull/1138)

zeozeozeo commented 2 weeks ago

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 commented 2 weeks ago

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 commented 2 weeks ago

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

floooh commented 2 weeks ago

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

floooh commented 2 weeks ago

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 commented 2 weeks ago

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

floooh commented 2 weeks ago

Ok, all green now. Thanks for the PR!

floooh commented 2 weeks ago

Ok, the two nuklear sokol-samples now use your code:

zeozeozeo commented 2 weeks ago

nice :shipit: