From c7d3d22ae1e2b8f84ae30a922099873d5016e6d6 Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 4 Oct 2022 15:39:55 +0200 Subject: [PATCH] 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) --- docs/CHANGELOG.txt | 2 ++ imgui.cpp | 14 +++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 9f181b7b..552b2610 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -105,6 +105,8 @@ Other Changes: achieve certains things (e.g. some ways to implement suggestion popup #718, #4461). - Scrolling: Tweak mouse-wheel locked window timer so it is shorter but also gets reset whenever scrolling again (#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) - InputText: added experimental io.ConfigInputTextEnterKeepActive feature to make pressing Enter keep the input active and select all text. - InputText: numerical fields automatically accept full-width characters (U+FF01..U+FF5E) diff --git a/imgui.cpp b/imgui.cpp index efa16bd6..c576f74d 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -4299,15 +4299,17 @@ void ImGui::UpdateMouseWheel() if (wheel_x == 0.0f && wheel_y == 0.0f) return; - ImGuiWindow* window = g.WheelingWindow ? g.WheelingWindow : g.HoveredWindow; - if (!window || window->Collapsed) + //IMGUI_DEBUG_LOG("MouseWheel X:%.3f Y:%.3f\n", wheel_x, wheel_y); + ImGuiWindow* mouse_window = g.WheelingWindow ? g.WheelingWindow : g.HoveredWindow; + if (!mouse_window || mouse_window->Collapsed) return; // Zoom / Scale window // 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(window); + LockWheelingWindow(mouse_window); + 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; window->FontWindowScale = new_font_scale; @@ -4338,11 +4340,12 @@ void ImGui::UpdateMouseWheel() // Vertical Mouse Wheel scrolling if (wheel_y != 0.0f) { - LockWheelingWindow(window); + ImGuiWindow* window = mouse_window; while ((window->Flags & ImGuiWindowFlags_ChildWindow) && ((window->ScrollMax.y == 0.0f) || ((window->Flags & ImGuiWindowFlags_NoScrollWithMouse) && !(window->Flags & ImGuiWindowFlags_NoMouseInputs)))) window = window->ParentWindow; if (!(window->Flags & ImGuiWindowFlags_NoScrollWithMouse) && !(window->Flags & ImGuiWindowFlags_NoMouseInputs)) { + LockWheelingWindow(mouse_window); 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); @@ -4352,11 +4355,12 @@ void ImGui::UpdateMouseWheel() // Horizontal Mouse Wheel scrolling, or Vertical Mouse Wheel w/ Shift held if (wheel_x != 0.0f) { - LockWheelingWindow(window); + ImGuiWindow* window = mouse_window; while ((window->Flags & ImGuiWindowFlags_ChildWindow) && ((window->ScrollMax.x == 0.0f) || ((window->Flags & ImGuiWindowFlags_NoScrollWithMouse) && !(window->Flags & ImGuiWindowFlags_NoMouseInputs)))) window = window->ParentWindow; if (!(window->Flags & ImGuiWindowFlags_NoScrollWithMouse) && !(window->Flags & ImGuiWindowFlags_NoMouseInputs)) { + LockWheelingWindow(mouse_window); 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);