From 2cc158ddf0f82e757ed6e78db0fe915b75cc8e98 Mon Sep 17 00:00:00 2001 From: Stanislav Denisov Date: Tue, 11 Nov 2025 08:11:47 +0100 Subject: [PATCH] Implement adaptive granularity-based scrolling (#1293) --- WickedEngine/wiGUI.cpp | 15 ++++++++------- WickedEngine/wiGUI.h | 9 ++++++++- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/WickedEngine/wiGUI.cpp b/WickedEngine/wiGUI.cpp index 564cfd3ab..8dca2a4da 100644 --- a/WickedEngine/wiGUI.cpp +++ b/WickedEngine/wiGUI.cpp @@ -1472,7 +1472,8 @@ namespace wi::gui scroll_allowed = false; state = FOCUS; // This is outside scrollbar code, because it can also be scrolled if parent widget is only in focus - scrollbar.Scroll(wi::input::GetPointer().z * 20); + const float wheel_delta = wi::input::GetPointer().z; + scrollbar.Scroll(wheel_delta * 60.0f); } else { @@ -3857,12 +3858,12 @@ namespace wi::gui if (!IsMinimized() && IsVisible()) { - float scroll = wi::input::GetPointer().z * 20; - if (scroll && scroll_allowed && scrollbar_vertical.IsScrollbarRequired() && pointerHitbox.intersects(hitBox)) // when window is in focus, but other widgets aren't + const float wheel_delta = wi::input::GetPointer().z; + if (wheel_delta != 0.0f && scroll_allowed && scrollbar_vertical.IsScrollbarRequired() && pointerHitbox.intersects(hitBox)) // when window is in focus, but other widgets aren't { scroll_allowed = false; // This is outside scrollbar code, because it can also be scrolled if parent widget is only in focus - scrollbar_vertical.Scroll(scroll); + scrollbar_vertical.Scroll(wheel_delta * 60.0f); } } @@ -5521,12 +5522,12 @@ namespace wi::gui } } - float scroll = wi::input::GetPointer().z * 10; - if (scroll && scroll_allowed && scrollbar.IsScrollbarRequired() && pointerHitbox.intersects(hitBox)) + const float wheel_delta = wi::input::GetPointer().z; + if (wheel_delta != 0.0f && scroll_allowed && scrollbar.IsScrollbarRequired() && pointerHitbox.intersects(hitBox)) { scroll_allowed = false; // This is outside scrollbar code, because it can also be scrolled if parent widget is only in focus - scrollbar.Scroll(scroll); + scrollbar.Scroll(wheel_delta * 40.0f); } Hitbox2D itemlist_box = GetHitbox_ListArea(); diff --git a/WickedEngine/wiGUI.h b/WickedEngine/wiGUI.h index 34f70fb87..5781d49dd 100644 --- a/WickedEngine/wiGUI.h +++ b/WickedEngine/wiGUI.h @@ -445,7 +445,14 @@ namespace wi::gui float GetOffset() const { return list_offset; } void SetOffset(float value); // This can be called by user for extra scrolling on top of base functionality - void Scroll(float amount) { scrollbar_delta -= amount; } + // scroll sensitivity based on how much content is hidden (higher granularity = more amplification) + void Scroll(const float amount) + { + if (scrollbar_granularity < 1.0f) + { + scrollbar_delta -= amount * scrollbar_granularity / (1.0f - scrollbar_granularity); + } + } // How much the max scrolling will offset the list even further than it would be necessary for fitting // this value is in percent of a full scrollbar's worth of extra offset // 0: no extra offset