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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions util/sokol_nuklear.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@
Set this to true if you don't want to use Nuklear's default
font. In this case you need to initialize the font
yourself after snk_setup() is called.

bool enable_set_mouse_cursor
If true, sokol_nuklear.h will control the mouse cursor type
by calling sapp_set_mouse_cursor(). If using this, you should
probably also call nk_style_hide_cursor() to hide Nuklear's
custom cursor.

--- At the start of a frame, call:

Expand Down Expand Up @@ -427,6 +433,7 @@ typedef struct snk_desc_t {
int sample_count;
float dpi_scale;
bool no_default_font;
bool enable_set_mouse_cursor;
snk_allocator_t allocator; // optional memory allocation overrides (default: malloc/free)
snk_logger_t logger; // optional log function override
} snk_desc_t;
Expand Down Expand Up @@ -3121,6 +3128,24 @@ SOKOL_API_IMPL bool snk_handle_event(const sapp_event* ev) {
default:
break;
}
if (_snuklear.desc.enable_set_mouse_cursor) {
for (enum nk_style_cursor c = 0; c < NK_CURSOR_COUNT; ++c) {
if (_snuklear.ctx.style.cursor_active == _snuklear.ctx.style.cursors[c]) {
sapp_mouse_cursor sapp_cur = SAPP_MOUSECURSOR_ARROW;
switch (c) {
case NK_CURSOR_TEXT: sapp_cur = SAPP_MOUSECURSOR_IBEAM; break;
case NK_CURSOR_MOVE: sapp_cur = SAPP_MOUSECURSOR_RESIZE_ALL; break;
case NK_CURSOR_RESIZE_VERTICAL: sapp_cur = SAPP_MOUSECURSOR_RESIZE_NS; break;
case NK_CURSOR_RESIZE_HORIZONTAL: sapp_cur = SAPP_MOUSECURSOR_RESIZE_EW; break;
case NK_CURSOR_RESIZE_TOP_LEFT_DOWN_RIGHT: sapp_cur = SAPP_MOUSECURSOR_RESIZE_NESW; break;
case NK_CURSOR_RESIZE_TOP_RIGHT_DOWN_LEFT: sapp_cur = SAPP_MOUSECURSOR_RESIZE_NWSE; break;
default: break;
}
sapp_set_mouse_cursor(sapp_cur);
break;
}
}
}
return nk_item_is_any_active(&_snuklear.ctx);
}

Expand Down