Integrate XCUI shell state and runtime frame seams

This commit is contained in:
2026-04-05 12:50:55 +08:00
parent ec97445071
commit e5e9f348a3
29 changed files with 3183 additions and 102 deletions

View File

@@ -22,6 +22,20 @@ XCEngine::Editor::XCUIBackend::XCUILayoutLabInputState BuildInputState(
return input;
}
XCEngine::Editor::XCUIBackend::XCUILayoutLabInputState BuildKeyboardInputState(
float width = 960.0f,
float height = 640.0f) {
XCEngine::Editor::XCUIBackend::XCUILayoutLabInputState input = BuildInputState(width, height);
input.pointerInside = false;
return input;
}
XCEngine::UI::UIPoint RectCenter(const XCEngine::UI::UIRect& rect) {
return XCEngine::UI::UIPoint(
rect.x + rect.width * 0.5f,
rect.y + rect.height * 0.5f);
}
std::vector<const UIDrawCommand*> CollectTextCommands(const XCEngine::UI::UIDrawData& drawData) {
std::vector<const UIDrawCommand*> textCommands = {};
for (const XCEngine::UI::UIDrawList& drawList : drawData.GetDrawLists()) {
@@ -363,3 +377,156 @@ TEST(NewEditorXCUILayoutLabRuntimeTest, ClickingPropertySectionHeaderTogglesFiel
EXPECT_TRUE(runtime.TryGetElementRect("fieldPosition", fieldRect));
EXPECT_GT(fieldRect.height, 0.0f);
}
TEST(NewEditorXCUILayoutLabRuntimeTest, KeyboardNavigationMovesSelectionAcrossListItems) {
XCEngine::Editor::XCUIBackend::XCUILayoutLabRuntime runtime;
ASSERT_TRUE(runtime.ReloadDocuments());
const auto& baseline = runtime.Update(BuildInputState());
ASSERT_TRUE(baseline.stats.documentsReady);
XCEngine::UI::UIRect listItemRect = {};
ASSERT_TRUE(runtime.TryGetElementRect("assetLighting", listItemRect));
XCEngine::Editor::XCUIBackend::XCUILayoutLabInputState selectInput = BuildInputState();
selectInput.pointerPosition = RectCenter(listItemRect);
selectInput.pointerPressed = true;
const auto& selectedFrame = runtime.Update(selectInput);
ASSERT_TRUE(selectedFrame.stats.documentsReady);
EXPECT_EQ(selectedFrame.stats.selectedElementId, "assetLighting");
XCEngine::Editor::XCUIBackend::XCUILayoutLabInputState nextInput = BuildKeyboardInputState();
nextInput.navigateNext = true;
const auto& nextFrame = runtime.Update(nextInput);
ASSERT_TRUE(nextFrame.stats.documentsReady);
EXPECT_EQ(nextFrame.stats.selectedElementId, "assetMaterials");
XCEngine::Editor::XCUIBackend::XCUILayoutLabInputState endInput = BuildKeyboardInputState();
endInput.navigateEnd = true;
const auto& endFrame = runtime.Update(endInput);
ASSERT_TRUE(endFrame.stats.documentsReady);
ASSERT_FALSE(endFrame.stats.selectedElementId.empty());
EXPECT_NE(endFrame.stats.selectedElementId, "assetLighting");
const std::string lastListSelection = endFrame.stats.selectedElementId;
XCEngine::Editor::XCUIBackend::XCUILayoutLabInputState nextAtEndInput = BuildKeyboardInputState();
nextAtEndInput.navigateNext = true;
const auto& nextAtEndFrame = runtime.Update(nextAtEndInput);
ASSERT_TRUE(nextAtEndFrame.stats.documentsReady);
EXPECT_EQ(nextAtEndFrame.stats.selectedElementId, lastListSelection);
XCEngine::Editor::XCUIBackend::XCUILayoutLabInputState homeInput = BuildKeyboardInputState();
homeInput.navigateHome = true;
const auto& homeFrame = runtime.Update(homeInput);
ASSERT_TRUE(homeFrame.stats.documentsReady);
EXPECT_EQ(homeFrame.stats.selectedElementId, "assetLighting");
}
TEST(NewEditorXCUILayoutLabRuntimeTest, KeyboardCollapseAndExpandFollowTreeHierarchy) {
XCEngine::Editor::XCUIBackend::XCUILayoutLabRuntime runtime;
ASSERT_TRUE(runtime.ReloadDocuments());
const auto& baseline = runtime.Update(BuildInputState());
ASSERT_TRUE(baseline.stats.documentsReady);
XCEngine::UI::UIRect treeChildRect = {};
ASSERT_TRUE(runtime.TryGetElementRect("treeScenes", treeChildRect));
XCEngine::Editor::XCUIBackend::XCUILayoutLabInputState selectInput = BuildInputState();
selectInput.pointerPosition = RectCenter(treeChildRect);
selectInput.pointerPressed = true;
const auto& selectedFrame = runtime.Update(selectInput);
ASSERT_TRUE(selectedFrame.stats.documentsReady);
EXPECT_EQ(selectedFrame.stats.selectedElementId, "treeScenes");
XCEngine::Editor::XCUIBackend::XCUILayoutLabInputState collapseToParent = BuildKeyboardInputState();
collapseToParent.navigateCollapse = true;
const auto& parentFrame = runtime.Update(collapseToParent);
ASSERT_TRUE(parentFrame.stats.documentsReady);
EXPECT_EQ(parentFrame.stats.selectedElementId, "treeAssetsRoot");
XCEngine::Editor::XCUIBackend::XCUILayoutLabInputState collapseRoot = BuildKeyboardInputState();
collapseRoot.navigateCollapse = true;
const auto& collapsedFrame = runtime.Update(collapseRoot);
ASSERT_TRUE(collapsedFrame.stats.documentsReady);
EXPECT_EQ(collapsedFrame.stats.selectedElementId, "treeAssetsRoot");
const auto& collapsedPersistedFrame = runtime.Update(BuildKeyboardInputState());
ASSERT_TRUE(collapsedPersistedFrame.stats.documentsReady);
EXPECT_EQ(collapsedPersistedFrame.stats.expandedTreeItemCount, 0u);
EXPECT_FALSE(runtime.TryGetElementRect("treeScenes", treeChildRect));
XCEngine::Editor::XCUIBackend::XCUILayoutLabInputState expandRoot = BuildKeyboardInputState();
expandRoot.navigateExpand = true;
const auto& expandedRootFrame = runtime.Update(expandRoot);
ASSERT_TRUE(expandedRootFrame.stats.documentsReady);
EXPECT_EQ(expandedRootFrame.stats.selectedElementId, "treeAssetsRoot");
const auto& expandedPersistedFrame = runtime.Update(BuildKeyboardInputState());
ASSERT_TRUE(expandedPersistedFrame.stats.documentsReady);
EXPECT_EQ(expandedPersistedFrame.stats.expandedTreeItemCount, 1u);
ASSERT_TRUE(runtime.TryGetElementRect("treeScenes", treeChildRect));
XCEngine::Editor::XCUIBackend::XCUILayoutLabInputState moveIntoChild = BuildKeyboardInputState();
moveIntoChild.navigateExpand = true;
const auto& childFrame = runtime.Update(moveIntoChild);
ASSERT_TRUE(childFrame.stats.documentsReady);
EXPECT_EQ(childFrame.stats.selectedElementId, "treeScenes");
}
TEST(NewEditorXCUILayoutLabRuntimeTest, KeyboardNavigationTraversesPropertySectionsAndFields) {
XCEngine::Editor::XCUIBackend::XCUILayoutLabRuntime runtime;
ASSERT_TRUE(runtime.ReloadDocuments());
const auto& baseline = runtime.Update(BuildInputState());
ASSERT_TRUE(baseline.stats.documentsReady);
XCEngine::UI::UIRect sectionRect = {};
ASSERT_TRUE(runtime.TryGetElementRect("inspectorTransform", sectionRect));
XCEngine::Editor::XCUIBackend::XCUILayoutLabInputState selectInput = BuildInputState();
selectInput.pointerPosition = XCEngine::UI::UIPoint(sectionRect.x + 18.0f, sectionRect.y + 10.0f);
selectInput.pointerPressed = true;
const auto& selectedFrame = runtime.Update(selectInput);
ASSERT_TRUE(selectedFrame.stats.documentsReady);
EXPECT_EQ(selectedFrame.stats.selectedElementId, "inspectorTransform");
XCEngine::Editor::XCUIBackend::XCUILayoutLabInputState nextSectionInput = BuildKeyboardInputState();
nextSectionInput.navigateNext = true;
const auto& nextSectionFrame = runtime.Update(nextSectionInput);
ASSERT_TRUE(nextSectionFrame.stats.documentsReady);
EXPECT_EQ(nextSectionFrame.stats.selectedElementId, "inspectorMesh");
XCEngine::Editor::XCUIBackend::XCUILayoutLabInputState previousSectionInput = BuildKeyboardInputState();
previousSectionInput.navigatePrevious = true;
const auto& previousSectionFrame = runtime.Update(previousSectionInput);
ASSERT_TRUE(previousSectionFrame.stats.documentsReady);
EXPECT_EQ(previousSectionFrame.stats.selectedElementId, "inspectorTransform");
XCEngine::Editor::XCUIBackend::XCUILayoutLabInputState expandIntoFieldsInput = BuildKeyboardInputState();
expandIntoFieldsInput.navigateExpand = true;
const auto& expandedSectionFrame = runtime.Update(expandIntoFieldsInput);
ASSERT_TRUE(expandedSectionFrame.stats.documentsReady);
EXPECT_EQ(expandedSectionFrame.stats.selectedElementId, "inspectorTransform");
XCEngine::Editor::XCUIBackend::XCUILayoutLabInputState enterFieldsInput = BuildKeyboardInputState();
enterFieldsInput.navigateExpand = true;
const auto& firstFieldFrame = runtime.Update(enterFieldsInput);
ASSERT_TRUE(firstFieldFrame.stats.documentsReady);
EXPECT_EQ(firstFieldFrame.stats.selectedElementId, "fieldPosition");
XCEngine::Editor::XCUIBackend::XCUILayoutLabInputState nextFieldInput = BuildKeyboardInputState();
nextFieldInput.navigateNext = true;
const auto& nextFieldFrame = runtime.Update(nextFieldInput);
ASSERT_TRUE(nextFieldFrame.stats.documentsReady);
EXPECT_EQ(nextFieldFrame.stats.selectedElementId, "fieldRotation");
XCEngine::Editor::XCUIBackend::XCUILayoutLabInputState collapseToSectionInput = BuildKeyboardInputState();
collapseToSectionInput.navigateCollapse = true;
const auto& collapseToSectionFrame = runtime.Update(collapseToSectionInput);
ASSERT_TRUE(collapseToSectionFrame.stats.documentsReady);
EXPECT_EQ(collapseToSectionFrame.stats.selectedElementId, "inspectorTransform");
}