chore: checkpoint current workspace changes
This commit is contained in:
@@ -89,7 +89,11 @@ TEST(UIEditorMenuPopupTest, HitTestIgnoresSeparatorsAndFallsBackToPopupSurface)
|
||||
EXPECT_EQ(itemHit.kind, UIEditorMenuPopupHitTargetKind::Item);
|
||||
EXPECT_EQ(itemHit.index, 0u);
|
||||
|
||||
const auto separatorHit = HitTestUIEditorMenuPopup(layout, items, UIPoint(130.0f, 88.0f));
|
||||
const UIRect separatorRect = layout.itemRects[1];
|
||||
const UIPoint separatorCenter(
|
||||
separatorRect.x + separatorRect.width * 0.5f,
|
||||
separatorRect.y + separatorRect.height * 0.5f);
|
||||
const auto separatorHit = HitTestUIEditorMenuPopup(layout, items, separatorCenter);
|
||||
EXPECT_EQ(separatorHit.kind, UIEditorMenuPopupHitTargetKind::PopupSurface);
|
||||
EXPECT_EQ(separatorHit.index, UIEditorMenuPopupInvalidIndex);
|
||||
|
||||
@@ -134,3 +138,34 @@ TEST(UIEditorMenuPopupTest, BackgroundAndForegroundEmitStableCommands) {
|
||||
EXPECT_EQ(foregroundCommands[12].type, UIDrawCommandType::Text);
|
||||
EXPECT_EQ(foregroundCommands[12].text, "Ctrl+W");
|
||||
}
|
||||
|
||||
TEST(UIEditorMenuPopupTest, SubmenuIndicatorStaysInsideReservedRightEdgeSlot) {
|
||||
const auto items = BuildItems();
|
||||
XCEngine::UI::Editor::Widgets::UIEditorMenuPopupMetrics metrics = {};
|
||||
const auto layout = BuildUIEditorMenuPopupLayout(
|
||||
UIRect(100.0f, 50.0f, 220.0f, 118.0f),
|
||||
items,
|
||||
metrics);
|
||||
|
||||
UIDrawList foreground("MenuPopupForeground");
|
||||
AppendUIEditorMenuPopupForeground(foreground, layout, items, {}, {}, metrics);
|
||||
|
||||
const auto& commands = foreground.GetCommands();
|
||||
auto submenuIt = std::find_if(
|
||||
commands.begin(),
|
||||
commands.end(),
|
||||
[](const auto& command) {
|
||||
return command.type == UIDrawCommandType::Text && command.text == ">";
|
||||
});
|
||||
ASSERT_NE(submenuIt, commands.end());
|
||||
|
||||
const UIRect& submenuRect = layout.itemRects[2];
|
||||
const float expectedLeft =
|
||||
submenuRect.x + submenuRect.width -
|
||||
metrics.shortcutInsetRight -
|
||||
metrics.submenuIndicatorWidth;
|
||||
EXPECT_FLOAT_EQ(submenuIt->position.x, expectedLeft);
|
||||
EXPECT_LE(
|
||||
submenuIt->position.x + metrics.estimatedGlyphWidth,
|
||||
submenuRect.x + submenuRect.width - metrics.shortcutInsetRight + 0.001f);
|
||||
}
|
||||
|
||||
@@ -149,15 +149,16 @@ TEST(UIEditorTabStripTest, BackgroundAndForegroundEmitStableChromeCommands) {
|
||||
|
||||
UIDrawList background("TabStripBackground");
|
||||
AppendUIEditorTabStripBackground(background, layout, state);
|
||||
ASSERT_EQ(background.GetCommandCount(), 9u);
|
||||
ASSERT_EQ(background.GetCommandCount(), 8u);
|
||||
const auto& backgroundCommands = background.GetCommands();
|
||||
EXPECT_EQ(backgroundCommands[0].type, UIDrawCommandType::FilledRect);
|
||||
EXPECT_EQ(backgroundCommands[3].type, UIDrawCommandType::RectOutline);
|
||||
EXPECT_EQ(backgroundCommands[4].type, UIDrawCommandType::FilledRect);
|
||||
EXPECT_EQ(backgroundCommands[5].type, UIDrawCommandType::RectOutline);
|
||||
EXPECT_EQ(backgroundCommands[1].type, UIDrawCommandType::FilledRect);
|
||||
EXPECT_EQ(backgroundCommands[2].type, UIDrawCommandType::FilledRect);
|
||||
EXPECT_EQ(backgroundCommands[3].type, UIDrawCommandType::FilledRect);
|
||||
EXPECT_EQ(backgroundCommands[4].type, UIDrawCommandType::RectOutline);
|
||||
EXPECT_EQ(backgroundCommands[5].type, UIDrawCommandType::FilledRect);
|
||||
EXPECT_EQ(backgroundCommands[6].type, UIDrawCommandType::FilledRect);
|
||||
EXPECT_EQ(backgroundCommands[7].type, UIDrawCommandType::FilledRect);
|
||||
EXPECT_EQ(backgroundCommands[8].type, UIDrawCommandType::RectOutline);
|
||||
EXPECT_EQ(backgroundCommands[7].type, UIDrawCommandType::RectOutline);
|
||||
|
||||
UIDrawList foreground("TabStripForeground");
|
||||
AppendUIEditorTabStripForeground(foreground, layout, items, state);
|
||||
@@ -198,13 +199,12 @@ TEST(UIEditorTabStripTest, ForegroundCentersTabLabelsWithinHeaderContentArea) {
|
||||
ASSERT_EQ(commands[3].type, UIDrawCommandType::Text);
|
||||
ASSERT_EQ(commands[6].type, UIDrawCommandType::Text);
|
||||
|
||||
const float padding = 8.0f;
|
||||
const float firstExpectedX =
|
||||
layout.tabHeaderRects[0].x + padding +
|
||||
((layout.tabHeaderRects[0].width - padding * 2.0f) - items[0].desiredHeaderLabelWidth) * 0.5f;
|
||||
layout.tabHeaderRects[0].x +
|
||||
std::floor((layout.tabHeaderRects[0].width - items[0].desiredHeaderLabelWidth) * 0.5f);
|
||||
const float secondExpectedX =
|
||||
layout.tabHeaderRects[1].x + padding +
|
||||
((layout.tabHeaderRects[1].width - padding * 2.0f) - items[1].desiredHeaderLabelWidth) * 0.5f;
|
||||
layout.tabHeaderRects[1].x +
|
||||
std::floor((layout.tabHeaderRects[1].width - items[1].desiredHeaderLabelWidth) * 0.5f);
|
||||
|
||||
EXPECT_FLOAT_EQ(commands[3].position.x, firstExpectedX);
|
||||
EXPECT_FLOAT_EQ(commands[6].position.x, secondExpectedX);
|
||||
|
||||
@@ -39,6 +39,16 @@ bool ContainsTextCommand(const UIDrawList& drawList, std::string_view text) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ContainsCommandType(const UIDrawList& drawList, UIDrawCommandType type) {
|
||||
for (const auto& command : drawList.GetCommands()) {
|
||||
if (command.type == type) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<UIEditorTreeViewItem> BuildTreeItems() {
|
||||
return {
|
||||
{ "scene", "Scene", 0u, false, 0.0f },
|
||||
@@ -178,10 +188,38 @@ TEST(UIEditorTreeViewTest, BackgroundAndForegroundEmitStableCommands) {
|
||||
AppendUIEditorTreeViewForeground(foreground, layout, items);
|
||||
ASSERT_EQ(foreground.GetCommandCount(), 20u);
|
||||
EXPECT_EQ(foreground.GetCommands()[0].type, UIDrawCommandType::PushClipRect);
|
||||
EXPECT_TRUE(ContainsTextCommand(foreground, "v"));
|
||||
EXPECT_TRUE(ContainsCommandType(foreground, UIDrawCommandType::FilledTriangle));
|
||||
EXPECT_TRUE(ContainsTextCommand(foreground, "Scene"));
|
||||
EXPECT_TRUE(ContainsTextCommand(foreground, "Camera"));
|
||||
EXPECT_EQ(foreground.GetCommands()[19].type, UIDrawCommandType::PopClipRect);
|
||||
}
|
||||
|
||||
TEST(UIEditorTreeViewTest, LeadingIconAddsImageCommandAndReservesIconRect) {
|
||||
std::vector<UIEditorTreeViewItem> items = {
|
||||
{ "folder", "Assets", 0u, true, 0.0f, XCEngine::UI::UITextureHandle { 1u, 18u, 18u } }
|
||||
};
|
||||
UIExpansionModel expansionModel = {};
|
||||
|
||||
UIEditorTreeViewMetrics metrics = {};
|
||||
metrics.rowHeight = 20.0f;
|
||||
metrics.horizontalPadding = 6.0f;
|
||||
metrics.disclosureExtent = 18.0f;
|
||||
metrics.disclosureLabelGap = 2.0f;
|
||||
metrics.iconExtent = 18.0f;
|
||||
metrics.iconLabelGap = 2.0f;
|
||||
|
||||
const UIEditorTreeViewLayout layout =
|
||||
BuildUIEditorTreeViewLayout(UIRect(10.0f, 12.0f, 240.0f, 80.0f), items, expansionModel, metrics);
|
||||
|
||||
ASSERT_EQ(layout.iconRects.size(), 1u);
|
||||
EXPECT_FLOAT_EQ(layout.iconRects[0].x, 36.0f);
|
||||
EXPECT_FLOAT_EQ(layout.iconRects[0].y, 13.0f);
|
||||
EXPECT_FLOAT_EQ(layout.labelRects[0].x, 56.0f);
|
||||
|
||||
UIDrawList foreground("TreeViewForegroundWithIcon");
|
||||
AppendUIEditorTreeViewForeground(foreground, layout, items);
|
||||
EXPECT_TRUE(ContainsCommandType(foreground, UIDrawCommandType::Image));
|
||||
EXPECT_TRUE(ContainsTextCommand(foreground, "Assets"));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user