From a61438740d6b4fcc543966d38182f04f24c51f67 Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 2 Oct 2023 15:01:42 +0200 Subject: [PATCH] Debug Tools: Metrics: Added "Show groups rectangles" in tools. --- docs/CHANGELOG.txt | 3 ++- imgui.cpp | 7 +++++-- imgui_internal.h | 2 ++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 28aad3d22feb..33fff5f062c9 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -105,7 +105,8 @@ Other changes: Was most often noticable when using an horizontal scrollbar. (#6789) - Misc: Most text functions also treat "%.*s" (along with "%s") specially to avoid formatting. (#3466, #6846) - IO: Setting io.WantSetMousePos ignores incoming MousePos events. (#6837, #228) [@bertaye] -- Debug Tools: Metrics: Added log recent alloc/free calls. +- Debug Tools: Metrics: Added log of recent alloc/free calls. +- Debug Tools: Metrics: Added "Show groups rectangles" in tools. - ImDrawList: Added AddEllipse(), AddEllipseFilled(), PathEllipticalArcTo(). (#2743) [@Doohl] - ImVector: Added find_index() helper. - Backends: GLFW: Clear emscripten's MouseWheel callback before shutdown. (#6790, #6096, #4019) [@halx99] diff --git a/imgui.cpp b/imgui.cpp index 2e9dd97d695d..c65df0b1d8b3 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -9954,7 +9954,8 @@ void ImGui::EndGroup() g.LastItemData.StatusFlags |= ImGuiItemStatusFlags_Deactivated; g.GroupStack.pop_back(); - //window->DrawList->AddRect(group_bb.Min, group_bb.Max, IM_COL32(255,0,255,255)); // [Debug] + if (g.DebugShowGroupRects) + window->DrawList->AddRect(group_bb.Min, group_bb.Max, IM_COL32(255,0,255,255)); // [Debug] } @@ -13888,6 +13889,7 @@ void ImGui::ShowMetricsWindow(bool* p_open) Unindent(); } } + Checkbox("Show groups rectangles", &g.DebugShowGroupRects); // Storing in context as this is used by group code and prefers to be in hot-data Checkbox("Debug Begin/BeginChild return value", &io.ConfigDebugBeginReturnValueLoop); SameLine(); @@ -14064,11 +14066,12 @@ void ImGui::ShowMetricsWindow(bool* p_open) { ImGuiDebugAllocInfo* info = &g.DebugAllocInfo; Text("%d current allocations", info->TotalAllocCount - info->TotalFreeCount); + Text("Recent frames with allocations:"); int buf_size = IM_ARRAYSIZE(info->LastEntriesBuf); for (int n = buf_size - 1; n >= 0; n--) { ImGuiDebugAllocEntry* entry = &info->LastEntriesBuf[(info->LastEntriesIdx - n + buf_size) % buf_size]; - BulletText("Frame %06d: %+3d ( %2d malloc, %2d free )", entry->FrameCount, entry->AllocCount - entry->FreeCount, entry->AllocCount, entry->FreeCount); + BulletText("Frame %06d: %+3d ( %2d malloc, %2d free )%s", entry->FrameCount, entry->AllocCount - entry->FreeCount, entry->AllocCount, entry->FreeCount, (n == 0) ? " (most recent)" : ""); } TreePop(); } diff --git a/imgui_internal.h b/imgui_internal.h index 73b3f2ed600d..4e6403535a9f 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1953,6 +1953,7 @@ struct ImGuiContext ImGuiNextItemData NextItemData; // Storage for SetNextItem** functions ImGuiLastItemData LastItemData; // Storage for last submitted item (setup by ItemAdd) ImGuiNextWindowData NextWindowData; // Storage for SetNextWindow** functions + bool DebugShowGroupRects; // Shared stacks ImVector ColorStack; // Stack for PushStyleColor()/PopStyleColor() - inherited by Begin() @@ -2225,6 +2226,7 @@ struct ImGuiContext CurrentFocusScopeId = 0; CurrentItemFlags = ImGuiItemFlags_None; + DebugShowGroupRects = false; BeginMenuCount = 0; NavWindow = NULL;