Add nk_input_is_mouse_moved() (#632)

* Add nk_input_is_mouse_moved()

* Move the nk_input_is_mouse_moved() declaration
This commit is contained in:
Rob Loach
2025-10-25 10:03:01 -04:00
committed by GitHub
parent 86178a8aa4
commit fcd64f85e5
5 changed files with 18 additions and 4 deletions
+9 -2
View File
@@ -4933,6 +4933,7 @@ NK_API nk_bool nk_input_is_mouse_click_down_in_rect(const struct nk_input *i, en
NK_API nk_bool nk_input_any_mouse_click_in_rect(const struct nk_input*, struct nk_rect);
NK_API nk_bool nk_input_is_mouse_prev_hovering_rect(const struct nk_input*, struct nk_rect);
NK_API nk_bool nk_input_is_mouse_hovering_rect(const struct nk_input*, struct nk_rect);
NK_API nk_bool nk_input_is_mouse_moved(const struct nk_input*);
NK_API nk_bool nk_input_mouse_clicked(const struct nk_input*, enum nk_buttons, struct nk_rect);
NK_API nk_bool nk_input_is_mouse_down(const struct nk_input*, enum nk_buttons);
NK_API nk_bool nk_input_is_mouse_pressed(const struct nk_input*, enum nk_buttons);
@@ -18434,6 +18435,12 @@ nk_input_is_mouse_released(const struct nk_input *i, enum nk_buttons id)
return (!i->mouse.buttons[id].down && i->mouse.buttons[id].clicked);
}
NK_API nk_bool
nk_input_is_mouse_moved(const struct nk_input *i)
{
if (!i) return nk_false;
return i->mouse.delta.x != 0 || i->mouse.delta.y != 0;
}
NK_API nk_bool
nk_input_is_key_pressed(const struct nk_input *i, enum nk_keys key)
{
const struct nk_key *k;
@@ -20381,7 +20388,7 @@ nk_panel_end(struct nk_context *ctx)
/* hide scroll if no user input */
if (window->flags & NK_WINDOW_SCROLL_AUTO_HIDE) {
int has_input = ctx->input.mouse.delta.x != 0 || ctx->input.mouse.delta.y != 0 || ctx->input.mouse.scroll_delta.y != 0;
int has_input = nk_input_is_mouse_moved(&ctx->input) || ctx->input.mouse.scroll_delta.y != 0;
int is_window_hovered = nk_window_is_hovered(ctx);
int any_item_active = (ctx->last_widget_state & NK_WIDGET_STATE_MODIFIED);
if ((!has_input && is_window_hovered) || (!is_window_hovered && !any_item_active))
@@ -28056,7 +28063,7 @@ nk_do_edit(nk_flags *state, struct nk_command_buffer *out,
in->mouse.buttons[NK_BUTTON_LEFT].clicked) {
nk_textedit_click(edit, mouse_x, mouse_y, font, row_height);
} else if (is_hovered && in->mouse.buttons[NK_BUTTON_LEFT].down &&
(in->mouse.delta.x != 0.0f || in->mouse.delta.y != 0.0f)) {
nk_input_is_mouse_moved(in)) {
nk_textedit_drag(edit, mouse_x, mouse_y, font, row_height);
cursor_follow = nk_true;
} else if (is_hovered && in->mouse.buttons[NK_BUTTON_RIGHT].clicked &&
+1
View File
@@ -4710,6 +4710,7 @@ NK_API nk_bool nk_input_is_mouse_click_down_in_rect(const struct nk_input *i, en
NK_API nk_bool nk_input_any_mouse_click_in_rect(const struct nk_input*, struct nk_rect);
NK_API nk_bool nk_input_is_mouse_prev_hovering_rect(const struct nk_input*, struct nk_rect);
NK_API nk_bool nk_input_is_mouse_hovering_rect(const struct nk_input*, struct nk_rect);
NK_API nk_bool nk_input_is_mouse_moved(const struct nk_input*);
NK_API nk_bool nk_input_mouse_clicked(const struct nk_input*, enum nk_buttons, struct nk_rect);
NK_API nk_bool nk_input_is_mouse_down(const struct nk_input*, enum nk_buttons);
NK_API nk_bool nk_input_is_mouse_pressed(const struct nk_input*, enum nk_buttons);
+1 -1
View File
@@ -232,7 +232,7 @@ nk_do_edit(nk_flags *state, struct nk_command_buffer *out,
in->mouse.buttons[NK_BUTTON_LEFT].clicked) {
nk_textedit_click(edit, mouse_x, mouse_y, font, row_height);
} else if (is_hovered && in->mouse.buttons[NK_BUTTON_LEFT].down &&
(in->mouse.delta.x != 0.0f || in->mouse.delta.y != 0.0f)) {
nk_input_is_mouse_moved(in)) {
nk_textedit_drag(edit, mouse_x, mouse_y, font, row_height);
cursor_follow = nk_true;
} else if (is_hovered && in->mouse.buttons[NK_BUTTON_RIGHT].clicked &&
+6
View File
@@ -253,6 +253,12 @@ nk_input_is_mouse_released(const struct nk_input *i, enum nk_buttons id)
return (!i->mouse.buttons[id].down && i->mouse.buttons[id].clicked);
}
NK_API nk_bool
nk_input_is_mouse_moved(const struct nk_input *i)
{
if (!i) return nk_false;
return i->mouse.delta.x != 0 || i->mouse.delta.y != 0;
}
NK_API nk_bool
nk_input_is_key_pressed(const struct nk_input *i, enum nk_keys key)
{
const struct nk_key *k;
+1 -1
View File
@@ -486,7 +486,7 @@ nk_panel_end(struct nk_context *ctx)
/* hide scroll if no user input */
if (window->flags & NK_WINDOW_SCROLL_AUTO_HIDE) {
int has_input = ctx->input.mouse.delta.x != 0 || ctx->input.mouse.delta.y != 0 || ctx->input.mouse.scroll_delta.y != 0;
int has_input = nk_input_is_mouse_moved(&ctx->input) || ctx->input.mouse.scroll_delta.y != 0;
int is_window_hovered = nk_window_is_hovered(ctx);
int any_item_active = (ctx->last_widget_state & NK_WIDGET_STATE_MODIFIED);
if ((!has_input && is_window_hovered) || (!is_window_hovered && !any_item_active))