Skip to content

Commit fcd64f8

Browse files
authored
Add nk_input_is_mouse_moved() (#632)
* Add nk_input_is_mouse_moved() * Move the nk_input_is_mouse_moved() declaration
1 parent 86178a8 commit fcd64f8

File tree

5 files changed

+18
-4
lines changed

5 files changed

+18
-4
lines changed

nuklear.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4933,6 +4933,7 @@ NK_API nk_bool nk_input_is_mouse_click_down_in_rect(const struct nk_input *i, en
49334933
NK_API nk_bool nk_input_any_mouse_click_in_rect(const struct nk_input*, struct nk_rect);
49344934
NK_API nk_bool nk_input_is_mouse_prev_hovering_rect(const struct nk_input*, struct nk_rect);
49354935
NK_API nk_bool nk_input_is_mouse_hovering_rect(const struct nk_input*, struct nk_rect);
4936+
NK_API nk_bool nk_input_is_mouse_moved(const struct nk_input*);
49364937
NK_API nk_bool nk_input_mouse_clicked(const struct nk_input*, enum nk_buttons, struct nk_rect);
49374938
NK_API nk_bool nk_input_is_mouse_down(const struct nk_input*, enum nk_buttons);
49384939
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)
1843418435
return (!i->mouse.buttons[id].down && i->mouse.buttons[id].clicked);
1843518436
}
1843618437
NK_API nk_bool
18438+
nk_input_is_mouse_moved(const struct nk_input *i)
18439+
{
18440+
if (!i) return nk_false;
18441+
return i->mouse.delta.x != 0 || i->mouse.delta.y != 0;
18442+
}
18443+
NK_API nk_bool
1843718444
nk_input_is_key_pressed(const struct nk_input *i, enum nk_keys key)
1843818445
{
1843918446
const struct nk_key *k;
@@ -20381,7 +20388,7 @@ nk_panel_end(struct nk_context *ctx)
2038120388

2038220389
/* hide scroll if no user input */
2038320390
if (window->flags & NK_WINDOW_SCROLL_AUTO_HIDE) {
20384-
int has_input = ctx->input.mouse.delta.x != 0 || ctx->input.mouse.delta.y != 0 || ctx->input.mouse.scroll_delta.y != 0;
20391+
int has_input = nk_input_is_mouse_moved(&ctx->input) || ctx->input.mouse.scroll_delta.y != 0;
2038520392
int is_window_hovered = nk_window_is_hovered(ctx);
2038620393
int any_item_active = (ctx->last_widget_state & NK_WIDGET_STATE_MODIFIED);
2038720394
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,
2805628063
in->mouse.buttons[NK_BUTTON_LEFT].clicked) {
2805728064
nk_textedit_click(edit, mouse_x, mouse_y, font, row_height);
2805828065
} else if (is_hovered && in->mouse.buttons[NK_BUTTON_LEFT].down &&
28059-
(in->mouse.delta.x != 0.0f || in->mouse.delta.y != 0.0f)) {
28066+
nk_input_is_mouse_moved(in)) {
2806028067
nk_textedit_drag(edit, mouse_x, mouse_y, font, row_height);
2806128068
cursor_follow = nk_true;
2806228069
} else if (is_hovered && in->mouse.buttons[NK_BUTTON_RIGHT].clicked &&

src/nuklear.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4710,6 +4710,7 @@ NK_API nk_bool nk_input_is_mouse_click_down_in_rect(const struct nk_input *i, en
47104710
NK_API nk_bool nk_input_any_mouse_click_in_rect(const struct nk_input*, struct nk_rect);
47114711
NK_API nk_bool nk_input_is_mouse_prev_hovering_rect(const struct nk_input*, struct nk_rect);
47124712
NK_API nk_bool nk_input_is_mouse_hovering_rect(const struct nk_input*, struct nk_rect);
4713+
NK_API nk_bool nk_input_is_mouse_moved(const struct nk_input*);
47134714
NK_API nk_bool nk_input_mouse_clicked(const struct nk_input*, enum nk_buttons, struct nk_rect);
47144715
NK_API nk_bool nk_input_is_mouse_down(const struct nk_input*, enum nk_buttons);
47154716
NK_API nk_bool nk_input_is_mouse_pressed(const struct nk_input*, enum nk_buttons);

src/nuklear_edit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ nk_do_edit(nk_flags *state, struct nk_command_buffer *out,
232232
in->mouse.buttons[NK_BUTTON_LEFT].clicked) {
233233
nk_textedit_click(edit, mouse_x, mouse_y, font, row_height);
234234
} else if (is_hovered && in->mouse.buttons[NK_BUTTON_LEFT].down &&
235-
(in->mouse.delta.x != 0.0f || in->mouse.delta.y != 0.0f)) {
235+
nk_input_is_mouse_moved(in)) {
236236
nk_textedit_drag(edit, mouse_x, mouse_y, font, row_height);
237237
cursor_follow = nk_true;
238238
} else if (is_hovered && in->mouse.buttons[NK_BUTTON_RIGHT].clicked &&

src/nuklear_input.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,12 @@ nk_input_is_mouse_released(const struct nk_input *i, enum nk_buttons id)
253253
return (!i->mouse.buttons[id].down && i->mouse.buttons[id].clicked);
254254
}
255255
NK_API nk_bool
256+
nk_input_is_mouse_moved(const struct nk_input *i)
257+
{
258+
if (!i) return nk_false;
259+
return i->mouse.delta.x != 0 || i->mouse.delta.y != 0;
260+
}
261+
NK_API nk_bool
256262
nk_input_is_key_pressed(const struct nk_input *i, enum nk_keys key)
257263
{
258264
const struct nk_key *k;

src/nuklear_panel.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ nk_panel_end(struct nk_context *ctx)
486486

487487
/* hide scroll if no user input */
488488
if (window->flags & NK_WINDOW_SCROLL_AUTO_HIDE) {
489-
int has_input = ctx->input.mouse.delta.x != 0 || ctx->input.mouse.delta.y != 0 || ctx->input.mouse.scroll_delta.y != 0;
489+
int has_input = nk_input_is_mouse_moved(&ctx->input) || ctx->input.mouse.scroll_delta.y != 0;
490490
int is_window_hovered = nk_window_is_hovered(ctx);
491491
int any_item_active = (ctx->last_widget_state & NK_WIDGET_STATE_MODIFIED);
492492
if ((!has_input && is_window_hovered) || (!is_window_hovered && !any_item_active))

0 commit comments

Comments
 (0)