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
27
imgui.cpp
27
imgui.cpp
@ -594,6 +594,8 @@
|
|||||||
#include <stdint.h> // intptr_t
|
#include <stdint.h> // intptr_t
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define IMGUI_DEBUG_NAV 0
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#pragma warning (disable: 4127) // condition expression is constant
|
#pragma warning (disable: 4127) // condition expression is constant
|
||||||
#pragma warning (disable: 4505) // unreferenced local function has been removed (stb stuff)
|
#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;
|
quadrant = (window->DC.LastItemId < g.NavId) ? ImGuiDir_Left : ImGuiDir_Right;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0 // [DEBUG]
|
#if IMGUI_DEBUG_NAV
|
||||||
if (ImGui::IsMouseHoveringRect(cand.Min, cand.Max))
|
if (ImGui::IsMouseHoveringRect(cand.Min, cand.Max))
|
||||||
{
|
{
|
||||||
char buf[128];
|
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.
|
// 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;
|
const ImGuiItemFlags item_flags = window->DC.ItemFlags;
|
||||||
if (id != NULL && g.NavWindow == window->RootNavWindow)
|
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))
|
if (g.IO.NavUsable && !(item_flags & ImGuiItemFlags_NoNav))
|
||||||
{
|
{
|
||||||
const ImRect& nav_bb = nav_bb_arg ? *nav_bb_arg : bb;
|
const ImRect& nav_bb = nav_bb_arg ? *nav_bb_arg : bb;
|
||||||
@ -2201,16 +2203,22 @@ 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.
|
bool new_best = false;
|
||||||
if ((g.NavMoveRequest /*|| DEBUG_NAV*/) && g.NavId != *id)
|
#if IMGUI_DEBUG_NAV
|
||||||
{
|
// [DEBUG] Score items at all times
|
||||||
//if (DEBUG_NAV && !g.NavMoveRequest) g.NavMoveDir = ImGuiDir_N;
|
if (!g.NavMoveRequest)
|
||||||
if (NavScoreItem(nav_bb)) //if (!DEBUG || 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)
|
||||||
{
|
{
|
||||||
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)
|
||||||
@ -2778,7 +2786,10 @@ static void NavUpdate()
|
|||||||
if ((allowed_dir_flags & (1<<ImGuiDir_Down)) && IsNavInputPressed(ImGuiNavInput_PadDown, ImGuiNavReadMode_Repeat)) g.NavMoveDir = ImGuiDir_Down;
|
if ((allowed_dir_flags & (1<<ImGuiDir_Down)) && IsNavInputPressed(ImGuiNavInput_PadDown, ImGuiNavReadMode_Repeat)) g.NavMoveDir = ImGuiDir_Down;
|
||||||
}
|
}
|
||||||
if (g.NavMoveDir != ImGuiDir_None)
|
if (g.NavMoveDir != ImGuiDir_None)
|
||||||
|
{
|
||||||
g.NavMoveRequest = true;
|
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 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)
|
if (g.NavMoveRequest && g.NavId == 0)
|
||||||
|
@ -476,6 +476,7 @@ struct ImGuiContext
|
|||||||
bool NavMoveRequest; // Move request for this frame
|
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
|
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 NavMoveDir; // West/East/North/South
|
||||||
|
ImGuiDir NavMoveDirLast; //
|
||||||
ImGuiID NavMoveResultId; // Best move request candidate
|
ImGuiID NavMoveResultId; // Best move request candidate
|
||||||
float NavMoveResultDistBox; // Best move request candidate box distance to current NavId
|
float NavMoveResultDistBox; // Best move request candidate box distance to current NavId
|
||||||
float NavMoveResultDistCenter; // Best move request candidate center distance to current NavId
|
float NavMoveResultDistCenter; // Best move request candidate center distance to current NavId
|
||||||
@ -583,7 +584,7 @@ struct ImGuiContext
|
|||||||
NavInitDefaultResultId = 0;
|
NavInitDefaultResultId = 0;
|
||||||
NavInitDefaultResultExplicit = false;
|
NavInitDefaultResultExplicit = false;
|
||||||
NavMoveRequest = false;
|
NavMoveRequest = false;
|
||||||
NavMoveDir = ImGuiDir_None;
|
NavMoveDir = NavMoveDirLast = ImGuiDir_None;
|
||||||
NavMoveResultId = 0;
|
NavMoveResultId = 0;
|
||||||
NavMoveResultDistBox = NavMoveResultDistCenter = NavMoveResultDistAxial = 0.0f;
|
NavMoveResultDistBox = NavMoveResultDistCenter = NavMoveResultDistAxial = 0.0f;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user