From 91a6e773a1d8a916f063e71c3091c7cc69bdaf64 Mon Sep 17 00:00:00 2001 From: Robert Winkler Date: Wed, 5 Mar 2025 13:55:15 -0700 Subject: [PATCH] Fix knob scrolling and remove some dead code --- clib.json | 2 +- nuklear.h | 27 +++++++++++++++------------ src/CHANGELOG | 1 + src/nuklear_knob.c | 20 +++++++++++--------- src/nuklear_panel.c | 6 +++--- 5 files changed, 31 insertions(+), 25 deletions(-) diff --git a/clib.json b/clib.json index af0eaf08..db1abfc5 100644 --- a/clib.json +++ b/clib.json @@ -1,6 +1,6 @@ { "name": "nuklear", - "version": "4.12.4", + "version": "4.12.5", "repo": "Immediate-Mode-UI/Nuklear", "description": "A small ANSI C gui toolkit", "keywords": ["gl", "ui", "toolkit"], diff --git a/nuklear.h b/nuklear.h index 8581bbc0..e27be460 100644 --- a/nuklear.h +++ b/nuklear.h @@ -20315,7 +20315,7 @@ nk_panel_end(struct nk_context *ctx) root_window = root_window->parent; /* only allow scrolling if parent window is active */ - scroll_has_scrolling = 0; + scroll_has_scrolling = nk_false; if ((root_window == ctx->active) && layout->has_scrolling) { /* and panel is being hovered and inside clip rect*/ if (nk_input_is_mouse_hovering_rect(in, layout->bounds) && @@ -20332,13 +20332,13 @@ nk_panel_end(struct nk_context *ctx) scroll_has_scrolling = nk_true; } } - } else if (!nk_panel_is_sub(layout->type)) { + } else { /* window mouse wheel scrolling */ scroll_has_scrolling = (window == ctx->active) && layout->has_scrolling; if (in && (in->mouse.scroll_delta.y > 0 || in->mouse.scroll_delta.x > 0) && scroll_has_scrolling) window->scrolled = nk_true; else window->scrolled = nk_false; - } else scroll_has_scrolling = nk_false; + } { /* vertical scrollbar */ @@ -26105,16 +26105,18 @@ nk_knob_behavior(nk_flags *state, struct nk_input *in, /* knob widget state */ if (nk_input_is_mouse_hovering_rect(in, bounds)){ *state = NK_WIDGET_STATE_HOVERED; - if (in) { - /* handle scroll and arrow inputs */ - if (in->mouse.scroll_delta.y > 0 || - (in->keyboard.keys[NK_KEY_UP].down && in->keyboard.keys[NK_KEY_UP].clicked)) - knob_value += knob_step; - - if (in->mouse.scroll_delta.y < 0 || - (in->keyboard.keys[NK_KEY_DOWN].down && in->keyboard.keys[NK_KEY_DOWN].clicked)) - knob_value -= knob_step; + /* handle scroll and arrow inputs */ + if (in->mouse.scroll_delta.y > 0 || + (in->keyboard.keys[NK_KEY_UP].down && in->keyboard.keys[NK_KEY_UP].clicked)) { + knob_value += knob_step; } + + if (in->mouse.scroll_delta.y < 0 || + (in->keyboard.keys[NK_KEY_DOWN].down && in->keyboard.keys[NK_KEY_DOWN].clicked)) { + knob_value -= knob_step; + } + /* easiest way to disable scrolling of parent panels..knob eats scrolling */ + in->mouse.scroll_delta.y = 0; knob_value = NK_CLAMP(knob_min, knob_value, knob_max); } if (*state & NK_WIDGET_STATE_HOVER && @@ -30698,6 +30700,7 @@ 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 /// +/// - 2025/03/05 (4.12.5) - Fix scrolling knob also scrolling parent window, remove dead code /// - 2024/12/11 (4.12.4) - Fix array subscript [0, 0] is outside array bounds of ‘char[1]’ /// - 2024/12/11 (4.12.3) - Fix border color for property widgets /// - 2024/11/20 (4.12.2) - Fix int/float type conversion warnings in `nk_roundf` diff --git a/src/CHANGELOG b/src/CHANGELOG index 89405d0c..edc18252 100644 --- a/src/CHANGELOG +++ b/src/CHANGELOG @@ -7,6 +7,7 @@ /// - [y]: Minor version with non-breaking API and library changes /// - [z]: Patch version with no direct changes to the API /// +/// - 2025/03/05 (4.12.5) - Fix scrolling knob also scrolling parent window, remove dead code /// - 2024/12/11 (4.12.4) - Fix array subscript [0, 0] is outside array bounds of ‘char[1]’ /// - 2024/12/11 (4.12.3) - Fix border color for property widgets /// - 2024/11/20 (4.12.2) - Fix int/float type conversion warnings in `nk_roundf` diff --git a/src/nuklear_knob.c b/src/nuklear_knob.c index 328f48be..81c5a713 100644 --- a/src/nuklear_knob.c +++ b/src/nuklear_knob.c @@ -51,16 +51,18 @@ nk_knob_behavior(nk_flags *state, struct nk_input *in, /* knob widget state */ if (nk_input_is_mouse_hovering_rect(in, bounds)){ *state = NK_WIDGET_STATE_HOVERED; - if (in) { - /* handle scroll and arrow inputs */ - if (in->mouse.scroll_delta.y > 0 || - (in->keyboard.keys[NK_KEY_UP].down && in->keyboard.keys[NK_KEY_UP].clicked)) - knob_value += knob_step; - - if (in->mouse.scroll_delta.y < 0 || - (in->keyboard.keys[NK_KEY_DOWN].down && in->keyboard.keys[NK_KEY_DOWN].clicked)) - knob_value -= knob_step; + /* handle scroll and arrow inputs */ + if (in->mouse.scroll_delta.y > 0 || + (in->keyboard.keys[NK_KEY_UP].down && in->keyboard.keys[NK_KEY_UP].clicked)) { + knob_value += knob_step; } + + if (in->mouse.scroll_delta.y < 0 || + (in->keyboard.keys[NK_KEY_DOWN].down && in->keyboard.keys[NK_KEY_DOWN].clicked)) { + knob_value -= knob_step; + } + /* easiest way to disable scrolling of parent panels..knob eats scrolling */ + in->mouse.scroll_delta.y = 0; knob_value = NK_CLAMP(knob_min, knob_value, knob_max); } if (*state & NK_WIDGET_STATE_HOVER && diff --git a/src/nuklear_panel.c b/src/nuklear_panel.c index 75b8eb47..ce28b1aa 100644 --- a/src/nuklear_panel.c +++ b/src/nuklear_panel.c @@ -421,7 +421,7 @@ nk_panel_end(struct nk_context *ctx) root_window = root_window->parent; /* only allow scrolling if parent window is active */ - scroll_has_scrolling = 0; + scroll_has_scrolling = nk_false; if ((root_window == ctx->active) && layout->has_scrolling) { /* and panel is being hovered and inside clip rect*/ if (nk_input_is_mouse_hovering_rect(in, layout->bounds) && @@ -438,13 +438,13 @@ nk_panel_end(struct nk_context *ctx) scroll_has_scrolling = nk_true; } } - } else if (!nk_panel_is_sub(layout->type)) { + } else { /* window mouse wheel scrolling */ scroll_has_scrolling = (window == ctx->active) && layout->has_scrolling; if (in && (in->mouse.scroll_delta.y > 0 || in->mouse.scroll_delta.x > 0) && scroll_has_scrolling) window->scrolled = nk_true; else window->scrolled = nk_false; - } else scroll_has_scrolling = nk_false; + } { /* vertical scrollbar */