Browse Source

Internals: added ImGuiContext::ContextName optionally used by debug log and to facilitate debugging.

ocornut 1 year ago
parent
commit
37c243bb35
2 changed files with 6 additions and 1 deletions
  1. 4 1
      imgui.cpp
  2. 2 0
      imgui_internal.h

+ 4 - 1
imgui.cpp

@@ -15606,7 +15606,10 @@ void ImGui::DebugLogV(const char* fmt, va_list args)
 {
 {
     ImGuiContext& g = *GImGui;
     ImGuiContext& g = *GImGui;
     const int old_size = g.DebugLogBuf.size();
     const int old_size = g.DebugLogBuf.size();
-    g.DebugLogBuf.appendf("[%05d] ", g.FrameCount);
+    if (g.ContextName[0] != 0)
+        g.DebugLogBuf.appendf("[%s] [%05d] ", g.ContextName, g.FrameCount);
+    else
+        g.DebugLogBuf.appendf("[%05d] ", g.FrameCount);
     g.DebugLogBuf.appendfv(fmt, args);
     g.DebugLogBuf.appendfv(fmt, args);
     g.DebugLogIndex.append(g.DebugLogBuf.c_str(), old_size, g.DebugLogBuf.size());
     g.DebugLogIndex.append(g.DebugLogBuf.c_str(), old_size, g.DebugLogBuf.size());
     if (g.DebugLogFlags & ImGuiDebugLogFlags_OutputToTTY)
     if (g.DebugLogFlags & ImGuiDebugLogFlags_OutputToTTY)

+ 2 - 0
imgui_internal.h

@@ -1939,6 +1939,7 @@ struct ImGuiContext
     bool                    GcCompactAll;                       // Request full GC
     bool                    GcCompactAll;                       // Request full GC
     bool                    TestEngineHookItems;                // Will call test engine hooks: ImGuiTestEngineHook_ItemAdd(), ImGuiTestEngineHook_ItemInfo(), ImGuiTestEngineHook_Log()
     bool                    TestEngineHookItems;                // Will call test engine hooks: ImGuiTestEngineHook_ItemAdd(), ImGuiTestEngineHook_ItemInfo(), ImGuiTestEngineHook_Log()
     void*                   TestEngine;                         // Test engine user data
     void*                   TestEngine;                         // Test engine user data
+    char                    ContextName[16];                    // Storage for a context name (to facilitate debugging multi-context setups)
 
 
     // Inputs
     // Inputs
     ImVector<ImGuiInputEvent> InputEventsQueue;                 // Input events which will be trickled/written into IO structure.
     ImVector<ImGuiInputEvent> InputEventsQueue;                 // Input events which will be trickled/written into IO structure.
@@ -2266,6 +2267,7 @@ struct ImGuiContext
         GcCompactAll = false;
         GcCompactAll = false;
         TestEngineHookItems = false;
         TestEngineHookItems = false;
         TestEngine = NULL;
         TestEngine = NULL;
+        memset(ContextName, 0, sizeof(ContextName));
 
 
         InputEventsNextMouseSource = ImGuiMouseSource_Mouse;
         InputEventsNextMouseSource = ImGuiMouseSource_Mouse;
         InputEventsNextEventId = 1;
         InputEventsNextEventId = 1;