mirror of
https://github.com/Drezil/imgui.git
synced 2025-07-06 04:58:47 +02:00
Misc: Added an explicit compile-time test for non-scoped IM_ASSERT() macros to redirect users to a solution + fixed our stb wrappers.
+ Nav: Use nav layer enum, comments.
This commit is contained in:
24
imgui.cpp
24
imgui.cpp
@ -6718,6 +6718,14 @@ static void ImGui::ErrorCheckNewFrameSanityChecks()
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
|
||||
// Check user IM_ASSERT macro
|
||||
// (IF YOU GET A WARNING OR COMPILE ERROR HERE: it means you assert macro is incorrectly defined!
|
||||
// If your macro uses multiple statements, it NEEDS to be surrounded by a 'do { ... } while (0)' block.
|
||||
// This is a common C/C++ idiom to allow multiple statements macros to be used in control flow blocks.)
|
||||
// #define IM_ASSERT(EXPR) SomeCode(EXPR); SomeMoreCode(); // Wrong!
|
||||
// #define IM_ASSERT(EXPR) do { SomeCode(EXPR); SomeMoreCode(); } while (0) // Correct!
|
||||
if (true) IM_ASSERT(1); else IM_ASSERT(0);
|
||||
|
||||
// Check user data
|
||||
// (We pass an error message in the assert expression to make it visible to programmers who are not using a debugger, as most assert handlers display their argument)
|
||||
IM_ASSERT(g.Initialized);
|
||||
@ -7631,7 +7639,7 @@ void ImGui::ClosePopupToLevel(int remaining, bool restore_focus_to_window_under_
|
||||
}
|
||||
else
|
||||
{
|
||||
if (g.NavLayer == 0 && focus_window)
|
||||
if (g.NavLayer == ImGuiNavLayer_Main && focus_window)
|
||||
focus_window = NavRestoreLastChildNavWindow(focus_window);
|
||||
FocusWindow(focus_window);
|
||||
}
|
||||
@ -8110,7 +8118,7 @@ static bool ImGui::NavScoreItem(ImGuiNavMoveResult* result, ImRect cand)
|
||||
// 2017/09/29: FIXME: This now currently only enabled inside menu bars, ideally we'd disable it everywhere. Menus in particular need to catch failure. For general navigation it feels awkward.
|
||||
// Disabling it may lead to disconnected graphs when nodes are very spaced out on different axis. Perhaps consider offering this as an option?
|
||||
if (result->DistBox == FLT_MAX && dist_axial < result->DistAxial) // Check axial match
|
||||
if (g.NavLayer == 1 && !(g.NavWindow->Flags & ImGuiWindowFlags_ChildMenu))
|
||||
if (g.NavLayer == ImGuiNavLayer_Menu && !(g.NavWindow->Flags & ImGuiWindowFlags_ChildMenu))
|
||||
if ((g.NavMoveDir == ImGuiDir_Left && dax < 0.0f) || (g.NavMoveDir == ImGuiDir_Right && dax > 0.0f) || (g.NavMoveDir == ImGuiDir_Up && day < 0.0f) || (g.NavMoveDir == ImGuiDir_Down && day > 0.0f))
|
||||
{
|
||||
result->DistAxial = dist_axial;
|
||||
@ -8221,7 +8229,7 @@ void ImGui::NavMoveRequestForward(ImGuiDir move_dir, ImGuiDir clip_dir, const Im
|
||||
void ImGui::NavMoveRequestTryWrapping(ImGuiWindow* window, ImGuiNavMoveFlags move_flags)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
if (g.NavWindow != window || !NavMoveRequestButNoResultYet() || g.NavMoveRequestForward != ImGuiNavForward_None || g.NavLayer != 0)
|
||||
if (g.NavWindow != window || !NavMoveRequestButNoResultYet() || g.NavMoveRequestForward != ImGuiNavForward_None || g.NavLayer != ImGuiNavLayer_Main)
|
||||
return;
|
||||
IM_ASSERT(move_flags != 0); // No points calling this with no wrapping
|
||||
ImRect bb_rel = window->NavRectRel[0];
|
||||
@ -8466,7 +8474,7 @@ static void ImGui::NavUpdate()
|
||||
// Store our return window (for returning from Layer 1 to Layer 0) and clear it as soon as we step back in our own Layer 0
|
||||
if (g.NavWindow)
|
||||
NavSaveLastChildNavWindowIntoParent(g.NavWindow);
|
||||
if (g.NavWindow && g.NavWindow->NavLastChildNavWindow != NULL && g.NavLayer == 0)
|
||||
if (g.NavWindow && g.NavWindow->NavLastChildNavWindow != NULL && g.NavLayer == ImGuiNavLayer_Main)
|
||||
g.NavWindow->NavLastChildNavWindow = NULL;
|
||||
|
||||
// Update CTRL+TAB and Windowing features (hold Square to move/resize/etc.)
|
||||
@ -8503,7 +8511,7 @@ static void ImGui::NavUpdate()
|
||||
if (!(g.OpenPopupStack.back().Window->Flags & ImGuiWindowFlags_Modal))
|
||||
ClosePopupToLevel(g.OpenPopupStack.Size - 1, true);
|
||||
}
|
||||
else if (g.NavLayer != 0)
|
||||
else if (g.NavLayer != ImGuiNavLayer_Main)
|
||||
{
|
||||
// Leave the "menu" layer
|
||||
NavRestoreLayer(ImGuiNavLayer_Main);
|
||||
@ -8625,7 +8633,7 @@ static void ImGui::NavUpdate()
|
||||
g.NavMoveResultOther.Clear();
|
||||
|
||||
// When we have manually scrolled (without using navigation) and NavId becomes out of bounds, we project its bounding box to the visible area to restart navigation within visible items
|
||||
if (g.NavMoveRequest && g.NavMoveFromClampedRefRect && g.NavLayer == 0)
|
||||
if (g.NavMoveRequest && g.NavMoveFromClampedRefRect && g.NavLayer == ImGuiNavLayer_Main)
|
||||
{
|
||||
ImGuiWindow* window = g.NavWindow;
|
||||
ImRect window_rect_rel(window->InnerRect.Min - window->Pos - ImVec2(1,1), window->InnerRect.Max - window->Pos + ImVec2(1,1));
|
||||
@ -8688,7 +8696,7 @@ static void ImGui::NavUpdateMoveResult()
|
||||
IM_ASSERT(g.NavWindow && result->Window);
|
||||
|
||||
// Scroll to keep newly navigated item fully into view.
|
||||
if (g.NavLayer == 0)
|
||||
if (g.NavLayer == ImGuiNavLayer_Main)
|
||||
{
|
||||
ImVec2 delta_scroll;
|
||||
if (g.NavMoveRequestFlags & ImGuiNavMoveFlags_ScrollToEdge)
|
||||
@ -8727,7 +8735,7 @@ static float ImGui::NavUpdatePageUpPageDown()
|
||||
ImGuiContext& g = *GImGui;
|
||||
if (g.NavMoveDir != ImGuiDir_None || g.NavWindow == NULL)
|
||||
return 0.0f;
|
||||
if ((g.NavWindow->Flags & ImGuiWindowFlags_NoNavInputs) || g.NavWindowingTarget != NULL || g.NavLayer != 0)
|
||||
if ((g.NavWindow->Flags & ImGuiWindowFlags_NoNavInputs) || g.NavWindowingTarget != NULL || g.NavLayer != ImGuiNavLayer_Main)
|
||||
return 0.0f;
|
||||
|
||||
ImGuiWindow* window = g.NavWindow;
|
||||
|
Reference in New Issue
Block a user