mirror of
https://github.com/Drezil/imgui.git
synced 2025-07-07 13:35:49 +02:00
Debug: Added ShowDebugLogWindow().
Internal: renamed old IMGUI_DEBUG_LOG() to IMGUI_DEBUG_PRINT(). Amended once.
This commit is contained in:
125
imgui.cpp
125
imgui.cpp
@ -83,6 +83,7 @@ CODE
|
||||
// [SECTION] VIEWPORTS
|
||||
// [SECTION] PLATFORM DEPENDENT HELPERS
|
||||
// [SECTION] METRICS/DEBUGGER WINDOW
|
||||
// [SECTION] DEBUG LOG WINDOW
|
||||
// [SECTION] OTHER DEBUG TOOLS (ITEM PICKER, STACK TOOL)
|
||||
|
||||
*/
|
||||
@ -1269,7 +1270,7 @@ void ImGuiIO::ClearInputKeys()
|
||||
// - float analog_value: 0.0f..1.0f
|
||||
void ImGuiIO::AddKeyAnalogEvent(ImGuiKey key, bool down, float analog_value)
|
||||
{
|
||||
//if (e->Down) { IMGUI_DEBUG_LOG("AddKeyEvent() Key='%s' %d, NativeKeycode = %d, NativeScancode = %d\n", ImGui::GetKeyName(e->Key), e->Down, e->NativeKeycode, e->NativeScancode); }
|
||||
//if (e->Down) { IMGUI_DEBUG_PRINT("AddKeyEvent() Key='%s' %d, NativeKeycode = %d, NativeScancode = %d\n", ImGui::GetKeyName(e->Key), e->Down, e->NativeKeycode, e->NativeScancode); }
|
||||
if (key == ImGuiKey_None || !AppAcceptingEvents)
|
||||
return;
|
||||
ImGuiContext& g = *GImGui;
|
||||
@ -3385,6 +3386,7 @@ void ImGui::SetActiveID(ImGuiID id, ImGuiWindow* window)
|
||||
g.ActiveIdIsJustActivated = (g.ActiveId != id);
|
||||
if (g.ActiveIdIsJustActivated)
|
||||
{
|
||||
IMGUI_DEBUG_LOG_ACTIVEID("[activeid] SetActiveID(0x%08X) in Window \"%s\"\n", id, window ? window->Name : "<NULL>");
|
||||
g.ActiveIdTimer = 0.0f;
|
||||
g.ActiveIdHasBeenPressedBefore = false;
|
||||
g.ActiveIdHasBeenEditedBefore = false;
|
||||
@ -4576,6 +4578,7 @@ void ImGui::Shutdown()
|
||||
g.LogFile = NULL;
|
||||
}
|
||||
g.LogBuffer.clear();
|
||||
g.DebugLogBuf.clear();
|
||||
|
||||
g.Initialized = false;
|
||||
}
|
||||
@ -5361,7 +5364,7 @@ static void UpdateWindowInFocusOrderList(ImGuiWindow* window, bool just_created,
|
||||
static ImGuiWindow* CreateNewWindow(const char* name, ImGuiWindowFlags flags)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
//IMGUI_DEBUG_LOG("CreateNewWindow '%s', flags = 0x%08X\n", name, flags);
|
||||
//IMGUI_DEBUG_PRINT("CreateNewWindow '%s', flags = 0x%08X\n", name, flags);
|
||||
|
||||
// Create window the first time
|
||||
ImGuiWindow* window = IM_NEW(ImGuiWindow)(&g, name);
|
||||
@ -6781,6 +6784,7 @@ void ImGui::FocusWindow(ImGuiWindow* window)
|
||||
|
||||
if (g.NavWindow != window)
|
||||
{
|
||||
IMGUI_DEBUG_LOG_FOCUS("[focus] FocusWindow(\"%s\")\n", window ? window->Name : "<NULL>");
|
||||
g.NavWindow = window;
|
||||
if (window && g.NavDisableMouseHover)
|
||||
g.NavMousePosDirty = true;
|
||||
@ -6790,7 +6794,6 @@ void ImGui::FocusWindow(ImGuiWindow* window)
|
||||
g.NavLayer = ImGuiNavLayer_Main;
|
||||
g.NavInitRequest = g.NavMoveSubmitted = g.NavMoveScoringItems = false;
|
||||
NavUpdateAnyRequestFlag();
|
||||
//IMGUI_DEBUG_LOG("FocusWindow(\"%s\")\n", window ? window->Name : NULL);
|
||||
}
|
||||
|
||||
// Close popups if any
|
||||
@ -7819,21 +7822,23 @@ void ImGui::SetNextFrameWantCaptureMouse(bool want_capture_mouse)
|
||||
g.WantCaptureMouseNextFrame = want_capture_mouse ? 1 : 0;
|
||||
}
|
||||
|
||||
#ifndef IMGUI_DISABLE_METRICS_WINDOW
|
||||
static const char* GetInputSourceName(ImGuiInputSource source)
|
||||
{
|
||||
const char* input_source_names[] = { "None", "Mouse", "Keyboard", "Gamepad", "Nav", "Clipboard" };
|
||||
IM_ASSERT(IM_ARRAYSIZE(input_source_names) == ImGuiInputSource_COUNT && source >= 0 && source < ImGuiInputSource_COUNT);
|
||||
return input_source_names[source];
|
||||
}
|
||||
#endif
|
||||
|
||||
/*static void DebugLogInputEvent(const char* prefix, const ImGuiInputEvent* e)
|
||||
/*static void DebugPrintInputEvent(const char* prefix, const ImGuiInputEvent* e)
|
||||
{
|
||||
if (e->Type == ImGuiInputEventType_MousePos) { IMGUI_DEBUG_LOG("%s: MousePos (%.1f %.1f)\n", prefix, e->MousePos.PosX, e->MousePos.PosY); return; }
|
||||
if (e->Type == ImGuiInputEventType_MouseButton) { IMGUI_DEBUG_LOG("%s: MouseButton %d %s\n", prefix, e->MouseButton.Button, e->MouseButton.Down ? "Down" : "Up"); return; }
|
||||
if (e->Type == ImGuiInputEventType_MouseWheel) { IMGUI_DEBUG_LOG("%s: MouseWheel (%.1f %.1f)\n", prefix, e->MouseWheel.WheelX, e->MouseWheel.WheelY); return; }
|
||||
if (e->Type == ImGuiInputEventType_Key) { IMGUI_DEBUG_LOG("%s: Key \"%s\" %s\n", prefix, ImGui::GetKeyName(e->Key.Key), e->Key.Down ? "Down" : "Up"); return; }
|
||||
if (e->Type == ImGuiInputEventType_Text) { IMGUI_DEBUG_LOG("%s: Text: %c (U+%08X)\n", prefix, e->Text.Char, e->Text.Char); return; }
|
||||
if (e->Type == ImGuiInputEventType_Focus) { IMGUI_DEBUG_LOG("%s: AppFocused %d\n", prefix, e->AppFocused.Focused); return; }
|
||||
if (e->Type == ImGuiInputEventType_MousePos) { IMGUI_DEBUG_PRINT("%s: MousePos (%.1f %.1f)\n", prefix, e->MousePos.PosX, e->MousePos.PosY); return; }
|
||||
if (e->Type == ImGuiInputEventType_MouseButton) { IMGUI_DEBUG_PRINT("%s: MouseButton %d %s\n", prefix, e->MouseButton.Button, e->MouseButton.Down ? "Down" : "Up"); return; }
|
||||
if (e->Type == ImGuiInputEventType_MouseWheel) { IMGUI_DEBUG_PRINT("%s: MouseWheel (%.1f %.1f)\n", prefix, e->MouseWheel.WheelX, e->MouseWheel.WheelY); return; }
|
||||
if (e->Type == ImGuiInputEventType_Key) { IMGUI_DEBUG_PRINT("%s: Key \"%s\" %s\n", prefix, ImGui::GetKeyName(e->Key.Key), e->Key.Down ? "Down" : "Up"); return; }
|
||||
if (e->Type == ImGuiInputEventType_Text) { IMGUI_DEBUG_PRINT("%s: Text: %c (U+%08X)\n", prefix, e->Text.Char, e->Text.Char); return; }
|
||||
if (e->Type == ImGuiInputEventType_Focus) { IMGUI_DEBUG_PRINT("%s: AppFocused %d\n", prefix, e->AppFocused.Focused); return; }
|
||||
}*/
|
||||
|
||||
// Process input queue
|
||||
@ -7953,14 +7958,14 @@ void ImGui::UpdateInputEvents(bool trickle_fast_inputs)
|
||||
}
|
||||
|
||||
// Record trail (for domain-specific applications wanting to access a precise trail)
|
||||
//if (event_n != 0) IMGUI_DEBUG_LOG("Processed: %d / Remaining: %d\n", event_n, g.InputEventsQueue.Size - event_n);
|
||||
//if (event_n != 0) IMGUI_DEBUG_PRINT("Processed: %d / Remaining: %d\n", event_n, g.InputEventsQueue.Size - event_n);
|
||||
for (int n = 0; n < event_n; n++)
|
||||
g.InputEventsTrail.push_back(g.InputEventsQueue[n]);
|
||||
|
||||
// [DEBUG]
|
||||
/*if (event_n != 0)
|
||||
for (int n = 0; n < g.InputEventsQueue.Size; n++)
|
||||
DebugLogInputEvent(n < event_n ? "Processed" : "Remaining", &g.InputEventsQueue[n]);*/
|
||||
DebugPrintInputEvent(n < event_n ? "Processed" : "Remaining", &g.InputEventsQueue[n]);*/
|
||||
|
||||
// Remaining events will be processed on the next frame
|
||||
if (event_n == g.InputEventsQueue.Size)
|
||||
@ -9080,7 +9085,9 @@ ImGuiWindow* ImGui::GetTopMostAndVisiblePopupModal()
|
||||
void ImGui::OpenPopup(const char* str_id, ImGuiPopupFlags popup_flags)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
OpenPopupEx(g.CurrentWindow->GetID(str_id), popup_flags);
|
||||
ImGuiID id = g.CurrentWindow->GetID(str_id);
|
||||
IMGUI_DEBUG_LOG_POPUP("[popup] OpenPopup(\"%s\" -> 0x%08X\n", str_id, id);
|
||||
OpenPopupEx(id, popup_flags);
|
||||
}
|
||||
|
||||
void ImGui::OpenPopup(ImGuiID id, ImGuiPopupFlags popup_flags)
|
||||
@ -9111,7 +9118,7 @@ void ImGui::OpenPopupEx(ImGuiID id, ImGuiPopupFlags popup_flags)
|
||||
popup_ref.OpenPopupPos = NavCalcPreferredRefPos();
|
||||
popup_ref.OpenMousePos = IsMousePosValid(&g.IO.MousePos) ? g.IO.MousePos : popup_ref.OpenPopupPos;
|
||||
|
||||
IMGUI_DEBUG_LOG_POPUP("OpenPopupEx(0x%08X)\n", id);
|
||||
IMGUI_DEBUG_LOG_POPUP("[popup] OpenPopupEx(0x%08X)\n", id);
|
||||
if (g.OpenPopupStack.Size < current_stack_size + 1)
|
||||
{
|
||||
g.OpenPopupStack.push_back(popup_ref);
|
||||
@ -9180,7 +9187,7 @@ void ImGui::ClosePopupsOverWindow(ImGuiWindow* ref_window, bool restore_focus_to
|
||||
}
|
||||
if (popup_count_to_keep < g.OpenPopupStack.Size) // This test is not required but it allows to set a convenient breakpoint on the statement below
|
||||
{
|
||||
IMGUI_DEBUG_LOG_POPUP("ClosePopupsOverWindow(\"%s\") -> ClosePopupToLevel(%d)\n", ref_window->Name, popup_count_to_keep);
|
||||
IMGUI_DEBUG_LOG_POPUP("[popup] ClosePopupsOverWindow(\"%s\")\n", ref_window ? ref_window->Name : "<NULL>");
|
||||
ClosePopupToLevel(popup_count_to_keep, restore_focus_to_window_under_popup);
|
||||
}
|
||||
}
|
||||
@ -9203,7 +9210,7 @@ void ImGui::ClosePopupsExceptModals()
|
||||
void ImGui::ClosePopupToLevel(int remaining, bool restore_focus_to_window_under_popup)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
IMGUI_DEBUG_LOG_POPUP("ClosePopupToLevel(%d), restore_focus_to_window_under_popup=%d\n", remaining, restore_focus_to_window_under_popup);
|
||||
IMGUI_DEBUG_LOG_POPUP("[popup] ClosePopupToLevel(%d), restore_focus_to_window_under_popup=%d\n", remaining, restore_focus_to_window_under_popup);
|
||||
IM_ASSERT(remaining >= 0 && remaining < g.OpenPopupStack.Size);
|
||||
|
||||
// Trim open popup stack
|
||||
@ -9248,7 +9255,7 @@ void ImGui::CloseCurrentPopup()
|
||||
break;
|
||||
popup_idx--;
|
||||
}
|
||||
IMGUI_DEBUG_LOG_POPUP("CloseCurrentPopup %d -> %d\n", g.BeginPopupStack.Size - 1, popup_idx);
|
||||
IMGUI_DEBUG_LOG_POPUP("[popup] CloseCurrentPopup %d -> %d\n", g.BeginPopupStack.Size - 1, popup_idx);
|
||||
ClosePopupToLevel(popup_idx, true);
|
||||
|
||||
// A common pattern is to close a popup when selecting a menu item/selectable that will open another window.
|
||||
@ -10129,7 +10136,7 @@ static void ImGui::NavUpdate()
|
||||
ImGuiIO& io = g.IO;
|
||||
|
||||
io.WantSetMousePos = false;
|
||||
//if (g.NavScoringDebugCount > 0) IMGUI_DEBUG_LOG("NavScoringDebugCount %d for '%s' layer %d (Init:%d, Move:%d)\n", g.NavScoringDebugCount, g.NavWindow ? g.NavWindow->Name : "NULL", g.NavLayer, g.NavInitRequest || g.NavInitResultId != 0, g.NavMoveRequest);
|
||||
//if (g.NavScoringDebugCount > 0) IMGUI_DEBUG_LOG_NAV("[nav] NavScoringDebugCount %d for '%s' layer %d (Init:%d, Move:%d)\n", g.NavScoringDebugCount, g.NavWindow ? g.NavWindow->Name : "NULL", g.NavLayer, g.NavInitRequest || g.NavInitResultId != 0, g.NavMoveRequest);
|
||||
|
||||
// Update Gamepad->Nav inputs mapping
|
||||
// Set input source as Gamepad when buttons are pressed (as some features differs when used with Gamepad vs Keyboard)
|
||||
@ -10303,7 +10310,7 @@ static void ImGui::NavUpdate()
|
||||
{
|
||||
io.MousePos = io.MousePosPrev = NavCalcPreferredRefPos();
|
||||
io.WantSetMousePos = true;
|
||||
//IMGUI_DEBUG_LOG("SetMousePos: (%.1f,%.1f)\n", io.MousePos.x, io.MousePos.y);
|
||||
//IMGUI_DEBUG_PRINT("SetMousePos: (%.1f,%.1f)\n", io.MousePos.x, io.MousePos.y);
|
||||
}
|
||||
|
||||
// [DEBUG]
|
||||
@ -10327,7 +10334,7 @@ void ImGui::NavInitRequestApplyResult()
|
||||
|
||||
// Apply result from previous navigation init request (will typically select the first item, unless SetItemDefaultFocus() has been called)
|
||||
// FIXME-NAV: On _NavFlattened windows, g.NavWindow will only be updated during subsequent frame. Not a problem currently.
|
||||
IMGUI_DEBUG_LOG_NAV("[nav] NavInitRequest: result NavID 0x%08X in Layer %d Window \"%s\"\n", g.NavInitResultId, g.NavLayer, g.NavWindow->Name);
|
||||
IMGUI_DEBUG_LOG_NAV("[nav] NavInitRequest: ApplyResult: NavID 0x%08X in Layer %d Window \"%s\"\n", g.NavInitResultId, g.NavLayer, g.NavWindow->Name);
|
||||
SetNavID(g.NavInitResultId, g.NavLayer, 0, g.NavInitResultRectRel);
|
||||
g.NavIdIsAlive = true; // Mark as alive from previous frame as we got a result
|
||||
if (g.NavInitRequestFromMove)
|
||||
@ -10397,7 +10404,7 @@ void ImGui::NavUpdateCreateMoveRequest()
|
||||
// Moving with no reference triggers a init request (will be used as a fallback if the direction fails to find a match)
|
||||
if (g.NavMoveSubmitted && g.NavId == 0)
|
||||
{
|
||||
IMGUI_DEBUG_LOG_NAV("[nav] NavInitRequest: from move, window \"%s\", layer=%d\n", g.NavWindow->Name, g.NavLayer);
|
||||
IMGUI_DEBUG_LOG_NAV("[nav] NavInitRequest: from move, window \"%s\", layer=%d\n", window ? window->Name : "<NULL>", g.NavLayer);
|
||||
g.NavInitRequest = g.NavInitRequestFromMove = true;
|
||||
g.NavInitResultId = 0;
|
||||
g.NavDisableHighlight = false;
|
||||
@ -10413,7 +10420,7 @@ void ImGui::NavUpdateCreateMoveRequest()
|
||||
ImRect inner_rect_rel = WindowRectAbsToRel(window, ImRect(window->InnerRect.Min - ImVec2(1, 1), window->InnerRect.Max + ImVec2(1, 1)));
|
||||
if ((clamp_x || clamp_y) && !inner_rect_rel.Contains(window->NavRectRel[g.NavLayer]))
|
||||
{
|
||||
IMGUI_DEBUG_LOG_NAV("[nav] NavMoveRequest: clamp NavRectRel for gamepad move\n");
|
||||
//IMGUI_DEBUG_LOG_NAV("[nav] NavMoveRequest: clamp NavRectRel for gamepad move\n");
|
||||
float pad_x = ImMin(inner_rect_rel.GetWidth(), window->CalcFontSize() * 0.5f);
|
||||
float pad_y = ImMin(inner_rect_rel.GetHeight(), window->CalcFontSize() * 0.5f); // Terrible approximation for the intent of starting navigation from first fully visible item
|
||||
inner_rect_rel.Min.x = clamp_x ? (inner_rect_rel.Min.x + pad_x) : -FLT_MAX;
|
||||
@ -12344,8 +12351,19 @@ void ImGui::ShowMetricsWindow(bool* p_open)
|
||||
TreePop();
|
||||
}
|
||||
|
||||
// The Item Picker tool is super useful to visually select an item and break into the call-stack of where it was submitted.
|
||||
if (Checkbox("Show Item Picker", &g.DebugItemPickerActive) && g.DebugItemPickerActive)
|
||||
DebugStartItemPicker();
|
||||
SameLine();
|
||||
MetricsHelpMarker("Will call the IM_DEBUG_BREAK() macro to break in debugger.\nWarning: If you don't have a debugger attached, this will probably crash.");
|
||||
|
||||
// Stack Tool is your best friend!
|
||||
Checkbox("Show stack tool", &cfg->ShowStackTool);
|
||||
Checkbox("Show Debug Log", &cfg->ShowDebugLog);
|
||||
SameLine();
|
||||
MetricsHelpMarker("You can also call ImGui::ShowDebugLogWindow() from your code.");
|
||||
|
||||
// Stack Tool is your best friend!
|
||||
Checkbox("Show Stack Tool", &cfg->ShowStackTool);
|
||||
SameLine();
|
||||
MetricsHelpMarker("You can also call ImGui::ShowStackToolWindow() from your code.");
|
||||
|
||||
@ -12411,12 +12429,6 @@ void ImGui::ShowMetricsWindow(bool* p_open)
|
||||
}
|
||||
}
|
||||
|
||||
// The Item Picker tool is super useful to visually select an item and break into the call-stack of where it was submitted.
|
||||
if (Button("Item Picker.."))
|
||||
DebugStartItemPicker();
|
||||
SameLine();
|
||||
MetricsHelpMarker("Will call the IM_DEBUG_BREAK() macro to break in debugger.\nWarning: If you don't have a debugger attached, this will probably crash.");
|
||||
|
||||
TreePop();
|
||||
}
|
||||
|
||||
@ -13086,6 +13098,58 @@ void ImGui::DebugNodeWindowsListByBeginStackParent(ImGuiWindow** windows, int wi
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// [SECTION] DEBUG LOG
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void ImGui::DebugLog(const char* fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
DebugLogV(fmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void ImGui::DebugLogV(const char* fmt, va_list args)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
g.DebugLogBuf.appendf("[%05d] ", g.FrameCount);
|
||||
g.DebugLogBuf.appendfv(fmt, args);
|
||||
}
|
||||
|
||||
void ImGui::ShowDebugLogWindow(bool* p_open)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
if (!(g.NextWindowData.Flags & ImGuiNextWindowDataFlags_HasSize))
|
||||
SetNextWindowSize(ImVec2(0.0f, GetFontSize() * 12.0f), ImGuiCond_FirstUseEver);
|
||||
if (!Begin("Dear ImGui Debug Log", p_open) || GetCurrentWindow()->BeginCount > 1)
|
||||
{
|
||||
End();
|
||||
return;
|
||||
}
|
||||
|
||||
AlignTextToFramePadding();
|
||||
Text("Log events:");
|
||||
SameLine(); CheckboxFlags("All", &g.DebugLogFlags, ImGuiDebugLogFlags_EventMask_);
|
||||
SameLine(); CheckboxFlags("ActiveId", &g.DebugLogFlags, ImGuiDebugLogFlags_EventActiveId);
|
||||
SameLine(); CheckboxFlags("Focus", &g.DebugLogFlags, ImGuiDebugLogFlags_EventFocus);
|
||||
SameLine(); CheckboxFlags("Popup", &g.DebugLogFlags, ImGuiDebugLogFlags_EventPopup);
|
||||
SameLine(); CheckboxFlags("Nav", &g.DebugLogFlags, ImGuiDebugLogFlags_EventNav);
|
||||
|
||||
if (SmallButton("Clear"))
|
||||
g.DebugLogBuf.clear();
|
||||
SameLine();
|
||||
if (SmallButton("Copy"))
|
||||
SetClipboardText(g.DebugLogBuf.c_str());
|
||||
BeginChild("##log", ImVec2(0.0f, 0.0f), true, ImGuiWindowFlags_AlwaysVerticalScrollbar | ImGuiWindowFlags_AlwaysHorizontalScrollbar);
|
||||
TextUnformatted(g.DebugLogBuf.begin(), g.DebugLogBuf.end()); // FIXME-OPT: Could use a line index, but TextUnformatted() has a semi-decent fast path for large text.
|
||||
if (GetScrollY() >= GetScrollMaxY())
|
||||
SetScrollHereY(1.0f);
|
||||
EndChild();
|
||||
|
||||
End();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// [SECTION] OTHER DEBUG TOOLS (ITEM PICKER, STACK TOOL)
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -13312,6 +13376,9 @@ void ImGui::DebugNodeWindowSettings(ImGuiWindowSettings*) {}
|
||||
void ImGui::DebugNodeWindowsList(ImVector<ImGuiWindow*>*, const char*) {}
|
||||
void ImGui::DebugNodeViewport(ImGuiViewportP*) {}
|
||||
|
||||
void ImGui::DebugLog(const char*, ...) {}
|
||||
void ImGui::DebugLogV(const char*, va_list) {}
|
||||
void ImGui::ShowDebugLogWindow(bool*) {}
|
||||
void ImGui::ShowStackToolWindow(bool*) {}
|
||||
void ImGui::DebugHookIdInfo(ImGuiID, ImGuiDataType, const void*, const void*) {}
|
||||
void ImGui::UpdateDebugToolItemPicker() {}
|
||||
|
Reference in New Issue
Block a user