From 78b7e2dfb3aaf5cef13da1fbe04de7b81fe9cdf4 Mon Sep 17 00:00:00 2001 From: ocornut Date: Sun, 21 Aug 2016 14:53:26 +0200 Subject: [PATCH] Nav: Process and apply mouse move request immediately after move request result comes (#323) --- imgui.cpp | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index e2718ce5f..5fcb20971 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2475,20 +2475,6 @@ static void NavUpdate() g.NavInitDefaultResultExplicit = false; g.NavInitDefaultResultId = 0; - // Apply application mouse position movement - if (g.NavMousePosDirty && g.NavIdIsAlive) - { - // Set mouse position given our knowledge of the nav widget position from last frame - if (g.IO.NavMovesMouse) - { - g.IO.MousePos = g.IO.MousePosPrev = NavCalcPreferredMousePos(); - g.IO.WantMoveMouse = true; - } - g.NavMousePosDirty = false; - } - g.NavIdIsAlive = false; - g.NavTabbedId = 0; - // Process navigation move request if (g.NavMoveRequest && g.NavMoveResultId != 0) { @@ -2519,6 +2505,10 @@ static void NavUpdate() g.NavWindow->ScrollTarget.y = g.NavMoveResultRectRel.Max.y + g.NavWindow->Scroll.y + g.Style.ItemSpacing.y; g.NavWindow->ScrollTargetCenterRatio.y = 1.0f; } + + // Estimate upcoming scroll so we can offset our relative mouse position so mouse position can be applied immediately (under this block) + ImVec2 next_scroll = CalcNextScrollFromScrollTargetAndClamp(g.NavWindow); + g.NavMoveResultRectRel.Translate(g.NavWindow->Scroll - next_scroll); } // Apply result from previous frame navigation directional move request @@ -2527,6 +2517,20 @@ static void NavUpdate() g.NavMoveFromClampedRefRect = false; } + // Apply application mouse position movement, after we had a chance to process move request result. + if (g.NavMousePosDirty && g.NavIdIsAlive) + { + // Set mouse position given our knowledge of the nav widget position from last frame + if (g.IO.NavMovesMouse) + { + g.IO.MousePos = g.IO.MousePosPrev = NavCalcPreferredMousePos(); + g.IO.WantMoveMouse = true; + } + g.NavMousePosDirty = false; + } + g.NavIdIsAlive = false; + g.NavTabbedId = 0; + // Navigation windowing mode (change focus, move/resize window) if (!g.NavWindowingTarget && IsNavInputPressed(ImGuiNavInput_PadMenu, ImGuiNavReadMode_Pressed)) {