mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-23 12:27:01 +00:00
Nav: Re-arranged ItemAdd() to maximize early out (#787)
This commit is contained in:
parent
dd0855de5c
commit
878fa96896
67
imgui.cpp
67
imgui.cpp
@ -2182,41 +2182,44 @@ bool ImGui::ItemAdd(const ImRect& bb, const ImGuiID* id, const ImRect* nav_bb_ar
|
|||||||
// We could early out with `if (is_clipped && !g.NavInitDefaultRequest) return false;` but when we wouldn't be able to reach unclipped widgets. This would work if user had explicit scrolling control (e.g. mapped on a stick)
|
// We could early out with `if (is_clipped && !g.NavInitDefaultRequest) return false;` but when we wouldn't be able to reach unclipped widgets. This would work if user had explicit scrolling control (e.g. mapped on a stick)
|
||||||
// A more pragmatic solution for handling long lists is relying on the fact that they are likely evenly spread items (so that clipper can be used) and we could Nav at higher-level (apply index, etc.)
|
// A more pragmatic solution for handling long lists is relying on the fact that they are likely evenly spread items (so that clipper can be used) and we could Nav at higher-level (apply index, etc.)
|
||||||
// So eventually we would like to provide the user will the primitives to be able to implement that customized/efficient navigation handling whenever necessary.
|
// So eventually we would like to provide the user will the primitives to be able to implement that customized/efficient navigation handling whenever necessary.
|
||||||
if (id != NULL && g.IO.NavUsable && g.NavWindow == window->RootNavWindow)
|
if (id != NULL && g.NavWindow == window->RootNavWindow)
|
||||||
{
|
if (g.NavId == *id || g.NavMoveRequest || g.NavInitDefaultRequest)
|
||||||
const ImRect& nav_bb = nav_bb_arg ? *nav_bb_arg : bb;
|
if (g.IO.NavUsable)
|
||||||
const ImRect nav_bb_rel(nav_bb.Min - g.NavWindow->Pos, nav_bb.Max - g.NavWindow->Pos);
|
|
||||||
if (g.NavInitDefaultRequest && g.NavLayer == window->DC.NavLayerCurrent)
|
|
||||||
{
|
|
||||||
if (!(window->DC.ItemFlags & ImGuiItemFlags_NoNavDefaultFocus))
|
|
||||||
// Even if 'ImGuiItemFlags_NoNavDefaultFocus' is on (typically collapse/close button) we record the first ResultId so they can be used as a fallback
|
|
||||||
g.NavInitDefaultRequest = g.NavInitDefaultResultExplicit = false; // Found a match, clear request
|
|
||||||
if (g.NavInitDefaultResultId == 0 || !(window->DC.ItemFlags & ImGuiItemFlags_NoNavDefaultFocus))
|
|
||||||
{
|
{
|
||||||
g.NavInitDefaultResultId = *id;
|
const ImRect& nav_bb = nav_bb_arg ? *nav_bb_arg : bb;
|
||||||
g.NavInitDefaultResultRectRel = nav_bb_rel;
|
const ImRect nav_bb_rel(nav_bb.Min - g.NavWindow->Pos, nav_bb.Max - g.NavWindow->Pos);
|
||||||
}
|
if (g.NavInitDefaultRequest && g.NavLayer == window->DC.NavLayerCurrent)
|
||||||
}
|
{
|
||||||
|
// Even if 'ImGuiItemFlags_NoNavDefaultFocus' is on (typically collapse/close button) we record the first ResultId so they can be used as a fallback
|
||||||
|
const ImGuiItemFlags item_flags = window->DC.ItemFlags;
|
||||||
|
if (!(item_flags & ImGuiItemFlags_NoNavDefaultFocus))
|
||||||
|
g.NavInitDefaultRequest = g.NavInitDefaultResultExplicit = false; // Found a match, clear request
|
||||||
|
if (g.NavInitDefaultResultId == 0 || !(item_flags & ImGuiItemFlags_NoNavDefaultFocus))
|
||||||
|
{
|
||||||
|
g.NavInitDefaultResultId = *id;
|
||||||
|
g.NavInitDefaultResultRectRel = nav_bb_rel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//const bool DEBUG_NAV = false; // [DEBUG] Enable to test scoring on all items.
|
//const bool DEBUG_NAV = false; // [DEBUG] Enable to test scoring on all items.
|
||||||
if ((g.NavMoveRequest /*|| DEBUG_NAV*/) && g.NavId != *id)
|
if ((g.NavMoveRequest /*|| DEBUG_NAV*/) && g.NavId != *id)
|
||||||
{
|
{
|
||||||
//if (DEBUG_NAV && !g.NavMoveRequest) g.NavMoveDir = ImGuiDir_N;
|
//if (DEBUG_NAV && !g.NavMoveRequest) g.NavMoveDir = ImGuiDir_N;
|
||||||
if (NavScoreItem(nav_bb)) //if (!DEBUG || g.NavMoveRequest)
|
if (NavScoreItem(nav_bb)) //if (!DEBUG || g.NavMoveRequest)
|
||||||
{
|
{
|
||||||
g.NavMoveResultId = *id;
|
g.NavMoveResultId = *id;
|
||||||
g.NavMoveResultRectRel = nav_bb_rel;
|
g.NavMoveResultRectRel = nav_bb_rel;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update window-relative bounding box of navigated item
|
// Update window-relative bounding box of navigated item
|
||||||
if (g.NavId == *id)
|
if (g.NavId == *id)
|
||||||
{
|
{
|
||||||
g.NavRefRectRel = nav_bb_rel;
|
g.NavRefRectRel = nav_bb_rel;
|
||||||
g.NavIdIsAlive = true;
|
g.NavIdIsAlive = true;
|
||||||
g.NavIdTabCounter = window->FocusIdxTabCounter;
|
g.NavIdTabCounter = window->FocusIdxTabCounter;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_clipped)
|
if (is_clipped)
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
Reference in New Issue
Block a user