mirror of
https://github.com/Drezil/imgui.git
synced 2025-01-11 16:26:35 +00:00
Nav: Commiting some better organized Debug helper because this going to stay for a bit.
This commit is contained in:
parent
1f7f54e196
commit
30b1d85962
31
imgui.cpp
31
imgui.cpp
@ -594,6 +594,8 @@
|
||||
#include <stdint.h> // intptr_t
|
||||
#endif
|
||||
|
||||
#define IMGUI_DEBUG_NAV 0
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning (disable: 4127) // condition expression is constant
|
||||
#pragma warning (disable: 4505) // unreferenced local function has been removed (stb stuff)
|
||||
@ -2091,7 +2093,7 @@ static bool NavScoreItem(ImRect cand)
|
||||
quadrant = (window->DC.LastItemId < g.NavId) ? ImGuiDir_Left : ImGuiDir_Right;
|
||||
}
|
||||
|
||||
#if 0 // [DEBUG]
|
||||
#if IMGUI_DEBUG_NAV
|
||||
if (ImGui::IsMouseHoveringRect(cand.Min, cand.Max))
|
||||
{
|
||||
char buf[128];
|
||||
@ -2184,7 +2186,7 @@ bool ImGui::ItemAdd(const ImRect& bb, const ImGuiID* id, const ImRect* nav_bb_ar
|
||||
// So eventually we would like to provide the user will the primitives to be able to implement that customized/efficient navigation handling whenever necessary.
|
||||
const ImGuiItemFlags item_flags = window->DC.ItemFlags;
|
||||
if (id != NULL && g.NavWindow == window->RootNavWindow)
|
||||
if (g.NavId == *id || g.NavMoveRequest || g.NavInitDefaultRequest)
|
||||
if (g.NavId == *id || g.NavMoveRequest || g.NavInitDefaultRequest || IMGUI_DEBUG_NAV)
|
||||
if (g.IO.NavUsable && !(item_flags & ImGuiItemFlags_NoNav))
|
||||
{
|
||||
const ImRect& nav_bb = nav_bb_arg ? *nav_bb_arg : bb;
|
||||
@ -2201,15 +2203,21 @@ bool ImGui::ItemAdd(const ImRect& bb, const ImGuiID* id, const ImRect* nav_bb_ar
|
||||
}
|
||||
}
|
||||
|
||||
//const bool DEBUG_NAV = false; // [DEBUG] Enable to test scoring on all items.
|
||||
if ((g.NavMoveRequest /*|| DEBUG_NAV*/) && g.NavId != *id)
|
||||
bool new_best = false;
|
||||
#if IMGUI_DEBUG_NAV
|
||||
// [DEBUG] Score items at all times
|
||||
if (!g.NavMoveRequest)
|
||||
g.NavMoveDir = g.NavMoveDirLast;
|
||||
if (g.NavId != *id)
|
||||
new_best = NavScoreItem(nav_bb) && g.NavMoveRequest;
|
||||
#else
|
||||
if (g.NavMoveRequest && g.NavId != *id)
|
||||
new_best = NavScoreItem(nav_bb);
|
||||
#endif
|
||||
if (new_best)
|
||||
{
|
||||
//if (DEBUG_NAV && !g.NavMoveRequest) g.NavMoveDir = ImGuiDir_N;
|
||||
if (NavScoreItem(nav_bb)) //if (!DEBUG || g.NavMoveRequest)
|
||||
{
|
||||
g.NavMoveResultId = *id;
|
||||
g.NavMoveResultRectRel = nav_bb_rel;
|
||||
}
|
||||
g.NavMoveResultId = *id;
|
||||
g.NavMoveResultRectRel = nav_bb_rel;
|
||||
}
|
||||
|
||||
// Update window-relative bounding box of navigated item
|
||||
@ -2778,7 +2786,10 @@ static void NavUpdate()
|
||||
if ((allowed_dir_flags & (1<<ImGuiDir_Down)) && IsNavInputPressed(ImGuiNavInput_PadDown, ImGuiNavReadMode_Repeat)) g.NavMoveDir = ImGuiDir_Down;
|
||||
}
|
||||
if (g.NavMoveDir != ImGuiDir_None)
|
||||
{
|
||||
g.NavMoveRequest = true;
|
||||
g.NavMoveDirLast = g.NavMoveDir;
|
||||
}
|
||||
|
||||
// If we initiate a movement request and have no current NavId, we initiate a InitDefautRequest that will be used as a fallback if the direction fails to find a match
|
||||
if (g.NavMoveRequest && g.NavId == 0)
|
||||
|
@ -476,6 +476,7 @@ struct ImGuiContext
|
||||
bool NavMoveRequest; // Move request for this frame
|
||||
bool NavMoveFromClampedRefRect; // Set by manual scrolling, if we scroll to a point where NavId isn't visible we reset navigation from visible items
|
||||
ImGuiDir NavMoveDir; // West/East/North/South
|
||||
ImGuiDir NavMoveDirLast; //
|
||||
ImGuiID NavMoveResultId; // Best move request candidate
|
||||
float NavMoveResultDistBox; // Best move request candidate box distance to current NavId
|
||||
float NavMoveResultDistCenter; // Best move request candidate center distance to current NavId
|
||||
@ -583,7 +584,7 @@ struct ImGuiContext
|
||||
NavInitDefaultResultId = 0;
|
||||
NavInitDefaultResultExplicit = false;
|
||||
NavMoveRequest = false;
|
||||
NavMoveDir = ImGuiDir_None;
|
||||
NavMoveDir = NavMoveDirLast = ImGuiDir_None;
|
||||
NavMoveResultId = 0;
|
||||
NavMoveResultDistBox = NavMoveResultDistCenter = NavMoveResultDistAxial = 0.0f;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user