Skip to content

Commit

Permalink
Scrolling: Fix mouse wheel axis swap when using SHIFT on macOS (syste…
Browse files Browse the repository at this point in the history
…m already does it). (#4010)
  • Loading branch information
ocornut committed Apr 6, 2021
1 parent 5f45047 commit 92b7b1f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions docs/CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Other Changes:

- Scrolling: Fix scroll tracking with e.g. SetScrollHereX/Y() when WindowPadding < ItemSpacing.
- Scrolling: Fix scroll snapping on edge of scroll region when both scrollbars are enabled.
- Scrolling: Fix mouse wheel axis swap when using SHIFT on macOS (system already does it). (#4010)
- Window: Fix IsWindowAppearing() from returning true twice in most cases. (#3982, #1497, #1061)
- Tables: Expose TableSetColumnEnabled() in public api. (#3935)
- TabBar: Fixed mouse reordering with very fast movements (e.g. crossing multiple tabs in a single
Expand Down
14 changes: 10 additions & 4 deletions imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3738,10 +3738,17 @@ void ImGui::UpdateMouseWheel()

// Mouse wheel scrolling
// If a child window has the ImGuiWindowFlags_NoScrollWithMouse flag, we give a chance to scroll its parent
if (g.IO.KeyCtrl)
return;

// As a standard behavior holding SHIFT while using Vertical Mouse Wheel triggers Horizontal scroll instead
// (we avoid doing it on OSX as it the OS input layer handles this already)
const bool swap_axis = g.IO.KeyShift && !g.IO.ConfigMacOSXBehaviors;
const float wheel_y = swap_axis ? 0.0f : g.IO.MouseWheel;
const float wheel_x = swap_axis ? g.IO.MouseWheel : g.IO.MouseWheelH;

// Vertical Mouse Wheel scrolling
const float wheel_y = (g.IO.MouseWheel != 0.0f && !g.IO.KeyShift) ? g.IO.MouseWheel : 0.0f;
if (wheel_y != 0.0f && !g.IO.KeyCtrl)
if (wheel_y != 0.0f)
{
StartLockWheelingWindow(window);
while ((window->Flags & ImGuiWindowFlags_ChildWindow) && ((window->ScrollMax.y == 0.0f) || ((window->Flags & ImGuiWindowFlags_NoScrollWithMouse) && !(window->Flags & ImGuiWindowFlags_NoMouseInputs))))
Expand All @@ -3755,8 +3762,7 @@ void ImGui::UpdateMouseWheel()
}

// Horizontal Mouse Wheel scrolling, or Vertical Mouse Wheel w/ Shift held
const float wheel_x = (g.IO.MouseWheelH != 0.0f && !g.IO.KeyShift) ? g.IO.MouseWheelH : (g.IO.MouseWheel != 0.0f && g.IO.KeyShift) ? g.IO.MouseWheel : 0.0f;
if (wheel_x != 0.0f && !g.IO.KeyCtrl)
if (wheel_x != 0.0f)
{
StartLockWheelingWindow(window);
while ((window->Flags & ImGuiWindowFlags_ChildWindow) && ((window->ScrollMax.x == 0.0f) || ((window->Flags & ImGuiWindowFlags_NoScrollWithMouse) && !(window->Flags & ImGuiWindowFlags_NoMouseInputs))))
Expand Down

0 comments on commit 92b7b1f

Please sign in to comment.