Refactor XCUI editor module layout
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
add_executable(editor_ui_asset_field_basic_validation WIN32
|
||||
main.cpp
|
||||
)
|
||||
|
||||
target_include_directories(editor_ui_asset_field_basic_validation PRIVATE
|
||||
${CMAKE_SOURCE_DIR}/tests/UI/Editor/integration/shared/src
|
||||
${CMAKE_SOURCE_DIR}/new_editor/include
|
||||
${CMAKE_SOURCE_DIR}/new_editor/app
|
||||
${CMAKE_SOURCE_DIR}/engine/include
|
||||
)
|
||||
|
||||
target_compile_definitions(editor_ui_asset_field_basic_validation PRIVATE
|
||||
UNICODE
|
||||
_UNICODE
|
||||
XCENGINE_EDITOR_UI_TESTS_REPO_ROOT="${XCENGINE_EDITOR_UI_TESTS_REPO_ROOT_PATH}"
|
||||
)
|
||||
|
||||
if(MSVC)
|
||||
target_compile_options(editor_ui_asset_field_basic_validation PRIVATE /utf-8 /FS)
|
||||
set_property(TARGET editor_ui_asset_field_basic_validation PROPERTY
|
||||
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
|
||||
endif()
|
||||
|
||||
target_link_libraries(editor_ui_asset_field_basic_validation PRIVATE
|
||||
XCUIEditorLib
|
||||
XCUIEditorHost
|
||||
)
|
||||
|
||||
set_target_properties(editor_ui_asset_field_basic_validation PROPERTIES
|
||||
OUTPUT_NAME "XCUIEditorAssetFieldBasicValidation"
|
||||
)
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
736
tests/UI/Editor/integration/shell/asset_field_basic/main.cpp
Normal file
736
tests/UI/Editor/integration/shell/asset_field_basic/main.cpp
Normal file
@@ -0,0 +1,736 @@
|
||||
#ifndef NOMINMAX
|
||||
#define NOMINMAX
|
||||
#endif
|
||||
|
||||
#include <XCEditor/Foundation/UIEditorTheme.h>
|
||||
#include <XCEditor/Fields/UIEditorAssetField.h>
|
||||
#include <XCEditor/Fields/UIEditorAssetFieldInteraction.h>
|
||||
#include "EditorValidationTheme.h"
|
||||
#include "Host/AutoScreenshot.h"
|
||||
#include "Host/NativeRenderer.h"
|
||||
|
||||
#include <XCEngine/Input/InputTypes.h>
|
||||
#include <XCEngine/UI/DrawData.h>
|
||||
|
||||
#include <windows.h>
|
||||
#include <windowsx.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <filesystem>
|
||||
#include <iterator>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
#ifndef XCENGINE_EDITOR_UI_TESTS_REPO_ROOT
|
||||
#define XCENGINE_EDITOR_UI_TESTS_REPO_ROOT "."
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
|
||||
using XCEngine::Input::KeyCode;
|
||||
using XCEngine::UI::UIColor;
|
||||
using XCEngine::UI::UIDrawData;
|
||||
using XCEngine::UI::UIDrawList;
|
||||
using XCEngine::UI::UIInputEvent;
|
||||
using XCEngine::UI::UIInputEventType;
|
||||
using XCEngine::UI::UIPoint;
|
||||
using XCEngine::UI::UIPointerButton;
|
||||
using XCEngine::UI::UIRect;
|
||||
using XCEngine::UI::Editor::Host::AutoScreenshotController;
|
||||
using XCEngine::UI::Editor::Host::NativeRenderer;
|
||||
using XCEngine::UI::Editor::UIEditorAssetFieldInteractionFrame;
|
||||
using XCEngine::UI::Editor::UIEditorAssetFieldInteractionResult;
|
||||
using XCEngine::UI::Editor::UIEditorAssetFieldInteractionState;
|
||||
using XCEngine::UI::Editor::UpdateUIEditorAssetFieldInteraction;
|
||||
using XCEngine::UI::Editor::Widgets::AppendUIEditorAssetField;
|
||||
using XCEngine::UI::Editor::Widgets::HitTestUIEditorAssetField;
|
||||
using XCEngine::UI::Editor::Widgets::UIEditorAssetFieldHitTarget;
|
||||
using XCEngine::UI::Editor::Widgets::UIEditorAssetFieldHitTargetKind;
|
||||
using XCEngine::UI::Editor::Widgets::UIEditorAssetFieldPalette;
|
||||
using XCEngine::UI::Editor::Widgets::UIEditorAssetFieldSpec;
|
||||
|
||||
constexpr const wchar_t* kWindowClassName = L"XCUIEditorAssetFieldBasicValidation";
|
||||
constexpr const wchar_t* kWindowTitle = L"XCUI Editor | AssetField Basic";
|
||||
|
||||
enum class ActionId : unsigned char {
|
||||
None = 0,
|
||||
Reset,
|
||||
Capture
|
||||
};
|
||||
|
||||
struct ButtonLayout {
|
||||
ActionId action = ActionId::None;
|
||||
const char* label = "";
|
||||
UIRect rect = {};
|
||||
};
|
||||
|
||||
struct ScenarioLayout {
|
||||
UIRect introRect = {};
|
||||
UIRect controlRect = {};
|
||||
UIRect stateRect = {};
|
||||
UIRect previewRect = {};
|
||||
UIRect fieldRect = {};
|
||||
std::vector<ButtonLayout> buttons = {};
|
||||
};
|
||||
|
||||
struct SampleAsset {
|
||||
const char* assetId = "";
|
||||
const char* displayName = "";
|
||||
const char* statusText = "";
|
||||
UIColor tint = {};
|
||||
};
|
||||
|
||||
constexpr SampleAsset kSampleAssets[] = {
|
||||
{
|
||||
"assets/textures/crate_albedo",
|
||||
"Crate_Albedo",
|
||||
"Ready",
|
||||
UIColor(0.30f, 0.55f, 0.84f, 1.0f)
|
||||
},
|
||||
{
|
||||
"assets/materials/sci_fi_panel",
|
||||
"SciFi_Panel",
|
||||
"Dirty",
|
||||
UIColor(0.77f, 0.56f, 0.28f, 1.0f)
|
||||
}
|
||||
};
|
||||
|
||||
std::filesystem::path ResolveRepoRootPath() {
|
||||
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();
|
||||
}
|
||||
|
||||
bool ContainsPoint(const UIRect& rect, float x, float y) {
|
||||
return x >= rect.x &&
|
||||
x <= rect.x + rect.width &&
|
||||
y >= rect.y &&
|
||||
y <= rect.y + rect.height;
|
||||
}
|
||||
|
||||
std::int32_t MapAssetFieldKey(UINT keyCode) {
|
||||
switch (keyCode) {
|
||||
case VK_SPACE:
|
||||
return static_cast<std::int32_t>(KeyCode::Space);
|
||||
case VK_RETURN:
|
||||
return static_cast<std::int32_t>(KeyCode::Enter);
|
||||
case VK_DELETE:
|
||||
return static_cast<std::int32_t>(KeyCode::Delete);
|
||||
case VK_BACK:
|
||||
return static_cast<std::int32_t>(KeyCode::Backspace);
|
||||
default:
|
||||
return static_cast<std::int32_t>(KeyCode::None);
|
||||
}
|
||||
}
|
||||
|
||||
ScenarioLayout BuildScenarioLayout(
|
||||
float width,
|
||||
float height,
|
||||
const XCEngine::Tests::EditorUI::EditorValidationShellMetrics& shellMetrics) {
|
||||
const float margin = shellMetrics.margin;
|
||||
constexpr float leftWidth = 470.0f;
|
||||
const float gap = shellMetrics.gap;
|
||||
|
||||
ScenarioLayout layout = {};
|
||||
layout.introRect = UIRect(margin, margin, leftWidth, 260.0f);
|
||||
layout.controlRect = UIRect(margin, layout.introRect.y + layout.introRect.height + gap, leftWidth, 84.0f);
|
||||
layout.stateRect = UIRect(
|
||||
margin,
|
||||
layout.controlRect.y + layout.controlRect.height + gap,
|
||||
leftWidth,
|
||||
(std::max)(220.0f, height - (layout.controlRect.y + layout.controlRect.height + gap) - margin));
|
||||
layout.previewRect = UIRect(
|
||||
leftWidth + margin * 2.0f,
|
||||
margin,
|
||||
(std::max)(420.0f, width - leftWidth - margin * 3.0f),
|
||||
height - margin * 2.0f);
|
||||
layout.fieldRect = UIRect(
|
||||
layout.previewRect.x + 28.0f,
|
||||
layout.previewRect.y + 96.0f,
|
||||
(std::min)(460.0f, layout.previewRect.width - 56.0f),
|
||||
22.0f);
|
||||
|
||||
const float buttonWidth = (layout.controlRect.width - 44.0f) * 0.5f;
|
||||
const float buttonY = layout.controlRect.y + 32.0f;
|
||||
layout.buttons = {
|
||||
{ ActionId::Reset, "重置", UIRect(layout.controlRect.x + 14.0f, buttonY, buttonWidth, 36.0f) },
|
||||
{ ActionId::Capture, "截图(F12)", UIRect(layout.controlRect.x + 26.0f + buttonWidth, buttonY, buttonWidth, 36.0f) }
|
||||
};
|
||||
return layout;
|
||||
}
|
||||
|
||||
void DrawCard(
|
||||
UIDrawList& drawList,
|
||||
const UIRect& rect,
|
||||
const XCEngine::Tests::EditorUI::EditorValidationShellPalette& shellPalette,
|
||||
const XCEngine::Tests::EditorUI::EditorValidationShellMetrics& shellMetrics,
|
||||
std::string_view title,
|
||||
std::string_view subtitle = {}) {
|
||||
drawList.AddFilledRect(rect, shellPalette.cardBackground, shellMetrics.cardRadius);
|
||||
drawList.AddRectOutline(rect, shellPalette.cardBorder, 1.0f, shellMetrics.cardRadius);
|
||||
drawList.AddText(
|
||||
UIPoint(rect.x + 16.0f, rect.y + 14.0f),
|
||||
std::string(title),
|
||||
shellPalette.textPrimary,
|
||||
shellMetrics.titleFontSize);
|
||||
if (!subtitle.empty()) {
|
||||
drawList.AddText(
|
||||
UIPoint(rect.x + 16.0f, rect.y + 40.0f),
|
||||
std::string(subtitle),
|
||||
shellPalette.textMuted,
|
||||
shellMetrics.bodyFontSize);
|
||||
}
|
||||
}
|
||||
|
||||
void DrawButton(
|
||||
UIDrawList& drawList,
|
||||
const ButtonLayout& button,
|
||||
const XCEngine::Tests::EditorUI::EditorValidationShellPalette& shellPalette,
|
||||
const XCEngine::Tests::EditorUI::EditorValidationShellMetrics& shellMetrics,
|
||||
bool hovered) {
|
||||
drawList.AddFilledRect(
|
||||
button.rect,
|
||||
hovered ? shellPalette.buttonHoverBackground : shellPalette.buttonBackground,
|
||||
shellMetrics.buttonRadius);
|
||||
drawList.AddRectOutline(button.rect, shellPalette.cardBorder, 1.0f, shellMetrics.buttonRadius);
|
||||
drawList.AddText(
|
||||
UIPoint(button.rect.x + 16.0f, button.rect.y + 10.0f),
|
||||
button.label,
|
||||
shellPalette.textPrimary,
|
||||
shellMetrics.bodyFontSize);
|
||||
}
|
||||
|
||||
std::string DescribeHitTarget(const UIEditorAssetFieldHitTarget& hitTarget) {
|
||||
switch (hitTarget.kind) {
|
||||
case UIEditorAssetFieldHitTargetKind::ValueBox:
|
||||
return "value_box";
|
||||
case UIEditorAssetFieldHitTargetKind::PickerButton:
|
||||
return "picker_button";
|
||||
case UIEditorAssetFieldHitTargetKind::ClearButton:
|
||||
return "clear_button";
|
||||
case UIEditorAssetFieldHitTargetKind::Row:
|
||||
return "row";
|
||||
case UIEditorAssetFieldHitTargetKind::None:
|
||||
default:
|
||||
return "none";
|
||||
}
|
||||
}
|
||||
|
||||
UIInputEvent MakePointerEvent(
|
||||
UIInputEventType type,
|
||||
const UIPoint& position,
|
||||
UIPointerButton button = UIPointerButton::None) {
|
||||
UIInputEvent event = {};
|
||||
event.type = type;
|
||||
event.position = position;
|
||||
event.pointerButton = button;
|
||||
return event;
|
||||
}
|
||||
|
||||
UIInputEvent MakeKeyEvent(std::int32_t keyCode) {
|
||||
UIInputEvent event = {};
|
||||
event.type = UIInputEventType::KeyDown;
|
||||
event.keyCode = keyCode;
|
||||
return event;
|
||||
}
|
||||
|
||||
UIInputEvent MakeFocusEvent(UIInputEventType type) {
|
||||
UIInputEvent event = {};
|
||||
event.type = type;
|
||||
return event;
|
||||
}
|
||||
|
||||
class ScenarioApp {
|
||||
public:
|
||||
int Run(HINSTANCE hInstance, int nCmdShow) {
|
||||
if (!Initialize(hInstance, nCmdShow)) {
|
||||
Shutdown();
|
||||
return 1;
|
||||
}
|
||||
|
||||
MSG message = {};
|
||||
while (message.message != WM_QUIT) {
|
||||
if (PeekMessageW(&message, nullptr, 0U, 0U, PM_REMOVE)) {
|
||||
TranslateMessage(&message);
|
||||
DispatchMessageW(&message);
|
||||
continue;
|
||||
}
|
||||
|
||||
RenderFrame();
|
||||
Sleep(8);
|
||||
}
|
||||
|
||||
Shutdown();
|
||||
return static_cast<int>(message.wParam);
|
||||
}
|
||||
|
||||
private:
|
||||
static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
|
||||
if (message == WM_NCCREATE) {
|
||||
const auto* createStruct = reinterpret_cast<CREATESTRUCTW*>(lParam);
|
||||
auto* app = static_cast<ScenarioApp*>(createStruct->lpCreateParams);
|
||||
SetWindowLongPtrW(hwnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(app));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
auto* app = reinterpret_cast<ScenarioApp*>(GetWindowLongPtrW(hwnd, GWLP_USERDATA));
|
||||
if (app == nullptr) {
|
||||
return DefWindowProcW(hwnd, message, wParam, lParam);
|
||||
}
|
||||
return app->HandleMessage(hwnd, message, wParam, lParam);
|
||||
}
|
||||
|
||||
bool Initialize(HINSTANCE hInstance, int nCmdShow) {
|
||||
m_hInstance = hInstance;
|
||||
|
||||
WNDCLASSEXW windowClass = {};
|
||||
windowClass.cbSize = sizeof(windowClass);
|
||||
windowClass.style = CS_HREDRAW | CS_VREDRAW;
|
||||
windowClass.lpfnWndProc = &ScenarioApp::WndProc;
|
||||
windowClass.hInstance = hInstance;
|
||||
windowClass.hCursor = LoadCursorW(nullptr, IDC_ARROW);
|
||||
windowClass.lpszClassName = kWindowClassName;
|
||||
|
||||
m_windowClassAtom = RegisterClassExW(&windowClass);
|
||||
if (m_windowClassAtom == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_hwnd = CreateWindowExW(
|
||||
0,
|
||||
kWindowClassName,
|
||||
kWindowTitle,
|
||||
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
|
||||
CW_USEDEFAULT,
|
||||
CW_USEDEFAULT,
|
||||
1440,
|
||||
860,
|
||||
nullptr,
|
||||
nullptr,
|
||||
hInstance,
|
||||
this);
|
||||
if (m_hwnd == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ShowWindow(m_hwnd, nCmdShow);
|
||||
UpdateWindow(m_hwnd);
|
||||
|
||||
if (!m_renderer.Initialize(m_hwnd)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_shellPalette = XCEngine::Tests::EditorUI::GetEditorValidationShellPalette();
|
||||
m_shellMetrics = XCEngine::Tests::EditorUI::GetEditorValidationShellMetrics();
|
||||
m_fieldMetrics = XCEngine::UI::Editor::ResolveUIEditorAssetFieldMetrics();
|
||||
m_fieldPalette = XCEngine::UI::Editor::ResolveUIEditorAssetFieldPalette();
|
||||
|
||||
m_captureRoot =
|
||||
ResolveRepoRootPath() / "tests/UI/Editor/integration/shell/asset_field_basic/captures";
|
||||
m_autoScreenshot.Initialize(m_captureRoot);
|
||||
ResetScenario();
|
||||
return true;
|
||||
}
|
||||
|
||||
void Shutdown() {
|
||||
m_autoScreenshot.Shutdown();
|
||||
m_renderer.Shutdown();
|
||||
|
||||
if (m_hwnd != nullptr && IsWindow(m_hwnd)) {
|
||||
DestroyWindow(m_hwnd);
|
||||
}
|
||||
m_hwnd = nullptr;
|
||||
|
||||
if (m_windowClassAtom != 0 && m_hInstance != nullptr) {
|
||||
UnregisterClassW(kWindowClassName, m_hInstance);
|
||||
m_windowClassAtom = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void ResetScenario() {
|
||||
m_spec = {};
|
||||
m_spec.fieldId = "renderer.base_map";
|
||||
m_spec.label = "Base Map";
|
||||
m_spec.emptyText = "None (Asset)";
|
||||
ApplySampleAsset(0u);
|
||||
m_interactionState = {};
|
||||
m_lastResult = "已重置到默认 AssetField 状态";
|
||||
m_activateCount = 0u;
|
||||
m_pressedAction = ActionId::None;
|
||||
}
|
||||
|
||||
void ApplySampleAsset(std::size_t sampleIndex) {
|
||||
m_currentSampleIndex = sampleIndex % std::size(kSampleAssets);
|
||||
const SampleAsset& sample = kSampleAssets[m_currentSampleIndex];
|
||||
m_spec.assetId = sample.assetId;
|
||||
m_spec.displayName = sample.displayName;
|
||||
m_spec.statusText = sample.statusText;
|
||||
m_spec.tint = sample.tint;
|
||||
}
|
||||
|
||||
void ApplyNextSampleAsset() {
|
||||
ApplySampleAsset(m_currentSampleIndex + 1u);
|
||||
}
|
||||
|
||||
ScenarioLayout GetLayout() const {
|
||||
RECT clientRect = {};
|
||||
GetClientRect(m_hwnd, &clientRect);
|
||||
const float width = static_cast<float>((std::max)(clientRect.right - clientRect.left, 1L));
|
||||
const float height = static_cast<float>((std::max)(clientRect.bottom - clientRect.top, 1L));
|
||||
return BuildScenarioLayout(width, height, m_shellMetrics);
|
||||
}
|
||||
|
||||
void RefreshFrame(const UIRect& fieldRect) {
|
||||
m_frame = UpdateUIEditorAssetFieldInteraction(
|
||||
m_interactionState,
|
||||
m_spec,
|
||||
fieldRect,
|
||||
{},
|
||||
m_fieldMetrics);
|
||||
}
|
||||
|
||||
void RenderFrame() {
|
||||
if (m_hwnd == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
RECT clientRect = {};
|
||||
GetClientRect(m_hwnd, &clientRect);
|
||||
const float width = static_cast<float>((std::max)(clientRect.right - clientRect.left, 1L));
|
||||
const float height = static_cast<float>((std::max)(clientRect.bottom - clientRect.top, 1L));
|
||||
const ScenarioLayout layout = BuildScenarioLayout(width, height, m_shellMetrics);
|
||||
|
||||
std::vector<UIInputEvent> events = std::move(m_pendingInputEvents);
|
||||
m_pendingInputEvents.clear();
|
||||
|
||||
m_frame = UpdateUIEditorAssetFieldInteraction(
|
||||
m_interactionState,
|
||||
m_spec,
|
||||
layout.fieldRect,
|
||||
events,
|
||||
m_fieldMetrics);
|
||||
ApplyInteractionResult(m_frame.result, layout.fieldRect);
|
||||
|
||||
const UIEditorAssetFieldHitTarget currentHit =
|
||||
HitTestUIEditorAssetField(m_frame.layout, m_mousePosition);
|
||||
|
||||
UIDrawData drawData = {};
|
||||
UIDrawList& drawList = drawData.EmplaceDrawList("EditorAssetFieldBasic");
|
||||
drawList.AddFilledRect(UIRect(0.0f, 0.0f, width, height), m_shellPalette.windowBackground);
|
||||
|
||||
DrawCard(
|
||||
drawList,
|
||||
layout.introRect,
|
||||
m_shellPalette,
|
||||
m_shellMetrics,
|
||||
"这个测试在验证什么功能?",
|
||||
"验证 Editor 基础 AssetField 的固定风格、清晰 hit target,以及 activate / picker / clear 三类最小请求。");
|
||||
drawList.AddText(
|
||||
UIPoint(layout.introRect.x + 16.0f, layout.introRect.y + 74.0f),
|
||||
"1. 字段视觉固定为 Unity 风格对象槽:标签、预览块、值文本、状态标记、选择按钮、清空按钮。",
|
||||
m_shellPalette.textPrimary,
|
||||
m_shellMetrics.bodyFontSize);
|
||||
drawList.AddText(
|
||||
UIPoint(layout.introRect.x + 16.0f, layout.introRect.y + 98.0f),
|
||||
"2. 点击值区域只产生 activateRequested;基础层不决定 ping、打开面板或业务跳转。",
|
||||
m_shellPalette.textPrimary,
|
||||
m_shellMetrics.bodyFontSize);
|
||||
drawList.AddText(
|
||||
UIPoint(layout.introRect.x + 16.0f, layout.introRect.y + 122.0f),
|
||||
"3. 点击 o,或 focused 后按 Enter / Space,只产生 pickerRequested。",
|
||||
m_shellPalette.textPrimary,
|
||||
m_shellMetrics.bodyFontSize);
|
||||
drawList.AddText(
|
||||
UIPoint(layout.introRect.x + 16.0f, layout.introRect.y + 146.0f),
|
||||
"4. 点击 X,或 focused 后按 Delete / Backspace,清空当前引用。",
|
||||
m_shellPalette.textPrimary,
|
||||
m_shellMetrics.bodyFontSize);
|
||||
drawList.AddText(
|
||||
UIPoint(layout.introRect.x + 16.0f, layout.introRect.y + 170.0f),
|
||||
"5. 本壳程序只用两个固定样本资产模拟 picker 外部响应,不引入 object picker 弹窗系统。",
|
||||
m_shellPalette.textPrimary,
|
||||
m_shellMetrics.bodyFontSize);
|
||||
drawList.AddText(
|
||||
UIPoint(layout.introRect.x + 16.0f, layout.introRect.y + 194.0f),
|
||||
"6. 左侧状态区观察 hover / focus / assetId / displayName / status / result;F12 截图。",
|
||||
m_shellPalette.textPrimary,
|
||||
m_shellMetrics.bodyFontSize);
|
||||
|
||||
DrawCard(drawList, layout.controlRect, m_shellPalette, m_shellMetrics, "操作");
|
||||
for (const ButtonLayout& button : layout.buttons) {
|
||||
DrawButton(
|
||||
drawList,
|
||||
button,
|
||||
m_shellPalette,
|
||||
m_shellMetrics,
|
||||
ContainsPoint(button.rect, m_mousePosition.x, m_mousePosition.y));
|
||||
}
|
||||
|
||||
DrawCard(
|
||||
drawList,
|
||||
layout.stateRect,
|
||||
m_shellPalette,
|
||||
m_shellMetrics,
|
||||
"状态摘要",
|
||||
"重点看 hit、focus、值是否变化,以及请求是否保持薄语义。");
|
||||
drawList.AddText(
|
||||
UIPoint(layout.stateRect.x + 16.0f, layout.stateRect.y + 72.0f),
|
||||
"Hover: " + DescribeHitTarget(currentHit),
|
||||
m_shellPalette.textPrimary,
|
||||
m_shellMetrics.bodyFontSize);
|
||||
drawList.AddText(
|
||||
UIPoint(layout.stateRect.x + 16.0f, layout.stateRect.y + 96.0f),
|
||||
std::string("Focused: ") + (m_interactionState.fieldState.focused ? "yes" : "no"),
|
||||
m_interactionState.fieldState.focused ? m_shellPalette.textSuccess : m_shellPalette.textMuted,
|
||||
m_shellMetrics.bodyFontSize);
|
||||
drawList.AddText(
|
||||
UIPoint(layout.stateRect.x + 16.0f, layout.stateRect.y + 120.0f),
|
||||
"AssetId: " + (m_spec.assetId.empty() ? std::string("(empty)") : m_spec.assetId),
|
||||
m_shellPalette.textPrimary,
|
||||
m_shellMetrics.bodyFontSize);
|
||||
drawList.AddText(
|
||||
UIPoint(layout.stateRect.x + 16.0f, layout.stateRect.y + 144.0f),
|
||||
"Display: " + (m_spec.displayName.empty() ? std::string("(empty)") : m_spec.displayName),
|
||||
m_shellPalette.textPrimary,
|
||||
m_shellMetrics.bodyFontSize);
|
||||
drawList.AddText(
|
||||
UIPoint(layout.stateRect.x + 16.0f, layout.stateRect.y + 168.0f),
|
||||
"Status: " + (m_spec.statusText.empty() ? std::string("(empty)") : m_spec.statusText),
|
||||
m_shellPalette.textPrimary,
|
||||
m_shellMetrics.bodyFontSize);
|
||||
drawList.AddText(
|
||||
UIPoint(layout.stateRect.x + 16.0f, layout.stateRect.y + 192.0f),
|
||||
"Activate Count: " + std::to_string(m_activateCount),
|
||||
m_shellPalette.textPrimary,
|
||||
m_shellMetrics.bodyFontSize);
|
||||
drawList.AddText(
|
||||
UIPoint(layout.stateRect.x + 16.0f, layout.stateRect.y + 216.0f),
|
||||
"Result: " + m_lastResult,
|
||||
m_shellPalette.textMuted,
|
||||
m_shellMetrics.bodyFontSize);
|
||||
drawList.AddText(
|
||||
UIPoint(layout.stateRect.x + 16.0f, layout.stateRect.y + 240.0f),
|
||||
m_autoScreenshot.HasPendingCapture()
|
||||
? "截图排队中..."
|
||||
: (m_autoScreenshot.GetLastCaptureSummary().empty()
|
||||
? std::string("F12 -> tests/UI/Editor/integration/shell/asset_field_basic/captures/")
|
||||
: m_autoScreenshot.GetLastCaptureSummary()),
|
||||
m_shellPalette.textWeak,
|
||||
m_shellMetrics.bodyFontSize);
|
||||
|
||||
DrawCard(
|
||||
drawList,
|
||||
layout.previewRect,
|
||||
m_shellPalette,
|
||||
m_shellMetrics,
|
||||
"AssetField 预览",
|
||||
"这里只放一个基础 AssetField,不接业务面板,也不接 picker。");
|
||||
AppendUIEditorAssetField(
|
||||
drawList,
|
||||
layout.fieldRect,
|
||||
m_spec,
|
||||
m_interactionState.fieldState,
|
||||
m_fieldPalette,
|
||||
m_fieldMetrics);
|
||||
|
||||
const bool framePresented = m_renderer.Render(drawData);
|
||||
m_autoScreenshot.CaptureIfRequested(
|
||||
m_renderer,
|
||||
drawData,
|
||||
static_cast<unsigned int>(width),
|
||||
static_cast<unsigned int>(height),
|
||||
framePresented);
|
||||
}
|
||||
|
||||
void ApplyInteractionResult(
|
||||
const UIEditorAssetFieldInteractionResult& result,
|
||||
const UIRect& fieldRect) {
|
||||
bool refreshNeeded = false;
|
||||
|
||||
if (result.pickerRequested) {
|
||||
ApplyNextSampleAsset();
|
||||
m_lastResult = "收到 pickerRequested,壳程序已用固定样本资产模拟外部选择结果";
|
||||
refreshNeeded = true;
|
||||
} else if (result.clearRequested) {
|
||||
m_lastResult = "收到 clearRequested,当前引用已清空";
|
||||
refreshNeeded = true;
|
||||
} else if (result.activateRequested) {
|
||||
++m_activateCount;
|
||||
m_lastResult = "收到 activateRequested;基础层只发请求,不绑定业务动作";
|
||||
} else if (result.focusChanged) {
|
||||
m_lastResult = std::string("焦点变化: ") +
|
||||
(m_interactionState.fieldState.focused ? "focused" : "lost");
|
||||
} else if (result.consumed) {
|
||||
m_lastResult = "输入已被当前字段消费";
|
||||
}
|
||||
|
||||
if (refreshNeeded) {
|
||||
RefreshFrame(fieldRect);
|
||||
}
|
||||
}
|
||||
|
||||
void ExecuteAction(ActionId action) {
|
||||
switch (action) {
|
||||
case ActionId::Reset:
|
||||
ResetScenario();
|
||||
break;
|
||||
|
||||
case ActionId::Capture:
|
||||
m_autoScreenshot.RequestCapture("manual_button");
|
||||
m_lastResult = "已请求截图,输出到 captures/latest.png";
|
||||
break;
|
||||
|
||||
case ActionId::None:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
const ButtonLayout* HitTestAction(const ScenarioLayout& layout, float x, float y) const {
|
||||
for (const ButtonLayout& button : layout.buttons) {
|
||||
if (ContainsPoint(button.rect, x, y)) {
|
||||
return &button;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
LRESULT HandleMessage(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
|
||||
switch (message) {
|
||||
case WM_CLOSE:
|
||||
DestroyWindow(hwnd);
|
||||
return 0;
|
||||
|
||||
case WM_DESTROY:
|
||||
PostQuitMessage(0);
|
||||
return 0;
|
||||
|
||||
case WM_SIZE:
|
||||
if (wParam != SIZE_MINIMIZED) {
|
||||
m_renderer.Resize(static_cast<UINT>(LOWORD(lParam)), static_cast<UINT>(HIWORD(lParam)));
|
||||
}
|
||||
return 0;
|
||||
|
||||
case WM_MOUSEMOVE: {
|
||||
m_mousePosition = UIPoint(
|
||||
static_cast<float>(GET_X_LPARAM(lParam)),
|
||||
static_cast<float>(GET_Y_LPARAM(lParam)));
|
||||
TRACKMOUSEEVENT trackEvent = {};
|
||||
trackEvent.cbSize = sizeof(trackEvent);
|
||||
trackEvent.dwFlags = TME_LEAVE;
|
||||
trackEvent.hwndTrack = hwnd;
|
||||
TrackMouseEvent(&trackEvent);
|
||||
|
||||
m_pendingInputEvents.push_back(MakePointerEvent(UIInputEventType::PointerMove, m_mousePosition));
|
||||
return 0;
|
||||
}
|
||||
|
||||
case WM_MOUSELEAVE:
|
||||
m_mousePosition = UIPoint(-1000.0f, -1000.0f);
|
||||
m_pendingInputEvents.push_back(MakePointerEvent(UIInputEventType::PointerLeave, m_mousePosition));
|
||||
return 0;
|
||||
|
||||
case WM_LBUTTONDOWN: {
|
||||
SetFocus(hwnd);
|
||||
m_mousePosition = UIPoint(
|
||||
static_cast<float>(GET_X_LPARAM(lParam)),
|
||||
static_cast<float>(GET_Y_LPARAM(lParam)));
|
||||
const ScenarioLayout layout = GetLayout();
|
||||
const ButtonLayout* button = HitTestAction(layout, m_mousePosition.x, m_mousePosition.y);
|
||||
m_pressedAction = button != nullptr ? button->action : ActionId::None;
|
||||
if (button == nullptr) {
|
||||
m_pendingInputEvents.push_back(
|
||||
MakePointerEvent(UIInputEventType::PointerButtonDown, m_mousePosition, UIPointerButton::Left));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
case WM_LBUTTONUP: {
|
||||
m_mousePosition = UIPoint(
|
||||
static_cast<float>(GET_X_LPARAM(lParam)),
|
||||
static_cast<float>(GET_Y_LPARAM(lParam)));
|
||||
const ScenarioLayout layout = GetLayout();
|
||||
const ButtonLayout* button = HitTestAction(layout, m_mousePosition.x, m_mousePosition.y);
|
||||
if (m_pressedAction != ActionId::None &&
|
||||
button != nullptr &&
|
||||
button->action == m_pressedAction) {
|
||||
ExecuteAction(button->action);
|
||||
} else {
|
||||
m_pendingInputEvents.push_back(
|
||||
MakePointerEvent(UIInputEventType::PointerButtonUp, m_mousePosition, UIPointerButton::Left));
|
||||
}
|
||||
m_pressedAction = ActionId::None;
|
||||
return 0;
|
||||
}
|
||||
|
||||
case WM_SETFOCUS:
|
||||
m_pendingInputEvents.push_back(MakeFocusEvent(UIInputEventType::FocusGained));
|
||||
return 0;
|
||||
|
||||
case WM_KILLFOCUS:
|
||||
m_pendingInputEvents.push_back(MakeFocusEvent(UIInputEventType::FocusLost));
|
||||
return 0;
|
||||
|
||||
case WM_KEYDOWN:
|
||||
case WM_SYSKEYDOWN:
|
||||
if (wParam == VK_F12) {
|
||||
m_autoScreenshot.RequestCapture("manual_f12");
|
||||
m_lastResult = "已请求截图,输出到 captures/latest.png";
|
||||
return 0;
|
||||
}
|
||||
if (wParam == VK_F6) {
|
||||
m_pendingInputEvents.push_back(MakeFocusEvent(UIInputEventType::FocusLost));
|
||||
return 0;
|
||||
}
|
||||
if (const std::int32_t keyCode = MapAssetFieldKey(static_cast<UINT>(wParam));
|
||||
keyCode != static_cast<std::int32_t>(KeyCode::None)) {
|
||||
m_pendingInputEvents.push_back(MakeKeyEvent(keyCode));
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case WM_PAINT:
|
||||
RenderFrame();
|
||||
ValidateRect(hwnd, nullptr);
|
||||
return 0;
|
||||
|
||||
case WM_ERASEBKGND:
|
||||
return 1;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return DefWindowProcW(hwnd, message, wParam, lParam);
|
||||
}
|
||||
|
||||
HWND m_hwnd = nullptr;
|
||||
HINSTANCE m_hInstance = nullptr;
|
||||
ATOM m_windowClassAtom = 0;
|
||||
NativeRenderer m_renderer = {};
|
||||
AutoScreenshotController m_autoScreenshot = {};
|
||||
std::filesystem::path m_captureRoot = {};
|
||||
XCEngine::Tests::EditorUI::EditorValidationShellPalette m_shellPalette = {};
|
||||
XCEngine::Tests::EditorUI::EditorValidationShellMetrics m_shellMetrics = {};
|
||||
UIEditorAssetFieldSpec m_spec = {};
|
||||
UIEditorAssetFieldInteractionState m_interactionState = {};
|
||||
UIEditorAssetFieldInteractionFrame m_frame = {};
|
||||
UIEditorAssetFieldPalette m_fieldPalette = {};
|
||||
XCEngine::UI::Editor::Widgets::UIEditorAssetFieldMetrics m_fieldMetrics = {};
|
||||
std::vector<UIInputEvent> m_pendingInputEvents = {};
|
||||
UIPoint m_mousePosition = UIPoint(-1000.0f, -1000.0f);
|
||||
ActionId m_pressedAction = ActionId::None;
|
||||
std::string m_lastResult = {};
|
||||
std::size_t m_currentSampleIndex = 0u;
|
||||
std::size_t m_activateCount = 0u;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, LPWSTR, int nCmdShow) {
|
||||
return ScenarioApp().Run(hInstance, nCmdShow);
|
||||
}
|
||||
Reference in New Issue
Block a user