Skip to content

Commit 54c49b5

Browse files
committed
Window: Mouse wheel scrolling while hovering a child window is automatically forwarded to parent window if ScrollMax is zero on the scrolling axis. Also still case if ImGuiWindowFlags_NoScrollWithMouse is set (not new), but previously the forwarding
would be disabled if ImGuiWindowFlags_NoScrollbar was set on the child window, which is not the case any more (amend #1502, #1380).
1 parent e16564e commit 54c49b5

File tree

2 files changed

+32
-22
lines changed

2 files changed

+32
-22
lines changed

docs/CHANGELOG.txt

+5
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ Breaking Changes:
4343

4444
Other Changes:
4545
- Window: Fixed InnerClipRect right-most coordinates using wrong padding setting (introduced in 1.71).
46+
- Window: Mouse wheel scrolling while hovering a child window is automatically forwarded to parent window
47+
if ScrollMax is zero on the scrolling axis.
48+
Also still case if ImGuiWindowFlags_NoScrollWithMouse is set (not new), but previously the forwarding
49+
would be disabled if ImGuiWindowFlags_NoScrollbar was set on the child window, which is not the case
50+
any more. Forwarding can still be disabled by setting ImGuiWindowFlags_NoInputs. (amend #1502, #1380).
4651
- Scrollbar: Avoid overlapping the opposite side when window (often a child window) is forcibly too small.
4752
- Word-wrapping: Fixed overzealous word-wrapping when glyph edge lands exactly on the limit. Because
4853
of this, auto-fitting exactly unwrapped text would make it wrap. (fixes initial 1.15 commit, 78645a7d).

imgui.cpp

+27-22
Original file line numberDiff line numberDiff line change
@@ -3449,12 +3449,12 @@ void ImGui::UpdateMouseWheel()
34493449
return;
34503450
if (g.IO.MouseWheel == 0.0f && g.IO.MouseWheelH == 0.0f)
34513451
return;
3452-
ImGuiWindow* window = g.HoveredWindow;
34533452

34543453
// Zoom / Scale window
34553454
// FIXME-OBSOLETE: This is an old feature, it still works but pretty much nobody is using it and may be best redesigned.
3456-
if (g.IO.MouseWheel != 0.0f && g.IO.KeyCtrl && g.IO.FontAllowUserScaling && !window->Collapsed)
3455+
if (g.IO.MouseWheel != 0.0f && g.IO.KeyCtrl && g.IO.FontAllowUserScaling && !g.HoveredWindow->Collapsed)
34573456
{
3457+
ImGuiWindow* window = g.HoveredWindow;
34583458
const float new_font_scale = ImClamp(window->FontWindowScale + g.IO.MouseWheel * 0.10f, 0.50f, 2.50f);
34593459
const float scale = new_font_scale / window->FontWindowScale;
34603460
window->FontWindowScale = new_font_scale;
@@ -3469,31 +3469,36 @@ void ImGui::UpdateMouseWheel()
34693469
}
34703470

34713471
// Mouse wheel scrolling
3472-
// If a child window has the ImGuiWindowFlags_NoScrollWithMouse flag, we give a chance to scroll its parent (unless either ImGuiWindowFlags_NoInputs or ImGuiWindowFlags_NoScrollbar are also set).
3473-
while ((window->Flags & ImGuiWindowFlags_ChildWindow) && (window->Flags & ImGuiWindowFlags_NoScrollWithMouse) && !(window->Flags & ImGuiWindowFlags_NoScrollbar) && !(window->Flags & ImGuiWindowFlags_NoMouseInputs) && window->ParentWindow)
3474-
window = window->ParentWindow;
3475-
const bool scroll_allowed = !(window->Flags & ImGuiWindowFlags_NoScrollWithMouse) && !(window->Flags & ImGuiWindowFlags_NoMouseInputs);
3476-
if (scroll_allowed && (g.IO.MouseWheel != 0.0f || g.IO.MouseWheelH != 0.0f) && !g.IO.KeyCtrl)
3477-
{
3478-
ImVec2 max_step = window->InnerRect.GetSize() * 0.67f;
3472+
// If a child window has the ImGuiWindowFlags_NoScrollWithMouse flag, we give a chance to scroll its parent
3473+
// FIXME: Lock scrolling window while not moving (see #2604)
34793474

3480-
// Vertical Mouse Wheel Scrolling (hold Shift to scroll horizontally)
3481-
if (g.IO.MouseWheel != 0.0f && !g.IO.KeyShift)
3482-
{
3483-
float scroll_step = ImFloor(ImMin(5 * window->CalcFontSize(), max_step.y));
3484-
SetWindowScrollY(window, window->Scroll.y - g.IO.MouseWheel * scroll_step);
3485-
}
3486-
else if (g.IO.MouseWheel != 0.0f && g.IO.KeyShift)
3475+
// Vertical Mouse Wheel scrolling
3476+
const float wheel_y = (g.IO.MouseWheel != 0.0f && !g.IO.KeyShift) ? g.IO.MouseWheel : 0.0f;
3477+
if (wheel_y != 0.0f && !g.IO.KeyCtrl)
3478+
{
3479+
ImGuiWindow* window = g.HoveredWindow;
3480+
while ((window->Flags & ImGuiWindowFlags_ChildWindow) && ((window->ScrollMax.y == 0.0f) || ((window->Flags & ImGuiWindowFlags_NoScrollWithMouse) && !(window->Flags & ImGuiWindowFlags_NoMouseInputs))))
3481+
window = window->ParentWindow;
3482+
if (!(window->Flags & ImGuiWindowFlags_NoScrollWithMouse) && !(window->Flags & ImGuiWindowFlags_NoMouseInputs))
34873483
{
3488-
float scroll_step = ImFloor(ImMin(2 * window->CalcFontSize(), max_step.x));
3489-
SetWindowScrollX(window, window->Scroll.x - g.IO.MouseWheel * scroll_step);
3484+
float max_step = window->InnerRect.GetHeight() * 0.67f;
3485+
float scroll_step = ImFloor(ImMin(5 * window->CalcFontSize(), max_step));
3486+
SetWindowScrollY(window, window->Scroll.y - wheel_y * scroll_step);
34903487
}
3488+
}
34913489

3492-
// Horizontal Mouse Wheel Scrolling (for hardware that supports it)
3493-
if (g.IO.MouseWheelH != 0.0f && !g.IO.KeyShift)
3490+
// Horizontal Mouse Wheel scrolling, or Vertical Mouse Wheel w/ Shift held
3491+
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;
3492+
if (wheel_x != 0.0f && !g.IO.KeyCtrl)
3493+
{
3494+
ImGuiWindow* window = g.HoveredWindow;
3495+
while ((window->Flags & ImGuiWindowFlags_ChildWindow) && ((window->ScrollMax.x == 0.0f) || ((window->Flags & ImGuiWindowFlags_NoScrollWithMouse) && !(window->Flags & ImGuiWindowFlags_NoMouseInputs))))
3496+
window = window->ParentWindow;
3497+
if (!(window->Flags & ImGuiWindowFlags_NoScrollWithMouse) && !(window->Flags & ImGuiWindowFlags_NoMouseInputs))
34943498
{
3495-
float scroll_step = ImFloor(ImMin(2 * window->CalcFontSize(), max_step.x));
3496-
SetWindowScrollX(window, window->Scroll.x - g.IO.MouseWheelH * scroll_step);
3499+
float max_step = window->InnerRect.GetWidth() * 0.67f;
3500+
float scroll_step = ImFloor(ImMin(2 * window->CalcFontSize(), max_step));
3501+
SetWindowScrollX(window, window->Scroll.x - wheel_x * scroll_step);
34973502
}
34983503
}
34993504
}

0 commit comments

Comments
 (0)