Nav: When entering into a NavFlattened child we only consider the visible items for scoring (note that this only work assuming the NavFlattened child window has interactive items). Fixes accidentally hoping into a NavFlattened child. (#767)
diff --git a/TODO.txt b/TODO.txt
index 904e661..4fe013c 100644
--- a/TODO.txt
+++ b/TODO.txt
@@ -253,8 +253,7 @@
- nav: allow input system to be be more tolerant of io.DeltaTime=0.0f
- nav: ESC within a menu of a child window seems to exit the child window.
- nav: ESC on a flattened child
- - nav: NavFlattened: broken: in typical usage scenario, the items of a fully clipped child wouldn't be considered to enter into a NavFlattened child.
- - nav: NavFlattened: broken: can accidentally enter a NavFlattened child as child items are scored outside of child visible bounds.
+ - nav: NavFlattened: broken: in typical usage scenario, the items of a fully clipped child are currently not considered to enter into a NavFlattened child.
- nav: NavFlattened: init request doesn't select items that are part of a NavFlattened child
- nav: Left within a tree node block as a fallback (ImGuiTreeNodeFlags_NavLeftJumpsBackHere by default?)
- nav: menus: pressing left-right on a vertically clipped menu bar tends to jump to the collapse/close buttons.
diff --git a/imgui.cpp b/imgui.cpp
index 65dd64b..c6df640 100644
--- a/imgui.cpp
+++ b/imgui.cpp
@@ -2341,6 +2341,15 @@
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 varied item width)
g.NavScoringCount++;
+ if (window != g.NavWindow)
+ {
+ // When crossing through a NavFlattened border, we score items on the other windows fully clipped
+ IM_ASSERT((window->Flags | g.NavWindow->Flags) & ImGuiWindowFlags_NavFlattened);
+ if (!window->ClipRect.Contains(cand))
+ return false;
+ cand.ClipWithFull(window->ClipRect); // This allows the scored item to not overlap other candidates in the parent window
+ }
+
// We perform scoring on items bounding box clipped by the current clipping rectangle on the other axis (clipping on our movement axis would give us equal scores for all clipped items)
// For example, this ensure that items in one column are not reached when moving vertically from items in another column.
NavClampRectToVisibleAreaForMoveDir(g.NavMoveClipDir, cand, window->ClipRect);