Merge pull request #448 from tcdude/master
Button behavior `NK_BUTTON_TRIGGER_ON_RELEASE`
This commit is contained in:
commit
b00c8e2c86
17
nuklear.h
17
nuklear.h
|
@ -4654,6 +4654,9 @@ struct nk_mouse_button {
|
|||
struct nk_mouse {
|
||||
struct nk_mouse_button buttons[NK_BUTTON_MAX];
|
||||
struct nk_vec2 pos;
|
||||
#ifdef NK_BUTTON_TRIGGER_ON_RELEASE
|
||||
struct nk_vec2 down_pos;
|
||||
#endif
|
||||
struct nk_vec2 prev;
|
||||
struct nk_vec2 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->down = down;
|
||||
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_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;
|
||||
if (!i) return nk_false;
|
||||
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))
|
||||
#endif
|
||||
return nk_false;
|
||||
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
|
||||
/// - [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
|
||||
/// - 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
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
/// - [y]: Minor version with non-breaking API and library changes
|
||||
/// - [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
|
||||
/// - 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
|
||||
|
|
|
@ -4433,6 +4433,9 @@ struct nk_mouse_button {
|
|||
struct nk_mouse {
|
||||
struct nk_mouse_button buttons[NK_BUTTON_MAX];
|
||||
struct nk_vec2 pos;
|
||||
#ifdef NK_BUTTON_TRIGGER_ON_RELEASE
|
||||
struct nk_vec2 down_pos;
|
||||
#endif
|
||||
struct nk_vec2 prev;
|
||||
struct nk_vec2 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->down = down;
|
||||
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_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;
|
||||
if (!i) return nk_false;
|
||||
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))
|
||||
#endif
|
||||
return nk_false;
|
||||
return nk_true;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue