Implement adaptive granularity-based scrolling (#1293)

This commit is contained in:
Stanislav Denisov
2025-11-11 08:11:47 +01:00
committed by GitHub
parent 3fc5efbb46
commit 2cc158ddf0
2 changed files with 16 additions and 8 deletions
+8 -7
View File
@@ -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();
+8 -1
View File
@@ -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