From 30b1d85962814ce3d127e17dcc697dafba45fd10 Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 28 Sep 2017 23:48:30 +0200 Subject: [PATCH] Nav: Commiting some better organized Debug helper because this going to stay for a bit. --- imgui.cpp | 31 +++++++++++++++++++++---------- imgui_internal.h | 3 ++- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index dada4887..fa632ee6 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -594,6 +594,8 @@ #include // 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<