mirror of
https://github.com/ocornut/imgui.git
synced 2025-12-17 20:05:40 +00:00
Debug Tools: ID Stack Tool: extracted code into a StackToolGetResultAsPath() function.
This commit is contained in:
60
imgui.cpp
60
imgui.cpp
@@ -17900,19 +17900,44 @@ static int StackToolFormatLevelInfo(ImGuiIDStackTool* tool, int n, bool format_f
|
||||
{
|
||||
ImGuiStackLevelInfo* info = &tool->Results[n];
|
||||
ImGuiWindow* window = (info->DescOffset == -1 && n == 0) ? ImGui::FindWindowByID(info->ID) : NULL;
|
||||
if (window) // Source: window name (because the root ID don't call GetID() and so doesn't get hooked)
|
||||
if (window) // Source: window name (because the root ID don't call GetID() and so doesn't get hooked)
|
||||
return ImFormatString(buf, buf_size, format_for_ui ? "\"%s\" [window]" : "%s", ImHashSkipUncontributingPrefix(window->Name));
|
||||
if (info->QuerySuccess) // Source: GetID() hooks (prioritize over ItemInfo() because we frequently use patterns like: PushID(str), Button("") where they both have same id)
|
||||
if (info->QuerySuccess) // Source: GetID() hooks (prioritize over ItemInfo() because we frequently use patterns like: PushID(str), Button("") where they both have same id)
|
||||
return ImFormatString(buf, buf_size, (format_for_ui && info->DataType == ImGuiDataType_String) ? "\"%s\"" : "%s", ImHashSkipUncontributingPrefix(&tool->ResultPathsBuf.Buf[info->DescOffset]));
|
||||
if (tool->StackLevel < tool->Results.Size) // Only start using fallback below when all queries are done, so during queries we don't flickering ??? markers.
|
||||
if (tool->StackLevel < tool->Results.Size) // Only start using fallback below when all queries are done, so during queries we don't flickering ??? markers.
|
||||
return (*buf = 0);
|
||||
#ifdef IMGUI_ENABLE_TEST_ENGINE
|
||||
if (const char* label = ImGuiTestEngine_FindItemDebugLabel(GImGui, info->ID)) // Source: ImGuiTestEngine's ItemInfo()
|
||||
if (const char* label = ImGuiTestEngine_FindItemDebugLabel(GImGui, info->ID)) // Source: ImGuiTestEngine's ItemInfo()
|
||||
return ImFormatString(buf, buf_size, format_for_ui ? "??? \"%s\"" : "%s", ImHashSkipUncontributingPrefix(label));
|
||||
#endif
|
||||
return ImFormatString(buf, buf_size, "???");
|
||||
}
|
||||
|
||||
static const char* StackToolGetResultAsPath(ImGuiIDStackTool* tool, bool hex_encode_non_ascii_chars)
|
||||
{
|
||||
ImGuiTextBuffer* buf = &tool->ResultFullPathBuf;
|
||||
buf->resize(0);
|
||||
for (int stack_n = 0; stack_n < tool->Results.Size; stack_n++)
|
||||
{
|
||||
char level_desc[256];
|
||||
StackToolFormatLevelInfo(tool, stack_n, false, level_desc, IM_ARRAYSIZE(level_desc));
|
||||
buf->append(stack_n == 0 ? "//" : "/");
|
||||
for (const char* p = level_desc; *p != 0; )
|
||||
{
|
||||
unsigned int c;
|
||||
const char* p_next = p + ImTextCharFromUtf8(&c, p, NULL);
|
||||
if (c == '/')
|
||||
buf->append("\\");
|
||||
if (c < 256 || !hex_encode_non_ascii_chars)
|
||||
buf->append(p, p_next);
|
||||
else for (; p < p_next; p++)
|
||||
buf->appendf("\\x%02x", (unsigned char)*p);
|
||||
p = p_next;
|
||||
}
|
||||
}
|
||||
return buf->c_str();
|
||||
}
|
||||
|
||||
// ID Stack Tool: Display UI
|
||||
void ImGui::ShowIDStackToolWindow(bool* p_open)
|
||||
{
|
||||
@@ -17927,27 +17952,7 @@ void ImGui::ShowIDStackToolWindow(bool* p_open)
|
||||
|
||||
// Display hovered/active status
|
||||
ImGuiIDStackTool* tool = &g.DebugIDStackTool;
|
||||
|
||||
// Build and display path
|
||||
tool->ResultTempBuf.resize(0);
|
||||
for (int stack_n = 0; stack_n < tool->Results.Size; stack_n++)
|
||||
{
|
||||
char level_desc[256];
|
||||
StackToolFormatLevelInfo(tool, stack_n, false, level_desc, IM_ARRAYSIZE(level_desc));
|
||||
tool->ResultTempBuf.append(stack_n == 0 ? "//" : "/");
|
||||
for (const char* p = level_desc; *p != 0; )
|
||||
{
|
||||
unsigned int c;
|
||||
const char* p_next = p + ImTextCharFromUtf8(&c, p, NULL);
|
||||
if (c == '/')
|
||||
tool->ResultTempBuf.append("\\");
|
||||
if (c < 256 || !tool->OptHexEncodeNonAsciiChars)
|
||||
tool->ResultTempBuf.append(p, p_next);
|
||||
else for (; p < p_next; p++)
|
||||
tool->ResultTempBuf.appendf("\\x%02x", (unsigned char)*p);
|
||||
p = p_next;
|
||||
}
|
||||
}
|
||||
const char* result_path = StackToolGetResultAsPath(tool, tool->OptHexEncodeNonAsciiChars);
|
||||
Text("0x%08X", tool->QueryMainId);
|
||||
SameLine();
|
||||
MetricsHelpMarker("Hover an item with the mouse to display elements of the ID Stack leading to the item's final ID.\nEach level of the stack correspond to a PushID() call.\nAll levels of the stack are hashed together to make the final ID of a widget (ID displayed at the bottom level of the stack).\nRead FAQ entry about the ID stack for details.");
|
||||
@@ -17964,14 +17969,13 @@ void ImGui::ShowIDStackToolWindow(bool* p_open)
|
||||
if (tool->OptCopyToClipboardOnCtrlC && Shortcut(ImGuiMod_Ctrl | ImGuiKey_C, ImGuiInputFlags_RouteGlobal | ImGuiInputFlags_RouteOverFocused))
|
||||
{
|
||||
tool->CopyToClipboardLastTime = (float)g.Time;
|
||||
SetClipboardText(tool->ResultTempBuf.c_str());
|
||||
SetClipboardText(result_path);
|
||||
}
|
||||
|
||||
Text("- Path \"%s\"", tool->ResultTempBuf.c_str());
|
||||
Text("- Path \"%s\"", result_path);
|
||||
#ifdef IMGUI_ENABLE_TEST_ENGINE
|
||||
Text("- Label \"%s\"", tool->QueryMainId ? ImGuiTestEngine_FindItemDebugLabel(&g, tool->QueryMainId) : "");
|
||||
#endif
|
||||
|
||||
Separator();
|
||||
|
||||
// Display decorated stack
|
||||
|
||||
@@ -2140,7 +2140,7 @@ struct ImGuiIDStackTool
|
||||
bool OptCopyToClipboardOnCtrlC;
|
||||
float CopyToClipboardLastTime;
|
||||
ImGuiTextBuffer ResultPathsBuf;
|
||||
ImGuiTextBuffer ResultTempBuf;
|
||||
ImGuiTextBuffer ResultFullPathBuf;
|
||||
|
||||
ImGuiIDStackTool() { memset(this, 0, sizeof(*this)); LastActiveFrame = -1; OptHexEncodeNonAsciiChars = true; CopyToClipboardLastTime = -FLT_MAX; }
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user