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,10 +1,11 @@
#ifndef NOMINMAX
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <XCEditor/Core/UIEditorTextFieldInteraction.h>
#include <XCEditor/Core/UIEditorTheme.h>
#include <XCEditor/Widgets/UIEditorTextField.h>
#include <XCEditor/Fields/UIEditorTextFieldInteraction.h>
#include <XCEditor/Fields/UIEditorFieldStyle.h>
#include <XCEditor/Fields/UIEditorTextField.h>
#include <XCEditor/Foundation/UIEditorTheme.h>
#include "EditorValidationTheme.h"
#include "Host/AutoScreenshot.h"
#include "Host/NativeRenderer.h"
@@ -25,6 +26,8 @@
#define XCENGINE_EDITOR_UI_TESTS_REPO_ROOT "."
#endif
// 场景说明:验证固定样式下 TextField 的基础编辑、提交、取消与焦点切换。
namespace {
using XCEngine::Input::KeyCode;
@@ -46,7 +49,6 @@ using XCEngine::UI::Editor::Widgets::HitTestUIEditorTextField;
using XCEngine::UI::Editor::Widgets::UIEditorTextFieldHitTarget;
using XCEngine::UI::Editor::Widgets::UIEditorTextFieldHitTargetKind;
using XCEngine::UI::Editor::Widgets::UIEditorTextFieldSpec;
namespace Style = XCEngine::UI::Style;
constexpr const wchar_t* kWindowClassName = L"XCUIEditorTextFieldBasicValidation";
constexpr const wchar_t* kWindowTitle = L"XCUI Editor | TextField Basic";
@@ -83,10 +85,6 @@ std::filesystem::path ResolveRepoRootPath() {
return std::filesystem::path(root).lexically_normal();
}
std::filesystem::path ResolveValidationThemePath() {
return (ResolveRepoRootPath() / "tests/UI/Editor/integration/shared/themes/editor_validation.xctheme")
.lexically_normal();
}
bool ContainsPoint(const UIRect& rect, float x, float y) {
return x >= rect.x &&
@@ -157,18 +155,16 @@ ScenarioLayout BuildScenarioLayout(
return layout;
}
XCEngine::UI::Editor::Widgets::UIEditorTextFieldMetrics ResolveHostedTextFieldMetrics(
const Style::UITheme& theme) {
const auto propertyMetrics = XCEngine::UI::Editor::ResolveUIEditorPropertyGridMetrics(theme);
const auto textMetrics = XCEngine::UI::Editor::ResolveUIEditorTextFieldMetrics(theme);
return XCEngine::UI::Editor::BuildUIEditorHostedTextFieldMetrics(propertyMetrics, textMetrics);
XCEngine::UI::Editor::Widgets::UIEditorTextFieldMetrics ResolvePropertyGridTextFieldMetrics() {
return XCEngine::UI::Editor::BuildUIEditorPropertyGridTextFieldMetrics(
XCEngine::UI::Editor::ResolveUIEditorPropertyGridMetrics(),
XCEngine::UI::Editor::ResolveUIEditorTextFieldMetrics());
}
XCEngine::UI::Editor::Widgets::UIEditorTextFieldPalette ResolveHostedTextFieldPalette(
const Style::UITheme& theme) {
const auto propertyPalette = XCEngine::UI::Editor::ResolveUIEditorPropertyGridPalette(theme);
const auto textPalette = XCEngine::UI::Editor::ResolveUIEditorTextFieldPalette(theme);
return XCEngine::UI::Editor::BuildUIEditorHostedTextFieldPalette(propertyPalette, textPalette);
XCEngine::UI::Editor::Widgets::UIEditorTextFieldPalette ResolvePropertyGridTextFieldPalette() {
return XCEngine::UI::Editor::BuildUIEditorPropertyGridTextFieldPalette(
XCEngine::UI::Editor::ResolveUIEditorPropertyGridPalette(),
XCEngine::UI::Editor::ResolveUIEditorTextFieldPalette());
}
void DrawCard(
@@ -427,14 +423,6 @@ private:
m_captureRoot =
ResolveRepoRootPath() / "tests/UI/Editor/integration/shell/text_field_basic/captures";
m_autoScreenshot.Initialize(m_captureRoot);
const auto themeLoad =
XCEngine::Tests::EditorUI::LoadEditorValidationTheme(ResolveValidationThemePath());
if (themeLoad.succeeded) {
m_theme = themeLoad.theme;
m_themeStatus = "loaded";
} else {
m_themeStatus = themeLoad.error.empty() ? "fallback" : themeLoad.error;
}
ResetScenario();
return true;
@@ -463,7 +451,7 @@ private:
return BuildScenarioLayout(
width,
height,
XCEngine::Tests::EditorUI::ResolveEditorValidationShellMetrics(m_theme));
XCEngine::Tests::EditorUI::GetEditorValidationShellMetrics());
}
void ResetScenario() {
@@ -487,7 +475,7 @@ private:
}
const ScenarioLayout layout = GetLayout();
const auto metrics = ResolveHostedTextFieldMetrics(m_theme);
const auto metrics = ResolvePropertyGridTextFieldMetrics();
m_frame = UpdateUIEditorTextFieldInteraction(
m_interactionState,
m_spec,
@@ -605,7 +593,7 @@ private:
UIEditorTextFieldInteractionResult PumpEvents(std::vector<UIInputEvent> events) {
const ScenarioLayout layout = GetLayout();
const auto metrics = ResolveHostedTextFieldMetrics(m_theme);
const auto metrics = ResolvePropertyGridTextFieldMetrics();
m_frame = UpdateUIEditorTextFieldInteraction(
m_interactionState,
m_spec,
@@ -661,16 +649,16 @@ private:
GetClientRect(m_hwnd, &clientRect);
const float width = static_cast<float>((std::max)(1L, clientRect.right - clientRect.left));
const float height = static_cast<float>((std::max)(1L, clientRect.bottom - clientRect.top));
const auto shellMetrics = XCEngine::Tests::EditorUI::ResolveEditorValidationShellMetrics(m_theme);
const auto shellPalette = XCEngine::Tests::EditorUI::ResolveEditorValidationShellPalette(m_theme);
const auto shellMetrics = XCEngine::Tests::EditorUI::GetEditorValidationShellMetrics();
const auto shellPalette = XCEngine::Tests::EditorUI::GetEditorValidationShellPalette();
const ScenarioLayout layout = BuildScenarioLayout(width, height, shellMetrics);
RefreshFrame();
const UIEditorTextFieldHitTarget currentHit =
HitTestUIEditorTextField(m_frame.layout, m_mousePosition);
const auto textMetrics = ResolveHostedTextFieldMetrics(m_theme);
const auto textPalette = ResolveHostedTextFieldPalette(m_theme);
const auto propertyPalette = XCEngine::UI::Editor::ResolveUIEditorPropertyGridPalette(m_theme);
const auto textMetrics = ResolvePropertyGridTextFieldMetrics();
const auto textPalette = ResolvePropertyGridTextFieldPalette();
const auto propertyPalette = XCEngine::UI::Editor::ResolveUIEditorPropertyGridPalette();
UIDrawData drawData = {};
UIDrawList& drawList = drawData.EmplaceDrawList("EditorTextFieldBasic");
@@ -681,8 +669,8 @@ private:
layout.introRect,
shellPalette,
shellMetrics,
"这个测试验证什么功能",
"验证 UIEditorTextField 的基础编辑交互契约,不涉及 PropertyGrid 或业务 Inspector。");
"这个测试验证什么功能",
"验证 UIEditorTextField 的基础编辑契约,不涉及 PropertyGrid 或任何 Inspector 业务逻辑");
drawList.AddText(
UIPoint(layout.introRect.x + 16.0f, layout.introRect.y + 72.0f),
"1. 点击 value box检查是否进入编辑态。",
@@ -775,7 +763,7 @@ private:
shellMetrics.bodyFontSize);
drawList.AddText(
UIPoint(layout.stateRect.x + 16.0f, layout.stateRect.y + 238.0f),
"Theme: " + m_themeStatus,
"Style: fixed",
shellPalette.textWeak,
shellMetrics.bodyFontSize);
@@ -785,7 +773,7 @@ private:
shellPalette,
shellMetrics,
"TextField 预览",
"这里只放一个 Editor TextField用来验证基础字段行为。");
"这里只放一个固定样式 TextField用来验证基础字段行为。");
drawList.AddFilledRect(layout.inspectorRect, propertyPalette.surfaceColor);
drawList.AddRectOutline(layout.inspectorRect, propertyPalette.borderColor, 1.0f);
drawList.AddFilledRect(layout.inspectorHeaderRect, shellPalette.cardBackground);
@@ -827,12 +815,10 @@ private:
UIEditorTextFieldSpec m_spec = {};
UIEditorTextFieldInteractionState m_interactionState = {};
UIEditorTextFieldInteractionFrame m_frame = {};
Style::UITheme m_theme = {};
UIPoint m_mousePosition = UIPoint(-1000.0f, -1000.0f);
ActionId m_hoveredAction = ActionId::Reset;
bool m_hasHoveredAction = false;
std::string m_lastResult = {};
std::string m_themeStatus = "fallback";
};
} // namespace