From a582d92c315b019b69b773d787b81c561c0e165a Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 15 Nov 2022 12:25:15 +0100 Subject: [PATCH] Inputs: modulate wheel lock timer for small amount of wheeling. Slightly lower timer. (#3795) --- docs/CHANGELOG.txt | 2 +- imgui.cpp | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 60aa32fa..c2ec2c3c 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -119,7 +119,7 @@ Other Changes: systems while letting early adopters adopters toy with internals. (#456, #2637, #2620, #2891, #3370, #3724, #4828, #5108, #5242, #5641) - Scrolling: Tweak mouse-wheel locked window timer so it is shorter but also gets reset - whenever scrolling again (#2604). + whenever scrolling again. Modulate for small (sub-pixel) amounts. (#2604) - Scrolling: Mitigated issue where multi-axis mouse-wheel inputs (usually from touch pad events) are incorrectly locking scrolling in a parent window. (#4559, #3795, #2604) - Scrolling: Exposed SetNextWindowScroll() in public API. Useful to remove a scrolling diff --git a/imgui.cpp b/imgui.cpp index 7bb6ea53..83607f7d 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -954,7 +954,7 @@ static const float NAV_WINDOWING_LIST_APPEAR_DELAY = 0.15f; // Time // Window resizing from edges (when io.ConfigWindowsResizeFromEdges = true and ImGuiBackendFlags_HasMouseCursors is set in io.BackendFlags by backend) static const float WINDOWS_HOVER_PADDING = 4.0f; // Extend outside window for hovering/resizing (maxxed with TouchPadding) and inside windows for borders. Affect FindHoveredWindow(). static const float WINDOWS_RESIZE_FROM_EDGES_FEEDBACK_TIMER = 0.04f; // Reduce visual noise by only highlighting the border after a certain time. -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. +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. //------------------------------------------------------------------------- // [SECTION] FORWARD DECLARATIONS @@ -4338,10 +4338,13 @@ static void ImGui::UpdateMouseInputs() } } -static void LockWheelingWindow(ImGuiWindow* window) +static void LockWheelingWindow(ImGuiWindow* window, float wheel_amount) { ImGuiContext& g = *GImGui; - g.WheelingWindowReleaseTimer = window ? WINDOWS_MOUSE_WHEEL_SCROLL_LOCK_TIMER : 0.0f; + if (window) + g.WheelingWindowReleaseTimer = ImMin(g.WheelingWindowReleaseTimer + ImAbs(wheel_amount) * WINDOWS_MOUSE_WHEEL_SCROLL_LOCK_TIMER, WINDOWS_MOUSE_WHEEL_SCROLL_LOCK_TIMER); + else + g.WheelingWindowReleaseTimer = NULL; if (g.WheelingWindow == window) return; IMGUI_DEBUG_LOG_IO("LockWheelingWindow() \"%s\"\n", window ? window->Name : "NULL"); @@ -4360,7 +4363,7 @@ void ImGui::UpdateMouseWheel() if (IsMousePosValid() && ImLengthSqr(g.IO.MousePos - g.WheelingWindowRefMousePos) > g.IO.MouseDragThreshold * g.IO.MouseDragThreshold) g.WheelingWindowReleaseTimer = 0.0f; if (g.WheelingWindowReleaseTimer <= 0.0f) - LockWheelingWindow(NULL); + LockWheelingWindow(NULL, 0.0f); } ImVec2 wheel; @@ -4378,7 +4381,7 @@ void ImGui::UpdateMouseWheel() // FIXME-OBSOLETE: This is an old feature, it still works but pretty much nobody is using it and may be best redesigned. if (wheel.y != 0.0f && g.IO.KeyCtrl && g.IO.FontAllowUserScaling) { - LockWheelingWindow(mouse_window); + LockWheelingWindow(mouse_window, wheel.y); ImGuiWindow* window = mouse_window; const float new_font_scale = ImClamp(window->FontWindowScale + g.IO.MouseWheel * 0.10f, 0.50f, 2.50f); const float scale = new_font_scale / window->FontWindowScale; @@ -4417,7 +4420,7 @@ void ImGui::UpdateMouseWheel() window = window->ParentWindow; if (!(window->Flags & ImGuiWindowFlags_NoScrollWithMouse) && !(window->Flags & ImGuiWindowFlags_NoMouseInputs)) { - LockWheelingWindow(mouse_window); + LockWheelingWindow(mouse_window, wheel.y); float max_step = window->InnerRect.GetHeight() * 0.67f; float scroll_step = ImFloor(ImMin(5 * window->CalcFontSize(), max_step)); SetScrollY(window, window->Scroll.y - wheel.y * scroll_step); @@ -4432,7 +4435,7 @@ void ImGui::UpdateMouseWheel() window = window->ParentWindow; if (!(window->Flags & ImGuiWindowFlags_NoScrollWithMouse) && !(window->Flags & ImGuiWindowFlags_NoMouseInputs)) { - LockWheelingWindow(mouse_window); + LockWheelingWindow(mouse_window, wheel.x); float max_step = window->InnerRect.GetWidth() * 0.67f; float scroll_step = ImFloor(ImMin(2 * window->CalcFontSize(), max_step)); SetScrollX(window, window->Scroll.x - wheel.x * scroll_step);