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:
52
imgui.cpp
52
imgui.cpp
@@ -17913,6 +17913,31 @@ static int StackToolFormatLevelInfo(ImGuiIDStackTool* tool, int n, bool format_f
|
||||
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