Refactor editor dock and panel chrome styling

This commit is contained in:
2026-03-26 16:43:06 +08:00
parent e174862b8a
commit 45842e961e
13 changed files with 623 additions and 328 deletions

View File

@@ -1,58 +1,59 @@
#include "ConsolePanel.h"
#include "Core/EditorConsoleSink.h"
#include "UI/Core.h"
#include "UI/PanelChrome.h"
#include <XCEngine/Debug/LogCategory.h>
#include <XCEngine/Debug/Logger.h>
#include <imgui.h>
namespace XCEngine {
namespace Editor {
namespace {
constexpr float kConsoleToolbarHeight = 34.0f;
} // namespace
ConsolePanel::ConsolePanel() : Panel("Console") {
}
void ConsolePanel::Render() {
ImGui::Begin(m_name.c_str(), nullptr, ImGuiWindowFlags_None);
UI::PanelWindowScope panel(m_name.c_str());
if (!panel.IsOpen()) {
return;
}
auto* sink = Debug::EditorConsoleSink::GetInstance();
if (ImGui::Button("Clear")) {
sink->Clear();
{
UI::PanelToolbarScope toolbar("ConsoleToolbar", kConsoleToolbarHeight);
if (toolbar.IsOpen()) {
if (UI::ToolbarButton("Clear")) {
sink->Clear();
}
ImGui::SameLine();
ImGui::TextDisabled("Filter");
ImGui::SameLine();
if (UI::ToolbarButton("Info", m_showInfo)) {
m_showInfo = !m_showInfo;
}
ImGui::SameLine();
if (UI::ToolbarButton("Warn", m_showWarning)) {
m_showWarning = !m_showWarning;
}
ImGui::SameLine();
if (UI::ToolbarButton("Error", m_showError)) {
m_showError = !m_showError;
}
}
}
ImGui::SameLine();
ImGui::TextColored(ImVec4(0.5f, 0.5f, 0.5f, 1.0f), "Filter:");
ImGui::SameLine();
ImGui::Separator();
ImGui::SameLine();
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 4.0f);
ImGui::PushStyleColor(ImGuiCol_Button, m_showInfo ? ImVec4(0.2f, 0.6f, 0.2f, 1.0f) : ImVec4(0.3f, 0.3f, 0.3f, 1.0f));
if (ImGui::Button("Info")) {
m_showInfo = !m_showInfo;
UI::PanelContentScope content("LogScroll", UI::DefaultPanelContentPadding(), ImGuiWindowFlags_HorizontalScrollbar);
if (!content.IsOpen()) {
return;
}
ImGui::PopStyleColor();
ImGui::SameLine();
ImGui::PushStyleColor(ImGuiCol_Button, m_showWarning ? ImVec4(0.8f, 0.6f, 0.0f, 1.0f) : ImVec4(0.3f, 0.3f, 0.3f, 1.0f));
if (ImGui::Button("Warn")) {
m_showWarning = !m_showWarning;
}
ImGui::PopStyleColor();
ImGui::SameLine();
ImGui::PushStyleColor(ImGuiCol_Button, m_showError ? ImVec4(0.8f, 0.2f, 0.2f, 1.0f) : ImVec4(0.3f, 0.3f, 0.3f, 1.0f));
if (ImGui::Button("Error")) {
m_showError = !m_showError;
}
ImGui::PopStyleColor();
ImGui::PopStyleVar();
ImGui::Separator();
ImGui::BeginChild("LogScroll", ImVec2(0, 0), false, ImGuiWindowFlags_HorizontalScrollbar);
const auto logs = sink->GetLogs();
size_t logIndex = 0;
@@ -77,35 +78,29 @@ void ConsolePanel::Render() {
continue;
}
ImVec4 color;
const char* prefix;
switch (log.level) {
case ::XCEngine::Debug::LogLevel::Verbose:
case ::XCEngine::Debug::LogLevel::Debug:
case ::XCEngine::Debug::LogLevel::Info:
color = ImVec4(0.5f, 0.5f, 0.5f, 1.0f);
prefix = "[INFO] ";
break;
case ::XCEngine::Debug::LogLevel::Warning:
color = ImVec4(1.0f, 0.8f, 0.0f, 1.0f);
prefix = "[WARN] ";
break;
case ::XCEngine::Debug::LogLevel::Error:
case ::XCEngine::Debug::LogLevel::Fatal:
color = ImVec4(1.0f, 0.3f, 0.3f, 1.0f);
prefix = "[ERROR]";
prefix = "[ERROR] ";
break;
}
ImGui::PushID(static_cast<int>(logIndex));
ImGui::TextColored(ImVec4(0.4f, 0.4f, 0.4f, 1.0f), "%s", log.message.CStr());
ImGui::SameLine();
std::string fullMessage = std::string(prefix) + log.message.CStr();
ImGui::TextColored(color, "%s", fullMessage.c_str());
const char* category = ::XCEngine::Debug::LogCategoryToString(log.category);
std::string fullMessage = std::string(prefix) + "[" + category + "] " + log.message.CStr();
ImGui::TextUnformatted(fullMessage.c_str());
if (ImGui::IsItemClicked()) {
ImGui::SetClipboardText(fullMessage.c_str());
}
@@ -114,8 +109,6 @@ void ConsolePanel::Render() {
logIndex++;
}
ImGui::EndChild();
ImGui::End();
}
}