Files
XCEngine/editor/src/panels/ConsolePanel.cpp

102 lines
3.2 KiB
C++
Raw Normal View History

2026-03-26 21:18:33 +08:00
#include "Actions/EditorActions.h"
#include "ConsolePanel.h"
#include "Core/EditorConsoleSink.h"
2026-03-26 21:18:33 +08:00
#include "UI/UI.h"
#include <XCEngine/Debug/LogCategory.h>
#include <XCEngine/Debug/Logger.h>
#include <imgui.h>
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();
{
2026-03-26 21:18:33 +08:00
UI::PanelToolbarScope toolbar("ConsoleToolbar", UI::StandardPanelToolbarHeight());
if (toolbar.IsOpen()) {
2026-03-26 21:18:33 +08:00
if (Actions::DrawToolbarAction(Actions::MakeClearConsoleAction())) {
sink->Clear();
}
ImGui::SameLine();
2026-03-26 21:18:33 +08:00
UI::DrawToolbarLabel("Filter");
ImGui::SameLine();
2026-03-26 21:18:33 +08:00
Actions::DrawToolbarToggleAction(Actions::MakeConsoleInfoFilterAction(m_showInfo), m_showInfo);
ImGui::SameLine();
2026-03-26 21:18:33 +08:00
Actions::DrawToolbarToggleAction(Actions::MakeConsoleWarningFilterAction(m_showWarning), m_showWarning);
ImGui::SameLine();
2026-03-26 21:18:33 +08:00
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<int>(logIndex));
const char* category = ::XCEngine::Debug::LogCategoryToString(log.category);
std::string fullMessage = std::string(prefix) + "[" + category + "] " + log.message.CStr();
2026-03-26 21:18:33 +08:00
if (UI::DrawConsoleLogRow(fullMessage.c_str())) {
ImGui::SetClipboardText(fullMessage.c_str());
}
ImGui::PopID();
logIndex++;
}
}
}
}