Refactor XCUI editor module layout

This commit is contained in:
2026-04-10 00:41:28 +08:00
parent 4b47764f26
commit 02a0e626fe
263 changed files with 12396 additions and 7592 deletions

View File

@@ -1,4 +1,5 @@
file(TO_CMAKE_PATH "${CMAKE_SOURCE_DIR}" XCENGINE_EDITOR_UI_TESTS_REPO_ROOT_PATH)
file(TO_CMAKE_PATH "${CMAKE_BINARY_DIR}" XCENGINE_EDITOR_UI_TESTS_BUILD_ROOT_PATH)
add_library(editor_ui_validation_registry STATIC
src/EditorValidationScenario.cpp
@@ -38,6 +39,7 @@ target_compile_definitions(editor_ui_integration_host
UNICODE
_UNICODE
XCENGINE_EDITOR_UI_TESTS_REPO_ROOT="${XCENGINE_EDITOR_UI_TESTS_REPO_ROOT_PATH}"
XCENGINE_EDITOR_UI_TESTS_BUILD_ROOT="${XCENGINE_EDITOR_UI_TESTS_BUILD_ROOT_PATH}"
)
if(MSVC)

View File

@@ -11,6 +11,14 @@
#include <unordered_set>
#include <vector>
#ifndef XCENGINE_EDITOR_UI_TESTS_REPO_ROOT
#define XCENGINE_EDITOR_UI_TESTS_REPO_ROOT "."
#endif
#ifndef XCENGINE_EDITOR_UI_TESTS_BUILD_ROOT
#define XCENGINE_EDITOR_UI_TESTS_BUILD_ROOT "."
#endif
namespace XCEngine::Tests::EditorUI {
namespace {
@@ -41,6 +49,55 @@ Application* GetApplicationFromWindow(HWND hwnd) {
return reinterpret_cast<Application*>(GetWindowLongPtrW(hwnd, GWLP_USERDATA));
}
std::filesystem::path GetRepoRootPath() {
std::string root = XCENGINE_EDITOR_UI_TESTS_REPO_ROOT;
if (root.size() >= 2u && root.front() == '"' && root.back() == '"') {
root = root.substr(1u, root.size() - 2u);
}
return std::filesystem::path(root).lexically_normal();
}
std::filesystem::path GetBuildRootPath() {
std::string root = XCENGINE_EDITOR_UI_TESTS_BUILD_ROOT;
if (root.size() >= 2u && root.front() == '"' && root.back() == '"') {
root = root.substr(1u, root.size() - 2u);
}
return std::filesystem::path(root).lexically_normal();
}
bool TryMakeRepoRelativePath(
const std::filesystem::path& absolutePath,
std::filesystem::path& outRelativePath) {
std::error_code errorCode = {};
outRelativePath = std::filesystem::relative(
absolutePath,
GetRepoRootPath(),
errorCode);
if (errorCode || outRelativePath.empty()) {
return false;
}
for (const auto& part : outRelativePath) {
if (part == "..") {
return false;
}
}
return true;
}
std::filesystem::path ResolveCaptureOutputRoot(
const std::filesystem::path& sourceCaptureRoot) {
const std::filesystem::path normalizedSourcePath =
sourceCaptureRoot.lexically_normal();
std::filesystem::path relativePath = {};
if (TryMakeRepoRelativePath(normalizedSourcePath, relativePath)) {
return (GetBuildRootPath() / relativePath).lexically_normal();
}
return (GetBuildRootPath() / "ui_test_captures" / normalizedSourcePath.filename())
.lexically_normal();
}
std::string TruncateText(const std::string& text, std::size_t maxLength) {
if (text.size() <= maxLength) {
return text;
@@ -230,7 +287,8 @@ bool Application::Initialize(HINSTANCE hInstance, int nCmdShow) {
initialScenario = &GetDefaultEditorValidationScenario();
}
m_autoScreenshot.Initialize(initialScenario->captureRootPath);
m_autoScreenshot.Initialize(
ResolveCaptureOutputRoot(initialScenario->captureRootPath));
LoadStructuredScreen("startup");
return true;
}
@@ -406,7 +464,6 @@ bool Application::LoadStructuredScreen(const char* triggerReason) {
m_screenAsset = {};
m_screenAsset.screenId = scenario->id;
m_screenAsset.documentPath = scenario->documentPath.string();
m_screenAsset.themePath = scenario->themePath.string();
const bool loaded = m_screenPlayer.Load(m_screenAsset);
m_useStructuredScreen = loaded;
@@ -463,7 +520,6 @@ void Application::RebuildTrackedFileStates() {
};
appendTrackedPath(m_screenAsset.documentPath);
appendTrackedPath(m_screenAsset.themePath);
if (const auto* document = m_screenPlayer.GetDocument(); document != nullptr) {
for (const std::string& dependency : document->dependencies) {

View File

@@ -33,7 +33,6 @@ const std::array<EditorValidationScenario, 1>& GetEditorValidationScenarios() {
"shell",
"Editor 壳层 | 工作区组合",
RepoRelative("tests/UI/Editor/integration/shell/workspace_shell_compose/View.xcui"),
RepoRelative("tests/UI/Editor/integration/shared/themes/editor_validation.xctheme"),
RepoRelative("tests/UI/Editor/integration/shell/workspace_shell_compose/captures")
}
} };

View File

@@ -16,7 +16,6 @@ struct EditorValidationScenario {
std::string categoryId = {};
std::string displayName = {};
std::filesystem::path documentPath = {};
std::filesystem::path themePath = {};
std::filesystem::path captureRootPath = {};
};

View File

@@ -1,25 +1,9 @@
#pragma once
#include <XCEngine/Core/Containers/String.h>
#include <XCEngine/Core/Math/Color.h>
#include <XCEngine/Resources/UI/UIDocumentCompiler.h>
#include <XCEngine/UI/DrawData.h>
#include <XCEngine/UI/Style/DocumentStyleCompiler.h>
#include <XCEngine/UI/Style/Theme.h>
#include <filesystem>
#include <initializer_list>
#include <string>
#include <string_view>
namespace XCEngine::Tests::EditorUI {
struct EditorValidationThemeLoadResult {
::XCEngine::UI::Style::UITheme theme = {};
std::string error = {};
bool succeeded = false;
};
struct EditorValidationShellPalette {
::XCEngine::UI::UIColor windowBackground = ::XCEngine::UI::UIColor(0.13f, 0.13f, 0.13f, 1.0f);
::XCEngine::UI::UIColor cardBackground = ::XCEngine::UI::UIColor(0.18f, 0.18f, 0.18f, 1.0f);
@@ -41,178 +25,12 @@ struct EditorValidationShellMetrics {
float bodyFontSize = 12.0f;
};
inline ::XCEngine::UI::UIColor ToUIColor(const ::XCEngine::Math::Color& color) {
return ::XCEngine::UI::UIColor(color.r, color.g, color.b, color.a);
inline EditorValidationShellPalette GetEditorValidationShellPalette() {
return {};
}
inline bool TryResolveThemeFloat(
const ::XCEngine::UI::Style::UITheme& theme,
std::string_view tokenName,
float& outValue) {
const auto resolution =
theme.ResolveToken(std::string(tokenName), ::XCEngine::UI::Style::UIStyleValueType::Float);
if (resolution.status != ::XCEngine::UI::Style::UITokenResolveStatus::Resolved) {
return false;
}
const float* value = resolution.value.TryGetFloat();
if (value == nullptr) {
return false;
}
outValue = *value;
return true;
}
inline bool TryResolveThemeColor(
const ::XCEngine::UI::Style::UITheme& theme,
std::string_view tokenName,
::XCEngine::UI::UIColor& outColor) {
const auto resolution =
theme.ResolveToken(std::string(tokenName), ::XCEngine::UI::Style::UIStyleValueType::Color);
if (resolution.status != ::XCEngine::UI::Style::UITokenResolveStatus::Resolved) {
return false;
}
const ::XCEngine::Math::Color* value = resolution.value.TryGetColor();
if (value == nullptr) {
return false;
}
outColor = ToUIColor(*value);
return true;
}
inline float ResolveThemeFloatAliases(
const ::XCEngine::UI::Style::UITheme& theme,
std::initializer_list<std::string_view> tokenNames,
float fallbackValue) {
float resolvedValue = fallbackValue;
for (std::string_view tokenName : tokenNames) {
if (TryResolveThemeFloat(theme, tokenName, resolvedValue)) {
return resolvedValue;
}
}
return fallbackValue;
}
inline ::XCEngine::UI::UIColor ResolveThemeColorAliases(
const ::XCEngine::UI::Style::UITheme& theme,
std::initializer_list<std::string_view> tokenNames,
const ::XCEngine::UI::UIColor& fallbackValue) {
::XCEngine::UI::UIColor resolvedValue = fallbackValue;
for (std::string_view tokenName : tokenNames) {
if (TryResolveThemeColor(theme, tokenName, resolvedValue)) {
return resolvedValue;
}
}
return fallbackValue;
}
inline EditorValidationThemeLoadResult LoadEditorValidationTheme(
const std::filesystem::path& themePath) {
EditorValidationThemeLoadResult result = {};
::XCEngine::Resources::UIDocumentCompileResult compileResult = {};
const ::XCEngine::Containers::String pathString(themePath.generic_string().c_str());
if (!::XCEngine::Resources::CompileUIDocument(
::XCEngine::Resources::UIDocumentCompileRequest {
::XCEngine::Resources::UIDocumentKind::Theme,
pathString,
::XCEngine::Resources::GetUIDocumentDefaultRootTag(
::XCEngine::Resources::UIDocumentKind::Theme)
},
compileResult)) {
result.error = compileResult.errorMessage.Empty()
? std::string("Failed to compile editor validation theme document.")
: std::string(compileResult.errorMessage.CStr());
return result;
}
const auto styleCompileResult =
::XCEngine::UI::Style::CompileDocumentStyle(compileResult.document);
if (!styleCompileResult.succeeded) {
result.error = styleCompileResult.errorMessage;
return result;
}
result.theme = styleCompileResult.theme;
result.succeeded = true;
return result;
}
inline EditorValidationShellPalette ResolveEditorValidationShellPalette(
const ::XCEngine::UI::Style::UITheme& theme) {
EditorValidationShellPalette palette = {};
palette.windowBackground = ResolveThemeColorAliases(
theme,
{ "editor.color.validation.window", "color.bg.workspace" },
palette.windowBackground);
palette.cardBackground = ResolveThemeColorAliases(
theme,
{ "editor.color.validation.card", "color.bg.panel" },
palette.cardBackground);
palette.cardBorder = ResolveThemeColorAliases(
theme,
{ "editor.color.validation.card_border", "editor.color.menu_popup.border" },
palette.cardBorder);
palette.textPrimary = ResolveThemeColorAliases(
theme,
{ "editor.color.validation.text_primary", "color.text.primary" },
palette.textPrimary);
palette.textMuted = ResolveThemeColorAliases(
theme,
{ "editor.color.validation.text_muted", "color.text.muted" },
palette.textMuted);
palette.textWeak = ResolveThemeColorAliases(
theme,
{ "editor.color.validation.text_weak", "color.text.muted" },
palette.textWeak);
palette.textSuccess = ResolveThemeColorAliases(
theme,
{ "editor.color.validation.text_success" },
palette.textSuccess);
palette.buttonBackground = ResolveThemeColorAliases(
theme,
{ "editor.color.validation.button", "color.bg.selection" },
palette.buttonBackground);
palette.buttonHoverBackground = ResolveThemeColorAliases(
theme,
{ "editor.color.validation.button_hover", "editor.color.validation.button", "color.bg.selection" },
palette.buttonHoverBackground);
return palette;
}
inline EditorValidationShellMetrics ResolveEditorValidationShellMetrics(
const ::XCEngine::UI::Style::UITheme& theme) {
EditorValidationShellMetrics metrics = {};
metrics.margin = ResolveThemeFloatAliases(
theme,
{ "editor.space.validation.margin", "space.shell" },
metrics.margin);
metrics.gap = ResolveThemeFloatAliases(
theme,
{ "editor.space.validation.gap" },
metrics.gap);
metrics.cardRadius = ResolveThemeFloatAliases(
theme,
{ "editor.radius.validation.card", "radius.panel" },
metrics.cardRadius);
metrics.buttonRadius = ResolveThemeFloatAliases(
theme,
{ "editor.radius.validation.button", "radius.control" },
metrics.buttonRadius);
metrics.titleFontSize = ResolveThemeFloatAliases(
theme,
{ "editor.font.validation.title" },
metrics.titleFontSize);
metrics.bodyFontSize = ResolveThemeFloatAliases(
theme,
{ "editor.font.validation.body", "editor.font.field.value" },
metrics.bodyFontSize);
return metrics;
inline EditorValidationShellMetrics GetEditorValidationShellMetrics() {
return {};
}
} // namespace XCEngine::Tests::EditorUI

View File

@@ -1,177 +0,0 @@
<Theme name="EditorValidationTheme">
<Tokens>
<Color name="color.bg.workspace" value="#1A1A1A" />
<Color name="color.bg.panel" value="#262626" />
<Color name="color.bg.selection" value="#3A3A3A" />
<Color name="color.text.primary" value="#F2F2F2" />
<Color name="color.text.muted" value="#B4B4B4" />
<Color name="color.text.weak" value="#8F8F8F" />
<Color name="color.text.success" value="#A6C3A6" />
<Color name="color.border.panel" value="#4A4A4A" />
<Color name="color.button.default" value="#343434" />
<Color name="color.button.hover" value="#404040" />
<Spacing name="space.shell" value="18" />
<Spacing name="space.panel" value="12" />
<Radius name="radius.panel" value="10" />
<Radius name="radius.control" value="8" />
<Spacing name="editor.space.validation.margin" value="20" />
<Spacing name="editor.space.validation.gap" value="16" />
<Radius name="editor.radius.validation.card" value="radius.panel" />
<Radius name="editor.radius.validation.button" value="radius.control" />
<Number name="editor.font.validation.title" value="17" />
<Number name="editor.font.validation.body" value="12" />
<Color name="editor.color.validation.window" value="color.bg.workspace" />
<Color name="editor.color.validation.card" value="color.bg.panel" />
<Color name="editor.color.validation.card_border" value="color.border.panel" />
<Color name="editor.color.validation.text_primary" value="color.text.primary" />
<Color name="editor.color.validation.text_muted" value="color.text.muted" />
<Color name="editor.color.validation.text_weak" value="color.text.weak" />
<Color name="editor.color.validation.text_success" value="color.text.success" />
<Color name="editor.color.validation.button" value="color.button.default" />
<Color name="editor.color.validation.button_hover" value="color.button.hover" />
<Number name="editor.size.field.row" value="22" />
<Number name="editor.space.field.padding_x" value="12" />
<Number name="editor.space.field.label_gap" value="20" />
<Number name="editor.layout.field.control_column" value="236" />
<Number name="editor.space.field.control_trailing_inset" value="8" />
<Number name="editor.size.field.checkbox" value="14" />
<Number name="editor.size.field.control_min_width" value="96" />
<Number name="editor.space.field.vector_component_gap" value="6" />
<Number name="editor.size.field.vector_component_min_width" value="72" />
<Number name="editor.size.field.vector_prefix_width" value="9" />
<Number name="editor.space.field.vector_prefix_gap" value="4" />
<Number name="editor.space.field.vector_prefix_inset_x" value="0" />
<Number name="editor.space.field.vector_prefix_inset_y" value="-1" />
<Number name="editor.space.field.control_inset_y" value="1" />
<Number name="editor.space.field.label_inset_y" value="0" />
<Number name="editor.space.field.value_inset_x" value="5" />
<Number name="editor.space.field.value_inset_y" value="0" />
<Number name="editor.space.field.checkbox_glyph_inset_x" value="1" />
<Number name="editor.space.field.checkbox_glyph_inset_y" value="-2" />
<Number name="editor.size.field.dropdown_arrow_width" value="16" />
<Number name="editor.space.field.dropdown_arrow_inset_x" value="4" />
<Number name="editor.space.field.dropdown_arrow_inset_y" value="3" />
<Number name="editor.radius.field.row" value="0" />
<Number name="editor.radius.field.control" value="2" />
<Number name="editor.border.field" value="1" />
<Number name="editor.border.field.focus" value="1" />
<Number name="editor.font.field.label" value="11" />
<Number name="editor.font.field.value" value="12" />
<Number name="editor.font.field.glyph" value="10" />
<Color name="editor.color.field.row" value="#00000000" />
<Color name="editor.color.field.row_hover" value="#2A2A2AFF" />
<Color name="editor.color.field.row_active" value="#313131FF" />
<Color name="editor.color.field.border" value="#00000000" />
<Color name="editor.color.field.border_focus" value="#00000000" />
<Color name="editor.color.field.label" value="#C9C9C9FF" />
<Color name="editor.color.field.value" value="#EEEEEEFF" />
<Color name="editor.color.field.value_readonly" value="#8E8E8EFF" />
<Color name="editor.color.field.control" value="#2E2E2EFF" />
<Color name="editor.color.field.control_hover" value="#353535FF" />
<Color name="editor.color.field.control_editing" value="#3A3A3AFF" />
<Color name="editor.color.field.control_readonly" value="#252525FF" />
<Color name="editor.color.field.control_border" value="#242424FF" />
<Color name="editor.color.field.control_border_focus" value="#2A2A2AFF" />
<Color name="editor.color.field.vector_prefix" value="#222222FF" />
<Color name="editor.color.field.vector_prefix_border" value="#343434FF" />
<Color name="editor.color.field.vector_axis_x" value="#A8A8A8FF" />
<Color name="editor.color.field.vector_axis_y" value="#A8A8A8FF" />
<Color name="editor.color.field.vector_axis_z" value="#A8A8A8FF" />
<Color name="editor.color.field.checkbox" value="#1C1C1CFF" />
<Color name="editor.color.field.checkbox_hover" value="#202020FF" />
<Color name="editor.color.field.checkbox_border" value="#343434FF" />
<Color name="editor.color.field.checkbox_mark" value="#D8D8D8FF" />
<Color name="editor.color.field.dropdown_arrow" value="#D0D0D0FF" />
<Number name="editor.space.property.content_inset" value="6" />
<Number name="editor.space.property.section_gap" value="4" />
<Number name="editor.size.property.section_header" value="24" />
<Number name="editor.size.property.field_row" value="24" />
<Number name="editor.space.property.row_gap" value="1" />
<Number name="editor.size.property.disclosure" value="10" />
<Number name="editor.space.property.disclosure_label_gap" value="6" />
<Number name="editor.space.property.section_inset_y" value="5" />
<Number name="editor.space.property.disclosure_glyph_inset_x" value="1" />
<Number name="editor.space.property.disclosure_glyph_inset_y" value="-1" />
<Number name="editor.space.property.label_inset_y" value="5" />
<Number name="editor.space.property.value_inset_y" value="4" />
<Number name="editor.space.property.value_box_inset_y" value="2" />
<Number name="editor.space.property.value_box_inset_x" value="6" />
<Number name="editor.radius.property.panel" value="0" />
<Number name="editor.radius.property.value" value="2" />
<Number name="editor.border.property" value="1" />
<Number name="editor.border.property.focus" value="1" />
<Number name="editor.border.property.edit" value="1" />
<Number name="editor.font.property.section" value="11" />
<Number name="editor.font.property.disclosure" value="10" />
<Number name="editor.font.property.label" value="11" />
<Number name="editor.font.property.value" value="12" />
<Number name="editor.font.property.tag" value="10" />
<Color name="editor.color.property.surface" value="#232323FF" />
<Color name="editor.color.property.border" value="#171717FF" />
<Color name="editor.color.property.border_focus" value="#717171FF" />
<Color name="editor.color.property.section" value="#2B2B2BFF" />
<Color name="editor.color.property.section_hover" value="#313131FF" />
<Color name="editor.color.property.field_hover" value="#262626FF" />
<Color name="editor.color.property.field_selected" value="#303030FF" />
<Color name="editor.color.property.field_selected_focused" value="#393939FF" />
<Color name="editor.color.property.value" value="#1C1C1CFF" />
<Color name="editor.color.property.value_hover" value="#222222FF" />
<Color name="editor.color.property.value_editing" value="#292929FF" />
<Color name="editor.color.property.value_readonly" value="#171717FF" />
<Color name="editor.color.property.value_border" value="#343434FF" />
<Color name="editor.color.property.value_border_editing" value="#767676FF" />
<Color name="editor.color.property.disclosure" value="#C9C9C9FF" />
<Color name="editor.color.property.section_text" value="#E2E2E2FF" />
<Color name="editor.color.property.label" value="#CDCDCDFF" />
<Color name="editor.color.property.value_text" value="#EFEFEFFF" />
<Color name="editor.color.property.value_text_readonly" value="#8E8E8EFF" />
<Color name="editor.color.property.edit_tag" value="#82A7DAFF" />
<Number name="editor.space.menu_popup.padding_x" value="6" />
<Number name="editor.space.menu_popup.padding_y" value="5" />
<Number name="editor.size.menu_popup.item" value="24" />
<Number name="editor.size.menu_popup.separator" value="8" />
<Number name="editor.size.menu_popup.check_column" value="16" />
<Number name="editor.space.menu_popup.shortcut_gap" value="18" />
<Number name="editor.size.menu_popup.submenu_indicator" value="12" />
<Number name="editor.radius.menu_popup.row" value="3" />
<Number name="editor.radius.menu_popup.surface" value="4" />
<Number name="editor.space.menu_popup.label_inset_x" value="10" />
<Number name="editor.space.menu_popup.label_inset_y" value="-1" />
<Number name="editor.font.menu_popup.label" value="11" />
<Number name="editor.space.menu_popup.shortcut_inset_right" value="18" />
<Number name="editor.size.menu_popup.estimated_glyph_width" value="6" />
<Number name="editor.font.menu_popup.glyph" value="10" />
<Number name="editor.border.menu_popup.separator" value="1" />
<Number name="editor.border.menu_popup.surface" value="1" />
<Color name="editor.color.menu_popup.surface" value="#242424FF" />
<Color name="editor.color.menu_popup.border" value="#343434FF" />
<Color name="editor.color.menu_popup.item_hover" value="#2C2C2CFF" />
<Color name="editor.color.menu_popup.item_open" value="#313131FF" />
<Color name="editor.color.menu_popup.separator" value="#3A3A3AFF" />
<Color name="editor.color.menu_popup.label" value="#E8E8E8FF" />
<Color name="editor.color.menu_popup.text_muted" value="#B9B9B9FF" />
<Color name="editor.color.menu_popup.text_disabled" value="#757575FF" />
<Color name="editor.color.menu_popup.glyph" value="#D0D0D0FF" />
</Tokens>
<Widgets>
<Widget type="View" style="EditorValidationWorkspace">
<Property name="background" value="color.bg.workspace" />
<Property name="padding" value="space.shell" />
</Widget>
<Widget type="Card" style="EditorShellPanel">
<Property name="background" value="color.bg.panel" />
<Property name="radius" value="radius.panel" />
<Property name="padding" value="space.panel" />
</Widget>
<Widget type="Button" style="EditorShellChip">
<Property name="background" value="color.bg.selection" />
<Property name="radius" value="radius.control" />
</Widget>
</Widgets>
</Theme>