Skip to content

Commit a582d92

Browse files
committed
Inputs: modulate wheel lock timer for small amount of wheeling. Slightly lower timer. (#3795)
1 parent 03d3343 commit a582d92

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

docs/CHANGELOG.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ Other Changes:
119119
systems while letting early adopters adopters toy with internals.
120120
(#456, #2637, #2620, #2891, #3370, #3724, #4828, #5108, #5242, #5641)
121121
- Scrolling: Tweak mouse-wheel locked window timer so it is shorter but also gets reset
122-
whenever scrolling again (#2604).
122+
whenever scrolling again. Modulate for small (sub-pixel) amounts. (#2604)
123123
- Scrolling: Mitigated issue where multi-axis mouse-wheel inputs (usually from touch pad
124124
events) are incorrectly locking scrolling in a parent window. (#4559, #3795, #2604)
125125
- Scrolling: Exposed SetNextWindowScroll() in public API. Useful to remove a scrolling

imgui.cpp

+10-7
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,7 @@ static const float NAV_WINDOWING_LIST_APPEAR_DELAY = 0.15f; // Time
954954
// Window resizing from edges (when io.ConfigWindowsResizeFromEdges = true and ImGuiBackendFlags_HasMouseCursors is set in io.BackendFlags by backend)
955955
static const float WINDOWS_HOVER_PADDING = 4.0f; // Extend outside window for hovering/resizing (maxxed with TouchPadding) and inside windows for borders. Affect FindHoveredWindow().
956956
static const float WINDOWS_RESIZE_FROM_EDGES_FEEDBACK_TIMER = 0.04f; // Reduce visual noise by only highlighting the border after a certain time.
957-
static const float WINDOWS_MOUSE_WHEEL_SCROLL_LOCK_TIMER = 0.80f; // Lock scrolled window (so it doesn't pick child windows that are scrolling through) for a certain time, unless mouse moved.
957+
static const float WINDOWS_MOUSE_WHEEL_SCROLL_LOCK_TIMER = 0.70f; // Lock scrolled window (so it doesn't pick child windows that are scrolling through) for a certain time, unless mouse moved.
958958

959959
//-------------------------------------------------------------------------
960960
// [SECTION] FORWARD DECLARATIONS
@@ -4338,10 +4338,13 @@ static void ImGui::UpdateMouseInputs()
43384338
}
43394339
}
43404340

4341-
static void LockWheelingWindow(ImGuiWindow* window)
4341+
static void LockWheelingWindow(ImGuiWindow* window, float wheel_amount)
43424342
{
43434343
ImGuiContext& g = *GImGui;
4344-
g.WheelingWindowReleaseTimer = window ? WINDOWS_MOUSE_WHEEL_SCROLL_LOCK_TIMER : 0.0f;
4344+
if (window)
4345+
g.WheelingWindowReleaseTimer = ImMin(g.WheelingWindowReleaseTimer + ImAbs(wheel_amount) * WINDOWS_MOUSE_WHEEL_SCROLL_LOCK_TIMER, WINDOWS_MOUSE_WHEEL_SCROLL_LOCK_TIMER);
4346+
else
4347+
g.WheelingWindowReleaseTimer = NULL;
43454348
if (g.WheelingWindow == window)
43464349
return;
43474350
IMGUI_DEBUG_LOG_IO("LockWheelingWindow() \"%s\"\n", window ? window->Name : "NULL");
@@ -4360,7 +4363,7 @@ void ImGui::UpdateMouseWheel()
43604363
if (IsMousePosValid() && ImLengthSqr(g.IO.MousePos - g.WheelingWindowRefMousePos) > g.IO.MouseDragThreshold * g.IO.MouseDragThreshold)
43614364
g.WheelingWindowReleaseTimer = 0.0f;
43624365
if (g.WheelingWindowReleaseTimer <= 0.0f)
4363-
LockWheelingWindow(NULL);
4366+
LockWheelingWindow(NULL, 0.0f);
43644367
}
43654368

43664369
ImVec2 wheel;
@@ -4378,7 +4381,7 @@ void ImGui::UpdateMouseWheel()
43784381
// FIXME-OBSOLETE: This is an old feature, it still works but pretty much nobody is using it and may be best redesigned.
43794382
if (wheel.y != 0.0f && g.IO.KeyCtrl && g.IO.FontAllowUserScaling)
43804383
{
4381-
LockWheelingWindow(mouse_window);
4384+
LockWheelingWindow(mouse_window, wheel.y);
43824385
ImGuiWindow* window = mouse_window;
43834386
const float new_font_scale = ImClamp(window->FontWindowScale + g.IO.MouseWheel * 0.10f, 0.50f, 2.50f);
43844387
const float scale = new_font_scale / window->FontWindowScale;
@@ -4417,7 +4420,7 @@ void ImGui::UpdateMouseWheel()
44174420
window = window->ParentWindow;
44184421
if (!(window->Flags & ImGuiWindowFlags_NoScrollWithMouse) && !(window->Flags & ImGuiWindowFlags_NoMouseInputs))
44194422
{
4420-
LockWheelingWindow(mouse_window);
4423+
LockWheelingWindow(mouse_window, wheel.y);
44214424
float max_step = window->InnerRect.GetHeight() * 0.67f;
44224425
float scroll_step = ImFloor(ImMin(5 * window->CalcFontSize(), max_step));
44234426
SetScrollY(window, window->Scroll.y - wheel.y * scroll_step);
@@ -4432,7 +4435,7 @@ void ImGui::UpdateMouseWheel()
44324435
window = window->ParentWindow;
44334436
if (!(window->Flags & ImGuiWindowFlags_NoScrollWithMouse) && !(window->Flags & ImGuiWindowFlags_NoMouseInputs))
44344437
{
4435-
LockWheelingWindow(mouse_window);
4438+
LockWheelingWindow(mouse_window, wheel.x);
44364439
float max_step = window->InnerRect.GetWidth() * 0.67f;
44374440
float scroll_step = ImFloor(ImMin(2 * window->CalcFontSize(), max_step));
44384441
SetScrollX(window, window->Scroll.x - wheel.x * scroll_step);

0 commit comments

Comments
 (0)