Logs: Made it a table instead of a List
This commit is contained in:
parent
99d99280cc
commit
d373951d91
15
imgui.ini
15
imgui.ini
@ -134,8 +134,8 @@ Collapsed=0
|
|||||||
DockId=0x0000001E,0
|
DockId=0x0000001E,0
|
||||||
|
|
||||||
[Window][ Logger##logger]
|
[Window][ Logger##logger]
|
||||||
Pos=345,739
|
Pos=345,282
|
||||||
Size=586,430
|
Size=265,430
|
||||||
Collapsed=0
|
Collapsed=0
|
||||||
DockId=0x00000021,0
|
DockId=0x00000021,0
|
||||||
|
|
||||||
@ -152,8 +152,8 @@ Collapsed=0
|
|||||||
DockId=0x00000022,0
|
DockId=0x00000022,0
|
||||||
|
|
||||||
[Window][ Profiler]
|
[Window][ Profiler]
|
||||||
Pos=345,282
|
Pos=612,282
|
||||||
Size=530,430
|
Size=263,430
|
||||||
Collapsed=0
|
Collapsed=0
|
||||||
DockId=0x00000023,0
|
DockId=0x00000023,0
|
||||||
|
|
||||||
@ -175,6 +175,11 @@ Column 1 Weight=0.9086
|
|||||||
Column 2 Weight=0.9665
|
Column 2 Weight=0.9665
|
||||||
Column 3 Weight=0.6950
|
Column 3 Weight=0.6950
|
||||||
|
|
||||||
|
[Table][0x801835C4,2]
|
||||||
|
RefScale=16
|
||||||
|
Column 0 Width=30
|
||||||
|
Column 1 Weight=1.0000
|
||||||
|
|
||||||
[Docking][Data]
|
[Docking][Data]
|
||||||
DockSpace ID=0x14621557 Window=0x3DA2F1DE Pos=146,189 Size=1264,684 Split=X Selected=0xF7365A5A
|
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
|
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=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=0x00000025 Parent=0x0000001D SizeRef=549,430 Split=X Selected=0x1F29F1F5
|
||||||
DockNode ID=0x00000021 Parent=0x00000025 SizeRef=586,323 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=0x0000001E Parent=0x00000017 SizeRef=518,417 Selected=0xC74E1AEE
|
||||||
DockNode ID=0x00000018 Parent=0x0000000D SizeRef=1202,364 Split=X Selected=0x1C0788A1
|
DockNode ID=0x00000018 Parent=0x0000000D SizeRef=1202,364 Split=X Selected=0x1C0788A1
|
||||||
DockNode ID=0x00000019 Parent=0x00000018 SizeRef=601,364 Selected=0x1C0788A1
|
DockNode ID=0x00000019 Parent=0x00000018 SizeRef=601,364 Selected=0x1C0788A1
|
||||||
|
@ -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");
|
g_LoggerWindow->AddLog(LogLevel::Warning, "Warning: You are in Debug Mode. Switch to Releace for more performance");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,8 +117,10 @@ void LoggerWindow::Show()
|
|||||||
{
|
{
|
||||||
SCOPE_TIMER("LoggerWindow::Show");
|
SCOPE_TIMER("LoggerWindow::Show");
|
||||||
|
|
||||||
|
// Window with an icon in the title
|
||||||
ImGui::Begin(ICON_FA_TERMINAL " Logger##logger");
|
ImGui::Begin(ICON_FA_TERMINAL " Logger##logger");
|
||||||
|
|
||||||
|
// Clear button
|
||||||
if (ImGui::Button("Clear"))
|
if (ImGui::Button("Clear"))
|
||||||
{
|
{
|
||||||
m_Logs.clear();
|
m_Logs.clear();
|
||||||
@ -126,21 +128,54 @@ void LoggerWindow::Show()
|
|||||||
|
|
||||||
ImGui::Separator();
|
ImGui::Separator();
|
||||||
|
|
||||||
|
// Child region for scrollable area
|
||||||
ImGui::BeginChild("LoggerScrollRegion", ImVec2(0, 0), false,
|
ImGui::BeginChild("LoggerScrollRegion", ImVec2(0, 0), false,
|
||||||
ImGuiWindowFlags_HorizontalScrollbar);
|
ImGuiWindowFlags_HorizontalScrollbar);
|
||||||
|
|
||||||
for (const auto &logEntry : m_Logs)
|
// Optional: tweak cell-padding or other style before beginning the table
|
||||||
{
|
// ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, ImVec2(4.0f, 4.0f));
|
||||||
// 1) Decide what color to use
|
|
||||||
ImVec4 color = logEntry.color.value_or(
|
|
||||||
GetDefaultColorForLevel(logEntry.level)
|
|
||||||
);
|
|
||||||
|
|
||||||
// 2) Show "[icon] the text"
|
// Begin the table with 2 columns
|
||||||
ImGui::TextColored(color, "%s %s", logEntry.icon.c_str(), logEntry.text.c_str());
|
// - 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)
|
if (m_ScrollToBottom)
|
||||||
{
|
{
|
||||||
ImGui::SetScrollHereY(1.0f);
|
ImGui::SetScrollHereY(1.0f);
|
||||||
@ -150,3 +185,4 @@ void LoggerWindow::Show()
|
|||||||
ImGui::EndChild();
|
ImGui::EndChild();
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user