#include "Actions/EditorActions.h" #include "ConsolePanel.h" #include "Core/EditorConsoleSink.h" #include "UI/UI.h" #include #include #include namespace XCEngine { namespace Editor { ConsolePanel::ConsolePanel() : Panel("Console") { } void ConsolePanel::Render() { UI::PanelWindowScope panel(m_name.c_str()); if (!panel.IsOpen()) { return; } auto* sink = Debug::EditorConsoleSink::GetInstance(); { UI::PanelToolbarScope toolbar("ConsoleToolbar", UI::StandardPanelToolbarHeight()); if (toolbar.IsOpen()) { if (Actions::DrawToolbarAction(Actions::MakeClearConsoleAction())) { sink->Clear(); } ImGui::SameLine(); UI::DrawToolbarLabel("Filter"); ImGui::SameLine(); Actions::DrawToolbarToggleAction(Actions::MakeConsoleInfoFilterAction(m_showInfo), m_showInfo); ImGui::SameLine(); Actions::DrawToolbarToggleAction(Actions::MakeConsoleWarningFilterAction(m_showWarning), m_showWarning); ImGui::SameLine(); Actions::DrawToolbarToggleAction(Actions::MakeConsoleErrorFilterAction(m_showError), m_showError); } } UI::PanelContentScope content("LogScroll", UI::DefaultPanelContentPadding(), ImGuiWindowFlags_HorizontalScrollbar); if (!content.IsOpen()) { return; } const auto logs = sink->GetLogs(); size_t logIndex = 0; for (const auto& log : logs) { bool shouldShow = false; switch (log.level) { case ::XCEngine::Debug::LogLevel::Info: case ::XCEngine::Debug::LogLevel::Verbose: case ::XCEngine::Debug::LogLevel::Debug: shouldShow = m_showInfo; break; case ::XCEngine::Debug::LogLevel::Warning: shouldShow = m_showWarning; break; case ::XCEngine::Debug::LogLevel::Error: case ::XCEngine::Debug::LogLevel::Fatal: shouldShow = m_showError; break; } if (!shouldShow) { continue; } const char* prefix; switch (log.level) { case ::XCEngine::Debug::LogLevel::Verbose: case ::XCEngine::Debug::LogLevel::Debug: case ::XCEngine::Debug::LogLevel::Info: prefix = "[INFO] "; break; case ::XCEngine::Debug::LogLevel::Warning: prefix = "[WARN] "; break; case ::XCEngine::Debug::LogLevel::Error: case ::XCEngine::Debug::LogLevel::Fatal: prefix = "[ERROR] "; break; } ImGui::PushID(static_cast(logIndex)); const char* category = ::XCEngine::Debug::LogCategoryToString(log.category); std::string fullMessage = std::string(prefix) + "[" + category + "] " + log.message.CStr(); if (UI::DrawConsoleLogRow(fullMessage.c_str())) { ImGui::SetClipboardText(fullMessage.c_str()); } ImGui::PopID(); logIndex++; } } } }