Unify inspector and console panel actions

This commit is contained in:
2026-03-27 00:08:46 +08:00
parent 31675e00c8
commit 3ebad63874
15 changed files with 296 additions and 142 deletions

View File

@@ -0,0 +1,36 @@
#pragma once
#include <XCEngine/Debug/LogCategory.h>
#include <XCEngine/Debug/LogEntry.h>
#include <XCEngine/Debug/LogLevel.h>
#include <string>
namespace XCEngine {
namespace Editor {
namespace UI {
inline const char* ConsoleLogPrefix(::XCEngine::Debug::LogLevel level) {
switch (level) {
case ::XCEngine::Debug::LogLevel::Verbose:
case ::XCEngine::Debug::LogLevel::Debug:
case ::XCEngine::Debug::LogLevel::Info:
return "[INFO] ";
case ::XCEngine::Debug::LogLevel::Warning:
return "[WARN] ";
case ::XCEngine::Debug::LogLevel::Error:
case ::XCEngine::Debug::LogLevel::Fatal:
return "[ERROR] ";
}
return "[LOG] ";
}
inline std::string BuildConsoleLogText(const ::XCEngine::Debug::LogEntry& log) {
const char* category = ::XCEngine::Debug::LogCategoryToString(log.category);
return std::string(ConsoleLogPrefix(log.level)) + "[" + category + "] " + log.message.CStr();
}
} // namespace UI
} // namespace Editor
} // namespace XCEngine

View File

@@ -2,6 +2,7 @@
#include "BaseTheme.h"
#include "ConsoleFilterState.h"
#include "ConsoleLogFormatter.h"
#include "Core.h"
#include "DockHostStyle.h"
#include "PanelChrome.h"

View File

@@ -11,7 +11,6 @@ namespace UI {
struct ComponentSectionResult {
bool open = false;
bool removeRequested = false;
};
struct HierarchyNodeResult {
@@ -281,10 +280,11 @@ inline void DrawAssetIcon(ImDrawList* drawList, const ImVec2& min, const ImVec2&
drawList->AddLine(foldA, foldB, lineColor);
}
template <typename DrawMenuFn>
inline ComponentSectionResult BeginComponentSection(
const void* id,
const char* label,
bool canRemove,
DrawMenuFn&& drawMenu,
bool defaultOpen = true) {
const ImGuiStyle& style = ImGui::GetStyle();
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, InspectorSectionFramePadding());
@@ -302,15 +302,19 @@ inline ComponentSectionResult BeginComponentSection(
const bool open = ImGui::TreeNodeEx(id, flags, "%s", label);
ImGui::PopStyleVar(2);
bool removeRequested = false;
if (BeginPopupContextItem("##ComponentSettings")) {
DrawMenuCommand(MenuCommand::Action("Remove Component", nullptr, false, canRemove), [&]() {
removeRequested = true;
});
drawMenu();
EndPopup();
}
return ComponentSectionResult{ open, removeRequested };
return ComponentSectionResult{ open };
}
inline ComponentSectionResult BeginComponentSection(
const void* id,
const char* label,
bool defaultOpen = true) {
return BeginComponentSection(id, label, []() {}, defaultOpen);
}
inline void EndComponentSection() {