tests: remove legacy test tree
This commit is contained in:
@@ -1,15 +0,0 @@
|
||||
add_subdirectory(shared)
|
||||
add_subdirectory(input)
|
||||
add_subdirectory(layout)
|
||||
add_subdirectory(render)
|
||||
add_subdirectory(style)
|
||||
add_subdirectory(text)
|
||||
|
||||
add_custom_target(core_ui_integration_tests
|
||||
DEPENDS
|
||||
core_ui_input_integration_tests
|
||||
core_ui_layout_integration_tests
|
||||
core_ui_render_integration_tests
|
||||
core_ui_style_integration_tests
|
||||
core_ui_text_integration_tests
|
||||
)
|
||||
@@ -1,25 +0,0 @@
|
||||
# Core UI Integration Validation
|
||||
|
||||
This directory contains the manual XCUI validation system for shared Core primitives.
|
||||
|
||||
Structure:
|
||||
|
||||
- `shared/`: shared host, native renderer, screenshot helper, scenario registry
|
||||
- `input/`: shared input validation category
|
||||
- `layout/`: shared layout validation category
|
||||
- `style/`: shared theme token and style resolution validation category
|
||||
- `text/`: shared UTF-8 text rendering and textInput focus marker validation category
|
||||
|
||||
Rules:
|
||||
|
||||
- One scenario directory maps to one executable.
|
||||
- Do not accumulate unrelated checks into one monolithic app.
|
||||
- Shared infrastructure belongs in `shared/`, not duplicated per scenario.
|
||||
- Screenshots are written only under the active CMake build directory.
|
||||
- The output root is the executable directory: `.../Debug/captures/<scenario>/`.
|
||||
|
||||
Build:
|
||||
|
||||
```bash
|
||||
cmake --build build --config Debug --target core_ui_integration_tests
|
||||
```
|
||||
@@ -1,21 +0,0 @@
|
||||
add_subdirectory(drag_drop_basic)
|
||||
add_subdirectory(keyboard_focus)
|
||||
add_subdirectory(popup_menu_overlay)
|
||||
add_subdirectory(pointer_states)
|
||||
add_subdirectory(scroll_view)
|
||||
add_subdirectory(shortcut_scope)
|
||||
|
||||
add_custom_target(core_ui_drag_drop_contract_validation
|
||||
DEPENDS
|
||||
core_ui_input_drag_drop_basic_validation
|
||||
)
|
||||
|
||||
add_custom_target(core_ui_input_integration_tests
|
||||
DEPENDS
|
||||
core_ui_input_drag_drop_basic_validation
|
||||
core_ui_input_keyboard_focus_validation
|
||||
core_ui_input_popup_menu_overlay_validation
|
||||
core_ui_input_pointer_states_validation
|
||||
core_ui_input_scroll_view_validation
|
||||
core_ui_input_shortcut_scope_validation
|
||||
)
|
||||
@@ -1,8 +0,0 @@
|
||||
# Core Input Integration
|
||||
|
||||
这个分类只放共享 XCUI 输入能力的手工验证场景。
|
||||
|
||||
规则:
|
||||
- 一个场景目录对应一个独立 exe
|
||||
- 共享宿主层只放在 `integration/shared/`
|
||||
- 不允许把多个无关检查点塞进同一个 exe
|
||||
@@ -1,35 +0,0 @@
|
||||
set(CORE_UI_INPUT_DRAG_DROP_BASIC_RESOURCES
|
||||
View.xcui
|
||||
${CMAKE_SOURCE_DIR}/tests/UI/Core/integration/shared/themes/core_validation.xctheme
|
||||
)
|
||||
|
||||
add_executable(core_ui_input_drag_drop_basic_validation WIN32
|
||||
main.cpp
|
||||
${CORE_UI_INPUT_DRAG_DROP_BASIC_RESOURCES}
|
||||
)
|
||||
|
||||
target_include_directories(core_ui_input_drag_drop_basic_validation PRIVATE
|
||||
${CMAKE_SOURCE_DIR}/tests/UI/Core/integration/shared/src
|
||||
${CMAKE_SOURCE_DIR}/engine/include
|
||||
)
|
||||
|
||||
target_compile_definitions(core_ui_input_drag_drop_basic_validation PRIVATE
|
||||
UNICODE
|
||||
_UNICODE
|
||||
)
|
||||
|
||||
if(MSVC)
|
||||
target_compile_options(core_ui_input_drag_drop_basic_validation PRIVATE /utf-8 /FS)
|
||||
set_property(TARGET core_ui_input_drag_drop_basic_validation PROPERTY
|
||||
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
|
||||
endif()
|
||||
|
||||
target_link_libraries(core_ui_input_drag_drop_basic_validation PRIVATE
|
||||
core_ui_integration_host
|
||||
)
|
||||
|
||||
set_target_properties(core_ui_input_drag_drop_basic_validation PROPERTIES
|
||||
OUTPUT_NAME "XCUICoreDragDropContractValidation"
|
||||
)
|
||||
|
||||
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}" FILES View.xcui)
|
||||
@@ -1,19 +0,0 @@
|
||||
<View
|
||||
name="CoreInputDragDropContract"
|
||||
theme="../../shared/themes/core_validation.xctheme">
|
||||
<Column padding="24" gap="16">
|
||||
<Card
|
||||
title="测试内容:Core Drag / Drop Contract"
|
||||
subtitle="只验证 Core 层拖拽原语本身:激活阈值、target accept/reject、release 完成、以及 Escape / focus lost 取消。"
|
||||
tone="accent"
|
||||
height="206">
|
||||
<Column gap="8">
|
||||
<Text text="1. 按住左侧任一 source 后不要立刻松开;只有拖过激活阈值后才会进入 active。" />
|
||||
<Text text="2. 将 Texture Asset 拖到 Project Browser,应显示 accept,预览操作应解析为 Copy。" />
|
||||
<Text text="3. 将 Texture Asset 拖到 Hierarchy Parent,应显示 reject;此时松开只会取消,不会完成 drop。" />
|
||||
<Text text="4. 将 Scene Entity 拖到 Hierarchy Parent,应显示 accept;松开后应完成 Move。" />
|
||||
<Text text="5. active 期间按 Esc,或切走窗口触发 focus lost,应立即取消当前 drag。" />
|
||||
</Column>
|
||||
</Card>
|
||||
</Column>
|
||||
</View>
|
||||
@@ -1,8 +0,0 @@
|
||||
#include "Application.h"
|
||||
|
||||
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, LPWSTR, int nCmdShow) {
|
||||
return XCEngine::Tests::CoreUI::RunCoreUIValidationApp(
|
||||
hInstance,
|
||||
nCmdShow,
|
||||
"core.input.drag_drop_basic");
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
set(CORE_UI_INPUT_KEYBOARD_FOCUS_RESOURCES
|
||||
View.xcui
|
||||
${CMAKE_SOURCE_DIR}/tests/UI/Core/integration/shared/themes/core_validation.xctheme
|
||||
)
|
||||
|
||||
add_executable(core_ui_input_keyboard_focus_validation WIN32
|
||||
main.cpp
|
||||
${CORE_UI_INPUT_KEYBOARD_FOCUS_RESOURCES}
|
||||
)
|
||||
|
||||
target_include_directories(core_ui_input_keyboard_focus_validation PRIVATE
|
||||
${CMAKE_SOURCE_DIR}/tests/UI/Core/integration/shared/src
|
||||
${CMAKE_SOURCE_DIR}/engine/include
|
||||
)
|
||||
|
||||
target_compile_definitions(core_ui_input_keyboard_focus_validation PRIVATE
|
||||
UNICODE
|
||||
_UNICODE
|
||||
)
|
||||
|
||||
if(MSVC)
|
||||
target_compile_options(core_ui_input_keyboard_focus_validation PRIVATE /utf-8 /FS)
|
||||
set_property(TARGET core_ui_input_keyboard_focus_validation PROPERTY
|
||||
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
|
||||
endif()
|
||||
|
||||
target_link_libraries(core_ui_input_keyboard_focus_validation PRIVATE
|
||||
core_ui_integration_host
|
||||
)
|
||||
|
||||
set_target_properties(core_ui_input_keyboard_focus_validation PROPERTIES
|
||||
OUTPUT_NAME "XCUICoreInputKeyboardFocusValidation"
|
||||
)
|
||||
|
||||
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}" FILES View.xcui)
|
||||
@@ -1,15 +0,0 @@
|
||||
# Keyboard Focus Validation
|
||||
|
||||
可执行 target:
|
||||
- `core_ui_input_keyboard_focus_validation`
|
||||
|
||||
运行:
|
||||
```bash
|
||||
build\tests\UI\Core\integration\input\keyboard_focus\Debug\XCUICoreInputKeyboardFocusValidation.exe
|
||||
```
|
||||
|
||||
检查点:
|
||||
1. 按 `Tab`,焦点依次切换三个按钮。
|
||||
2. 按 `Shift+Tab`,焦点反向切换。
|
||||
3. 按 `Enter` 或 `Space`,当前 `focus` 按钮进入 `active`。
|
||||
4. 松开按键后,`active` 清空。
|
||||
@@ -1,30 +0,0 @@
|
||||
<View
|
||||
name="CoreInputKeyboardFocus"
|
||||
theme="../../shared/themes/core_validation.xctheme">
|
||||
<Column padding="24" gap="16">
|
||||
<Card
|
||||
title="Core Validation | Keyboard Focus"
|
||||
subtitle="当前批次:Tab 焦点遍历 | Enter / Space 激活"
|
||||
tone="accent"
|
||||
height="90">
|
||||
<Column gap="8">
|
||||
<Text text="这是 Core 层验证场景,不承载 runtime 游戏 UI。" />
|
||||
<Text text="这一轮只检查键盘焦点和激活,不混入上层业务面板。" />
|
||||
</Column>
|
||||
</Card>
|
||||
|
||||
<Card title="Keyboard Focus" subtitle="tab focus active" height="214">
|
||||
<Column gap="12">
|
||||
<Text text="只检查下面三个可聚焦按钮和右下角状态叠层。" />
|
||||
<Row gap="12">
|
||||
<Button id="focus-first" text="First Focus" />
|
||||
<Button id="focus-second" text="Second Focus" />
|
||||
<Button id="focus-third" text="Third Focus" />
|
||||
</Row>
|
||||
<Text text="1. 按 Tab:focus 应依次切到 First / Second / Third。" />
|
||||
<Text text="2. 按 Shift+Tab:focus 应反向切换。" />
|
||||
<Text text="3. focus 停在任一按钮后,按 Enter 或 Space:active 应出现;松开后 active 清空。" />
|
||||
</Column>
|
||||
</Card>
|
||||
</Column>
|
||||
</View>
|
||||
@@ -1,8 +0,0 @@
|
||||
#include "Application.h"
|
||||
|
||||
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, LPWSTR, int nCmdShow) {
|
||||
return XCEngine::Tests::CoreUI::RunCoreUIValidationApp(
|
||||
hInstance,
|
||||
nCmdShow,
|
||||
"core.input.keyboard_focus");
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
set(CORE_UI_INPUT_POINTER_STATES_RESOURCES
|
||||
View.xcui
|
||||
${CMAKE_SOURCE_DIR}/tests/UI/Core/integration/shared/themes/core_validation.xctheme
|
||||
)
|
||||
|
||||
add_executable(core_ui_input_pointer_states_validation WIN32
|
||||
main.cpp
|
||||
${CORE_UI_INPUT_POINTER_STATES_RESOURCES}
|
||||
)
|
||||
|
||||
target_include_directories(core_ui_input_pointer_states_validation PRIVATE
|
||||
${CMAKE_SOURCE_DIR}/tests/UI/Core/integration/shared/src
|
||||
${CMAKE_SOURCE_DIR}/engine/include
|
||||
)
|
||||
|
||||
target_compile_definitions(core_ui_input_pointer_states_validation PRIVATE
|
||||
UNICODE
|
||||
_UNICODE
|
||||
)
|
||||
|
||||
if(MSVC)
|
||||
target_compile_options(core_ui_input_pointer_states_validation PRIVATE /utf-8 /FS)
|
||||
set_property(TARGET core_ui_input_pointer_states_validation PROPERTY
|
||||
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
|
||||
endif()
|
||||
|
||||
target_link_libraries(core_ui_input_pointer_states_validation PRIVATE
|
||||
core_ui_integration_host
|
||||
)
|
||||
|
||||
set_target_properties(core_ui_input_pointer_states_validation PROPERTIES
|
||||
OUTPUT_NAME "XCUICoreInputPointerStatesValidation"
|
||||
)
|
||||
|
||||
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}" FILES View.xcui)
|
||||
@@ -1,14 +0,0 @@
|
||||
# Pointer States Validation
|
||||
|
||||
可执行 target:
|
||||
- `core_ui_input_pointer_states_validation`
|
||||
|
||||
运行:
|
||||
```bash
|
||||
build\tests\UI\Core\integration\input\pointer_states\Debug\XCUICoreInputPointerStatesValidation.exe
|
||||
```
|
||||
|
||||
检查点:
|
||||
1. hover 左侧按钮,只应变化 `hover`。
|
||||
2. 按住中间按钮,应看到 `focus`、`active`、`capture`。
|
||||
3. 拖到右侧再松开,应看到 `capture` 清空,route 转到新的目标。
|
||||
@@ -1,30 +0,0 @@
|
||||
<View
|
||||
name="CoreInputPointerStates"
|
||||
theme="../../shared/themes/core_validation.xctheme">
|
||||
<Column padding="24" gap="16">
|
||||
<Card
|
||||
title="Core Validation | Pointer States"
|
||||
subtitle="当前批次:鼠标 hover / focus / active / capture"
|
||||
tone="accent"
|
||||
height="90">
|
||||
<Column gap="8">
|
||||
<Text text="这是 Core 层验证场景,不承载 runtime 游戏 UI。" />
|
||||
<Text text="这一轮只检查鼠标输入状态,不混入别的控件实验。" />
|
||||
</Column>
|
||||
</Card>
|
||||
|
||||
<Card title="Pointer Input" subtitle="hover focus active capture" height="196">
|
||||
<Column gap="12">
|
||||
<Text text="这一轮只需要检查下面这三个按钮。" />
|
||||
<Row gap="12">
|
||||
<Button id="input-hover" text="Hover / Focus" />
|
||||
<Button id="input-capture" text="Pointer Capture" capturePointer="true" />
|
||||
<Button id="input-route" text="Route Target" />
|
||||
</Row>
|
||||
<Text text="1. 鼠标移到左侧按钮:hover 应变化,focus 保持空。" />
|
||||
<Text text="2. 按住中间按钮:focus、active、capture 都应留在中间。" />
|
||||
<Text text="3. 拖到右侧再松开:hover 移到右侧,capture 清空,focus 仍留中间。" />
|
||||
</Column>
|
||||
</Card>
|
||||
</Column>
|
||||
</View>
|
||||
@@ -1,8 +0,0 @@
|
||||
#include "Application.h"
|
||||
|
||||
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, LPWSTR, int nCmdShow) {
|
||||
return XCEngine::Tests::CoreUI::RunCoreUIValidationApp(
|
||||
hInstance,
|
||||
nCmdShow,
|
||||
"core.input.pointer_states");
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
set(CORE_UI_INPUT_POPUP_MENU_OVERLAY_RESOURCES
|
||||
View.xcui
|
||||
${CMAKE_SOURCE_DIR}/tests/UI/Core/integration/shared/themes/core_validation.xctheme
|
||||
)
|
||||
|
||||
add_executable(core_ui_input_popup_menu_overlay_validation WIN32
|
||||
main.cpp
|
||||
${CORE_UI_INPUT_POPUP_MENU_OVERLAY_RESOURCES}
|
||||
)
|
||||
|
||||
target_include_directories(core_ui_input_popup_menu_overlay_validation PRIVATE
|
||||
${CMAKE_SOURCE_DIR}/tests/UI/Core/integration/shared/src
|
||||
${CMAKE_SOURCE_DIR}/engine/include
|
||||
)
|
||||
|
||||
target_compile_definitions(core_ui_input_popup_menu_overlay_validation PRIVATE
|
||||
UNICODE
|
||||
_UNICODE
|
||||
)
|
||||
|
||||
if(MSVC)
|
||||
target_compile_options(core_ui_input_popup_menu_overlay_validation PRIVATE /utf-8 /FS)
|
||||
set_property(TARGET core_ui_input_popup_menu_overlay_validation PROPERTY
|
||||
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
|
||||
endif()
|
||||
|
||||
target_link_libraries(core_ui_input_popup_menu_overlay_validation PRIVATE
|
||||
core_ui_integration_host
|
||||
)
|
||||
|
||||
set_target_properties(core_ui_input_popup_menu_overlay_validation PROPERTIES
|
||||
OUTPUT_NAME "XCUICoreInputPopupMenuOverlayValidation"
|
||||
)
|
||||
|
||||
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}" FILES View.xcui)
|
||||
@@ -1,10 +0,0 @@
|
||||
# Core Input | Popup Menu Overlay
|
||||
|
||||
这个场景只验证 `Core popup / menu overlay primitive`:
|
||||
|
||||
- 根 popup 打开与关闭
|
||||
- submenu 展开与分支关闭
|
||||
- overlay 空白区点击 dismiss
|
||||
- popup 打开时阻断底层按钮命中
|
||||
|
||||
不验证 Editor 菜单栏,不验证业务命令。
|
||||
@@ -1,18 +0,0 @@
|
||||
<View
|
||||
name="CoreInputPopupMenuOverlay"
|
||||
theme="../../shared/themes/core_validation.xctheme">
|
||||
<Column padding="24" gap="16">
|
||||
<Card
|
||||
title="测试内容:Core Popup / Menu Overlay Primitive"
|
||||
subtitle="只验证 popup 打开关闭、overlay 遮挡、outside click dismiss 与 hover 展开子菜单"
|
||||
tone="accent"
|
||||
height="160">
|
||||
<Column gap="8">
|
||||
<Text text="1. 点击下方交互区里的 Open Menu,根 popup 应在 overlay 层弹出。" />
|
||||
<Text text="2. hover 到 Open Submenu 后,右侧应直接弹出 child popup;再点根 popup 空白区,应该只关闭 child popup。" />
|
||||
<Text text="3. popup 打开时,Background Button 不应在同一次点击里被命中;先 dismiss,再点它才应生效。" />
|
||||
<Text text="4. 按 Esc 应关闭当前最上层 popup;点击 overlay 空白区应关闭整条 popup 链。" />
|
||||
</Column>
|
||||
</Card>
|
||||
</Column>
|
||||
</View>
|
||||
@@ -1,8 +0,0 @@
|
||||
#include "Application.h"
|
||||
|
||||
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, LPWSTR, int nCmdShow) {
|
||||
return XCEngine::Tests::CoreUI::RunCoreUIValidationApp(
|
||||
hInstance,
|
||||
nCmdShow,
|
||||
"core.input.popup_menu_overlay");
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
set(CORE_UI_INPUT_SCROLL_VIEW_RESOURCES
|
||||
View.xcui
|
||||
${CMAKE_SOURCE_DIR}/tests/UI/Core/integration/shared/themes/core_validation.xctheme
|
||||
)
|
||||
|
||||
add_executable(core_ui_input_scroll_view_validation WIN32
|
||||
main.cpp
|
||||
${CORE_UI_INPUT_SCROLL_VIEW_RESOURCES}
|
||||
)
|
||||
|
||||
target_include_directories(core_ui_input_scroll_view_validation PRIVATE
|
||||
${CMAKE_SOURCE_DIR}/tests/UI/Core/integration/shared/src
|
||||
${CMAKE_SOURCE_DIR}/engine/include
|
||||
)
|
||||
|
||||
target_compile_definitions(core_ui_input_scroll_view_validation PRIVATE
|
||||
UNICODE
|
||||
_UNICODE
|
||||
)
|
||||
|
||||
if(MSVC)
|
||||
target_compile_options(core_ui_input_scroll_view_validation PRIVATE /utf-8 /FS)
|
||||
set_property(TARGET core_ui_input_scroll_view_validation PROPERTY
|
||||
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
|
||||
endif()
|
||||
|
||||
target_link_libraries(core_ui_input_scroll_view_validation PRIVATE
|
||||
core_ui_integration_host
|
||||
)
|
||||
|
||||
set_target_properties(core_ui_input_scroll_view_validation PROPERTIES
|
||||
OUTPUT_NAME "XCUICoreInputScrollViewValidation"
|
||||
)
|
||||
|
||||
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}" FILES View.xcui)
|
||||
@@ -1,61 +0,0 @@
|
||||
<View
|
||||
name="CoreInputScrollView"
|
||||
theme="../../shared/themes/core_validation.xctheme">
|
||||
<Column padding="20" gap="12">
|
||||
<Card
|
||||
title="功能:ScrollView 滚动 / clip / overflow"
|
||||
subtitle="只检查滚轮滚动、裁剪、overflow 与 target 路由,不检查业务面板"
|
||||
tone="accent"
|
||||
height="118">
|
||||
<Column gap="6">
|
||||
<Text text="1. 把鼠标放到下方日志区内滚动滚轮:内容应上下移动,右下角 Scroll target 应落到 validation-scroll。" />
|
||||
<Text text="2. 连续向下滚到末尾再继续滚:Offset 应被 clamp,Result 应显示 Scroll delta clamped to current offset。" />
|
||||
<Text text="3. 把鼠标移到日志区外再滚动:日志位置不应变化,Result 应显示 No hovered ScrollView。" />
|
||||
<Text text="4. 这个场景只验证 ScrollView 基础能力,不验证上层业务面板。" />
|
||||
</Column>
|
||||
</Card>
|
||||
|
||||
<Card
|
||||
title="Scrollable Log"
|
||||
subtitle="wheel inside this viewport"
|
||||
height="fill">
|
||||
<ScrollView id="validation-scroll" height="fill">
|
||||
<Column gap="8">
|
||||
<Text text="Line 01 - Scroll validation log" />
|
||||
<Text text="Line 02 - Scroll validation log" />
|
||||
<Text text="Line 03 - Scroll validation log" />
|
||||
<Text text="Line 04 - Scroll validation log" />
|
||||
<Text text="Line 05 - Scroll validation log" />
|
||||
<Text text="Line 06 - Scroll validation log" />
|
||||
<Text text="Line 07 - Scroll validation log" />
|
||||
<Text text="Line 08 - Scroll validation log" />
|
||||
<Text text="Line 09 - Scroll validation log" />
|
||||
<Text text="Line 10 - Scroll validation log" />
|
||||
<Text text="Line 11 - Scroll validation log" />
|
||||
<Text text="Line 12 - Scroll validation log" />
|
||||
<Text text="Line 13 - Scroll validation log" />
|
||||
<Text text="Line 14 - Scroll validation log" />
|
||||
<Text text="Line 15 - Scroll validation log" />
|
||||
<Text text="Line 16 - Scroll validation log" />
|
||||
<Text text="Line 17 - Scroll validation log" />
|
||||
<Text text="Line 18 - Scroll validation log" />
|
||||
<Text text="Line 19 - Scroll validation log" />
|
||||
<Text text="Line 20 - Scroll validation log" />
|
||||
<Text text="Line 21 - Scroll validation log" />
|
||||
<Text text="Line 22 - Scroll validation log" />
|
||||
<Text text="Line 23 - Scroll validation log" />
|
||||
<Text text="Line 24 - Scroll validation log" />
|
||||
</Column>
|
||||
</ScrollView>
|
||||
</Card>
|
||||
|
||||
<Card
|
||||
title="Outside Area"
|
||||
subtitle="wheel here should not move the log"
|
||||
height="84">
|
||||
<Column gap="8">
|
||||
<Text text="把鼠标移到这个区域再滚动,用来检查 No hovered ScrollView。" />
|
||||
</Column>
|
||||
</Card>
|
||||
</Column>
|
||||
</View>
|
||||
@@ -1,8 +0,0 @@
|
||||
#include "Application.h"
|
||||
|
||||
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, LPWSTR, int nCmdShow) {
|
||||
return XCEngine::Tests::CoreUI::RunCoreUIValidationApp(
|
||||
hInstance,
|
||||
nCmdShow,
|
||||
"core.input.scroll_view");
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
set(CORE_UI_INPUT_SHORTCUT_SCOPE_RESOURCES
|
||||
View.xcui
|
||||
${CMAKE_SOURCE_DIR}/tests/UI/Core/integration/shared/themes/core_validation.xctheme
|
||||
)
|
||||
|
||||
add_executable(core_ui_input_shortcut_scope_validation WIN32
|
||||
main.cpp
|
||||
${CORE_UI_INPUT_SHORTCUT_SCOPE_RESOURCES}
|
||||
)
|
||||
|
||||
target_include_directories(core_ui_input_shortcut_scope_validation PRIVATE
|
||||
${CMAKE_SOURCE_DIR}/tests/UI/Core/integration/shared/src
|
||||
${CMAKE_SOURCE_DIR}/engine/include
|
||||
)
|
||||
|
||||
target_compile_definitions(core_ui_input_shortcut_scope_validation PRIVATE
|
||||
UNICODE
|
||||
_UNICODE
|
||||
)
|
||||
|
||||
if(MSVC)
|
||||
target_compile_options(core_ui_input_shortcut_scope_validation PRIVATE /utf-8 /FS)
|
||||
set_property(TARGET core_ui_input_shortcut_scope_validation PROPERTY
|
||||
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
|
||||
endif()
|
||||
|
||||
target_link_libraries(core_ui_input_shortcut_scope_validation PRIVATE
|
||||
core_ui_integration_host
|
||||
)
|
||||
|
||||
set_target_properties(core_ui_input_shortcut_scope_validation PROPERTIES
|
||||
OUTPUT_NAME "XCUICoreInputShortcutScopeValidation"
|
||||
)
|
||||
|
||||
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}" FILES View.xcui)
|
||||
@@ -1,69 +0,0 @@
|
||||
<View
|
||||
name="CoreInputShortcutScope"
|
||||
theme="../../shared/themes/core_validation.xctheme"
|
||||
shortcut="Ctrl+P"
|
||||
shortcutCommand="global.command"
|
||||
shortcutScope="global">
|
||||
<Column padding="20" gap="12">
|
||||
<Card
|
||||
title="Core Validation | Shortcut Scope"
|
||||
subtitle="验证功能:Core shortcut scope 路由与 text input suppression"
|
||||
tone="accent"
|
||||
height="100">
|
||||
<Column gap="6">
|
||||
<Text text="功能 1:验证 Ctrl+P 在 Widget / Panel / Window / Global 间按优先级命中 shortcut。" />
|
||||
<Text text="功能 2:验证 Text Input Proxy 会抑制 Ctrl+P 和 Tab 焦点遍历。" />
|
||||
</Column>
|
||||
</Card>
|
||||
|
||||
<Button id="global-focus" text="Global Focus" />
|
||||
|
||||
<Card
|
||||
id="window-shell"
|
||||
title="Window Scope"
|
||||
subtitle="Ctrl+P -> window.command"
|
||||
shortcutScopeRoot="window"
|
||||
shortcut="Ctrl+P"
|
||||
shortcutCommand="window.command"
|
||||
shortcutScope="window">
|
||||
<Column gap="10">
|
||||
<Text text="先检查优先级:widget > panel > window > global。" />
|
||||
<Button id="window-focus" text="Window Focus" />
|
||||
|
||||
<Card
|
||||
id="panel-shell"
|
||||
title="Panel Scope"
|
||||
subtitle="Ctrl+P -> panel.command"
|
||||
shortcutScopeRoot="panel"
|
||||
shortcut="Ctrl+P"
|
||||
shortcutCommand="panel.command"
|
||||
shortcutScope="panel">
|
||||
<Column gap="10">
|
||||
<Button id="panel-focus" text="Panel Focus" />
|
||||
|
||||
<Card
|
||||
id="widget-shell"
|
||||
title="Widget Scope"
|
||||
subtitle="Ctrl+P -> widget.command"
|
||||
tone="accent-alt"
|
||||
shortcutScopeRoot="widget"
|
||||
shortcut="Ctrl+P"
|
||||
shortcutCommand="widget.command"
|
||||
shortcutScope="widget">
|
||||
<Column gap="10">
|
||||
<Button id="widget-focus" text="Widget Focus" />
|
||||
</Column>
|
||||
</Card>
|
||||
|
||||
<Button id="text-input" text="Text Input Proxy" textInput="true" />
|
||||
<Text text="操作指引:" />
|
||||
<Text text="1. 依次点 Widget / Panel / Window / Global Focus,再按 Ctrl+P。" />
|
||||
<Text text="2. 右下角 Recent shortcut 应分别显示 widget / panel / window / global,且状态为 handled。" />
|
||||
<Text text="3. 点 Text Input Proxy 再按 Ctrl+P,Recent shortcut 状态应变为 suppressed。" />
|
||||
<Text text="4. 保持 Text Input Proxy focus 再按 Tab,Result 应显示 focus traversal suppressed,focus 不应跳走。" />
|
||||
</Column>
|
||||
</Card>
|
||||
</Column>
|
||||
</Card>
|
||||
</Column>
|
||||
</View>
|
||||
@@ -1,8 +0,0 @@
|
||||
#include "Application.h"
|
||||
|
||||
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, LPWSTR, int nCmdShow) {
|
||||
return XCEngine::Tests::CoreUI::RunCoreUIValidationApp(
|
||||
hInstance,
|
||||
nCmdShow,
|
||||
"core.input.shortcut_scope");
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
add_subdirectory(splitter_resize)
|
||||
add_subdirectory(tab_strip_selection)
|
||||
add_subdirectory(workspace_compose)
|
||||
|
||||
add_custom_target(core_ui_layout_integration_tests
|
||||
DEPENDS
|
||||
core_ui_layout_splitter_resize_validation
|
||||
core_ui_layout_tab_strip_selection_validation
|
||||
core_ui_layout_workspace_compose_validation
|
||||
)
|
||||
@@ -1,35 +0,0 @@
|
||||
set(CORE_UI_LAYOUT_SPLITTER_RESIZE_RESOURCES
|
||||
View.xcui
|
||||
${CMAKE_SOURCE_DIR}/tests/UI/Core/integration/shared/themes/core_validation.xctheme
|
||||
)
|
||||
|
||||
add_executable(core_ui_layout_splitter_resize_validation WIN32
|
||||
main.cpp
|
||||
${CORE_UI_LAYOUT_SPLITTER_RESIZE_RESOURCES}
|
||||
)
|
||||
|
||||
target_include_directories(core_ui_layout_splitter_resize_validation PRIVATE
|
||||
${CMAKE_SOURCE_DIR}/tests/UI/Core/integration/shared/src
|
||||
${CMAKE_SOURCE_DIR}/engine/include
|
||||
)
|
||||
|
||||
target_compile_definitions(core_ui_layout_splitter_resize_validation PRIVATE
|
||||
UNICODE
|
||||
_UNICODE
|
||||
)
|
||||
|
||||
if(MSVC)
|
||||
target_compile_options(core_ui_layout_splitter_resize_validation PRIVATE /utf-8 /FS)
|
||||
set_property(TARGET core_ui_layout_splitter_resize_validation PROPERTY
|
||||
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
|
||||
endif()
|
||||
|
||||
target_link_libraries(core_ui_layout_splitter_resize_validation PRIVATE
|
||||
core_ui_integration_host
|
||||
)
|
||||
|
||||
set_target_properties(core_ui_layout_splitter_resize_validation PROPERTIES
|
||||
OUTPUT_NAME "XCUICoreLayoutSplitterResizeValidation"
|
||||
)
|
||||
|
||||
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}" FILES View.xcui)
|
||||
@@ -1,39 +0,0 @@
|
||||
<View
|
||||
name="CoreSplitterResizeValidation"
|
||||
theme="../../shared/themes/core_validation.xctheme">
|
||||
<Column width="fill" height="fill" padding="20" gap="12">
|
||||
<Card
|
||||
title="功能:Splitter / pane resize"
|
||||
subtitle="这一轮只检查分割条拖拽和最小尺寸 clamp"
|
||||
tone="accent"
|
||||
height="128">
|
||||
<Column gap="6">
|
||||
<Text text="1. 鼠标移到中间 divider:右下角 Hover 应落到 workspace-splitter。" />
|
||||
<Text text="2. 按住左键拖拽:左右 pane 宽度应实时变化,Result 应出现 Splitter drag started / Splitter resized。" />
|
||||
<Text text="3. 向左右极限拖拽:布局应被 primaryMin / secondaryMin clamp 住,不应穿透。" />
|
||||
<Text text="4. 松开左键:Result 应显示 Splitter drag finished。" />
|
||||
</Column>
|
||||
</Card>
|
||||
|
||||
<Splitter
|
||||
id="workspace-splitter"
|
||||
axis="horizontal"
|
||||
splitRatio="0.38"
|
||||
splitterSize="10"
|
||||
splitterHitSize="18"
|
||||
primaryMin="180"
|
||||
secondaryMin="220"
|
||||
height="fill">
|
||||
<Card id="left-pane" title="Left Empty Pane" subtitle="min 180" height="fill">
|
||||
<Column gap="8">
|
||||
<Text text="这里只保留空 pane,用来观察 resize。" />
|
||||
</Column>
|
||||
</Card>
|
||||
<Card id="right-pane" title="Right Empty Pane" subtitle="min 220" height="fill">
|
||||
<Column gap="8">
|
||||
<Text text="拖拽过程中不应出现翻转、穿透或抖动。" />
|
||||
</Column>
|
||||
</Card>
|
||||
</Splitter>
|
||||
</Column>
|
||||
</View>
|
||||
@@ -1,8 +0,0 @@
|
||||
#include "Application.h"
|
||||
|
||||
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, LPWSTR, int nCmdShow) {
|
||||
return XCEngine::Tests::CoreUI::RunCoreUIValidationApp(
|
||||
hInstance,
|
||||
nCmdShow,
|
||||
"core.layout.splitter_resize");
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
set(CORE_UI_LAYOUT_TAB_STRIP_SELECTION_RESOURCES
|
||||
View.xcui
|
||||
${CMAKE_SOURCE_DIR}/tests/UI/Core/integration/shared/themes/core_validation.xctheme
|
||||
)
|
||||
|
||||
add_executable(core_ui_layout_tab_strip_selection_validation WIN32
|
||||
main.cpp
|
||||
${CORE_UI_LAYOUT_TAB_STRIP_SELECTION_RESOURCES}
|
||||
)
|
||||
|
||||
target_include_directories(core_ui_layout_tab_strip_selection_validation PRIVATE
|
||||
${CMAKE_SOURCE_DIR}/tests/UI/Core/integration/shared/src
|
||||
${CMAKE_SOURCE_DIR}/engine/include
|
||||
)
|
||||
|
||||
target_compile_definitions(core_ui_layout_tab_strip_selection_validation PRIVATE
|
||||
UNICODE
|
||||
_UNICODE
|
||||
)
|
||||
|
||||
if(MSVC)
|
||||
target_compile_options(core_ui_layout_tab_strip_selection_validation PRIVATE /utf-8 /FS)
|
||||
set_property(TARGET core_ui_layout_tab_strip_selection_validation PROPERTY
|
||||
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
|
||||
endif()
|
||||
|
||||
target_link_libraries(core_ui_layout_tab_strip_selection_validation PRIVATE
|
||||
core_ui_integration_host
|
||||
)
|
||||
|
||||
set_target_properties(core_ui_layout_tab_strip_selection_validation PROPERTIES
|
||||
OUTPUT_NAME "XCUICoreLayoutTabStripSelectionValidation"
|
||||
)
|
||||
|
||||
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}" FILES View.xcui)
|
||||
@@ -1,46 +0,0 @@
|
||||
<View
|
||||
name="CoreTabStripSelectionValidation"
|
||||
theme="../../shared/themes/core_validation.xctheme">
|
||||
<Column width="fill" height="fill" padding="20" gap="12">
|
||||
<Card
|
||||
title="功能:TabStrip 选择切换"
|
||||
subtitle="只验证 tab 头部点击、键盘导航,以及只渲染 selected tab 内容"
|
||||
tone="accent"
|
||||
height="156">
|
||||
<Column gap="6">
|
||||
<Text text="1. 点击 Scene / Console / Inspector 任一 tab:下方内容区应立即切换,旧内容不应继续显示。" />
|
||||
<Text text="2. 先点击一个 tab 让它获得 focus,再按 Left / Right / Home / End:selected tab 应变化。" />
|
||||
<Text text="3. 右下角 Result 正常应显示 Tab selected 或 Tab navigated;Focused 应落在当前 tab。" />
|
||||
<Text text="4. 这个场景只检查 TabStrip 基础能力,不检查上层业务面板。" />
|
||||
</Column>
|
||||
</Card>
|
||||
|
||||
<TabStrip
|
||||
id="core-workspace-tabs"
|
||||
tabHeaderHeight="34"
|
||||
tabMinWidth="96"
|
||||
height="fill">
|
||||
<Tab id="tab-scene" label="Scene" selected="true">
|
||||
<Card title="Scene Tab Content" subtitle="selected = Scene" height="fill">
|
||||
<Column gap="8">
|
||||
<Text text="这里应该只显示 Scene 的内容占位。" />
|
||||
</Column>
|
||||
</Card>
|
||||
</Tab>
|
||||
<Tab id="tab-console" label="Console">
|
||||
<Card title="Console Tab Content" subtitle="selected = Console" height="fill">
|
||||
<Column gap="8">
|
||||
<Text text="切换到 Console 后,Scene 内容应消失。" />
|
||||
</Column>
|
||||
</Card>
|
||||
</Tab>
|
||||
<Tab id="tab-inspector" label="Inspector">
|
||||
<Card title="Inspector Tab Content" subtitle="selected = Inspector" height="fill">
|
||||
<Column gap="8">
|
||||
<Text text="按 Home / End 时,也应只保留当前 selected 内容。" />
|
||||
</Column>
|
||||
</Card>
|
||||
</Tab>
|
||||
</TabStrip>
|
||||
</Column>
|
||||
</View>
|
||||
@@ -1,8 +0,0 @@
|
||||
#include "Application.h"
|
||||
|
||||
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, LPWSTR, int nCmdShow) {
|
||||
return XCEngine::Tests::CoreUI::RunCoreUIValidationApp(
|
||||
hInstance,
|
||||
nCmdShow,
|
||||
"core.layout.tab_strip_selection");
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
set(CORE_UI_LAYOUT_WORKSPACE_COMPOSE_RESOURCES
|
||||
View.xcui
|
||||
${CMAKE_SOURCE_DIR}/tests/UI/Core/integration/shared/themes/core_validation.xctheme
|
||||
)
|
||||
|
||||
add_executable(core_ui_layout_workspace_compose_validation WIN32
|
||||
main.cpp
|
||||
${CORE_UI_LAYOUT_WORKSPACE_COMPOSE_RESOURCES}
|
||||
)
|
||||
|
||||
target_include_directories(core_ui_layout_workspace_compose_validation PRIVATE
|
||||
${CMAKE_SOURCE_DIR}/tests/UI/Core/integration/shared/src
|
||||
${CMAKE_SOURCE_DIR}/engine/include
|
||||
)
|
||||
|
||||
target_compile_definitions(core_ui_layout_workspace_compose_validation PRIVATE
|
||||
UNICODE
|
||||
_UNICODE
|
||||
)
|
||||
|
||||
if(MSVC)
|
||||
target_compile_options(core_ui_layout_workspace_compose_validation PRIVATE /utf-8 /FS)
|
||||
set_property(TARGET core_ui_layout_workspace_compose_validation PROPERTY
|
||||
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
|
||||
endif()
|
||||
|
||||
target_link_libraries(core_ui_layout_workspace_compose_validation PRIVATE
|
||||
core_ui_integration_host
|
||||
)
|
||||
|
||||
set_target_properties(core_ui_layout_workspace_compose_validation PROPERTIES
|
||||
OUTPUT_NAME "XCUICoreLayoutWorkspaceComposeValidation"
|
||||
)
|
||||
|
||||
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}" FILES View.xcui)
|
||||
@@ -1,94 +0,0 @@
|
||||
<View
|
||||
name="CoreWorkspaceComposeValidation"
|
||||
theme="../../shared/themes/core_validation.xctheme">
|
||||
<Column width="fill" height="fill" padding="20" gap="12">
|
||||
<Card
|
||||
title="功能:Workspace compose"
|
||||
subtitle="只检查共享工作区组合原语的 split + tab + placeholder,不检查任何业务面板"
|
||||
tone="accent"
|
||||
height="156">
|
||||
<Column gap="6">
|
||||
<Text text="1. 先看布局:左、中、右、下四个区域应边界清晰,没有重叠、穿透或错位。" />
|
||||
<Text text="2. 拖拽 workspace-left-right 和 workspace-top-bottom:各区域尺寸应实时变化,并被最小尺寸 clamp 住。" />
|
||||
<Text text="3. 点击中间的 Document A / B / C:只应显示当前 selected tab 的 placeholder 内容。" />
|
||||
<Text text="4. 这个场景只验证工作区组合基础,不代表 Hierarchy / Inspector / Console 已开始实现。" />
|
||||
</Column>
|
||||
</Card>
|
||||
|
||||
<Splitter
|
||||
id="workspace-top-bottom"
|
||||
axis="vertical"
|
||||
splitRatio="0.76"
|
||||
splitterSize="10"
|
||||
splitterHitSize="18"
|
||||
primaryMin="320"
|
||||
secondaryMin="120"
|
||||
height="fill">
|
||||
<Splitter
|
||||
id="workspace-left-right"
|
||||
axis="horizontal"
|
||||
splitRatio="0.24"
|
||||
splitterSize="10"
|
||||
splitterHitSize="18"
|
||||
primaryMin="160"
|
||||
secondaryMin="420"
|
||||
height="fill">
|
||||
<Card id="workspace-left-slot" title="Navigation Slot" subtitle="placeholder panel host" height="fill">
|
||||
<Column gap="8">
|
||||
<Text text="这里是左侧 placeholder slot,只检查 pane compose。" />
|
||||
</Column>
|
||||
</Card>
|
||||
|
||||
<Splitter
|
||||
id="workspace-center-right"
|
||||
axis="horizontal"
|
||||
splitRatio="0.70"
|
||||
splitterSize="10"
|
||||
splitterHitSize="18"
|
||||
primaryMin="260"
|
||||
secondaryMin="180"
|
||||
height="fill">
|
||||
<TabStrip
|
||||
id="workspace-document-tabs"
|
||||
tabHeaderHeight="34"
|
||||
tabMinWidth="112"
|
||||
height="fill">
|
||||
<Tab id="tab-document-a" label="Document A" selected="true">
|
||||
<Card title="Primary Document Slot" subtitle="selected = Document A" height="fill">
|
||||
<Column gap="8">
|
||||
<Text text="这里应只显示 Document A 的 placeholder 内容。" />
|
||||
</Column>
|
||||
</Card>
|
||||
</Tab>
|
||||
<Tab id="tab-document-b" label="Document B">
|
||||
<Card title="Secondary Document Slot" subtitle="selected = Document B" height="fill">
|
||||
<Column gap="8">
|
||||
<Text text="切换到 Document B 后,A 的内容应消失。" />
|
||||
</Column>
|
||||
</Card>
|
||||
</Tab>
|
||||
<Tab id="tab-document-c" label="Document C">
|
||||
<Card title="Tertiary Document Slot" subtitle="selected = Document C" height="fill">
|
||||
<Column gap="8">
|
||||
<Text text="这里只是第三个 placeholder,不代表真实面板业务。" />
|
||||
</Column>
|
||||
</Card>
|
||||
</Tab>
|
||||
</TabStrip>
|
||||
|
||||
<Card id="workspace-right-slot" title="Details Slot" subtitle="placeholder panel host" height="fill">
|
||||
<Column gap="8">
|
||||
<Text text="这里是右侧 placeholder slot,只检查嵌套 split 稳定性。" />
|
||||
</Column>
|
||||
</Card>
|
||||
</Splitter>
|
||||
</Splitter>
|
||||
|
||||
<Card id="workspace-bottom-slot" title="Output Slot" subtitle="placeholder panel host" height="fill">
|
||||
<Column gap="8">
|
||||
<Text text="这里是底部 placeholder slot,用来检查上下 split compose。" />
|
||||
</Column>
|
||||
</Card>
|
||||
</Splitter>
|
||||
</Column>
|
||||
</View>
|
||||
@@ -1,8 +0,0 @@
|
||||
#include "Application.h"
|
||||
|
||||
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, LPWSTR, int nCmdShow) {
|
||||
return XCEngine::Tests::CoreUI::RunCoreUIValidationApp(
|
||||
hInstance,
|
||||
nCmdShow,
|
||||
"core.layout.workspace_compose");
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
add_subdirectory(draw_primitives_basic)
|
||||
|
||||
add_custom_target(core_ui_render_integration_tests
|
||||
DEPENDS
|
||||
core_ui_render_draw_primitives_basic_validation
|
||||
)
|
||||
@@ -1,27 +0,0 @@
|
||||
add_executable(core_ui_render_draw_primitives_basic_validation WIN32
|
||||
main.cpp
|
||||
)
|
||||
|
||||
target_include_directories(core_ui_render_draw_primitives_basic_validation PRIVATE
|
||||
${CMAKE_SOURCE_DIR}/tests/UI/Core/integration/shared/src
|
||||
${CMAKE_SOURCE_DIR}/engine/include
|
||||
)
|
||||
|
||||
target_compile_definitions(core_ui_render_draw_primitives_basic_validation PRIVATE
|
||||
UNICODE
|
||||
_UNICODE
|
||||
)
|
||||
|
||||
if(MSVC)
|
||||
target_compile_options(core_ui_render_draw_primitives_basic_validation PRIVATE /utf-8 /FS)
|
||||
set_property(TARGET core_ui_render_draw_primitives_basic_validation PROPERTY
|
||||
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
|
||||
endif()
|
||||
|
||||
target_link_libraries(core_ui_render_draw_primitives_basic_validation PRIVATE
|
||||
core_ui_integration_host
|
||||
)
|
||||
|
||||
set_target_properties(core_ui_render_draw_primitives_basic_validation PROPERTIES
|
||||
OUTPUT_NAME "XCUICoreRenderDrawPrimitivesBasicValidation"
|
||||
)
|
||||
@@ -1,465 +0,0 @@
|
||||
#ifndef NOMINMAX
|
||||
#define NOMINMAX
|
||||
#endif
|
||||
|
||||
#include "AutoScreenshot.h"
|
||||
#include "NativeRenderer.h"
|
||||
|
||||
#include <XCEngine/UI/DrawData.h>
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
|
||||
#ifndef XCENGINE_CORE_UI_TESTS_REPO_ROOT
|
||||
#define XCENGINE_CORE_UI_TESTS_REPO_ROOT "."
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
|
||||
using XCEngine::Tests::CoreUI::Host::AutoScreenshotController;
|
||||
using XCEngine::Tests::CoreUI::Host::NativeRenderer;
|
||||
using XCEngine::UI::UIColor;
|
||||
using XCEngine::UI::UIDrawData;
|
||||
using XCEngine::UI::UIDrawList;
|
||||
using XCEngine::UI::UILinearGradientDirection;
|
||||
using XCEngine::UI::UIPoint;
|
||||
using XCEngine::UI::UIRect;
|
||||
|
||||
constexpr const wchar_t* kWindowClassName = L"XCUICoreRenderDrawPrimitivesBasicValidation";
|
||||
constexpr const wchar_t* kWindowTitle = L"XCUI Core | Draw Primitives Basic";
|
||||
|
||||
constexpr UIColor kWindowColor(0.09f, 0.09f, 0.09f, 1.0f);
|
||||
constexpr UIColor kCardColor(0.15f, 0.15f, 0.15f, 1.0f);
|
||||
constexpr UIColor kCardBorderColor(0.26f, 0.26f, 0.26f, 1.0f);
|
||||
constexpr UIColor kTitleColor(0.95f, 0.95f, 0.95f, 1.0f);
|
||||
constexpr UIColor kBodyColor(0.82f, 0.82f, 0.82f, 1.0f);
|
||||
constexpr UIColor kMutedColor(0.64f, 0.64f, 0.64f, 1.0f);
|
||||
constexpr UIColor kCheckerLight(0.74f, 0.74f, 0.74f, 1.0f);
|
||||
constexpr UIColor kCheckerDark(0.46f, 0.46f, 0.46f, 1.0f);
|
||||
|
||||
struct ScenarioLayout {
|
||||
UIRect introRect = {};
|
||||
UIRect stateRect = {};
|
||||
UIRect previewRect = {};
|
||||
UIRect gradientRowRect = {};
|
||||
UIRect svRect = {};
|
||||
UIRect hueStripRect = {};
|
||||
UIRect closeButtonRect = {};
|
||||
UIRect alphaPreviewRect = {};
|
||||
};
|
||||
|
||||
std::filesystem::path ResolveRepoRootPath() {
|
||||
std::string root = XCENGINE_CORE_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();
|
||||
}
|
||||
|
||||
ScenarioLayout BuildScenarioLayout(float width, float height) {
|
||||
constexpr float margin = 20.0f;
|
||||
constexpr float gap = 16.0f;
|
||||
constexpr float leftWidth = 430.0f;
|
||||
|
||||
ScenarioLayout layout = {};
|
||||
layout.introRect = UIRect(margin, margin, leftWidth, 220.0f);
|
||||
layout.stateRect = UIRect(
|
||||
margin,
|
||||
layout.introRect.y + layout.introRect.height + gap,
|
||||
leftWidth,
|
||||
(std::max)(240.0f, height - layout.introRect.height - gap - margin * 2.0f));
|
||||
layout.previewRect = UIRect(
|
||||
margin * 2.0f + leftWidth,
|
||||
margin,
|
||||
(std::max)(460.0f, width - leftWidth - margin * 3.0f),
|
||||
height - margin * 2.0f);
|
||||
|
||||
const float contentX = layout.previewRect.x + 24.0f;
|
||||
const float contentY = layout.previewRect.y + 58.0f;
|
||||
layout.gradientRowRect = UIRect(contentX, contentY, 360.0f, 24.0f);
|
||||
layout.svRect = UIRect(contentX, contentY + 52.0f, 208.0f, 208.0f);
|
||||
layout.hueStripRect = UIRect(layout.svRect.x + layout.svRect.width + 18.0f, layout.svRect.y, 28.0f, layout.svRect.height);
|
||||
layout.alphaPreviewRect = UIRect(layout.hueStripRect.x + layout.hueStripRect.width + 26.0f, layout.svRect.y, 96.0f, 48.0f);
|
||||
layout.closeButtonRect = UIRect(
|
||||
layout.previewRect.x + layout.previewRect.width - 42.0f,
|
||||
layout.previewRect.y + 18.0f,
|
||||
20.0f,
|
||||
20.0f);
|
||||
return layout;
|
||||
}
|
||||
|
||||
bool ShouldAutoCaptureOnStartup() {
|
||||
const char* value = std::getenv("XCUI_AUTO_CAPTURE_ON_STARTUP");
|
||||
return value != nullptr && value[0] == '1' && value[1] == '\0';
|
||||
}
|
||||
|
||||
void DrawCard(UIDrawList& drawList, const UIRect& rect) {
|
||||
drawList.AddFilledRect(rect, kCardColor, 8.0f);
|
||||
drawList.AddRectOutline(rect, kCardBorderColor, 1.0f, 8.0f);
|
||||
}
|
||||
|
||||
void DrawCheckerboard(UIDrawList& drawList, const UIRect& rect, float cellSize) {
|
||||
const int columns = static_cast<int>(std::ceil(rect.width / cellSize));
|
||||
const int rows = static_cast<int>(std::ceil(rect.height / cellSize));
|
||||
for (int row = 0; row < rows; ++row) {
|
||||
for (int column = 0; column < columns; ++column) {
|
||||
const bool light = ((row + column) & 1) == 0;
|
||||
const float x = rect.x + cellSize * static_cast<float>(column);
|
||||
const float y = rect.y + cellSize * static_cast<float>(row);
|
||||
drawList.AddFilledRect(
|
||||
UIRect(
|
||||
x,
|
||||
y,
|
||||
(std::min)(cellSize, rect.x + rect.width - x),
|
||||
(std::min)(cellSize, rect.y + rect.height - y)),
|
||||
light ? kCheckerLight : kCheckerDark);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 = reinterpret_cast<ScenarioApp*>(createStruct->lpCreateParams);
|
||||
SetWindowLongPtrW(hwnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(app));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
auto* app = reinterpret_cast<ScenarioApp*>(GetWindowLongPtrW(hwnd, GWLP_USERDATA));
|
||||
switch (message) {
|
||||
case WM_SIZE:
|
||||
if (app != nullptr && wParam != SIZE_MINIMIZED) {
|
||||
app->m_renderer.Resize(static_cast<UINT>(LOWORD(lParam)), static_cast<UINT>(HIWORD(lParam)));
|
||||
}
|
||||
return 0;
|
||||
case WM_KEYDOWN:
|
||||
case WM_SYSKEYDOWN:
|
||||
if (app != nullptr) {
|
||||
if (wParam == VK_F12) {
|
||||
app->m_autoScreenshot.RequestCapture("manual_f12");
|
||||
app->m_lastStatus = "已请求截图,输出到 captures/latest.png";
|
||||
InvalidateRect(hwnd, nullptr, FALSE);
|
||||
return 0;
|
||||
}
|
||||
if (wParam == 'R') {
|
||||
app->ResetScenario();
|
||||
InvalidateRect(hwnd, nullptr, FALSE);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case WM_PAINT:
|
||||
if (app != nullptr) {
|
||||
PAINTSTRUCT paintStruct = {};
|
||||
BeginPaint(hwnd, &paintStruct);
|
||||
app->RenderFrame();
|
||||
EndPaint(hwnd, &paintStruct);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case WM_ERASEBKGND:
|
||||
return 1;
|
||||
case WM_DESTROY:
|
||||
if (app != nullptr) {
|
||||
app->m_hwnd = nullptr;
|
||||
}
|
||||
PostQuitMessage(0);
|
||||
return 0;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return DefWindowProcW(hwnd, message, wParam, lParam);
|
||||
}
|
||||
|
||||
bool Initialize(HINSTANCE hInstance, int nCmdShow) {
|
||||
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,
|
||||
920,
|
||||
nullptr,
|
||||
nullptr,
|
||||
hInstance,
|
||||
this);
|
||||
if (m_hwnd == nullptr || !m_renderer.Initialize(m_hwnd)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ShowWindow(m_hwnd, nCmdShow);
|
||||
UpdateWindow(m_hwnd);
|
||||
|
||||
m_captureRoot =
|
||||
ResolveRepoRootPath() / "tests/UI/Core/integration/render/draw_primitives_basic/captures";
|
||||
m_autoScreenshot.Initialize(m_captureRoot);
|
||||
ResetScenario();
|
||||
if (ShouldAutoCaptureOnStartup()) {
|
||||
m_autoScreenshot.RequestCapture("startup");
|
||||
m_lastStatus = "已请求启动截图";
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void Shutdown() {
|
||||
m_autoScreenshot.Shutdown();
|
||||
m_renderer.Shutdown();
|
||||
if (m_hwnd != nullptr && IsWindow(m_hwnd)) {
|
||||
DestroyWindow(m_hwnd);
|
||||
}
|
||||
if (m_windowClassAtom != 0) {
|
||||
UnregisterClassW(kWindowClassName, GetModuleHandleW(nullptr));
|
||||
}
|
||||
}
|
||||
|
||||
void ResetScenario() {
|
||||
m_lastStatus = "已重置到默认 Draw Primitives 场景";
|
||||
}
|
||||
|
||||
void RenderFrame() {
|
||||
RECT clientRect = {};
|
||||
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 ScenarioLayout layout = BuildScenarioLayout(width, height);
|
||||
|
||||
UIDrawData drawData = {};
|
||||
UIDrawList& drawList = drawData.EmplaceDrawList("CoreDrawPrimitives");
|
||||
drawList.AddFilledRect(UIRect(0.0f, 0.0f, width, height), kWindowColor);
|
||||
|
||||
DrawCard(drawList, layout.introRect);
|
||||
DrawCard(drawList, layout.stateRect);
|
||||
DrawCard(drawList, layout.previewRect);
|
||||
|
||||
drawList.AddText(
|
||||
UIPoint(layout.introRect.x + 16.0f, layout.introRect.y + 14.0f),
|
||||
"这个测试在验证什么功能?",
|
||||
kTitleColor,
|
||||
17.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(layout.introRect.x + 16.0f, layout.introRect.y + 40.0f),
|
||||
"只验证 UI Core 新增的 linear gradient / line / circle primitive 的真实渲染。",
|
||||
kMutedColor,
|
||||
12.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(layout.introRect.x + 16.0f, layout.introRect.y + 74.0f),
|
||||
"1. 右侧横向和纵向 gradient 不能出现纯色退化或明显断层。",
|
||||
kBodyColor,
|
||||
12.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(layout.introRect.x + 16.0f, layout.introRect.y + 96.0f),
|
||||
"2. SV 方块应由两层 gradient 叠加;白到主色、再由透明到黑。",
|
||||
kBodyColor,
|
||||
12.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(layout.introRect.x + 16.0f, layout.introRect.y + 118.0f),
|
||||
"3. 手柄必须是圆形;关闭按钮 X 和标尺都必须是 line,不准用文字假冒。",
|
||||
kBodyColor,
|
||||
12.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(layout.introRect.x + 16.0f, layout.introRect.y + 140.0f),
|
||||
"4. 按 F12 手动截图;设置 XCUI_AUTO_CAPTURE_ON_STARTUP=1 可自动截图;按 R 重置。",
|
||||
kBodyColor,
|
||||
12.0f);
|
||||
|
||||
drawList.AddText(
|
||||
UIPoint(layout.stateRect.x + 16.0f, layout.stateRect.y + 14.0f),
|
||||
"状态摘要",
|
||||
kTitleColor,
|
||||
17.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(layout.stateRect.x + 16.0f, layout.stateRect.y + 44.0f),
|
||||
"Primitive: FilledRectLinearGradient / Line / FilledCircle / CircleOutline",
|
||||
kBodyColor,
|
||||
12.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(layout.stateRect.x + 16.0f, layout.stateRect.y + 68.0f),
|
||||
"Preview: Gradient Row + SV Square + Hue Strip + Close Button + Alpha Preview",
|
||||
kBodyColor,
|
||||
12.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(layout.stateRect.x + 16.0f, layout.stateRect.y + 92.0f),
|
||||
"Result: " + m_lastStatus,
|
||||
kBodyColor,
|
||||
12.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(layout.stateRect.x + 16.0f, layout.stateRect.y + 116.0f),
|
||||
m_autoScreenshot.GetLastCaptureSummary().empty()
|
||||
? std::string("Capture: F12 -> tests/UI/Core/integration/render/draw_primitives_basic/captures/")
|
||||
: ("Capture: " + m_autoScreenshot.GetLastCaptureSummary()),
|
||||
kMutedColor,
|
||||
12.0f);
|
||||
if (!m_autoScreenshot.GetLastCaptureError().empty()) {
|
||||
drawList.AddText(
|
||||
UIPoint(layout.stateRect.x + 16.0f, layout.stateRect.y + 140.0f),
|
||||
"Error: " + m_autoScreenshot.GetLastCaptureError(),
|
||||
UIColor(0.95f, 0.56f, 0.56f, 1.0f),
|
||||
12.0f);
|
||||
}
|
||||
|
||||
drawList.AddText(
|
||||
UIPoint(layout.previewRect.x + 16.0f, layout.previewRect.y + 14.0f),
|
||||
"Draw Primitives 预览",
|
||||
kTitleColor,
|
||||
17.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(layout.previewRect.x + 16.0f, layout.previewRect.y + 36.0f),
|
||||
"这里不验证 ColorField 业务,只验证底层绘制 primitive 的像素效果。",
|
||||
kMutedColor,
|
||||
12.0f);
|
||||
|
||||
drawList.AddFilledRectLinearGradient(
|
||||
layout.gradientRowRect,
|
||||
UIColor(0.95f, 0.27f, 0.27f, 1.0f),
|
||||
UIColor(0.14f, 0.72f, 0.94f, 1.0f),
|
||||
UILinearGradientDirection::Horizontal,
|
||||
3.0f);
|
||||
drawList.AddRectOutline(layout.gradientRowRect, UIColor(0.12f, 0.12f, 0.12f, 1.0f), 1.0f, 3.0f);
|
||||
const float markerX = layout.gradientRowRect.x + layout.gradientRowRect.width * 0.68f;
|
||||
drawList.AddLine(
|
||||
UIPoint(markerX, layout.gradientRowRect.y - 2.0f),
|
||||
UIPoint(markerX, layout.gradientRowRect.y + layout.gradientRowRect.height + 2.0f),
|
||||
UIColor(1.0f, 1.0f, 1.0f, 1.0f),
|
||||
2.0f);
|
||||
|
||||
drawList.AddFilledRectLinearGradient(
|
||||
layout.svRect,
|
||||
UIColor(1.0f, 1.0f, 1.0f, 1.0f),
|
||||
UIColor(0.23f, 0.64f, 0.98f, 1.0f),
|
||||
UILinearGradientDirection::Horizontal,
|
||||
2.0f);
|
||||
drawList.AddFilledRectLinearGradient(
|
||||
layout.svRect,
|
||||
UIColor(0.0f, 0.0f, 0.0f, 0.0f),
|
||||
UIColor(0.0f, 0.0f, 0.0f, 1.0f),
|
||||
UILinearGradientDirection::Vertical,
|
||||
2.0f);
|
||||
drawList.AddRectOutline(layout.svRect, UIColor(0.12f, 0.12f, 0.12f, 1.0f), 1.0f, 2.0f);
|
||||
const UIPoint svHandle(
|
||||
layout.svRect.x + layout.svRect.width * 0.72f,
|
||||
layout.svRect.y + layout.svRect.height * 0.34f);
|
||||
drawList.AddFilledCircle(svHandle, 5.0f, UIColor(1.0f, 1.0f, 1.0f, 0.15f));
|
||||
drawList.AddCircleOutline(svHandle, 7.0f, UIColor(1.0f, 1.0f, 1.0f, 1.0f), 2.0f);
|
||||
drawList.AddCircleOutline(svHandle, 8.0f, UIColor(0.0f, 0.0f, 0.0f, 0.35f), 1.0f);
|
||||
|
||||
const float segmentHeight = layout.hueStripRect.height / 6.0f;
|
||||
const UIColor hueStops[7] = {
|
||||
UIColor(1.0f, 0.0f, 0.0f, 1.0f),
|
||||
UIColor(1.0f, 1.0f, 0.0f, 1.0f),
|
||||
UIColor(0.0f, 1.0f, 0.0f, 1.0f),
|
||||
UIColor(0.0f, 1.0f, 1.0f, 1.0f),
|
||||
UIColor(0.0f, 0.0f, 1.0f, 1.0f),
|
||||
UIColor(1.0f, 0.0f, 1.0f, 1.0f),
|
||||
UIColor(1.0f, 0.0f, 0.0f, 1.0f)
|
||||
};
|
||||
for (int index = 0; index < 6; ++index) {
|
||||
drawList.AddFilledRectLinearGradient(
|
||||
UIRect(
|
||||
layout.hueStripRect.x,
|
||||
layout.hueStripRect.y + segmentHeight * static_cast<float>(index),
|
||||
layout.hueStripRect.width,
|
||||
segmentHeight + 1.0f),
|
||||
hueStops[index],
|
||||
hueStops[index + 1],
|
||||
UILinearGradientDirection::Vertical,
|
||||
0.0f);
|
||||
}
|
||||
drawList.AddRectOutline(layout.hueStripRect, UIColor(0.12f, 0.12f, 0.12f, 1.0f), 1.0f, 2.0f);
|
||||
const float hueMarkerY = layout.hueStripRect.y + layout.hueStripRect.height * 0.44f;
|
||||
drawList.AddLine(
|
||||
UIPoint(layout.hueStripRect.x - 4.0f, hueMarkerY),
|
||||
UIPoint(layout.hueStripRect.x + layout.hueStripRect.width + 4.0f, hueMarkerY),
|
||||
UIColor(1.0f, 1.0f, 1.0f, 1.0f),
|
||||
2.0f);
|
||||
|
||||
DrawCheckerboard(drawList, layout.alphaPreviewRect, 6.0f);
|
||||
drawList.AddFilledRect(
|
||||
UIRect(
|
||||
layout.alphaPreviewRect.x,
|
||||
layout.alphaPreviewRect.y,
|
||||
layout.alphaPreviewRect.width,
|
||||
layout.alphaPreviewRect.height),
|
||||
UIColor(0.23f, 0.64f, 0.98f, 0.55f),
|
||||
2.0f);
|
||||
drawList.AddRectOutline(layout.alphaPreviewRect, UIColor(0.12f, 0.12f, 0.12f, 1.0f), 1.0f, 2.0f);
|
||||
|
||||
drawList.AddRectOutline(layout.closeButtonRect, UIColor(0.38f, 0.38f, 0.38f, 1.0f), 1.0f, 2.0f);
|
||||
drawList.AddLine(
|
||||
UIPoint(layout.closeButtonRect.x + 5.0f, layout.closeButtonRect.y + 5.0f),
|
||||
UIPoint(layout.closeButtonRect.x + layout.closeButtonRect.width - 5.0f, layout.closeButtonRect.y + layout.closeButtonRect.height - 5.0f),
|
||||
UIColor(0.92f, 0.92f, 0.92f, 1.0f),
|
||||
1.5f);
|
||||
drawList.AddLine(
|
||||
UIPoint(layout.closeButtonRect.x + layout.closeButtonRect.width - 5.0f, layout.closeButtonRect.y + 5.0f),
|
||||
UIPoint(layout.closeButtonRect.x + 5.0f, layout.closeButtonRect.y + layout.closeButtonRect.height - 5.0f),
|
||||
UIColor(0.92f, 0.92f, 0.92f, 1.0f),
|
||||
1.5f);
|
||||
|
||||
const bool framePresented = m_renderer.Render(drawData);
|
||||
m_autoScreenshot.CaptureIfRequested(
|
||||
m_renderer,
|
||||
drawData,
|
||||
static_cast<unsigned int>(width),
|
||||
static_cast<unsigned int>(height),
|
||||
framePresented);
|
||||
}
|
||||
|
||||
HWND m_hwnd = nullptr;
|
||||
ATOM m_windowClassAtom = 0;
|
||||
NativeRenderer m_renderer = {};
|
||||
AutoScreenshotController m_autoScreenshot = {};
|
||||
std::filesystem::path m_captureRoot = {};
|
||||
std::string m_lastStatus = "等待检查";
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, LPWSTR, int nCmdShow) {
|
||||
return ScenarioApp().Run(hInstance, nCmdShow);
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
file(TO_CMAKE_PATH "${CMAKE_SOURCE_DIR}" XCENGINE_CORE_UI_TESTS_REPO_ROOT_PATH)
|
||||
file(TO_CMAKE_PATH "${CMAKE_BINARY_DIR}" XCENGINE_CORE_UI_TESTS_BUILD_ROOT_PATH)
|
||||
|
||||
add_library(core_ui_validation_registry STATIC
|
||||
src/CoreValidationScenario.cpp
|
||||
)
|
||||
|
||||
target_include_directories(core_ui_validation_registry
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src
|
||||
${CMAKE_SOURCE_DIR}/engine/include
|
||||
)
|
||||
|
||||
target_compile_definitions(core_ui_validation_registry
|
||||
PUBLIC
|
||||
XCENGINE_CORE_UI_TESTS_REPO_ROOT="${XCENGINE_CORE_UI_TESTS_REPO_ROOT_PATH}"
|
||||
)
|
||||
|
||||
if(MSVC)
|
||||
target_compile_options(core_ui_validation_registry PRIVATE /utf-8 /FS)
|
||||
set_property(TARGET core_ui_validation_registry PROPERTY
|
||||
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
|
||||
endif()
|
||||
|
||||
target_link_libraries(core_ui_validation_registry
|
||||
PUBLIC
|
||||
XCEngine
|
||||
)
|
||||
|
||||
add_library(core_ui_integration_host STATIC
|
||||
src/AutoScreenshot.cpp
|
||||
src/Application.cpp
|
||||
src/DragDropValidationScene.cpp
|
||||
src/NativeRenderer.cpp
|
||||
src/PopupMenuOverlayValidationScene.cpp
|
||||
)
|
||||
|
||||
target_include_directories(core_ui_integration_host
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src
|
||||
${CMAKE_SOURCE_DIR}/engine/include
|
||||
)
|
||||
|
||||
target_compile_definitions(core_ui_integration_host
|
||||
PUBLIC
|
||||
UNICODE
|
||||
_UNICODE
|
||||
XCENGINE_CORE_UI_TESTS_REPO_ROOT="${XCENGINE_CORE_UI_TESTS_REPO_ROOT_PATH}"
|
||||
XCENGINE_CORE_UI_TESTS_BUILD_ROOT="${XCENGINE_CORE_UI_TESTS_BUILD_ROOT_PATH}"
|
||||
)
|
||||
|
||||
if(MSVC)
|
||||
target_compile_options(core_ui_integration_host PRIVATE /utf-8 /FS)
|
||||
set_property(TARGET core_ui_integration_host PROPERTY
|
||||
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
|
||||
endif()
|
||||
|
||||
target_link_libraries(core_ui_integration_host
|
||||
PUBLIC
|
||||
core_ui_validation_registry
|
||||
XCEngine
|
||||
d2d1.lib
|
||||
dwrite.lib
|
||||
windowscodecs.lib
|
||||
)
|
||||
@@ -1,874 +0,0 @@
|
||||
#include "Application.h"
|
||||
|
||||
#include <XCEngine/Input/InputTypes.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <filesystem>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <system_error>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
|
||||
#ifndef XCENGINE_CORE_UI_TESTS_REPO_ROOT
|
||||
#define XCENGINE_CORE_UI_TESTS_REPO_ROOT "."
|
||||
#endif
|
||||
|
||||
#ifndef XCENGINE_CORE_UI_TESTS_BUILD_ROOT
|
||||
#define XCENGINE_CORE_UI_TESTS_BUILD_ROOT "."
|
||||
#endif
|
||||
|
||||
namespace XCEngine::Tests::CoreUI {
|
||||
|
||||
namespace {
|
||||
|
||||
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::Runtime::UIScreenFrameInput;
|
||||
using ::XCEngine::Input::KeyCode;
|
||||
|
||||
constexpr const wchar_t* kWindowClassName = L"XCUICoreValidationHost";
|
||||
constexpr const wchar_t* kWindowTitle = L"XCUI Core Validation";
|
||||
constexpr auto kReloadPollInterval = std::chrono::milliseconds(150);
|
||||
|
||||
constexpr UIColor kOverlayBgColor(0.10f, 0.10f, 0.10f, 0.95f);
|
||||
constexpr UIColor kOverlayBorderColor(0.25f, 0.25f, 0.25f, 1.0f);
|
||||
constexpr UIColor kOverlayTextPrimary(0.93f, 0.93f, 0.93f, 1.0f);
|
||||
constexpr UIColor kOverlayTextMuted(0.70f, 0.70f, 0.70f, 1.0f);
|
||||
constexpr UIColor kOverlaySuccess(0.82f, 0.82f, 0.82f, 1.0f);
|
||||
constexpr UIColor kOverlayFallback(0.56f, 0.56f, 0.56f, 1.0f);
|
||||
|
||||
Application* GetApplicationFromWindow(HWND hwnd) {
|
||||
return reinterpret_cast<Application*>(GetWindowLongPtrW(hwnd, GWLP_USERDATA));
|
||||
}
|
||||
|
||||
std::filesystem::path GetRepoRootPath() {
|
||||
std::string root = XCENGINE_CORE_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_CORE_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;
|
||||
}
|
||||
|
||||
if (maxLength <= 3u) {
|
||||
return text.substr(0, maxLength);
|
||||
}
|
||||
|
||||
return text.substr(0, maxLength - 3u) + "...";
|
||||
}
|
||||
|
||||
std::string ExtractStateKeyTail(const std::string& stateKey) {
|
||||
if (stateKey.empty()) {
|
||||
return "-";
|
||||
}
|
||||
|
||||
const std::size_t separator = stateKey.find_last_of('/');
|
||||
if (separator == std::string::npos || separator + 1u >= stateKey.size()) {
|
||||
return stateKey;
|
||||
}
|
||||
|
||||
return stateKey.substr(separator + 1u);
|
||||
}
|
||||
|
||||
std::string FormatFloat(float value) {
|
||||
std::ostringstream stream;
|
||||
stream.setf(std::ios::fixed, std::ios::floatfield);
|
||||
stream.precision(1);
|
||||
stream << value;
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
std::string FormatPoint(const UIPoint& point) {
|
||||
return "(" + FormatFloat(point.x) + ", " + FormatFloat(point.y) + ")";
|
||||
}
|
||||
|
||||
std::string FormatRect(const UIRect& rect) {
|
||||
return "(" + FormatFloat(rect.x) +
|
||||
", " + FormatFloat(rect.y) +
|
||||
", " + FormatFloat(rect.width) +
|
||||
", " + FormatFloat(rect.height) +
|
||||
")";
|
||||
}
|
||||
|
||||
std::int32_t MapVirtualKeyToUIKeyCode(WPARAM wParam) {
|
||||
switch (wParam) {
|
||||
case 'A': return static_cast<std::int32_t>(KeyCode::A);
|
||||
case 'B': return static_cast<std::int32_t>(KeyCode::B);
|
||||
case 'C': return static_cast<std::int32_t>(KeyCode::C);
|
||||
case 'D': return static_cast<std::int32_t>(KeyCode::D);
|
||||
case 'E': return static_cast<std::int32_t>(KeyCode::E);
|
||||
case 'F': return static_cast<std::int32_t>(KeyCode::F);
|
||||
case 'G': return static_cast<std::int32_t>(KeyCode::G);
|
||||
case 'H': return static_cast<std::int32_t>(KeyCode::H);
|
||||
case 'I': return static_cast<std::int32_t>(KeyCode::I);
|
||||
case 'J': return static_cast<std::int32_t>(KeyCode::J);
|
||||
case 'K': return static_cast<std::int32_t>(KeyCode::K);
|
||||
case 'L': return static_cast<std::int32_t>(KeyCode::L);
|
||||
case 'M': return static_cast<std::int32_t>(KeyCode::M);
|
||||
case 'N': return static_cast<std::int32_t>(KeyCode::N);
|
||||
case 'O': return static_cast<std::int32_t>(KeyCode::O);
|
||||
case 'P': return static_cast<std::int32_t>(KeyCode::P);
|
||||
case 'Q': return static_cast<std::int32_t>(KeyCode::Q);
|
||||
case 'R': return static_cast<std::int32_t>(KeyCode::R);
|
||||
case 'S': return static_cast<std::int32_t>(KeyCode::S);
|
||||
case 'T': return static_cast<std::int32_t>(KeyCode::T);
|
||||
case 'U': return static_cast<std::int32_t>(KeyCode::U);
|
||||
case 'V': return static_cast<std::int32_t>(KeyCode::V);
|
||||
case 'W': return static_cast<std::int32_t>(KeyCode::W);
|
||||
case 'X': return static_cast<std::int32_t>(KeyCode::X);
|
||||
case 'Y': return static_cast<std::int32_t>(KeyCode::Y);
|
||||
case 'Z': return static_cast<std::int32_t>(KeyCode::Z);
|
||||
case '0': return static_cast<std::int32_t>(KeyCode::Zero);
|
||||
case '1': return static_cast<std::int32_t>(KeyCode::One);
|
||||
case '2': return static_cast<std::int32_t>(KeyCode::Two);
|
||||
case '3': return static_cast<std::int32_t>(KeyCode::Three);
|
||||
case '4': return static_cast<std::int32_t>(KeyCode::Four);
|
||||
case '5': return static_cast<std::int32_t>(KeyCode::Five);
|
||||
case '6': return static_cast<std::int32_t>(KeyCode::Six);
|
||||
case '7': return static_cast<std::int32_t>(KeyCode::Seven);
|
||||
case '8': return static_cast<std::int32_t>(KeyCode::Eight);
|
||||
case '9': return static_cast<std::int32_t>(KeyCode::Nine);
|
||||
case VK_SPACE: return static_cast<std::int32_t>(KeyCode::Space);
|
||||
case VK_TAB: return static_cast<std::int32_t>(KeyCode::Tab);
|
||||
case VK_RETURN: return static_cast<std::int32_t>(KeyCode::Enter);
|
||||
case VK_ESCAPE: return static_cast<std::int32_t>(KeyCode::Escape);
|
||||
case VK_SHIFT: return static_cast<std::int32_t>(KeyCode::LeftShift);
|
||||
case VK_CONTROL: return static_cast<std::int32_t>(KeyCode::LeftCtrl);
|
||||
case VK_MENU: return static_cast<std::int32_t>(KeyCode::LeftAlt);
|
||||
case VK_UP: return static_cast<std::int32_t>(KeyCode::Up);
|
||||
case VK_DOWN: return static_cast<std::int32_t>(KeyCode::Down);
|
||||
case VK_LEFT: return static_cast<std::int32_t>(KeyCode::Left);
|
||||
case VK_RIGHT: return static_cast<std::int32_t>(KeyCode::Right);
|
||||
case VK_HOME: return static_cast<std::int32_t>(KeyCode::Home);
|
||||
case VK_END: return static_cast<std::int32_t>(KeyCode::End);
|
||||
case VK_PRIOR: return static_cast<std::int32_t>(KeyCode::PageUp);
|
||||
case VK_NEXT: return static_cast<std::int32_t>(KeyCode::PageDown);
|
||||
case VK_DELETE: return static_cast<std::int32_t>(KeyCode::Delete);
|
||||
case VK_BACK: return static_cast<std::int32_t>(KeyCode::Backspace);
|
||||
case VK_F1: return static_cast<std::int32_t>(KeyCode::F1);
|
||||
case VK_F2: return static_cast<std::int32_t>(KeyCode::F2);
|
||||
case VK_F3: return static_cast<std::int32_t>(KeyCode::F3);
|
||||
case VK_F4: return static_cast<std::int32_t>(KeyCode::F4);
|
||||
case VK_F5: return static_cast<std::int32_t>(KeyCode::F5);
|
||||
case VK_F6: return static_cast<std::int32_t>(KeyCode::F6);
|
||||
case VK_F7: return static_cast<std::int32_t>(KeyCode::F7);
|
||||
case VK_F8: return static_cast<std::int32_t>(KeyCode::F8);
|
||||
case VK_F9: return static_cast<std::int32_t>(KeyCode::F9);
|
||||
case VK_F10: return static_cast<std::int32_t>(KeyCode::F10);
|
||||
case VK_F11: return static_cast<std::int32_t>(KeyCode::F11);
|
||||
case VK_F12: return static_cast<std::int32_t>(KeyCode::F12);
|
||||
default: return static_cast<std::int32_t>(KeyCode::None);
|
||||
}
|
||||
}
|
||||
|
||||
bool IsRepeatKeyMessage(LPARAM lParam) {
|
||||
return (static_cast<unsigned long>(lParam) & (1ul << 30)) != 0ul;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
Application::Application(std::string requestedScenarioId)
|
||||
: m_screenPlayer(m_documentHost)
|
||||
, m_requestedScenarioId(std::move(requestedScenarioId)) {
|
||||
}
|
||||
|
||||
int Application::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);
|
||||
}
|
||||
|
||||
bool Application::Initialize(HINSTANCE hInstance, int nCmdShow) {
|
||||
m_hInstance = hInstance;
|
||||
|
||||
WNDCLASSEXW windowClass = {};
|
||||
windowClass.cbSize = sizeof(windowClass);
|
||||
windowClass.style = CS_HREDRAW | CS_VREDRAW;
|
||||
windowClass.lpfnWndProc = &Application::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,
|
||||
900,
|
||||
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_startTime = std::chrono::steady_clock::now();
|
||||
m_lastFrameTime = m_startTime;
|
||||
const CoreValidationScenario* initialScenario = m_requestedScenarioId.empty()
|
||||
? &GetDefaultCoreValidationScenario()
|
||||
: FindCoreValidationScenario(m_requestedScenarioId);
|
||||
if (initialScenario == nullptr) {
|
||||
initialScenario = &GetDefaultCoreValidationScenario();
|
||||
}
|
||||
m_autoScreenshot.Initialize(
|
||||
ResolveCaptureOutputRoot(initialScenario->captureRootPath));
|
||||
LoadStructuredScreen("startup");
|
||||
return true;
|
||||
}
|
||||
|
||||
void Application::Shutdown() {
|
||||
m_autoScreenshot.Shutdown();
|
||||
m_screenPlayer.Unload();
|
||||
m_trackedFiles.clear();
|
||||
m_screenAsset = {};
|
||||
m_useStructuredScreen = false;
|
||||
m_runtimeStatus.clear();
|
||||
m_runtimeError.clear();
|
||||
m_frameIndex = 0;
|
||||
|
||||
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 Application::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 auto now = std::chrono::steady_clock::now();
|
||||
double deltaTimeSeconds = std::chrono::duration<double>(now - m_lastFrameTime).count();
|
||||
if (deltaTimeSeconds <= 0.0) {
|
||||
deltaTimeSeconds = 1.0 / 60.0;
|
||||
}
|
||||
m_lastFrameTime = now;
|
||||
|
||||
RefreshStructuredScreen();
|
||||
std::vector<UIInputEvent> frameEvents = std::move(m_pendingInputEvents);
|
||||
m_pendingInputEvents.clear();
|
||||
|
||||
UIDrawData drawData = {};
|
||||
const UIRect viewportRect(0.0f, 0.0f, width, height);
|
||||
const bool windowFocused = GetForegroundWindow() == m_hwnd;
|
||||
if (m_activeScenario != nullptr &&
|
||||
m_activeScenario->id == PopupMenuOverlayValidationScene::ScenarioId) {
|
||||
m_popupMenuOverlayScene.Update(frameEvents, viewportRect, windowFocused);
|
||||
}
|
||||
if (m_activeScenario != nullptr &&
|
||||
m_activeScenario->id == DragDropValidationScene::ScenarioId) {
|
||||
m_dragDropValidationScene.Update(frameEvents, viewportRect, windowFocused);
|
||||
}
|
||||
|
||||
if (m_useStructuredScreen && m_screenPlayer.IsLoaded()) {
|
||||
UIScreenFrameInput input = {};
|
||||
input.viewportRect = viewportRect;
|
||||
input.events = std::move(frameEvents);
|
||||
input.deltaTimeSeconds = deltaTimeSeconds;
|
||||
input.frameIndex = ++m_frameIndex;
|
||||
input.focused = windowFocused;
|
||||
|
||||
const auto& frame = m_screenPlayer.Update(input);
|
||||
for (const auto& drawList : frame.drawData.GetDrawLists()) {
|
||||
drawData.AddDrawList(drawList);
|
||||
}
|
||||
|
||||
m_runtimeStatus = m_activeScenario != nullptr
|
||||
? m_activeScenario->displayName
|
||||
: "Core UI Validation";
|
||||
m_runtimeError = frame.errorMessage;
|
||||
}
|
||||
|
||||
if (m_activeScenario != nullptr &&
|
||||
m_activeScenario->id == PopupMenuOverlayValidationScene::ScenarioId) {
|
||||
m_popupMenuOverlayScene.AppendDrawData(drawData, viewportRect);
|
||||
}
|
||||
if (m_activeScenario != nullptr &&
|
||||
m_activeScenario->id == DragDropValidationScene::ScenarioId) {
|
||||
m_dragDropValidationScene.AppendDrawData(drawData, viewportRect);
|
||||
}
|
||||
|
||||
if (drawData.Empty()) {
|
||||
m_runtimeStatus = "Core UI Validation | Load Error";
|
||||
if (m_runtimeError.empty() && !m_screenPlayer.IsLoaded()) {
|
||||
m_runtimeError = m_screenPlayer.GetLastError();
|
||||
}
|
||||
}
|
||||
|
||||
AppendRuntimeOverlay(drawData, width, height);
|
||||
|
||||
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 Application::OnResize(UINT width, UINT height) {
|
||||
if (width == 0 || height == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_renderer.Resize(width, height);
|
||||
}
|
||||
|
||||
void Application::QueuePointerEvent(UIInputEventType type, UIPointerButton button, WPARAM wParam, LPARAM lParam) {
|
||||
UIInputEvent event = {};
|
||||
event.type = type;
|
||||
event.pointerButton = button;
|
||||
event.position = UIPoint(
|
||||
static_cast<float>(GET_X_LPARAM(lParam)),
|
||||
static_cast<float>(GET_Y_LPARAM(lParam)));
|
||||
event.modifiers = m_inputModifierTracker.BuildPointerModifiers(static_cast<size_t>(wParam));
|
||||
m_pendingInputEvents.push_back(event);
|
||||
}
|
||||
|
||||
void Application::QueuePointerLeaveEvent() {
|
||||
UIInputEvent event = {};
|
||||
event.type = UIInputEventType::PointerLeave;
|
||||
if (m_hwnd != nullptr) {
|
||||
POINT clientPoint = {};
|
||||
GetCursorPos(&clientPoint);
|
||||
ScreenToClient(m_hwnd, &clientPoint);
|
||||
event.position = UIPoint(static_cast<float>(clientPoint.x), static_cast<float>(clientPoint.y));
|
||||
}
|
||||
m_pendingInputEvents.push_back(event);
|
||||
}
|
||||
|
||||
void Application::QueuePointerWheelEvent(short wheelDelta, WPARAM wParam, LPARAM lParam) {
|
||||
if (m_hwnd == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
POINT screenPoint = {
|
||||
GET_X_LPARAM(lParam),
|
||||
GET_Y_LPARAM(lParam)
|
||||
};
|
||||
ScreenToClient(m_hwnd, &screenPoint);
|
||||
|
||||
UIInputEvent event = {};
|
||||
event.type = UIInputEventType::PointerWheel;
|
||||
event.position = UIPoint(static_cast<float>(screenPoint.x), static_cast<float>(screenPoint.y));
|
||||
event.wheelDelta = static_cast<float>(wheelDelta);
|
||||
event.modifiers = m_inputModifierTracker.BuildPointerModifiers(static_cast<size_t>(wParam));
|
||||
m_pendingInputEvents.push_back(event);
|
||||
}
|
||||
|
||||
void Application::QueueKeyEvent(UIInputEventType type, WPARAM wParam, LPARAM lParam) {
|
||||
UIInputEvent event = {};
|
||||
event.type = type;
|
||||
event.keyCode = MapVirtualKeyToUIKeyCode(wParam);
|
||||
event.modifiers = m_inputModifierTracker.ApplyKeyMessage(type, wParam, lParam);
|
||||
event.repeat = IsRepeatKeyMessage(lParam);
|
||||
m_pendingInputEvents.push_back(event);
|
||||
}
|
||||
|
||||
void Application::QueueCharacterEvent(WPARAM wParam, LPARAM) {
|
||||
UIInputEvent event = {};
|
||||
event.type = UIInputEventType::Character;
|
||||
event.character = static_cast<std::uint32_t>(wParam);
|
||||
event.modifiers = m_inputModifierTracker.GetCurrentModifiers();
|
||||
m_pendingInputEvents.push_back(event);
|
||||
}
|
||||
|
||||
void Application::QueueWindowFocusEvent(UIInputEventType type) {
|
||||
UIInputEvent event = {};
|
||||
event.type = type;
|
||||
m_pendingInputEvents.push_back(event);
|
||||
}
|
||||
|
||||
bool Application::LoadStructuredScreen(const char* triggerReason) {
|
||||
(void)triggerReason;
|
||||
std::string scenarioLoadWarning = {};
|
||||
const CoreValidationScenario* scenario = m_requestedScenarioId.empty()
|
||||
? &GetDefaultCoreValidationScenario()
|
||||
: FindCoreValidationScenario(m_requestedScenarioId);
|
||||
if (scenario == nullptr) {
|
||||
scenario = &GetDefaultCoreValidationScenario();
|
||||
scenarioLoadWarning = "Unknown validation scenario: " + m_requestedScenarioId;
|
||||
}
|
||||
|
||||
m_activeScenario = scenario;
|
||||
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;
|
||||
m_runtimeStatus = loaded ? scenario->displayName : "Core UI Validation | Load Error";
|
||||
m_runtimeError = loaded
|
||||
? scenarioLoadWarning
|
||||
: (scenarioLoadWarning.empty()
|
||||
? m_screenPlayer.GetLastError()
|
||||
: scenarioLoadWarning + " | " + m_screenPlayer.GetLastError());
|
||||
m_dragDropValidationScene.Reset();
|
||||
m_popupMenuOverlayScene.Reset();
|
||||
RebuildTrackedFileStates();
|
||||
return loaded;
|
||||
}
|
||||
|
||||
void Application::RefreshStructuredScreen() {
|
||||
const auto now = std::chrono::steady_clock::now();
|
||||
if (m_lastReloadPollTime.time_since_epoch().count() != 0 &&
|
||||
now - m_lastReloadPollTime < kReloadPollInterval) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_lastReloadPollTime = now;
|
||||
if (DetectTrackedFileChange()) {
|
||||
LoadStructuredScreen("reload");
|
||||
}
|
||||
}
|
||||
|
||||
void Application::RebuildTrackedFileStates() {
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
m_trackedFiles.clear();
|
||||
std::unordered_set<std::string> seenPaths = {};
|
||||
std::error_code errorCode = {};
|
||||
|
||||
auto appendTrackedPath = [&](const std::string& rawPath) {
|
||||
if (rawPath.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const fs::path normalizedPath = fs::path(rawPath).lexically_normal();
|
||||
const std::string key = normalizedPath.string();
|
||||
if (!seenPaths.insert(key).second) {
|
||||
return;
|
||||
}
|
||||
|
||||
TrackedFileState state = {};
|
||||
state.path = normalizedPath;
|
||||
state.exists = fs::exists(normalizedPath, errorCode);
|
||||
errorCode.clear();
|
||||
if (state.exists) {
|
||||
state.writeTime = fs::last_write_time(normalizedPath, errorCode);
|
||||
errorCode.clear();
|
||||
}
|
||||
m_trackedFiles.push_back(std::move(state));
|
||||
};
|
||||
|
||||
appendTrackedPath(m_screenAsset.documentPath);
|
||||
appendTrackedPath(m_screenAsset.themePath);
|
||||
|
||||
if (const auto* document = m_screenPlayer.GetDocument(); document != nullptr) {
|
||||
for (const std::string& dependency : document->dependencies) {
|
||||
appendTrackedPath(dependency);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool Application::DetectTrackedFileChange() const {
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
std::error_code errorCode = {};
|
||||
for (const TrackedFileState& trackedFile : m_trackedFiles) {
|
||||
const bool existsNow = fs::exists(trackedFile.path, errorCode);
|
||||
errorCode.clear();
|
||||
if (existsNow != trackedFile.exists) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!existsNow) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const auto writeTimeNow = fs::last_write_time(trackedFile.path, errorCode);
|
||||
errorCode.clear();
|
||||
if (writeTimeNow != trackedFile.writeTime) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void Application::AppendRuntimeOverlay(UIDrawData& drawData, float width, float height) const {
|
||||
const bool authoredMode = m_useStructuredScreen && m_screenPlayer.IsLoaded();
|
||||
const float panelWidth = authoredMode ? 460.0f : 360.0f;
|
||||
std::vector<std::string> detailLines = {};
|
||||
detailLines.push_back(
|
||||
authoredMode
|
||||
? "Hot reload watches authored UI resources."
|
||||
: "Authored validation scene failed to load.");
|
||||
if (m_activeScenario != nullptr) {
|
||||
detailLines.push_back("Scenario: " + m_activeScenario->id);
|
||||
}
|
||||
|
||||
if (authoredMode) {
|
||||
const auto& inputDebug = m_documentHost.GetInputDebugSnapshot();
|
||||
const auto& scrollDebug = m_documentHost.GetScrollDebugSnapshot();
|
||||
detailLines.push_back(
|
||||
"Hover | Focus: " +
|
||||
ExtractStateKeyTail(inputDebug.hoveredStateKey) +
|
||||
" | " +
|
||||
ExtractStateKeyTail(inputDebug.focusedStateKey));
|
||||
detailLines.push_back(
|
||||
"Active | Capture: " +
|
||||
ExtractStateKeyTail(inputDebug.activeStateKey) +
|
||||
" | " +
|
||||
ExtractStateKeyTail(inputDebug.captureStateKey));
|
||||
detailLines.push_back(
|
||||
"Scope W/P/Wg: " +
|
||||
ExtractStateKeyTail(inputDebug.windowScopeStateKey) +
|
||||
" | " +
|
||||
ExtractStateKeyTail(inputDebug.panelScopeStateKey) +
|
||||
" | " +
|
||||
ExtractStateKeyTail(inputDebug.widgetScopeStateKey));
|
||||
detailLines.push_back(
|
||||
std::string("Text input: ") +
|
||||
(inputDebug.textInputActive ? "active" : "idle"));
|
||||
if (!inputDebug.recentShortcutCommandId.empty()) {
|
||||
detailLines.push_back(
|
||||
"Recent shortcut: " +
|
||||
inputDebug.recentShortcutScope +
|
||||
" -> " +
|
||||
inputDebug.recentShortcutCommandId);
|
||||
detailLines.push_back(
|
||||
std::string("Recent shortcut state: ") +
|
||||
(inputDebug.recentShortcutHandled
|
||||
? "handled"
|
||||
: (inputDebug.recentShortcutSuppressed ? "suppressed" : "observed")) +
|
||||
" @ " +
|
||||
ExtractStateKeyTail(inputDebug.recentShortcutOwnerStateKey));
|
||||
} else {
|
||||
detailLines.push_back("Recent shortcut: none");
|
||||
}
|
||||
if (!inputDebug.lastEventType.empty()) {
|
||||
const std::string eventPosition = inputDebug.lastEventType == "KeyDown" ||
|
||||
inputDebug.lastEventType == "KeyUp" ||
|
||||
inputDebug.lastEventType == "Character" ||
|
||||
inputDebug.lastEventType == "FocusGained" ||
|
||||
inputDebug.lastEventType == "FocusLost"
|
||||
? std::string()
|
||||
: " at " + FormatPoint(inputDebug.pointerPosition);
|
||||
detailLines.push_back(
|
||||
"Last input: " +
|
||||
inputDebug.lastEventType +
|
||||
eventPosition);
|
||||
detailLines.push_back(
|
||||
"Route: " +
|
||||
inputDebug.lastTargetKind +
|
||||
" -> " +
|
||||
ExtractStateKeyTail(inputDebug.lastTargetStateKey));
|
||||
if (!inputDebug.lastShortcutCommandId.empty()) {
|
||||
detailLines.push_back(
|
||||
"Shortcut: " +
|
||||
inputDebug.lastShortcutScope +
|
||||
" -> " +
|
||||
inputDebug.lastShortcutCommandId);
|
||||
detailLines.push_back(
|
||||
std::string("Shortcut state: ") +
|
||||
(inputDebug.lastShortcutHandled
|
||||
? "handled"
|
||||
: (inputDebug.lastShortcutSuppressed ? "suppressed" : "observed")) +
|
||||
" @ " +
|
||||
ExtractStateKeyTail(inputDebug.lastShortcutOwnerStateKey));
|
||||
}
|
||||
detailLines.push_back(
|
||||
"Last event result: " +
|
||||
(inputDebug.lastResult.empty() ? std::string("n/a") : inputDebug.lastResult));
|
||||
}
|
||||
detailLines.push_back(
|
||||
"Scroll target | Primary: " +
|
||||
ExtractStateKeyTail(scrollDebug.lastTargetStateKey) +
|
||||
" | " +
|
||||
ExtractStateKeyTail(scrollDebug.primaryTargetStateKey));
|
||||
detailLines.push_back(
|
||||
"Scroll offset B/A: " +
|
||||
FormatFloat(scrollDebug.lastOffsetBefore) +
|
||||
" -> " +
|
||||
FormatFloat(scrollDebug.lastOffsetAfter) +
|
||||
" | overflow " +
|
||||
FormatFloat(scrollDebug.lastOverflow));
|
||||
detailLines.push_back(
|
||||
"Scroll H/T: " +
|
||||
std::to_string(scrollDebug.handledWheelEventCount) +
|
||||
"/" +
|
||||
std::to_string(scrollDebug.totalWheelEventCount) +
|
||||
" | " +
|
||||
(scrollDebug.lastResult.empty() ? std::string("n/a") : scrollDebug.lastResult));
|
||||
}
|
||||
|
||||
if (m_autoScreenshot.HasPendingCapture()) {
|
||||
detailLines.push_back("Shot pending...");
|
||||
} else if (!m_autoScreenshot.GetLastCaptureSummary().empty()) {
|
||||
detailLines.push_back(TruncateText(m_autoScreenshot.GetLastCaptureSummary(), 78u));
|
||||
} else {
|
||||
detailLines.push_back(
|
||||
"Screenshots: F12 -> " +
|
||||
TruncateText(
|
||||
m_autoScreenshot.GetLatestCapturePath().parent_path().string(),
|
||||
60u));
|
||||
}
|
||||
|
||||
if (!m_runtimeError.empty()) {
|
||||
detailLines.push_back(TruncateText(m_runtimeError, 78u));
|
||||
} else if (!m_autoScreenshot.GetLastCaptureError().empty()) {
|
||||
detailLines.push_back(TruncateText(m_autoScreenshot.GetLastCaptureError(), 78u));
|
||||
} else if (!authoredMode) {
|
||||
detailLines.push_back("No fallback sandbox is rendered in this host.");
|
||||
}
|
||||
|
||||
const float panelHeight = 38.0f + static_cast<float>(detailLines.size()) * 18.0f;
|
||||
const UIRect panelRect(width - panelWidth - 16.0f, height - panelHeight - 42.0f, panelWidth, panelHeight);
|
||||
|
||||
UIDrawList& overlay = drawData.EmplaceDrawList("Core UI Validation Overlay");
|
||||
overlay.AddFilledRect(panelRect, kOverlayBgColor, 10.0f);
|
||||
overlay.AddRectOutline(panelRect, kOverlayBorderColor, 1.0f, 10.0f);
|
||||
overlay.AddFilledRect(
|
||||
UIRect(panelRect.x + 12.0f, panelRect.y + 14.0f, 8.0f, 8.0f),
|
||||
authoredMode ? kOverlaySuccess : kOverlayFallback,
|
||||
4.0f);
|
||||
overlay.AddText(
|
||||
UIPoint(panelRect.x + 28.0f, panelRect.y + 10.0f),
|
||||
m_runtimeStatus.empty() ? "Core UI Validation" : m_runtimeStatus,
|
||||
kOverlayTextPrimary,
|
||||
14.0f);
|
||||
|
||||
float detailY = panelRect.y + 30.0f;
|
||||
for (std::size_t index = 0; index < detailLines.size(); ++index) {
|
||||
const bool lastLine = index + 1u == detailLines.size();
|
||||
overlay.AddText(
|
||||
UIPoint(panelRect.x + 28.0f, detailY),
|
||||
detailLines[index],
|
||||
lastLine && (!m_runtimeError.empty() || !m_autoScreenshot.GetLastCaptureError().empty())
|
||||
? kOverlayFallback
|
||||
: kOverlayTextMuted,
|
||||
12.0f);
|
||||
detailY += 18.0f;
|
||||
}
|
||||
}
|
||||
|
||||
std::filesystem::path Application::ResolveRepoRelativePath(const char* relativePath) {
|
||||
return (GetRepoRootPath() / relativePath).lexically_normal();
|
||||
}
|
||||
|
||||
LRESULT CALLBACK Application::WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
|
||||
if (message == WM_NCCREATE) {
|
||||
const auto* createStruct = reinterpret_cast<CREATESTRUCTW*>(lParam);
|
||||
auto* application = reinterpret_cast<Application*>(createStruct->lpCreateParams);
|
||||
SetWindowLongPtrW(hwnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(application));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
Application* application = GetApplicationFromWindow(hwnd);
|
||||
switch (message) {
|
||||
case WM_SIZE:
|
||||
if (application != nullptr && wParam != SIZE_MINIMIZED) {
|
||||
application->OnResize(static_cast<UINT>(LOWORD(lParam)), static_cast<UINT>(HIWORD(lParam)));
|
||||
}
|
||||
return 0;
|
||||
case WM_PAINT:
|
||||
if (application != nullptr) {
|
||||
PAINTSTRUCT paintStruct = {};
|
||||
BeginPaint(hwnd, &paintStruct);
|
||||
application->RenderFrame();
|
||||
EndPaint(hwnd, &paintStruct);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case WM_MOUSEMOVE:
|
||||
if (application != nullptr) {
|
||||
if (!application->m_trackingMouseLeave) {
|
||||
TRACKMOUSEEVENT trackMouseEvent = {};
|
||||
trackMouseEvent.cbSize = sizeof(trackMouseEvent);
|
||||
trackMouseEvent.dwFlags = TME_LEAVE;
|
||||
trackMouseEvent.hwndTrack = hwnd;
|
||||
if (TrackMouseEvent(&trackMouseEvent)) {
|
||||
application->m_trackingMouseLeave = true;
|
||||
}
|
||||
}
|
||||
application->QueuePointerEvent(UIInputEventType::PointerMove, UIPointerButton::None, wParam, lParam);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case WM_MOUSELEAVE:
|
||||
if (application != nullptr) {
|
||||
application->m_trackingMouseLeave = false;
|
||||
application->QueuePointerLeaveEvent();
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case WM_LBUTTONDOWN:
|
||||
if (application != nullptr) {
|
||||
SetFocus(hwnd);
|
||||
SetCapture(hwnd);
|
||||
application->QueuePointerEvent(UIInputEventType::PointerButtonDown, UIPointerButton::Left, wParam, lParam);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case WM_LBUTTONUP:
|
||||
if (application != nullptr) {
|
||||
if (GetCapture() == hwnd) {
|
||||
ReleaseCapture();
|
||||
}
|
||||
application->QueuePointerEvent(UIInputEventType::PointerButtonUp, UIPointerButton::Left, wParam, lParam);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case WM_MOUSEWHEEL:
|
||||
if (application != nullptr) {
|
||||
application->QueuePointerWheelEvent(GET_WHEEL_DELTA_WPARAM(wParam), wParam, lParam);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case WM_SETFOCUS:
|
||||
if (application != nullptr) {
|
||||
application->m_inputModifierTracker.SyncFromSystemState();
|
||||
application->QueueWindowFocusEvent(UIInputEventType::FocusGained);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case WM_KILLFOCUS:
|
||||
if (application != nullptr) {
|
||||
application->m_inputModifierTracker.Reset();
|
||||
application->QueueWindowFocusEvent(UIInputEventType::FocusLost);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case WM_KEYDOWN:
|
||||
case WM_SYSKEYDOWN:
|
||||
if (application != nullptr) {
|
||||
if (wParam == VK_F12) {
|
||||
application->m_autoScreenshot.RequestCapture("manual_f12");
|
||||
}
|
||||
application->QueueKeyEvent(UIInputEventType::KeyDown, wParam, lParam);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case WM_KEYUP:
|
||||
case WM_SYSKEYUP:
|
||||
if (application != nullptr) {
|
||||
application->QueueKeyEvent(UIInputEventType::KeyUp, wParam, lParam);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case WM_CHAR:
|
||||
if (application != nullptr) {
|
||||
application->QueueCharacterEvent(wParam, lParam);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case WM_ERASEBKGND:
|
||||
return 1;
|
||||
case WM_DESTROY:
|
||||
if (application != nullptr) {
|
||||
application->m_hwnd = nullptr;
|
||||
}
|
||||
PostQuitMessage(0);
|
||||
return 0;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return DefWindowProcW(hwnd, message, wParam, lParam);
|
||||
}
|
||||
|
||||
int RunCoreUIValidationApp(HINSTANCE hInstance, int nCmdShow, std::string requestedScenarioId) {
|
||||
Application application(std::move(requestedScenarioId));
|
||||
return application.Run(hInstance, nCmdShow);
|
||||
}
|
||||
|
||||
} // namespace XCEngine::Tests::CoreUI
|
||||
@@ -1,87 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef NOMINMAX
|
||||
#define NOMINMAX
|
||||
#endif
|
||||
|
||||
#include "AutoScreenshot.h"
|
||||
#include "CoreValidationScenario.h"
|
||||
#include "DragDropValidationScene.h"
|
||||
#include "InputModifierTracker.h"
|
||||
#include "NativeRenderer.h"
|
||||
#include "PopupMenuOverlayValidationScene.h"
|
||||
|
||||
#include <XCEngine/UI/Runtime/UIScreenDocumentHost.h>
|
||||
#include <XCEngine/UI/Runtime/UIScreenPlayer.h>
|
||||
|
||||
#include <windows.h>
|
||||
#include <windowsx.h>
|
||||
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace XCEngine::Tests::CoreUI {
|
||||
|
||||
class Application {
|
||||
public:
|
||||
explicit Application(std::string requestedScenarioId = {});
|
||||
|
||||
int Run(HINSTANCE hInstance, int nCmdShow);
|
||||
|
||||
private:
|
||||
struct TrackedFileState {
|
||||
std::filesystem::path path = {};
|
||||
std::filesystem::file_time_type writeTime = {};
|
||||
bool exists = false;
|
||||
};
|
||||
|
||||
static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
|
||||
|
||||
bool Initialize(HINSTANCE hInstance, int nCmdShow);
|
||||
void Shutdown();
|
||||
void RenderFrame();
|
||||
void OnResize(UINT width, UINT height);
|
||||
void QueuePointerEvent(::XCEngine::UI::UIInputEventType type, ::XCEngine::UI::UIPointerButton button, WPARAM wParam, LPARAM lParam);
|
||||
void QueuePointerLeaveEvent();
|
||||
void QueuePointerWheelEvent(short wheelDelta, WPARAM wParam, LPARAM lParam);
|
||||
void QueueKeyEvent(::XCEngine::UI::UIInputEventType type, WPARAM wParam, LPARAM lParam);
|
||||
void QueueCharacterEvent(WPARAM wParam, LPARAM lParam);
|
||||
void QueueWindowFocusEvent(::XCEngine::UI::UIInputEventType type);
|
||||
bool LoadStructuredScreen(const char* triggerReason);
|
||||
void RefreshStructuredScreen();
|
||||
void RebuildTrackedFileStates();
|
||||
bool DetectTrackedFileChange() const;
|
||||
void AppendRuntimeOverlay(::XCEngine::UI::UIDrawData& drawData, float width, float height) const;
|
||||
static std::filesystem::path ResolveRepoRelativePath(const char* relativePath);
|
||||
|
||||
HWND m_hwnd = nullptr;
|
||||
HINSTANCE m_hInstance = nullptr;
|
||||
ATOM m_windowClassAtom = 0;
|
||||
Host::NativeRenderer m_renderer;
|
||||
Host::AutoScreenshotController m_autoScreenshot;
|
||||
::XCEngine::UI::Runtime::UIDocumentScreenHost m_documentHost;
|
||||
::XCEngine::UI::Runtime::UIScreenPlayer m_screenPlayer;
|
||||
::XCEngine::UI::Runtime::UIScreenAsset m_screenAsset = {};
|
||||
const CoreValidationScenario* m_activeScenario = nullptr;
|
||||
std::string m_requestedScenarioId = {};
|
||||
std::vector<TrackedFileState> m_trackedFiles = {};
|
||||
std::chrono::steady_clock::time_point m_startTime = {};
|
||||
std::chrono::steady_clock::time_point m_lastFrameTime = {};
|
||||
std::chrono::steady_clock::time_point m_lastReloadPollTime = {};
|
||||
std::uint64_t m_frameIndex = 0;
|
||||
std::vector<::XCEngine::UI::UIInputEvent> m_pendingInputEvents = {};
|
||||
Host::InputModifierTracker m_inputModifierTracker = {};
|
||||
DragDropValidationScene m_dragDropValidationScene = {};
|
||||
PopupMenuOverlayValidationScene m_popupMenuOverlayScene = {};
|
||||
bool m_trackingMouseLeave = false;
|
||||
bool m_useStructuredScreen = false;
|
||||
std::string m_runtimeStatus = {};
|
||||
std::string m_runtimeError = {};
|
||||
};
|
||||
|
||||
int RunCoreUIValidationApp(HINSTANCE hInstance, int nCmdShow, std::string requestedScenarioId = {});
|
||||
|
||||
} // namespace XCEngine::Tests::CoreUI
|
||||
@@ -1,224 +0,0 @@
|
||||
#include "AutoScreenshot.h"
|
||||
|
||||
#include "NativeRenderer.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <cctype>
|
||||
#include <cstdlib>
|
||||
#include <cstdio>
|
||||
#include <sstream>
|
||||
#include <system_error>
|
||||
#include <vector>
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
namespace XCEngine::Tests::CoreUI::Host {
|
||||
|
||||
namespace {
|
||||
|
||||
bool IsAutoCaptureOnStartupEnabled() {
|
||||
const char* value = std::getenv("XCUI_AUTO_CAPTURE_ON_STARTUP");
|
||||
if (value == nullptr || value[0] == '\0') {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string normalized = value;
|
||||
for (char& character : normalized) {
|
||||
character = static_cast<char>(std::tolower(static_cast<unsigned char>(character)));
|
||||
}
|
||||
|
||||
return normalized != "0" &&
|
||||
normalized != "false" &&
|
||||
normalized != "off" &&
|
||||
normalized != "no";
|
||||
}
|
||||
|
||||
std::filesystem::path GetExecutableDirectory() {
|
||||
std::vector<wchar_t> buffer(MAX_PATH);
|
||||
while (true) {
|
||||
const DWORD copied = ::GetModuleFileNameW(
|
||||
nullptr,
|
||||
buffer.data(),
|
||||
static_cast<DWORD>(buffer.size()));
|
||||
if (copied == 0u) {
|
||||
return std::filesystem::current_path().lexically_normal();
|
||||
}
|
||||
|
||||
if (copied < buffer.size() - 1u) {
|
||||
return std::filesystem::path(std::wstring(buffer.data(), copied))
|
||||
.parent_path()
|
||||
.lexically_normal();
|
||||
}
|
||||
|
||||
buffer.resize(buffer.size() * 2u);
|
||||
}
|
||||
}
|
||||
|
||||
std::filesystem::path ResolveBuildCaptureRoot(const std::filesystem::path& requestedCaptureRoot) {
|
||||
std::filesystem::path captureRoot = GetExecutableDirectory() / "captures";
|
||||
const std::filesystem::path scenarioPath = requestedCaptureRoot.parent_path().filename();
|
||||
if (!scenarioPath.empty() && scenarioPath != "captures") {
|
||||
captureRoot /= scenarioPath;
|
||||
}
|
||||
|
||||
return captureRoot.lexically_normal();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void AutoScreenshotController::Initialize(const std::filesystem::path& captureRoot) {
|
||||
m_captureRoot = ResolveBuildCaptureRoot(captureRoot);
|
||||
m_historyRoot = (m_captureRoot / "history").lexically_normal();
|
||||
m_latestCapturePath = (m_captureRoot / "latest.png").lexically_normal();
|
||||
m_captureCount = 0;
|
||||
m_capturePending = false;
|
||||
m_pendingReason.clear();
|
||||
m_lastCaptureSummary = "Output: " + m_captureRoot.string();
|
||||
m_lastCaptureError.clear();
|
||||
if (IsAutoCaptureOnStartupEnabled()) {
|
||||
RequestCapture("startup");
|
||||
}
|
||||
}
|
||||
|
||||
void AutoScreenshotController::Shutdown() {
|
||||
m_capturePending = false;
|
||||
m_pendingReason.clear();
|
||||
}
|
||||
|
||||
void AutoScreenshotController::RequestCapture(std::string reason) {
|
||||
m_pendingReason = reason.empty() ? "capture" : std::move(reason);
|
||||
m_capturePending = true;
|
||||
}
|
||||
|
||||
void AutoScreenshotController::CaptureIfRequested(
|
||||
NativeRenderer& renderer,
|
||||
const ::XCEngine::UI::UIDrawData& drawData,
|
||||
unsigned int width,
|
||||
unsigned int height,
|
||||
bool framePresented) {
|
||||
if (!m_capturePending || !framePresented || drawData.Empty() || width == 0u || height == 0u) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::error_code errorCode = {};
|
||||
std::filesystem::create_directories(m_captureRoot, errorCode);
|
||||
if (errorCode) {
|
||||
m_lastCaptureError = "Failed to create screenshot directory: " + m_captureRoot.string();
|
||||
m_lastCaptureSummary = "AutoShot failed";
|
||||
m_capturePending = false;
|
||||
return;
|
||||
}
|
||||
|
||||
std::filesystem::create_directories(m_historyRoot, errorCode);
|
||||
if (errorCode) {
|
||||
m_lastCaptureError = "Failed to create screenshot directory: " + m_historyRoot.string();
|
||||
m_lastCaptureSummary = "AutoShot failed";
|
||||
m_capturePending = false;
|
||||
return;
|
||||
}
|
||||
|
||||
std::string captureError = {};
|
||||
const std::filesystem::path historyPath = BuildHistoryCapturePath(m_pendingReason);
|
||||
if (!renderer.CaptureToPng(drawData, width, height, historyPath, captureError)) {
|
||||
m_lastCaptureError = std::move(captureError);
|
||||
m_lastCaptureSummary = "AutoShot failed";
|
||||
m_capturePending = false;
|
||||
return;
|
||||
}
|
||||
|
||||
errorCode.clear();
|
||||
std::filesystem::copy_file(
|
||||
historyPath,
|
||||
m_latestCapturePath,
|
||||
std::filesystem::copy_options::overwrite_existing,
|
||||
errorCode);
|
||||
if (errorCode) {
|
||||
m_lastCaptureError = "Failed to update latest screenshot: " + m_latestCapturePath.string();
|
||||
m_lastCaptureSummary = "AutoShot failed";
|
||||
m_capturePending = false;
|
||||
return;
|
||||
}
|
||||
|
||||
++m_captureCount;
|
||||
m_lastCaptureError.clear();
|
||||
m_lastCaptureSummary = "Shot: latest.png | " + historyPath.filename().string();
|
||||
m_capturePending = false;
|
||||
m_pendingReason.clear();
|
||||
}
|
||||
|
||||
bool AutoScreenshotController::HasPendingCapture() const {
|
||||
return m_capturePending;
|
||||
}
|
||||
|
||||
const std::filesystem::path& AutoScreenshotController::GetLatestCapturePath() const {
|
||||
return m_latestCapturePath;
|
||||
}
|
||||
|
||||
const std::string& AutoScreenshotController::GetLastCaptureSummary() const {
|
||||
return m_lastCaptureSummary;
|
||||
}
|
||||
|
||||
const std::string& AutoScreenshotController::GetLastCaptureError() const {
|
||||
return m_lastCaptureError;
|
||||
}
|
||||
|
||||
std::filesystem::path AutoScreenshotController::BuildHistoryCapturePath(std::string_view reason) const {
|
||||
std::ostringstream filename;
|
||||
filename << BuildTimestampString()
|
||||
<< '_'
|
||||
<< (m_captureCount + 1u)
|
||||
<< '_'
|
||||
<< SanitizeReason(reason)
|
||||
<< ".png";
|
||||
return (m_historyRoot / filename.str()).lexically_normal();
|
||||
}
|
||||
|
||||
std::string AutoScreenshotController::BuildTimestampString() {
|
||||
const auto now = std::chrono::system_clock::now();
|
||||
const std::time_t currentTime = std::chrono::system_clock::to_time_t(now);
|
||||
std::tm localTime = {};
|
||||
localtime_s(&localTime, ¤tTime);
|
||||
|
||||
char buffer[32] = {};
|
||||
std::snprintf(
|
||||
buffer,
|
||||
sizeof(buffer),
|
||||
"%04d%02d%02d_%02d%02d%02d",
|
||||
localTime.tm_year + 1900,
|
||||
localTime.tm_mon + 1,
|
||||
localTime.tm_mday,
|
||||
localTime.tm_hour,
|
||||
localTime.tm_min,
|
||||
localTime.tm_sec);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
std::string AutoScreenshotController::SanitizeReason(std::string_view reason) {
|
||||
std::string sanitized = {};
|
||||
sanitized.reserve(reason.size());
|
||||
|
||||
bool lastWasSeparator = false;
|
||||
for (const unsigned char value : reason) {
|
||||
if (std::isalnum(value)) {
|
||||
sanitized.push_back(static_cast<char>(std::tolower(value)));
|
||||
lastWasSeparator = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!lastWasSeparator) {
|
||||
sanitized.push_back('_');
|
||||
lastWasSeparator = true;
|
||||
}
|
||||
}
|
||||
|
||||
while (!sanitized.empty() && sanitized.front() == '_') {
|
||||
sanitized.erase(sanitized.begin());
|
||||
}
|
||||
while (!sanitized.empty() && sanitized.back() == '_') {
|
||||
sanitized.pop_back();
|
||||
}
|
||||
|
||||
return sanitized.empty() ? "capture" : sanitized;
|
||||
}
|
||||
|
||||
} // namespace XCEngine::Tests::CoreUI::Host
|
||||
@@ -1,52 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef NOMINMAX
|
||||
#define NOMINMAX
|
||||
#endif
|
||||
|
||||
#include <XCEngine/UI/DrawData.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
namespace XCEngine::Tests::CoreUI::Host {
|
||||
|
||||
class NativeRenderer;
|
||||
|
||||
class AutoScreenshotController {
|
||||
public:
|
||||
void Initialize(const std::filesystem::path& captureRoot);
|
||||
void Shutdown();
|
||||
|
||||
void RequestCapture(std::string reason);
|
||||
void CaptureIfRequested(
|
||||
NativeRenderer& renderer,
|
||||
const ::XCEngine::UI::UIDrawData& drawData,
|
||||
unsigned int width,
|
||||
unsigned int height,
|
||||
bool framePresented);
|
||||
|
||||
bool HasPendingCapture() const;
|
||||
const std::filesystem::path& GetLatestCapturePath() const;
|
||||
const std::string& GetLastCaptureSummary() const;
|
||||
const std::string& GetLastCaptureError() const;
|
||||
|
||||
private:
|
||||
std::filesystem::path BuildHistoryCapturePath(std::string_view reason) const;
|
||||
|
||||
static std::string BuildTimestampString();
|
||||
static std::string SanitizeReason(std::string_view reason);
|
||||
|
||||
std::filesystem::path m_captureRoot = {};
|
||||
std::filesystem::path m_historyRoot = {};
|
||||
std::filesystem::path m_latestCapturePath = {};
|
||||
std::string m_pendingReason = {};
|
||||
std::string m_lastCaptureSummary = {};
|
||||
std::string m_lastCaptureError = {};
|
||||
std::uint64_t m_captureCount = 0;
|
||||
bool m_capturePending = false;
|
||||
};
|
||||
|
||||
} // namespace XCEngine::Tests::CoreUI::Host
|
||||
@@ -1,154 +0,0 @@
|
||||
#include "CoreValidationScenario.h"
|
||||
|
||||
#include <array>
|
||||
|
||||
#ifndef XCENGINE_CORE_UI_TESTS_REPO_ROOT
|
||||
#define XCENGINE_CORE_UI_TESTS_REPO_ROOT "."
|
||||
#endif
|
||||
|
||||
namespace XCEngine::Tests::CoreUI {
|
||||
|
||||
namespace {
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
fs::path RepoRootPath() {
|
||||
std::string root = XCENGINE_CORE_UI_TESTS_REPO_ROOT;
|
||||
if (root.size() >= 2u && root.front() == '"' && root.back() == '"') {
|
||||
root = root.substr(1u, root.size() - 2u);
|
||||
}
|
||||
return fs::path(root).lexically_normal();
|
||||
}
|
||||
|
||||
fs::path RepoRelative(const char* relativePath) {
|
||||
return (RepoRootPath() / relativePath).lexically_normal();
|
||||
}
|
||||
|
||||
const std::array<CoreValidationScenario, 11>& GetCoreValidationScenarios() {
|
||||
static const std::array<CoreValidationScenario, 11> scenarios = { {
|
||||
{
|
||||
"core.input.drag_drop_basic",
|
||||
UIValidationDomain::Core,
|
||||
"input",
|
||||
"Core Input | Drag Drop Contract",
|
||||
RepoRelative("tests/UI/Core/integration/input/drag_drop_basic/View.xcui"),
|
||||
RepoRelative("tests/UI/Core/integration/shared/themes/core_validation.xctheme"),
|
||||
RepoRelative("tests/UI/Core/integration/input/drag_drop_basic/captures")
|
||||
},
|
||||
{
|
||||
"core.input.keyboard_focus",
|
||||
UIValidationDomain::Core,
|
||||
"input",
|
||||
"Core Input | Keyboard Focus",
|
||||
RepoRelative("tests/UI/Core/integration/input/keyboard_focus/View.xcui"),
|
||||
RepoRelative("tests/UI/Core/integration/shared/themes/core_validation.xctheme"),
|
||||
RepoRelative("tests/UI/Core/integration/input/keyboard_focus/captures")
|
||||
},
|
||||
{
|
||||
"core.input.popup_menu_overlay",
|
||||
UIValidationDomain::Core,
|
||||
"input",
|
||||
"Core Input | Popup Menu Overlay",
|
||||
RepoRelative("tests/UI/Core/integration/input/popup_menu_overlay/View.xcui"),
|
||||
RepoRelative("tests/UI/Core/integration/shared/themes/core_validation.xctheme"),
|
||||
RepoRelative("tests/UI/Core/integration/input/popup_menu_overlay/captures")
|
||||
},
|
||||
{
|
||||
"core.input.pointer_states",
|
||||
UIValidationDomain::Core,
|
||||
"input",
|
||||
"Core Input | Pointer States",
|
||||
RepoRelative("tests/UI/Core/integration/input/pointer_states/View.xcui"),
|
||||
RepoRelative("tests/UI/Core/integration/shared/themes/core_validation.xctheme"),
|
||||
RepoRelative("tests/UI/Core/integration/input/pointer_states/captures")
|
||||
},
|
||||
{
|
||||
"core.input.scroll_view",
|
||||
UIValidationDomain::Core,
|
||||
"input",
|
||||
"Core Input | Scroll View",
|
||||
RepoRelative("tests/UI/Core/integration/input/scroll_view/View.xcui"),
|
||||
RepoRelative("tests/UI/Core/integration/shared/themes/core_validation.xctheme"),
|
||||
RepoRelative("tests/UI/Core/integration/input/scroll_view/captures")
|
||||
},
|
||||
{
|
||||
"core.input.shortcut_scope",
|
||||
UIValidationDomain::Core,
|
||||
"input",
|
||||
"Core Input | Shortcut Scope",
|
||||
RepoRelative("tests/UI/Core/integration/input/shortcut_scope/View.xcui"),
|
||||
RepoRelative("tests/UI/Core/integration/shared/themes/core_validation.xctheme"),
|
||||
RepoRelative("tests/UI/Core/integration/input/shortcut_scope/captures")
|
||||
},
|
||||
{
|
||||
"core.layout.splitter_resize",
|
||||
UIValidationDomain::Core,
|
||||
"layout",
|
||||
"Core Layout | Splitter Resize",
|
||||
RepoRelative("tests/UI/Core/integration/layout/splitter_resize/View.xcui"),
|
||||
RepoRelative("tests/UI/Core/integration/shared/themes/core_validation.xctheme"),
|
||||
RepoRelative("tests/UI/Core/integration/layout/splitter_resize/captures")
|
||||
},
|
||||
{
|
||||
"core.layout.tab_strip_selection",
|
||||
UIValidationDomain::Core,
|
||||
"layout",
|
||||
"Core Layout | TabStrip Selection",
|
||||
RepoRelative("tests/UI/Core/integration/layout/tab_strip_selection/View.xcui"),
|
||||
RepoRelative("tests/UI/Core/integration/shared/themes/core_validation.xctheme"),
|
||||
RepoRelative("tests/UI/Core/integration/layout/tab_strip_selection/captures")
|
||||
},
|
||||
{
|
||||
"core.layout.workspace_compose",
|
||||
UIValidationDomain::Core,
|
||||
"layout",
|
||||
"Core Layout | Workspace Compose",
|
||||
RepoRelative("tests/UI/Core/integration/layout/workspace_compose/View.xcui"),
|
||||
RepoRelative("tests/UI/Core/integration/shared/themes/core_validation.xctheme"),
|
||||
RepoRelative("tests/UI/Core/integration/layout/workspace_compose/captures")
|
||||
},
|
||||
{
|
||||
"core.style.theme_tokens",
|
||||
UIValidationDomain::Core,
|
||||
"style",
|
||||
"Core Style | Theme Tokens",
|
||||
RepoRelative("tests/UI/Core/integration/style/theme_tokens/View.xcui"),
|
||||
RepoRelative("tests/UI/Core/integration/shared/themes/core_validation.xctheme"),
|
||||
RepoRelative("tests/UI/Core/integration/style/theme_tokens/captures")
|
||||
},
|
||||
{
|
||||
"core.text.utf8_focus_surface",
|
||||
UIValidationDomain::Core,
|
||||
"text",
|
||||
"Core Text | UTF-8 Focus Surface",
|
||||
RepoRelative("tests/UI/Core/integration/text/utf8_focus_surface/View.xcui"),
|
||||
RepoRelative("tests/UI/Core/integration/shared/themes/core_validation.xctheme"),
|
||||
RepoRelative("tests/UI/Core/integration/text/utf8_focus_surface/captures")
|
||||
}
|
||||
} };
|
||||
return scenarios;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
const CoreValidationScenario& GetDefaultCoreValidationScenario() {
|
||||
for (const CoreValidationScenario& scenario : GetCoreValidationScenarios()) {
|
||||
if (scenario.id == "core.input.keyboard_focus") {
|
||||
return scenario;
|
||||
}
|
||||
}
|
||||
|
||||
return GetCoreValidationScenarios().front();
|
||||
}
|
||||
|
||||
const CoreValidationScenario* FindCoreValidationScenario(std::string_view id) {
|
||||
for (const CoreValidationScenario& scenario : GetCoreValidationScenarios()) {
|
||||
if (scenario.id == id) {
|
||||
return &scenario;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace XCEngine::Tests::CoreUI
|
||||
@@ -1,26 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
namespace XCEngine::Tests::CoreUI {
|
||||
|
||||
enum class UIValidationDomain : unsigned char {
|
||||
Core = 0
|
||||
};
|
||||
|
||||
struct CoreValidationScenario {
|
||||
std::string id = {};
|
||||
UIValidationDomain domain = UIValidationDomain::Core;
|
||||
std::string categoryId = {};
|
||||
std::string displayName = {};
|
||||
std::filesystem::path documentPath = {};
|
||||
std::filesystem::path themePath = {};
|
||||
std::filesystem::path captureRootPath = {};
|
||||
};
|
||||
|
||||
const CoreValidationScenario& GetDefaultCoreValidationScenario();
|
||||
const CoreValidationScenario* FindCoreValidationScenario(std::string_view id);
|
||||
|
||||
} // namespace XCEngine::Tests::CoreUI
|
||||
@@ -1,504 +0,0 @@
|
||||
#include "DragDropValidationScene.h"
|
||||
|
||||
#include <XCEngine/Input/InputTypes.h>
|
||||
|
||||
#include <array>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
namespace XCEngine::Tests::CoreUI {
|
||||
|
||||
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::Widgets::BeginUIDragDrop;
|
||||
using ::XCEngine::UI::Widgets::CancelUIDragDrop;
|
||||
using ::XCEngine::UI::Widgets::EndUIDragDrop;
|
||||
using ::XCEngine::UI::Widgets::HasResolvedUIDragDropTarget;
|
||||
using ::XCEngine::UI::Widgets::IsUIDragDropInProgress;
|
||||
using ::XCEngine::UI::Widgets::UIDragDropOperation;
|
||||
using ::XCEngine::UI::Widgets::UIDragDropPayload;
|
||||
using ::XCEngine::UI::Widgets::UIDragDropResult;
|
||||
using ::XCEngine::UI::Widgets::UIDragDropSourceDescriptor;
|
||||
using ::XCEngine::UI::Widgets::UIDragDropTargetDescriptor;
|
||||
using ::XCEngine::UI::Widgets::UpdateUIDragDropPointer;
|
||||
using ::XCEngine::UI::Widgets::UpdateUIDragDropTarget;
|
||||
|
||||
constexpr UIColor kLabPanelBg(0.12f, 0.12f, 0.12f, 1.0f);
|
||||
constexpr UIColor kLabPanelBorder(0.24f, 0.24f, 0.24f, 1.0f);
|
||||
constexpr UIColor kStatusBg(0.16f, 0.16f, 0.16f, 1.0f);
|
||||
constexpr UIColor kCardBg(0.18f, 0.18f, 0.18f, 1.0f);
|
||||
constexpr UIColor kCardHover(0.24f, 0.24f, 0.24f, 1.0f);
|
||||
constexpr UIColor kCardBorder(0.32f, 0.32f, 0.32f, 1.0f);
|
||||
constexpr UIColor kAccept(0.36f, 0.46f, 0.36f, 1.0f);
|
||||
constexpr UIColor kAcceptBorder(0.56f, 0.72f, 0.56f, 1.0f);
|
||||
constexpr UIColor kReject(0.34f, 0.22f, 0.22f, 1.0f);
|
||||
constexpr UIColor kRejectBorder(0.72f, 0.38f, 0.38f, 1.0f);
|
||||
constexpr UIColor kGhostBg(0.28f, 0.28f, 0.28f, 0.95f);
|
||||
constexpr UIColor kGhostBorder(0.78f, 0.78f, 0.78f, 1.0f);
|
||||
constexpr UIColor kTextPrimary(0.93f, 0.93f, 0.93f, 1.0f);
|
||||
constexpr UIColor kTextMuted(0.72f, 0.72f, 0.72f, 1.0f);
|
||||
constexpr UIColor kTextWeak(0.56f, 0.56f, 0.56f, 1.0f);
|
||||
constexpr UIColor kTextSuccess(0.62f, 0.82f, 0.62f, 1.0f);
|
||||
constexpr UIColor kTextDanger(0.84f, 0.48f, 0.48f, 1.0f);
|
||||
|
||||
constexpr std::uint64_t kTextureSourceOwnerId = 1001u;
|
||||
constexpr std::uint64_t kEntitySourceOwnerId = 1002u;
|
||||
constexpr std::uint64_t kProjectTargetOwnerId = 2001u;
|
||||
constexpr std::uint64_t kHierarchyTargetOwnerId = 2002u;
|
||||
|
||||
std::string DescribeOperation(UIDragDropOperation operation) {
|
||||
switch (operation) {
|
||||
case UIDragDropOperation::Copy:
|
||||
return "Copy";
|
||||
case UIDragDropOperation::Move:
|
||||
return "Move";
|
||||
case UIDragDropOperation::Link:
|
||||
return "Link";
|
||||
default:
|
||||
return "(none)";
|
||||
}
|
||||
}
|
||||
|
||||
void DrawPanel(
|
||||
UIDrawList& drawList,
|
||||
const UIRect& rect,
|
||||
const UIColor& fillColor,
|
||||
const UIColor& borderColor,
|
||||
float rounding) {
|
||||
drawList.AddFilledRect(rect, fillColor, rounding);
|
||||
drawList.AddRectOutline(rect, borderColor, 1.0f, rounding);
|
||||
}
|
||||
|
||||
void DrawCard(
|
||||
UIDrawList& drawList,
|
||||
const UIRect& rect,
|
||||
std::string_view title,
|
||||
std::string_view subtitle,
|
||||
const UIColor& fillColor,
|
||||
const UIColor& borderColor) {
|
||||
DrawPanel(drawList, rect, fillColor, borderColor, 10.0f);
|
||||
drawList.AddText(UIPoint(rect.x + 14.0f, rect.y + 12.0f), std::string(title), kTextPrimary, 15.0f);
|
||||
drawList.AddText(UIPoint(rect.x + 14.0f, rect.y + 34.0f), std::string(subtitle), kTextMuted, 12.0f);
|
||||
}
|
||||
|
||||
UIDragDropSourceDescriptor BuildTextureSource(const UIPoint& pointerPosition) {
|
||||
UIDragDropSourceDescriptor source = {};
|
||||
source.ownerId = kTextureSourceOwnerId;
|
||||
source.sourceId = "project.texture";
|
||||
source.pointerDownPosition = pointerPosition;
|
||||
source.payload = UIDragDropPayload{ "asset.texture", "tex-001", "Checker.png" };
|
||||
source.allowedOperations = UIDragDropOperation::Copy | UIDragDropOperation::Move;
|
||||
source.activationDistance = 6.0f;
|
||||
return source;
|
||||
}
|
||||
|
||||
UIDragDropSourceDescriptor BuildEntitySource(const UIPoint& pointerPosition) {
|
||||
UIDragDropSourceDescriptor source = {};
|
||||
source.ownerId = kEntitySourceOwnerId;
|
||||
source.sourceId = "hierarchy.entity";
|
||||
source.pointerDownPosition = pointerPosition;
|
||||
source.payload = UIDragDropPayload{ "scene.entity", "entity-hero", "HeroRoot" };
|
||||
source.allowedOperations = UIDragDropOperation::Move;
|
||||
source.activationDistance = 6.0f;
|
||||
return source;
|
||||
}
|
||||
|
||||
UIDragDropTargetDescriptor BuildProjectTarget() {
|
||||
static constexpr std::array<std::string_view, 2> kAcceptedTypes = {
|
||||
"asset.texture",
|
||||
"asset.material"
|
||||
};
|
||||
|
||||
UIDragDropTargetDescriptor target = {};
|
||||
target.ownerId = kProjectTargetOwnerId;
|
||||
target.targetId = "project.browser";
|
||||
target.acceptedPayloadTypes = kAcceptedTypes;
|
||||
target.acceptedOperations =
|
||||
UIDragDropOperation::Copy |
|
||||
UIDragDropOperation::Move;
|
||||
target.preferredOperation = UIDragDropOperation::Copy;
|
||||
return target;
|
||||
}
|
||||
|
||||
UIDragDropTargetDescriptor BuildHierarchyTarget() {
|
||||
static constexpr std::array<std::string_view, 1> kAcceptedTypes = {
|
||||
"scene.entity"
|
||||
};
|
||||
|
||||
UIDragDropTargetDescriptor target = {};
|
||||
target.ownerId = kHierarchyTargetOwnerId;
|
||||
target.targetId = "hierarchy.parent";
|
||||
target.acceptedPayloadTypes = kAcceptedTypes;
|
||||
target.acceptedOperations = UIDragDropOperation::Move;
|
||||
target.preferredOperation = UIDragDropOperation::Move;
|
||||
return target;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void DragDropValidationScene::Reset() {
|
||||
m_dragState = {};
|
||||
m_pointerPosition = {};
|
||||
m_hasPointer = false;
|
||||
m_resultText = "Result: Ready";
|
||||
m_lastDropText = "(none)";
|
||||
}
|
||||
|
||||
void DragDropValidationScene::Update(
|
||||
const std::vector<UIInputEvent>& events,
|
||||
const UIRect& viewportRect,
|
||||
bool windowFocused) {
|
||||
const Geometry geometry = BuildGeometry(viewportRect);
|
||||
|
||||
if (!windowFocused &&
|
||||
IsUIDragDropInProgress(m_dragState)) {
|
||||
HandleCancel("Result: focus lost, drag cancelled");
|
||||
}
|
||||
|
||||
for (const UIInputEvent& event : events) {
|
||||
switch (event.type) {
|
||||
case UIInputEventType::PointerMove:
|
||||
m_pointerPosition = event.position;
|
||||
m_hasPointer = true;
|
||||
HandlePointerMove(geometry, event.position);
|
||||
break;
|
||||
case UIInputEventType::PointerLeave:
|
||||
m_hasPointer = false;
|
||||
break;
|
||||
case UIInputEventType::PointerButtonDown:
|
||||
if (event.pointerButton == UIPointerButton::Left) {
|
||||
m_pointerPosition = event.position;
|
||||
m_hasPointer = true;
|
||||
HandlePointerDown(geometry, event.position);
|
||||
}
|
||||
break;
|
||||
case UIInputEventType::PointerButtonUp:
|
||||
if (event.pointerButton == UIPointerButton::Left) {
|
||||
m_pointerPosition = event.position;
|
||||
m_hasPointer = true;
|
||||
HandlePointerUp(geometry, event.position);
|
||||
}
|
||||
break;
|
||||
case UIInputEventType::KeyDown:
|
||||
if (event.keyCode == static_cast<std::int32_t>(KeyCode::Escape)) {
|
||||
HandleCancel("Result: Escape cancelled current drag");
|
||||
}
|
||||
break;
|
||||
case UIInputEventType::FocusLost:
|
||||
HandleCancel("Result: focus lost, drag cancelled");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DragDropValidationScene::AppendDrawData(
|
||||
UIDrawData& drawData,
|
||||
const UIRect& viewportRect) const {
|
||||
const Geometry geometry = BuildGeometry(viewportRect);
|
||||
const bool hoverTexture = m_hasPointer && RectContains(geometry.textureSourceRect, m_pointerPosition);
|
||||
const bool hoverEntity = m_hasPointer && RectContains(geometry.entitySourceRect, m_pointerPosition);
|
||||
const bool hoverProject = m_hasPointer && RectContains(geometry.projectTargetRect, m_pointerPosition);
|
||||
const bool hoverHierarchy = m_hasPointer && RectContains(geometry.hierarchyTargetRect, m_pointerPosition);
|
||||
const bool dragProject =
|
||||
m_dragState.active && m_dragState.targetOwnerId == kProjectTargetOwnerId;
|
||||
const bool dragHierarchy =
|
||||
m_dragState.active && m_dragState.targetOwnerId == kHierarchyTargetOwnerId;
|
||||
const bool rejectProject =
|
||||
m_dragState.active && hoverProject && !dragProject;
|
||||
const bool rejectHierarchy =
|
||||
m_dragState.active && hoverHierarchy && !dragHierarchy;
|
||||
|
||||
UIDrawList& drawList = drawData.EmplaceDrawList("Core Drag Drop Primitive Lab");
|
||||
DrawPanel(drawList, geometry.labRect, kLabPanelBg, kLabPanelBorder, 12.0f);
|
||||
DrawPanel(drawList, geometry.statusRect, kStatusBg, kCardBorder, 10.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(geometry.statusRect.x + 14.0f, geometry.statusRect.y + 12.0f),
|
||||
"测试内容:Core Drag / Drop Contract",
|
||||
kTextPrimary,
|
||||
14.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(geometry.statusRect.x + 14.0f, geometry.statusRect.y + 34.0f),
|
||||
m_resultText,
|
||||
kTextMuted,
|
||||
12.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(geometry.statusRect.x + 14.0f, geometry.statusRect.y + 54.0f),
|
||||
"Payload: " + (m_dragState.payload.label.empty() ? std::string("(none)") : m_dragState.payload.label),
|
||||
kTextMuted,
|
||||
12.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(geometry.statusRect.x + 280.0f, geometry.statusRect.y + 34.0f),
|
||||
std::string("Armed: ") + (m_dragState.armed ? "true" : "false"),
|
||||
m_dragState.armed ? kTextPrimary : kTextWeak,
|
||||
12.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(geometry.statusRect.x + 280.0f, geometry.statusRect.y + 54.0f),
|
||||
std::string("Active: ") + (m_dragState.active ? "true" : "false"),
|
||||
m_dragState.active ? kTextSuccess : kTextWeak,
|
||||
12.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(geometry.statusRect.x + 430.0f, geometry.statusRect.y + 34.0f),
|
||||
"Hover Target: " +
|
||||
(m_dragState.targetId.empty() ? std::string("(none)") : m_dragState.targetId),
|
||||
kTextMuted,
|
||||
12.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(geometry.statusRect.x + 430.0f, geometry.statusRect.y + 54.0f),
|
||||
"Preview Op: " + DescribeOperation(m_dragState.previewOperation),
|
||||
m_dragState.previewOperation == UIDragDropOperation::None ? kTextWeak : kTextSuccess,
|
||||
12.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(geometry.statusRect.x + 650.0f, geometry.statusRect.y + 34.0f),
|
||||
"Last Drop: " + m_lastDropText,
|
||||
kTextMuted,
|
||||
12.0f);
|
||||
|
||||
DrawCard(
|
||||
drawList,
|
||||
geometry.sourcesRect,
|
||||
"Sources",
|
||||
"按下 source 后先保持,越过阈值才会进入 active。",
|
||||
kCardBg,
|
||||
kCardBorder);
|
||||
DrawCard(
|
||||
drawList,
|
||||
geometry.targetsRect,
|
||||
"Targets",
|
||||
"右侧同时展示 accept / reject 与预览操作。",
|
||||
kCardBg,
|
||||
kCardBorder);
|
||||
|
||||
DrawCard(
|
||||
drawList,
|
||||
geometry.textureSourceRect,
|
||||
"Texture Asset",
|
||||
"type=asset.texture | Copy/Move",
|
||||
hoverTexture ? kCardHover : kCardBg,
|
||||
kCardBorder);
|
||||
drawList.AddText(
|
||||
UIPoint(geometry.textureSourceRect.x + 14.0f, geometry.textureSourceRect.y + 58.0f),
|
||||
"Checker.png",
|
||||
kTextPrimary,
|
||||
13.0f);
|
||||
|
||||
DrawCard(
|
||||
drawList,
|
||||
geometry.entitySourceRect,
|
||||
"Scene Entity",
|
||||
"type=scene.entity | Move only",
|
||||
hoverEntity ? kCardHover : kCardBg,
|
||||
kCardBorder);
|
||||
drawList.AddText(
|
||||
UIPoint(geometry.entitySourceRect.x + 14.0f, geometry.entitySourceRect.y + 58.0f),
|
||||
"HeroRoot",
|
||||
kTextPrimary,
|
||||
13.0f);
|
||||
|
||||
DrawCard(
|
||||
drawList,
|
||||
geometry.projectTargetRect,
|
||||
"Project Browser",
|
||||
"accepts asset.texture / asset.material | preferred Copy",
|
||||
dragProject ? kAccept : (rejectProject ? kReject : (hoverProject ? kCardHover : kCardBg)),
|
||||
dragProject ? kAcceptBorder : (rejectProject ? kRejectBorder : kCardBorder));
|
||||
drawList.AddText(
|
||||
UIPoint(geometry.projectTargetRect.x + 14.0f, geometry.projectTargetRect.y + 58.0f),
|
||||
dragProject ? "Accepting current payload" : "拖入 texture 时应显示 Copy",
|
||||
dragProject ? kTextSuccess : (rejectProject ? kTextDanger : kTextMuted),
|
||||
12.0f);
|
||||
|
||||
DrawCard(
|
||||
drawList,
|
||||
geometry.hierarchyTargetRect,
|
||||
"Hierarchy Parent",
|
||||
"accepts scene.entity | preferred Move",
|
||||
dragHierarchy ? kAccept : (rejectHierarchy ? kReject : (hoverHierarchy ? kCardHover : kCardBg)),
|
||||
dragHierarchy ? kAcceptBorder : (rejectHierarchy ? kRejectBorder : kCardBorder));
|
||||
drawList.AddText(
|
||||
UIPoint(geometry.hierarchyTargetRect.x + 14.0f, geometry.hierarchyTargetRect.y + 58.0f),
|
||||
dragHierarchy ? "Accepting current payload" : "拖入 entity 时应显示 Move",
|
||||
dragHierarchy ? kTextSuccess : (rejectHierarchy ? kTextDanger : kTextMuted),
|
||||
12.0f);
|
||||
|
||||
if (m_dragState.active) {
|
||||
const UIRect ghostRect(
|
||||
m_pointerPosition.x + 16.0f,
|
||||
m_pointerPosition.y + 12.0f,
|
||||
188.0f,
|
||||
64.0f);
|
||||
DrawPanel(drawList, ghostRect, kGhostBg, kGhostBorder, 8.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(ghostRect.x + 12.0f, ghostRect.y + 12.0f),
|
||||
m_dragState.payload.label.empty() ? std::string("(payload)") : m_dragState.payload.label,
|
||||
kTextPrimary,
|
||||
14.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(ghostRect.x + 12.0f, ghostRect.y + 34.0f),
|
||||
"type=" + m_dragState.payload.typeId + " | op=" + DescribeOperation(m_dragState.previewOperation),
|
||||
kTextMuted,
|
||||
12.0f);
|
||||
}
|
||||
}
|
||||
|
||||
DragDropValidationScene::Geometry DragDropValidationScene::BuildGeometry(
|
||||
const UIRect& viewportRect) const {
|
||||
Geometry geometry = {};
|
||||
const float availableWidth = (std::max)(720.0f, viewportRect.width - 48.0f);
|
||||
const float availableHeight = (std::max)(360.0f, viewportRect.height - 256.0f);
|
||||
geometry.labRect = UIRect(
|
||||
24.0f,
|
||||
220.0f,
|
||||
(std::min)(980.0f, availableWidth),
|
||||
(std::min)(460.0f, availableHeight));
|
||||
geometry.statusRect = UIRect(
|
||||
geometry.labRect.x + 20.0f,
|
||||
geometry.labRect.y + 18.0f,
|
||||
geometry.labRect.width - 40.0f,
|
||||
84.0f);
|
||||
geometry.sourcesRect = UIRect(
|
||||
geometry.labRect.x + 20.0f,
|
||||
geometry.statusRect.y + geometry.statusRect.height + 18.0f,
|
||||
280.0f,
|
||||
geometry.labRect.height - 140.0f);
|
||||
geometry.targetsRect = UIRect(
|
||||
geometry.sourcesRect.x + geometry.sourcesRect.width + 18.0f,
|
||||
geometry.sourcesRect.y,
|
||||
geometry.labRect.width - 338.0f,
|
||||
geometry.sourcesRect.height);
|
||||
geometry.textureSourceRect = UIRect(
|
||||
geometry.sourcesRect.x + 14.0f,
|
||||
geometry.sourcesRect.y + 54.0f,
|
||||
geometry.sourcesRect.width - 28.0f,
|
||||
96.0f);
|
||||
geometry.entitySourceRect = UIRect(
|
||||
geometry.textureSourceRect.x,
|
||||
geometry.textureSourceRect.y + geometry.textureSourceRect.height + 16.0f,
|
||||
geometry.textureSourceRect.width,
|
||||
96.0f);
|
||||
geometry.projectTargetRect = UIRect(
|
||||
geometry.targetsRect.x + 14.0f,
|
||||
geometry.targetsRect.y + 54.0f,
|
||||
geometry.targetsRect.width - 28.0f,
|
||||
112.0f);
|
||||
geometry.hierarchyTargetRect = UIRect(
|
||||
geometry.projectTargetRect.x,
|
||||
geometry.projectTargetRect.y + geometry.projectTargetRect.height + 18.0f,
|
||||
geometry.projectTargetRect.width,
|
||||
112.0f);
|
||||
return geometry;
|
||||
}
|
||||
|
||||
void DragDropValidationScene::HandlePointerDown(
|
||||
const Geometry& geometry,
|
||||
const UIPoint& position) {
|
||||
if (RectContains(geometry.textureSourceRect, position)) {
|
||||
BeginUIDragDrop(BuildTextureSource(position), m_dragState);
|
||||
SetResult("Result: armed Texture Asset, move beyond threshold to activate");
|
||||
return;
|
||||
}
|
||||
if (RectContains(geometry.entitySourceRect, position)) {
|
||||
BeginUIDragDrop(BuildEntitySource(position), m_dragState);
|
||||
SetResult("Result: armed Scene Entity, move beyond threshold to activate");
|
||||
}
|
||||
}
|
||||
|
||||
void DragDropValidationScene::HandlePointerMove(
|
||||
const Geometry& geometry,
|
||||
const UIPoint& position) {
|
||||
if (!IsUIDragDropInProgress(m_dragState)) {
|
||||
return;
|
||||
}
|
||||
|
||||
UIDragDropResult result = {};
|
||||
UpdateUIDragDropPointer(m_dragState, position, &result);
|
||||
if (result.activated) {
|
||||
SetResult("Result: drag became active after crossing activation distance");
|
||||
}
|
||||
UpdateHoveredTarget(geometry, position);
|
||||
}
|
||||
|
||||
void DragDropValidationScene::HandlePointerUp(
|
||||
const Geometry& geometry,
|
||||
const UIPoint& position) {
|
||||
if (!IsUIDragDropInProgress(m_dragState)) {
|
||||
return;
|
||||
}
|
||||
|
||||
UpdateHoveredTarget(geometry, position);
|
||||
UIDragDropResult result = {};
|
||||
if (!EndUIDragDrop(m_dragState, result)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (result.completed) {
|
||||
m_lastDropText =
|
||||
result.payloadItemId + " -> " + result.targetId + " (" + DescribeOperation(result.operation) + ")";
|
||||
SetResult("Result: drop completed on " + result.targetId + " with " + DescribeOperation(result.operation));
|
||||
return;
|
||||
}
|
||||
|
||||
SetResult("Result: pointer released without accepted target, drag cancelled");
|
||||
}
|
||||
|
||||
void DragDropValidationScene::HandleCancel(std::string reason) {
|
||||
if (!IsUIDragDropInProgress(m_dragState)) {
|
||||
return;
|
||||
}
|
||||
|
||||
UIDragDropResult result = {};
|
||||
CancelUIDragDrop(m_dragState, &result);
|
||||
SetResult(std::move(reason));
|
||||
}
|
||||
|
||||
void DragDropValidationScene::UpdateHoveredTarget(
|
||||
const Geometry& geometry,
|
||||
const UIPoint& position) {
|
||||
if (!m_dragState.active) {
|
||||
return;
|
||||
}
|
||||
|
||||
UIDragDropResult result = {};
|
||||
if (RectContains(geometry.projectTargetRect, position)) {
|
||||
const UIDragDropTargetDescriptor projectTarget = BuildProjectTarget();
|
||||
UpdateUIDragDropTarget(m_dragState, &projectTarget, &result);
|
||||
} else if (RectContains(geometry.hierarchyTargetRect, position)) {
|
||||
const UIDragDropTargetDescriptor hierarchyTarget = BuildHierarchyTarget();
|
||||
UpdateUIDragDropTarget(m_dragState, &hierarchyTarget, &result);
|
||||
} else {
|
||||
UpdateUIDragDropTarget(m_dragState, nullptr, &result);
|
||||
}
|
||||
|
||||
if (result.targetChanged) {
|
||||
if (!HasResolvedUIDragDropTarget(m_dragState)) {
|
||||
SetResult("Result: current hover target rejects payload type or operation");
|
||||
} else {
|
||||
SetResult("Result: hover target accepts payload with " + DescribeOperation(m_dragState.previewOperation));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DragDropValidationScene::SetResult(std::string text) {
|
||||
m_resultText = std::move(text);
|
||||
}
|
||||
|
||||
bool DragDropValidationScene::RectContains(
|
||||
const UIRect& rect,
|
||||
const UIPoint& position) {
|
||||
return position.x >= rect.x &&
|
||||
position.x <= rect.x + rect.width &&
|
||||
position.y >= rect.y &&
|
||||
position.y <= rect.y + rect.height;
|
||||
}
|
||||
|
||||
} // namespace XCEngine::Tests::CoreUI
|
||||
@@ -1,62 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <XCEngine/UI/DrawData.h>
|
||||
#include <XCEngine/UI/Widgets/UIDragDropInteraction.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace XCEngine::Tests::CoreUI {
|
||||
|
||||
class DragDropValidationScene {
|
||||
public:
|
||||
static constexpr const char* ScenarioId = "core.input.drag_drop_basic";
|
||||
|
||||
void Reset();
|
||||
void Update(
|
||||
const std::vector<::XCEngine::UI::UIInputEvent>& events,
|
||||
const ::XCEngine::UI::UIRect& viewportRect,
|
||||
bool windowFocused);
|
||||
void AppendDrawData(
|
||||
::XCEngine::UI::UIDrawData& drawData,
|
||||
const ::XCEngine::UI::UIRect& viewportRect) const;
|
||||
|
||||
private:
|
||||
struct Geometry {
|
||||
::XCEngine::UI::UIRect labRect = {};
|
||||
::XCEngine::UI::UIRect statusRect = {};
|
||||
::XCEngine::UI::UIRect sourcesRect = {};
|
||||
::XCEngine::UI::UIRect targetsRect = {};
|
||||
::XCEngine::UI::UIRect textureSourceRect = {};
|
||||
::XCEngine::UI::UIRect entitySourceRect = {};
|
||||
::XCEngine::UI::UIRect projectTargetRect = {};
|
||||
::XCEngine::UI::UIRect hierarchyTargetRect = {};
|
||||
};
|
||||
|
||||
Geometry BuildGeometry(const ::XCEngine::UI::UIRect& viewportRect) const;
|
||||
void HandlePointerDown(
|
||||
const Geometry& geometry,
|
||||
const ::XCEngine::UI::UIPoint& position);
|
||||
void HandlePointerMove(
|
||||
const Geometry& geometry,
|
||||
const ::XCEngine::UI::UIPoint& position);
|
||||
void HandlePointerUp(
|
||||
const Geometry& geometry,
|
||||
const ::XCEngine::UI::UIPoint& position);
|
||||
void HandleCancel(std::string reason);
|
||||
void UpdateHoveredTarget(
|
||||
const Geometry& geometry,
|
||||
const ::XCEngine::UI::UIPoint& position);
|
||||
void SetResult(std::string text);
|
||||
static bool RectContains(
|
||||
const ::XCEngine::UI::UIRect& rect,
|
||||
const ::XCEngine::UI::UIPoint& position);
|
||||
|
||||
::XCEngine::UI::Widgets::UIDragDropState m_dragState = {};
|
||||
::XCEngine::UI::UIPoint m_pointerPosition = {};
|
||||
bool m_hasPointer = false;
|
||||
std::string m_resultText = "Result: Ready";
|
||||
std::string m_lastDropText = "(none)";
|
||||
};
|
||||
|
||||
} // namespace XCEngine::Tests::CoreUI
|
||||
@@ -1,253 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef NOMINMAX
|
||||
#define NOMINMAX
|
||||
#endif
|
||||
|
||||
#include <XCEngine/UI/Types.h>
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
namespace XCEngine::Tests::CoreUI::Host {
|
||||
|
||||
class InputModifierTracker {
|
||||
public:
|
||||
void Reset() {
|
||||
m_leftShift = false;
|
||||
m_rightShift = false;
|
||||
m_leftControl = false;
|
||||
m_rightControl = false;
|
||||
m_leftAlt = false;
|
||||
m_rightAlt = false;
|
||||
m_leftSuper = false;
|
||||
m_rightSuper = false;
|
||||
m_leftMouse = false;
|
||||
m_rightMouse = false;
|
||||
m_middleMouse = false;
|
||||
m_x1Mouse = false;
|
||||
m_x2Mouse = false;
|
||||
}
|
||||
|
||||
void SyncFromSystemState() {
|
||||
m_leftShift = (GetKeyState(VK_LSHIFT) & 0x8000) != 0;
|
||||
m_rightShift = (GetKeyState(VK_RSHIFT) & 0x8000) != 0;
|
||||
m_leftControl = (GetKeyState(VK_LCONTROL) & 0x8000) != 0;
|
||||
m_rightControl = (GetKeyState(VK_RCONTROL) & 0x8000) != 0;
|
||||
m_leftAlt = (GetKeyState(VK_LMENU) & 0x8000) != 0;
|
||||
m_rightAlt = (GetKeyState(VK_RMENU) & 0x8000) != 0;
|
||||
m_leftSuper = (GetKeyState(VK_LWIN) & 0x8000) != 0;
|
||||
m_rightSuper = (GetKeyState(VK_RWIN) & 0x8000) != 0;
|
||||
m_leftMouse = (GetKeyState(VK_LBUTTON) & 0x8000) != 0;
|
||||
m_rightMouse = (GetKeyState(VK_RBUTTON) & 0x8000) != 0;
|
||||
m_middleMouse = (GetKeyState(VK_MBUTTON) & 0x8000) != 0;
|
||||
m_x1Mouse = (GetKeyState(VK_XBUTTON1) & 0x8000) != 0;
|
||||
m_x2Mouse = (GetKeyState(VK_XBUTTON2) & 0x8000) != 0;
|
||||
}
|
||||
|
||||
::XCEngine::UI::UIInputModifiers GetCurrentModifiers() const {
|
||||
return BuildModifiers();
|
||||
}
|
||||
|
||||
::XCEngine::UI::UIInputModifiers BuildPointerModifiers(std::size_t wParam) const {
|
||||
::XCEngine::UI::UIInputModifiers modifiers = BuildModifiers();
|
||||
ApplyPointerWParam(modifiers, wParam);
|
||||
return modifiers;
|
||||
}
|
||||
|
||||
::XCEngine::UI::UIInputModifiers ApplyPointerMessage(
|
||||
::XCEngine::UI::UIInputEventType type,
|
||||
::XCEngine::UI::UIPointerButton button,
|
||||
std::size_t wParam) {
|
||||
::XCEngine::UI::UIInputModifiers modifiers = BuildPointerModifiers(wParam);
|
||||
if (type == ::XCEngine::UI::UIInputEventType::PointerButtonDown) {
|
||||
SetPointerButton(modifiers, button, true);
|
||||
} else if (type == ::XCEngine::UI::UIInputEventType::PointerButtonUp) {
|
||||
SetPointerButton(modifiers, button, false);
|
||||
}
|
||||
|
||||
ApplyPointerState(modifiers);
|
||||
return BuildModifiers();
|
||||
}
|
||||
|
||||
::XCEngine::UI::UIInputModifiers ApplyKeyMessage(
|
||||
::XCEngine::UI::UIInputEventType type,
|
||||
WPARAM wParam,
|
||||
LPARAM lParam) {
|
||||
if (type == ::XCEngine::UI::UIInputEventType::KeyDown) {
|
||||
SetModifierState(ResolveModifierKey(wParam, lParam), true);
|
||||
} else if (type == ::XCEngine::UI::UIInputEventType::KeyUp) {
|
||||
SetModifierState(ResolveModifierKey(wParam, lParam), false);
|
||||
}
|
||||
|
||||
return BuildModifiers();
|
||||
}
|
||||
|
||||
private:
|
||||
enum class ModifierKey : std::uint8_t {
|
||||
None = 0,
|
||||
LeftShift,
|
||||
RightShift,
|
||||
LeftControl,
|
||||
RightControl,
|
||||
LeftAlt,
|
||||
RightAlt,
|
||||
LeftSuper,
|
||||
RightSuper
|
||||
};
|
||||
|
||||
static bool IsExtendedKey(LPARAM lParam) {
|
||||
return (static_cast<std::uint32_t>(lParam) & 0x01000000u) != 0u;
|
||||
}
|
||||
|
||||
static std::uint32_t ExtractScanCode(LPARAM lParam) {
|
||||
return (static_cast<std::uint32_t>(lParam) >> 16u) & 0xffu;
|
||||
}
|
||||
|
||||
static ModifierKey ResolveModifierKey(WPARAM wParam, LPARAM lParam) {
|
||||
switch (static_cast<std::uint32_t>(wParam)) {
|
||||
case VK_SHIFT: {
|
||||
const UINT shiftVirtualKey = MapVirtualKeyW(ExtractScanCode(lParam), MAPVK_VSC_TO_VK_EX);
|
||||
return shiftVirtualKey == VK_RSHIFT
|
||||
? ModifierKey::RightShift
|
||||
: ModifierKey::LeftShift;
|
||||
}
|
||||
case VK_LSHIFT:
|
||||
return ModifierKey::LeftShift;
|
||||
case VK_RSHIFT:
|
||||
return ModifierKey::RightShift;
|
||||
case VK_CONTROL:
|
||||
return IsExtendedKey(lParam)
|
||||
? ModifierKey::RightControl
|
||||
: ModifierKey::LeftControl;
|
||||
case VK_LCONTROL:
|
||||
return ModifierKey::LeftControl;
|
||||
case VK_RCONTROL:
|
||||
return ModifierKey::RightControl;
|
||||
case VK_MENU:
|
||||
return IsExtendedKey(lParam)
|
||||
? ModifierKey::RightAlt
|
||||
: ModifierKey::LeftAlt;
|
||||
case VK_LMENU:
|
||||
return ModifierKey::LeftAlt;
|
||||
case VK_RMENU:
|
||||
return ModifierKey::RightAlt;
|
||||
case VK_LWIN:
|
||||
return ModifierKey::LeftSuper;
|
||||
case VK_RWIN:
|
||||
return ModifierKey::RightSuper;
|
||||
default:
|
||||
return ModifierKey::None;
|
||||
}
|
||||
}
|
||||
|
||||
static void ApplyPointerWParam(
|
||||
::XCEngine::UI::UIInputModifiers& modifiers,
|
||||
std::size_t wParam) {
|
||||
modifiers.shift = modifiers.shift || (wParam & MK_SHIFT) != 0;
|
||||
modifiers.control = modifiers.control || (wParam & MK_CONTROL) != 0;
|
||||
modifiers.leftMouse = (wParam & MK_LBUTTON) != 0;
|
||||
modifiers.rightMouse = (wParam & MK_RBUTTON) != 0;
|
||||
modifiers.middleMouse = (wParam & MK_MBUTTON) != 0;
|
||||
modifiers.x1Mouse = (wParam & MK_XBUTTON1) != 0;
|
||||
modifiers.x2Mouse = (wParam & MK_XBUTTON2) != 0;
|
||||
}
|
||||
|
||||
static void SetPointerButton(
|
||||
::XCEngine::UI::UIInputModifiers& modifiers,
|
||||
::XCEngine::UI::UIPointerButton button,
|
||||
bool pressed) {
|
||||
switch (button) {
|
||||
case ::XCEngine::UI::UIPointerButton::Left:
|
||||
modifiers.leftMouse = pressed;
|
||||
break;
|
||||
case ::XCEngine::UI::UIPointerButton::Right:
|
||||
modifiers.rightMouse = pressed;
|
||||
break;
|
||||
case ::XCEngine::UI::UIPointerButton::Middle:
|
||||
modifiers.middleMouse = pressed;
|
||||
break;
|
||||
case ::XCEngine::UI::UIPointerButton::X1:
|
||||
modifiers.x1Mouse = pressed;
|
||||
break;
|
||||
case ::XCEngine::UI::UIPointerButton::X2:
|
||||
modifiers.x2Mouse = pressed;
|
||||
break;
|
||||
case ::XCEngine::UI::UIPointerButton::None:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void ApplyPointerState(const ::XCEngine::UI::UIInputModifiers& modifiers) {
|
||||
m_leftMouse = modifiers.leftMouse;
|
||||
m_rightMouse = modifiers.rightMouse;
|
||||
m_middleMouse = modifiers.middleMouse;
|
||||
m_x1Mouse = modifiers.x1Mouse;
|
||||
m_x2Mouse = modifiers.x2Mouse;
|
||||
}
|
||||
|
||||
void SetModifierState(ModifierKey key, bool pressed) {
|
||||
switch (key) {
|
||||
case ModifierKey::LeftShift:
|
||||
m_leftShift = pressed;
|
||||
break;
|
||||
case ModifierKey::RightShift:
|
||||
m_rightShift = pressed;
|
||||
break;
|
||||
case ModifierKey::LeftControl:
|
||||
m_leftControl = pressed;
|
||||
break;
|
||||
case ModifierKey::RightControl:
|
||||
m_rightControl = pressed;
|
||||
break;
|
||||
case ModifierKey::LeftAlt:
|
||||
m_leftAlt = pressed;
|
||||
break;
|
||||
case ModifierKey::RightAlt:
|
||||
m_rightAlt = pressed;
|
||||
break;
|
||||
case ModifierKey::LeftSuper:
|
||||
m_leftSuper = pressed;
|
||||
break;
|
||||
case ModifierKey::RightSuper:
|
||||
m_rightSuper = pressed;
|
||||
break;
|
||||
case ModifierKey::None:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
::XCEngine::UI::UIInputModifiers BuildModifiers() const {
|
||||
::XCEngine::UI::UIInputModifiers modifiers = {};
|
||||
modifiers.shift = m_leftShift || m_rightShift;
|
||||
modifiers.control = m_leftControl || m_rightControl;
|
||||
modifiers.alt = m_leftAlt || m_rightAlt;
|
||||
modifiers.super = m_leftSuper || m_rightSuper;
|
||||
modifiers.leftMouse = m_leftMouse;
|
||||
modifiers.rightMouse = m_rightMouse;
|
||||
modifiers.middleMouse = m_middleMouse;
|
||||
modifiers.x1Mouse = m_x1Mouse;
|
||||
modifiers.x2Mouse = m_x2Mouse;
|
||||
return modifiers;
|
||||
}
|
||||
|
||||
bool m_leftShift = false;
|
||||
bool m_rightShift = false;
|
||||
bool m_leftControl = false;
|
||||
bool m_rightControl = false;
|
||||
bool m_leftAlt = false;
|
||||
bool m_rightAlt = false;
|
||||
bool m_leftSuper = false;
|
||||
bool m_rightSuper = false;
|
||||
bool m_leftMouse = false;
|
||||
bool m_rightMouse = false;
|
||||
bool m_middleMouse = false;
|
||||
bool m_x1Mouse = false;
|
||||
bool m_x2Mouse = false;
|
||||
};
|
||||
|
||||
} // namespace XCEngine::Tests::CoreUI::Host
|
||||
@@ -1,561 +0,0 @@
|
||||
#include "NativeRenderer.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <filesystem>
|
||||
|
||||
namespace XCEngine::Tests::CoreUI::Host {
|
||||
|
||||
namespace {
|
||||
|
||||
D2D1_RECT_F ToD2DRect(const ::XCEngine::UI::UIRect& rect) {
|
||||
return D2D1::RectF(rect.x, rect.y, rect.x + rect.width, rect.y + rect.height);
|
||||
}
|
||||
|
||||
D2D1_COLOR_F ToD2DColorValue(const ::XCEngine::UI::UIColor& color) {
|
||||
return D2D1::ColorF(color.r, color.g, color.b, color.a);
|
||||
}
|
||||
|
||||
std::string HrToString(const char* operation, HRESULT hr) {
|
||||
char buffer[128] = {};
|
||||
sprintf_s(buffer, "%s failed with hr=0x%08X.", operation, static_cast<unsigned int>(hr));
|
||||
return buffer;
|
||||
}
|
||||
|
||||
void FillLinearGradientRect(
|
||||
ID2D1RenderTarget& renderTarget,
|
||||
const ::XCEngine::UI::UIDrawCommand& command) {
|
||||
const D2D1_RECT_F rect = ToD2DRect(command.rect);
|
||||
const D2D1_GRADIENT_STOP stops[2] = {
|
||||
D2D1::GradientStop(0.0f, ToD2DColorValue(command.color)),
|
||||
D2D1::GradientStop(1.0f, ToD2DColorValue(command.secondaryColor))
|
||||
};
|
||||
|
||||
Microsoft::WRL::ComPtr<ID2D1GradientStopCollection> stopCollection;
|
||||
if (FAILED(renderTarget.CreateGradientStopCollection(
|
||||
stops,
|
||||
2u,
|
||||
stopCollection.ReleaseAndGetAddressOf()))) {
|
||||
return;
|
||||
}
|
||||
|
||||
const D2D1_POINT_2F startPoint = D2D1::Point2F(rect.left, rect.top);
|
||||
const D2D1_POINT_2F endPoint =
|
||||
command.gradientDirection == ::XCEngine::UI::UILinearGradientDirection::Vertical
|
||||
? D2D1::Point2F(rect.left, rect.bottom)
|
||||
: D2D1::Point2F(rect.right, rect.top);
|
||||
|
||||
Microsoft::WRL::ComPtr<ID2D1LinearGradientBrush> gradientBrush;
|
||||
if (FAILED(renderTarget.CreateLinearGradientBrush(
|
||||
D2D1::LinearGradientBrushProperties(startPoint, endPoint),
|
||||
stopCollection.Get(),
|
||||
gradientBrush.ReleaseAndGetAddressOf()))) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (command.rounding > 0.0f) {
|
||||
renderTarget.FillRoundedRectangle(
|
||||
D2D1::RoundedRect(rect, command.rounding, command.rounding),
|
||||
gradientBrush.Get());
|
||||
return;
|
||||
}
|
||||
|
||||
renderTarget.FillRectangle(rect, gradientBrush.Get());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
bool NativeRenderer::Initialize(HWND hwnd) {
|
||||
Shutdown();
|
||||
|
||||
if (hwnd == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_hwnd = hwnd;
|
||||
if (FAILED(D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, m_d2dFactory.ReleaseAndGetAddressOf()))) {
|
||||
Shutdown();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (FAILED(DWriteCreateFactory(
|
||||
DWRITE_FACTORY_TYPE_SHARED,
|
||||
__uuidof(IDWriteFactory),
|
||||
reinterpret_cast<IUnknown**>(m_dwriteFactory.ReleaseAndGetAddressOf())))) {
|
||||
Shutdown();
|
||||
return false;
|
||||
}
|
||||
|
||||
return EnsureRenderTarget();
|
||||
}
|
||||
|
||||
void NativeRenderer::Shutdown() {
|
||||
m_textFormats.clear();
|
||||
m_solidBrush.Reset();
|
||||
m_renderTarget.Reset();
|
||||
m_wicFactory.Reset();
|
||||
m_dwriteFactory.Reset();
|
||||
m_d2dFactory.Reset();
|
||||
if (m_wicComInitialized) {
|
||||
CoUninitialize();
|
||||
m_wicComInitialized = false;
|
||||
}
|
||||
m_hwnd = nullptr;
|
||||
}
|
||||
|
||||
void NativeRenderer::Resize(UINT width, UINT height) {
|
||||
if (!m_renderTarget || width == 0 || height == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const HRESULT hr = m_renderTarget->Resize(D2D1::SizeU(width, height));
|
||||
if (hr == D2DERR_RECREATE_TARGET) {
|
||||
DiscardRenderTarget();
|
||||
}
|
||||
}
|
||||
|
||||
bool NativeRenderer::Render(const ::XCEngine::UI::UIDrawData& drawData) {
|
||||
if (!EnsureRenderTarget()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const bool rendered = RenderToTarget(*m_renderTarget.Get(), *m_solidBrush.Get(), drawData);
|
||||
const HRESULT hr = m_renderTarget->EndDraw();
|
||||
if (hr == D2DERR_RECREATE_TARGET) {
|
||||
DiscardRenderTarget();
|
||||
return false;
|
||||
}
|
||||
|
||||
return rendered && SUCCEEDED(hr);
|
||||
}
|
||||
|
||||
bool NativeRenderer::CaptureToPng(
|
||||
const ::XCEngine::UI::UIDrawData& drawData,
|
||||
UINT width,
|
||||
UINT height,
|
||||
const std::filesystem::path& outputPath,
|
||||
std::string& outError) {
|
||||
outError.clear();
|
||||
if (width == 0 || height == 0) {
|
||||
outError = "CaptureToPng rejected an empty render size.";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!m_d2dFactory || !m_dwriteFactory) {
|
||||
outError = "CaptureToPng requires an initialized NativeRenderer.";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!EnsureWicFactory(outError)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::error_code errorCode = {};
|
||||
std::filesystem::create_directories(outputPath.parent_path(), errorCode);
|
||||
if (errorCode) {
|
||||
outError = "Failed to create screenshot directory: " + outputPath.parent_path().string();
|
||||
return false;
|
||||
}
|
||||
|
||||
Microsoft::WRL::ComPtr<IWICBitmap> bitmap;
|
||||
HRESULT hr = m_wicFactory->CreateBitmap(
|
||||
width,
|
||||
height,
|
||||
GUID_WICPixelFormat32bppPBGRA,
|
||||
WICBitmapCacheOnLoad,
|
||||
bitmap.ReleaseAndGetAddressOf());
|
||||
if (FAILED(hr)) {
|
||||
outError = HrToString("IWICImagingFactory::CreateBitmap", hr);
|
||||
return false;
|
||||
}
|
||||
|
||||
const D2D1_RENDER_TARGET_PROPERTIES renderTargetProperties = D2D1::RenderTargetProperties(
|
||||
D2D1_RENDER_TARGET_TYPE_DEFAULT,
|
||||
D2D1::PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_PREMULTIPLIED));
|
||||
|
||||
Microsoft::WRL::ComPtr<ID2D1RenderTarget> offscreenRenderTarget;
|
||||
hr = m_d2dFactory->CreateWicBitmapRenderTarget(
|
||||
bitmap.Get(),
|
||||
renderTargetProperties,
|
||||
offscreenRenderTarget.ReleaseAndGetAddressOf());
|
||||
if (FAILED(hr)) {
|
||||
outError = HrToString("ID2D1Factory::CreateWicBitmapRenderTarget", hr);
|
||||
return false;
|
||||
}
|
||||
|
||||
Microsoft::WRL::ComPtr<ID2D1SolidColorBrush> offscreenBrush;
|
||||
hr = offscreenRenderTarget->CreateSolidColorBrush(
|
||||
D2D1::ColorF(1.0f, 1.0f, 1.0f, 1.0f),
|
||||
offscreenBrush.ReleaseAndGetAddressOf());
|
||||
if (FAILED(hr)) {
|
||||
outError = HrToString("ID2D1RenderTarget::CreateSolidColorBrush", hr);
|
||||
return false;
|
||||
}
|
||||
|
||||
const bool rendered = RenderToTarget(*offscreenRenderTarget.Get(), *offscreenBrush.Get(), drawData);
|
||||
hr = offscreenRenderTarget->EndDraw();
|
||||
if (!rendered || FAILED(hr)) {
|
||||
outError = HrToString("ID2D1RenderTarget::EndDraw", hr);
|
||||
return false;
|
||||
}
|
||||
|
||||
const std::wstring wideOutputPath = outputPath.wstring();
|
||||
Microsoft::WRL::ComPtr<IWICStream> stream;
|
||||
hr = m_wicFactory->CreateStream(stream.ReleaseAndGetAddressOf());
|
||||
if (FAILED(hr)) {
|
||||
outError = HrToString("IWICImagingFactory::CreateStream", hr);
|
||||
return false;
|
||||
}
|
||||
|
||||
hr = stream->InitializeFromFilename(wideOutputPath.c_str(), GENERIC_WRITE);
|
||||
if (FAILED(hr)) {
|
||||
outError = HrToString("IWICStream::InitializeFromFilename", hr);
|
||||
return false;
|
||||
}
|
||||
|
||||
Microsoft::WRL::ComPtr<IWICBitmapEncoder> encoder;
|
||||
hr = m_wicFactory->CreateEncoder(GUID_ContainerFormatPng, nullptr, encoder.ReleaseAndGetAddressOf());
|
||||
if (FAILED(hr)) {
|
||||
outError = HrToString("IWICImagingFactory::CreateEncoder", hr);
|
||||
return false;
|
||||
}
|
||||
|
||||
hr = encoder->Initialize(stream.Get(), WICBitmapEncoderNoCache);
|
||||
if (FAILED(hr)) {
|
||||
outError = HrToString("IWICBitmapEncoder::Initialize", hr);
|
||||
return false;
|
||||
}
|
||||
|
||||
Microsoft::WRL::ComPtr<IWICBitmapFrameEncode> frame;
|
||||
Microsoft::WRL::ComPtr<IPropertyBag2> propertyBag;
|
||||
hr = encoder->CreateNewFrame(frame.ReleaseAndGetAddressOf(), propertyBag.ReleaseAndGetAddressOf());
|
||||
if (FAILED(hr)) {
|
||||
outError = HrToString("IWICBitmapEncoder::CreateNewFrame", hr);
|
||||
return false;
|
||||
}
|
||||
|
||||
hr = frame->Initialize(propertyBag.Get());
|
||||
if (FAILED(hr)) {
|
||||
outError = HrToString("IWICBitmapFrameEncode::Initialize", hr);
|
||||
return false;
|
||||
}
|
||||
|
||||
hr = frame->SetSize(width, height);
|
||||
if (FAILED(hr)) {
|
||||
outError = HrToString("IWICBitmapFrameEncode::SetSize", hr);
|
||||
return false;
|
||||
}
|
||||
|
||||
WICPixelFormatGUID pixelFormat = GUID_WICPixelFormat32bppPBGRA;
|
||||
hr = frame->SetPixelFormat(&pixelFormat);
|
||||
if (FAILED(hr)) {
|
||||
outError = HrToString("IWICBitmapFrameEncode::SetPixelFormat", hr);
|
||||
return false;
|
||||
}
|
||||
|
||||
hr = frame->WriteSource(bitmap.Get(), nullptr);
|
||||
if (FAILED(hr)) {
|
||||
outError = HrToString("IWICBitmapFrameEncode::WriteSource", hr);
|
||||
return false;
|
||||
}
|
||||
|
||||
hr = frame->Commit();
|
||||
if (FAILED(hr)) {
|
||||
outError = HrToString("IWICBitmapFrameEncode::Commit", hr);
|
||||
return false;
|
||||
}
|
||||
|
||||
hr = encoder->Commit();
|
||||
if (FAILED(hr)) {
|
||||
outError = HrToString("IWICBitmapEncoder::Commit", hr);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NativeRenderer::EnsureRenderTarget() {
|
||||
if (!m_hwnd || !m_d2dFactory || !m_dwriteFactory) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return CreateDeviceResources();
|
||||
}
|
||||
|
||||
bool NativeRenderer::EnsureWicFactory(std::string& outError) {
|
||||
outError.clear();
|
||||
if (m_wicFactory) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const HRESULT initHr = CoInitializeEx(nullptr, COINIT_MULTITHREADED);
|
||||
if (FAILED(initHr) && initHr != RPC_E_CHANGED_MODE) {
|
||||
outError = HrToString("CoInitializeEx", initHr);
|
||||
return false;
|
||||
}
|
||||
if (SUCCEEDED(initHr)) {
|
||||
m_wicComInitialized = true;
|
||||
}
|
||||
|
||||
const HRESULT factoryHr = CoCreateInstance(
|
||||
CLSID_WICImagingFactory,
|
||||
nullptr,
|
||||
CLSCTX_INPROC_SERVER,
|
||||
IID_PPV_ARGS(m_wicFactory.ReleaseAndGetAddressOf()));
|
||||
if (FAILED(factoryHr)) {
|
||||
outError = HrToString("CoCreateInstance(CLSID_WICImagingFactory)", factoryHr);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void NativeRenderer::DiscardRenderTarget() {
|
||||
m_solidBrush.Reset();
|
||||
m_renderTarget.Reset();
|
||||
}
|
||||
|
||||
bool NativeRenderer::CreateDeviceResources() {
|
||||
if (m_renderTarget) {
|
||||
return true;
|
||||
}
|
||||
|
||||
RECT clientRect = {};
|
||||
GetClientRect(m_hwnd, &clientRect);
|
||||
const UINT width = static_cast<UINT>((std::max)(clientRect.right - clientRect.left, 1L));
|
||||
const UINT height = static_cast<UINT>((std::max)(clientRect.bottom - clientRect.top, 1L));
|
||||
|
||||
const D2D1_RENDER_TARGET_PROPERTIES renderTargetProps = D2D1::RenderTargetProperties();
|
||||
const D2D1_HWND_RENDER_TARGET_PROPERTIES hwndProps = D2D1::HwndRenderTargetProperties(
|
||||
m_hwnd,
|
||||
D2D1::SizeU(width, height));
|
||||
|
||||
if (FAILED(m_d2dFactory->CreateHwndRenderTarget(
|
||||
renderTargetProps,
|
||||
hwndProps,
|
||||
m_renderTarget.ReleaseAndGetAddressOf()))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (FAILED(m_renderTarget->CreateSolidColorBrush(
|
||||
D2D1::ColorF(1.0f, 1.0f, 1.0f, 1.0f),
|
||||
m_solidBrush.ReleaseAndGetAddressOf()))) {
|
||||
DiscardRenderTarget();
|
||||
return false;
|
||||
}
|
||||
|
||||
m_renderTarget->SetTextAntialiasMode(D2D1_TEXT_ANTIALIAS_MODE_GRAYSCALE);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NativeRenderer::RenderToTarget(
|
||||
ID2D1RenderTarget& renderTarget,
|
||||
ID2D1SolidColorBrush& solidBrush,
|
||||
const ::XCEngine::UI::UIDrawData& drawData) {
|
||||
renderTarget.SetTextAntialiasMode(D2D1_TEXT_ANTIALIAS_MODE_GRAYSCALE);
|
||||
renderTarget.BeginDraw();
|
||||
renderTarget.Clear(D2D1::ColorF(0.04f, 0.05f, 0.06f, 1.0f));
|
||||
|
||||
std::vector<D2D1_RECT_F> clipStack = {};
|
||||
for (const ::XCEngine::UI::UIDrawList& drawList : drawData.GetDrawLists()) {
|
||||
for (const ::XCEngine::UI::UIDrawCommand& command : drawList.GetCommands()) {
|
||||
RenderCommand(renderTarget, solidBrush, command, clipStack);
|
||||
}
|
||||
}
|
||||
|
||||
while (!clipStack.empty()) {
|
||||
renderTarget.PopAxisAlignedClip();
|
||||
clipStack.pop_back();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void NativeRenderer::RenderCommand(
|
||||
ID2D1RenderTarget& renderTarget,
|
||||
ID2D1SolidColorBrush& solidBrush,
|
||||
const ::XCEngine::UI::UIDrawCommand& command,
|
||||
std::vector<D2D1_RECT_F>& clipStack) {
|
||||
solidBrush.SetColor(ToD2DColor(command.color));
|
||||
|
||||
switch (command.type) {
|
||||
case ::XCEngine::UI::UIDrawCommandType::FilledRect: {
|
||||
const D2D1_RECT_F rect = ToD2DRect(command.rect);
|
||||
if (command.rounding > 0.0f) {
|
||||
renderTarget.FillRoundedRectangle(
|
||||
D2D1::RoundedRect(rect, command.rounding, command.rounding),
|
||||
&solidBrush);
|
||||
} else {
|
||||
renderTarget.FillRectangle(rect, &solidBrush);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ::XCEngine::UI::UIDrawCommandType::FilledRectLinearGradient:
|
||||
FillLinearGradientRect(renderTarget, command);
|
||||
break;
|
||||
case ::XCEngine::UI::UIDrawCommandType::RectOutline: {
|
||||
const D2D1_RECT_F rect = ToD2DRect(command.rect);
|
||||
const float thickness = command.thickness > 0.0f ? command.thickness : 1.0f;
|
||||
if (command.rounding > 0.0f) {
|
||||
renderTarget.DrawRoundedRectangle(
|
||||
D2D1::RoundedRect(rect, command.rounding, command.rounding),
|
||||
&solidBrush,
|
||||
thickness);
|
||||
} else {
|
||||
renderTarget.DrawRectangle(rect, &solidBrush, thickness);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ::XCEngine::UI::UIDrawCommandType::Line:
|
||||
renderTarget.DrawLine(
|
||||
D2D1::Point2F(command.position.x, command.position.y),
|
||||
D2D1::Point2F(command.uvMin.x, command.uvMin.y),
|
||||
&solidBrush,
|
||||
command.thickness > 0.0f ? command.thickness : 1.0f);
|
||||
break;
|
||||
case ::XCEngine::UI::UIDrawCommandType::FilledCircle:
|
||||
if (command.radius > 0.0f) {
|
||||
renderTarget.FillEllipse(
|
||||
D2D1::Ellipse(
|
||||
D2D1::Point2F(command.position.x, command.position.y),
|
||||
command.radius,
|
||||
command.radius),
|
||||
&solidBrush);
|
||||
}
|
||||
break;
|
||||
case ::XCEngine::UI::UIDrawCommandType::CircleOutline:
|
||||
if (command.radius > 0.0f) {
|
||||
renderTarget.DrawEllipse(
|
||||
D2D1::Ellipse(
|
||||
D2D1::Point2F(command.position.x, command.position.y),
|
||||
command.radius,
|
||||
command.radius),
|
||||
&solidBrush,
|
||||
command.thickness > 0.0f ? command.thickness : 1.0f);
|
||||
}
|
||||
break;
|
||||
case ::XCEngine::UI::UIDrawCommandType::Text: {
|
||||
if (command.text.empty()) {
|
||||
break;
|
||||
}
|
||||
|
||||
const float fontSize = command.fontSize > 0.0f ? command.fontSize : 16.0f;
|
||||
IDWriteTextFormat* textFormat = GetTextFormat(fontSize);
|
||||
if (textFormat == nullptr) {
|
||||
break;
|
||||
}
|
||||
|
||||
const std::wstring text = Utf8ToWide(command.text);
|
||||
if (text.empty()) {
|
||||
break;
|
||||
}
|
||||
|
||||
const D2D1_SIZE_F targetSize = renderTarget.GetSize();
|
||||
const D2D1_RECT_F layoutRect = D2D1::RectF(
|
||||
command.position.x,
|
||||
command.position.y,
|
||||
targetSize.width,
|
||||
command.position.y + fontSize * 1.8f);
|
||||
renderTarget.DrawTextW(
|
||||
text.c_str(),
|
||||
static_cast<UINT32>(text.size()),
|
||||
textFormat,
|
||||
layoutRect,
|
||||
&solidBrush,
|
||||
D2D1_DRAW_TEXT_OPTIONS_CLIP,
|
||||
DWRITE_MEASURING_MODE_NATURAL);
|
||||
break;
|
||||
}
|
||||
case ::XCEngine::UI::UIDrawCommandType::Image: {
|
||||
if (!command.texture.IsValid()) {
|
||||
break;
|
||||
}
|
||||
|
||||
const D2D1_RECT_F rect = ToD2DRect(command.rect);
|
||||
renderTarget.DrawRectangle(rect, &solidBrush, 1.0f);
|
||||
break;
|
||||
}
|
||||
case ::XCEngine::UI::UIDrawCommandType::PushClipRect: {
|
||||
const D2D1_RECT_F rect = ToD2DRect(command.rect);
|
||||
renderTarget.PushAxisAlignedClip(rect, D2D1_ANTIALIAS_MODE_PER_PRIMITIVE);
|
||||
clipStack.push_back(rect);
|
||||
break;
|
||||
}
|
||||
case ::XCEngine::UI::UIDrawCommandType::PopClipRect: {
|
||||
if (!clipStack.empty()) {
|
||||
renderTarget.PopAxisAlignedClip();
|
||||
clipStack.pop_back();
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
IDWriteTextFormat* NativeRenderer::GetTextFormat(float fontSize) {
|
||||
if (!m_dwriteFactory) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const int key = static_cast<int>(std::lround(fontSize * 10.0f));
|
||||
const auto found = m_textFormats.find(key);
|
||||
if (found != m_textFormats.end()) {
|
||||
return found->second.Get();
|
||||
}
|
||||
|
||||
Microsoft::WRL::ComPtr<IDWriteTextFormat> textFormat;
|
||||
const HRESULT hr = m_dwriteFactory->CreateTextFormat(
|
||||
L"Segoe UI",
|
||||
nullptr,
|
||||
DWRITE_FONT_WEIGHT_REGULAR,
|
||||
DWRITE_FONT_STYLE_NORMAL,
|
||||
DWRITE_FONT_STRETCH_NORMAL,
|
||||
fontSize,
|
||||
L"",
|
||||
textFormat.ReleaseAndGetAddressOf());
|
||||
if (FAILED(hr)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
textFormat->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_LEADING);
|
||||
textFormat->SetParagraphAlignment(DWRITE_PARAGRAPH_ALIGNMENT_NEAR);
|
||||
textFormat->SetWordWrapping(DWRITE_WORD_WRAPPING_NO_WRAP);
|
||||
|
||||
IDWriteTextFormat* result = textFormat.Get();
|
||||
m_textFormats.emplace(key, std::move(textFormat));
|
||||
return result;
|
||||
}
|
||||
|
||||
D2D1_COLOR_F NativeRenderer::ToD2DColor(const ::XCEngine::UI::UIColor& color) {
|
||||
return ToD2DColorValue(color);
|
||||
}
|
||||
|
||||
std::wstring NativeRenderer::Utf8ToWide(std::string_view text) {
|
||||
if (text.empty()) {
|
||||
return {};
|
||||
}
|
||||
|
||||
const int sizeNeeded = MultiByteToWideChar(
|
||||
CP_UTF8,
|
||||
0,
|
||||
text.data(),
|
||||
static_cast<int>(text.size()),
|
||||
nullptr,
|
||||
0);
|
||||
if (sizeNeeded <= 0) {
|
||||
return {};
|
||||
}
|
||||
|
||||
std::wstring wideText(static_cast<size_t>(sizeNeeded), L'\0');
|
||||
MultiByteToWideChar(
|
||||
CP_UTF8,
|
||||
0,
|
||||
text.data(),
|
||||
static_cast<int>(text.size()),
|
||||
wideText.data(),
|
||||
sizeNeeded);
|
||||
return wideText;
|
||||
}
|
||||
|
||||
} // namespace XCEngine::Tests::CoreUI::Host
|
||||
@@ -1,65 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef NOMINMAX
|
||||
#define NOMINMAX
|
||||
#endif
|
||||
|
||||
#include <XCEngine/UI/DrawData.h>
|
||||
|
||||
#include <d2d1.h>
|
||||
#include <dwrite.h>
|
||||
#include <wincodec.h>
|
||||
#include <windows.h>
|
||||
#include <wrl/client.h>
|
||||
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
namespace XCEngine::Tests::CoreUI::Host {
|
||||
|
||||
class NativeRenderer {
|
||||
public:
|
||||
bool Initialize(HWND hwnd);
|
||||
void Shutdown();
|
||||
void Resize(UINT width, UINT height);
|
||||
bool Render(const ::XCEngine::UI::UIDrawData& drawData);
|
||||
bool CaptureToPng(
|
||||
const ::XCEngine::UI::UIDrawData& drawData,
|
||||
UINT width,
|
||||
UINT height,
|
||||
const std::filesystem::path& outputPath,
|
||||
std::string& outError);
|
||||
|
||||
private:
|
||||
bool EnsureRenderTarget();
|
||||
bool EnsureWicFactory(std::string& outError);
|
||||
void DiscardRenderTarget();
|
||||
bool CreateDeviceResources();
|
||||
bool RenderToTarget(
|
||||
ID2D1RenderTarget& renderTarget,
|
||||
ID2D1SolidColorBrush& solidBrush,
|
||||
const ::XCEngine::UI::UIDrawData& drawData);
|
||||
void RenderCommand(
|
||||
ID2D1RenderTarget& renderTarget,
|
||||
ID2D1SolidColorBrush& solidBrush,
|
||||
const ::XCEngine::UI::UIDrawCommand& command,
|
||||
std::vector<D2D1_RECT_F>& clipStack);
|
||||
|
||||
IDWriteTextFormat* GetTextFormat(float fontSize);
|
||||
static D2D1_COLOR_F ToD2DColor(const ::XCEngine::UI::UIColor& color);
|
||||
static std::wstring Utf8ToWide(std::string_view text);
|
||||
|
||||
HWND m_hwnd = nullptr;
|
||||
Microsoft::WRL::ComPtr<ID2D1Factory> m_d2dFactory;
|
||||
Microsoft::WRL::ComPtr<IDWriteFactory> m_dwriteFactory;
|
||||
Microsoft::WRL::ComPtr<IWICImagingFactory> m_wicFactory;
|
||||
Microsoft::WRL::ComPtr<ID2D1HwndRenderTarget> m_renderTarget;
|
||||
Microsoft::WRL::ComPtr<ID2D1SolidColorBrush> m_solidBrush;
|
||||
std::unordered_map<int, Microsoft::WRL::ComPtr<IDWriteTextFormat>> m_textFormats;
|
||||
bool m_wicComInitialized = false;
|
||||
};
|
||||
|
||||
} // namespace XCEngine::Tests::CoreUI::Host
|
||||
@@ -1,471 +0,0 @@
|
||||
#include "PopupMenuOverlayValidationScene.h"
|
||||
|
||||
#include <XCEngine/Input/InputTypes.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
namespace XCEngine::Tests::CoreUI {
|
||||
|
||||
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::UIInputPath;
|
||||
using ::XCEngine::UI::UIPoint;
|
||||
using ::XCEngine::UI::UIRect;
|
||||
using ::XCEngine::UI::UISize;
|
||||
using ::XCEngine::UI::Widgets::ResolvePopupPlacementRect;
|
||||
using ::XCEngine::UI::Widgets::UIPopupDismissReason;
|
||||
using ::XCEngine::UI::Widgets::UIPopupOverlayEntry;
|
||||
using ::XCEngine::UI::Widgets::UIPopupPlacement;
|
||||
|
||||
constexpr UIColor kLabPanelBg(0.12f, 0.12f, 0.12f, 1.0f);
|
||||
constexpr UIColor kLabPanelBorder(0.24f, 0.24f, 0.24f, 1.0f);
|
||||
constexpr UIColor kStatusBg(0.16f, 0.16f, 0.16f, 1.0f);
|
||||
constexpr UIColor kStatusBorder(0.28f, 0.28f, 0.28f, 1.0f);
|
||||
constexpr UIColor kControlBg(0.22f, 0.22f, 0.22f, 1.0f);
|
||||
constexpr UIColor kControlHover(0.31f, 0.31f, 0.31f, 1.0f);
|
||||
constexpr UIColor kControlDisabled(0.18f, 0.18f, 0.18f, 1.0f);
|
||||
constexpr UIColor kPopupBg(0.17f, 0.17f, 0.17f, 1.0f);
|
||||
constexpr UIColor kPopupHover(0.30f, 0.30f, 0.30f, 1.0f);
|
||||
constexpr UIColor kPopupBorder(0.38f, 0.38f, 0.38f, 1.0f);
|
||||
constexpr UIColor kScrim(0.05f, 0.05f, 0.05f, 0.48f);
|
||||
constexpr UIColor kTextPrimary(0.93f, 0.93f, 0.93f, 1.0f);
|
||||
constexpr UIColor kTextMuted(0.72f, 0.72f, 0.72f, 1.0f);
|
||||
|
||||
const UIInputPath kTriggerPath = { 10u, 11u };
|
||||
const UIInputPath kBackgroundButtonPath = { 20u, 21u };
|
||||
const UIInputPath kRootSurfacePath = { 30u, 31u };
|
||||
const UIInputPath kRootActionPath = { 30u, 31u, 32u };
|
||||
const UIInputPath kRootSubmenuPath = { 30u, 31u, 33u };
|
||||
const UIInputPath kChildSurfacePath = { 40u, 41u };
|
||||
const UIInputPath kChildActionPath = { 40u, 41u, 42u };
|
||||
|
||||
std::string DescribePath(const UIInputPath& path) {
|
||||
if (path == kTriggerPath) {
|
||||
return "Open Menu";
|
||||
}
|
||||
if (path == kBackgroundButtonPath) {
|
||||
return "Background Button";
|
||||
}
|
||||
if (path == kRootActionPath) {
|
||||
return "Root Action";
|
||||
}
|
||||
if (path == kRootSubmenuPath) {
|
||||
return "Open Submenu";
|
||||
}
|
||||
if (path == kRootSurfacePath) {
|
||||
return "Root Popup Surface";
|
||||
}
|
||||
if (path == kChildActionPath) {
|
||||
return "Leaf Action";
|
||||
}
|
||||
if (path == kChildSurfacePath) {
|
||||
return "Child Popup Surface";
|
||||
}
|
||||
return "Overlay Blank";
|
||||
}
|
||||
|
||||
void DrawPanel(
|
||||
UIDrawList& drawList,
|
||||
const UIRect& rect,
|
||||
const UIColor& fillColor,
|
||||
const UIColor& borderColor,
|
||||
float rounding) {
|
||||
drawList.AddFilledRect(rect, fillColor, rounding);
|
||||
drawList.AddRectOutline(rect, borderColor, 1.0f, rounding);
|
||||
}
|
||||
|
||||
void DrawLabel(
|
||||
UIDrawList& drawList,
|
||||
const UIRect& rect,
|
||||
std::string text,
|
||||
const UIColor& textColor,
|
||||
float fontSize = 13.0f) {
|
||||
drawList.AddText(
|
||||
UIPoint(rect.x + 12.0f, rect.y + 10.0f),
|
||||
std::move(text),
|
||||
textColor,
|
||||
fontSize);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void PopupMenuOverlayValidationScene::Reset() {
|
||||
m_popupModel = {};
|
||||
m_pointerPosition = {};
|
||||
m_hasPointer = false;
|
||||
m_backgroundClickCount = 0;
|
||||
m_resultText = "Result: Ready";
|
||||
}
|
||||
|
||||
void PopupMenuOverlayValidationScene::Update(
|
||||
const std::vector<UIInputEvent>& events,
|
||||
const UIRect& viewportRect,
|
||||
bool windowFocused) {
|
||||
(void)windowFocused;
|
||||
const Geometry geometry = BuildGeometry(viewportRect);
|
||||
|
||||
for (const UIInputEvent& event : events) {
|
||||
switch (event.type) {
|
||||
case UIInputEventType::PointerMove:
|
||||
m_pointerPosition = event.position;
|
||||
m_hasPointer = true;
|
||||
HandlePointerHover(geometry, event.position);
|
||||
break;
|
||||
case UIInputEventType::PointerLeave:
|
||||
m_hasPointer = false;
|
||||
break;
|
||||
case UIInputEventType::PointerButtonDown:
|
||||
if (event.pointerButton == ::XCEngine::UI::UIPointerButton::Left) {
|
||||
m_pointerPosition = event.position;
|
||||
m_hasPointer = true;
|
||||
HandlePointerDown(geometry, event.position);
|
||||
}
|
||||
break;
|
||||
case UIInputEventType::KeyDown:
|
||||
if (event.keyCode == static_cast<std::int32_t>(KeyCode::Escape)) {
|
||||
HandleEscapeKey();
|
||||
}
|
||||
break;
|
||||
case UIInputEventType::FocusLost: {
|
||||
const auto dismissResult = m_popupModel.DismissFromFocusLoss({});
|
||||
if (dismissResult.changed) {
|
||||
SetResult("Result: window focus lost, popup chain closed");
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PopupMenuOverlayValidationScene::AppendDrawData(
|
||||
UIDrawData& drawData,
|
||||
const UIRect& viewportRect) const {
|
||||
const Geometry geometry = BuildGeometry(viewportRect);
|
||||
const UIInputPath hoverPath =
|
||||
m_hasPointer ? HitTest(geometry, m_pointerPosition) : UIInputPath();
|
||||
|
||||
UIDrawList& drawList = drawData.EmplaceDrawList("Core Popup Menu Overlay Lab");
|
||||
DrawPanel(drawList, geometry.labRect, kLabPanelBg, kLabPanelBorder, 12.0f);
|
||||
DrawPanel(drawList, geometry.backgroundButtonRect, kControlBg, kStatusBorder, 8.0f);
|
||||
DrawLabel(
|
||||
drawList,
|
||||
geometry.backgroundButtonRect,
|
||||
"Background Button",
|
||||
!HasOpenPopups() && hoverPath == kBackgroundButtonPath ? kTextPrimary : kTextMuted);
|
||||
|
||||
if (HasOpenPopups()) {
|
||||
drawList.AddFilledRect(geometry.labRect, kScrim, 12.0f);
|
||||
}
|
||||
|
||||
DrawPanel(drawList, geometry.statusRect, kStatusBg, kStatusBorder, 10.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(geometry.statusRect.x + 12.0f, geometry.statusRect.y + 10.0f),
|
||||
"测试内容:Core Popup / Menu Overlay Primitive",
|
||||
kTextPrimary,
|
||||
14.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(geometry.statusRect.x + 12.0f, geometry.statusRect.y + 32.0f),
|
||||
m_resultText,
|
||||
kTextMuted,
|
||||
12.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(geometry.statusRect.x + 12.0f, geometry.statusRect.y + 50.0f),
|
||||
"Popup Chain: " + FormatPopupChain(),
|
||||
kTextMuted,
|
||||
12.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(geometry.statusRect.x + 320.0f, geometry.statusRect.y + 32.0f),
|
||||
"Hover: " + DescribeHoverTarget(geometry),
|
||||
kTextMuted,
|
||||
12.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(geometry.statusRect.x + 320.0f, geometry.statusRect.y + 50.0f),
|
||||
"Background Hits: " + std::to_string(m_backgroundClickCount),
|
||||
kTextMuted,
|
||||
12.0f);
|
||||
|
||||
const UIColor triggerColor =
|
||||
hoverPath == kTriggerPath ? kControlHover : kControlBg;
|
||||
DrawPanel(drawList, geometry.triggerRect, triggerColor, kStatusBorder, 8.0f);
|
||||
DrawLabel(drawList, geometry.triggerRect, "Open Menu", kTextPrimary);
|
||||
|
||||
if (IsRootOpen()) {
|
||||
DrawPanel(drawList, geometry.rootPopupRect, kPopupBg, kPopupBorder, 10.0f);
|
||||
|
||||
const UIColor rootActionColor =
|
||||
hoverPath == kRootActionPath ? kPopupHover : kPopupBg;
|
||||
DrawPanel(drawList, geometry.rootActionRect, rootActionColor, kStatusBorder, 8.0f);
|
||||
DrawLabel(drawList, geometry.rootActionRect, "Root Action", kTextPrimary);
|
||||
|
||||
const UIColor submenuColor =
|
||||
hoverPath == kRootSubmenuPath || hoverPath == kChildSurfacePath || hoverPath == kChildActionPath
|
||||
? kPopupHover
|
||||
: kPopupBg;
|
||||
DrawPanel(drawList, geometry.rootSubmenuRect, submenuColor, kStatusBorder, 8.0f);
|
||||
DrawLabel(drawList, geometry.rootSubmenuRect, "Open Submenu >", kTextPrimary);
|
||||
}
|
||||
|
||||
if (IsSubmenuOpen()) {
|
||||
DrawPanel(drawList, geometry.childPopupRect, kPopupBg, kPopupBorder, 10.0f);
|
||||
const UIColor childActionColor =
|
||||
hoverPath == kChildActionPath ? kPopupHover : kPopupBg;
|
||||
DrawPanel(drawList, geometry.childActionRect, childActionColor, kStatusBorder, 8.0f);
|
||||
DrawLabel(drawList, geometry.childActionRect, "Leaf Action", kTextPrimary);
|
||||
}
|
||||
}
|
||||
|
||||
PopupMenuOverlayValidationScene::Geometry PopupMenuOverlayValidationScene::BuildGeometry(
|
||||
const UIRect& viewportRect) const {
|
||||
Geometry geometry = {};
|
||||
|
||||
const float availableWidth = (std::max)(280.0f, viewportRect.width - 48.0f);
|
||||
const float availableHeight = (std::max)(280.0f, viewportRect.height - 244.0f);
|
||||
geometry.labRect = UIRect(
|
||||
24.0f,
|
||||
220.0f,
|
||||
(std::min)(760.0f, availableWidth),
|
||||
(std::min)(380.0f, availableHeight));
|
||||
|
||||
geometry.statusRect = UIRect(
|
||||
geometry.labRect.x + 20.0f,
|
||||
geometry.labRect.y + 20.0f,
|
||||
geometry.labRect.width - 40.0f,
|
||||
78.0f);
|
||||
geometry.triggerRect = UIRect(
|
||||
geometry.labRect.x + 20.0f,
|
||||
geometry.statusRect.y + geometry.statusRect.height + 18.0f,
|
||||
126.0f,
|
||||
40.0f);
|
||||
geometry.backgroundButtonRect = UIRect(
|
||||
geometry.labRect.x + geometry.labRect.width - 220.0f,
|
||||
geometry.labRect.y + geometry.labRect.height - 64.0f,
|
||||
180.0f,
|
||||
40.0f);
|
||||
|
||||
const auto rootPlacement = ResolvePopupPlacementRect(
|
||||
geometry.triggerRect,
|
||||
UISize(220.0f, 112.0f),
|
||||
geometry.labRect,
|
||||
UIPopupPlacement::BottomStart);
|
||||
geometry.rootPopupRect = rootPlacement.rect;
|
||||
geometry.rootActionRect = UIRect(
|
||||
geometry.rootPopupRect.x + 10.0f,
|
||||
geometry.rootPopupRect.y + 10.0f,
|
||||
geometry.rootPopupRect.width - 20.0f,
|
||||
40.0f);
|
||||
geometry.rootSubmenuRect = UIRect(
|
||||
geometry.rootPopupRect.x + 10.0f,
|
||||
geometry.rootPopupRect.y + 58.0f,
|
||||
geometry.rootPopupRect.width - 20.0f,
|
||||
40.0f);
|
||||
|
||||
const auto childPlacement = ResolvePopupPlacementRect(
|
||||
geometry.rootSubmenuRect,
|
||||
UISize(180.0f, 60.0f),
|
||||
geometry.labRect,
|
||||
UIPopupPlacement::RightStart);
|
||||
geometry.childPopupRect = childPlacement.rect;
|
||||
geometry.childActionRect = UIRect(
|
||||
geometry.childPopupRect.x + 10.0f,
|
||||
geometry.childPopupRect.y + 10.0f,
|
||||
geometry.childPopupRect.width - 20.0f,
|
||||
40.0f);
|
||||
return geometry;
|
||||
}
|
||||
|
||||
UIInputPath PopupMenuOverlayValidationScene::HitTest(
|
||||
const Geometry& geometry,
|
||||
const UIPoint& position) const {
|
||||
if (IsSubmenuOpen()) {
|
||||
if (RectContains(geometry.childActionRect, position)) {
|
||||
return kChildActionPath;
|
||||
}
|
||||
if (RectContains(geometry.childPopupRect, position)) {
|
||||
return kChildSurfacePath;
|
||||
}
|
||||
}
|
||||
|
||||
if (IsRootOpen()) {
|
||||
if (RectContains(geometry.rootActionRect, position)) {
|
||||
return kRootActionPath;
|
||||
}
|
||||
if (RectContains(geometry.rootSubmenuRect, position)) {
|
||||
return kRootSubmenuPath;
|
||||
}
|
||||
if (RectContains(geometry.rootPopupRect, position)) {
|
||||
return kRootSurfacePath;
|
||||
}
|
||||
}
|
||||
|
||||
if (RectContains(geometry.triggerRect, position)) {
|
||||
return kTriggerPath;
|
||||
}
|
||||
|
||||
if (!HasOpenPopups() && RectContains(geometry.backgroundButtonRect, position)) {
|
||||
return kBackgroundButtonPath;
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
void PopupMenuOverlayValidationScene::HandlePointerDown(
|
||||
const Geometry& geometry,
|
||||
const UIPoint& position) {
|
||||
const UIInputPath hitPath = HitTest(geometry, position);
|
||||
if (hitPath == kTriggerPath) {
|
||||
if (IsRootOpen()) {
|
||||
m_popupModel.CloseAll(UIPopupDismissReason::Programmatic);
|
||||
SetResult("Result: root popup closed");
|
||||
} else {
|
||||
OpenRootPopup(geometry);
|
||||
SetResult("Result: root popup opened");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (hitPath == kRootActionPath) {
|
||||
m_popupModel.CloseAll(UIPopupDismissReason::Programmatic);
|
||||
SetResult("Result: Root Action dispatched");
|
||||
return;
|
||||
}
|
||||
|
||||
if (hitPath == kRootSubmenuPath) {
|
||||
if (!IsSubmenuOpen()) {
|
||||
OpenSubmenuPopup(geometry);
|
||||
SetResult("Result: submenu opened");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (hitPath == kChildActionPath) {
|
||||
m_popupModel.CloseAll(UIPopupDismissReason::Programmatic);
|
||||
SetResult("Result: Leaf Action dispatched");
|
||||
return;
|
||||
}
|
||||
|
||||
const auto dismissResult = m_popupModel.DismissFromPointerDown(hitPath);
|
||||
if (dismissResult.changed) {
|
||||
if (dismissResult.closedPopupIds.size() == 1u &&
|
||||
dismissResult.closedPopupIds.front() == "submenu") {
|
||||
SetResult("Result: click stayed in root popup, submenu closed");
|
||||
} else {
|
||||
SetResult("Result: click hit overlay blank, popup chain closed");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (hitPath == kBackgroundButtonPath) {
|
||||
++m_backgroundClickCount;
|
||||
SetResult("Result: Background Button dispatched #" + std::to_string(m_backgroundClickCount));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void PopupMenuOverlayValidationScene::HandlePointerHover(
|
||||
const Geometry& geometry,
|
||||
const UIPoint& position) {
|
||||
const UIInputPath hitPath = HitTest(geometry, position);
|
||||
if (!IsRootOpen()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (hitPath == kRootSubmenuPath && !IsSubmenuOpen()) {
|
||||
OpenSubmenuPopup(geometry);
|
||||
SetResult("Result: submenu opened by hover");
|
||||
return;
|
||||
}
|
||||
|
||||
if (hitPath == kRootActionPath && IsSubmenuOpen()) {
|
||||
m_popupModel.ClosePopup("submenu", UIPopupDismissReason::Programmatic);
|
||||
SetResult("Result: submenu collapsed by hover");
|
||||
}
|
||||
}
|
||||
|
||||
void PopupMenuOverlayValidationScene::HandleEscapeKey() {
|
||||
const auto dismissResult = m_popupModel.DismissFromEscape();
|
||||
if (dismissResult.changed) {
|
||||
SetResult("Result: Escape closed topmost popup");
|
||||
}
|
||||
}
|
||||
|
||||
void PopupMenuOverlayValidationScene::OpenRootPopup(const Geometry& geometry) {
|
||||
UIPopupOverlayEntry entry = {};
|
||||
entry.popupId = "root";
|
||||
entry.anchorRect = geometry.triggerRect;
|
||||
entry.anchorPath = kTriggerPath;
|
||||
entry.surfacePath = kRootSurfacePath;
|
||||
entry.placement = UIPopupPlacement::BottomStart;
|
||||
m_popupModel.OpenPopup(std::move(entry));
|
||||
}
|
||||
|
||||
void PopupMenuOverlayValidationScene::OpenSubmenuPopup(const Geometry& geometry) {
|
||||
UIPopupOverlayEntry entry = {};
|
||||
entry.popupId = "submenu";
|
||||
entry.parentPopupId = "root";
|
||||
entry.anchorRect = geometry.rootSubmenuRect;
|
||||
entry.anchorPath = kRootSubmenuPath;
|
||||
entry.surfacePath = kChildSurfacePath;
|
||||
entry.placement = UIPopupPlacement::RightStart;
|
||||
m_popupModel.OpenPopup(std::move(entry));
|
||||
}
|
||||
|
||||
void PopupMenuOverlayValidationScene::SetResult(std::string text) {
|
||||
m_resultText = std::move(text);
|
||||
}
|
||||
|
||||
std::string PopupMenuOverlayValidationScene::FormatPopupChain() const {
|
||||
if (!HasOpenPopups()) {
|
||||
return "(empty)";
|
||||
}
|
||||
|
||||
std::string chain = {};
|
||||
const auto& popups = m_popupModel.GetPopupChain();
|
||||
for (std::size_t index = 0; index < popups.size(); ++index) {
|
||||
if (!chain.empty()) {
|
||||
chain += " > ";
|
||||
}
|
||||
chain += popups[index].popupId;
|
||||
}
|
||||
return chain;
|
||||
}
|
||||
|
||||
std::string PopupMenuOverlayValidationScene::DescribeHoverTarget(const Geometry& geometry) const {
|
||||
if (!m_hasPointer) {
|
||||
return "(none)";
|
||||
}
|
||||
|
||||
return DescribePath(HitTest(geometry, m_pointerPosition));
|
||||
}
|
||||
|
||||
bool PopupMenuOverlayValidationScene::HasOpenPopups() const {
|
||||
return m_popupModel.HasOpenPopups();
|
||||
}
|
||||
|
||||
bool PopupMenuOverlayValidationScene::IsRootOpen() const {
|
||||
return m_popupModel.FindPopup("root") != nullptr;
|
||||
}
|
||||
|
||||
bool PopupMenuOverlayValidationScene::IsSubmenuOpen() const {
|
||||
return m_popupModel.FindPopup("submenu") != nullptr;
|
||||
}
|
||||
|
||||
bool PopupMenuOverlayValidationScene::RectContains(
|
||||
const UIRect& rect,
|
||||
const UIPoint& position) {
|
||||
return position.x >= rect.x &&
|
||||
position.x <= rect.x + rect.width &&
|
||||
position.y >= rect.y &&
|
||||
position.y <= rect.y + rect.height;
|
||||
}
|
||||
|
||||
} // namespace XCEngine::Tests::CoreUI
|
||||
@@ -1,69 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <XCEngine/UI/DrawData.h>
|
||||
#include <XCEngine/UI/Widgets/UIPopupOverlayModel.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace XCEngine::Tests::CoreUI {
|
||||
|
||||
class PopupMenuOverlayValidationScene {
|
||||
public:
|
||||
static constexpr const char* ScenarioId = "core.input.popup_menu_overlay";
|
||||
|
||||
void Reset();
|
||||
void Update(
|
||||
const std::vector<::XCEngine::UI::UIInputEvent>& events,
|
||||
const ::XCEngine::UI::UIRect& viewportRect,
|
||||
bool windowFocused);
|
||||
void AppendDrawData(
|
||||
::XCEngine::UI::UIDrawData& drawData,
|
||||
const ::XCEngine::UI::UIRect& viewportRect) const;
|
||||
|
||||
private:
|
||||
struct Geometry {
|
||||
::XCEngine::UI::UIRect labRect = {};
|
||||
::XCEngine::UI::UIRect statusRect = {};
|
||||
::XCEngine::UI::UIRect triggerRect = {};
|
||||
::XCEngine::UI::UIRect backgroundButtonRect = {};
|
||||
::XCEngine::UI::UIRect rootPopupRect = {};
|
||||
::XCEngine::UI::UIRect rootActionRect = {};
|
||||
::XCEngine::UI::UIRect rootSubmenuRect = {};
|
||||
::XCEngine::UI::UIRect childPopupRect = {};
|
||||
::XCEngine::UI::UIRect childActionRect = {};
|
||||
};
|
||||
|
||||
Geometry BuildGeometry(const ::XCEngine::UI::UIRect& viewportRect) const;
|
||||
::XCEngine::UI::UIInputPath HitTest(
|
||||
const Geometry& geometry,
|
||||
const ::XCEngine::UI::UIPoint& position) const;
|
||||
void HandlePointerDown(
|
||||
const Geometry& geometry,
|
||||
const ::XCEngine::UI::UIPoint& position);
|
||||
void HandlePointerHover(
|
||||
const Geometry& geometry,
|
||||
const ::XCEngine::UI::UIPoint& position);
|
||||
void HandleEscapeKey();
|
||||
void OpenRootPopup(const Geometry& geometry);
|
||||
void OpenSubmenuPopup(const Geometry& geometry);
|
||||
void SetResult(std::string text);
|
||||
std::string FormatPopupChain() const;
|
||||
std::string DescribeHoverTarget(const Geometry& geometry) const;
|
||||
bool HasOpenPopups() const;
|
||||
bool IsRootOpen() const;
|
||||
bool IsSubmenuOpen() const;
|
||||
|
||||
static bool RectContains(
|
||||
const ::XCEngine::UI::UIRect& rect,
|
||||
const ::XCEngine::UI::UIPoint& position);
|
||||
|
||||
::XCEngine::UI::Widgets::UIPopupOverlayModel m_popupModel = {};
|
||||
::XCEngine::UI::UIPoint m_pointerPosition = {};
|
||||
bool m_hasPointer = false;
|
||||
std::uint32_t m_backgroundClickCount = 0;
|
||||
std::string m_resultText = "Result: Ready";
|
||||
};
|
||||
|
||||
} // namespace XCEngine::Tests::CoreUI
|
||||
@@ -1,65 +0,0 @@
|
||||
<Theme name="CoreValidationTheme">
|
||||
<Tokens>
|
||||
<Color name="color.bg.workspace" value="#1C1C1C" />
|
||||
<Color name="color.bg.panel" value="#292929" />
|
||||
<Color name="color.bg.accent" value="#3A3A3A" />
|
||||
<Color name="color.bg.selection" value="#4A4A4A" />
|
||||
<Color name="color.style.warm" value="#4A3426" />
|
||||
<Color name="color.style.cool" value="#243C4C" />
|
||||
<Color name="color.style.borderWarm" value="#D0925B" />
|
||||
<Color name="color.style.borderCool" value="#6BA3C7" />
|
||||
<Color name="color.style.buttonAccent" value="#4B5E7B" />
|
||||
<Color name="color.text.primary" value="#EEEEEE" />
|
||||
<Color name="color.text.muted" value="#B0B0B0" />
|
||||
<Spacing name="space.panel" value="12" />
|
||||
<Spacing name="space.shell" value="18" />
|
||||
<Spacing name="space.loose" value="18" />
|
||||
<Radius name="radius.panel" value="10" />
|
||||
<Radius name="radius.control" value="8" />
|
||||
<Radius name="radius.loose" value="16" />
|
||||
</Tokens>
|
||||
|
||||
<Widgets>
|
||||
<Widget type="View" style="CoreWorkspace">
|
||||
<Property name="background" value="color.bg.workspace" />
|
||||
<Property name="padding" value="space.shell" />
|
||||
</Widget>
|
||||
|
||||
<Widget type="Card" style="CorePanel">
|
||||
<Property name="background" value="color.bg.panel" />
|
||||
<Property name="radius" value="radius.panel" />
|
||||
<Property name="padding" value="space.panel" />
|
||||
</Widget>
|
||||
|
||||
<Widget type="Card" style="CoreStyleWarmCard">
|
||||
<Property name="background" value="color.style.warm" />
|
||||
<Property name="borderColor" value="color.style.borderWarm" />
|
||||
<Property name="borderWidth" value="1" />
|
||||
<Property name="padding" value="space.loose" />
|
||||
<Property name="radius" value="radius.loose" />
|
||||
</Widget>
|
||||
|
||||
<Widget type="Card" style="CoreStyleCoolCard">
|
||||
<Property name="background" value="color.style.cool" />
|
||||
<Property name="borderColor" value="color.style.borderCool" />
|
||||
<Property name="borderWidth" value="1" />
|
||||
<Property name="padding" value="space.loose" />
|
||||
<Property name="radius" value="radius.loose" />
|
||||
</Widget>
|
||||
|
||||
<Widget type="Button" style="CoreChip">
|
||||
<Property name="background" value="color.bg.selection" />
|
||||
<Property name="radius" value="radius.control" />
|
||||
</Widget>
|
||||
|
||||
<Widget type="Button" style="CoreStyleAccentButton">
|
||||
<Property name="background" value="color.style.buttonAccent" />
|
||||
<Property name="radius" value="radius.control" />
|
||||
</Widget>
|
||||
|
||||
<Widget type="Text" style="CoreTextMuted">
|
||||
<Property name="foreground" value="color.text.muted" />
|
||||
<Property name="fontSize" value="14" />
|
||||
</Widget>
|
||||
</Widgets>
|
||||
</Theme>
|
||||
@@ -1,6 +0,0 @@
|
||||
add_subdirectory(theme_tokens)
|
||||
|
||||
add_custom_target(core_ui_style_integration_tests
|
||||
DEPENDS
|
||||
core_ui_style_theme_tokens_validation
|
||||
)
|
||||
@@ -1,35 +0,0 @@
|
||||
set(CORE_UI_STYLE_THEME_TOKENS_RESOURCES
|
||||
View.xcui
|
||||
${CMAKE_SOURCE_DIR}/tests/UI/Core/integration/shared/themes/core_validation.xctheme
|
||||
)
|
||||
|
||||
add_executable(core_ui_style_theme_tokens_validation WIN32
|
||||
main.cpp
|
||||
${CORE_UI_STYLE_THEME_TOKENS_RESOURCES}
|
||||
)
|
||||
|
||||
target_include_directories(core_ui_style_theme_tokens_validation PRIVATE
|
||||
${CMAKE_SOURCE_DIR}/tests/UI/Core/integration/shared/src
|
||||
${CMAKE_SOURCE_DIR}/engine/include
|
||||
)
|
||||
|
||||
target_compile_definitions(core_ui_style_theme_tokens_validation PRIVATE
|
||||
UNICODE
|
||||
_UNICODE
|
||||
)
|
||||
|
||||
if(MSVC)
|
||||
target_compile_options(core_ui_style_theme_tokens_validation PRIVATE /utf-8 /FS)
|
||||
set_property(TARGET core_ui_style_theme_tokens_validation PROPERTY
|
||||
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
|
||||
endif()
|
||||
|
||||
target_link_libraries(core_ui_style_theme_tokens_validation PRIVATE
|
||||
core_ui_integration_host
|
||||
)
|
||||
|
||||
set_target_properties(core_ui_style_theme_tokens_validation PROPERTIES
|
||||
OUTPUT_NAME "XCUICoreStyleThemeTokensValidation"
|
||||
)
|
||||
|
||||
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}" FILES View.xcui)
|
||||
@@ -1,50 +0,0 @@
|
||||
<View
|
||||
name="CoreStyleThemeTokens"
|
||||
theme="../../shared/themes/core_validation.xctheme"
|
||||
style="CoreWorkspace">
|
||||
<Column padding="24" gap="16">
|
||||
<Card
|
||||
title="测试内容:Core Style 主题 Token 与样式优先级"
|
||||
subtitle="只验证 shared theme / named style / inline override;不验证上层业务面板"
|
||||
tone="accent"
|
||||
height="108">
|
||||
<Column gap="8">
|
||||
<Text text="1. 检查下面三张卡片的背景、边框、圆角是否明显不同。" />
|
||||
<Text text="2. Named Style Warm / Cool 应直接体现主题 Token;Inline Override 应覆盖同名样式的背景色。" />
|
||||
<Text text="3. 下方 Accent Button 应明显区别于默认按钮,用来确认 widget named style 已生效。" />
|
||||
</Column>
|
||||
</Card>
|
||||
|
||||
<Column gap="12">
|
||||
<Card id="style-warm-card" style="CoreStyleWarmCard" title="Named Style Warm" subtitle="theme named style" height="112">
|
||||
<Column gap="6">
|
||||
<Text text="预期:暖色背景 + 暖色边框 + 较大的 padding。" />
|
||||
</Column>
|
||||
</Card>
|
||||
|
||||
<Card id="style-cool-card" style="CoreStyleCoolCard" title="Named Style Cool" subtitle="theme named style" height="112">
|
||||
<Column gap="6">
|
||||
<Text text="预期:冷色背景 + 冷色边框;应与 Warm 卡片明显区分。" />
|
||||
</Column>
|
||||
</Card>
|
||||
|
||||
<Card
|
||||
id="style-inline-card"
|
||||
style="CoreStyleWarmCard"
|
||||
background="#6B4A2D"
|
||||
borderColor="#D8A56B"
|
||||
title="Inline Override"
|
||||
subtitle="inline background overrides named style"
|
||||
height="112">
|
||||
<Column gap="6">
|
||||
<Text text="预期:仍保留 Warm 卡片结构,但背景和边框应以 inline 值为准。" />
|
||||
</Column>
|
||||
</Card>
|
||||
</Column>
|
||||
|
||||
<Row gap="12">
|
||||
<Button id="style-default-button" text="Default Button" />
|
||||
<Button id="style-accent-button" style="CoreStyleAccentButton" text="Accent Button" />
|
||||
</Row>
|
||||
</Column>
|
||||
</View>
|
||||
@@ -1,8 +0,0 @@
|
||||
#include "Application.h"
|
||||
|
||||
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, LPWSTR, int nCmdShow) {
|
||||
return XCEngine::Tests::CoreUI::RunCoreUIValidationApp(
|
||||
hInstance,
|
||||
nCmdShow,
|
||||
"core.style.theme_tokens");
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
add_subdirectory(utf8_focus_surface)
|
||||
|
||||
add_custom_target(core_ui_text_integration_tests
|
||||
DEPENDS
|
||||
core_ui_text_utf8_focus_surface_validation
|
||||
)
|
||||
@@ -1,35 +0,0 @@
|
||||
set(CORE_UI_TEXT_UTF8_FOCUS_SURFACE_RESOURCES
|
||||
View.xcui
|
||||
${CMAKE_SOURCE_DIR}/tests/UI/Core/integration/shared/themes/core_validation.xctheme
|
||||
)
|
||||
|
||||
add_executable(core_ui_text_utf8_focus_surface_validation WIN32
|
||||
main.cpp
|
||||
${CORE_UI_TEXT_UTF8_FOCUS_SURFACE_RESOURCES}
|
||||
)
|
||||
|
||||
target_include_directories(core_ui_text_utf8_focus_surface_validation PRIVATE
|
||||
${CMAKE_SOURCE_DIR}/tests/UI/Core/integration/shared/src
|
||||
${CMAKE_SOURCE_DIR}/engine/include
|
||||
)
|
||||
|
||||
target_compile_definitions(core_ui_text_utf8_focus_surface_validation PRIVATE
|
||||
UNICODE
|
||||
_UNICODE
|
||||
)
|
||||
|
||||
if(MSVC)
|
||||
target_compile_options(core_ui_text_utf8_focus_surface_validation PRIVATE /utf-8 /FS)
|
||||
set_property(TARGET core_ui_text_utf8_focus_surface_validation PROPERTY
|
||||
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
|
||||
endif()
|
||||
|
||||
target_link_libraries(core_ui_text_utf8_focus_surface_validation PRIVATE
|
||||
core_ui_integration_host
|
||||
)
|
||||
|
||||
set_target_properties(core_ui_text_utf8_focus_surface_validation PROPERTIES
|
||||
OUTPUT_NAME "XCUICoreTextUtf8FocusSurfaceValidation"
|
||||
)
|
||||
|
||||
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}" FILES View.xcui)
|
||||
@@ -1,43 +0,0 @@
|
||||
<View
|
||||
name="CoreTextUtf8FocusSurface"
|
||||
theme="../../shared/themes/core_validation.xctheme"
|
||||
style="CoreWorkspace">
|
||||
<Column padding="24" gap="16">
|
||||
<Card
|
||||
title="测试内容:Core Text UTF-8 渲染与 textInput 焦点面"
|
||||
subtitle="只验证共享文本渲染、字号差异和 textInput focus 标记;不伪造完整输入框"
|
||||
tone="accent"
|
||||
height="108">
|
||||
<Column gap="8">
|
||||
<Text text="1. 检查下面的 UTF-8 文本是否正常显示,不应出现乱码或错位。" />
|
||||
<Text text="2. 按 Tab 把 focus 切到中间的 Text Input Surface,右下角 Text input 应变为 active。" />
|
||||
<Text text="3. 再按 Tab / Shift+Tab 离开时,Text input 应恢复为 idle。" />
|
||||
</Column>
|
||||
</Card>
|
||||
|
||||
<Card title="UTF-8 Rendering" subtitle="shared text drawing only" height="144">
|
||||
<Column gap="8">
|
||||
<Text text="English / 中文 / UTF-8 / Delete / Backspace" />
|
||||
<Text fontSize="20" text="大字号文本:删除键 Delete 与 Backspace 现在应分离。" />
|
||||
<Text style="CoreTextMuted" text="多语言混排检查:层级、布局、主题、文本。" />
|
||||
</Column>
|
||||
</Card>
|
||||
|
||||
<Button id="text-focus-before" text="Focus Before" />
|
||||
|
||||
<Card
|
||||
id="text-input-surface"
|
||||
title="Text Input Surface"
|
||||
subtitle="focusable + textInput marker"
|
||||
focusable="true"
|
||||
textInput="true"
|
||||
height="132">
|
||||
<Column gap="8">
|
||||
<Text text="这个面板本身不是完整输入框,只用于验证 textInput focus 标记链路。" />
|
||||
<Text text="当 focus 停在这里时,右下角 Text input 应显示 active。" />
|
||||
</Column>
|
||||
</Card>
|
||||
|
||||
<Button id="text-focus-after" text="Focus After" />
|
||||
</Column>
|
||||
</View>
|
||||
@@ -1,8 +0,0 @@
|
||||
#include "Application.h"
|
||||
|
||||
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, LPWSTR, int nCmdShow) {
|
||||
return XCEngine::Tests::CoreUI::RunCoreUIValidationApp(
|
||||
hInstance,
|
||||
nCmdShow,
|
||||
"core.text.utf8_focus_surface");
|
||||
}
|
||||
Reference in New Issue
Block a user