Skip to content

Commit fdbce6c

Browse files
folaysfolays
folays
authored and
folays
committed
fix scroll-x on touchpad (prevent bubbling scroll-y events and lock further wheeling events to parent window, if children window has interest for scroll-x)
1 parent 56f7bda commit fdbce6c

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

imgui.cpp

+9-15
Original file line numberDiff line numberDiff line change
@@ -3655,28 +3655,22 @@ void ImGui::UpdateMouseWheel()
36553655
// If a child window has the ImGuiWindowFlags_NoScrollWithMouse flag, we give a chance to scroll its parent
36563656

36573657
// Vertical Mouse Wheel scrolling
3658-
const float wheel_y = (g.IO.MouseWheel != 0.0f && !g.IO.KeyShift) ? g.IO.MouseWheel : 0.0f;
3659-
if (wheel_y != 0.0f && !g.IO.KeyCtrl)
3658+
const float wheel_y = (!g.IO.KeyShift) ? g.IO.MouseWheel : 0.0f;
3659+
// Horizontal Mouse Wheel scrolling, or Vertical Mouse Wheel w/ Shift held
3660+
const float wheel_x = (!g.IO.KeyShift) ? g.IO.MouseWheelH : g.IO.MouseWheel;
3661+
if ((wheel_y != 0.0f || wheel_x != 0.0f) && !g.IO.KeyCtrl)
36603662
{
3661-
StartLockWheelingWindow(window);
3662-
while ((window->Flags & ImGuiWindowFlags_ChildWindow) && ((window->ScrollMax.y == 0.0f) || ((window->Flags & ImGuiWindowFlags_NoScrollWithMouse) && !(window->Flags & ImGuiWindowFlags_NoMouseInputs))))
3663+
bool noScroll = (window->Flags & ImGuiWindowFlags_NoScrollWithMouse) && !(window->Flags & ImGuiWindowFlags_NoMouseInputs);
3664+
while ((window->Flags & ImGuiWindowFlags_ChildWindow) && ((window->ScrollMax.y == 0.0f && window->ScrollMax.x == 0.0f) || noScroll))
36633665
window = window->ParentWindow;
3664-
if (!(window->Flags & ImGuiWindowFlags_NoScrollWithMouse) && !(window->Flags & ImGuiWindowFlags_NoMouseInputs))
3666+
StartLockWheelingWindow(window);
3667+
if (!noScroll && wheel_y != 0.0f)
36653668
{
36663669
float max_step = window->InnerRect.GetHeight() * 0.67f;
36673670
float scroll_step = ImFloor(ImMin(5 * window->CalcFontSize(), max_step));
36683671
SetScrollY(window, window->Scroll.y - wheel_y * scroll_step);
36693672
}
3670-
}
3671-
3672-
// Horizontal Mouse Wheel scrolling, or Vertical Mouse Wheel w/ Shift held
3673-
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;
3674-
if (wheel_x != 0.0f && !g.IO.KeyCtrl)
3675-
{
3676-
StartLockWheelingWindow(window);
3677-
while ((window->Flags & ImGuiWindowFlags_ChildWindow) && ((window->ScrollMax.x == 0.0f) || ((window->Flags & ImGuiWindowFlags_NoScrollWithMouse) && !(window->Flags & ImGuiWindowFlags_NoMouseInputs))))
3678-
window = window->ParentWindow;
3679-
if (!(window->Flags & ImGuiWindowFlags_NoScrollWithMouse) && !(window->Flags & ImGuiWindowFlags_NoMouseInputs))
3673+
if (!noScroll && wheel_x != 0.0f)
36803674
{
36813675
float max_step = window->InnerRect.GetWidth() * 0.67f;
36823676
float scroll_step = ImFloor(ImMin(2 * window->CalcFontSize(), max_step));

0 commit comments

Comments
 (0)