From f4398226ccbe0dc89196d7535958c9d555c0c03a Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 29 Sep 2017 00:01:26 +0200 Subject: [PATCH] Nav: Support for fallback horizontal scrolling with PadLeft/PadRight (nb: fallback scrolling is only used to navigate windows that have no interactive items). (#787) --- imgui.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index fa632ee6..186f262c 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2802,12 +2802,17 @@ static void NavUpdate() // Scrolling if (g.NavWindow && !(g.NavWindow->Flags & ImGuiWindowFlags_NoNavInputs) && !g.NavWindowingTarget) { - // Fallback manual-scroll with NavUp/NavDown when window has no navigable item + // *Fallback* manual-scroll with NavUp/NavDown when window has no navigable item const float scroll_speed = ImFloor(g.NavWindow->CalcFontSize() * 100 * g.IO.DeltaTime + 0.5f); // We need round the scrolling speed because sub-pixel scroll isn't reliably supported. - if (!g.NavWindow->DC.NavLayerActiveMask && g.NavWindow->DC.NavHasScroll && g.NavMoveRequest && (g.NavMoveDir == ImGuiDir_Up || g.NavMoveDir == ImGuiDir_Down)) - SetWindowScrollY(g.NavWindow, ImFloor(g.NavWindow->Scroll.y + ((g.NavMoveDir == ImGuiDir_Up) ? -1.0f : +1.0f) * scroll_speed)); + if (!g.NavWindow->DC.NavLayerActiveMask && g.NavWindow->DC.NavHasScroll && g.NavMoveRequest) + { + if (g.NavMoveDir == ImGuiDir_Left || g.NavMoveDir == ImGuiDir_Right) + SetWindowScrollX(g.NavWindow, ImFloor(g.NavWindow->Scroll.x + ((g.NavMoveDir == ImGuiDir_Left) ? -1.0f : +1.0f) * scroll_speed)); + if (g.NavMoveDir == ImGuiDir_Up || g.NavMoveDir == ImGuiDir_Down) + SetWindowScrollY(g.NavWindow, ImFloor(g.NavWindow->Scroll.y + ((g.NavMoveDir == ImGuiDir_Up) ? -1.0f : +1.0f) * scroll_speed)); + } - // Manual scroll with NavScrollXXX keys + // *Normal* Manual scroll with NavScrollXXX keys ImVec2 scroll_dir = GetNavInputAmount2d(1, ImGuiNavReadMode_Down, 1.0f/10.0f, 10.0f); if (scroll_dir.x != 0.0f && g.NavWindow->ScrollbarX) {