From d373951d917b3f3d33d0b41833e31b605e87fcc0 Mon Sep 17 00:00:00 2001 From: OusmBlueNinja <89956790+OusmBlueNinja@users.noreply.github.com> Date: Sat, 4 Jan 2025 23:26:13 -0600 Subject: [PATCH] Logs: Made it a table instead of a List --- imgui.ini | 15 ++++++---- src/Engine.cpp | 1 + src/Windows/LoggerWindow.cpp | 54 ++++++++++++++++++++++++++++++------ 3 files changed, 56 insertions(+), 14 deletions(-) diff --git a/imgui.ini b/imgui.ini index 13fa828..13ceb8c 100644 --- a/imgui.ini +++ b/imgui.ini @@ -134,8 +134,8 @@ Collapsed=0 DockId=0x0000001E,0 [Window][ Logger##logger] -Pos=345,739 -Size=586,430 +Pos=345,282 +Size=265,430 Collapsed=0 DockId=0x00000021,0 @@ -152,8 +152,8 @@ Collapsed=0 DockId=0x00000022,0 [Window][ Profiler] -Pos=345,282 -Size=530,430 +Pos=612,282 +Size=263,430 Collapsed=0 DockId=0x00000023,0 @@ -175,6 +175,11 @@ Column 1 Weight=0.9086 Column 2 Weight=0.9665 Column 3 Weight=0.6950 +[Table][0x801835C4,2] +RefScale=16 +Column 0 Width=30 +Column 1 Weight=1.0000 + [Docking][Data] DockSpace ID=0x14621557 Window=0x3DA2F1DE Pos=146,189 Size=1264,684 Split=X Selected=0xF7365A5A DockNode ID=0x00000020 Parent=0x14621557 SizeRef=884,684 Split=X @@ -201,7 +206,7 @@ DockSpace ID=0x14621557 Window=0x3DA2F1DE Pos=146,189 DockNode ID=0x0000001F Parent=0x0000001D SizeRef=549,709 CentralNode=1 HiddenTabBar=1 Selected=0x9A7B23B9 DockNode ID=0x00000025 Parent=0x0000001D SizeRef=549,430 Split=X Selected=0x1F29F1F5 DockNode ID=0x00000021 Parent=0x00000025 SizeRef=586,323 Selected=0x1F29F1F5 - DockNode ID=0x00000023 Parent=0x00000025 SizeRef=582,323 Selected=0x8E897E2D + DockNode ID=0x00000023 Parent=0x00000025 SizeRef=582,323 Selected=0x7A66B86B DockNode ID=0x0000001E Parent=0x00000017 SizeRef=518,417 Selected=0xC74E1AEE DockNode ID=0x00000018 Parent=0x0000000D SizeRef=1202,364 Split=X Selected=0x1C0788A1 DockNode ID=0x00000019 Parent=0x00000018 SizeRef=601,364 Selected=0x1C0788A1 diff --git a/src/Engine.cpp b/src/Engine.cpp index 586c763..6b61514 100644 --- a/src/Engine.cpp +++ b/src/Engine.cpp @@ -195,6 +195,7 @@ bool MyEngine::Init(int width, int height, const std::string &title) g_LoggerWindow->AddLog(LogLevel::Warning, "Warning: You are in Debug Mode. Switch to Releace for more performance"); #endif + return true; } diff --git a/src/Windows/LoggerWindow.cpp b/src/Windows/LoggerWindow.cpp index 6d3bf5d..393f3fb 100644 --- a/src/Windows/LoggerWindow.cpp +++ b/src/Windows/LoggerWindow.cpp @@ -117,8 +117,10 @@ void LoggerWindow::Show() { SCOPE_TIMER("LoggerWindow::Show"); + // Window with an icon in the title ImGui::Begin(ICON_FA_TERMINAL " Logger##logger"); + // Clear button if (ImGui::Button("Clear")) { m_Logs.clear(); @@ -126,21 +128,54 @@ void LoggerWindow::Show() ImGui::Separator(); + // Child region for scrollable area ImGui::BeginChild("LoggerScrollRegion", ImVec2(0, 0), false, ImGuiWindowFlags_HorizontalScrollbar); - for (const auto &logEntry : m_Logs) - { - // 1) Decide what color to use - ImVec4 color = logEntry.color.value_or( - GetDefaultColorForLevel(logEntry.level) - ); + // Optional: tweak cell-padding or other style before beginning the table + // ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, ImVec2(4.0f, 4.0f)); - // 2) Show "[icon] the text" - ImGui::TextColored(color, "%s %s", logEntry.icon.c_str(), logEntry.text.c_str()); + // Begin the table with 2 columns + // - RowBg flag for striped rows + // - Borders for a neat grid + // - SizingFixedFit or SizingStretch can be chosen per preference + if (ImGui::BeginTable("LogTable", 2, + ImGuiTableFlags_SizingFixedFit | + ImGuiTableFlags_Borders | + ImGuiTableFlags_RowBg | + ImGuiTableFlags_Resizable)) + { + // Optionally set up columns (width, name, etc.) + ImGui::TableSetupColumn("Icon", ImGuiTableColumnFlags_WidthFixed, 30.0f); + ImGui::TableSetupColumn("Message", ImGuiTableColumnFlags_WidthStretch); + + // If you want a header row (not strictly needed for a log) + // ImGui::TableHeadersRow(); + + // Loop over your log entries + for (const auto &logEntry : m_Logs) + { + ImVec4 color = logEntry.color.value_or(GetDefaultColorForLevel(logEntry.level)); + + // Start a new row + ImGui::TableNextRow(); + + // Column 0: Icon + ImGui::TableNextColumn(); + ImGui::TextColored(color, "%s", logEntry.icon.c_str()); + + // Column 1: Text + ImGui::TableNextColumn(); + ImGui::TextUnformatted(logEntry.text.c_str()); + } + + ImGui::EndTable(); } - // Auto-scroll to bottom if new logs are added + // If you used PushStyleVar above, pop it here: + // ImGui::PopStyleVar(); + + // Auto-scroll to bottom if needed if (m_ScrollToBottom) { ImGui::SetScrollHereY(1.0f); @@ -150,3 +185,4 @@ void LoggerWindow::Show() ImGui::EndChild(); ImGui::End(); } +