Skip to content

Commit

Permalink
Scrolling: Mitigated issue where multi-axis mouse-wheel inputs (usual…
Browse files Browse the repository at this point in the history
…ly from touch pad events) are incorrectly locking scrolling in a parent window. (#4559, #3795, #2604)
  • Loading branch information
ocornut committed Oct 4, 2022
1 parent 80a870a commit c7d3d22
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 2 additions & 0 deletions docs/CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 9 additions & 5 deletions imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit c7d3d22

Please sign in to comment.