From f2d1472481725d0a89e27be6f2bc0db32a92fccf Mon Sep 17 00:00:00 2001 From: ocornut Date: Sat, 30 Jul 2016 15:17:12 +0200 Subject: [PATCH] Nav: Fixed navigating outside of current scrolling bounds (bug from 0cc20fca831e60b4898cf66e3ac595d8bdebb830) (#323) + spaces --- imgui.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 80bd9ec3..b36ee915 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1920,7 +1920,18 @@ static bool NavScoreItem(ImRect cand) return false; const ImRect& curr = g.NavScoringRectScreen; // Current modified source rect (NB: we've applied Max.x = Min.x in NavUpdate() to inhibit the effect of having lots of items with varied width) - window->ClipRect.Clip(cand); + + // We perform scoring on items bounding box clipped by their parent window on the other axis (clipping on our movement axis would give us equal scores for all clipped items) + if (g.NavMoveDir == ImGuiNavDir_Left || g.NavMoveDir == ImGuiNavDir_Right) + { + cand.Min.y = ImClamp(cand.Min.y, window->ClipRect.Min.y, window->ClipRect.Max.y); + cand.Max.y = ImClamp(cand.Max.y, window->ClipRect.Min.y, window->ClipRect.Max.y); + } + else + { + cand.Min.x = ImClamp(cand.Min.x, window->ClipRect.Min.x, window->ClipRect.Max.x); + cand.Max.x = ImClamp(cand.Max.x, window->ClipRect.Min.x, window->ClipRect.Max.x); + } // Compute distance between boxes // FIXME-NAVIGATION: Introducing various biases toward typical imgui uses cases, but we don't have any rigorous proof of their effect now. @@ -6168,7 +6179,7 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool // Set active id so it can be queried by user via IsItemActive(), etc. but don't react to it ourselves g.NavActivateId = g.NavId; SetActiveID(g.NavId, window); - g.ActiveIdAllowNavDirFlags = (1<