mirror of
https://github.com/ocornut/imgui.git
synced 2024-12-03 03:37:24 +01:00
Nav: removed parameters from NavScoreItem(), NavProcessItem(), NavApplyItemToResult(): made little sense / misleading because pulling from other current state anyway.
Will readd in a more thorough manner is actually needed.
This commit is contained in:
parent
a735a8c084
commit
73a5e82e04
41
imgui.cpp
41
imgui.cpp
@ -916,9 +916,9 @@ static void NavUpdateCreateMoveRequest();
|
|||||||
static float NavUpdatePageUpPageDown();
|
static float NavUpdatePageUpPageDown();
|
||||||
static inline void NavUpdateAnyRequestFlag();
|
static inline void NavUpdateAnyRequestFlag();
|
||||||
static void NavEndFrame();
|
static void NavEndFrame();
|
||||||
static bool NavScoreItem(ImGuiNavItemData* result, ImRect cand);
|
static bool NavScoreItem(ImGuiNavItemData* result);
|
||||||
static void NavApplyItemToResult(ImGuiNavItemData* result, ImGuiWindow* window, ImGuiID id, const ImRect& nav_bb);
|
static void NavApplyItemToResult(ImGuiNavItemData* result);
|
||||||
static void NavProcessItem(ImGuiWindow* window, ImGuiID id, const ImRect& nav_bb);
|
static void NavProcessItem();
|
||||||
static ImVec2 NavCalcPreferredRefPos();
|
static ImVec2 NavCalcPreferredRefPos();
|
||||||
static void NavSaveLastChildNavWindowIntoParent(ImGuiWindow* nav_window);
|
static void NavSaveLastChildNavWindowIntoParent(ImGuiWindow* nav_window);
|
||||||
static ImGuiWindow* NavRestoreLastChildNavWindow(ImGuiWindow* window);
|
static ImGuiWindow* NavRestoreLastChildNavWindow(ImGuiWindow* window);
|
||||||
@ -7518,7 +7518,7 @@ bool ImGui::ItemAdd(const ImRect& bb, ImGuiID id, const ImRect* nav_bb_arg, ImGu
|
|||||||
if (g.NavId == id || g.NavAnyRequest)
|
if (g.NavId == id || g.NavAnyRequest)
|
||||||
if (g.NavWindow->RootWindowForNav == window->RootWindowForNav)
|
if (g.NavWindow->RootWindowForNav == window->RootWindowForNav)
|
||||||
if (window == g.NavWindow || ((window->Flags | g.NavWindow->Flags) & ImGuiWindowFlags_NavFlattened))
|
if (window == g.NavWindow || ((window->Flags | g.NavWindow->Flags) & ImGuiWindowFlags_NavFlattened))
|
||||||
NavProcessItem(window, id, g.LastItemData.NavRect);
|
NavProcessItem();
|
||||||
|
|
||||||
// [DEBUG] Item Picker tool, when enabling the "extended" version we perform the check in ItemAdd()
|
// [DEBUG] Item Picker tool, when enabling the "extended" version we perform the check in ItemAdd()
|
||||||
#ifdef IMGUI_DEBUG_TOOL_ITEM_PICKER_EX
|
#ifdef IMGUI_DEBUG_TOOL_ITEM_PICKER_EX
|
||||||
@ -8742,7 +8742,7 @@ static void inline NavClampRectToVisibleAreaForMoveDir(ImGuiDir move_dir, ImRect
|
|||||||
r.Min.y = ImClamp(r.Min.y, clip_rect.Min.y, clip_rect.Max.y);
|
r.Min.y = ImClamp(r.Min.y, clip_rect.Min.y, clip_rect.Max.y);
|
||||||
r.Max.y = ImClamp(r.Max.y, clip_rect.Min.y, clip_rect.Max.y);
|
r.Max.y = ImClamp(r.Max.y, clip_rect.Min.y, clip_rect.Max.y);
|
||||||
}
|
}
|
||||||
else
|
else // FIXME: PageUp/PageDown are leaving move_dir == None
|
||||||
{
|
{
|
||||||
r.Min.x = ImClamp(r.Min.x, clip_rect.Min.x, clip_rect.Max.x);
|
r.Min.x = ImClamp(r.Min.x, clip_rect.Min.x, clip_rect.Max.x);
|
||||||
r.Max.x = ImClamp(r.Max.x, clip_rect.Min.x, clip_rect.Max.x);
|
r.Max.x = ImClamp(r.Max.x, clip_rect.Min.x, clip_rect.Max.x);
|
||||||
@ -8750,14 +8750,16 @@ static void inline NavClampRectToVisibleAreaForMoveDir(ImGuiDir move_dir, ImRect
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Scoring function for gamepad/keyboard directional navigation. Based on https://gist.github.com/rygorous/6981057
|
// Scoring function for gamepad/keyboard directional navigation. Based on https://gist.github.com/rygorous/6981057
|
||||||
static bool ImGui::NavScoreItem(ImGuiNavItemData* result, ImRect cand)
|
static bool ImGui::NavScoreItem(ImGuiNavItemData* result)
|
||||||
{
|
{
|
||||||
ImGuiContext& g = *GImGui;
|
ImGuiContext& g = *GImGui;
|
||||||
ImGuiWindow* window = g.CurrentWindow;
|
ImGuiWindow* window = g.CurrentWindow;
|
||||||
if (g.NavLayer != window->DC.NavLayerCurrent)
|
if (g.NavLayer != window->DC.NavLayerCurrent)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const ImRect curr = g.NavScoringRect; // Current modified source rect (NB: we've applied Max.x = Min.x in NavUpdate() to inhibit the effect of having varied item width)
|
// FIXME: Those are not good variables names
|
||||||
|
ImRect cand = g.LastItemData.NavRect; // Current item nav rectangle
|
||||||
|
const ImRect curr = g.NavScoringRect; // 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++;
|
g.NavScoringCount++;
|
||||||
|
|
||||||
// When entering through a NavFlattened border, we consider child window items as fully clipped for scoring
|
// When entering through a NavFlattened border, we consider child window items as fully clipped for scoring
|
||||||
@ -8820,7 +8822,7 @@ static bool ImGui::NavScoreItem(ImGuiNavItemData* result, ImRect cand)
|
|||||||
draw_list->AddRect(curr.Min, curr.Max, IM_COL32(255,200,0,100));
|
draw_list->AddRect(curr.Min, curr.Max, IM_COL32(255,200,0,100));
|
||||||
draw_list->AddRect(cand.Min, cand.Max, IM_COL32(255,255,0,200));
|
draw_list->AddRect(cand.Min, cand.Max, IM_COL32(255,255,0,200));
|
||||||
draw_list->AddRectFilled(cand.Max - ImVec2(4, 4), cand.Max + CalcTextSize(buf) + ImVec2(4, 4), IM_COL32(40,0,0,150));
|
draw_list->AddRectFilled(cand.Max - ImVec2(4, 4), cand.Max + CalcTextSize(buf) + ImVec2(4, 4), IM_COL32(40,0,0,150));
|
||||||
draw_list->AddText(g.IO.FontDefault, 13.0f, cand.Max, ~0U, buf);
|
draw_list->AddText(cand.Max, ~0U, buf);
|
||||||
}
|
}
|
||||||
else if (g.IO.KeyCtrl) // Hold to preview score in matching quadrant. Press C to rotate.
|
else if (g.IO.KeyCtrl) // Hold to preview score in matching quadrant. Press C to rotate.
|
||||||
{
|
{
|
||||||
@ -8829,7 +8831,7 @@ static bool ImGui::NavScoreItem(ImGuiNavItemData* result, ImRect cand)
|
|||||||
ImFormatString(buf, IM_ARRAYSIZE(buf), "%.0f/%.0f", dist_box, dist_center);
|
ImFormatString(buf, IM_ARRAYSIZE(buf), "%.0f/%.0f", dist_box, dist_center);
|
||||||
ImDrawList* draw_list = GetForegroundDrawList(window);
|
ImDrawList* draw_list = GetForegroundDrawList(window);
|
||||||
draw_list->AddRectFilled(cand.Min, cand.Max, IM_COL32(255, 0, 0, 200));
|
draw_list->AddRectFilled(cand.Min, cand.Max, IM_COL32(255, 0, 0, 200));
|
||||||
draw_list->AddText(g.IO.FontDefault, 13.0f, cand.Min, IM_COL32(255, 255, 255, 255), buf);
|
draw_list->AddText(cand.Min, IM_COL32(255, 255, 255, 255), buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -8881,21 +8883,24 @@ static bool ImGui::NavScoreItem(ImGuiNavItemData* result, ImRect cand)
|
|||||||
return new_best;
|
return new_best;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ImGui::NavApplyItemToResult(ImGuiNavItemData* result, ImGuiWindow* window, ImGuiID id, const ImRect& nav_bb)
|
static void ImGui::NavApplyItemToResult(ImGuiNavItemData* result)
|
||||||
{
|
{
|
||||||
ImGuiContext& g = *GImGui;
|
ImGuiContext& g = *GImGui;
|
||||||
IM_ASSERT(g.LastItemData.ID == id); // Otherwise pulling from window->DC wouldn't be right
|
ImGuiWindow* window = g.CurrentWindow;
|
||||||
result->Window = window;
|
result->Window = window;
|
||||||
result->ID = id;
|
result->ID = g.LastItemData.ID;
|
||||||
result->FocusScopeId = window->DC.NavFocusScopeIdCurrent;
|
result->FocusScopeId = window->DC.NavFocusScopeIdCurrent;
|
||||||
result->RectRel = ImRect(nav_bb.Min - window->Pos, nav_bb.Max - window->Pos);
|
result->RectRel = ImRect(g.LastItemData.NavRect.Min - window->Pos, g.LastItemData.NavRect.Max - window->Pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
// We get there when either NavId == id, or when g.NavAnyRequest is set (which is updated by NavUpdateAnyRequestFlag above)
|
// We get there when either NavId == id, or when g.NavAnyRequest is set (which is updated by NavUpdateAnyRequestFlag above)
|
||||||
// This is called after LastItemData is set.
|
// This is called after LastItemData is set.
|
||||||
static void ImGui::NavProcessItem(ImGuiWindow* window, ImGuiID id, const ImRect& nav_bb)
|
static void ImGui::NavProcessItem()
|
||||||
{
|
{
|
||||||
ImGuiContext& g = *GImGui;
|
ImGuiContext& g = *GImGui;
|
||||||
|
ImGuiWindow* window = g.CurrentWindow;
|
||||||
|
const ImGuiID id = g.LastItemData.ID;
|
||||||
|
const ImRect nav_bb = g.LastItemData.NavRect;
|
||||||
const ImGuiItemFlags item_flags = g.LastItemData.InFlags;
|
const ImGuiItemFlags item_flags = g.LastItemData.InFlags;
|
||||||
|
|
||||||
// Process Init Request
|
// Process Init Request
|
||||||
@ -8922,7 +8927,7 @@ static void ImGui::NavProcessItem(ImGuiWindow* window, ImGuiID id, const ImRect&
|
|||||||
if ((g.NavId != id || (g.NavMoveFlags & ImGuiNavMoveFlags_AllowCurrentNavId)) && !(item_flags & (ImGuiItemFlags_Disabled | ImGuiItemFlags_NoNav)))
|
if ((g.NavId != id || (g.NavMoveFlags & ImGuiNavMoveFlags_AllowCurrentNavId)) && !(item_flags & (ImGuiItemFlags_Disabled | ImGuiItemFlags_NoNav)))
|
||||||
{
|
{
|
||||||
ImGuiNavItemData* result = (window == g.NavWindow) ? &g.NavMoveResultLocal : &g.NavMoveResultOther;
|
ImGuiNavItemData* result = (window == g.NavWindow) ? &g.NavMoveResultLocal : &g.NavMoveResultOther;
|
||||||
bool new_best = NavScoreItem(result, nav_bb);
|
bool new_best = NavScoreItem(result);
|
||||||
|
|
||||||
#if IMGUI_DEBUG_NAV_SCORING
|
#if IMGUI_DEBUG_NAV_SCORING
|
||||||
// [DEBUG] Scoring all items in NavWindow at all times
|
// [DEBUG] Scoring all items in NavWindow at all times
|
||||||
@ -8930,14 +8935,14 @@ static void ImGui::NavProcessItem(ImGuiWindow* window, ImGuiID id, const ImRect&
|
|||||||
new_best = false;
|
new_best = false;
|
||||||
#endif
|
#endif
|
||||||
if (new_best)
|
if (new_best)
|
||||||
NavApplyItemToResult(result, window, id, nav_bb);
|
NavApplyItemToResult(result);
|
||||||
|
|
||||||
// Features like PageUp/PageDown need to maintain a separate score for the visible set of items.
|
// Features like PageUp/PageDown need to maintain a separate score for the visible set of items.
|
||||||
const float VISIBLE_RATIO = 0.70f;
|
const float VISIBLE_RATIO = 0.70f;
|
||||||
if ((g.NavMoveFlags & ImGuiNavMoveFlags_AlsoScoreVisibleSet) && window->ClipRect.Overlaps(nav_bb))
|
if ((g.NavMoveFlags & ImGuiNavMoveFlags_AlsoScoreVisibleSet) && window->ClipRect.Overlaps(nav_bb))
|
||||||
if (ImClamp(nav_bb.Max.y, window->ClipRect.Min.y, window->ClipRect.Max.y) - ImClamp(nav_bb.Min.y, window->ClipRect.Min.y, window->ClipRect.Max.y) >= (nav_bb.Max.y - nav_bb.Min.y) * VISIBLE_RATIO)
|
if (ImClamp(nav_bb.Max.y, window->ClipRect.Min.y, window->ClipRect.Max.y) - ImClamp(nav_bb.Min.y, window->ClipRect.Min.y, window->ClipRect.Max.y) >= (nav_bb.Max.y - nav_bb.Min.y) * VISIBLE_RATIO)
|
||||||
if (NavScoreItem(&g.NavMoveResultLocalVisible, nav_bb))
|
if (NavScoreItem(&g.NavMoveResultLocalVisible))
|
||||||
NavApplyItemToResult(&g.NavMoveResultLocalVisible, window, id, nav_bb);
|
NavApplyItemToResult(&g.NavMoveResultLocalVisible);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1851,7 +1851,7 @@ struct IMGUI_API ImGuiWindowTempData
|
|||||||
int CurrentTableIdx; // Current table index (into g.Tables)
|
int CurrentTableIdx; // Current table index (into g.Tables)
|
||||||
ImGuiLayoutType LayoutType;
|
ImGuiLayoutType LayoutType;
|
||||||
ImGuiLayoutType ParentLayoutType; // Layout type of parent window at the time of Begin()
|
ImGuiLayoutType ParentLayoutType; // Layout type of parent window at the time of Begin()
|
||||||
int FocusCounterRegular; // (Legacy Focus/Tabbing system) Sequential counter, start at -1 and increase as assigned via FocusableItemRegister() (FIXME-NAV: Needs redesign)
|
int FocusCounterRegular; // (Legacy Focus/Tabbing system) Sequential counter, start at -1 and increase as assigned via ImGuiItemAddFlags_Focusable (FIXME-NAV: Needs redesign)
|
||||||
int FocusCounterTabStop; // (Legacy Focus/Tabbing system) Same, but only count widgets which you can Tab through.
|
int FocusCounterTabStop; // (Legacy Focus/Tabbing system) Same, but only count widgets which you can Tab through.
|
||||||
|
|
||||||
// Local parameters stacks
|
// Local parameters stacks
|
||||||
|
Loading…
Reference in New Issue
Block a user