Button behavior `NK_BUTTON_TRIGGER_ON_RELEASE`
This modifies the trigger behavior of buttons to only activate when the mouse was also over the same button on the mouse button down event. Side note: I also modified my version of Nuklear I use to apply the same logic for hover, because I use Nuklear for touch input devices where traditional hover behavior tends to be misleading. I left this out for now because I can imagine that this could be seen as wrong/faulty behavior by some.
This commit is contained in:
parent
e5c44b7182
commit
068ae5fc33
17
nuklear.h
17
nuklear.h
|
@ -4654,6 +4654,9 @@ struct nk_mouse_button {
|
||||||
struct nk_mouse {
|
struct nk_mouse {
|
||||||
struct nk_mouse_button buttons[NK_BUTTON_MAX];
|
struct nk_mouse_button buttons[NK_BUTTON_MAX];
|
||||||
struct nk_vec2 pos;
|
struct nk_vec2 pos;
|
||||||
|
#ifdef NK_BUTTON_TRIGGER_ON_RELEASE
|
||||||
|
struct nk_vec2 down_pos;
|
||||||
|
#endif
|
||||||
struct nk_vec2 prev;
|
struct nk_vec2 prev;
|
||||||
struct nk_vec2 delta;
|
struct nk_vec2 delta;
|
||||||
struct nk_vec2 scroll_delta;
|
struct nk_vec2 scroll_delta;
|
||||||
|
@ -17881,6 +17884,13 @@ nk_input_button(struct nk_context *ctx, enum nk_buttons id, int x, int y, nk_boo
|
||||||
btn->clicked_pos.y = (float)y;
|
btn->clicked_pos.y = (float)y;
|
||||||
btn->down = down;
|
btn->down = down;
|
||||||
btn->clicked++;
|
btn->clicked++;
|
||||||
|
#ifdef NK_BUTTON_TRIGGER_ON_RELEASE
|
||||||
|
if (down == 1 && id == NK_BUTTON_LEFT)
|
||||||
|
{
|
||||||
|
in->mouse.down_pos.x = btn->clicked_pos.x;
|
||||||
|
in->mouse.down_pos.y = btn->clicked_pos.y;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
NK_API void
|
NK_API void
|
||||||
nk_input_scroll(struct nk_context *ctx, struct nk_vec2 val)
|
nk_input_scroll(struct nk_context *ctx, struct nk_vec2 val)
|
||||||
|
@ -17941,7 +17951,12 @@ nk_input_has_mouse_click_in_rect(const struct nk_input *i, enum nk_buttons id,
|
||||||
const struct nk_mouse_button *btn;
|
const struct nk_mouse_button *btn;
|
||||||
if (!i) return nk_false;
|
if (!i) return nk_false;
|
||||||
btn = &i->mouse.buttons[id];
|
btn = &i->mouse.buttons[id];
|
||||||
|
#ifdef NK_BUTTON_TRIGGER_ON_RELEASE
|
||||||
|
if (!NK_INBOX(btn->clicked_pos.x,btn->clicked_pos.y,b.x,b.y,b.w,b.h)
|
||||||
|
|| !NK_INBOX(i->mouse.down_pos.x,i->mouse.down_pos.y,b.x,b.y,b.w,b.h))
|
||||||
|
#else
|
||||||
if (!NK_INBOX(btn->clicked_pos.x,btn->clicked_pos.y,b.x,b.y,b.w,b.h))
|
if (!NK_INBOX(btn->clicked_pos.x,btn->clicked_pos.y,b.x,b.y,b.w,b.h))
|
||||||
|
#endif
|
||||||
return nk_false;
|
return nk_false;
|
||||||
return nk_true;
|
return nk_true;
|
||||||
}
|
}
|
||||||
|
@ -29629,6 +29644,8 @@ nk_tooltipfv(struct nk_context *ctx, const char *fmt, va_list args)
|
||||||
/// - [y]: Minor version with non-breaking API and library changes
|
/// - [y]: Minor version with non-breaking API and library changes
|
||||||
/// - [z]: Patch version with no direct changes to the API
|
/// - [z]: Patch version with no direct changes to the API
|
||||||
///
|
///
|
||||||
|
/// - 2022/04/18 (4.9.7) - Change button behavior when NK_BUTTON_TRIGGER_ON_RELEASE is defined to
|
||||||
|
/// only trigger when the mouse position was inside the same button on down
|
||||||
/// - 2022/02/03 (4.9.6) - Allow overriding the NK_INV_SQRT function, similar to NK_SIN and NK_COS
|
/// - 2022/02/03 (4.9.6) - Allow overriding the NK_INV_SQRT function, similar to NK_SIN and NK_COS
|
||||||
/// - 2021/12/22 (4.9.5) - Revert layout bounds not accounting for padding due to regressions
|
/// - 2021/12/22 (4.9.5) - Revert layout bounds not accounting for padding due to regressions
|
||||||
/// - 2021/12/22 (4.9.4) - Fix checking hovering when window is minimized
|
/// - 2021/12/22 (4.9.4) - Fix checking hovering when window is minimized
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
/// - [y]: Minor version with non-breaking API and library changes
|
/// - [y]: Minor version with non-breaking API and library changes
|
||||||
/// - [z]: Patch version with no direct changes to the API
|
/// - [z]: Patch version with no direct changes to the API
|
||||||
///
|
///
|
||||||
|
/// - 2022/04/18 (4.9.7) - Change button behavior when NK_BUTTON_TRIGGER_ON_RELEASE is defined to
|
||||||
|
/// only trigger when the mouse position was inside the same button on down
|
||||||
/// - 2022/02/03 (4.9.6) - Allow overriding the NK_INV_SQRT function, similar to NK_SIN and NK_COS
|
/// - 2022/02/03 (4.9.6) - Allow overriding the NK_INV_SQRT function, similar to NK_SIN and NK_COS
|
||||||
/// - 2021/12/22 (4.9.5) - Revert layout bounds not accounting for padding due to regressions
|
/// - 2021/12/22 (4.9.5) - Revert layout bounds not accounting for padding due to regressions
|
||||||
/// - 2021/12/22 (4.9.4) - Fix checking hovering when window is minimized
|
/// - 2021/12/22 (4.9.4) - Fix checking hovering when window is minimized
|
||||||
|
|
|
@ -4433,6 +4433,9 @@ struct nk_mouse_button {
|
||||||
struct nk_mouse {
|
struct nk_mouse {
|
||||||
struct nk_mouse_button buttons[NK_BUTTON_MAX];
|
struct nk_mouse_button buttons[NK_BUTTON_MAX];
|
||||||
struct nk_vec2 pos;
|
struct nk_vec2 pos;
|
||||||
|
#ifdef NK_BUTTON_TRIGGER_ON_RELEASE
|
||||||
|
struct nk_vec2 down_pos;
|
||||||
|
#endif
|
||||||
struct nk_vec2 prev;
|
struct nk_vec2 prev;
|
||||||
struct nk_vec2 delta;
|
struct nk_vec2 delta;
|
||||||
struct nk_vec2 scroll_delta;
|
struct nk_vec2 scroll_delta;
|
||||||
|
|
|
@ -83,6 +83,13 @@ nk_input_button(struct nk_context *ctx, enum nk_buttons id, int x, int y, nk_boo
|
||||||
btn->clicked_pos.y = (float)y;
|
btn->clicked_pos.y = (float)y;
|
||||||
btn->down = down;
|
btn->down = down;
|
||||||
btn->clicked++;
|
btn->clicked++;
|
||||||
|
#ifdef NK_BUTTON_TRIGGER_ON_RELEASE
|
||||||
|
if (down == 1 && id == NK_BUTTON_LEFT)
|
||||||
|
{
|
||||||
|
in->mouse.down_pos.x = btn->clicked_pos.x;
|
||||||
|
in->mouse.down_pos.y = btn->clicked_pos.y;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
NK_API void
|
NK_API void
|
||||||
nk_input_scroll(struct nk_context *ctx, struct nk_vec2 val)
|
nk_input_scroll(struct nk_context *ctx, struct nk_vec2 val)
|
||||||
|
@ -143,7 +150,12 @@ nk_input_has_mouse_click_in_rect(const struct nk_input *i, enum nk_buttons id,
|
||||||
const struct nk_mouse_button *btn;
|
const struct nk_mouse_button *btn;
|
||||||
if (!i) return nk_false;
|
if (!i) return nk_false;
|
||||||
btn = &i->mouse.buttons[id];
|
btn = &i->mouse.buttons[id];
|
||||||
|
#ifdef NK_BUTTON_TRIGGER_ON_RELEASE
|
||||||
|
if (!NK_INBOX(btn->clicked_pos.x,btn->clicked_pos.y,b.x,b.y,b.w,b.h)
|
||||||
|
|| !NK_INBOX(i->mouse.down_pos.x,i->mouse.down_pos.y,b.x,b.y,b.w,b.h))
|
||||||
|
#else
|
||||||
if (!NK_INBOX(btn->clicked_pos.x,btn->clicked_pos.y,b.x,b.y,b.w,b.h))
|
if (!NK_INBOX(btn->clicked_pos.x,btn->clicked_pos.y,b.x,b.y,b.w,b.h))
|
||||||
|
#endif
|
||||||
return nk_false;
|
return nk_false;
|
||||||
return nk_true;
|
return nk_true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue