Sync editor rendering and UI workspace updates

This commit is contained in:
2026-04-09 02:59:36 +08:00
parent 23b23a56be
commit d46bf87970
107 changed files with 10918 additions and 430 deletions

View File

@@ -37,6 +37,58 @@ TEST(UISelectionModelTest, ToggleSelectionSelectsAndDeselectsMatchingId) {
EXPECT_EQ(selection.GetSelectedId(), "treeMaterials");
EXPECT_TRUE(selection.ToggleSelection("treeUi"));
EXPECT_EQ(selection.GetSelectedId(), "treeUi");
ASSERT_EQ(selection.GetSelectedIds().size(), 1u);
EXPECT_EQ(selection.GetSelectedIds()[0], "treeUi");
}
TEST(UISelectionModelTest, MultiSelectionTracksMembershipAndPrimarySelection) {
UISelectionModel selection = {};
EXPECT_TRUE(selection.AddSelection("scene", true));
EXPECT_TRUE(selection.AddSelection("camera"));
EXPECT_TRUE(selection.AddSelection("lights"));
EXPECT_EQ(selection.GetSelectionCount(), 3u);
EXPECT_TRUE(selection.HasMultipleSelection());
EXPECT_TRUE(selection.IsSelected("scene"));
EXPECT_TRUE(selection.IsSelected("camera"));
EXPECT_TRUE(selection.IsSelected("lights"));
EXPECT_EQ(selection.GetSelectedId(), "scene");
EXPECT_TRUE(selection.SetPrimarySelection("lights"));
EXPECT_EQ(selection.GetSelectedId(), "lights");
EXPECT_FALSE(selection.SetPrimarySelection("missing"));
}
TEST(UISelectionModelTest, SetSelectionsNormalizesDuplicatesAndKeepsRequestedPrimary) {
UISelectionModel selection = {};
EXPECT_TRUE(selection.SetSelections(
{ "", "camera", "lights", "camera", "sun" },
"lights"));
ASSERT_EQ(selection.GetSelectedIds().size(), 3u);
EXPECT_EQ(selection.GetSelectedIds()[0], "camera");
EXPECT_EQ(selection.GetSelectedIds()[1], "lights");
EXPECT_EQ(selection.GetSelectedIds()[2], "sun");
EXPECT_EQ(selection.GetSelectedId(), "lights");
EXPECT_TRUE(selection.SetSelections({ "camera", "sun" }));
EXPECT_EQ(selection.GetSelectedId(), "sun");
}
TEST(UISelectionModelTest, RemovingPrimaryFallsBackToMostRecentlyAddedRemainingItem) {
UISelectionModel selection = {};
EXPECT_TRUE(selection.SetSelections({ "scene", "camera", "lights" }, "camera"));
EXPECT_TRUE(selection.RemoveSelection("camera"));
EXPECT_TRUE(selection.IsSelected("scene"));
EXPECT_TRUE(selection.IsSelected("lights"));
EXPECT_FALSE(selection.IsSelected("camera"));
EXPECT_EQ(selection.GetSelectedId(), "lights");
EXPECT_TRUE(selection.RemoveSelection("lights"));
EXPECT_EQ(selection.GetSelectedId(), "scene");
EXPECT_TRUE(selection.RemoveSelection("scene"));
EXPECT_FALSE(selection.HasSelection());
}
} // namespace

View File

@@ -53,6 +53,11 @@ if(TARGET editor_ui_tree_view_basic_validation)
editor_ui_tree_view_basic_validation)
endif()
if(TARGET editor_ui_tree_view_multiselect_validation)
list(APPEND EDITOR_UI_INTEGRATION_TARGETS
editor_ui_tree_view_multiselect_validation)
endif()
if(TARGET editor_ui_property_grid_basic_validation)
list(APPEND EDITOR_UI_INTEGRATION_TARGETS
editor_ui_property_grid_basic_validation)
@@ -98,6 +103,16 @@ if(TARGET editor_ui_list_view_basic_validation)
editor_ui_list_view_basic_validation)
endif()
if(TARGET editor_ui_list_view_multiselect_validation)
list(APPEND EDITOR_UI_INTEGRATION_TARGETS
editor_ui_list_view_multiselect_validation)
endif()
if(TARGET editor_ui_list_view_inline_rename_validation)
list(APPEND EDITOR_UI_INTEGRATION_TARGETS
editor_ui_list_view_inline_rename_validation)
endif()
add_custom_target(editor_ui_integration_tests
DEPENDS
${EDITOR_UI_INTEGRATION_TARGETS}

View File

@@ -29,7 +29,10 @@ Layout:
- `shell/enum_field_basic/`: EnumField previous/next switch, keyboard switch, hover/focus/selection feedback only
- `shell/status_bar_basic/`: status bar slot/segment/hit-test only
- `shell/tree_view_basic/`: TreeView row layout, indent, disclosure, selection, focus, hit-test only
- `shell/tree_view_multiselect/`: TreeView multi-selection contract only
- `shell/list_view_basic/`: ListView row layout, selection, focus, keyboard navigation, hit-test only
- `shell/list_view_multiselect/`: ListView multi-selection contract only
- `shell/list_view_inline_rename/`: ListView inline rename/edit session only
- `shell/tab_strip_basic/`: tab strip layout/state/hit-test/close/navigation only
- `shell/viewport_slot_basic/`: viewport slot chrome/surface/status only
- `shell/viewport_shell_basic/`: viewport shell request/state compose only
@@ -118,11 +121,31 @@ Scenarios:
Executable: `XCUIEditorTreeViewBasicValidation.exe`
Scope: TreeView 基础控件验证只检查行缩进、disclosure 展开/折叠、selection、hover/focus 和 hit-test不涉及业务面板
- `editor.shell.tree_view_multiselect`
Build target: `editor_ui_tree_view_multiselect_validation`
Executable: `XCUIEditorTreeViewMultiSelectValidation.exe`
Scope: TreeView 多选契约验证;只检查 Ctrl/Shift 多选、锚点、右键命中已选集合、键盘范围扩选、expanded/visible/current 同步,不涉及业务面板
- `editor.shell.tree_view_inline_rename`
Build target: `editor_ui_tree_view_inline_rename_validation`
Executable: `XCUIEditorTreeViewInlineRenameValidation.exe`
Scope: TreeView inline rename 契约验证;只检查 F2 开启、字符编辑、Enter 提交、Esc 取消、点击外部结束编辑,以及标签写回
- `editor.shell.list_view_basic`
Build target: `editor_ui_list_view_basic_validation`
Executable: `XCUIEditorListViewBasicValidation.exe`
Scope: ListView 基础控件验证;只检查 row 排列、selection、hover/focus、Up/Down/Home/End 键盘导航和 hit-test不涉及业务面板
- `editor.shell.list_view_multiselect`
Build target: `editor_ui_list_view_multiselect_validation`
Executable: `XCUIEditorListViewMultiSelectValidation.exe`
Scope: ListView 多选契约验证;只检查 Ctrl/Shift 多选、锚点、右键命中已选集合、键盘范围扩选、current/primary 同步,不涉及业务面板
- `editor.shell.list_view_inline_rename`
Build target: `editor_ui_list_view_inline_rename_validation`
Executable: `XCUIEditorListViewInlineRenameValidation.exe`
Scope: ListView inline rename 契约验证;只检查 F2 开启、字符编辑、Enter 提交、Esc 取消、点击外部结束编辑,以及标签写回
- `editor.shell.tab_strip_basic`
Build target: `editor_ui_tab_strip_basic_validation`
Executable: `XCUIEditorTabStripBasicValidation.exe`
@@ -225,8 +248,20 @@ Selected controls:
- `shell/tree_view_basic/`
先看顶部中文说明“这个测试在验证什么功能”,再点击 disclosure 和树节点行,检查 `Hover / Focused / Selected / Expanded / Visible / Result`,按 `重置``截图(F12)` 或直接按 `F12`
- `shell/tree_view_multiselect/`
先看顶部中文说明“这个测试在验证什么功能”,再分别执行 `单击``Ctrl+单击``Shift+单击``Shift+Up/Down/Home/End``Right Click`,检查 `Primary / Selected Count / Selected Ids / Anchor / Current / Expanded / Visible / Result`
- `shell/tree_view_inline_rename/`
先看顶部中文说明“这个测试在验证什么功能”,再依次执行 `单击``F2`、输入字符、`Enter / Esc / 点击外部`,检查 `Rename Active / Rename Item / Draft / Committed / Result`
- `shell/list_view_basic/`
先看顶部中文说明“这个测试在验证什么功能”,再点击列表行,并在列表获得 focus 后按 `Up / Down / Home / End`,检查 `Hover / Focused / Selected / Current / Result`,按 `重置``截图(F12)` 或直接按 `F12`
- `shell/list_view_multiselect/`
先看顶部中文说明“这个测试在验证什么功能”,再分别执行 `单击``Ctrl+单击``Shift+单击``Shift+Up/Down/Home/End``Right Click`,检查 `Primary / Selected Count / Selected Ids / Anchor / Current / Result`
- `shell/list_view_inline_rename/`
先看顶部中文说明“这个测试在验证什么功能”,再依次执行 `单击``F2`、输入字符、`Enter / Esc / 点击外部`,检查 `Rename Active / Rename Item / Draft / Committed / Result`
- `shell/tab_strip_basic/`
Click `Document A / B / C`, click `X` on closable tabs, click content to focus, press `Left / Right / Home / End`, press `Reset`, press `F12`.

Binary file not shown.

After

Width:  |  Height:  |  Size: 84 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 84 KiB

View File

@@ -2,8 +2,8 @@
#define NOMINMAX
#endif
#include <XCEditor/Core/UIEditorListViewInteraction.h>
#include <XCEditor/Widgets/UIEditorListView.h>
#include <XCEditor/Collections/UIEditorListView.h>
#include <XCEditor/Collections/UIEditorListViewInteraction.h>
#include "Host/AutoScreenshot.h"
#include "Host/NativeRenderer.h"

View File

@@ -0,0 +1,31 @@
add_executable(editor_ui_list_view_inline_rename_validation WIN32
main.cpp
)
target_include_directories(editor_ui_list_view_inline_rename_validation PRIVATE
${CMAKE_SOURCE_DIR}/new_editor/include
${CMAKE_SOURCE_DIR}/new_editor/app
${CMAKE_SOURCE_DIR}/engine/include
${CMAKE_SOURCE_DIR}/tests/UI/Editor/integration/shared/src
)
target_compile_definitions(editor_ui_list_view_inline_rename_validation PRIVATE
UNICODE
_UNICODE
XCENGINE_EDITOR_UI_TESTS_REPO_ROOT="${XCENGINE_EDITOR_UI_TESTS_REPO_ROOT_PATH}"
)
if(MSVC)
target_compile_options(editor_ui_list_view_inline_rename_validation PRIVATE /utf-8 /FS)
set_property(TARGET editor_ui_list_view_inline_rename_validation PROPERTY
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
endif()
target_link_libraries(editor_ui_list_view_inline_rename_validation PRIVATE
XCUIEditorLib
XCUIEditorHost
)
set_target_properties(editor_ui_list_view_inline_rename_validation PROPERTIES
OUTPUT_NAME "XCUIEditorListViewInlineRenameValidation"
)

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,31 @@
add_executable(editor_ui_list_view_multiselect_validation WIN32
main.cpp
)
target_include_directories(editor_ui_list_view_multiselect_validation PRIVATE
${CMAKE_SOURCE_DIR}/tests/UI/Editor/integration/shared/src
${CMAKE_SOURCE_DIR}/new_editor/include
${CMAKE_SOURCE_DIR}/new_editor/app
${CMAKE_SOURCE_DIR}/engine/include
)
target_compile_definitions(editor_ui_list_view_multiselect_validation PRIVATE
UNICODE
_UNICODE
XCENGINE_EDITOR_UI_TESTS_REPO_ROOT="${XCENGINE_EDITOR_UI_TESTS_REPO_ROOT_PATH}"
)
if(MSVC)
target_compile_options(editor_ui_list_view_multiselect_validation PRIVATE /utf-8 /FS)
set_property(TARGET editor_ui_list_view_multiselect_validation PROPERTY
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
endif()
target_link_libraries(editor_ui_list_view_multiselect_validation PRIVATE
XCUIEditorLib
XCUIEditorHost
)
set_target_properties(editor_ui_list_view_multiselect_validation PROPERTIES
OUTPUT_NAME "XCUIEditorListViewMultiSelectValidation"
)

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

View File

@@ -0,0 +1,901 @@
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <XCEditor/Collections/UIEditorListView.h>
#include <XCEditor/Collections/UIEditorListViewInteraction.h>
#include "EditorValidationTheme.h"
#include "Host/AutoScreenshot.h"
#include "Host/InputModifierTracker.h"
#include "Host/NativeRenderer.h"
#include <XCEngine/Input/InputTypes.h>
#include <XCEngine/UI/DrawData.h>
#include <XCEngine/UI/Style/Theme.h>
#include <XCEngine/UI/Widgets/UISelectionModel.h>
#include <windows.h>
#include <windowsx.h>
#include <algorithm>
#include <cstdint>
#include <filesystem>
#include <sstream>
#include <string>
#include <string_view>
#include <utility>
#include <vector>
#ifndef XCENGINE_EDITOR_UI_TESTS_REPO_ROOT
#define XCENGINE_EDITOR_UI_TESTS_REPO_ROOT "."
#endif
namespace {
using XCEngine::Input::KeyCode;
using XCEngine::Tests::EditorUI::EditorValidationShellMetrics;
using XCEngine::Tests::EditorUI::EditorValidationShellPalette;
using XCEngine::UI::UIDrawData;
using XCEngine::UI::UIDrawList;
using XCEngine::UI::UIInputEvent;
using XCEngine::UI::UIInputEventType;
using XCEngine::UI::UIInputModifiers;
using XCEngine::UI::UIPoint;
using XCEngine::UI::UIPointerButton;
using XCEngine::UI::UIRect;
using XCEngine::UI::Widgets::UISelectionModel;
using XCEngine::UI::Editor::Host::AutoScreenshotController;
using XCEngine::UI::Editor::Host::InputModifierTracker;
using XCEngine::UI::Editor::Host::NativeRenderer;
using XCEngine::UI::Editor::UIEditorListViewInteractionFrame;
using XCEngine::UI::Editor::UIEditorListViewInteractionResult;
using XCEngine::UI::Editor::UIEditorListViewInteractionState;
using XCEngine::UI::Editor::UpdateUIEditorListViewInteraction;
using XCEngine::UI::Editor::Widgets::AppendUIEditorListViewBackground;
using XCEngine::UI::Editor::Widgets::AppendUIEditorListViewForeground;
using XCEngine::UI::Editor::Widgets::HitTestUIEditorListView;
using XCEngine::UI::Editor::Widgets::UIEditorListViewHitTarget;
using XCEngine::UI::Editor::Widgets::UIEditorListViewItem;
namespace Style = XCEngine::UI::Style;
constexpr const wchar_t* kWindowClassName = L"XCUIEditorListViewMultiSelectValidation";
constexpr const wchar_t* kWindowTitle = L"XCUI Editor | ListView MultiSelect";
enum class ActionId : unsigned char {
Reset = 0,
Capture
};
struct ButtonLayout {
ActionId action = ActionId::Reset;
const char* label = "";
UIRect rect = {};
};
struct ScenarioLayout {
UIRect introRect = {};
UIRect controlRect = {};
UIRect stateRect = {};
UIRect previewRect = {};
UIRect listRect = {};
std::vector<ButtonLayout> buttons = {};
};
std::filesystem::path ResolveRepoRootPath() {
std::string root = XCENGINE_EDITOR_UI_TESTS_REPO_ROOT;
if (root.size() >= 2u && root.front() == '"' && root.back() == '"') {
root = root.substr(1u, root.size() - 2u);
}
return std::filesystem::path(root).lexically_normal();
}
std::filesystem::path ResolveValidationThemePath() {
return (ResolveRepoRootPath() / "tests/UI/Editor/integration/shared/themes/editor_validation.xctheme")
.lexically_normal();
}
bool ContainsPoint(const UIRect& rect, float x, float y) {
return x >= rect.x &&
x <= rect.x + rect.width &&
y >= rect.y &&
y <= rect.y + rect.height;
}
std::int32_t MapListNavigationKey(UINT keyCode) {
switch (keyCode) {
case VK_UP:
return static_cast<std::int32_t>(KeyCode::Up);
case VK_DOWN:
return static_cast<std::int32_t>(KeyCode::Down);
case VK_HOME:
return static_cast<std::int32_t>(KeyCode::Home);
case VK_END:
return static_cast<std::int32_t>(KeyCode::End);
default:
return static_cast<std::int32_t>(KeyCode::None);
}
}
ScenarioLayout BuildScenarioLayout(
float width,
float height,
const EditorValidationShellMetrics& shellMetrics) {
const float margin = shellMetrics.margin;
constexpr float leftWidth = 470.0f;
const float gap = shellMetrics.gap;
ScenarioLayout layout = {};
layout.introRect = UIRect(margin, margin, leftWidth, 252.0f);
layout.controlRect = UIRect(margin, layout.introRect.y + layout.introRect.height + gap, leftWidth, 84.0f);
layout.stateRect = UIRect(
margin,
layout.controlRect.y + layout.controlRect.height + gap,
leftWidth,
(std::max)(260.0f, height - (layout.controlRect.y + layout.controlRect.height + gap) - margin));
layout.previewRect = UIRect(
leftWidth + margin * 2.0f,
margin,
(std::max)(520.0f, width - leftWidth - margin * 3.0f),
height - margin * 2.0f);
layout.listRect = UIRect(
layout.previewRect.x + 22.0f,
layout.previewRect.y + 72.0f,
layout.previewRect.width - 44.0f,
layout.previewRect.height - 104.0f);
const float buttonWidth = (layout.controlRect.width - 44.0f) * 0.5f;
const float buttonY = layout.controlRect.y + 32.0f;
layout.buttons = {
{ ActionId::Reset, "重置", UIRect(layout.controlRect.x + 14.0f, buttonY, buttonWidth, 36.0f) },
{ ActionId::Capture, "截图(F12)", UIRect(layout.controlRect.x + 26.0f + buttonWidth, buttonY, buttonWidth, 36.0f) }
};
return layout;
}
void DrawCard(
UIDrawList& drawList,
const UIRect& rect,
const EditorValidationShellPalette& shellPalette,
const EditorValidationShellMetrics& shellMetrics,
std::string_view title,
std::string_view subtitle = {}) {
drawList.AddFilledRect(rect, shellPalette.cardBackground, shellMetrics.cardRadius);
drawList.AddRectOutline(rect, shellPalette.cardBorder, 1.0f, shellMetrics.cardRadius);
drawList.AddText(
UIPoint(rect.x + 16.0f, rect.y + 14.0f),
std::string(title),
shellPalette.textPrimary,
shellMetrics.titleFontSize);
if (!subtitle.empty()) {
drawList.AddText(
UIPoint(rect.x + 16.0f, rect.y + 40.0f),
std::string(subtitle),
shellPalette.textMuted,
shellMetrics.bodyFontSize);
}
}
void DrawButton(
UIDrawList& drawList,
const ButtonLayout& button,
const EditorValidationShellPalette& shellPalette,
const EditorValidationShellMetrics& shellMetrics,
bool hovered) {
drawList.AddFilledRect(
button.rect,
hovered ? shellPalette.buttonHoverBackground : shellPalette.buttonBackground,
shellMetrics.buttonRadius);
drawList.AddRectOutline(button.rect, shellPalette.cardBorder, 1.0f, shellMetrics.buttonRadius);
drawList.AddText(
UIPoint(button.rect.x + 16.0f, button.rect.y + 10.0f),
button.label,
shellPalette.textPrimary,
shellMetrics.bodyFontSize);
}
std::vector<UIEditorListViewItem> BuildListItems() {
return {
{ "scene", "SampleScene.unity", "Scene | 4 分钟前修改", 0.0f },
{ "lighting", "LightingProfile.asset", "Preset | 3 个 profile", 0.0f },
{ "material", "RobotBody.mat", "Material | Metallic Workflow", 0.0f },
{ "script", "PlayerController.cs", "C# Script | 3.4 KB", 0.0f },
{ "texture", "Checker_AO.png", "Texture2D | 2048x2048", 0.0f },
{ "prefab", "Robot.prefab", "Prefab | 9 个组件", 0.0f },
{ "anim", "Walk.anim", "Animation Clip | 1.2 s", 0.0f },
{ "shader", "Outline.shader", "Shader | URP compatible", 0.0f },
{ "mesh", "Robot.fbx", "Model | 38k triangles", 0.0f },
{ "audio", "FactoryLoop.wav", "AudioClip | 44.1 kHz", 0.0f },
{ "timeline", "IntroPlayable.playable", "Timeline | 7 tracks", 0.0f },
{ "profile", "GameplayProfile.asset", "Volume Profile | 6 overrides", 0.0f }
};
}
std::string JoinSelectedIds(const UISelectionModel& selectionModel) {
const std::vector<std::string>& selectedIds = selectionModel.GetSelectedIds();
if (selectedIds.empty()) {
return "(none)";
}
std::ostringstream stream = {};
for (std::size_t index = 0u; index < selectedIds.size(); ++index) {
if (index > 0u) {
stream << " | ";
}
stream << selectedIds[index];
}
return stream.str();
}
std::string DescribeHitTarget(
const UIEditorListViewHitTarget& hitTarget,
const std::vector<UIEditorListViewItem>& items) {
if (hitTarget.itemIndex >= items.size()) {
return "(none)";
}
return "row: " + items[hitTarget.itemIndex].primaryText;
}
std::string DescribeModifiers(const UIInputModifiers& modifiers) {
std::ostringstream stream = {};
stream << "Ctrl " << (modifiers.control ? "on" : "off")
<< " | Shift " << (modifiers.shift ? "on" : "off")
<< " | Alt " << (modifiers.alt ? "on" : "off");
return stream.str();
}
UIInputEvent MakePointerEvent(
UIInputEventType type,
const UIPoint& position,
const UIInputModifiers& modifiers,
UIPointerButton button = UIPointerButton::None) {
UIInputEvent event = {};
event.type = type;
event.position = position;
event.pointerButton = button;
event.modifiers = modifiers;
return event;
}
UIInputEvent MakeKeyEvent(
std::int32_t keyCode,
const UIInputModifiers& modifiers) {
UIInputEvent event = {};
event.type = UIInputEventType::KeyDown;
event.keyCode = keyCode;
event.modifiers = modifiers;
return event;
}
class ScenarioApp {
public:
int Run(HINSTANCE hInstance, int nCmdShow) {
if (!Initialize(hInstance, nCmdShow)) {
Shutdown();
return 1;
}
MSG message = {};
while (message.message != WM_QUIT) {
if (PeekMessageW(&message, nullptr, 0U, 0U, PM_REMOVE)) {
TranslateMessage(&message);
DispatchMessageW(&message);
continue;
}
RenderFrame();
Sleep(8);
}
Shutdown();
return static_cast<int>(message.wParam);
}
private:
static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
if (message == WM_NCCREATE) {
const auto* createStruct = reinterpret_cast<CREATESTRUCTW*>(lParam);
auto* app = 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->OnResize(static_cast<UINT>(LOWORD(lParam)), static_cast<UINT>(HIWORD(lParam)));
}
return 0;
case WM_MOUSEMOVE:
if (app != nullptr) {
app->HandleMouseMove(
static_cast<float>(GET_X_LPARAM(lParam)),
static_cast<float>(GET_Y_LPARAM(lParam)),
static_cast<std::size_t>(wParam));
return 0;
}
break;
case WM_MOUSELEAVE:
if (app != nullptr) {
app->HandleMouseLeave();
return 0;
}
break;
case WM_LBUTTONDOWN:
if (app != nullptr) {
app->HandleLeftButtonDown(
static_cast<float>(GET_X_LPARAM(lParam)),
static_cast<float>(GET_Y_LPARAM(lParam)),
static_cast<std::size_t>(wParam));
return 0;
}
break;
case WM_LBUTTONUP:
if (app != nullptr) {
app->HandleLeftButtonUp(
static_cast<float>(GET_X_LPARAM(lParam)),
static_cast<float>(GET_Y_LPARAM(lParam)),
static_cast<std::size_t>(wParam));
return 0;
}
break;
case WM_RBUTTONDOWN:
if (app != nullptr) {
app->HandleRightButtonDown(
static_cast<float>(GET_X_LPARAM(lParam)),
static_cast<float>(GET_Y_LPARAM(lParam)),
static_cast<std::size_t>(wParam));
return 0;
}
break;
case WM_RBUTTONUP:
if (app != nullptr) {
app->HandleRightButtonUp(
static_cast<float>(GET_X_LPARAM(lParam)),
static_cast<float>(GET_Y_LPARAM(lParam)),
static_cast<std::size_t>(wParam));
return 0;
}
break;
case WM_KEYDOWN:
case WM_SYSKEYDOWN:
if (app != nullptr) {
app->HandleKeyDown(wParam, lParam);
return 0;
}
break;
case WM_KEYUP:
case WM_SYSKEYUP:
if (app != nullptr) {
app->HandleKeyUp(wParam, lParam);
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,
1540,
940,
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_captureRoot =
ResolveRepoRootPath() / "tests/UI/Editor/integration/shell/list_view_multiselect/captures";
m_autoScreenshot.Initialize(m_captureRoot);
const auto themeLoad =
XCEngine::Tests::EditorUI::LoadEditorValidationTheme(ResolveValidationThemePath());
if (themeLoad.succeeded) {
m_theme = themeLoad.theme;
m_themeStatus = "loaded";
} else {
m_themeStatus = themeLoad.error.empty() ? "fallback" : themeLoad.error;
}
m_modifierTracker.SyncFromSystemState();
ResetScenario();
return true;
}
void Shutdown() {
m_autoScreenshot.Shutdown();
m_renderer.Shutdown();
if (m_hwnd != nullptr && IsWindow(m_hwnd)) {
DestroyWindow(m_hwnd);
}
m_hwnd = nullptr;
if (m_windowClassAtom != 0) {
UnregisterClassW(kWindowClassName, GetModuleHandleW(nullptr));
m_windowClassAtom = 0;
}
}
ScenarioLayout GetLayout() const {
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));
return BuildScenarioLayout(
width,
height,
XCEngine::Tests::EditorUI::ResolveEditorValidationShellMetrics(m_theme));
}
void ResetScenario() {
m_items = BuildListItems();
m_selectionModel = {};
m_selectionModel.SetSelections({ "material", "script" }, "script");
m_interactionState = {};
m_interactionState.listViewState.focused = true;
m_mousePosition = UIPoint(-1000.0f, -1000.0f);
m_hasHoveredAction = false;
m_hoveredAction = ActionId::Reset;
m_lastModifiers = {};
m_lastResult = "已重置到默认多选状态";
RefreshFrame();
}
void RefreshFrame() {
if (m_hwnd == nullptr) {
return;
}
const ScenarioLayout layout = GetLayout();
m_frame = UpdateUIEditorListViewInteraction(
m_interactionState,
m_selectionModel,
layout.listRect,
m_items,
{});
}
void OnResize(UINT width, UINT height) {
if (width == 0u || height == 0u) {
return;
}
m_renderer.Resize(width, height);
RefreshFrame();
}
void HandleMouseMove(float x, float y, std::size_t keyState) {
m_modifierTracker.SyncFromSystemState();
m_mousePosition = UIPoint(x, y);
const ScenarioLayout layout = GetLayout();
UpdateHoveredAction(layout, x, y);
TRACKMOUSEEVENT trackEvent = {};
trackEvent.cbSize = sizeof(trackEvent);
trackEvent.dwFlags = TME_LEAVE;
trackEvent.hwndTrack = m_hwnd;
TrackMouseEvent(&trackEvent);
const UIInputModifiers modifiers = m_modifierTracker.BuildPointerModifiers(keyState);
m_lastModifiers = modifiers;
PumpEvents({ MakePointerEvent(UIInputEventType::PointerMove, m_mousePosition, modifiers) });
InvalidateRect(m_hwnd, nullptr, FALSE);
}
void HandleMouseLeave() {
m_mousePosition = UIPoint(-1000.0f, -1000.0f);
m_hasHoveredAction = false;
PumpEvents({ MakePointerEvent(UIInputEventType::PointerLeave, m_mousePosition, {}) });
InvalidateRect(m_hwnd, nullptr, FALSE);
}
void HandleLeftButtonDown(float x, float y, std::size_t keyState) {
m_modifierTracker.SyncFromSystemState();
m_mousePosition = UIPoint(x, y);
const ScenarioLayout layout = GetLayout();
if (HitTestAction(layout, x, y) != nullptr) {
UpdateHoveredAction(layout, x, y);
InvalidateRect(m_hwnd, nullptr, FALSE);
return;
}
const UIInputModifiers modifiers = m_modifierTracker.BuildPointerModifiers(keyState);
m_lastModifiers = modifiers;
PumpEvents({ MakePointerEvent(UIInputEventType::PointerButtonDown, m_mousePosition, modifiers, UIPointerButton::Left) });
InvalidateRect(m_hwnd, nullptr, FALSE);
}
void HandleLeftButtonUp(float x, float y, std::size_t keyState) {
m_modifierTracker.SyncFromSystemState();
m_mousePosition = UIPoint(x, y);
const ScenarioLayout layout = GetLayout();
const ButtonLayout* button = HitTestAction(layout, x, y);
if (button != nullptr) {
ExecuteAction(button->action);
UpdateHoveredAction(layout, x, y);
InvalidateRect(m_hwnd, nullptr, FALSE);
return;
}
const bool insideList = ContainsPoint(layout.listRect, x, y);
const bool wasFocused = m_interactionState.listViewState.focused;
const UIInputModifiers modifiers = m_modifierTracker.BuildPointerModifiers(keyState);
m_lastModifiers = modifiers;
const UIEditorListViewInteractionResult result =
PumpEvents({ MakePointerEvent(UIInputEventType::PointerButtonUp, m_mousePosition, modifiers, UIPointerButton::Left) });
UpdateResultText(result, insideList, wasFocused);
InvalidateRect(m_hwnd, nullptr, FALSE);
}
void HandleRightButtonDown(float x, float y, std::size_t keyState) {
m_modifierTracker.SyncFromSystemState();
m_mousePosition = UIPoint(x, y);
const UIInputModifiers modifiers = m_modifierTracker.BuildPointerModifiers(keyState);
m_lastModifiers = modifiers;
PumpEvents({ MakePointerEvent(UIInputEventType::PointerButtonDown, m_mousePosition, modifiers, UIPointerButton::Right) });
InvalidateRect(m_hwnd, nullptr, FALSE);
}
void HandleRightButtonUp(float x, float y, std::size_t keyState) {
m_modifierTracker.SyncFromSystemState();
m_mousePosition = UIPoint(x, y);
const UIInputModifiers modifiers = m_modifierTracker.BuildPointerModifiers(keyState);
m_lastModifiers = modifiers;
const UIEditorListViewInteractionResult result =
PumpEvents({ MakePointerEvent(UIInputEventType::PointerButtonUp, m_mousePosition, modifiers, UIPointerButton::Right) });
UpdateResultText(result, true, m_interactionState.listViewState.focused);
InvalidateRect(m_hwnd, nullptr, FALSE);
}
void HandleKeyDown(WPARAM wParam, LPARAM lParam) {
const UIInputModifiers modifiers = m_modifierTracker.ApplyKeyMessage(UIInputEventType::KeyDown, wParam, lParam);
m_lastModifiers = modifiers;
if (wParam == VK_F12) {
m_autoScreenshot.RequestCapture("manual_f12");
m_lastResult = "已请求截图,输出到 captures/latest.png";
InvalidateRect(m_hwnd, nullptr, FALSE);
return;
}
const std::int32_t keyCode = MapListNavigationKey(static_cast<UINT>(wParam));
if (keyCode == static_cast<std::int32_t>(KeyCode::None)) {
return;
}
const UIEditorListViewInteractionResult result =
PumpEvents({ MakeKeyEvent(keyCode, modifiers) });
UpdateResultText(result, true, true);
InvalidateRect(m_hwnd, nullptr, FALSE);
}
void HandleKeyUp(WPARAM wParam, LPARAM lParam) {
m_lastModifiers = m_modifierTracker.ApplyKeyMessage(UIInputEventType::KeyUp, wParam, lParam);
InvalidateRect(m_hwnd, nullptr, FALSE);
}
void UpdateHoveredAction(const ScenarioLayout& layout, float x, float y) {
const ButtonLayout* button = HitTestAction(layout, x, y);
if (button == nullptr) {
m_hasHoveredAction = false;
return;
}
m_hoveredAction = button->action;
m_hasHoveredAction = true;
}
const ButtonLayout* HitTestAction(const ScenarioLayout& layout, float x, float y) const {
for (const ButtonLayout& button : layout.buttons) {
if (ContainsPoint(button.rect, x, y)) {
return &button;
}
}
return nullptr;
}
UIEditorListViewInteractionResult PumpEvents(std::vector<UIInputEvent> events) {
const ScenarioLayout layout = GetLayout();
m_frame = UpdateUIEditorListViewInteraction(
m_interactionState,
m_selectionModel,
layout.listRect,
m_items,
std::move(events));
return m_frame.result;
}
void UpdateResultText(
const UIEditorListViewInteractionResult& result,
bool insideList,
bool wasFocused) {
if (result.secondaryClicked && !result.selectedItemId.empty()) {
m_lastResult =
"右键命中: " + result.selectedItemId +
" | primary=" + m_selectionModel.GetSelectedId() +
" | count=" + std::to_string(m_selectionModel.GetSelectionCount());
return;
}
if (result.keyboardNavigated && result.selectionChanged) {
m_lastResult = "键盘导航更新选集: " + JoinSelectedIds(m_selectionModel);
return;
}
if (result.keyboardNavigated && !result.selectedItemId.empty()) {
m_lastResult = "键盘导航到: " + result.selectedItemId;
return;
}
if (result.selectionChanged) {
m_lastResult =
"选集已更新: primary=" + m_selectionModel.GetSelectedId() +
" | ids=" + JoinSelectedIds(m_selectionModel);
return;
}
if (!insideList && wasFocused && !m_interactionState.listViewState.focused) {
m_lastResult = "点击列表外空白focus 已清除selection 保留";
return;
}
if (insideList) {
m_lastResult = "点击列表内空白,只更新 hover / focus";
return;
}
m_lastResult = "等待交互";
}
void ExecuteAction(ActionId action) {
switch (action) {
case ActionId::Reset:
ResetScenario();
break;
case ActionId::Capture:
m_autoScreenshot.RequestCapture("manual_button");
m_lastResult = "已请求截图,输出到 captures/latest.png";
break;
}
}
void RenderFrame() {
if (m_hwnd == nullptr) {
return;
}
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 auto shellMetrics = XCEngine::Tests::EditorUI::ResolveEditorValidationShellMetrics(m_theme);
const auto shellPalette = XCEngine::Tests::EditorUI::ResolveEditorValidationShellPalette(m_theme);
const ScenarioLayout layout = BuildScenarioLayout(width, height, shellMetrics);
RefreshFrame();
const UIEditorListViewHitTarget currentHit =
HitTestUIEditorListView(m_frame.layout, m_mousePosition);
UIDrawData drawData = {};
UIDrawList& drawList = drawData.EmplaceDrawList("EditorListViewMultiSelect");
drawList.AddFilledRect(UIRect(0.0f, 0.0f, width, height), shellPalette.windowBackground);
DrawCard(
drawList,
layout.introRect,
shellPalette,
shellMetrics,
"这个测试在验证什么功能?",
"只验证 Editor ListView 多选 contractCtrl/Shift 选集、右键 primary 切换、键盘范围扩展,不涉及任何业务面板。");
drawList.AddText(
UIPoint(layout.introRect.x + 16.0f, layout.introRect.y + 72.0f),
"1. Ctrl+左键:对单行做 add/remove多选集合必须稳定保留。",
shellPalette.textPrimary,
shellMetrics.bodyFontSize);
drawList.AddText(
UIPoint(layout.introRect.x + 16.0f, layout.introRect.y + 94.0f),
"2. Shift+左键:以 anchor 为起点扩展范围primary 应切到当前点击行。",
shellPalette.textPrimary,
shellMetrics.bodyFontSize);
drawList.AddText(
UIPoint(layout.introRect.x + 16.0f, layout.introRect.y + 116.0f),
"3. 右键命中已选集合:只切换 primary/context target不应破坏当前多选集合。",
shellPalette.textPrimary,
shellMetrics.bodyFontSize);
drawList.AddText(
UIPoint(layout.introRect.x + 16.0f, layout.introRect.y + 138.0f),
"4. 列表获得 focus 后按 Up/Down/Home/End按住 Shift 时应扩展范围,不按 Shift 时应回到单选。",
shellPalette.textPrimary,
shellMetrics.bodyFontSize);
drawList.AddText(
UIPoint(layout.introRect.x + 16.0f, layout.introRect.y + 160.0f),
"5. 点击列表外空白只清除 focus点击列表内空白只更新 hover/focusF12 或按钮触发截图。",
shellPalette.textPrimary,
shellMetrics.bodyFontSize);
DrawCard(drawList, layout.controlRect, shellPalette, shellMetrics, "操作");
for (const ButtonLayout& button : layout.buttons) {
DrawButton(
drawList,
button,
shellPalette,
shellMetrics,
m_hasHoveredAction && m_hoveredAction == button.action);
}
DrawCard(
drawList,
layout.stateRect,
shellPalette,
shellMetrics,
"状态摘要",
"重点检查 primary / count / ids / anchor / current / hit / result。");
drawList.AddText(
UIPoint(layout.stateRect.x + 16.0f, layout.stateRect.y + 70.0f),
"Hover: " + DescribeHitTarget(currentHit, m_items),
shellPalette.textPrimary,
shellMetrics.bodyFontSize);
drawList.AddText(
UIPoint(layout.stateRect.x + 16.0f, layout.stateRect.y + 94.0f),
std::string("Focused: ") + (m_interactionState.listViewState.focused ? "on" : "off"),
shellPalette.textPrimary,
shellMetrics.bodyFontSize);
drawList.AddText(
UIPoint(layout.stateRect.x + 16.0f, layout.stateRect.y + 118.0f),
"Primary Selected: " +
(m_selectionModel.HasSelection() ? m_selectionModel.GetSelectedId() : std::string("(none)")),
shellPalette.textPrimary,
shellMetrics.bodyFontSize);
drawList.AddText(
UIPoint(layout.stateRect.x + 16.0f, layout.stateRect.y + 142.0f),
"Selected Count: " + std::to_string(m_selectionModel.GetSelectionCount()),
shellPalette.textPrimary,
shellMetrics.bodyFontSize);
drawList.AddText(
UIPoint(layout.stateRect.x + 16.0f, layout.stateRect.y + 166.0f),
"Selected IDs: " + JoinSelectedIds(m_selectionModel),
shellPalette.textPrimary,
shellMetrics.bodyFontSize);
drawList.AddText(
UIPoint(layout.stateRect.x + 16.0f, layout.stateRect.y + 190.0f),
"Anchor ID: " + (m_interactionState.selectionAnchorId.empty()
? std::string("(none)")
: m_interactionState.selectionAnchorId),
shellPalette.textPrimary,
shellMetrics.bodyFontSize);
drawList.AddText(
UIPoint(layout.stateRect.x + 16.0f, layout.stateRect.y + 214.0f),
std::string("Current: ") +
(m_interactionState.keyboardNavigation.HasCurrentIndex()
? std::to_string(m_interactionState.keyboardNavigation.GetCurrentIndex())
: std::string("(none)")),
shellPalette.textPrimary,
shellMetrics.bodyFontSize);
drawList.AddText(
UIPoint(layout.stateRect.x + 16.0f, layout.stateRect.y + 238.0f),
"Modifiers: " + DescribeModifiers(m_lastModifiers),
shellPalette.textMuted,
shellMetrics.bodyFontSize);
drawList.AddText(
UIPoint(layout.stateRect.x + 16.0f, layout.stateRect.y + 262.0f),
"Result: " + m_lastResult,
shellPalette.textPrimary,
shellMetrics.bodyFontSize);
const std::string captureSummary =
m_autoScreenshot.HasPendingCapture()
? "截图排队中..."
: (m_autoScreenshot.GetLastCaptureSummary().empty()
? std::string("F12 -> tests/UI/Editor/integration/shell/list_view_multiselect/captures/")
: m_autoScreenshot.GetLastCaptureSummary());
drawList.AddText(
UIPoint(layout.stateRect.x + 16.0f, layout.stateRect.y + 286.0f),
captureSummary,
shellPalette.textWeak,
shellMetrics.bodyFontSize);
drawList.AddText(
UIPoint(layout.stateRect.x + 16.0f, layout.stateRect.y + 310.0f),
"Theme: " + m_themeStatus,
shellPalette.textWeak,
shellMetrics.bodyFontSize);
DrawCard(
drawList,
layout.previewRect,
shellPalette,
shellMetrics,
"ListView 预览",
"这里只放一个 ListView。默认状态下已选中 material + script方便直接检查多选 contract。");
AppendUIEditorListViewBackground(
drawList,
m_frame.layout,
m_items,
m_selectionModel,
m_interactionState.listViewState);
AppendUIEditorListViewForeground(drawList, m_frame.layout, m_items);
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 = {};
InputModifierTracker m_modifierTracker = {};
std::filesystem::path m_captureRoot = {};
Style::UITheme m_theme = {};
std::string m_themeStatus = "fallback";
std::vector<UIEditorListViewItem> m_items = {};
UISelectionModel m_selectionModel = {};
UIEditorListViewInteractionState m_interactionState = {};
UIEditorListViewInteractionFrame m_frame = {};
UIPoint m_mousePosition = UIPoint(-1000.0f, -1000.0f);
ActionId m_hoveredAction = ActionId::Reset;
bool m_hasHoveredAction = false;
UIInputModifiers m_lastModifiers = {};
std::string m_lastResult = {};
};
} // namespace
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, LPWSTR, int nCmdShow) {
return ScenarioApp().Run(hInstance, nCmdShow);
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

View File

@@ -2,14 +2,15 @@
#define NOMINMAX
#endif
#include <XCEditor/Core/UIEditorTabStripInteraction.h>
#include <XCEditor/Core/UIEditorPanelRegistry.h>
#include <XCEditor/Core/UIEditorWorkspaceController.h>
#include <XCEditor/Widgets/UIEditorTabStrip.h>
#include "Host/AutoScreenshot.h"
#include "Host/NativeRenderer.h"
#include <XCEngine/Input/InputTypes.h>
#include <XCEngine/UI/DrawData.h>
#include <XCEngine/UI/Widgets/UITabStripModel.h>
#include <windows.h>
#include <windowsx.h>
@@ -27,12 +28,15 @@
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::UITabStripModel;
using XCEngine::UI::Editor::BuildDefaultUIEditorWorkspaceController;
using XCEngine::UI::Editor::BuildUIEditorWorkspacePanel;
using XCEngine::UI::Editor::BuildUIEditorWorkspaceTabStack;
@@ -43,6 +47,9 @@ using XCEngine::UI::Editor::Host::AutoScreenshotController;
using XCEngine::UI::Editor::Host::NativeRenderer;
using XCEngine::UI::Editor::UIEditorPanelDescriptor;
using XCEngine::UI::Editor::UIEditorPanelRegistry;
using XCEngine::UI::Editor::UIEditorTabStripInteractionFrame;
using XCEngine::UI::Editor::UIEditorTabStripInteractionResult;
using XCEngine::UI::Editor::UIEditorTabStripInteractionState;
using XCEngine::UI::Editor::UIEditorWorkspaceCommand;
using XCEngine::UI::Editor::UIEditorWorkspaceCommandKind;
using XCEngine::UI::Editor::UIEditorWorkspaceCommandResult;
@@ -50,9 +57,9 @@ using XCEngine::UI::Editor::UIEditorWorkspaceController;
using XCEngine::UI::Editor::UIEditorWorkspaceModel;
using XCEngine::UI::Editor::UIEditorWorkspaceNode;
using XCEngine::UI::Editor::UIEditorWorkspaceNodeKind;
using XCEngine::UI::Editor::UpdateUIEditorTabStripInteraction;
using XCEngine::UI::Editor::Widgets::AppendUIEditorTabStripBackground;
using XCEngine::UI::Editor::Widgets::AppendUIEditorTabStripForeground;
using XCEngine::UI::Editor::Widgets::BuildUIEditorTabStripLayout;
using XCEngine::UI::Editor::Widgets::HitTestUIEditorTabStrip;
using XCEngine::UI::Editor::Widgets::ResolveUIEditorTabStripSelectedIndex;
using XCEngine::UI::Editor::Widgets::UIEditorTabStripHitTarget;
@@ -93,6 +100,39 @@ bool ContainsPoint(const UIRect& rect, float x, float y) {
y <= rect.y + rect.height;
}
std::int32_t MapTabNavigationKey(UINT keyCode) {
switch (keyCode) {
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);
default:
return static_cast<std::int32_t>(KeyCode::None);
}
}
UIInputEvent MakePointerEvent(
UIInputEventType type,
const UIPoint& position,
UIPointerButton button = UIPointerButton::None) {
UIInputEvent event = {};
event.type = type;
event.position = position;
event.pointerButton = button;
return event;
}
UIInputEvent MakeKeyEvent(std::int32_t keyCode) {
UIInputEvent event = {};
event.type = UIInputEventType::KeyDown;
event.keyCode = keyCode;
return event;
}
void DrawCard(
UIDrawList& drawList,
const UIRect& rect,
@@ -240,9 +280,17 @@ private:
return 0;
}
break;
case WM_LBUTTONDOWN:
if (app != nullptr) {
app->HandleLeftButtonDown(
static_cast<float>(GET_X_LPARAM(lParam)),
static_cast<float>(GET_Y_LPARAM(lParam)));
return 0;
}
break;
case WM_LBUTTONUP:
if (app != nullptr) {
app->HandleClick(
app->HandleLeftButtonUp(
static_cast<float>(GET_X_LPARAM(lParam)),
static_cast<float>(GET_Y_LPARAM(lParam)));
return 0;
@@ -254,7 +302,10 @@ private:
if (wParam == VK_F12) {
app->m_autoScreenshot.RequestCapture("manual_f12");
} else {
app->HandleKeyDown(static_cast<UINT>(wParam));
const std::int32_t keyCode = MapTabNavigationKey(static_cast<UINT>(wParam));
if (keyCode != static_cast<std::int32_t>(KeyCode::None)) {
app->HandleKeyDown(keyCode);
}
}
return 0;
}
@@ -347,13 +398,30 @@ private:
void ResetScenario() {
m_controller =
BuildDefaultUIEditorWorkspaceController(BuildPanelRegistry(), BuildWorkspace());
m_tabStripState = {};
m_layout = {};
m_interactionState = {};
m_tabStripFrame = {};
m_tabItems.clear();
m_hoverTarget = {};
m_mousePosition = UIPoint(-1000.0f, -1000.0f);
m_lastResult = "等待操作";
m_navigationModel = {};
}
UIRect GetTabStripRect() const {
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 float outerPadding = 20.0f;
const float leftColumnWidth = 360.0f;
const UIRect previewCardRect(
leftColumnWidth + outerPadding * 2.0f,
outerPadding,
width - leftColumnWidth - outerPadding * 3.0f,
height - outerPadding * 2.0f);
return UIRect(
previewCardRect.x + 20.0f,
previewCardRect.y + 20.0f,
previewCardRect.width - 40.0f,
previewCardRect.height - 40.0f);
}
void OnResize(UINT width, UINT height) {
@@ -373,114 +441,97 @@ private:
TrackMouseEvent(&event);
m_resetButtonHovered = ContainsPoint(m_resetButtonRect, x, y);
RefreshHoverTarget();
PumpTabStripEvents({ MakePointerEvent(UIInputEventType::PointerMove, m_mousePosition) });
InvalidateRect(m_hwnd, nullptr, FALSE);
}
void HandleMouseLeave() {
m_mousePosition = UIPoint(-1000.0f, -1000.0f);
m_resetButtonHovered = false;
m_hoverTarget = {};
m_tabStripState.hoveredIndex = UIEditorTabStripInvalidIndex;
m_tabStripState.closeHoveredIndex = UIEditorTabStripInvalidIndex;
PumpTabStripEvents({ MakePointerEvent(UIInputEventType::PointerLeave, m_mousePosition) });
InvalidateRect(m_hwnd, nullptr, FALSE);
}
void HandleClick(float x, float y) {
void HandleLeftButtonDown(float x, float y) {
m_mousePosition = UIPoint(x, y);
if (ContainsPoint(m_resetButtonRect, x, y)) {
m_resetButtonHovered = true;
InvalidateRect(m_hwnd, nullptr, FALSE);
return;
}
PumpTabStripEvents({ MakePointerEvent(UIInputEventType::PointerButtonDown, m_mousePosition, UIPointerButton::Left) });
InvalidateRect(m_hwnd, nullptr, FALSE);
}
void HandleLeftButtonUp(float x, float y) {
m_mousePosition = UIPoint(x, y);
if (ContainsPoint(m_resetButtonRect, x, y)) {
ResetScenario();
InvalidateRect(m_hwnd, nullptr, FALSE);
return;
}
const UIEditorTabStripHitTarget hit =
HitTestUIEditorTabStrip(m_layout, m_tabStripState, UIPoint(x, y));
switch (hit.kind) {
case UIEditorTabStripHitTargetKind::CloseButton:
if (hit.index < m_tabItems.size()) {
DispatchCommand(
UIEditorWorkspaceCommandKind::ClosePanel,
m_tabItems[hit.index].tabId,
"Close " + m_tabItems[hit.index].title);
m_tabStripState.focused = true;
}
break;
case UIEditorTabStripHitTargetKind::Tab:
if (hit.index < m_tabItems.size()) {
DispatchCommand(
UIEditorWorkspaceCommandKind::ActivatePanel,
m_tabItems[hit.index].tabId,
"Activate " + m_tabItems[hit.index].title);
m_tabStripState.focused = true;
}
break;
case UIEditorTabStripHitTargetKind::HeaderBackground:
case UIEditorTabStripHitTargetKind::Content:
m_tabStripState.focused = true;
m_lastResult = "TabStrip 获得 focus";
break;
case UIEditorTabStripHitTargetKind::None:
default:
m_tabStripState.focused = false;
m_lastResult = "Focus cleared";
break;
}
RefreshHoverTarget();
const UIEditorTabStripInteractionResult result =
PumpTabStripEvents({ MakePointerEvent(UIInputEventType::PointerButtonUp, m_mousePosition, UIPointerButton::Left) });
ApplyInteractionResult(result, "Mouse");
InvalidateRect(m_hwnd, nullptr, FALSE);
}
void HandleKeyDown(UINT keyCode) {
if (!m_tabStripState.focused) {
return;
}
void HandleKeyDown(std::int32_t keyCode) {
const UIEditorTabStripInteractionResult result =
PumpTabStripEvents({ MakeKeyEvent(keyCode) });
ApplyInteractionResult(result, "Keyboard");
InvalidateRect(m_hwnd, nullptr, FALSE);
}
UIEditorTabStripInteractionResult PumpTabStripEvents(std::vector<UIInputEvent> events) {
RefreshTabItems();
bool handled = true;
bool changed = false;
std::string action = {};
std::string selectedTabId = m_controller.GetWorkspace().activePanelId;
m_tabStripFrame = UpdateUIEditorTabStripInteraction(
m_interactionState,
selectedTabId,
GetTabStripRect(),
m_tabItems,
events);
m_tabStripState = m_interactionState.tabStripState;
m_layout = m_tabStripFrame.layout;
m_hoverTarget = HitTestUIEditorTabStrip(m_layout, m_tabStripState, m_mousePosition);
return m_tabStripFrame.result;
}
switch (keyCode) {
case VK_LEFT:
action = "Keyboard Left";
changed = m_navigationModel.SelectPrevious();
break;
case VK_RIGHT:
action = "Keyboard Right";
changed = m_navigationModel.SelectNext();
break;
case VK_HOME:
action = "Keyboard Home";
changed = m_navigationModel.SelectFirst();
break;
case VK_END:
action = "Keyboard End";
changed = m_navigationModel.SelectLast();
break;
default:
handled = false;
break;
}
if (!handled) {
void ApplyInteractionResult(
const UIEditorTabStripInteractionResult& result,
std::string_view source) {
if (result.closeRequested && !result.closedTabId.empty()) {
DispatchCommand(
UIEditorWorkspaceCommandKind::ClosePanel,
result.closedTabId,
std::string(source) + " Close -> " + result.closedTabId);
PumpTabStripEvents({});
return;
}
if (!changed || !m_navigationModel.HasSelection()) {
m_lastResult = action + " -> NoOp";
InvalidateRect(m_hwnd, nullptr, FALSE);
return;
}
const std::size_t selectedIndex = m_navigationModel.GetSelectedIndex();
if (selectedIndex < m_tabItems.size()) {
if ((result.selectionChanged || result.keyboardNavigated) &&
!result.selectedTabId.empty()) {
DispatchCommand(
UIEditorWorkspaceCommandKind::ActivatePanel,
m_tabItems[selectedIndex].tabId,
action + " -> " + m_tabItems[selectedIndex].title);
result.selectedTabId,
std::string(source) + " Activate -> " + result.selectedTabId);
PumpTabStripEvents({});
return;
}
InvalidateRect(m_hwnd, nullptr, FALSE);
if (result.hitTarget.kind == UIEditorTabStripHitTargetKind::HeaderBackground ||
result.hitTarget.kind == UIEditorTabStripHitTargetKind::Content) {
m_lastResult = "TabStrip 获得 focus";
return;
}
if (result.hitTarget.kind == UIEditorTabStripHitTargetKind::None &&
!m_interactionState.tabStripState.focused) {
m_lastResult = "Focus cleared";
}
}
void DispatchCommand(
@@ -527,31 +578,6 @@ private:
}
}
m_tabStripState.selectedIndex =
ResolveUIEditorTabStripSelectedIndex(m_tabItems, workspace.activePanelId);
m_navigationModel.SetItemCount(m_tabItems.size());
if (m_tabStripState.selectedIndex != UIEditorTabStripInvalidIndex) {
m_navigationModel.SetSelectedIndex(m_tabStripState.selectedIndex);
}
}
void RefreshHoverTarget() {
m_hoverTarget = HitTestUIEditorTabStrip(m_layout, m_tabStripState, m_mousePosition);
m_tabStripState.hoveredIndex = UIEditorTabStripInvalidIndex;
m_tabStripState.closeHoveredIndex = UIEditorTabStripInvalidIndex;
if (m_hoverTarget.kind == UIEditorTabStripHitTargetKind::CloseButton &&
m_hoverTarget.index < m_tabItems.size()) {
m_tabStripState.hoveredIndex = m_hoverTarget.index;
m_tabStripState.closeHoveredIndex = m_hoverTarget.index;
return;
}
if (m_hoverTarget.kind == UIEditorTabStripHitTargetKind::Tab &&
m_hoverTarget.index < m_tabItems.size()) {
m_tabStripState.hoveredIndex = m_hoverTarget.index;
}
}
void RenderFrame() {
@@ -569,15 +595,7 @@ private:
outerPadding,
width - leftColumnWidth - outerPadding * 3.0f,
height - outerPadding * 2.0f);
const UIRect tabStripRect(
previewCardRect.x + 20.0f,
previewCardRect.y + 20.0f,
previewCardRect.width - 40.0f,
previewCardRect.height - 40.0f);
RefreshTabItems();
m_layout = BuildUIEditorTabStripLayout(tabStripRect, m_tabItems, m_tabStripState);
RefreshHoverTarget();
PumpTabStripEvents({});
m_resetButtonRect = UIRect(
stateRect.x + 16.0f,
@@ -723,10 +741,11 @@ private:
std::filesystem::path m_captureRoot = {};
UIPoint m_mousePosition = UIPoint(-1000.0f, -1000.0f);
UIEditorWorkspaceController m_controller = {};
UIEditorTabStripInteractionState m_interactionState = {};
UIEditorTabStripInteractionFrame m_tabStripFrame = {};
UIEditorTabStripState m_tabStripState = {};
UIEditorTabStripLayout m_layout = {};
std::vector<UIEditorTabStripItem> m_tabItems = {};
UITabStripModel m_navigationModel = {};
UIEditorTabStripHitTarget m_hoverTarget = {};
UIRect m_resetButtonRect = {};
bool m_resetButtonHovered = false;

Binary file not shown.

After

Width:  |  Height:  |  Size: 63 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 63 KiB

View File

@@ -2,11 +2,12 @@
#define NOMINMAX
#endif
#include <XCEditor/Core/UIEditorTreeViewInteraction.h>
#include <XCEditor/Widgets/UIEditorTreeView.h>
#include <XCEditor/Collections/UIEditorTreeView.h>
#include <XCEditor/Collections/UIEditorTreeViewInteraction.h>
#include "Host/AutoScreenshot.h"
#include "Host/NativeRenderer.h"
#include <XCEngine/Input/InputTypes.h>
#include <XCEngine/UI/DrawData.h>
#include <XCEngine/UI/Widgets/UIExpansionModel.h>
#include <XCEngine/UI/Widgets/UISelectionModel.h>
@@ -28,6 +29,7 @@
namespace {
using XCEngine::Input::KeyCode;
using XCEngine::UI::UIColor;
using XCEngine::UI::UIDrawData;
using XCEngine::UI::UIDrawList;
@@ -101,6 +103,25 @@ bool ContainsPoint(const UIRect& rect, float x, float y) {
y <= rect.y + rect.height;
}
std::int32_t MapTreeNavigationKey(UINT keyCode) {
switch (keyCode) {
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);
default:
return static_cast<std::int32_t>(KeyCode::None);
}
}
ScenarioLayout BuildScenarioLayout(float width, float height) {
constexpr float margin = 20.0f;
constexpr float leftWidth = 430.0f;
@@ -204,10 +225,11 @@ std::string JoinVisibleItems(
constexpr std::size_t kMaxVisibleLabels = 5u;
std::ostringstream stream = {};
const std::size_t labelCount = (std::min)(layout.visibleItemIndices.size(), kMaxVisibleLabels);
for (std::size_t index = 0; index < labelCount; ++index) {
for (std::size_t index = 0u; index < labelCount; ++index) {
if (index > 0u) {
stream << " | ";
}
const std::size_t itemIndex = layout.visibleItemIndices[index];
if (itemIndex < items.size()) {
stream << items[itemIndex].label;
@@ -225,7 +247,7 @@ std::string DescribeHitTarget(
const UIEditorTreeViewHitTarget& hitTarget,
const std::vector<UIEditorTreeViewItem>& items) {
if (hitTarget.itemIndex >= items.size()) {
return "";
return "(none)";
}
const std::string& label = items[hitTarget.itemIndex].label;
@@ -236,7 +258,7 @@ std::string DescribeHitTarget(
return "row: " + label;
case UIEditorTreeViewHitTargetKind::None:
default:
return "";
return "(none)";
}
}
@@ -251,6 +273,13 @@ UIInputEvent MakePointerEvent(
return event;
}
UIInputEvent MakeKeyEvent(std::int32_t keyCode) {
UIInputEvent event = {};
event.type = UIInputEventType::KeyDown;
event.keyCode = keyCode;
return event;
}
class ScenarioApp {
public:
int Run(HINSTANCE hInstance, int nCmdShow) {
@@ -328,11 +357,19 @@ private:
case WM_KEYDOWN:
case WM_SYSKEYDOWN:
if (app != nullptr && wParam == VK_F12) {
app->m_autoScreenshot.RequestCapture("manual_f12");
app->m_lastResult = "已请求截图,输出到 captures/latest.png";
InvalidateRect(hwnd, nullptr, FALSE);
return 0;
if (app != nullptr) {
if (wParam == VK_F12) {
app->m_autoScreenshot.RequestCapture("manual_f12");
app->m_lastResult = "已请求截图,输出到 captures/latest.png";
InvalidateRect(hwnd, nullptr, FALSE);
return 0;
}
const std::int32_t keyCode = MapTreeNavigationKey(static_cast<UINT>(wParam));
if (keyCode != static_cast<std::int32_t>(KeyCode::None)) {
app->HandleNavigationKey(keyCode);
return 0;
}
}
break;
@@ -528,6 +565,14 @@ private:
InvalidateRect(m_hwnd, nullptr, FALSE);
}
void HandleNavigationKey(std::int32_t keyCode) {
const bool wasFocused = m_interactionState.treeViewState.focused;
const UIEditorTreeViewInteractionResult result =
PumpTreeEvents({ MakeKeyEvent(keyCode) });
UpdateResultText(result, wasFocused, true);
InvalidateRect(m_hwnd, nullptr, FALSE);
}
void UpdateHoveredAction(const ScenarioLayout& layout, float x, float y) {
const ButtonLayout* button = HitTestAction(layout, x, y);
if (button == nullptr) {
@@ -558,7 +603,7 @@ private:
m_expansionModel,
layout.treeRect,
m_items,
events);
std::move(events));
return m_treeFrame.result;
}
@@ -566,6 +611,21 @@ private:
const UIEditorTreeViewInteractionResult& result,
bool wasFocused,
bool insideTree) {
if (result.keyboardNavigated && result.expansionChanged && !result.toggledItemId.empty()) {
m_lastResult = "键盘切换展开: " + result.toggledItemId;
return;
}
if (result.keyboardNavigated && !result.selectedItemId.empty()) {
m_lastResult = "键盘选择: " + result.selectedItemId;
return;
}
if (result.expansionChanged && result.selectionChanged && !result.selectedItemId.empty()) {
m_lastResult = "折叠后回收 selection: " + result.selectedItemId;
return;
}
if (result.expansionChanged && !result.toggledItemId.empty()) {
m_lastResult = "切换展开: " + result.toggledItemId;
return;
@@ -582,7 +642,7 @@ private:
}
if (insideTree) {
m_lastResult = "点击树内空白: 更新 focus / hover";
m_lastResult = "点击树内空白: 更新 focus / hover";
return;
}
@@ -624,31 +684,31 @@ private:
DrawCard(
drawList,
layout.introRect,
"这个测试在验证什么功能",
"只验证 Editor TreeView 基础控件,不涉及任何业务面板。");
"这个测试在验证什么功能",
"只验证 Editor TreeView 的单选、层级展开/折叠和键盘导航契约,不涉及任何业务面板。");
drawList.AddText(
UIPoint(layout.introRect.x + 16.0f, layout.introRect.y + 72.0f),
"1. 验证行缩进是否正确Scene 的子项右移一层Directional Light 再右移一层",
"1. 点击 row只切换 selectionhover / selected / focused 必须能明确区分",
kTextPrimary,
12.0f);
drawList.AddText(
UIPoint(layout.introRect.x + 16.0f, layout.introRect.y + 94.0f),
"2. 点击 disclosure 只切换展开/折叠,不应误改 selection。",
"2. 点击 disclosure只切换展开/折叠,不应误改 selection。",
kTextPrimary,
12.0f);
drawList.AddText(
UIPoint(layout.introRect.x + 16.0f, layout.introRect.y + 116.0f),
"3. 点击行只切换 selectionhover、selected、focused 三种视觉状态要能区分",
"3. 按 Left / Right验证折叠、展开以及父子层级跳转",
kTextPrimary,
12.0f);
drawList.AddText(
UIPoint(layout.introRect.x + 16.0f, layout.introRect.y + 138.0f),
"4. 点击树外空白后 focus 应清除,但 selection 不应丢失",
"4. 按 Up / Down / Home / End验证可见行导航以及 current 与 selection 同步",
kTextPrimary,
12.0f);
drawList.AddText(
UIPoint(layout.introRect.x + 16.0f, layout.introRect.y + 160.0f),
"5. F12 手动截图;设置 XCUI_AUTO_CAPTURE_ON_STARTUP=1 自动截图。",
"5. 点击树外空白清除 focusF12 手动截图XCUI_AUTO_CAPTURE_ON_STARTUP=1 自动截图。",
kTextPrimary,
12.0f);
@@ -660,7 +720,7 @@ private:
m_hasHoveredAction && m_hoveredAction == button.action);
}
DrawCard(drawList, layout.stateRect, "状态摘要", "重点检查 hit / focus / selection / expanded / visible。");
DrawCard(drawList, layout.stateRect, "状态摘要", "重点检查 hit / focus / selection / current / expanded / visible。");
drawList.AddText(
UIPoint(layout.stateRect.x + 16.0f, layout.stateRect.y + 70.0f),
"Hover: " + DescribeHitTarget(currentHit, m_items),
@@ -668,7 +728,7 @@ private:
12.0f);
drawList.AddText(
UIPoint(layout.stateRect.x + 16.0f, layout.stateRect.y + 94.0f),
std::string("Focused: ") + (m_interactionState.treeViewState.focused ? "" : ""),
std::string("Focused: ") + (m_interactionState.treeViewState.focused ? "on" : "off"),
kTextPrimary,
12.0f);
drawList.AddText(
@@ -679,17 +739,25 @@ private:
12.0f);
drawList.AddText(
UIPoint(layout.stateRect.x + 16.0f, layout.stateRect.y + 142.0f),
"Expanded: " + JoinExpandedItems(m_items, m_expansionModel),
std::string("Current: ") +
(m_interactionState.keyboardNavigation.HasCurrentIndex()
? std::to_string(m_interactionState.keyboardNavigation.GetCurrentIndex())
: std::string("(none)")),
kTextMuted,
12.0f);
drawList.AddText(
UIPoint(layout.stateRect.x + 16.0f, layout.stateRect.y + 166.0f),
"Expanded: " + JoinExpandedItems(m_items, m_expansionModel),
kTextMuted,
12.0f);
drawList.AddText(
UIPoint(layout.stateRect.x + 16.0f, layout.stateRect.y + 190.0f),
"Visible(" + std::to_string(m_treeFrame.layout.visibleItemIndices.size()) + "): " +
JoinVisibleItems(m_items, m_treeFrame.layout),
kTextMuted,
12.0f);
drawList.AddText(
UIPoint(layout.stateRect.x + 16.0f, layout.stateRect.y + 190.0f),
UIPoint(layout.stateRect.x + 16.0f, layout.stateRect.y + 214.0f),
"Result: " + m_lastResult,
kTextPrimary,
12.0f);
@@ -701,12 +769,12 @@ private:
? std::string("F12 -> tests/UI/Editor/integration/shell/tree_view_basic/captures/")
: m_autoScreenshot.GetLastCaptureSummary());
drawList.AddText(
UIPoint(layout.stateRect.x + 16.0f, layout.stateRect.y + 216.0f),
UIPoint(layout.stateRect.x + 16.0f, layout.stateRect.y + 238.0f),
captureSummary,
kTextWeak,
12.0f);
DrawCard(drawList, layout.previewRect, "TreeView 预览", "这里只放一个 TreeView不混入 Hierarchy/Inspector 等业务内容。");
DrawCard(drawList, layout.previewRect, "TreeView 预览", "这里只放一个 TreeView不混入 Hierarchy / Inspector 等业务内容。");
AppendUIEditorTreeViewBackground(
drawList,
m_treeFrame.layout,

View File

@@ -0,0 +1,31 @@
add_executable(editor_ui_tree_view_inline_rename_validation WIN32
main.cpp
)
target_include_directories(editor_ui_tree_view_inline_rename_validation PRIVATE
${CMAKE_SOURCE_DIR}/new_editor/include
${CMAKE_SOURCE_DIR}/new_editor/app
${CMAKE_SOURCE_DIR}/engine/include
${CMAKE_SOURCE_DIR}/tests/UI/Editor/integration/shared/src
)
target_compile_definitions(editor_ui_tree_view_inline_rename_validation PRIVATE
UNICODE
_UNICODE
XCENGINE_EDITOR_UI_TESTS_REPO_ROOT="${XCENGINE_EDITOR_UI_TESTS_REPO_ROOT_PATH}"
)
if(MSVC)
target_compile_options(editor_ui_tree_view_inline_rename_validation PRIVATE /utf-8 /FS)
set_property(TARGET editor_ui_tree_view_inline_rename_validation PROPERTY
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
endif()
target_link_libraries(editor_ui_tree_view_inline_rename_validation PRIVATE
XCUIEditorLib
XCUIEditorHost
)
set_target_properties(editor_ui_tree_view_inline_rename_validation PROPERTIES
OUTPUT_NAME "XCUIEditorTreeViewInlineRenameValidation"
)

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

View File

@@ -0,0 +1,958 @@
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <XCEditor/Collections/UIEditorInlineRenameSession.h>
#include <XCEditor/Collections/UIEditorTreeView.h>
#include <XCEditor/Collections/UIEditorTreeViewInteraction.h>
#include <XCEditor/Fields/UIEditorTextField.h>
#include <XCEditor/Foundation/UIEditorTheme.h>
#include "EditorValidationTheme.h"
#include "Host/AutoScreenshot.h"
#include "Host/NativeRenderer.h"
#include <XCEngine/Input/InputTypes.h>
#include <XCEngine/UI/DrawData.h>
#include <XCEngine/UI/Style/Theme.h>
#include <XCEngine/UI/Widgets/UIExpansionModel.h>
#include <XCEngine/UI/Widgets/UISelectionModel.h>
#include <windows.h>
#include <windowsx.h>
#include <algorithm>
#include <cstdint>
#include <filesystem>
#include <string>
#include <string_view>
#include <utility>
#include <vector>
#ifndef XCENGINE_EDITOR_UI_TESTS_REPO_ROOT
#define XCENGINE_EDITOR_UI_TESTS_REPO_ROOT "."
#endif
namespace {
using XCEngine::Input::KeyCode;
using XCEngine::Tests::EditorUI::EditorValidationShellMetrics;
using XCEngine::Tests::EditorUI::EditorValidationShellPalette;
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::UIExpansionModel;
using XCEngine::UI::Widgets::UISelectionModel;
using XCEngine::UI::Editor::BuildUIEditorHostedTextFieldMetrics;
using XCEngine::UI::Editor::BuildUIEditorHostedTextFieldPalette;
using XCEngine::UI::Editor::BuildUIEditorInlineRenameTextFieldMetrics;
using XCEngine::UI::Editor::Host::AutoScreenshotController;
using XCEngine::UI::Editor::Host::NativeRenderer;
using XCEngine::UI::Editor::ResolveUIEditorPropertyGridMetrics;
using XCEngine::UI::Editor::ResolveUIEditorPropertyGridPalette;
using XCEngine::UI::Editor::ResolveUIEditorTextFieldMetrics;
using XCEngine::UI::Editor::ResolveUIEditorTextFieldPalette;
using XCEngine::UI::Editor::UIEditorInlineRenameSessionFrame;
using XCEngine::UI::Editor::UIEditorInlineRenameSessionRequest;
using XCEngine::UI::Editor::UIEditorInlineRenameSessionState;
using XCEngine::UI::Editor::UIEditorTreeViewInteractionFrame;
using XCEngine::UI::Editor::UIEditorTreeViewInteractionResult;
using XCEngine::UI::Editor::UIEditorTreeViewInteractionState;
using XCEngine::UI::Editor::UpdateUIEditorInlineRenameSession;
using XCEngine::UI::Editor::UpdateUIEditorTreeViewInteraction;
using XCEngine::UI::Editor::Widgets::AppendUIEditorTextFieldBackground;
using XCEngine::UI::Editor::Widgets::AppendUIEditorTextFieldForeground;
using XCEngine::UI::Editor::Widgets::AppendUIEditorTreeViewBackground;
using XCEngine::UI::Editor::Widgets::AppendUIEditorTreeViewForeground;
using XCEngine::UI::Editor::Widgets::FindUIEditorTreeViewItemIndex;
using XCEngine::UI::Editor::Widgets::HitTestUIEditorTreeView;
using XCEngine::UI::Editor::Widgets::UIEditorTreeViewHitTarget;
using XCEngine::UI::Editor::Widgets::UIEditorTreeViewHitTargetKind;
using XCEngine::UI::Editor::Widgets::UIEditorTreeViewInvalidIndex;
using XCEngine::UI::Editor::Widgets::UIEditorTreeViewItem;
using XCEngine::UI::Editor::Widgets::UIEditorTextFieldMetrics;
using XCEngine::UI::Editor::Widgets::UIEditorTextFieldPalette;
namespace Style = XCEngine::UI::Style;
constexpr const wchar_t* kWindowClassName = L"XCUIEditorTreeViewInlineRenameValidation";
constexpr const wchar_t* kWindowTitle = L"XCUI Editor | TreeView Inline Rename";
enum class ActionId : unsigned char { Reset = 0, Capture };
struct ButtonLayout { ActionId action = ActionId::Reset; const char* label = ""; UIRect rect = {}; };
struct ScenarioLayout {
UIRect introRect = {};
UIRect controlRect = {};
UIRect stateRect = {};
UIRect previewRect = {};
UIRect treeRect = {};
std::vector<ButtonLayout> buttons = {};
};
std::filesystem::path ResolveRepoRootPath();
std::filesystem::path ResolveValidationThemePath();
bool ContainsPoint(const UIRect& rect, float x, float y);
std::int32_t MapTreeKey(UINT keyCode);
ScenarioLayout BuildScenarioLayout(float width, float height, const EditorValidationShellMetrics& shellMetrics);
void DrawCard(UIDrawList& drawList, const UIRect& rect, const EditorValidationShellPalette& shellPalette, const EditorValidationShellMetrics& shellMetrics, std::string_view title, std::string_view subtitle = {});
void DrawButton(UIDrawList& drawList, const ButtonLayout& button, const EditorValidationShellPalette& shellPalette, const EditorValidationShellMetrics& shellMetrics, bool hovered);
std::vector<UIEditorTreeViewItem> BuildTreeItems();
std::string DescribeHitTarget(const UIEditorTreeViewHitTarget& hitTarget, const std::vector<UIEditorTreeViewItem>& items);
UIInputEvent MakePointerEvent(UIInputEventType type, const UIPoint& position, UIPointerButton button = UIPointerButton::None);
UIInputEvent MakeKeyEvent(std::int32_t keyCode);
UIInputEvent MakeCharacterEvent(wchar_t character);
class ScenarioApp {
public:
int Run(HINSTANCE hInstance, int nCmdShow);
private:
static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
bool Initialize(HINSTANCE hInstance, int nCmdShow);
void Shutdown();
ScenarioLayout GetLayout() const;
void ResetScenario();
void RefreshTreeFrame();
void OnResize(UINT width, UINT height);
void HandleMouseMove(float x, float y);
void HandleMouseLeave();
void HandleLeftButtonDown(float x, float y);
void HandleLeftButtonUp(float x, float y);
void HandleKeyDown(UINT virtualKey);
void HandleCharacter(wchar_t character);
void UpdateHoveredAction(const ScenarioLayout& layout, float x, float y);
const ButtonLayout* HitTestAction(const ScenarioLayout& layout, float x, float y) const;
UIEditorTreeViewInteractionResult PumpTreeEvents(std::vector<UIInputEvent> events);
void BeginRename(const std::string& itemId);
void PumpRenameEvents(std::vector<UIInputEvent> events);
void ApplyRenameFrame(const UIEditorInlineRenameSessionFrame& frame);
void UpdateTreeResultText(const UIEditorTreeViewInteractionResult& result);
UIRect BuildRenameBoundsForActiveItem() const;
UIRect BuildRenameBounds(std::size_t itemIndex) const;
UIEditorInlineRenameSessionRequest BuildRenameRequest(bool beginSession) const;
UIEditorTextFieldMetrics ResolveHostedTextFieldMetrics() const;
UIEditorTextFieldMetrics ResolveInlineRenameMetrics(const UIRect& bounds) const;
UIEditorTextFieldPalette ResolveInlineRenamePalette() const;
void ExecuteAction(ActionId action);
void RenderFrame();
HWND m_hwnd = nullptr;
ATOM m_windowClassAtom = 0;
NativeRenderer m_renderer = {};
AutoScreenshotController m_autoScreenshot = {};
std::filesystem::path m_captureRoot = {};
Style::UITheme m_theme = {};
std::string m_themeStatus = "fallback";
std::vector<UIEditorTreeViewItem> m_items = {};
UISelectionModel m_selectionModel = {};
UIExpansionModel m_expansionModel = {};
UIEditorTreeViewInteractionState m_treeInteractionState = {};
UIEditorTreeViewInteractionFrame m_treeFrame = {};
UIEditorInlineRenameSessionState m_renameState = {};
UIEditorInlineRenameSessionFrame m_renameFrame = {};
UIPoint m_mousePosition = UIPoint(-1000.0f, -1000.0f);
ActionId m_hoveredAction = ActionId::Reset;
bool m_hasHoveredAction = false;
std::string m_lastCommittedItemId = {};
std::string m_lastCommittedValue = {};
std::string m_lastResult = {};
};
std::filesystem::path ResolveRepoRootPath() {
std::string root = XCENGINE_EDITOR_UI_TESTS_REPO_ROOT;
if (root.size() >= 2u && root.front() == '"' && root.back() == '"') {
root = root.substr(1u, root.size() - 2u);
}
return std::filesystem::path(root).lexically_normal();
}
std::filesystem::path ResolveValidationThemePath() {
return (ResolveRepoRootPath() / "tests/UI/Editor/integration/shared/themes/editor_validation.xctheme").lexically_normal();
}
bool ContainsPoint(const UIRect& rect, float x, float y) {
return x >= rect.x && x <= rect.x + rect.width && y >= rect.y && y <= rect.y + rect.height;
}
std::int32_t MapTreeKey(UINT keyCode) {
switch (keyCode) {
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_BACK: return static_cast<std::int32_t>(KeyCode::Backspace);
case VK_DELETE: return static_cast<std::int32_t>(KeyCode::Delete);
case VK_RETURN: return static_cast<std::int32_t>(KeyCode::Enter);
case VK_ESCAPE: return static_cast<std::int32_t>(KeyCode::Escape);
case VK_F2: return static_cast<std::int32_t>(KeyCode::F2);
default: return static_cast<std::int32_t>(KeyCode::None);
}
}
ScenarioLayout BuildScenarioLayout(float width, float height, const EditorValidationShellMetrics& shellMetrics) {
const float margin = shellMetrics.margin;
constexpr float leftWidth = 470.0f;
const float gap = shellMetrics.gap;
ScenarioLayout layout = {};
layout.introRect = UIRect(margin, margin, leftWidth, 252.0f);
layout.controlRect = UIRect(margin, layout.introRect.y + layout.introRect.height + gap, leftWidth, 84.0f);
layout.stateRect = UIRect(margin, layout.controlRect.y + layout.controlRect.height + gap, leftWidth, (std::max)(260.0f, height - (layout.controlRect.y + layout.controlRect.height + gap) - margin));
layout.previewRect = UIRect(leftWidth + margin * 2.0f, margin, (std::max)(520.0f, width - leftWidth - margin * 3.0f), height - margin * 2.0f);
layout.treeRect = UIRect(layout.previewRect.x + 22.0f, layout.previewRect.y + 72.0f, layout.previewRect.width - 44.0f, layout.previewRect.height - 104.0f);
const float buttonWidth = (layout.controlRect.width - 44.0f) * 0.5f;
const float buttonY = layout.controlRect.y + 32.0f;
layout.buttons = {
{ ActionId::Reset, "重置", UIRect(layout.controlRect.x + 14.0f, buttonY, buttonWidth, 36.0f) },
{ ActionId::Capture, "截图(F12)", UIRect(layout.controlRect.x + 26.0f + buttonWidth, buttonY, buttonWidth, 36.0f) }
};
return layout;
}
void DrawCard(UIDrawList& drawList, const UIRect& rect, const EditorValidationShellPalette& shellPalette, const EditorValidationShellMetrics& shellMetrics, std::string_view title, std::string_view subtitle) {
drawList.AddFilledRect(rect, shellPalette.cardBackground, shellMetrics.cardRadius);
drawList.AddRectOutline(rect, shellPalette.cardBorder, 1.0f, shellMetrics.cardRadius);
drawList.AddText(UIPoint(rect.x + 16.0f, rect.y + 14.0f), std::string(title), shellPalette.textPrimary, shellMetrics.titleFontSize);
if (!subtitle.empty()) {
drawList.AddText(UIPoint(rect.x + 16.0f, rect.y + 40.0f), std::string(subtitle), shellPalette.textMuted, shellMetrics.bodyFontSize);
}
}
void DrawButton(UIDrawList& drawList, const ButtonLayout& button, const EditorValidationShellPalette& shellPalette, const EditorValidationShellMetrics& shellMetrics, bool hovered) {
drawList.AddFilledRect(button.rect, hovered ? shellPalette.buttonHoverBackground : shellPalette.buttonBackground, shellMetrics.buttonRadius);
drawList.AddRectOutline(button.rect, shellPalette.cardBorder, 1.0f, shellMetrics.buttonRadius);
drawList.AddText(UIPoint(button.rect.x + 16.0f, button.rect.y + 10.0f), button.label, shellPalette.textPrimary, shellMetrics.bodyFontSize);
}
std::vector<UIEditorTreeViewItem> BuildTreeItems() {
return {
{ "scene", "Scene", 0u, false, 0.0f },
{ "camera", "Camera", 1u, true, 0.0f },
{ "lights", "Lights", 1u, false, 0.0f },
{ "directional-light", "Directional Light", 2u, true, 0.0f },
{ "fill-light", "Fill Light", 2u, true, 0.0f },
{ "characters", "Characters", 0u, false, 0.0f },
{ "hero", "Hero", 1u, false, 0.0f },
{ "hero-mesh", "HeroMesh", 2u, true, 0.0f },
{ "hero-rig", "HeroRig", 2u, true, 0.0f }
};
}
std::string DescribeHitTarget(const UIEditorTreeViewHitTarget& hitTarget, const std::vector<UIEditorTreeViewItem>& items) {
if (hitTarget.kind == UIEditorTreeViewHitTargetKind::None || hitTarget.itemIndex >= items.size()) {
return "(none)";
}
return items[hitTarget.itemIndex].itemId;
}
UIInputEvent MakePointerEvent(UIInputEventType type, const UIPoint& position, UIPointerButton button) {
UIInputEvent event = {};
event.type = type;
event.position = position;
event.pointerButton = button;
return event;
}
UIInputEvent MakeKeyEvent(std::int32_t keyCode) {
UIInputEvent event = {};
event.type = UIInputEventType::KeyDown;
event.keyCode = keyCode;
return event;
}
UIInputEvent MakeCharacterEvent(wchar_t character) {
UIInputEvent event = {};
event.type = UIInputEventType::Character;
event.character = static_cast<std::uint32_t>(character);
return event;
}
int ScenarioApp::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);
}
LRESULT CALLBACK ScenarioApp::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->OnResize(static_cast<UINT>(LOWORD(lParam)), static_cast<UINT>(HIWORD(lParam))); } return 0;
case WM_MOUSEMOVE: if (app != nullptr) { app->HandleMouseMove(static_cast<float>(GET_X_LPARAM(lParam)), static_cast<float>(GET_Y_LPARAM(lParam))); return 0; } break;
case WM_MOUSELEAVE: if (app != nullptr) { app->HandleMouseLeave(); return 0; } break;
case WM_LBUTTONDOWN: if (app != nullptr) { app->HandleLeftButtonDown(static_cast<float>(GET_X_LPARAM(lParam)), static_cast<float>(GET_Y_LPARAM(lParam))); return 0; } break;
case WM_LBUTTONUP: if (app != nullptr) { app->HandleLeftButtonUp(static_cast<float>(GET_X_LPARAM(lParam)), static_cast<float>(GET_Y_LPARAM(lParam))); return 0; } break;
case WM_KEYDOWN:
case WM_SYSKEYDOWN: if (app != nullptr) { app->HandleKeyDown(static_cast<UINT>(wParam)); return 0; } break;
case WM_CHAR: if (app != nullptr) { app->HandleCharacter(static_cast<wchar_t>(wParam)); 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 ScenarioApp::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, 1540, 940, 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_captureRoot = ResolveRepoRootPath() / "tests/UI/Editor/integration/shell/tree_view_inline_rename/captures";
m_autoScreenshot.Initialize(m_captureRoot);
const auto themeLoad = XCEngine::Tests::EditorUI::LoadEditorValidationTheme(ResolveValidationThemePath());
if (themeLoad.succeeded) {
m_theme = themeLoad.theme;
m_themeStatus = "loaded";
} else {
m_themeStatus = themeLoad.error.empty() ? "fallback" : themeLoad.error;
}
ResetScenario();
return true;
}
void ScenarioApp::Shutdown() {
m_autoScreenshot.Shutdown();
m_renderer.Shutdown();
if (m_hwnd != nullptr && IsWindow(m_hwnd)) {
DestroyWindow(m_hwnd);
}
m_hwnd = nullptr;
if (m_windowClassAtom != 0) {
UnregisterClassW(kWindowClassName, GetModuleHandleW(nullptr));
m_windowClassAtom = 0;
}
}
ScenarioLayout ScenarioApp::GetLayout() const {
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));
return BuildScenarioLayout(width, height, XCEngine::Tests::EditorUI::ResolveEditorValidationShellMetrics(m_theme));
}
void ScenarioApp::ResetScenario() {
m_items = BuildTreeItems();
m_selectionModel = {};
m_selectionModel.SetSelection("hero-mesh");
m_expansionModel = {};
m_expansionModel.Expand("scene");
m_expansionModel.Expand("lights");
m_expansionModel.Expand("characters");
m_expansionModel.Expand("hero");
m_treeInteractionState = {};
m_treeInteractionState.treeViewState.focused = true;
m_renameState = {};
m_renameFrame = {};
m_mousePosition = UIPoint(-1000.0f, -1000.0f);
m_hoveredAction = ActionId::Reset;
m_hasHoveredAction = false;
m_lastCommittedItemId.clear();
m_lastCommittedValue.clear();
m_lastResult = "已重置到默认状态,准备进入 hero-mesh 的 inline rename。";
RefreshTreeFrame();
BeginRename("hero-mesh");
}
void ScenarioApp::RefreshTreeFrame() {
if (m_hwnd == nullptr) {
return;
}
const ScenarioLayout layout = GetLayout();
m_treeFrame = UpdateUIEditorTreeViewInteraction(m_treeInteractionState, m_selectionModel, m_expansionModel, layout.treeRect, m_items, {});
if (m_renameState.active) {
const UIEditorInlineRenameSessionRequest request = BuildRenameRequest(false);
m_renameFrame = UpdateUIEditorInlineRenameSession(m_renameState, request, {}, ResolveInlineRenameMetrics(request.bounds));
ApplyRenameFrame(m_renameFrame);
}
}
void ScenarioApp::OnResize(UINT width, UINT height) {
if (width == 0u || height == 0u) {
return;
}
m_renderer.Resize(width, height);
RefreshTreeFrame();
}
void ScenarioApp::HandleMouseMove(float x, float y) {
m_mousePosition = UIPoint(x, y);
const ScenarioLayout layout = GetLayout();
UpdateHoveredAction(layout, x, y);
TRACKMOUSEEVENT trackEvent = {};
trackEvent.cbSize = sizeof(trackEvent);
trackEvent.dwFlags = TME_LEAVE;
trackEvent.hwndTrack = m_hwnd;
TrackMouseEvent(&trackEvent);
const UIInputEvent pointerEvent =
MakePointerEvent(UIInputEventType::PointerMove, m_mousePosition);
if (m_renameState.active) {
PumpRenameEvents({ pointerEvent });
} else {
PumpTreeEvents({ pointerEvent });
}
InvalidateRect(m_hwnd, nullptr, FALSE);
}
void ScenarioApp::HandleMouseLeave() {
m_mousePosition = UIPoint(-1000.0f, -1000.0f);
m_hasHoveredAction = false;
const UIInputEvent leaveEvent =
MakePointerEvent(UIInputEventType::PointerLeave, m_mousePosition);
if (m_renameState.active) {
PumpRenameEvents({ leaveEvent });
} else {
PumpTreeEvents({ leaveEvent });
}
InvalidateRect(m_hwnd, nullptr, FALSE);
}
void ScenarioApp::HandleLeftButtonDown(float x, float y) {
m_mousePosition = UIPoint(x, y);
const ScenarioLayout layout = GetLayout();
if (HitTestAction(layout, x, y) != nullptr) {
UpdateHoveredAction(layout, x, y);
InvalidateRect(m_hwnd, nullptr, FALSE);
return;
}
const UIInputEvent pointerEvent =
MakePointerEvent(UIInputEventType::PointerButtonDown, m_mousePosition, UIPointerButton::Left);
if (m_renameState.active) {
const UIRect renameBounds = BuildRenameBoundsForActiveItem();
const bool insideRename = ContainsPoint(renameBounds, x, y);
PumpRenameEvents({ pointerEvent });
if (!insideRename && !m_renameState.active) {
PumpTreeEvents({ pointerEvent });
}
} else {
PumpTreeEvents({ pointerEvent });
}
InvalidateRect(m_hwnd, nullptr, FALSE);
}
void ScenarioApp::HandleLeftButtonUp(float x, float y) {
m_mousePosition = UIPoint(x, y);
const ScenarioLayout layout = GetLayout();
const ButtonLayout* button = HitTestAction(layout, x, y);
if (button != nullptr) {
ExecuteAction(button->action);
UpdateHoveredAction(layout, x, y);
InvalidateRect(m_hwnd, nullptr, FALSE);
return;
}
const UIInputEvent pointerEvent =
MakePointerEvent(UIInputEventType::PointerButtonUp, m_mousePosition, UIPointerButton::Left);
if (m_renameState.active) {
const UIRect renameBounds = BuildRenameBoundsForActiveItem();
const bool insideRename = ContainsPoint(renameBounds, x, y);
PumpRenameEvents({ pointerEvent });
if (!insideRename && !m_renameState.active) {
const UIEditorTreeViewInteractionResult result = PumpTreeEvents({ pointerEvent });
UpdateTreeResultText(result);
}
} else {
const UIEditorTreeViewInteractionResult result = PumpTreeEvents({ pointerEvent });
UpdateTreeResultText(result);
}
InvalidateRect(m_hwnd, nullptr, FALSE);
}
void ScenarioApp::HandleKeyDown(UINT virtualKey) {
if (virtualKey == VK_F12) {
m_autoScreenshot.RequestCapture("manual_f12");
m_lastResult = "已请求截图,输出到 captures/latest.png";
InvalidateRect(m_hwnd, nullptr, FALSE);
return;
}
const std::int32_t keyCode = MapTreeKey(virtualKey);
if (keyCode == static_cast<std::int32_t>(KeyCode::None)) {
return;
}
if (m_renameState.active) {
PumpRenameEvents({ MakeKeyEvent(keyCode) });
} else {
const UIEditorTreeViewInteractionResult result =
PumpTreeEvents({ MakeKeyEvent(keyCode) });
if (result.renameRequested) {
BeginRename(result.renameItemId);
} else {
UpdateTreeResultText(result);
}
}
InvalidateRect(m_hwnd, nullptr, FALSE);
}
void ScenarioApp::HandleCharacter(wchar_t character) {
if (character < 32 || !m_renameState.active) {
return;
}
PumpRenameEvents({ MakeCharacterEvent(character) });
InvalidateRect(m_hwnd, nullptr, FALSE);
}
void ScenarioApp::UpdateHoveredAction(const ScenarioLayout& layout, float x, float y) {
const ButtonLayout* button = HitTestAction(layout, x, y);
if (button == nullptr) {
m_hasHoveredAction = false;
return;
}
m_hoveredAction = button->action;
m_hasHoveredAction = true;
}
const ButtonLayout* ScenarioApp::HitTestAction(const ScenarioLayout& layout, float x, float y) const {
for (const ButtonLayout& button : layout.buttons) {
if (ContainsPoint(button.rect, x, y)) {
return &button;
}
}
return nullptr;
}
UIEditorTreeViewInteractionResult ScenarioApp::PumpTreeEvents(std::vector<UIInputEvent> events) {
const ScenarioLayout layout = GetLayout();
m_treeFrame = UpdateUIEditorTreeViewInteraction(
m_treeInteractionState,
m_selectionModel,
m_expansionModel,
layout.treeRect,
m_items,
std::move(events));
return m_treeFrame.result;
}
void ScenarioApp::BeginRename(const std::string& itemId) {
if (itemId.empty()) {
return;
}
const std::size_t itemIndex = FindUIEditorTreeViewItemIndex(m_items, itemId);
if (itemIndex == UIEditorTreeViewInvalidIndex) {
return;
}
UIEditorInlineRenameSessionRequest request = {};
request.beginSession = true;
request.itemId = itemId;
request.initialText = m_items[itemIndex].label;
request.bounds = BuildRenameBounds(itemIndex);
m_renameFrame = UpdateUIEditorInlineRenameSession(
m_renameState,
request,
{},
ResolveInlineRenameMetrics(request.bounds));
ApplyRenameFrame(m_renameFrame);
}
void ScenarioApp::PumpRenameEvents(std::vector<UIInputEvent> events) {
if (!m_renameState.active) {
return;
}
const UIEditorInlineRenameSessionRequest request = BuildRenameRequest(false);
m_renameFrame = UpdateUIEditorInlineRenameSession(
m_renameState,
request,
std::move(events),
ResolveInlineRenameMetrics(request.bounds));
ApplyRenameFrame(m_renameFrame);
}
void ScenarioApp::ApplyRenameFrame(const UIEditorInlineRenameSessionFrame& frame) {
const auto& result = frame.result;
if (result.sessionStarted) {
m_lastResult = "已进入 inline rename: " + result.itemId;
return;
}
if (result.sessionCommitted) {
const std::size_t itemIndex = FindUIEditorTreeViewItemIndex(m_items, result.itemId);
if (itemIndex != UIEditorTreeViewInvalidIndex) {
m_items[itemIndex].label = result.valueAfter;
m_lastCommittedItemId = result.itemId;
m_lastCommittedValue = result.valueAfter;
RefreshTreeFrame();
}
m_lastResult = "已提交 rename: " + result.itemId + " -> " + result.valueAfter;
return;
}
if (result.sessionCanceled) {
m_lastResult = "已取消 rename: " + result.itemId;
return;
}
if (m_renameState.active && result.textFieldResult.consumed) {
m_lastResult =
"编辑中: " + m_renameState.itemId + " -> " +
m_renameState.textFieldInteraction.textFieldState.displayText;
}
}
void ScenarioApp::UpdateTreeResultText(const UIEditorTreeViewInteractionResult& result) {
if (result.renameRequested) {
m_lastResult = "收到 rename 请求: " + result.renameItemId;
return;
}
if (result.keyboardNavigated && !result.selectedItemId.empty()) {
m_lastResult = "键盘导航到: " + result.selectedItemId;
return;
}
if (result.expansionChanged && !result.toggledItemId.empty()) {
m_lastResult = "切换展开: " + result.toggledItemId;
return;
}
if (result.selectionChanged && !result.selectedItemId.empty()) {
m_lastResult = "选中行: " + result.selectedItemId;
return;
}
if (result.consumed && result.hitTarget.kind == UIEditorTreeViewHitTargetKind::Row) {
m_lastResult = "点击行: " + DescribeHitTarget(result.hitTarget, m_items);
return;
}
if (result.consumed && result.hitTarget.kind == UIEditorTreeViewHitTargetKind::Disclosure) {
m_lastResult = "点击 disclosure: " + DescribeHitTarget(result.hitTarget, m_items);
return;
}
m_lastResult = "等待交互";
}
UIRect ScenarioApp::BuildRenameBoundsForActiveItem() const {
if (!m_renameState.active) {
return {};
}
const std::size_t itemIndex = FindUIEditorTreeViewItemIndex(m_items, m_renameState.itemId);
return BuildRenameBounds(itemIndex);
}
UIRect ScenarioApp::BuildRenameBounds(std::size_t itemIndex) const {
if (itemIndex == UIEditorTreeViewInvalidIndex) {
return {};
}
const auto& layout = m_treeFrame.layout;
std::size_t visibleIndex = UIEditorTreeViewInvalidIndex;
for (std::size_t index = 0u; index < layout.visibleItemIndices.size(); ++index) {
if (layout.visibleItemIndices[index] == itemIndex) {
visibleIndex = index;
break;
}
}
if (visibleIndex == UIEditorTreeViewInvalidIndex ||
visibleIndex >= layout.labelRects.size() ||
visibleIndex >= layout.rowRects.size()) {
return {};
}
const UIEditorTextFieldMetrics hostedMetrics = ResolveHostedTextFieldMetrics();
const UIRect& rowRect = layout.rowRects[visibleIndex];
const UIRect& labelRect = layout.labelRects[visibleIndex];
const float x = (std::max)(rowRect.x, labelRect.x - hostedMetrics.valueTextInsetX);
const float right = rowRect.x + rowRect.width - 8.0f;
const float width = (std::max)(120.0f, right - x);
return UIRect(x, rowRect.y, width, rowRect.height);
}
UIEditorInlineRenameSessionRequest ScenarioApp::BuildRenameRequest(bool beginSession) const {
UIEditorInlineRenameSessionRequest request = {};
request.beginSession = beginSession;
request.itemId = m_renameState.itemId;
request.initialText = m_renameState.textFieldSpec.value;
request.bounds = BuildRenameBoundsForActiveItem();
return request;
}
UIEditorTextFieldMetrics ScenarioApp::ResolveHostedTextFieldMetrics() const {
const auto propertyMetrics = ResolveUIEditorPropertyGridMetrics(m_theme);
const auto textMetrics = ResolveUIEditorTextFieldMetrics(m_theme);
return BuildUIEditorHostedTextFieldMetrics(propertyMetrics, textMetrics);
}
UIEditorTextFieldMetrics ScenarioApp::ResolveInlineRenameMetrics(const UIRect& bounds) const {
return BuildUIEditorInlineRenameTextFieldMetrics(bounds, ResolveHostedTextFieldMetrics());
}
UIEditorTextFieldPalette ScenarioApp::ResolveInlineRenamePalette() const {
const auto propertyPalette = ResolveUIEditorPropertyGridPalette(m_theme);
const auto textPalette = ResolveUIEditorTextFieldPalette(m_theme);
return BuildUIEditorHostedTextFieldPalette(propertyPalette, textPalette);
}
void ScenarioApp::ExecuteAction(ActionId action) {
switch (action) {
case ActionId::Reset:
ResetScenario();
break;
case ActionId::Capture:
m_autoScreenshot.RequestCapture("manual_button");
m_lastResult = "已请求截图,输出到 captures/latest.png";
break;
}
}
void ScenarioApp::RenderFrame() {
if (m_hwnd == nullptr) {
return;
}
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 auto shellMetrics =
XCEngine::Tests::EditorUI::ResolveEditorValidationShellMetrics(m_theme);
const auto shellPalette =
XCEngine::Tests::EditorUI::ResolveEditorValidationShellPalette(m_theme);
const ScenarioLayout layout = BuildScenarioLayout(width, height, shellMetrics);
RefreshTreeFrame();
const UIEditorTreeViewHitTarget currentHit =
HitTestUIEditorTreeView(m_treeFrame.layout, m_mousePosition);
std::vector<UIEditorTreeViewItem> renderItems = m_items;
if (m_renameState.active) {
const std::size_t activeIndex = FindUIEditorTreeViewItemIndex(m_items, m_renameState.itemId);
if (activeIndex != UIEditorTreeViewInvalidIndex && activeIndex < renderItems.size()) {
renderItems[activeIndex].label.clear();
}
}
UIDrawData drawData = {};
UIDrawList& drawList = drawData.EmplaceDrawList("EditorTreeViewInlineRename");
drawList.AddFilledRect(UIRect(0.0f, 0.0f, width, height), shellPalette.windowBackground);
DrawCard(
drawList,
layout.introRect,
shellPalette,
shellMetrics,
"这个测试在验证什么功能?",
"只验证 Editor TreeView 的 inline rename 契约默认进入编辑、字符编辑、Enter 提交、Esc 取消、点击外部提交。");
drawList.AddText(
UIPoint(layout.introRect.x + 16.0f, layout.introRect.y + 72.0f),
"1. 启动后默认进入 hero-mesh rename输入框只能覆盖 label 区。",
shellPalette.textPrimary,
shellMetrics.bodyFontSize);
drawList.AddText(
UIPoint(layout.introRect.x + 16.0f, layout.introRect.y + 94.0f),
"2. 输入字符后Draft 必须实时变化,原标签不能和 overlay 叠字。",
shellPalette.textPrimary,
shellMetrics.bodyFontSize);
drawList.AddText(
UIPoint(layout.introRect.x + 16.0f, layout.introRect.y + 116.0f),
"3. 按 Enter名称写回 TreeViewItem.label并退出 rename。",
shellPalette.textPrimary,
shellMetrics.bodyFontSize);
drawList.AddText(
UIPoint(layout.introRect.x + 16.0f, layout.introRect.y + 138.0f),
"4. 按 Esc取消编辑保留原标签。",
shellPalette.textPrimary,
shellMetrics.bodyFontSize);
drawList.AddText(
UIPoint(layout.introRect.x + 16.0f, layout.introRect.y + 160.0f),
"5. rename 中点击输入框外部:提交当前草稿并退出编辑态。",
shellPalette.textPrimary,
shellMetrics.bodyFontSize);
drawList.AddText(
UIPoint(layout.introRect.x + 16.0f, layout.introRect.y + 182.0f),
"6. 需要时先按 Esc 退出,再单击树节点后按 F2F12 可截图。",
shellPalette.textPrimary,
shellMetrics.bodyFontSize);
DrawCard(drawList, layout.controlRect, shellPalette, shellMetrics, "操作");
for (const ButtonLayout& button : layout.buttons) {
DrawButton(
drawList,
button,
shellPalette,
shellMetrics,
m_hasHoveredAction && m_hoveredAction == button.action);
}
DrawCard(
drawList,
layout.stateRect,
shellPalette,
shellMetrics,
"状态摘要",
"重点检查 TreeView 选择状态、可见索引和 rename 生命周期是否同步。");
drawList.AddText(
UIPoint(layout.stateRect.x + 16.0f, layout.stateRect.y + 70.0f),
"Hover: " + DescribeHitTarget(currentHit, m_items),
shellPalette.textPrimary,
shellMetrics.bodyFontSize);
drawList.AddText(
UIPoint(layout.stateRect.x + 16.0f, layout.stateRect.y + 94.0f),
std::string("Tree Focused: ") + (m_treeInteractionState.treeViewState.focused ? "on" : "off"),
shellPalette.textPrimary,
shellMetrics.bodyFontSize);
drawList.AddText(
UIPoint(layout.stateRect.x + 16.0f, layout.stateRect.y + 118.0f),
"Selected Item: " +
(m_selectionModel.HasSelection() ? m_selectionModel.GetSelectedId() : std::string("(none)")),
shellPalette.textPrimary,
shellMetrics.bodyFontSize);
drawList.AddText(
UIPoint(layout.stateRect.x + 16.0f, layout.stateRect.y + 142.0f),
std::string("Rename Active: ") + (m_renameState.active ? "yes" : "no"),
shellPalette.textPrimary,
shellMetrics.bodyFontSize);
drawList.AddText(
UIPoint(layout.stateRect.x + 16.0f, layout.stateRect.y + 166.0f),
"Rename Item: " + (m_renameState.active ? m_renameState.itemId : std::string("(none)")),
shellPalette.textPrimary,
shellMetrics.bodyFontSize);
drawList.AddText(
UIPoint(layout.stateRect.x + 16.0f, layout.stateRect.y + 190.0f),
"Draft: " + (m_renameState.active
? m_renameState.textFieldInteraction.textFieldState.displayText
: std::string("(none)")),
shellPalette.textPrimary,
shellMetrics.bodyFontSize);
drawList.AddText(
UIPoint(layout.stateRect.x + 16.0f, layout.stateRect.y + 214.0f),
"Committed: " + (m_lastCommittedValue.empty()
? std::string("(none)")
: (m_lastCommittedItemId + " -> " + m_lastCommittedValue)),
shellPalette.textPrimary,
shellMetrics.bodyFontSize);
drawList.AddText(
UIPoint(layout.stateRect.x + 16.0f, layout.stateRect.y + 238.0f),
std::string("Current Index: ") +
(m_treeInteractionState.keyboardNavigation.HasCurrentIndex()
? std::to_string(m_treeInteractionState.keyboardNavigation.GetCurrentIndex())
: std::string("(none)")),
shellPalette.textMuted,
shellMetrics.bodyFontSize);
drawList.AddText(
UIPoint(layout.stateRect.x + 16.0f, layout.stateRect.y + 262.0f),
"Visible Count: " + std::to_string(m_treeFrame.layout.visibleItemIndices.size()),
shellPalette.textMuted,
shellMetrics.bodyFontSize);
drawList.AddText(
UIPoint(layout.stateRect.x + 16.0f, layout.stateRect.y + 286.0f),
"Result: " + m_lastResult,
shellPalette.textPrimary,
shellMetrics.bodyFontSize);
const std::string captureSummary =
m_autoScreenshot.HasPendingCapture()
? "截图排队中..."
: (m_autoScreenshot.GetLastCaptureSummary().empty()
? std::string("F12 -> tests/UI/Editor/integration/shell/tree_view_inline_rename/captures/")
: m_autoScreenshot.GetLastCaptureSummary());
drawList.AddText(
UIPoint(layout.stateRect.x + 16.0f, layout.stateRect.y + 310.0f),
captureSummary,
shellPalette.textWeak,
shellMetrics.bodyFontSize);
drawList.AddText(
UIPoint(layout.stateRect.x + 16.0f, layout.stateRect.y + 334.0f),
"Theme: " + m_themeStatus,
shellPalette.textWeak,
shellMetrics.bodyFontSize);
DrawCard(
drawList,
layout.previewRect,
shellPalette,
shellMetrics,
"TreeView 预览",
"这里只放一个 TreeView启动时默认直接进入 hero-mesh 的 rename便于截图和自检。");
AppendUIEditorTreeViewBackground(
drawList,
m_treeFrame.layout,
renderItems,
m_selectionModel,
m_treeInteractionState.treeViewState);
AppendUIEditorTreeViewForeground(drawList, m_treeFrame.layout, renderItems);
if (m_renameState.active) {
const UIEditorTextFieldPalette palette = ResolveInlineRenamePalette();
const UIEditorTextFieldMetrics metrics =
ResolveInlineRenameMetrics(BuildRenameBoundsForActiveItem());
AppendUIEditorTextFieldBackground(
drawList,
m_renameFrame.layout,
m_renameState.textFieldSpec,
m_renameState.textFieldInteraction.textFieldState,
palette,
metrics);
AppendUIEditorTextFieldForeground(
drawList,
m_renameFrame.layout,
m_renameState.textFieldSpec,
m_renameState.textFieldInteraction.textFieldState,
palette,
metrics);
}
const bool framePresented = m_renderer.Render(drawData);
m_autoScreenshot.CaptureIfRequested(
m_renderer,
drawData,
static_cast<unsigned int>(width),
static_cast<unsigned int>(height),
framePresented);
}
} // namespace
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, LPWSTR, int nCmdShow) {
return ScenarioApp().Run(hInstance, nCmdShow);
}

View File

@@ -0,0 +1,30 @@
add_executable(editor_ui_tree_view_multiselect_validation WIN32
main.cpp
)
target_include_directories(editor_ui_tree_view_multiselect_validation PRIVATE
${CMAKE_SOURCE_DIR}/new_editor/include
${CMAKE_SOURCE_DIR}/new_editor/app
${CMAKE_SOURCE_DIR}/engine/include
)
target_compile_definitions(editor_ui_tree_view_multiselect_validation PRIVATE
UNICODE
_UNICODE
XCENGINE_EDITOR_UI_TESTS_REPO_ROOT="${XCENGINE_EDITOR_UI_TESTS_REPO_ROOT_PATH}"
)
if(MSVC)
target_compile_options(editor_ui_tree_view_multiselect_validation PRIVATE /utf-8 /FS)
set_property(TARGET editor_ui_tree_view_multiselect_validation PROPERTY
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
endif()
target_link_libraries(editor_ui_tree_view_multiselect_validation PRIVATE
XCUIEditorLib
XCUIEditorHost
)
set_target_properties(editor_ui_tree_view_multiselect_validation PROPERTIES
OUTPUT_NAME "XCUIEditorTreeViewMultiSelectValidation"
)

Binary file not shown.

After

Width:  |  Height:  |  Size: 83 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 83 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 83 KiB

View File

@@ -0,0 +1,971 @@
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <XCEditor/Collections/UIEditorTreeView.h>
#include <XCEditor/Collections/UIEditorTreeViewInteraction.h>
#include "Host/AutoScreenshot.h"
#include "Host/NativeRenderer.h"
#include <XCEngine/Input/InputTypes.h>
#include <XCEngine/UI/DrawData.h>
#include <XCEngine/UI/Widgets/UIExpansionModel.h>
#include <XCEngine/UI/Widgets/UISelectionModel.h>
#include <windows.h>
#include <windowsx.h>
#include <algorithm>
#include <filesystem>
#include <sstream>
#include <string>
#include <string_view>
#include <utility>
#include <vector>
#ifndef XCENGINE_EDITOR_UI_TESTS_REPO_ROOT
#define XCENGINE_EDITOR_UI_TESTS_REPO_ROOT "."
#endif
namespace {
using XCEngine::Input::KeyCode;
using XCEngine::UI::UIColor;
using XCEngine::UI::UIDrawData;
using XCEngine::UI::UIDrawList;
using XCEngine::UI::UIInputEvent;
using XCEngine::UI::UIInputEventType;
using XCEngine::UI::UIInputModifiers;
using XCEngine::UI::UIPoint;
using XCEngine::UI::UIPointerButton;
using XCEngine::UI::UIRect;
using XCEngine::UI::Widgets::UIExpansionModel;
using XCEngine::UI::Widgets::UISelectionModel;
using XCEngine::UI::Editor::Host::AutoScreenshotController;
using XCEngine::UI::Editor::Host::NativeRenderer;
using XCEngine::UI::Editor::UIEditorTreeViewInteractionFrame;
using XCEngine::UI::Editor::UIEditorTreeViewInteractionResult;
using XCEngine::UI::Editor::UIEditorTreeViewInteractionState;
using XCEngine::UI::Editor::UpdateUIEditorTreeViewInteraction;
using XCEngine::UI::Editor::Widgets::AppendUIEditorTreeViewBackground;
using XCEngine::UI::Editor::Widgets::AppendUIEditorTreeViewForeground;
using XCEngine::UI::Editor::Widgets::HitTestUIEditorTreeView;
using XCEngine::UI::Editor::Widgets::UIEditorTreeViewHitTarget;
using XCEngine::UI::Editor::Widgets::UIEditorTreeViewHitTargetKind;
using XCEngine::UI::Editor::Widgets::UIEditorTreeViewInvalidIndex;
using XCEngine::UI::Editor::Widgets::UIEditorTreeViewItem;
using XCEngine::UI::Editor::Widgets::UIEditorTreeViewLayout;
constexpr const wchar_t* kWindowClassName = L"XCUIEditorTreeViewMultiSelectValidation";
constexpr const wchar_t* kWindowTitle = L"XCUI Editor | TreeView MultiSelect";
constexpr UIColor kWindowBg(0.13f, 0.13f, 0.13f, 1.0f);
constexpr UIColor kCardBg(0.18f, 0.18f, 0.18f, 1.0f);
constexpr UIColor kCardBorder(0.29f, 0.29f, 0.29f, 1.0f);
constexpr UIColor kTextPrimary(0.94f, 0.94f, 0.94f, 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.63f, 0.76f, 0.63f, 1.0f);
constexpr UIColor kButtonBg(0.25f, 0.25f, 0.25f, 1.0f);
constexpr UIColor kButtonHoverBg(0.32f, 0.32f, 0.32f, 1.0f);
enum class ActionId : unsigned char {
Reset = 0,
Capture
};
struct ButtonLayout {
ActionId action = ActionId::Reset;
const char* label = "";
UIRect rect = {};
};
struct ScenarioLayout {
UIRect introRect = {};
UIRect controlRect = {};
UIRect stateRect = {};
UIRect previewRect = {};
UIRect treeRect = {};
std::vector<ButtonLayout> buttons = {};
};
std::filesystem::path ResolveRepoRootPath() {
std::string root = XCENGINE_EDITOR_UI_TESTS_REPO_ROOT;
if (root.size() >= 2u && root.front() == '"' && root.back() == '"') {
root = root.substr(1u, root.size() - 2u);
}
return std::filesystem::path(root).lexically_normal();
}
bool ContainsPoint(const UIRect& rect, float x, float y) {
return x >= rect.x &&
x <= rect.x + rect.width &&
y >= rect.y &&
y <= rect.y + rect.height;
}
const char* BoolText(bool value) {
return value ? "true" : "false";
}
UIInputModifiers QueryKeyboardModifiers() {
UIInputModifiers modifiers = {};
modifiers.shift = (GetKeyState(VK_SHIFT) & 0x8000) != 0;
modifiers.control = (GetKeyState(VK_CONTROL) & 0x8000) != 0;
modifiers.alt = (GetKeyState(VK_MENU) & 0x8000) != 0;
modifiers.super = (GetKeyState(VK_LWIN) & 0x8000) != 0 || (GetKeyState(VK_RWIN) & 0x8000) != 0;
return modifiers;
}
UIInputModifiers QueryPointerModifiers(WPARAM wParam) {
UIInputModifiers modifiers = QueryKeyboardModifiers();
modifiers.shift = modifiers.shift || (wParam & MK_SHIFT) != 0;
modifiers.control = modifiers.control || (wParam & MK_CONTROL) != 0;
return modifiers;
}
std::int32_t MapTreeNavigationKey(UINT keyCode) {
switch (keyCode) {
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);
default:
return static_cast<std::int32_t>(KeyCode::None);
}
}
ScenarioLayout BuildScenarioLayout(float width, float height) {
constexpr float margin = 20.0f;
constexpr float leftWidth = 456.0f;
constexpr float gap = 16.0f;
ScenarioLayout layout = {};
layout.introRect = UIRect(margin, margin, leftWidth, 272.0f);
layout.controlRect = UIRect(margin, layout.introRect.y + layout.introRect.height + gap, leftWidth, 92.0f);
layout.stateRect = UIRect(
margin,
layout.controlRect.y + layout.controlRect.height + gap,
leftWidth,
(std::max)(240.0f, height - (layout.controlRect.y + layout.controlRect.height + gap) - margin));
layout.previewRect = UIRect(
leftWidth + margin * 2.0f,
margin,
(std::max)(420.0f, width - leftWidth - margin * 3.0f),
height - margin * 2.0f);
layout.treeRect = UIRect(
layout.previewRect.x + 18.0f,
layout.previewRect.y + 64.0f,
layout.previewRect.width - 36.0f,
layout.previewRect.height - 84.0f);
const float buttonWidth = (layout.controlRect.width - 44.0f) * 0.5f;
const float buttonY = layout.controlRect.y + 40.0f;
layout.buttons = {
{ ActionId::Reset, "重置", UIRect(layout.controlRect.x + 14.0f, buttonY, buttonWidth, 36.0f) },
{ ActionId::Capture, "截图(F12)", UIRect(layout.controlRect.x + 26.0f + buttonWidth, buttonY, buttonWidth, 36.0f) }
};
return layout;
}
void DrawCard(
UIDrawList& drawList,
const UIRect& rect,
std::string_view title,
std::string_view subtitle = {}) {
drawList.AddFilledRect(rect, kCardBg, 10.0f);
drawList.AddRectOutline(rect, kCardBorder, 1.0f, 10.0f);
drawList.AddText(UIPoint(rect.x + 16.0f, rect.y + 14.0f), std::string(title), kTextPrimary, 17.0f);
if (!subtitle.empty()) {
drawList.AddText(UIPoint(rect.x + 16.0f, rect.y + 40.0f), std::string(subtitle), kTextMuted, 12.0f);
}
}
void DrawButton(UIDrawList& drawList, const ButtonLayout& button, bool hovered) {
drawList.AddFilledRect(button.rect, hovered ? kButtonHoverBg : kButtonBg, 8.0f);
drawList.AddRectOutline(button.rect, kCardBorder, 1.0f, 8.0f);
drawList.AddText(UIPoint(button.rect.x + 16.0f, button.rect.y + 10.0f), button.label, kTextPrimary, 12.0f);
}
std::vector<UIEditorTreeViewItem> BuildTreeItems() {
return {
{ "scene", "Scene", 0u, false, 0.0f },
{ "camera", "Camera", 1u, true, 0.0f },
{ "lights", "Lights", 1u, false, 0.0f },
{ "directional-light", "Directional Light", 2u, true, 0.0f },
{ "fill-light", "Fill Light", 2u, true, 0.0f },
{ "characters", "Characters", 0u, false, 0.0f },
{ "hero", "Hero", 1u, false, 0.0f },
{ "hero-mesh", "HeroMesh", 2u, true, 0.0f },
{ "hero-rig", "HeroRig", 2u, true, 0.0f },
{ "ui-root", "UI Root", 0u, false, 0.0f },
{ "canvas", "Canvas", 1u, false, 0.0f },
{ "button", "Button", 2u, true, 0.0f },
{ "event-system", "EventSystem", 1u, true, 0.0f }
};
}
std::string JoinSelectedIds(const UISelectionModel& selectionModel) {
if (selectionModel.GetSelectedIds().empty()) {
return "(none)";
}
std::ostringstream stream = {};
for (std::size_t index = 0u; index < selectionModel.GetSelectedIds().size(); ++index) {
if (index > 0u) {
stream << " | ";
}
stream << selectionModel.GetSelectedIds()[index];
}
return stream.str();
}
std::string JoinExpandedIds(
const std::vector<UIEditorTreeViewItem>& items,
const UIExpansionModel& expansionModel) {
std::ostringstream stream = {};
bool first = true;
for (const UIEditorTreeViewItem& item : items) {
if (!expansionModel.IsExpanded(item.itemId)) {
continue;
}
if (!first) {
stream << " | ";
}
first = false;
stream << item.itemId;
}
return first ? "(none)" : stream.str();
}
std::string JoinVisibleIds(
const std::vector<UIEditorTreeViewItem>& items,
const UIEditorTreeViewLayout& layout) {
if (layout.visibleItemIndices.empty()) {
return "(none)";
}
std::ostringstream stream = {};
for (std::size_t visibleIndex = 0u; visibleIndex < layout.visibleItemIndices.size(); ++visibleIndex) {
if (visibleIndex > 0u) {
stream << " | ";
}
const std::size_t itemIndex = layout.visibleItemIndices[visibleIndex];
if (itemIndex < items.size()) {
stream << items[itemIndex].itemId;
}
}
return stream.str();
}
std::string DescribeHitTarget(
const UIEditorTreeViewHitTarget& hitTarget,
const std::vector<UIEditorTreeViewItem>& items) {
if (hitTarget.itemIndex >= items.size()) {
return "(none)";
}
const std::string& itemId = items[hitTarget.itemIndex].itemId;
switch (hitTarget.kind) {
case UIEditorTreeViewHitTargetKind::Disclosure:
return "disclosure: " + itemId;
case UIEditorTreeViewHitTargetKind::Row:
return "row: " + itemId;
case UIEditorTreeViewHitTargetKind::None:
default:
return "(none)";
}
}
UIInputEvent MakePointerEvent(
UIInputEventType type,
const UIPoint& position,
const UIInputModifiers& modifiers,
UIPointerButton button = UIPointerButton::None) {
UIInputEvent event = {};
event.type = type;
event.position = position;
event.modifiers = modifiers;
event.pointerButton = button;
return event;
}
UIInputEvent MakeKeyEvent(std::int32_t keyCode, const UIInputModifiers& modifiers) {
UIInputEvent event = {};
event.type = UIInputEventType::KeyDown;
event.keyCode = keyCode;
event.modifiers = modifiers;
return event;
}
class ScenarioApp {
public:
int Run(HINSTANCE hInstance, int nCmdShow) {
if (!Initialize(hInstance, nCmdShow)) {
Shutdown();
return 1;
}
MSG message = {};
while (message.message != WM_QUIT) {
if (PeekMessageW(&message, nullptr, 0U, 0U, PM_REMOVE)) {
TranslateMessage(&message);
DispatchMessageW(&message);
continue;
}
RenderFrame();
Sleep(8);
}
Shutdown();
return static_cast<int>(message.wParam);
}
private:
static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
if (message == WM_NCCREATE) {
const auto* createStruct = reinterpret_cast<CREATESTRUCTW*>(lParam);
auto* app = 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->OnResize(static_cast<UINT>(LOWORD(lParam)), static_cast<UINT>(HIWORD(lParam)));
}
return 0;
case WM_MOUSEMOVE:
if (app != nullptr) {
app->HandleMouseMove(
static_cast<float>(GET_X_LPARAM(lParam)),
static_cast<float>(GET_Y_LPARAM(lParam)),
wParam);
return 0;
}
break;
case WM_MOUSELEAVE:
if (app != nullptr) {
app->HandleMouseLeave();
return 0;
}
break;
case WM_LBUTTONDOWN:
if (app != nullptr) {
app->HandleLeftButtonDown(
static_cast<float>(GET_X_LPARAM(lParam)),
static_cast<float>(GET_Y_LPARAM(lParam)),
wParam);
return 0;
}
break;
case WM_LBUTTONUP:
if (app != nullptr) {
app->HandleLeftButtonUp(
static_cast<float>(GET_X_LPARAM(lParam)),
static_cast<float>(GET_Y_LPARAM(lParam)),
wParam);
return 0;
}
break;
case WM_RBUTTONDOWN:
if (app != nullptr) {
app->HandleRightButtonDown(
static_cast<float>(GET_X_LPARAM(lParam)),
static_cast<float>(GET_Y_LPARAM(lParam)),
wParam);
return 0;
}
break;
case WM_RBUTTONUP:
if (app != nullptr) {
app->HandleRightButtonUp(
static_cast<float>(GET_X_LPARAM(lParam)),
static_cast<float>(GET_Y_LPARAM(lParam)),
wParam);
return 0;
}
break;
case WM_KEYDOWN:
case WM_SYSKEYDOWN:
if (app != nullptr) {
if (wParam == VK_F12) {
app->m_autoScreenshot.RequestCapture("manual_f12");
app->m_lastResult = "已请求截图,输出到 captures/latest.png";
app->m_resultFlags =
"selectionChanged=false, expansionChanged=false, keyboardNavigated=false, secondaryClicked=false, consumed=true";
InvalidateRect(hwnd, nullptr, FALSE);
return 0;
}
const std::int32_t keyCode = MapTreeNavigationKey(static_cast<UINT>(wParam));
if (keyCode != static_cast<std::int32_t>(KeyCode::None)) {
app->HandleNavigationKey(keyCode, QueryKeyboardModifiers());
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,
1480,
920,
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_captureRoot =
ResolveRepoRootPath() / "tests/UI/Editor/integration/shell/tree_view_multiselect/captures";
m_autoScreenshot.Initialize(m_captureRoot);
ResetScenario();
return true;
}
void Shutdown() {
m_autoScreenshot.Shutdown();
m_renderer.Shutdown();
if (m_hwnd != nullptr && IsWindow(m_hwnd)) {
DestroyWindow(m_hwnd);
}
m_hwnd = nullptr;
if (m_windowClassAtom != 0) {
UnregisterClassW(kWindowClassName, GetModuleHandleW(nullptr));
m_windowClassAtom = 0;
}
}
ScenarioLayout GetLayout() const {
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));
return BuildScenarioLayout(width, height);
}
void ResetScenario() {
m_items = BuildTreeItems();
m_selectionModel = {};
m_selectionModel.SetSelections({ "camera", "lights", "ui-root" }, "lights");
m_expansionModel = {};
m_expansionModel.Expand("scene");
m_expansionModel.Expand("lights");
m_expansionModel.Expand("characters");
m_expansionModel.Expand("hero");
m_expansionModel.Expand("ui-root");
m_expansionModel.Expand("canvas");
m_interactionState = {};
m_interactionState.treeViewState.focused = true;
m_interactionState.selectionAnchorId = "lights";
m_mousePosition = UIPoint(-1000.0f, -1000.0f);
m_hoveredAction = ActionId::Reset;
m_hasHoveredAction = false;
m_lastResult = "已重置到默认多选状态camera | lights | ui-root";
m_resultFlags =
"selectionChanged=false, expansionChanged=false, keyboardNavigated=false, secondaryClicked=false, consumed=false";
RefreshTreeFrame();
}
void RefreshTreeFrame() {
if (m_hwnd == nullptr) {
return;
}
const ScenarioLayout layout = GetLayout();
m_treeFrame = UpdateUIEditorTreeViewInteraction(
m_interactionState,
m_selectionModel,
m_expansionModel,
layout.treeRect,
m_items,
{});
}
void OnResize(UINT width, UINT height) {
if (width == 0u || height == 0u) {
return;
}
m_renderer.Resize(width, height);
RefreshTreeFrame();
}
void HandleMouseMove(float x, float y, WPARAM wParam) {
m_mousePosition = UIPoint(x, y);
const ScenarioLayout layout = GetLayout();
UpdateHoveredAction(layout, x, y);
TRACKMOUSEEVENT trackEvent = {};
trackEvent.cbSize = sizeof(trackEvent);
trackEvent.dwFlags = TME_LEAVE;
trackEvent.hwndTrack = m_hwnd;
TrackMouseEvent(&trackEvent);
PumpTreeEvents({ MakePointerEvent(UIInputEventType::PointerMove, m_mousePosition, QueryPointerModifiers(wParam)) });
InvalidateRect(m_hwnd, nullptr, FALSE);
}
void HandleMouseLeave() {
m_mousePosition = UIPoint(-1000.0f, -1000.0f);
m_hasHoveredAction = false;
PumpTreeEvents({ MakePointerEvent(UIInputEventType::PointerLeave, m_mousePosition, {}) });
InvalidateRect(m_hwnd, nullptr, FALSE);
}
void HandleLeftButtonDown(float x, float y, WPARAM wParam) {
m_mousePosition = UIPoint(x, y);
const ScenarioLayout layout = GetLayout();
if (HitTestAction(layout, x, y) != nullptr) {
UpdateHoveredAction(layout, x, y);
InvalidateRect(m_hwnd, nullptr, FALSE);
return;
}
PumpTreeEvents({
MakePointerEvent(
UIInputEventType::PointerButtonDown,
m_mousePosition,
QueryPointerModifiers(wParam),
UIPointerButton::Left)
});
InvalidateRect(m_hwnd, nullptr, FALSE);
}
void HandleLeftButtonUp(float x, float y, WPARAM wParam) {
m_mousePosition = UIPoint(x, y);
const ScenarioLayout layout = GetLayout();
const ButtonLayout* button = HitTestAction(layout, x, y);
if (button != nullptr) {
ExecuteAction(button->action);
UpdateHoveredAction(layout, x, y);
InvalidateRect(m_hwnd, nullptr, FALSE);
return;
}
const UIInputModifiers modifiers = QueryPointerModifiers(wParam);
const bool insideTree = ContainsPoint(layout.treeRect, x, y);
const UIEditorTreeViewInteractionResult result =
PumpTreeEvents({
MakePointerEvent(
UIInputEventType::PointerButtonUp,
m_mousePosition,
modifiers,
UIPointerButton::Left)
});
std::string actionLabel = "点击树外空白focus 清除";
if (result.hitTarget.kind == UIEditorTreeViewHitTargetKind::Disclosure) {
actionLabel = "点击 disclosure 切换展开,不改 selection";
} else if (result.hitTarget.kind == UIEditorTreeViewHitTargetKind::Row) {
if (modifiers.shift) {
actionLabel = "Shift+单击范围多选";
} else if (modifiers.control) {
actionLabel = "Ctrl+单击切换多选";
} else {
actionLabel = "单击单选";
}
} else if (insideTree) {
actionLabel = "点击树内空白,只更新 focus / hover";
}
UpdateResultSummary(result, actionLabel);
InvalidateRect(m_hwnd, nullptr, FALSE);
}
void HandleRightButtonDown(float x, float y, WPARAM wParam) {
m_mousePosition = UIPoint(x, y);
PumpTreeEvents({
MakePointerEvent(
UIInputEventType::PointerButtonDown,
m_mousePosition,
QueryPointerModifiers(wParam),
UIPointerButton::Right)
});
InvalidateRect(m_hwnd, nullptr, FALSE);
}
void HandleRightButtonUp(float x, float y, WPARAM wParam) {
m_mousePosition = UIPoint(x, y);
const UIEditorTreeViewHitTarget hitBefore = HitTestUIEditorTreeView(m_treeFrame.layout, m_mousePosition);
const std::size_t selectedCountBefore = m_selectionModel.GetSelectionCount();
bool targetAlreadySelected = false;
if (hitBefore.itemIndex < m_items.size()) {
targetAlreadySelected = m_selectionModel.IsSelected(m_items[hitBefore.itemIndex].itemId);
}
const UIEditorTreeViewInteractionResult result =
PumpTreeEvents({
MakePointerEvent(
UIInputEventType::PointerButtonUp,
m_mousePosition,
QueryPointerModifiers(wParam),
UIPointerButton::Right)
});
std::string actionLabel = "右键空白区域";
if (result.hitTarget.kind == UIEditorTreeViewHitTargetKind::Row ||
result.hitTarget.kind == UIEditorTreeViewHitTargetKind::Disclosure) {
if (targetAlreadySelected && selectedCountBefore > 1u) {
actionLabel = "右键命中已选集合,不打散 selection仅切换 primary";
} else if (targetAlreadySelected) {
actionLabel = "右键命中已选项,仅切换 primary";
} else {
actionLabel = "右键命中未选项,改为单选并触发 secondary click";
}
}
UpdateResultSummary(result, actionLabel);
InvalidateRect(m_hwnd, nullptr, FALSE);
}
void HandleNavigationKey(std::int32_t keyCode, const UIInputModifiers& modifiers) {
const UIEditorTreeViewInteractionResult result =
PumpTreeEvents({ MakeKeyEvent(keyCode, modifiers) });
std::string actionLabel = modifiers.shift
? "Shift+键盘范围扩选"
: "键盘导航";
if (keyCode == static_cast<std::int32_t>(KeyCode::Left) ||
keyCode == static_cast<std::int32_t>(KeyCode::Right)) {
actionLabel = "Left/Right 层级导航或展开切换";
}
UpdateResultSummary(result, actionLabel);
InvalidateRect(m_hwnd, nullptr, FALSE);
}
void UpdateHoveredAction(const ScenarioLayout& layout, float x, float y) {
const ButtonLayout* button = HitTestAction(layout, x, y);
if (button == nullptr) {
m_hasHoveredAction = false;
return;
}
m_hoveredAction = button->action;
m_hasHoveredAction = true;
}
const ButtonLayout* HitTestAction(const ScenarioLayout& layout, float x, float y) const {
for (const ButtonLayout& button : layout.buttons) {
if (ContainsPoint(button.rect, x, y)) {
return &button;
}
}
return nullptr;
}
UIEditorTreeViewInteractionResult PumpTreeEvents(std::vector<UIInputEvent> events) {
const ScenarioLayout layout = GetLayout();
m_treeFrame = UpdateUIEditorTreeViewInteraction(
m_interactionState,
m_selectionModel,
m_expansionModel,
layout.treeRect,
m_items,
std::move(events));
return m_treeFrame.result;
}
void UpdateResultSummary(
const UIEditorTreeViewInteractionResult& result,
std::string_view actionLabel) {
std::ostringstream summary = {};
summary << actionLabel;
if (!result.selectedItemId.empty()) {
summary << " -> selected " << result.selectedItemId;
}
if (!result.toggledItemId.empty()) {
summary << " -> toggled " << result.toggledItemId;
}
if (result.selectedVisibleIndex != UIEditorTreeViewInvalidIndex) {
summary << " (visible " << result.selectedVisibleIndex << ")";
}
m_lastResult = summary.str();
std::ostringstream flags = {};
flags << "selectionChanged=" << BoolText(result.selectionChanged)
<< ", expansionChanged=" << BoolText(result.expansionChanged)
<< ", keyboardNavigated=" << BoolText(result.keyboardNavigated)
<< ", secondaryClicked=" << BoolText(result.secondaryClicked)
<< ", consumed=" << BoolText(result.consumed);
m_resultFlags = flags.str();
}
void ExecuteAction(ActionId action) {
switch (action) {
case ActionId::Reset:
ResetScenario();
break;
case ActionId::Capture:
m_autoScreenshot.RequestCapture("manual_button");
m_lastResult = "已请求截图,输出到 captures/latest.png";
m_resultFlags =
"selectionChanged=false, expansionChanged=false, keyboardNavigated=false, secondaryClicked=false, consumed=true";
break;
}
}
void RenderFrame() {
if (m_hwnd == nullptr) {
return;
}
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);
RefreshTreeFrame();
const UIEditorTreeViewHitTarget currentHit = HitTestUIEditorTreeView(m_treeFrame.layout, m_mousePosition);
UIDrawData drawData = {};
UIDrawList& drawList = drawData.EmplaceDrawList("EditorTreeViewMultiSelect");
drawList.AddFilledRect(UIRect(0.0f, 0.0f, width, height), kWindowBg);
DrawCard(
drawList,
layout.introRect,
"这个测试在验证什么功能?",
"只验证 Editor TreeView 的多选契约,不混入 Hierarchy / Inspector 业务面板。");
drawList.AddText(
UIPoint(layout.introRect.x + 16.0f, layout.introRect.y + 72.0f),
"1. 单击 row应切回单选primary / anchor / current 同步到该行。",
kTextPrimary,
12.0f);
drawList.AddText(
UIPoint(layout.introRect.x + 16.0f, layout.introRect.y + 94.0f),
"2. Ctrl+单击 / Shift+单击:应只验证 visible tree 范围内的多选切换与连续扩选。",
kTextPrimary,
12.0f);
drawList.AddText(
UIPoint(layout.introRect.x + 16.0f, layout.introRect.y + 116.0f),
"3. 点击 disclosure应只切换 expanded不应无故打散 selection。",
kTextPrimary,
12.0f);
drawList.AddText(
UIPoint(layout.introRect.x + 16.0f, layout.introRect.y + 138.0f),
"4. Left / Right应验证展开、折叠以及父子层级之间的 current / selection 跳转。",
kTextPrimary,
12.0f);
drawList.AddText(
UIPoint(layout.introRect.x + 16.0f, layout.introRect.y + 160.0f),
"5. 右键命中已选集合中的一项:不得打散 selection只允许切换 primary。",
kTextPrimary,
12.0f);
drawList.AddText(
UIPoint(layout.introRect.x + 16.0f, layout.introRect.y + 182.0f),
"6. 重点检查左侧状态Primary / Count / Ids / Anchor / Current / Expanded / Visible / Result。",
kTextPrimary,
12.0f);
drawList.AddText(
UIPoint(layout.introRect.x + 16.0f, layout.introRect.y + 204.0f),
"7. 按 F12 手动截图;设置 XCUI_AUTO_CAPTURE_ON_STARTUP=1 可做启动自动截图。",
kTextPrimary,
12.0f);
DrawCard(drawList, layout.controlRect, "操作");
for (const ButtonLayout& button : layout.buttons) {
DrawButton(drawList, button, m_hasHoveredAction && m_hoveredAction == button.action);
}
DrawCard(drawList, layout.stateRect, "状态摘要", "重点检查 multi-select 与 expanded / visible contract 是否稳定。");
drawList.AddText(
UIPoint(layout.stateRect.x + 16.0f, layout.stateRect.y + 70.0f),
"Hit: " + DescribeHitTarget(currentHit, m_items),
kTextPrimary,
12.0f);
drawList.AddText(
UIPoint(layout.stateRect.x + 16.0f, layout.stateRect.y + 94.0f),
std::string("Focused: ") + BoolText(m_interactionState.treeViewState.focused),
kTextPrimary,
12.0f);
drawList.AddText(
UIPoint(layout.stateRect.x + 16.0f, layout.stateRect.y + 118.0f),
"Primary: " +
(m_selectionModel.HasSelection() ? m_selectionModel.GetSelectedId() : std::string("(none)")),
kTextSuccess,
12.0f);
drawList.AddText(
UIPoint(layout.stateRect.x + 16.0f, layout.stateRect.y + 142.0f),
"Selected Count: " + std::to_string(m_selectionModel.GetSelectionCount()),
kTextPrimary,
12.0f);
drawList.AddText(
UIPoint(layout.stateRect.x + 16.0f, layout.stateRect.y + 166.0f),
"Selected Ids: " + JoinSelectedIds(m_selectionModel),
kTextMuted,
12.0f);
drawList.AddText(
UIPoint(layout.stateRect.x + 16.0f, layout.stateRect.y + 190.0f),
"Anchor: " +
(m_interactionState.selectionAnchorId.empty()
? std::string("(none)")
: m_interactionState.selectionAnchorId),
kTextMuted,
12.0f);
drawList.AddText(
UIPoint(layout.stateRect.x + 16.0f, layout.stateRect.y + 214.0f),
std::string("Current: ") +
(m_interactionState.keyboardNavigation.HasCurrentIndex()
? std::to_string(m_interactionState.keyboardNavigation.GetCurrentIndex())
: std::string("(none)")),
kTextMuted,
12.0f);
drawList.AddText(
UIPoint(layout.stateRect.x + 16.0f, layout.stateRect.y + 238.0f),
"Expanded: " + JoinExpandedIds(m_items, m_expansionModel),
kTextMuted,
12.0f);
drawList.AddText(
UIPoint(layout.stateRect.x + 16.0f, layout.stateRect.y + 262.0f),
"Visible: " + JoinVisibleIds(m_items, m_treeFrame.layout),
kTextMuted,
12.0f);
drawList.AddText(
UIPoint(layout.stateRect.x + 16.0f, layout.stateRect.y + 286.0f),
"Result: " + m_lastResult,
kTextPrimary,
12.0f);
drawList.AddText(
UIPoint(layout.stateRect.x + 16.0f, layout.stateRect.y + 310.0f),
"Flags: " + m_resultFlags,
kTextWeak,
12.0f);
const std::string captureSummary =
m_autoScreenshot.HasPendingCapture()
? "截图排队中..."
: (m_autoScreenshot.GetLastCaptureSummary().empty()
? std::string("F12 -> tests/UI/Editor/integration/shell/tree_view_multiselect/captures/")
: m_autoScreenshot.GetLastCaptureSummary());
drawList.AddText(
UIPoint(layout.stateRect.x + 16.0f, layout.stateRect.y + 334.0f),
captureSummary,
kTextWeak,
12.0f);
DrawCard(drawList, layout.previewRect, "TreeView 多选预览", "这里只放一个 TreeView用来验证多选与层级展开状态机。");
AppendUIEditorTreeViewBackground(
drawList,
m_treeFrame.layout,
m_items,
m_selectionModel,
m_interactionState.treeViewState);
AppendUIEditorTreeViewForeground(drawList, m_treeFrame.layout, m_items);
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::vector<UIEditorTreeViewItem> m_items = {};
UISelectionModel m_selectionModel = {};
UIExpansionModel m_expansionModel = {};
UIEditorTreeViewInteractionState m_interactionState = {};
UIEditorTreeViewInteractionFrame m_treeFrame = {};
UIPoint m_mousePosition = UIPoint(-1000.0f, -1000.0f);
ActionId m_hoveredAction = ActionId::Reset;
bool m_hasHoveredAction = false;
std::string m_lastResult = {};
std::string m_resultFlags = {};
};
} // namespace
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, LPWSTR, int nCmdShow) {
return ScenarioApp().Run(hInstance, nCmdShow);
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 89 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 89 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

View File

@@ -2,6 +2,7 @@
#define NOMINMAX
#endif
#include <XCEditor/Core/UIEditorDockHostInteraction.h>
#include <XCEditor/Core/UIEditorPanelRegistry.h>
#include <XCEditor/Core/UIEditorWorkspaceController.h>
#include <XCEditor/Core/UIEditorWorkspaceModel.h>
@@ -10,7 +11,6 @@
#include "Host/NativeRenderer.h"
#include <XCEngine/UI/DrawData.h>
#include <XCEngine/UI/Widgets/UISplitterInteraction.h>
#include <windows.h>
#include <windowsx.h>
@@ -31,12 +31,11 @@ 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::Widgets::BeginUISplitterDrag;
using XCEngine::UI::Widgets::EndUISplitterDrag;
using XCEngine::UI::Widgets::UISplitterDragState;
using XCEngine::UI::Widgets::UpdateUISplitterDrag;
using XCEngine::UI::Editor::BuildDefaultUIEditorWorkspaceController;
using XCEngine::UI::Editor::BuildUIEditorWorkspacePanel;
using XCEngine::UI::Editor::BuildUIEditorWorkspaceSplit;
@@ -46,26 +45,22 @@ using XCEngine::UI::Editor::GetUIEditorWorkspaceCommandStatusName;
using XCEngine::UI::Editor::GetUIEditorWorkspaceLayoutOperationStatusName;
using XCEngine::UI::Editor::Host::AutoScreenshotController;
using XCEngine::UI::Editor::Host::NativeRenderer;
using XCEngine::UI::Editor::TrySetUIEditorWorkspaceSplitRatio;
using XCEngine::UI::Editor::UIEditorDockHostInteractionFrame;
using XCEngine::UI::Editor::UIEditorDockHostInteractionResult;
using XCEngine::UI::Editor::UIEditorDockHostInteractionState;
using XCEngine::UI::Editor::UIEditorPanelRegistry;
using XCEngine::UI::Editor::UIEditorWorkspaceCommand;
using XCEngine::UI::Editor::UIEditorWorkspaceCommandKind;
using XCEngine::UI::Editor::UIEditorWorkspaceCommandResult;
using XCEngine::UI::Editor::UIEditorWorkspaceCommandStatus;
using XCEngine::UI::Editor::UIEditorWorkspaceController;
using XCEngine::UI::Editor::UIEditorWorkspaceLayoutOperationStatus;
using XCEngine::UI::Editor::UIEditorWorkspaceModel;
using XCEngine::UI::Editor::UIEditorWorkspaceNode;
using XCEngine::UI::Editor::UIEditorWorkspaceNodeKind;
using XCEngine::UI::Editor::UIEditorWorkspaceSplitAxis;
using XCEngine::UI::Editor::UpdateUIEditorDockHostInteraction;
using XCEngine::UI::Editor::Widgets::AppendUIEditorDockHostBackground;
using XCEngine::UI::Editor::Widgets::AppendUIEditorDockHostForeground;
using XCEngine::UI::Editor::Widgets::BuildUIEditorDockHostLayout;
using XCEngine::UI::Editor::Widgets::FindUIEditorDockHostSplitterLayout;
using XCEngine::UI::Editor::Widgets::HitTestUIEditorDockHost;
using XCEngine::UI::Editor::Widgets::UIEditorDockHostHitTarget;
using XCEngine::UI::Editor::Widgets::UIEditorDockHostHitTargetKind;
using XCEngine::UI::Editor::Widgets::UIEditorDockHostLayout;
using XCEngine::UI::Editor::Widgets::UIEditorDockHostState;
using XCEngine::UI::Editor::Widgets::UIEditorTabStripInvalidIndex;
constexpr const wchar_t* kWindowClassName = L"XCUIEditorWorkspaceShellComposeValidation";
constexpr const wchar_t* kWindowTitle = L"XCUI Editor | Workspace Shell Compose";
@@ -77,6 +72,7 @@ constexpr UIColor kTextPrimary(0.94f, 0.94f, 0.94f, 1.0f);
constexpr UIColor kTextMuted(0.73f, 0.73f, 0.73f, 1.0f);
constexpr UIColor kTextWeak(0.58f, 0.58f, 0.58f, 1.0f);
constexpr UIColor kSuccess(0.63f, 0.76f, 0.63f, 1.0f);
constexpr UIColor kWarning(0.82f, 0.67f, 0.35f, 1.0f);
constexpr UIColor kDanger(0.82f, 0.50f, 0.50f, 1.0f);
constexpr UIColor kButtonBg(0.26f, 0.26f, 0.26f, 1.0f);
constexpr UIColor kButtonHoveredBg(0.34f, 0.34f, 0.34f, 1.0f);
@@ -97,15 +93,6 @@ bool ContainsPoint(const UIRect& rect, float x, float y) {
y <= rect.y + rect.height;
}
bool AreTargetsEqual(
const UIEditorDockHostHitTarget& lhs,
const UIEditorDockHostHitTarget& rhs) {
return lhs.kind == rhs.kind &&
lhs.nodeId == rhs.nodeId &&
lhs.panelId == rhs.panelId &&
lhs.index == rhs.index;
}
void DrawCard(
UIDrawList& drawList,
const UIRect& rect,
@@ -285,6 +272,7 @@ private:
break;
case WM_LBUTTONDOWN:
if (app != nullptr) {
SetFocus(hwnd);
app->HandleLeftButtonDown(
static_cast<float>(GET_X_LPARAM(lParam)),
static_cast<float>(GET_Y_LPARAM(lParam)));
@@ -299,6 +287,32 @@ private:
return 0;
}
break;
case WM_SETFOCUS:
if (app != nullptr) {
UIInputEvent eventInput = {};
eventInput.type = UIInputEventType::FocusGained;
app->m_pendingInputEvents.push_back(eventInput);
return 0;
}
break;
case WM_KILLFOCUS:
if (app != nullptr) {
UIInputEvent eventInput = {};
eventInput.type = UIInputEventType::FocusLost;
app->m_pendingInputEvents.push_back(eventInput);
return 0;
}
break;
case WM_CAPTURECHANGED:
if (app != nullptr &&
app->m_interactionState.splitterDragState.active &&
reinterpret_cast<HWND>(lParam) != hwnd) {
UIInputEvent eventInput = {};
eventInput.type = UIInputEventType::FocusLost;
app->m_pendingInputEvents.push_back(eventInput);
return 0;
}
break;
case WM_KEYDOWN:
case WM_SYSKEYDOWN:
if (app != nullptr && wParam == VK_F12) {
@@ -342,7 +356,6 @@ private:
windowClass.hInstance = hInstance;
windowClass.hCursor = LoadCursorW(nullptr, IDC_ARROW);
windowClass.lpszClassName = kWindowClassName;
m_windowClassAtom = RegisterClassExW(&windowClass);
if (m_windowClassAtom == 0) {
return false;
@@ -377,6 +390,9 @@ private:
}
void Shutdown() {
if (GetCapture() == m_hwnd) {
ReleaseCapture();
}
m_autoScreenshot.Shutdown();
m_renderer.Shutdown();
@@ -392,18 +408,19 @@ private:
}
void ResetScenario() {
if (GetCapture() == m_hwnd) {
ReleaseCapture();
}
m_controller =
BuildDefaultUIEditorWorkspaceController(BuildPanelRegistry(), BuildWorkspace());
m_dockState = {};
m_layout = {};
m_dragState = {};
m_dragSplitterNodeId.clear();
m_interactionState = {};
m_cachedFrame = {};
m_pendingInputEvents.clear();
m_mousePosition = UIPoint(-1000.0f, -1000.0f);
m_resetHovered = false;
m_resetPressed = false;
m_lastResult = "等待操作";
UpdateSceneRects();
RefreshLayout();
UpdateHoverTarget();
}
void OnResize(UINT width, UINT height) {
@@ -423,8 +440,8 @@ private:
constexpr float outerPadding = 20.0f;
constexpr float leftColumnWidth = 380.0f;
m_introRect = UIRect(outerPadding, outerPadding, leftColumnWidth, 192.0f);
m_stateRect = UIRect(outerPadding, 228.0f, leftColumnWidth, height - 248.0f);
m_introRect = UIRect(outerPadding, outerPadding, leftColumnWidth, 212.0f);
m_stateRect = UIRect(outerPadding, 248.0f, leftColumnWidth, height - 268.0f);
m_previewCardRect = UIRect(
leftColumnWidth + outerPadding * 2.0f,
outerPadding,
@@ -442,23 +459,6 @@ private:
38.0f);
}
void RefreshLayout() {
m_layout = BuildUIEditorDockHostLayout(
m_previewRect,
m_controller.GetPanelRegistry(),
m_controller.GetWorkspace(),
m_controller.GetSession(),
m_dockState);
}
void UpdateHoverTarget() {
UIEditorDockHostHitTarget hoveredTarget = HitTestUIEditorDockHost(m_layout, m_mousePosition);
if (!AreTargetsEqual(hoveredTarget, m_dockState.hoveredTarget)) {
m_dockState.hoveredTarget = std::move(hoveredTarget);
RefreshLayout();
}
}
void HandleMouseMove(float x, float y) {
m_mousePosition = UIPoint(x, y);
TRACKMOUSEEVENT event = {};
@@ -470,79 +470,38 @@ private:
UpdateSceneRects();
m_resetHovered = ContainsPoint(m_resetButtonRect, x, y);
if (m_dragState.active) {
XCEngine::UI::Layout::UISplitterLayoutResult draggedLayout = {};
if (UpdateUISplitterDrag(m_dragState, m_mousePosition, draggedLayout)) {
ApplyDraggedSplitterRatio(draggedLayout.splitRatio);
} else {
RefreshLayout();
}
m_dockState.hoveredTarget = {
UIEditorDockHostHitTargetKind::SplitterHandle,
m_dragSplitterNodeId,
{},
UIEditorTabStripInvalidIndex
};
m_dockState.activeSplitterNodeId = m_dragSplitterNodeId;
RefreshLayout();
InvalidateRect(m_hwnd, nullptr, FALSE);
return;
}
RefreshLayout();
UpdateHoverTarget();
UIInputEvent eventInput = {};
eventInput.type = UIInputEventType::PointerMove;
eventInput.position = m_mousePosition;
m_pendingInputEvents.push_back(eventInput);
InvalidateRect(m_hwnd, nullptr, FALSE);
}
void HandleMouseLeave() {
if (m_dragState.active) {
return;
}
m_mousePosition = UIPoint(-1000.0f, -1000.0f);
m_resetHovered = false;
m_dockState.hoveredTarget = {};
RefreshLayout();
UIInputEvent eventInput = {};
eventInput.type = UIInputEventType::PointerLeave;
eventInput.position = m_mousePosition;
m_pendingInputEvents.push_back(eventInput);
InvalidateRect(m_hwnd, nullptr, FALSE);
}
void HandleLeftButtonDown(float x, float y) {
UpdateSceneRects();
m_mousePosition = UIPoint(x, y);
m_dockState.focused = true;
RefreshLayout();
UpdateHoverTarget();
const UIEditorDockHostHitTarget hit = m_dockState.hoveredTarget;
if (hit.kind != UIEditorDockHostHitTargetKind::SplitterHandle) {
m_resetPressed = ContainsPoint(m_resetButtonRect, x, y);
if (m_resetPressed) {
InvalidateRect(m_hwnd, nullptr, FALSE);
return;
}
const auto* splitter = FindUIEditorDockHostSplitterLayout(m_layout, hit.nodeId);
if (splitter == nullptr) {
return;
}
if (!BeginUISplitterDrag(
1u,
splitter->axis == UIEditorWorkspaceSplitAxis::Horizontal
? XCEngine::UI::Layout::UILayoutAxis::Horizontal
: XCEngine::UI::Layout::UILayoutAxis::Vertical,
splitter->bounds,
splitter->splitterLayout,
splitter->constraints,
splitter->metrics,
m_mousePosition,
m_dragState)) {
return;
}
m_dragSplitterNodeId = splitter->nodeId;
m_dockState.activeSplitterNodeId = splitter->nodeId;
SetCapture(m_hwnd);
m_lastResult = "开始拖拽 splitter: " + splitter->nodeId;
RefreshLayout();
UIInputEvent eventInput = {};
eventInput.type = UIInputEventType::PointerButtonDown;
eventInput.position = m_mousePosition;
eventInput.pointerButton = UIPointerButton::Left;
m_pendingInputEvents.push_back(eventInput);
InvalidateRect(m_hwnd, nullptr, FALSE);
}
@@ -550,115 +509,81 @@ private:
UpdateSceneRects();
m_mousePosition = UIPoint(x, y);
if (m_dragState.active) {
XCEngine::UI::Layout::UISplitterLayoutResult draggedLayout = {};
if (UpdateUISplitterDrag(m_dragState, m_mousePosition, draggedLayout)) {
ApplyDraggedSplitterRatio(draggedLayout.splitRatio);
}
EndUISplitterDrag(m_dragState);
m_dockState.activeSplitterNodeId.clear();
if (GetCapture() == m_hwnd) {
ReleaseCapture();
}
m_lastResult = "结束拖拽 splitter: " + m_dragSplitterNodeId;
m_dragSplitterNodeId.clear();
RefreshLayout();
UpdateHoverTarget();
InvalidateRect(m_hwnd, nullptr, FALSE);
return;
}
if (ContainsPoint(m_resetButtonRect, x, y)) {
const bool resetTriggered = m_resetPressed && ContainsPoint(m_resetButtonRect, x, y);
m_resetPressed = false;
if (resetTriggered) {
ResetScenario();
m_lastResult = "Reset";
InvalidateRect(m_hwnd, nullptr, FALSE);
return;
}
RefreshLayout();
UpdateHoverTarget();
ExecuteClick(m_dockState.hoveredTarget);
RefreshLayout();
UpdateHoverTarget();
UIInputEvent eventInput = {};
eventInput.type = UIInputEventType::PointerButtonUp;
eventInput.position = m_mousePosition;
eventInput.pointerButton = UIPointerButton::Left;
m_pendingInputEvents.push_back(eventInput);
InvalidateRect(m_hwnd, nullptr, FALSE);
}
void ExecuteClick(const UIEditorDockHostHitTarget& hit) {
switch (hit.kind) {
case UIEditorDockHostHitTargetKind::Tab:
DispatchWorkspaceCommand(
UIEditorWorkspaceCommandKind::ActivatePanel,
hit.panelId,
"Activate Tab");
return;
case UIEditorDockHostHitTargetKind::TabCloseButton:
DispatchWorkspaceCommand(
UIEditorWorkspaceCommandKind::ClosePanel,
hit.panelId,
"Close Tab");
return;
case UIEditorDockHostHitTargetKind::PanelHeader:
case UIEditorDockHostHitTargetKind::PanelBody:
case UIEditorDockHostHitTargetKind::PanelFooter:
DispatchWorkspaceCommand(
UIEditorWorkspaceCommandKind::ActivatePanel,
hit.panelId,
"Activate Panel");
return;
case UIEditorDockHostHitTargetKind::PanelCloseButton:
DispatchWorkspaceCommand(
UIEditorWorkspaceCommandKind::ClosePanel,
hit.panelId,
"Close Panel");
return;
case UIEditorDockHostHitTargetKind::TabStripBackground:
m_lastResult = "DockHost focus = On";
return;
case UIEditorDockHostHitTargetKind::None:
default:
m_dockState.focused = false;
m_lastResult = "DockHost focus = Off";
return;
void ApplyHostCaptureRequests(const UIEditorDockHostInteractionResult& result) {
if (result.requestPointerCapture && GetCapture() != m_hwnd) {
SetCapture(m_hwnd);
}
if (result.releasePointerCapture && GetCapture() == m_hwnd) {
ReleaseCapture();
}
}
void DispatchWorkspaceCommand(
UIEditorWorkspaceCommandKind kind,
std::string_view panelId,
std::string_view label) {
UIEditorWorkspaceCommand command = {};
command.kind = kind;
command.panelId = std::string(panelId);
const UIEditorWorkspaceCommandResult result = m_controller.Dispatch(command);
m_lastResult =
std::string(label) + " -> " +
std::string(GetUIEditorWorkspaceCommandStatusName(result.status)) +
" | " +
result.message;
}
void ApplyDraggedSplitterRatio(float splitRatio) {
auto snapshot = m_controller.CaptureLayoutSnapshot();
if (!TrySetUIEditorWorkspaceSplitRatio(snapshot.workspace, m_dragSplitterNodeId, splitRatio)) {
void SetInteractionResult(const UIEditorDockHostInteractionResult& result) {
if (result.layoutResult.status != UIEditorWorkspaceLayoutOperationStatus::Rejected) {
m_lastResult =
std::string("Layout: ") +
std::string(GetUIEditorWorkspaceLayoutOperationStatusName(result.layoutResult.status)) +
" | " +
(result.layoutResult.message.empty() ? "layout updated" : result.layoutResult.message);
return;
}
const auto result = m_controller.RestoreLayoutSnapshot(snapshot);
std::ostringstream stream;
stream.setf(std::ios::fixed, std::ios::floatfield);
stream.precision(2);
stream << "Drag " << m_dragSplitterNodeId << " -> "
<< GetUIEditorWorkspaceLayoutOperationStatusName(result.status)
<< " | ratio=" << splitRatio;
m_lastResult = stream.str();
RefreshLayout();
if (result.commandResult.status != UIEditorWorkspaceCommandStatus::Rejected) {
m_lastResult =
std::string("Command: ") +
std::string(GetUIEditorWorkspaceCommandStatusName(result.commandResult.status)) +
" | " +
(result.commandResult.message.empty() ? "command handled" : result.commandResult.message);
return;
}
if (result.requestPointerCapture) {
m_lastResult = "Capture: begin splitter drag";
return;
}
if (result.releasePointerCapture) {
m_lastResult = "Capture: end splitter drag";
return;
}
if (result.hitTarget.kind != UIEditorDockHostHitTargetKind::None) {
m_lastResult = "Hover: " + DescribeHitTarget(result.hitTarget);
return;
}
if (result.consumed) {
m_lastResult = "Consumed: input handled by DockHostInteraction";
}
}
void RenderFrame() {
UpdateSceneRects();
RefreshLayout();
UpdateHoverTarget();
m_cachedFrame = UpdateUIEditorDockHostInteraction(
m_interactionState,
m_controller,
m_previewRect,
m_pendingInputEvents);
m_pendingInputEvents.clear();
ApplyHostCaptureRequests(m_cachedFrame.result);
SetInteractionResult(m_cachedFrame.result);
RECT clientRect = {};
GetClientRect(m_hwnd, &clientRect);
@@ -672,54 +597,67 @@ private:
DrawCard(
drawList,
m_introRect,
"测试功能DockHost / Workspace Compose 基础层",
"验证 DockHost 真实 compose、splitter drag、tab host、panel frame 联动,不包含业务面板");
"这个测试在验证什么功能?",
"验证 Workspace + DockHost 的组合场景是否完全收口到统一交互层");
drawList.AddText(
UIPoint(m_introRect.x + 16.0f, m_introRect.y + 68.0f),
"重点检查:三条 splitter 的 resize 是否稳定;关闭面板后 branch 是否正确 collapse点击 tab / panel 是否同步 active",
"1. splitter drag 只能通过 UIEditorDockHostInteraction + WorkspaceController 生效",
kTextPrimary,
12.0f);
drawList.AddText(
UIPoint(m_introRect.x + 16.0f, m_introRect.y + 92.0f),
"操作:拖拽 Hierarchy / Documents / Inspector / Console 之间的 splitter点击 Document A/B/C点 X 关闭 tab 或 side panelReset 恢复F12 截图",
kTextMuted,
"2. tab 激活/关闭、panel 激活/关闭都必须统一回到 controller",
kTextPrimary,
12.0f);
drawList.AddText(
UIPoint(m_introRect.x + 16.0f, m_introRect.y + 116.0f),
"预期splitter 会被最小尺寸 clampDocument C 没有 XInspector/Console 关闭后对应分支会收拢,不应留下歪掉的空洞",
kTextWeak,
"3. active panel、visible panels、split ratio 在组合场景里必须同步更新",
kTextPrimary,
12.0f);
drawList.AddText(
UIPoint(m_introRect.x + 16.0f, m_introRect.y + 140.0f),
"4. 操作建议:拖动三个 splitter点击 Document A/B/C关闭 Inspector 或 Console按 F12 截图。",
kTextWeak,
11.0f);
DrawCard(
drawList,
m_stateRect,
"状态回显",
"这里直接回显 hover / focus / dragging / active panel / split ratio,方便人工检查");
"这里直接展示 hover / focus / dragging / active panel / split ratio。");
DrawButton(drawList, m_resetButtonRect, "Reset", m_resetHovered);
const auto validation = m_controller.ValidateState();
drawList.AddText(
UIPoint(m_stateRect.x + 16.0f, m_stateRect.y + 70.0f),
"Hover: " + DescribeHitTarget(m_dockState.hoveredTarget),
"Hover: " + DescribeHitTarget(m_interactionState.dockHostState.hoveredTarget),
kTextPrimary,
13.0f);
drawList.AddText(
UIPoint(m_stateRect.x + 16.0f, m_stateRect.y + 96.0f),
std::string("Focused: ") + (m_dockState.focused ? "On" : "Off"),
kTextPrimary,
std::string("Focused: ") + (m_cachedFrame.focused ? "On" : "Off"),
m_cachedFrame.focused ? kSuccess : kTextMuted,
13.0f);
drawList.AddText(
UIPoint(m_stateRect.x + 16.0f, m_stateRect.y + 122.0f),
"Dragging: " + (m_dragSplitterNodeId.empty() ? std::string("(none)") : m_dragSplitterNodeId),
kTextPrimary,
"Capture: " + std::string(GetCapture() == m_hwnd ? "On" : "Off"),
GetCapture() == m_hwnd ? kSuccess : kTextMuted,
13.0f);
drawList.AddText(
UIPoint(m_stateRect.x + 16.0f, m_stateRect.y + 148.0f),
"Active Panel: " + m_controller.GetWorkspace().activePanelId,
"Dragging: " +
(m_interactionState.dockHostState.activeSplitterNodeId.empty()
? std::string("(none)")
: m_interactionState.dockHostState.activeSplitterNodeId),
kTextPrimary,
13.0f);
drawList.AddText(
UIPoint(m_stateRect.x + 16.0f, m_stateRect.y + 174.0f),
"Active Panel: " + m_controller.GetWorkspace().activePanelId,
kTextPrimary,
13.0f);
drawList.AddText(
UIPoint(m_stateRect.x + 16.0f, m_stateRect.y + 198.0f),
"Visible Panels: " + JoinVisiblePanelIds(m_controller),
kTextMuted,
12.0f);
@@ -741,7 +679,7 @@ private:
drawList.AddText(
UIPoint(m_stateRect.x + 16.0f, m_stateRect.y + 356.0f),
"Result: " + m_lastResult,
kTextMuted,
kWarning,
12.0f);
drawList.AddText(
UIPoint(m_stateRect.x + 16.0f, m_stateRect.y + 382.0f),
@@ -765,10 +703,10 @@ private:
drawList,
m_previewCardRect,
"预览区",
"这里只保留一个 DockHost 试验场,不混入业务 UI。");
"这里只保留一个 DockHost 组合试验场,不混入业务 UI。");
AppendUIEditorDockHostBackground(drawList, m_layout);
AppendUIEditorDockHostForeground(drawList, m_layout);
AppendUIEditorDockHostBackground(drawList, m_cachedFrame.layout);
AppendUIEditorDockHostForeground(drawList, m_cachedFrame.layout);
const bool framePresented = m_renderer.Render(drawData);
m_autoScreenshot.CaptureIfRequested(
@@ -785,10 +723,9 @@ private:
AutoScreenshotController m_autoScreenshot = {};
std::filesystem::path m_captureRoot = {};
UIEditorWorkspaceController m_controller = {};
UIEditorDockHostState m_dockState = {};
UIEditorDockHostLayout m_layout = {};
UISplitterDragState m_dragState = {};
std::string m_dragSplitterNodeId = {};
UIEditorDockHostInteractionState m_interactionState = {};
UIEditorDockHostInteractionFrame m_cachedFrame = {};
std::vector<UIInputEvent> m_pendingInputEvents = {};
UIPoint m_mousePosition = UIPoint(-1000.0f, -1000.0f);
UIRect m_introRect = {};
UIRect m_stateRect = {};
@@ -796,6 +733,7 @@ private:
UIRect m_previewRect = {};
UIRect m_resetButtonRect = {};
bool m_resetHovered = false;
bool m_resetPressed = false;
std::string m_lastResult = {};
};

View File

@@ -24,6 +24,7 @@ set(EDITOR_UI_UNIT_TEST_SOURCES
test_ui_editor_color_field.cpp
test_ui_editor_color_field_interaction.cpp
test_ui_editor_dock_host.cpp
test_ui_editor_inline_rename_session.cpp
test_ui_editor_list_view.cpp
test_ui_editor_list_view_interaction.cpp
test_ui_editor_panel_chrome.cpp
@@ -44,6 +45,7 @@ set(EDITOR_UI_UNIT_TEST_SOURCES
test_ui_editor_scroll_view_interaction.cpp
test_ui_editor_status_bar.cpp
test_ui_editor_tab_strip.cpp
test_ui_editor_tab_strip_interaction.cpp
test_ui_editor_tree_view.cpp
test_ui_editor_tree_view_interaction.cpp
test_ui_editor_viewport_input_bridge.cpp

View File

@@ -1,6 +1,6 @@
#include <gtest/gtest.h>
#include <XCEditor/Core/UIEditorCommandDispatcher.h>
#include <XCEditor/Foundation/UIEditorCommandDispatcher.h>
namespace {

View File

@@ -1,6 +1,6 @@
#include <gtest/gtest.h>
#include <XCEditor/Core/UIEditorCommandRegistry.h>
#include <XCEditor/Foundation/UIEditorCommandRegistry.h>
namespace {

View File

@@ -1,5 +1,6 @@
#include <gtest/gtest.h>
#include <XCEngine/Input/InputTypes.h>
#include <XCEditor/Core/UIEditorDockHostInteraction.h>
#include <XCEditor/Core/UIEditorWorkspaceController.h>
#include <XCEditor/Core/UIEditorWorkspaceModel.h>
@@ -11,6 +12,7 @@ using XCEngine::UI::UIInputEventType;
using XCEngine::UI::UIPoint;
using XCEngine::UI::UIRect;
using XCEngine::UI::UIPointerButton;
using XCEngine::Input::KeyCode;
using XCEngine::UI::Editor::BuildDefaultUIEditorWorkspaceController;
using XCEngine::UI::Editor::BuildUIEditorWorkspacePanel;
using XCEngine::UI::Editor::BuildUIEditorWorkspaceSplit;
@@ -86,6 +88,13 @@ UIInputEvent MakeFocusLost() {
return event;
}
UIInputEvent MakeKeyDown(KeyCode keyCode) {
UIInputEvent event = {};
event.type = UIInputEventType::KeyDown;
event.keyCode = static_cast<std::int32_t>(keyCode);
return event;
}
UIPoint RectCenter(const UIRect& rect) {
return UIPoint(rect.x + rect.width * 0.5f, rect.y + rect.height * 0.5f);
}
@@ -184,6 +193,14 @@ TEST(UIEditorDockHostInteractionTest, ClickingTabActivatesTargetPanel) {
EXPECT_EQ(frame.result.hitTarget.kind, UIEditorDockHostHitTargetKind::Tab);
EXPECT_EQ(frame.result.hitTarget.panelId, "doc-a");
frame = UpdateUIEditorDockHostInteraction(
state,
controller,
UIRect(0.0f, 0.0f, 800.0f, 600.0f),
{ MakePointerDown(RectCenter(docARect).x, RectCenter(docARect).y) });
EXPECT_TRUE(frame.result.consumed);
EXPECT_FALSE(frame.result.commandExecuted);
frame = UpdateUIEditorDockHostInteraction(
state,
controller,
@@ -218,6 +235,14 @@ TEST(UIEditorDockHostInteractionTest, ClickingTabCloseClosesPanelThroughControll
EXPECT_EQ(frame.result.hitTarget.kind, UIEditorDockHostHitTargetKind::TabCloseButton);
EXPECT_EQ(frame.result.hitTarget.panelId, "doc-b");
frame = UpdateUIEditorDockHostInteraction(
state,
controller,
UIRect(0.0f, 0.0f, 800.0f, 600.0f),
{ MakePointerDown(closeCenter.x, closeCenter.y) });
EXPECT_TRUE(frame.result.consumed);
EXPECT_FALSE(frame.result.commandExecuted);
frame = UpdateUIEditorDockHostInteraction(
state,
controller,
@@ -233,6 +258,84 @@ TEST(UIEditorDockHostInteractionTest, ClickingTabCloseClosesPanelThroughControll
EXPECT_EQ(controller.GetWorkspace().activePanelId, "doc-a");
}
TEST(UIEditorDockHostInteractionTest, FocusedTabStripHandlesKeyboardNavigationThroughTabStripInteraction) {
auto controller =
BuildDefaultUIEditorWorkspaceController(BuildPanelRegistry(), BuildWorkspace());
UIEditorDockHostInteractionState state = {};
auto frame = UpdateUIEditorDockHostInteraction(
state,
controller,
UIRect(0.0f, 0.0f, 800.0f, 600.0f),
{});
ASSERT_EQ(frame.layout.tabStacks.size(), 1u);
const UIRect docARect = frame.layout.tabStacks.front().tabStripLayout.tabHeaderRects[0];
const UIPoint docACenter = RectCenter(docARect);
frame = UpdateUIEditorDockHostInteraction(
state,
controller,
UIRect(0.0f, 0.0f, 800.0f, 600.0f),
{ MakePointerMove(docACenter.x, docACenter.y) });
EXPECT_EQ(frame.result.hitTarget.kind, UIEditorDockHostHitTargetKind::Tab);
frame = UpdateUIEditorDockHostInteraction(
state,
controller,
UIRect(0.0f, 0.0f, 800.0f, 600.0f),
{ MakePointerDown(docACenter.x, docACenter.y) });
EXPECT_TRUE(frame.result.consumed);
frame = UpdateUIEditorDockHostInteraction(
state,
controller,
UIRect(0.0f, 0.0f, 800.0f, 600.0f),
{ MakePointerUp(docACenter.x, docACenter.y) });
EXPECT_TRUE(frame.result.commandExecuted);
EXPECT_EQ(controller.GetWorkspace().activePanelId, "doc-a");
frame = UpdateUIEditorDockHostInteraction(
state,
controller,
UIRect(0.0f, 0.0f, 800.0f, 600.0f),
{ MakeKeyDown(KeyCode::Right) });
EXPECT_TRUE(frame.result.consumed);
EXPECT_TRUE(frame.result.commandExecuted);
EXPECT_EQ(controller.GetWorkspace().activePanelId, "doc-b");
ASSERT_EQ(frame.layout.tabStacks.size(), 1u);
EXPECT_EQ(frame.layout.tabStacks.front().selectedPanelId, "doc-b");
}
TEST(UIEditorDockHostInteractionTest, BatchedPointerMoveDownUpActivatesTabInSameUpdateCall) {
auto controller =
BuildDefaultUIEditorWorkspaceController(BuildPanelRegistry(), BuildWorkspace());
UIEditorDockHostInteractionState state = {};
auto frame = UpdateUIEditorDockHostInteraction(
state,
controller,
UIRect(0.0f, 0.0f, 800.0f, 600.0f),
{});
ASSERT_EQ(frame.layout.tabStacks.size(), 1u);
const UIPoint docACenter =
RectCenter(frame.layout.tabStacks.front().tabStripLayout.tabHeaderRects[0]);
frame = UpdateUIEditorDockHostInteraction(
state,
controller,
UIRect(0.0f, 0.0f, 800.0f, 600.0f),
{
MakePointerMove(docACenter.x, docACenter.y),
MakePointerDown(docACenter.x, docACenter.y),
MakePointerUp(docACenter.x, docACenter.y)
});
EXPECT_TRUE(frame.result.consumed);
EXPECT_TRUE(frame.result.commandExecuted);
EXPECT_EQ(controller.GetWorkspace().activePanelId, "doc-a");
ASSERT_EQ(frame.layout.tabStacks.size(), 1u);
EXPECT_EQ(frame.layout.tabStacks.front().selectedPanelId, "doc-a");
}
TEST(UIEditorDockHostInteractionTest, ClickingStandalonePanelBodyActivatesTargetPanel) {
auto controller =
BuildDefaultUIEditorWorkspaceController(BuildPanelRegistry(), BuildWorkspace());

View File

@@ -0,0 +1,124 @@
#include <gtest/gtest.h>
#include <XCEditor/Collections/UIEditorInlineRenameSession.h>
#include <XCEngine/Input/InputTypes.h>
namespace {
using XCEngine::Input::KeyCode;
using XCEngine::UI::UIInputEvent;
using XCEngine::UI::UIInputEventType;
using XCEngine::UI::UIRect;
using XCEngine::UI::Editor::UIEditorInlineRenameSessionRequest;
using XCEngine::UI::Editor::UIEditorInlineRenameSessionState;
using XCEngine::UI::Editor::UpdateUIEditorInlineRenameSession;
UIInputEvent MakeKeyDown(KeyCode keyCode) {
UIInputEvent event = {};
event.type = UIInputEventType::KeyDown;
event.keyCode = static_cast<std::int32_t>(keyCode);
return event;
}
UIInputEvent MakeCharacter(char character) {
UIInputEvent event = {};
event.type = UIInputEventType::Character;
event.character = static_cast<std::uint32_t>(character);
return event;
}
UIInputEvent MakeFocusLost() {
UIInputEvent event = {};
event.type = UIInputEventType::FocusLost;
return event;
}
UIEditorInlineRenameSessionRequest MakeRequest(bool beginSession = false) {
UIEditorInlineRenameSessionRequest request = {};
request.beginSession = beginSession;
request.itemId = "camera";
request.initialText = "Camera";
request.bounds = UIRect(10.0f, 20.0f, 180.0f, 24.0f);
return request;
}
} // namespace
TEST(UIEditorInlineRenameSessionTest, BeginRequestStartsActiveEditingSession) {
UIEditorInlineRenameSessionState state = {};
const auto frame = UpdateUIEditorInlineRenameSession(
state,
MakeRequest(true),
{});
EXPECT_TRUE(frame.result.sessionStarted);
EXPECT_TRUE(frame.result.active);
EXPECT_EQ(frame.result.itemId, "camera");
EXPECT_TRUE(state.active);
EXPECT_EQ(state.itemId, "camera");
EXPECT_TRUE(state.textFieldInteraction.textFieldState.focused);
EXPECT_TRUE(state.textFieldInteraction.textFieldState.editing);
EXPECT_EQ(state.textFieldInteraction.textFieldState.displayText, "Camera");
}
TEST(UIEditorInlineRenameSessionTest, EnterCommitsEditedValueAndClosesSession) {
UIEditorInlineRenameSessionState state = {};
UpdateUIEditorInlineRenameSession(state, MakeRequest(true), {});
UpdateUIEditorInlineRenameSession(
state,
MakeRequest(false),
{ MakeCharacter('2') });
const auto frame = UpdateUIEditorInlineRenameSession(
state,
MakeRequest(false),
{ MakeKeyDown(KeyCode::Enter) });
EXPECT_TRUE(frame.result.sessionCommitted);
EXPECT_TRUE(frame.result.valueChanged);
EXPECT_EQ(frame.result.valueBefore, "Camera");
EXPECT_EQ(frame.result.valueAfter, "Camera2");
EXPECT_FALSE(state.active);
}
TEST(UIEditorInlineRenameSessionTest, EscapeCancelsEditedValueAndClosesSession) {
UIEditorInlineRenameSessionState state = {};
UpdateUIEditorInlineRenameSession(state, MakeRequest(true), {});
UpdateUIEditorInlineRenameSession(
state,
MakeRequest(false),
{ MakeCharacter('X') });
const auto frame = UpdateUIEditorInlineRenameSession(
state,
MakeRequest(false),
{ MakeKeyDown(KeyCode::Escape) });
EXPECT_TRUE(frame.result.sessionCanceled);
EXPECT_EQ(frame.result.valueBefore, "Camera");
EXPECT_EQ(frame.result.valueAfter, "Camera");
EXPECT_FALSE(state.active);
}
TEST(UIEditorInlineRenameSessionTest, FocusLostCommitsEditedValue) {
UIEditorInlineRenameSessionState state = {};
UpdateUIEditorInlineRenameSession(state, MakeRequest(true), {});
UpdateUIEditorInlineRenameSession(
state,
MakeRequest(false),
{ MakeCharacter('X') });
const auto frame = UpdateUIEditorInlineRenameSession(
state,
MakeRequest(false),
{ MakeFocusLost() });
EXPECT_TRUE(frame.result.sessionCommitted);
EXPECT_EQ(frame.result.valueAfter, "CameraX");
EXPECT_FALSE(state.active);
}

View File

@@ -1,6 +1,6 @@
#include <gtest/gtest.h>
#include <XCEditor/Widgets/UIEditorListView.h>
#include <XCEditor/Collections/UIEditorListView.h>
namespace {

View File

@@ -1,6 +1,6 @@
#include <gtest/gtest.h>
#include <XCEditor/Core/UIEditorListViewInteraction.h>
#include <XCEditor/Collections/UIEditorListViewInteraction.h>
#include <XCEngine/Input/InputTypes.h>
@@ -9,6 +9,7 @@ namespace {
using XCEngine::Input::KeyCode;
using XCEngine::UI::UIInputEvent;
using XCEngine::UI::UIInputEventType;
using XCEngine::UI::UIInputModifiers;
using XCEngine::UI::UIPoint;
using XCEngine::UI::UIPointerButton;
using XCEngine::UI::UIRect;
@@ -27,6 +28,18 @@ std::vector<UIEditorListViewItem> BuildListItems() {
};
}
UIInputModifiers MakeShiftModifiers() {
UIInputModifiers modifiers = {};
modifiers.shift = true;
return modifiers;
}
UIInputModifiers MakeControlModifiers() {
UIInputModifiers modifiers = {};
modifiers.control = true;
return modifiers;
}
UIInputEvent MakePointerMove(float x, float y) {
UIInputEvent event = {};
event.type = UIInputEventType::PointerMove;
@@ -34,26 +47,37 @@ UIInputEvent MakePointerMove(float x, float y) {
return event;
}
UIInputEvent MakePointerDown(float x, float y, UIPointerButton button = UIPointerButton::Left) {
UIInputEvent MakePointerDown(
float x,
float y,
UIPointerButton button = UIPointerButton::Left,
UIInputModifiers modifiers = {}) {
UIInputEvent event = {};
event.type = UIInputEventType::PointerButtonDown;
event.position = UIPoint(x, y);
event.pointerButton = button;
event.modifiers = modifiers;
return event;
}
UIInputEvent MakePointerUp(float x, float y, UIPointerButton button = UIPointerButton::Left) {
UIInputEvent MakePointerUp(
float x,
float y,
UIPointerButton button = UIPointerButton::Left,
UIInputModifiers modifiers = {}) {
UIInputEvent event = {};
event.type = UIInputEventType::PointerButtonUp;
event.position = UIPoint(x, y);
event.pointerButton = button;
event.modifiers = modifiers;
return event;
}
UIInputEvent MakeKeyDown(KeyCode keyCode) {
UIInputEvent MakeKeyDown(KeyCode keyCode, UIInputModifiers modifiers = {}) {
UIInputEvent event = {};
event.type = UIInputEventType::KeyDown;
event.keyCode = static_cast<std::int32_t>(keyCode);
event.modifiers = modifiers;
return event;
}
@@ -163,6 +187,124 @@ TEST(UIEditorListViewInteractionTest, RightClickRowSelectsItemAndMarksSecondaryC
EXPECT_TRUE(state.listViewState.focused);
}
TEST(UIEditorListViewInteractionTest, ControlClickRowTogglesMembershipWithoutDroppingExistingSelection) {
const auto items = BuildListItems();
UISelectionModel selectionModel = {};
selectionModel.SetSelections({ "material", "script" }, "script");
UIEditorListViewInteractionState state = {};
state.listViewState.focused = true;
state.selectionAnchorId = "script";
const auto initialFrame = UpdateUIEditorListViewInteraction(
state,
selectionModel,
UIRect(0.0f, 0.0f, 320.0f, 240.0f),
items,
{});
const UIPoint sceneCenter = RectCenter(initialFrame.layout.rowRects[0]);
auto frame = UpdateUIEditorListViewInteraction(
state,
selectionModel,
UIRect(0.0f, 0.0f, 320.0f, 240.0f),
items,
{
MakePointerDown(sceneCenter.x, sceneCenter.y, UIPointerButton::Left, MakeControlModifiers()),
MakePointerUp(sceneCenter.x, sceneCenter.y, UIPointerButton::Left, MakeControlModifiers())
});
EXPECT_TRUE(frame.result.selectionChanged);
EXPECT_TRUE(selectionModel.IsSelected("scene"));
EXPECT_TRUE(selectionModel.IsSelected("material"));
EXPECT_TRUE(selectionModel.IsSelected("script"));
EXPECT_EQ(selectionModel.GetSelectedId(), "scene");
const UIPoint scriptCenter = RectCenter(initialFrame.layout.rowRects[2]);
frame = UpdateUIEditorListViewInteraction(
state,
selectionModel,
UIRect(0.0f, 0.0f, 320.0f, 240.0f),
items,
{
MakePointerDown(scriptCenter.x, scriptCenter.y, UIPointerButton::Left, MakeControlModifiers()),
MakePointerUp(scriptCenter.x, scriptCenter.y, UIPointerButton::Left, MakeControlModifiers())
});
EXPECT_TRUE(frame.result.selectionChanged);
EXPECT_TRUE(selectionModel.IsSelected("scene"));
EXPECT_TRUE(selectionModel.IsSelected("material"));
EXPECT_FALSE(selectionModel.IsSelected("script"));
}
TEST(UIEditorListViewInteractionTest, ShiftClickRowSelectsRangeFromAnchor) {
const auto items = BuildListItems();
UISelectionModel selectionModel = {};
selectionModel.SetSelection("material");
UIEditorListViewInteractionState state = {};
state.listViewState.focused = true;
state.selectionAnchorId = "material";
const auto initialFrame = UpdateUIEditorListViewInteraction(
state,
selectionModel,
UIRect(0.0f, 0.0f, 320.0f, 240.0f),
items,
{});
const UIPoint textureCenter = RectCenter(initialFrame.layout.rowRects[3]);
const auto frame = UpdateUIEditorListViewInteraction(
state,
selectionModel,
UIRect(0.0f, 0.0f, 320.0f, 240.0f),
items,
{
MakePointerDown(textureCenter.x, textureCenter.y, UIPointerButton::Left, MakeShiftModifiers()),
MakePointerUp(textureCenter.x, textureCenter.y, UIPointerButton::Left, MakeShiftModifiers())
});
EXPECT_TRUE(frame.result.selectionChanged);
EXPECT_EQ(frame.result.selectedItemId, "texture");
EXPECT_TRUE(selectionModel.IsSelected("material"));
EXPECT_TRUE(selectionModel.IsSelected("script"));
EXPECT_TRUE(selectionModel.IsSelected("texture"));
EXPECT_EQ(selectionModel.GetSelectionCount(), 3u);
EXPECT_EQ(state.selectionAnchorId, "material");
}
TEST(UIEditorListViewInteractionTest, RightClickSelectedRowKeepsExistingMultiSelection) {
const auto items = BuildListItems();
UISelectionModel selectionModel = {};
selectionModel.SetSelections({ "material", "script", "texture" }, "material");
UIEditorListViewInteractionState state = {};
state.listViewState.focused = true;
state.selectionAnchorId = "material";
const auto initialFrame = UpdateUIEditorListViewInteraction(
state,
selectionModel,
UIRect(0.0f, 0.0f, 320.0f, 240.0f),
items,
{});
const UIPoint scriptCenter = RectCenter(initialFrame.layout.rowRects[2]);
const auto frame = UpdateUIEditorListViewInteraction(
state,
selectionModel,
UIRect(0.0f, 0.0f, 320.0f, 240.0f),
items,
{
MakePointerDown(scriptCenter.x, scriptCenter.y, UIPointerButton::Right),
MakePointerUp(scriptCenter.x, scriptCenter.y, UIPointerButton::Right)
});
EXPECT_TRUE(frame.result.secondaryClicked);
EXPECT_FALSE(frame.result.selectionChanged);
EXPECT_TRUE(selectionModel.IsSelected("material"));
EXPECT_TRUE(selectionModel.IsSelected("script"));
EXPECT_TRUE(selectionModel.IsSelected("texture"));
EXPECT_EQ(selectionModel.GetSelectionCount(), 3u);
EXPECT_EQ(selectionModel.GetSelectedId(), "script");
}
TEST(UIEditorListViewInteractionTest, ArrowAndHomeEndKeysDriveSelectionWhenFocused) {
const auto items = BuildListItems();
UISelectionModel selectionModel = {};
@@ -201,6 +343,50 @@ TEST(UIEditorListViewInteractionTest, ArrowAndHomeEndKeysDriveSelectionWhenFocus
EXPECT_TRUE(selectionModel.IsSelected("texture"));
}
TEST(UIEditorListViewInteractionTest, ShiftArrowExtendsVisibleRangeFromAnchor) {
const auto items = BuildListItems();
UISelectionModel selectionModel = {};
selectionModel.SetSelection("material");
UIEditorListViewInteractionState state = {};
state.listViewState.focused = true;
state.selectionAnchorId = "material";
const auto frame = UpdateUIEditorListViewInteraction(
state,
selectionModel,
UIRect(0.0f, 0.0f, 320.0f, 240.0f),
items,
{ MakeKeyDown(KeyCode::Down, MakeShiftModifiers()) });
EXPECT_TRUE(frame.result.keyboardNavigated);
EXPECT_TRUE(selectionModel.IsSelected("material"));
EXPECT_TRUE(selectionModel.IsSelected("script"));
EXPECT_EQ(selectionModel.GetSelectionCount(), 2u);
EXPECT_EQ(frame.result.selectedItemId, "script");
}
TEST(UIEditorListViewInteractionTest, F2RequestsRenameForPrimarySelectionWhenFocused) {
const auto items = BuildListItems();
UISelectionModel selectionModel = {};
selectionModel.SetSelection("script");
UIEditorListViewInteractionState state = {};
state.listViewState.focused = true;
const auto frame = UpdateUIEditorListViewInteraction(
state,
selectionModel,
UIRect(0.0f, 0.0f, 320.0f, 240.0f),
items,
{ MakeKeyDown(KeyCode::F2) });
EXPECT_TRUE(frame.result.renameRequested);
EXPECT_TRUE(frame.result.consumed);
EXPECT_EQ(frame.result.renameItemId, "script");
EXPECT_EQ(frame.result.selectedItemId, "script");
EXPECT_EQ(frame.result.selectedIndex, 2u);
EXPECT_FALSE(frame.result.selectionChanged);
}
TEST(UIEditorListViewInteractionTest, OutsideClickAndFocusLostClearFocusAndHoverButKeepSelection) {
const auto items = BuildListItems();
UISelectionModel selectionModel = {};

View File

@@ -94,6 +94,20 @@ UIEditorPropertyGridField MakeEnumField(
return field;
}
UIEditorPropertyGridField MakeColorField(
std::string id,
std::string label,
XCEngine::UI::UIColor value,
bool showAlpha = true) {
UIEditorPropertyGridField field = {};
field.fieldId = std::move(id);
field.label = std::move(label);
field.kind = UIEditorPropertyGridFieldKind::Color;
field.colorValue.value = value;
field.colorValue.showAlpha = showAlpha;
return field;
}
UIEditorPropertyGridField MakeVector4Field(
std::string id,
std::string label,
@@ -337,3 +351,68 @@ TEST(UIEditorPropertyGridTest, Vector4FieldUsesHostedLayoutAndForegroundText) {
EXPECT_TRUE(ContainsTextCommand(drawData, "4"));
EXPECT_EQ(ResolveUIEditorPropertyGridFieldValueText(sections[0].fields[0]), "1, 2, 3, 4");
}
TEST(UIEditorPropertyGridTest, ColorFieldUsesHostedLayoutAndPopupAwareForeground) {
std::vector<UIEditorPropertyGridSection> sections = {
{
"material",
"Material",
{
MakeColorField("tint", "Tint", XCEngine::UI::UIColor(0.8f, 0.4f, 0.2f, 0.5f))
},
0.0f
}
};
UISelectionModel selectionModel = {};
selectionModel.SetSelection("tint");
UIExpansionModel expansionModel = {};
expansionModel.Expand("material");
UIPropertyEditModel propertyEditModel = {};
UIEditorPropertyGridState state = {};
state.focused = true;
state.hoveredFieldId = "tint";
state.hoveredHitTarget = UIEditorPropertyGridHitTargetKind::ValueBox;
state.colorFieldStates = {
{
"tint",
{
XCEngine::UI::Editor::Widgets::UIEditorColorFieldHitTargetKind::Swatch,
XCEngine::UI::Editor::Widgets::UIEditorColorFieldHitTargetKind::None,
true,
true,
0.0f,
false
}
}
};
const auto layout = BuildUIEditorPropertyGridLayout(
UIRect(0.0f, 0.0f, 520.0f, 320.0f),
sections,
expansionModel);
ASSERT_EQ(layout.visibleFieldIndices.size(), 1u);
EXPECT_GT(layout.fieldValueRects[0].x, layout.fieldLabelRects[0].x + layout.fieldLabelRects[0].width);
EXPECT_GT(layout.fieldValueRects[0].width, 200.0f);
XCEngine::UI::UIDrawData drawData = {};
auto& drawList = drawData.EmplaceDrawList("PropertyGridColor");
AppendUIEditorPropertyGridBackground(
drawList,
layout,
sections,
selectionModel,
propertyEditModel,
state);
AppendUIEditorPropertyGridForeground(
drawList,
layout,
sections,
state,
propertyEditModel);
EXPECT_TRUE(ContainsTextCommand(drawData, "Tint"));
EXPECT_TRUE(ContainsTextCommand(drawData, "Color"));
EXPECT_TRUE(ContainsTextCommand(drawData, "Hexadecimal"));
EXPECT_EQ(ResolveUIEditorPropertyGridFieldValueText(sections[0].fields[0]), "#CC663380");
}

View File

@@ -1,6 +1,8 @@
#include <gtest/gtest.h>
#include <XCEditor/Core/UIEditorTheme.h>
#include <XCEditor/Core/UIEditorPropertyGridInteraction.h>
#include <XCEditor/Widgets/UIEditorColorField.h>
#include <XCEngine/Input/InputTypes.h>
@@ -15,8 +17,10 @@ using XCEngine::UI::UIRect;
using XCEngine::UI::Widgets::UIExpansionModel;
using XCEngine::UI::Widgets::UIPropertyEditModel;
using XCEngine::UI::Widgets::UISelectionModel;
using XCEngine::UI::Editor::BuildUIEditorHostedColorFieldMetrics;
using XCEngine::UI::Editor::UIEditorPropertyGridInteractionState;
using XCEngine::UI::Editor::UpdateUIEditorPropertyGridInteraction;
using XCEngine::UI::Editor::Widgets::BuildUIEditorColorFieldLayout;
using XCEngine::UI::Editor::Widgets::UIEditorPropertyGridField;
using XCEngine::UI::Editor::Widgets::UIEditorPropertyGridFieldKind;
using XCEngine::UI::Editor::Widgets::UIEditorPropertyGridSection;
@@ -76,6 +80,20 @@ UIEditorPropertyGridField MakeEnumField(
return field;
}
UIEditorPropertyGridField MakeColorField(
std::string id,
std::string label,
XCEngine::UI::UIColor value,
bool showAlpha = true) {
UIEditorPropertyGridField field = {};
field.fieldId = std::move(id);
field.label = std::move(label);
field.kind = UIEditorPropertyGridFieldKind::Color;
field.colorValue.value = value;
field.colorValue.showAlpha = showAlpha;
return field;
}
std::vector<UIEditorPropertyGridSection> BuildSections() {
return {
{
@@ -489,3 +507,101 @@ TEST(UIEditorPropertyGridInteractionTest, ArrowAndHomeEndKeysNavigateVisibleFiel
EXPECT_EQ(frame.result.selectedFieldId, "guid");
EXPECT_TRUE(selectionModel.IsSelected("guid"));
}
TEST(UIEditorPropertyGridInteractionTest, ColorFieldPopupCanOpenAndDragAlphaThroughHostedInteraction) {
std::vector<UIEditorPropertyGridSection> sections = {
{
"material",
"Material",
{
MakeColorField("tint", "Tint", XCEngine::UI::UIColor(0.8f, 0.4f, 0.2f, 1.0f))
},
0.0f
}
};
UISelectionModel selectionModel = {};
UIExpansionModel expansionModel = {};
expansionModel.Expand("material");
UIPropertyEditModel propertyEditModel = {};
UIEditorPropertyGridInteractionState state = {};
auto frame = UpdateUIEditorPropertyGridInteraction(
state,
selectionModel,
expansionModel,
propertyEditModel,
UIRect(0.0f, 0.0f, 520.0f, 360.0f),
sections,
{});
XCEngine::UI::Editor::Widgets::UIEditorColorFieldSpec initialColorSpec = {};
initialColorSpec.fieldId = "tint";
initialColorSpec.label = "Tint";
initialColorSpec.value = sections[0].fields[0].colorValue.value;
initialColorSpec.showAlpha = sections[0].fields[0].colorValue.showAlpha;
const auto initialColorLayout = BuildUIEditorColorFieldLayout(
frame.layout.fieldRowRects[0],
initialColorSpec,
BuildUIEditorHostedColorFieldMetrics({}),
UIRect(-4096.0f, -4096.0f, 8192.0f, 8192.0f));
const UIPoint swatchCenter = RectCenter(initialColorLayout.swatchRect);
frame = UpdateUIEditorPropertyGridInteraction(
state,
selectionModel,
expansionModel,
propertyEditModel,
UIRect(0.0f, 0.0f, 520.0f, 360.0f),
sections,
{
MakePointerDown(swatchCenter.x, swatchCenter.y),
MakePointerUp(swatchCenter.x, swatchCenter.y)
});
ASSERT_TRUE(frame.result.popupOpened);
ASSERT_EQ(state.propertyGridState.colorFieldStates.size(), 1u);
EXPECT_TRUE(state.propertyGridState.colorFieldStates[0].state.popupOpen);
EXPECT_TRUE(selectionModel.IsSelected("tint"));
const auto popupFrame = UpdateUIEditorPropertyGridInteraction(
state,
selectionModel,
expansionModel,
propertyEditModel,
UIRect(0.0f, 0.0f, 520.0f, 360.0f),
sections,
{});
const auto& colorState = state.propertyGridState.colorFieldStates[0].state;
EXPECT_TRUE(colorState.popupOpen);
XCEngine::UI::Editor::Widgets::UIEditorColorFieldSpec colorSpec = {};
colorSpec.fieldId = "tint";
colorSpec.label = "Tint";
colorSpec.value = sections[0].fields[0].colorValue.value;
colorSpec.showAlpha = sections[0].fields[0].colorValue.showAlpha;
const auto colorLayout = BuildUIEditorColorFieldLayout(
popupFrame.layout.fieldRowRects[0],
colorSpec,
BuildUIEditorHostedColorFieldMetrics({}),
UIRect(-4096.0f, -4096.0f, 8192.0f, 8192.0f));
const float alphaX =
colorLayout.alphaSliderRect.x + colorLayout.alphaSliderRect.width * 0.25f;
const float alphaY =
colorLayout.alphaSliderRect.y + colorLayout.alphaSliderRect.height * 0.5f;
frame = UpdateUIEditorPropertyGridInteraction(
state,
selectionModel,
expansionModel,
propertyEditModel,
UIRect(0.0f, 0.0f, 520.0f, 360.0f),
sections,
{
MakePointerDown(alphaX, alphaY),
MakePointerMove(alphaX, alphaY),
MakePointerUp(alphaX, alphaY)
});
EXPECT_TRUE(frame.result.fieldValueChanged);
EXPECT_EQ(frame.result.changedFieldId, "tint");
EXPECT_LT(sections[0].fields[0].colorValue.value.a, 0.5f);
}

View File

@@ -1,6 +1,6 @@
#include <gtest/gtest.h>
#include <XCEditor/Core/UIEditorShortcutManager.h>
#include <XCEditor/Foundation/UIEditorShortcutManager.h>
#include <XCEngine/Input/InputTypes.h>

View File

@@ -1,7 +1,7 @@
#include <gtest/gtest.h>
#include <XCEngine/UI/DrawData.h>
#include <XCEditor/Widgets/UIEditorTabStrip.h>
#include <XCEditor/Collections/UIEditorTabStrip.h>
namespace {

View File

@@ -0,0 +1,244 @@
#include <gtest/gtest.h>
#include <XCEditor/Collections/UIEditorTabStripInteraction.h>
#include <XCEngine/Input/InputTypes.h>
namespace {
using XCEngine::Input::KeyCode;
using XCEngine::UI::UIInputEvent;
using XCEngine::UI::UIInputEventType;
using XCEngine::UI::UIPoint;
using XCEngine::UI::UIPointerButton;
using XCEngine::UI::UIRect;
using XCEngine::UI::Editor::UIEditorTabStripInteractionState;
using XCEngine::UI::Editor::UpdateUIEditorTabStripInteraction;
using XCEngine::UI::Editor::Widgets::UIEditorTabStripHitTargetKind;
using XCEngine::UI::Editor::Widgets::UIEditorTabStripItem;
std::vector<UIEditorTabStripItem> BuildTabItems() {
return {
{ "doc-a", "Document A", true, 48.0f },
{ "doc-b", "Document B", true, 46.0f },
{ "doc-c", "Document C", false, 44.0f }
};
}
UIInputEvent MakePointerMove(float x, float y) {
UIInputEvent event = {};
event.type = UIInputEventType::PointerMove;
event.position = UIPoint(x, y);
return event;
}
UIInputEvent MakePointerDown(float x, float y, UIPointerButton button = UIPointerButton::Left) {
UIInputEvent event = {};
event.type = UIInputEventType::PointerButtonDown;
event.position = UIPoint(x, y);
event.pointerButton = button;
return event;
}
UIInputEvent MakePointerUp(float x, float y, UIPointerButton button = UIPointerButton::Left) {
UIInputEvent event = {};
event.type = UIInputEventType::PointerButtonUp;
event.position = UIPoint(x, y);
event.pointerButton = button;
return event;
}
UIInputEvent MakeKeyDown(KeyCode keyCode) {
UIInputEvent event = {};
event.type = UIInputEventType::KeyDown;
event.keyCode = static_cast<std::int32_t>(keyCode);
return event;
}
UIInputEvent MakePointerLeave() {
UIInputEvent event = {};
event.type = UIInputEventType::PointerLeave;
return event;
}
UIInputEvent MakeFocusLost() {
UIInputEvent event = {};
event.type = UIInputEventType::FocusLost;
return event;
}
UIPoint RectCenter(const XCEngine::UI::UIRect& rect) {
return UIPoint(rect.x + rect.width * 0.5f, rect.y + rect.height * 0.5f);
}
} // namespace
TEST(UIEditorTabStripInteractionTest, PointerMoveUpdatesHoveredTabAndCloseState) {
const auto items = BuildTabItems();
std::string selectedTabId = "doc-a";
UIEditorTabStripInteractionState state = {};
const auto initialFrame = UpdateUIEditorTabStripInteraction(
state,
selectedTabId,
UIRect(0.0f, 0.0f, 320.0f, 180.0f),
items,
{});
auto frame = UpdateUIEditorTabStripInteraction(
state,
selectedTabId,
UIRect(0.0f, 0.0f, 320.0f, 180.0f),
items,
{ MakePointerMove(
initialFrame.layout.tabHeaderRects[1].x + 12.0f,
initialFrame.layout.tabHeaderRects[1].y + 12.0f) });
EXPECT_EQ(frame.result.hitTarget.kind, UIEditorTabStripHitTargetKind::Tab);
EXPECT_EQ(state.tabStripState.hoveredIndex, 1u);
EXPECT_EQ(state.tabStripState.closeHoveredIndex, XCEngine::UI::Editor::Widgets::UIEditorTabStripInvalidIndex);
frame = UpdateUIEditorTabStripInteraction(
state,
selectedTabId,
UIRect(0.0f, 0.0f, 320.0f, 180.0f),
items,
{ MakePointerMove(
initialFrame.layout.closeButtonRects[0].x + 4.0f,
initialFrame.layout.closeButtonRects[0].y + 4.0f) });
EXPECT_EQ(frame.result.hitTarget.kind, UIEditorTabStripHitTargetKind::CloseButton);
EXPECT_EQ(state.tabStripState.hoveredIndex, 0u);
EXPECT_EQ(state.tabStripState.closeHoveredIndex, 0u);
}
TEST(UIEditorTabStripInteractionTest, LeftClickTabSelectsAndFocusesStrip) {
const auto items = BuildTabItems();
std::string selectedTabId = "doc-a";
UIEditorTabStripInteractionState state = {};
const auto initialFrame = UpdateUIEditorTabStripInteraction(
state,
selectedTabId,
UIRect(0.0f, 0.0f, 320.0f, 180.0f),
items,
{});
const UIPoint tabCenter = RectCenter(initialFrame.layout.tabHeaderRects[1]);
const auto frame = UpdateUIEditorTabStripInteraction(
state,
selectedTabId,
UIRect(0.0f, 0.0f, 320.0f, 180.0f),
items,
{
MakePointerDown(tabCenter.x, tabCenter.y),
MakePointerUp(tabCenter.x, tabCenter.y)
});
EXPECT_TRUE(frame.result.consumed);
EXPECT_TRUE(frame.result.selectionChanged);
EXPECT_EQ(frame.result.selectedTabId, "doc-b");
EXPECT_EQ(frame.result.selectedIndex, 1u);
EXPECT_EQ(selectedTabId, "doc-b");
EXPECT_TRUE(state.tabStripState.focused);
}
TEST(UIEditorTabStripInteractionTest, LeftClickCloseButtonRequestsCloseWithoutChangingSelection) {
const auto items = BuildTabItems();
std::string selectedTabId = "doc-a";
UIEditorTabStripInteractionState state = {};
const auto initialFrame = UpdateUIEditorTabStripInteraction(
state,
selectedTabId,
UIRect(0.0f, 0.0f, 320.0f, 180.0f),
items,
{});
const UIPoint closeCenter = RectCenter(initialFrame.layout.closeButtonRects[1]);
const auto frame = UpdateUIEditorTabStripInteraction(
state,
selectedTabId,
UIRect(0.0f, 0.0f, 320.0f, 180.0f),
items,
{
MakePointerDown(closeCenter.x, closeCenter.y),
MakePointerUp(closeCenter.x, closeCenter.y)
});
EXPECT_TRUE(frame.result.consumed);
EXPECT_TRUE(frame.result.closeRequested);
EXPECT_FALSE(frame.result.selectionChanged);
EXPECT_EQ(frame.result.closedTabId, "doc-b");
EXPECT_EQ(frame.result.closedIndex, 1u);
EXPECT_EQ(selectedTabId, "doc-a");
EXPECT_TRUE(state.tabStripState.focused);
}
TEST(UIEditorTabStripInteractionTest, KeyboardNavigationMovesSelectionWhenFocused) {
const auto items = BuildTabItems();
std::string selectedTabId = "doc-b";
UIEditorTabStripInteractionState state = {};
state.tabStripState.focused = true;
auto frame = UpdateUIEditorTabStripInteraction(
state,
selectedTabId,
UIRect(0.0f, 0.0f, 320.0f, 180.0f),
items,
{ MakeKeyDown(KeyCode::Right) });
EXPECT_TRUE(frame.result.keyboardNavigated);
EXPECT_EQ(frame.result.selectedTabId, "doc-c");
EXPECT_EQ(selectedTabId, "doc-c");
frame = UpdateUIEditorTabStripInteraction(
state,
selectedTabId,
UIRect(0.0f, 0.0f, 320.0f, 180.0f),
items,
{ MakeKeyDown(KeyCode::Home) });
EXPECT_TRUE(frame.result.keyboardNavigated);
EXPECT_EQ(frame.result.selectedTabId, "doc-a");
EXPECT_EQ(selectedTabId, "doc-a");
frame = UpdateUIEditorTabStripInteraction(
state,
selectedTabId,
UIRect(0.0f, 0.0f, 320.0f, 180.0f),
items,
{ MakeKeyDown(KeyCode::End) });
EXPECT_TRUE(frame.result.keyboardNavigated);
EXPECT_EQ(frame.result.selectedTabId, "doc-c");
EXPECT_EQ(selectedTabId, "doc-c");
}
TEST(UIEditorTabStripInteractionTest, OutsideClickAndFocusLostClearFocusAndHover) {
const auto items = BuildTabItems();
std::string selectedTabId = "doc-b";
UIEditorTabStripInteractionState state = {};
state.tabStripState.focused = true;
state.tabStripState.hoveredIndex = 1u;
state.tabStripState.closeHoveredIndex = 1u;
auto frame = UpdateUIEditorTabStripInteraction(
state,
selectedTabId,
UIRect(0.0f, 0.0f, 320.0f, 180.0f),
items,
{
MakePointerDown(420.0f, 240.0f),
MakePointerUp(420.0f, 240.0f)
});
EXPECT_FALSE(state.tabStripState.focused);
EXPECT_EQ(frame.result.hitTarget.kind, UIEditorTabStripHitTargetKind::None);
EXPECT_EQ(selectedTabId, "doc-b");
frame = UpdateUIEditorTabStripInteraction(
state,
selectedTabId,
UIRect(0.0f, 0.0f, 320.0f, 180.0f),
items,
{ MakePointerLeave(), MakeFocusLost() });
EXPECT_FALSE(state.tabStripState.focused);
EXPECT_EQ(state.tabStripState.hoveredIndex, XCEngine::UI::Editor::Widgets::UIEditorTabStripInvalidIndex);
EXPECT_EQ(state.tabStripState.closeHoveredIndex, XCEngine::UI::Editor::Widgets::UIEditorTabStripInvalidIndex);
EXPECT_FALSE(state.hasPointerPosition);
}

View File

@@ -1,6 +1,6 @@
#include <gtest/gtest.h>
#include <XCEditor/Core/UIEditorTheme.h>
#include <XCEditor/Foundation/UIEditorTheme.h>
#include <XCEngine/Core/Math/Color.h>
#include <XCEngine/UI/Style/StyleTypes.h>

View File

@@ -3,7 +3,7 @@
#include <XCEngine/UI/DrawData.h>
#include <XCEngine/UI/Widgets/UIExpansionModel.h>
#include <XCEngine/UI/Widgets/UISelectionModel.h>
#include <XCEditor/Widgets/UIEditorTreeView.h>
#include <XCEditor/Collections/UIEditorTreeView.h>
namespace {

View File

@@ -1,11 +1,15 @@
#include <gtest/gtest.h>
#include <XCEditor/Core/UIEditorTreeViewInteraction.h>
#include <XCEditor/Collections/UIEditorTreeViewInteraction.h>
#include <XCEngine/Input/InputTypes.h>
namespace {
using XCEngine::Input::KeyCode;
using XCEngine::UI::UIInputEvent;
using XCEngine::UI::UIInputEventType;
using XCEngine::UI::UIInputModifiers;
using XCEngine::UI::UIPoint;
using XCEngine::UI::UIPointerButton;
using XCEngine::UI::UIRect;
@@ -35,19 +39,41 @@ UIInputEvent MakePointerMove(float x, float y) {
return event;
}
UIInputEvent MakePointerDown(float x, float y, UIPointerButton button = UIPointerButton::Left) {
UIInputModifiers MakeShiftModifiers() {
UIInputModifiers modifiers = {};
modifiers.shift = true;
return modifiers;
}
UIInputModifiers MakeControlModifiers() {
UIInputModifiers modifiers = {};
modifiers.control = true;
return modifiers;
}
UIInputEvent MakePointerDown(
float x,
float y,
UIPointerButton button = UIPointerButton::Left,
UIInputModifiers modifiers = {}) {
UIInputEvent event = {};
event.type = UIInputEventType::PointerButtonDown;
event.position = UIPoint(x, y);
event.pointerButton = button;
event.modifiers = modifiers;
return event;
}
UIInputEvent MakePointerUp(float x, float y, UIPointerButton button = UIPointerButton::Left) {
UIInputEvent MakePointerUp(
float x,
float y,
UIPointerButton button = UIPointerButton::Left,
UIInputModifiers modifiers = {}) {
UIInputEvent event = {};
event.type = UIInputEventType::PointerButtonUp;
event.position = UIPoint(x, y);
event.pointerButton = button;
event.modifiers = modifiers;
return event;
}
@@ -63,6 +89,14 @@ UIInputEvent MakeFocusLost() {
return event;
}
UIInputEvent MakeKeyDown(KeyCode keyCode, UIInputModifiers modifiers = {}) {
UIInputEvent event = {};
event.type = UIInputEventType::KeyDown;
event.keyCode = static_cast<std::int32_t>(keyCode);
event.modifiers = modifiers;
return event;
}
UIPoint RectCenter(const XCEngine::UI::UIRect& rect) {
return UIPoint(rect.x + rect.width * 0.5f, rect.y + rect.height * 0.5f);
}
@@ -168,6 +202,42 @@ TEST(UIEditorTreeViewInteractionTest, LeftClickDisclosureTogglesExpansionAndRebu
EXPECT_EQ(frame.layout.visibleItemIndices[4], 4u);
}
TEST(UIEditorTreeViewInteractionTest, DisclosureClickKeepsKeyboardCurrentAnchoredToSelection) {
const auto items = BuildTreeItems();
UISelectionModel selectionModel = {};
selectionModel.SetSelection("camera");
UIExpansionModel expansionModel = {};
expansionModel.Expand("scene");
UIEditorTreeViewInteractionState state = {};
state.treeViewState.focused = true;
const auto initialFrame = UpdateUIEditorTreeViewInteraction(
state,
selectionModel,
expansionModel,
UIRect(0.0f, 0.0f, 320.0f, 240.0f),
items,
{});
const UIPoint lightsDisclosureCenter = RectCenter(initialFrame.layout.disclosureRects[2]);
const auto frame = UpdateUIEditorTreeViewInteraction(
state,
selectionModel,
expansionModel,
UIRect(0.0f, 0.0f, 320.0f, 240.0f),
items,
{
MakePointerDown(lightsDisclosureCenter.x, lightsDisclosureCenter.y),
MakePointerUp(lightsDisclosureCenter.x, lightsDisclosureCenter.y)
});
EXPECT_TRUE(frame.result.expansionChanged);
EXPECT_FALSE(frame.result.selectionChanged);
EXPECT_TRUE(selectionModel.IsSelected("camera"));
ASSERT_TRUE(state.keyboardNavigation.HasCurrentIndex());
EXPECT_EQ(state.keyboardNavigation.GetCurrentIndex(), 1u);
}
TEST(UIEditorTreeViewInteractionTest, RightClickRowSelectsItemAndMarksSecondaryClick) {
const auto items = BuildTreeItems();
UISelectionModel selectionModel = {};
@@ -203,6 +273,137 @@ TEST(UIEditorTreeViewInteractionTest, RightClickRowSelectsItemAndMarksSecondaryC
EXPECT_TRUE(state.treeViewState.focused);
}
TEST(UIEditorTreeViewInteractionTest, ControlClickRowTogglesMembershipWithoutDroppingExistingSelection) {
const auto items = BuildTreeItems();
UISelectionModel selectionModel = {};
selectionModel.SetSelections({ "camera", "lights" }, "lights");
UIExpansionModel expansionModel = {};
expansionModel.Expand("scene");
UIEditorTreeViewInteractionState state = {};
state.treeViewState.focused = true;
state.selectionAnchorId = "lights";
const auto initialFrame = UpdateUIEditorTreeViewInteraction(
state,
selectionModel,
expansionModel,
UIRect(0.0f, 0.0f, 320.0f, 240.0f),
items,
{});
const UIPoint sceneCenter = RectCenter(initialFrame.layout.rowRects[0]);
auto frame = UpdateUIEditorTreeViewInteraction(
state,
selectionModel,
expansionModel,
UIRect(0.0f, 0.0f, 320.0f, 240.0f),
items,
{
MakePointerDown(sceneCenter.x, sceneCenter.y, UIPointerButton::Left, MakeControlModifiers()),
MakePointerUp(sceneCenter.x, sceneCenter.y, UIPointerButton::Left, MakeControlModifiers())
});
EXPECT_TRUE(frame.result.selectionChanged);
EXPECT_TRUE(selectionModel.IsSelected("camera"));
EXPECT_TRUE(selectionModel.IsSelected("lights"));
EXPECT_TRUE(selectionModel.IsSelected("scene"));
EXPECT_EQ(selectionModel.GetSelectedId(), "scene");
const UIPoint lightsCenter = RectCenter(initialFrame.layout.rowRects[2]);
frame = UpdateUIEditorTreeViewInteraction(
state,
selectionModel,
expansionModel,
UIRect(0.0f, 0.0f, 320.0f, 240.0f),
items,
{
MakePointerDown(lightsCenter.x, lightsCenter.y, UIPointerButton::Left, MakeControlModifiers()),
MakePointerUp(lightsCenter.x, lightsCenter.y, UIPointerButton::Left, MakeControlModifiers())
});
EXPECT_TRUE(frame.result.selectionChanged);
EXPECT_TRUE(selectionModel.IsSelected("camera"));
EXPECT_FALSE(selectionModel.IsSelected("lights"));
EXPECT_TRUE(selectionModel.IsSelected("scene"));
}
TEST(UIEditorTreeViewInteractionTest, ShiftClickRowSelectsVisibleRangeFromAnchor) {
const auto items = BuildTreeItems();
UISelectionModel selectionModel = {};
selectionModel.SetSelection("camera");
UIExpansionModel expansionModel = {};
expansionModel.Expand("scene");
UIEditorTreeViewInteractionState state = {};
state.treeViewState.focused = true;
state.selectionAnchorId = "camera";
const auto initialFrame = UpdateUIEditorTreeViewInteraction(
state,
selectionModel,
expansionModel,
UIRect(0.0f, 0.0f, 320.0f, 240.0f),
items,
{});
const UIPoint uiCenter = RectCenter(initialFrame.layout.rowRects[3]);
const auto frame = UpdateUIEditorTreeViewInteraction(
state,
selectionModel,
expansionModel,
UIRect(0.0f, 0.0f, 320.0f, 240.0f),
items,
{
MakePointerDown(uiCenter.x, uiCenter.y, UIPointerButton::Left, MakeShiftModifiers()),
MakePointerUp(uiCenter.x, uiCenter.y, UIPointerButton::Left, MakeShiftModifiers())
});
EXPECT_TRUE(frame.result.selectionChanged);
EXPECT_EQ(frame.result.selectedItemId, "ui");
EXPECT_TRUE(selectionModel.IsSelected("camera"));
EXPECT_TRUE(selectionModel.IsSelected("lights"));
EXPECT_TRUE(selectionModel.IsSelected("ui"));
EXPECT_EQ(selectionModel.GetSelectionCount(), 3u);
EXPECT_EQ(state.selectionAnchorId, "camera");
}
TEST(UIEditorTreeViewInteractionTest, RightClickSelectedRowKeepsExistingMultiSelection) {
const auto items = BuildTreeItems();
UISelectionModel selectionModel = {};
selectionModel.SetSelections({ "camera", "lights", "ui" }, "camera");
UIExpansionModel expansionModel = {};
expansionModel.Expand("scene");
UIEditorTreeViewInteractionState state = {};
state.treeViewState.focused = true;
state.selectionAnchorId = "camera";
const auto initialFrame = UpdateUIEditorTreeViewInteraction(
state,
selectionModel,
expansionModel,
UIRect(0.0f, 0.0f, 320.0f, 240.0f),
items,
{});
const UIPoint lightsCenter = RectCenter(initialFrame.layout.rowRects[2]);
const auto frame = UpdateUIEditorTreeViewInteraction(
state,
selectionModel,
expansionModel,
UIRect(0.0f, 0.0f, 320.0f, 240.0f),
items,
{
MakePointerDown(lightsCenter.x, lightsCenter.y, UIPointerButton::Right),
MakePointerUp(lightsCenter.x, lightsCenter.y, UIPointerButton::Right)
});
EXPECT_TRUE(frame.result.secondaryClicked);
EXPECT_FALSE(frame.result.selectionChanged);
EXPECT_TRUE(selectionModel.IsSelected("camera"));
EXPECT_TRUE(selectionModel.IsSelected("lights"));
EXPECT_TRUE(selectionModel.IsSelected("ui"));
EXPECT_EQ(selectionModel.GetSelectionCount(), 3u);
EXPECT_EQ(selectionModel.GetSelectedId(), "lights");
}
TEST(UIEditorTreeViewInteractionTest, OutsideClickAndFocusLostClearFocusAndHover) {
const auto items = BuildTreeItems();
UISelectionModel selectionModel = {};
@@ -233,3 +434,186 @@ TEST(UIEditorTreeViewInteractionTest, OutsideClickAndFocusLostClearFocusAndHover
EXPECT_TRUE(state.treeViewState.hoveredItemId.empty());
EXPECT_FALSE(state.hasPointerPosition);
}
TEST(UIEditorTreeViewInteractionTest, KeyboardNavigationMovesSelectionAcrossVisibleRows) {
const auto items = BuildTreeItems();
UISelectionModel selectionModel = {};
selectionModel.SetSelection("camera");
UIExpansionModel expansionModel = {};
expansionModel.Expand("scene");
UIEditorTreeViewInteractionState state = {};
state.treeViewState.focused = true;
auto frame = UpdateUIEditorTreeViewInteraction(
state,
selectionModel,
expansionModel,
UIRect(0.0f, 0.0f, 320.0f, 240.0f),
items,
{ MakeKeyDown(KeyCode::Down) });
EXPECT_TRUE(frame.result.keyboardNavigated);
EXPECT_TRUE(selectionModel.IsSelected("lights"));
EXPECT_EQ(state.keyboardNavigation.GetCurrentIndex(), 2u);
frame = UpdateUIEditorTreeViewInteraction(
state,
selectionModel,
expansionModel,
UIRect(0.0f, 0.0f, 320.0f, 240.0f),
items,
{ MakeKeyDown(KeyCode::Home) });
EXPECT_TRUE(frame.result.keyboardNavigated);
EXPECT_TRUE(selectionModel.IsSelected("scene"));
frame = UpdateUIEditorTreeViewInteraction(
state,
selectionModel,
expansionModel,
UIRect(0.0f, 0.0f, 320.0f, 240.0f),
items,
{ MakeKeyDown(KeyCode::End) });
EXPECT_TRUE(frame.result.keyboardNavigated);
EXPECT_TRUE(selectionModel.IsSelected("ui"));
}
TEST(UIEditorTreeViewInteractionTest, ShiftArrowExtendsVisibleRangeFromAnchor) {
const auto items = BuildTreeItems();
UISelectionModel selectionModel = {};
selectionModel.SetSelection("camera");
UIExpansionModel expansionModel = {};
expansionModel.Expand("scene");
UIEditorTreeViewInteractionState state = {};
state.treeViewState.focused = true;
state.selectionAnchorId = "camera";
const auto frame = UpdateUIEditorTreeViewInteraction(
state,
selectionModel,
expansionModel,
UIRect(0.0f, 0.0f, 320.0f, 240.0f),
items,
{ MakeKeyDown(KeyCode::Down, MakeShiftModifiers()) });
EXPECT_TRUE(frame.result.keyboardNavigated);
EXPECT_TRUE(selectionModel.IsSelected("camera"));
EXPECT_TRUE(selectionModel.IsSelected("lights"));
EXPECT_EQ(selectionModel.GetSelectionCount(), 2u);
EXPECT_EQ(frame.result.selectedItemId, "lights");
}
TEST(UIEditorTreeViewInteractionTest, F2RequestsRenameForPrimarySelectionWhenFocused) {
const auto items = BuildTreeItems();
UISelectionModel selectionModel = {};
selectionModel.SetSelection("lights");
UIExpansionModel expansionModel = {};
expansionModel.Expand("scene");
UIEditorTreeViewInteractionState state = {};
state.treeViewState.focused = true;
const auto frame = UpdateUIEditorTreeViewInteraction(
state,
selectionModel,
expansionModel,
UIRect(0.0f, 0.0f, 320.0f, 240.0f),
items,
{ MakeKeyDown(KeyCode::F2) });
EXPECT_TRUE(frame.result.renameRequested);
EXPECT_TRUE(frame.result.consumed);
EXPECT_EQ(frame.result.renameItemId, "lights");
EXPECT_EQ(frame.result.selectedItemId, "lights");
EXPECT_EQ(frame.result.selectedVisibleIndex, 2u);
EXPECT_FALSE(frame.result.selectionChanged);
}
TEST(UIEditorTreeViewInteractionTest, RightAndLeftKeysExpandCollapseAndMoveHierarchySelection) {
const auto items = BuildTreeItems();
UISelectionModel selectionModel = {};
selectionModel.SetSelection("lights");
UIExpansionModel expansionModel = {};
expansionModel.Expand("scene");
UIEditorTreeViewInteractionState state = {};
state.treeViewState.focused = true;
auto frame = UpdateUIEditorTreeViewInteraction(
state,
selectionModel,
expansionModel,
UIRect(0.0f, 0.0f, 320.0f, 240.0f),
items,
{ MakeKeyDown(KeyCode::Right) });
EXPECT_TRUE(frame.result.expansionChanged);
EXPECT_TRUE(frame.result.keyboardNavigated);
EXPECT_TRUE(expansionModel.IsExpanded("lights"));
EXPECT_EQ(frame.result.toggledItemId, "lights");
EXPECT_EQ(frame.result.selectedItemId, "lights");
EXPECT_EQ(frame.result.selectedVisibleIndex, 2u);
frame = UpdateUIEditorTreeViewInteraction(
state,
selectionModel,
expansionModel,
UIRect(0.0f, 0.0f, 320.0f, 240.0f),
items,
{ MakeKeyDown(KeyCode::Right) });
EXPECT_TRUE(frame.result.keyboardNavigated);
EXPECT_TRUE(selectionModel.IsSelected("sun"));
frame = UpdateUIEditorTreeViewInteraction(
state,
selectionModel,
expansionModel,
UIRect(0.0f, 0.0f, 320.0f, 240.0f),
items,
{ MakeKeyDown(KeyCode::Left) });
EXPECT_TRUE(frame.result.keyboardNavigated);
EXPECT_TRUE(selectionModel.IsSelected("lights"));
frame = UpdateUIEditorTreeViewInteraction(
state,
selectionModel,
expansionModel,
UIRect(0.0f, 0.0f, 320.0f, 240.0f),
items,
{ MakeKeyDown(KeyCode::Left) });
EXPECT_TRUE(frame.result.expansionChanged);
EXPECT_TRUE(frame.result.keyboardNavigated);
EXPECT_FALSE(expansionModel.IsExpanded("lights"));
EXPECT_EQ(frame.result.selectedItemId, "lights");
EXPECT_EQ(frame.result.selectedVisibleIndex, 2u);
}
TEST(UIEditorTreeViewInteractionTest, CollapsingAncestorRehomesHiddenSelectionToCollapsedItem) {
const auto items = BuildTreeItems();
UISelectionModel selectionModel = {};
selectionModel.SetSelection("sun");
UIExpansionModel expansionModel = {};
expansionModel.Expand("scene");
expansionModel.Expand("lights");
UIEditorTreeViewInteractionState state = {};
state.treeViewState.focused = true;
const auto initialFrame = UpdateUIEditorTreeViewInteraction(
state,
selectionModel,
expansionModel,
UIRect(0.0f, 0.0f, 320.0f, 240.0f),
items,
{});
const UIPoint lightsDisclosureCenter = RectCenter(initialFrame.layout.disclosureRects[2]);
const auto frame = UpdateUIEditorTreeViewInteraction(
state,
selectionModel,
expansionModel,
UIRect(0.0f, 0.0f, 320.0f, 240.0f),
items,
{
MakePointerDown(lightsDisclosureCenter.x, lightsDisclosureCenter.y),
MakePointerUp(lightsDisclosureCenter.x, lightsDisclosureCenter.y)
});
EXPECT_TRUE(frame.result.expansionChanged);
EXPECT_FALSE(expansionModel.IsExpanded("lights"));
EXPECT_TRUE(selectionModel.IsSelected("lights"));
}

View File

@@ -194,6 +194,7 @@ TEST(UIEditorWorkspaceInteractionTest, ActivatingDocumentTabRemovesViewportPrese
model,
{
MakePointerEvent(UIInputEventType::PointerMove, docTabCenter.x, docTabCenter.y),
MakePointerEvent(UIInputEventType::PointerButtonDown, docTabCenter.x, docTabCenter.y, UIPointerButton::Left),
MakePointerEvent(UIInputEventType::PointerButtonUp, docTabCenter.x, docTabCenter.y, UIPointerButton::Left)
});

View File

@@ -68,6 +68,7 @@ tests/UI/
- 必须产出可直接运行的 exe。
- 一个 exe 只验证一个聚焦场景。
- 如果某个交互契约已经超出 basic 场景的检查范围,例如 multi-select、drag/drop、inline rename就必须拆成独立 scenario不得继续往 basic exe 里堆。
- 每次只暴露当前批次需要检查的操作区域,不做大杂烩面板。
- 界面中的操作提示默认使用中文,必要时可混用 `hover``focus``active``capture` 等术语。
- 测哪一层,就把场景放到哪一层的 `integration/` 目录下。
@@ -153,6 +154,10 @@ Editor 集成测试只承载 editor-only 场景,不再承载共享 Core primit
- `editor.shell.workspace_compose`
- `editor.state.panel_session_flow`
- `editor.shell.tree_view_multiselect`
- `editor.shell.tree_view_inline_rename`
- `editor.shell.list_view_multiselect`
- `editor.shell.list_view_inline_rename`
## 7. 截图规范