Stabilize XCEditor shell foundation widgets
This commit is contained in:
@@ -8,6 +8,8 @@ add_custom_target(editor_ui_integration_tests
|
||||
DEPENDS
|
||||
editor_ui_workspace_shell_compose_validation
|
||||
editor_ui_menu_bar_basic_validation
|
||||
editor_ui_panel_frame_basic_validation
|
||||
editor_ui_tab_strip_basic_validation
|
||||
editor_ui_panel_session_flow_validation
|
||||
editor_ui_layout_persistence_validation
|
||||
editor_ui_shortcut_dispatch_validation
|
||||
|
||||
@@ -14,6 +14,8 @@ Layout:
|
||||
- `shared/`: shared host wrapper, scenario registry, shared theme
|
||||
- `shell/workspace_shell_compose/`: split/tab/panel shell compose only
|
||||
- `shell/menu_bar_basic/`: menu bar open/close/hover/dispatch only
|
||||
- `shell/panel_frame_basic/`: panel frame layout/state/hit-test only
|
||||
- `shell/tab_strip_basic/`: tab strip layout/state/hit-test/close/navigation only
|
||||
- `state/panel_session_flow/`: panel session state flow only
|
||||
- `state/layout_persistence/`: layout save/load/reset only
|
||||
- `state/shortcut_dispatch/`: shortcut match/suppression/dispatch only
|
||||
@@ -30,6 +32,16 @@ Scenarios:
|
||||
Executable: `XCUIEditorMenuBarBasicValidation.exe`
|
||||
Scope: menu bar open/close, hover, dismiss, menu command dispatch only
|
||||
|
||||
- `editor.shell.panel_frame_basic`
|
||||
Build target: `editor_ui_panel_frame_basic_validation`
|
||||
Executable: `XCUIEditorPanelFrameBasicValidation.exe`
|
||||
Scope: panel frame header/body/footer layout, focus/active/hover chrome, pin/close hit target only
|
||||
|
||||
- `editor.shell.tab_strip_basic`
|
||||
Build target: `editor_ui_tab_strip_basic_validation`
|
||||
Executable: `XCUIEditorTabStripBasicValidation.exe`
|
||||
Scope: tab header layout, selected/hover/focus, close hit target, close fallback, Left/Right/Home/End navigation only
|
||||
|
||||
- `editor.state.panel_session_flow`
|
||||
Build target: `editor_ui_panel_session_flow_validation`
|
||||
Executable: `XCUIEditorPanelSessionFlowValidation.exe`
|
||||
@@ -59,6 +71,12 @@ Selected controls:
|
||||
- `shell/menu_bar_basic/`
|
||||
Click `File / Window / Layout`, move the mouse across menu items, click outside the menu or press `Esc`, press `F12`.
|
||||
|
||||
- `shell/panel_frame_basic/`
|
||||
Move the mouse over the preview panel, click `Body / Pin / Close`, toggle `Active / Focus / Closable / Footer`, press `F12`.
|
||||
|
||||
- `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`.
|
||||
|
||||
- `state/panel_session_flow/`
|
||||
Click `Hide Active / Show Doc A / Close Doc B / Open Doc B / Activate Details / Reset`, press `F12`.
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
add_subdirectory(workspace_shell_compose)
|
||||
add_subdirectory(panel_frame_basic)
|
||||
add_subdirectory(tab_strip_basic)
|
||||
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/menu_bar_basic/CMakeLists.txt")
|
||||
add_subdirectory(menu_bar_basic)
|
||||
endif()
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,30 @@
|
||||
add_executable(editor_ui_panel_frame_basic_validation WIN32
|
||||
main.cpp
|
||||
)
|
||||
|
||||
target_include_directories(editor_ui_panel_frame_basic_validation PRIVATE
|
||||
${CMAKE_SOURCE_DIR}/new_editor/include
|
||||
${CMAKE_SOURCE_DIR}/new_editor/app
|
||||
${CMAKE_SOURCE_DIR}/engine/include
|
||||
)
|
||||
|
||||
target_compile_definitions(editor_ui_panel_frame_basic_validation PRIVATE
|
||||
UNICODE
|
||||
_UNICODE
|
||||
XCENGINE_EDITOR_UI_TESTS_REPO_ROOT="${XCENGINE_EDITOR_UI_TESTS_REPO_ROOT_PATH}"
|
||||
)
|
||||
|
||||
if(MSVC)
|
||||
target_compile_options(editor_ui_panel_frame_basic_validation PRIVATE /utf-8 /FS)
|
||||
set_property(TARGET editor_ui_panel_frame_basic_validation PROPERTY
|
||||
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
|
||||
endif()
|
||||
|
||||
target_link_libraries(editor_ui_panel_frame_basic_validation PRIVATE
|
||||
XCUIEditorLib
|
||||
XCUIEditorHost
|
||||
)
|
||||
|
||||
set_target_properties(editor_ui_panel_frame_basic_validation PROPERTIES
|
||||
OUTPUT_NAME "XCUIEditorPanelFrameBasicValidation"
|
||||
)
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
520
tests/UI/Editor/integration/shell/panel_frame_basic/main.cpp
Normal file
520
tests/UI/Editor/integration/shell/panel_frame_basic/main.cpp
Normal file
@@ -0,0 +1,520 @@
|
||||
#ifndef NOMINMAX
|
||||
#define NOMINMAX
|
||||
#endif
|
||||
|
||||
#include <XCEditor/Widgets/UIEditorPanelFrame.h>
|
||||
#include "Host/AutoScreenshot.h"
|
||||
#include "Host/NativeRenderer.h"
|
||||
|
||||
#include <XCEngine/UI/DrawData.h>
|
||||
|
||||
#include <windows.h>
|
||||
#include <windowsx.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
#ifndef XCENGINE_EDITOR_UI_TESTS_REPO_ROOT
|
||||
#define XCENGINE_EDITOR_UI_TESTS_REPO_ROOT "."
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
|
||||
using XCEngine::UI::UIColor;
|
||||
using XCEngine::UI::UIDrawData;
|
||||
using XCEngine::UI::UIDrawList;
|
||||
using XCEngine::UI::UIPoint;
|
||||
using XCEngine::UI::UIRect;
|
||||
using XCEngine::UI::Editor::Host::AutoScreenshotController;
|
||||
using XCEngine::UI::Editor::Host::NativeRenderer;
|
||||
using XCEngine::UI::Editor::Widgets::AppendUIEditorPanelFrameBackground;
|
||||
using XCEngine::UI::Editor::Widgets::AppendUIEditorPanelFrameForeground;
|
||||
using XCEngine::UI::Editor::Widgets::BuildUIEditorPanelFrameLayout;
|
||||
using XCEngine::UI::Editor::Widgets::HitTestUIEditorPanelFrame;
|
||||
using XCEngine::UI::Editor::Widgets::UIEditorPanelFrameHitTarget;
|
||||
using XCEngine::UI::Editor::Widgets::UIEditorPanelFrameLayout;
|
||||
using XCEngine::UI::Editor::Widgets::UIEditorPanelFrameState;
|
||||
using XCEngine::UI::Editor::Widgets::UIEditorPanelFrameText;
|
||||
|
||||
constexpr const wchar_t* kWindowClassName = L"XCUIEditorPanelFrameBasicValidation";
|
||||
constexpr const wchar_t* kWindowTitle = L"XCUI Editor | PanelFrame Basic";
|
||||
|
||||
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.30f, 0.30f, 0.30f, 1.0f);
|
||||
constexpr UIColor kCardAccent(0.82f, 0.82f, 0.82f, 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 kButtonBg(0.26f, 0.26f, 0.26f, 1.0f);
|
||||
constexpr UIColor kButtonOnBg(0.42f, 0.42f, 0.42f, 1.0f);
|
||||
constexpr UIColor kButtonBorder(0.48f, 0.48f, 0.48f, 1.0f);
|
||||
|
||||
enum class ActionId : unsigned char {
|
||||
ToggleFooter = 0,
|
||||
TogglePin,
|
||||
ToggleClose,
|
||||
Reset
|
||||
};
|
||||
|
||||
struct ButtonState {
|
||||
ActionId action = ActionId::ToggleFooter;
|
||||
std::string label = {};
|
||||
UIRect rect = {};
|
||||
bool selected = false;
|
||||
};
|
||||
|
||||
std::filesystem::path ResolveRepoRootPath() {
|
||||
std::string root = XCENGINE_EDITOR_UI_TESTS_REPO_ROOT;
|
||||
if (root.size() >= 2u && root.front() == '"' && root.back() == '"') {
|
||||
root = root.substr(1u, root.size() - 2u);
|
||||
}
|
||||
|
||||
return std::filesystem::path(root).lexically_normal();
|
||||
}
|
||||
|
||||
bool ContainsPoint(const UIRect& rect, float x, float y) {
|
||||
return x >= rect.x &&
|
||||
x <= rect.x + rect.width &&
|
||||
y >= rect.y &&
|
||||
y <= rect.y + rect.height;
|
||||
}
|
||||
|
||||
std::string DescribePart(UIEditorPanelFrameHitTarget part) {
|
||||
switch (part) {
|
||||
case UIEditorPanelFrameHitTarget::Header: return "Header";
|
||||
case UIEditorPanelFrameHitTarget::Body: return "Body";
|
||||
case UIEditorPanelFrameHitTarget::Footer: return "Footer";
|
||||
case UIEditorPanelFrameHitTarget::PinButton: return "Pin";
|
||||
case UIEditorPanelFrameHitTarget::CloseButton: return "Close";
|
||||
default: return "None";
|
||||
}
|
||||
}
|
||||
|
||||
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 + 38.0f), std::string(subtitle), kTextMuted, 12.0f);
|
||||
}
|
||||
}
|
||||
|
||||
void DrawButton(
|
||||
UIDrawList& drawList,
|
||||
const ButtonState& button) {
|
||||
drawList.AddFilledRect(button.rect, button.selected ? kButtonOnBg : kButtonBg, 8.0f);
|
||||
drawList.AddRectOutline(button.rect, button.selected ? kCardAccent : kButtonBorder, 1.0f, 8.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(button.rect.x + 12.0f, button.rect.y + 10.0f),
|
||||
button.label,
|
||||
kTextPrimary,
|
||||
12.0f);
|
||||
}
|
||||
|
||||
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)));
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case WM_MOUSELEAVE:
|
||||
if (app != nullptr) {
|
||||
app->HandleMouseLeave();
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case WM_LBUTTONUP:
|
||||
if (app != nullptr) {
|
||||
app->HandleClick(
|
||||
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 && wParam == VK_F12) {
|
||||
app->m_autoScreenshot.RequestCapture("manual_f12");
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case WM_PAINT:
|
||||
if (app != nullptr) {
|
||||
PAINTSTRUCT paintStruct = {};
|
||||
BeginPaint(hwnd, &paintStruct);
|
||||
app->RenderFrame();
|
||||
EndPaint(hwnd, &paintStruct);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case WM_DESTROY:
|
||||
PostQuitMessage(0);
|
||||
return 0;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return DefWindowProcW(hwnd, message, wParam, lParam);
|
||||
}
|
||||
|
||||
bool Initialize(HINSTANCE hInstance, int nCmdShow) {
|
||||
m_captureRoot =
|
||||
ResolveRepoRootPath() / "tests/UI/Editor/integration/shell/panel_frame_basic/captures";
|
||||
m_autoScreenshot.Initialize(m_captureRoot);
|
||||
|
||||
WNDCLASSEXW windowClass = {};
|
||||
windowClass.cbSize = sizeof(windowClass);
|
||||
windowClass.style = CS_HREDRAW | CS_VREDRAW;
|
||||
windowClass.lpfnWndProc = &ScenarioApp::WndProc;
|
||||
windowClass.hInstance = hInstance;
|
||||
windowClass.hCursor = LoadCursorW(nullptr, IDC_ARROW);
|
||||
windowClass.lpszClassName = kWindowClassName;
|
||||
|
||||
m_windowClassAtom = RegisterClassExW(&windowClass);
|
||||
if (m_windowClassAtom == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_hwnd = CreateWindowExW(
|
||||
0,
|
||||
kWindowClassName,
|
||||
kWindowTitle,
|
||||
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
|
||||
CW_USEDEFAULT,
|
||||
CW_USEDEFAULT,
|
||||
1440,
|
||||
920,
|
||||
nullptr,
|
||||
nullptr,
|
||||
hInstance,
|
||||
this);
|
||||
if (m_hwnd == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ShowWindow(m_hwnd, nCmdShow);
|
||||
UpdateWindow(m_hwnd);
|
||||
|
||||
if (!m_renderer.Initialize(m_hwnd)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ResetState();
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
void OnResize(UINT width, UINT height) {
|
||||
m_renderer.Resize(width, height);
|
||||
}
|
||||
|
||||
void HandleMouseMove(float x, float y) {
|
||||
m_mousePosition = UIPoint(x, y);
|
||||
TRACKMOUSEEVENT event = {};
|
||||
event.cbSize = sizeof(event);
|
||||
event.dwFlags = TME_LEAVE;
|
||||
event.hwndTrack = m_hwnd;
|
||||
TrackMouseEvent(&event);
|
||||
UpdateHoveredPart();
|
||||
}
|
||||
|
||||
void HandleMouseLeave() {
|
||||
m_mousePosition = UIPoint(-1000.0f, -1000.0f);
|
||||
m_hoveredPart = UIEditorPanelFrameHitTarget::None;
|
||||
}
|
||||
|
||||
void HandleClick(float x, float y) {
|
||||
for (const ButtonState& button : m_buttons) {
|
||||
if (ContainsPoint(button.rect, x, y)) {
|
||||
ExecuteAction(button.action);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const UIEditorPanelFrameHitTarget part =
|
||||
HitTestUIEditorPanelFrame(m_layout, m_state, UIPoint(x, y));
|
||||
switch (part) {
|
||||
case UIEditorPanelFrameHitTarget::Header:
|
||||
m_state.active = !m_state.active;
|
||||
m_lastResult = m_state.active ? "Header click -> Active = On" : "Header click -> Active = Off";
|
||||
break;
|
||||
case UIEditorPanelFrameHitTarget::Body:
|
||||
case UIEditorPanelFrameHitTarget::Footer:
|
||||
m_state.focused = true;
|
||||
m_lastResult = "Body/Footer click -> Focus = On";
|
||||
break;
|
||||
case UIEditorPanelFrameHitTarget::PinButton:
|
||||
if (m_state.pinnable) {
|
||||
m_state.pinned = !m_state.pinned;
|
||||
m_lastResult = m_state.pinned ? "Pin click -> Pinned = On" : "Pin click -> Pinned = Off";
|
||||
}
|
||||
break;
|
||||
case UIEditorPanelFrameHitTarget::CloseButton:
|
||||
if (m_state.closable) {
|
||||
++m_closeDispatchCount;
|
||||
m_lastResult = "Close click -> CloseRequested #" + std::to_string(m_closeDispatchCount);
|
||||
}
|
||||
break;
|
||||
case UIEditorPanelFrameHitTarget::None:
|
||||
default:
|
||||
m_state.focused = false;
|
||||
m_lastResult = "Outside click -> Focus = Off";
|
||||
break;
|
||||
}
|
||||
|
||||
UpdateHoveredPart();
|
||||
}
|
||||
|
||||
void ExecuteAction(ActionId action) {
|
||||
switch (action) {
|
||||
case ActionId::ToggleFooter:
|
||||
m_state.showFooter = !m_state.showFooter;
|
||||
m_lastResult = m_state.showFooter ? "Footer = On" : "Footer = Off";
|
||||
break;
|
||||
case ActionId::TogglePin:
|
||||
m_state.pinnable = !m_state.pinnable;
|
||||
if (!m_state.pinnable) {
|
||||
m_state.pinned = false;
|
||||
}
|
||||
m_lastResult = m_state.pinnable ? "Pin button = On" : "Pin button = Off";
|
||||
break;
|
||||
case ActionId::ToggleClose:
|
||||
m_state.closable = !m_state.closable;
|
||||
m_lastResult = m_state.closable ? "Close button = On" : "Close button = Off";
|
||||
break;
|
||||
case ActionId::Reset:
|
||||
ResetState();
|
||||
m_lastResult = "State reset";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void ResetState() {
|
||||
m_state = {};
|
||||
m_state.active = true;
|
||||
m_state.showFooter = true;
|
||||
m_state.pinnable = true;
|
||||
m_state.closable = true;
|
||||
m_hoveredPart = UIEditorPanelFrameHitTarget::None;
|
||||
m_lastResult = "Ready";
|
||||
m_closeDispatchCount = 0;
|
||||
}
|
||||
|
||||
void UpdateHoveredPart() {
|
||||
m_hoveredPart = HitTestUIEditorPanelFrame(m_layout, m_state, m_mousePosition);
|
||||
}
|
||||
|
||||
void BuildButtons(float left, float top, float width) {
|
||||
const float buttonHeight = 34.0f;
|
||||
const float gap = 10.0f;
|
||||
m_buttons = {
|
||||
{ ActionId::ToggleFooter, "Footer", UIRect(left, top, width, buttonHeight), m_state.showFooter },
|
||||
{ ActionId::TogglePin, "Pin Button", UIRect(left, top + (buttonHeight + gap), width, buttonHeight), m_state.pinnable },
|
||||
{ ActionId::ToggleClose, "Close Button", UIRect(left, top + (buttonHeight + gap) * 2.0f, width, buttonHeight), m_state.closable },
|
||||
{ ActionId::Reset, "Reset", UIRect(left, top + (buttonHeight + gap) * 3.0f, width, buttonHeight), false }
|
||||
};
|
||||
}
|
||||
|
||||
void RenderFrame() {
|
||||
RECT clientRect = {};
|
||||
GetClientRect(m_hwnd, &clientRect);
|
||||
const float width = static_cast<float>((std::max)(1L, clientRect.right - clientRect.left));
|
||||
const float height = static_cast<float>((std::max)(1L, clientRect.bottom - clientRect.top));
|
||||
|
||||
const float leftColumnWidth = 340.0f;
|
||||
const float outerPadding = 20.0f;
|
||||
const UIRect introRect(outerPadding, outerPadding, leftColumnWidth, 148.0f);
|
||||
const UIRect controlsRect(outerPadding, 188.0f, leftColumnWidth, 180.0f);
|
||||
const UIRect stateRect(outerPadding, 388.0f, leftColumnWidth, 220.0f);
|
||||
const UIRect panelRect(
|
||||
leftColumnWidth + outerPadding * 2.0f,
|
||||
outerPadding,
|
||||
width - leftColumnWidth - outerPadding * 3.0f,
|
||||
height - outerPadding * 2.0f);
|
||||
|
||||
BuildButtons(controlsRect.x + 16.0f, controlsRect.y + 54.0f, controlsRect.width - 32.0f);
|
||||
|
||||
UIDrawData drawData = {};
|
||||
UIDrawList& drawList = drawData.EmplaceDrawList("PanelFrameBasic");
|
||||
drawList.AddFilledRect(UIRect(0.0f, 0.0f, width, height), kWindowBg);
|
||||
|
||||
DrawCard(
|
||||
drawList,
|
||||
introRect,
|
||||
"测试功能:PanelFrame 基础壳层",
|
||||
"重点检查:Header / Body / Footer 布局,Active / Focus 边框,Pin / Close 命中。");
|
||||
drawList.AddText(
|
||||
UIPoint(introRect.x + 16.0f, introRect.y + 66.0f),
|
||||
"操作:移动鼠标观察 hover;点 Header 切 Active;点 Body/Footer 取 Focus;点 Pin/Close 看 Result;按 F12 截图。",
|
||||
kTextMuted,
|
||||
12.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(introRect.x + 16.0f, introRect.y + 90.0f),
|
||||
"这个场景只验证 Editor 基础层 PanelFrame,不包含任何业务面板。",
|
||||
kTextWeak,
|
||||
12.0f);
|
||||
|
||||
DrawCard(drawList, controlsRect, "开关", "这里只保留基础状态开关,避免试验面板过杂。");
|
||||
for (const ButtonState& button : m_buttons) {
|
||||
DrawButton(drawList, button);
|
||||
}
|
||||
|
||||
DrawCard(drawList, stateRect, "状态", "右侧面板的命中结果和状态变化会同步显示在这里。");
|
||||
drawList.AddText(
|
||||
UIPoint(stateRect.x + 16.0f, stateRect.y + 66.0f),
|
||||
"Hover: " + DescribePart(m_hoveredPart),
|
||||
kTextPrimary,
|
||||
13.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(stateRect.x + 16.0f, stateRect.y + 92.0f),
|
||||
std::string("Active: ") + (m_state.active ? "On" : "Off"),
|
||||
kTextPrimary,
|
||||
13.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(stateRect.x + 16.0f, stateRect.y + 118.0f),
|
||||
std::string("Focused: ") + (m_state.focused ? "On" : "Off"),
|
||||
kTextPrimary,
|
||||
13.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(stateRect.x + 16.0f, stateRect.y + 144.0f),
|
||||
std::string("Pinned: ") + (m_state.pinned ? "On" : "Off"),
|
||||
kTextPrimary,
|
||||
13.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(stateRect.x + 16.0f, stateRect.y + 170.0f),
|
||||
"Result: " + m_lastResult,
|
||||
kTextMuted,
|
||||
12.0f);
|
||||
|
||||
UIEditorPanelFrameState frameState = m_state;
|
||||
frameState.hovered = m_hoveredPart != UIEditorPanelFrameHitTarget::None;
|
||||
frameState.pinHovered = m_hoveredPart == UIEditorPanelFrameHitTarget::PinButton;
|
||||
frameState.closeHovered = m_hoveredPart == UIEditorPanelFrameHitTarget::CloseButton;
|
||||
m_layout = BuildUIEditorPanelFrameLayout(panelRect, frameState);
|
||||
|
||||
AppendUIEditorPanelFrameBackground(drawList, m_layout, frameState);
|
||||
AppendUIEditorPanelFrameForeground(
|
||||
drawList,
|
||||
m_layout,
|
||||
frameState,
|
||||
UIEditorPanelFrameText{
|
||||
"Inspector Placeholder",
|
||||
"PanelFrame foundation validation",
|
||||
m_state.showFooter
|
||||
? "Footer visible | Active=" + std::string(m_state.active ? "On" : "Off")
|
||||
: ""
|
||||
});
|
||||
|
||||
drawList.AddText(
|
||||
UIPoint(m_layout.bodyRect.x, m_layout.bodyRect.y),
|
||||
"Body content placeholder",
|
||||
kTextPrimary,
|
||||
15.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(m_layout.bodyRect.x, m_layout.bodyRect.y + 28.0f),
|
||||
"Hover current region: " + DescribePart(m_hoveredPart),
|
||||
kTextMuted,
|
||||
12.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(m_layout.bodyRect.x, m_layout.bodyRect.y + 50.0f),
|
||||
"Pin button and Close button use PanelFrame hit rects.",
|
||||
kTextMuted,
|
||||
12.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(m_layout.bodyRect.x, m_layout.bodyRect.y + 72.0f),
|
||||
"Close does not destroy the panel here. It only verifies dispatch intent.",
|
||||
kTextWeak,
|
||||
12.0f);
|
||||
|
||||
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<ButtonState> m_buttons = {};
|
||||
UIPoint m_mousePosition = UIPoint(-1000.0f, -1000.0f);
|
||||
UIEditorPanelFrameState m_state = {};
|
||||
UIEditorPanelFrameLayout m_layout = {};
|
||||
UIEditorPanelFrameHitTarget m_hoveredPart = UIEditorPanelFrameHitTarget::None;
|
||||
std::string m_lastResult = {};
|
||||
int m_closeDispatchCount = 0;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, LPWSTR, int nCmdShow) {
|
||||
return ScenarioApp().Run(hInstance, nCmdShow);
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
add_executable(editor_ui_tab_strip_basic_validation WIN32
|
||||
main.cpp
|
||||
)
|
||||
|
||||
target_include_directories(editor_ui_tab_strip_basic_validation PRIVATE
|
||||
${CMAKE_SOURCE_DIR}/new_editor/include
|
||||
${CMAKE_SOURCE_DIR}/new_editor/app
|
||||
${CMAKE_SOURCE_DIR}/engine/include
|
||||
)
|
||||
|
||||
target_compile_definitions(editor_ui_tab_strip_basic_validation PRIVATE
|
||||
UNICODE
|
||||
_UNICODE
|
||||
XCENGINE_EDITOR_UI_TESTS_REPO_ROOT="${XCENGINE_EDITOR_UI_TESTS_REPO_ROOT_PATH}"
|
||||
)
|
||||
|
||||
if(MSVC)
|
||||
target_compile_options(editor_ui_tab_strip_basic_validation PRIVATE /utf-8 /FS)
|
||||
set_property(TARGET editor_ui_tab_strip_basic_validation PROPERTY
|
||||
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
|
||||
endif()
|
||||
|
||||
target_link_libraries(editor_ui_tab_strip_basic_validation PRIVATE
|
||||
XCUIEditorLib
|
||||
XCUIEditorHost
|
||||
)
|
||||
|
||||
set_target_properties(editor_ui_tab_strip_basic_validation PROPERTIES
|
||||
OUTPUT_NAME "XCUIEditorTabStripBasicValidation"
|
||||
)
|
||||
740
tests/UI/Editor/integration/shell/tab_strip_basic/main.cpp
Normal file
740
tests/UI/Editor/integration/shell/tab_strip_basic/main.cpp
Normal file
@@ -0,0 +1,740 @@
|
||||
#ifndef NOMINMAX
|
||||
#define NOMINMAX
|
||||
#endif
|
||||
|
||||
#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/UI/DrawData.h>
|
||||
#include <XCEngine/UI/Widgets/UITabStripModel.h>
|
||||
|
||||
#include <windows.h>
|
||||
#include <windowsx.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <filesystem>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
#ifndef XCENGINE_EDITOR_UI_TESTS_REPO_ROOT
|
||||
#define XCENGINE_EDITOR_UI_TESTS_REPO_ROOT "."
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
|
||||
using XCEngine::UI::UIColor;
|
||||
using XCEngine::UI::UIDrawData;
|
||||
using XCEngine::UI::UIDrawList;
|
||||
using XCEngine::UI::UIPoint;
|
||||
using XCEngine::UI::UIRect;
|
||||
using XCEngine::UI::Widgets::UITabStripModel;
|
||||
using XCEngine::UI::Editor::BuildDefaultUIEditorWorkspaceController;
|
||||
using XCEngine::UI::Editor::BuildUIEditorWorkspacePanel;
|
||||
using XCEngine::UI::Editor::BuildUIEditorWorkspaceTabStack;
|
||||
using XCEngine::UI::Editor::FindUIEditorPanelDescriptor;
|
||||
using XCEngine::UI::Editor::FindUIEditorPanelSessionState;
|
||||
using XCEngine::UI::Editor::GetUIEditorWorkspaceCommandStatusName;
|
||||
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::UIEditorWorkspaceCommand;
|
||||
using XCEngine::UI::Editor::UIEditorWorkspaceCommandKind;
|
||||
using XCEngine::UI::Editor::UIEditorWorkspaceCommandResult;
|
||||
using XCEngine::UI::Editor::UIEditorWorkspaceController;
|
||||
using XCEngine::UI::Editor::UIEditorWorkspaceModel;
|
||||
using XCEngine::UI::Editor::UIEditorWorkspaceNode;
|
||||
using XCEngine::UI::Editor::UIEditorWorkspaceNodeKind;
|
||||
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;
|
||||
using XCEngine::UI::Editor::Widgets::UIEditorTabStripHitTargetKind;
|
||||
using XCEngine::UI::Editor::Widgets::UIEditorTabStripInvalidIndex;
|
||||
using XCEngine::UI::Editor::Widgets::UIEditorTabStripItem;
|
||||
using XCEngine::UI::Editor::Widgets::UIEditorTabStripLayout;
|
||||
using XCEngine::UI::Editor::Widgets::UIEditorTabStripState;
|
||||
|
||||
constexpr const wchar_t* kWindowClassName = L"XCUIEditorTabStripBasicValidation";
|
||||
constexpr const wchar_t* kWindowTitle = L"XCUI Editor | TabStrip Basic";
|
||||
|
||||
constexpr UIColor kWindowBg(0.15f, 0.15f, 0.15f, 1.0f);
|
||||
constexpr UIColor kCardBg(0.19f, 0.19f, 0.19f, 1.0f);
|
||||
constexpr UIColor kCardBorder(0.30f, 0.30f, 0.30f, 1.0f);
|
||||
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.62f, 0.74f, 0.62f, 1.0f);
|
||||
constexpr UIColor kWarning(0.78f, 0.70f, 0.46f, 1.0f);
|
||||
constexpr UIColor kDanger(0.82f, 0.48f, 0.48f, 1.0f);
|
||||
constexpr UIColor kButtonBg(0.25f, 0.25f, 0.25f, 1.0f);
|
||||
constexpr UIColor kButtonHoveredBg(0.31f, 0.31f, 0.31f, 1.0f);
|
||||
|
||||
std::filesystem::path ResolveRepoRootPath() {
|
||||
std::string root = XCENGINE_EDITOR_UI_TESTS_REPO_ROOT;
|
||||
if (root.size() >= 2u && root.front() == '"' && root.back() == '"') {
|
||||
root = root.substr(1u, root.size() - 2u);
|
||||
}
|
||||
|
||||
return std::filesystem::path(root).lexically_normal();
|
||||
}
|
||||
|
||||
bool ContainsPoint(const UIRect& rect, float x, float y) {
|
||||
return x >= rect.x &&
|
||||
x <= rect.x + rect.width &&
|
||||
y >= rect.y &&
|
||||
y <= rect.y + rect.height;
|
||||
}
|
||||
|
||||
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 UIRect& rect,
|
||||
std::string_view label,
|
||||
bool hovered) {
|
||||
drawList.AddFilledRect(rect, hovered ? kButtonHoveredBg : kButtonBg, 8.0f);
|
||||
drawList.AddRectOutline(rect, kCardBorder, 1.0f, 8.0f);
|
||||
drawList.AddText(UIPoint(rect.x + 14.0f, rect.y + 11.0f), std::string(label), kTextPrimary, 13.0f);
|
||||
}
|
||||
|
||||
UIEditorPanelRegistry BuildPanelRegistry() {
|
||||
UIEditorPanelRegistry registry = {};
|
||||
registry.panels = {
|
||||
{ "doc-a", "Document A", {}, true, true, true },
|
||||
{ "doc-b", "Document B", {}, true, true, true },
|
||||
{ "doc-c", "Document C", {}, true, true, false }
|
||||
};
|
||||
return registry;
|
||||
}
|
||||
|
||||
UIEditorWorkspaceModel BuildWorkspace() {
|
||||
UIEditorWorkspaceModel workspace = {};
|
||||
workspace.root = BuildUIEditorWorkspaceTabStack(
|
||||
"document-tabs",
|
||||
{
|
||||
BuildUIEditorWorkspacePanel("doc-a-node", "doc-a", "Document A", true),
|
||||
BuildUIEditorWorkspacePanel("doc-b-node", "doc-b", "Document B", true),
|
||||
BuildUIEditorWorkspacePanel("doc-c-node", "doc-c", "Document C", true)
|
||||
},
|
||||
0u);
|
||||
workspace.activePanelId = "doc-a";
|
||||
return workspace;
|
||||
}
|
||||
|
||||
const UIEditorWorkspaceNode* GetRootTabStack(const UIEditorWorkspaceModel& workspace) {
|
||||
return workspace.root.kind == UIEditorWorkspaceNodeKind::TabStack ? &workspace.root : nullptr;
|
||||
}
|
||||
|
||||
std::string DescribeHitTarget(
|
||||
const UIEditorTabStripHitTarget& target,
|
||||
const std::vector<UIEditorTabStripItem>& items) {
|
||||
switch (target.kind) {
|
||||
case UIEditorTabStripHitTargetKind::HeaderBackground:
|
||||
return "HeaderBackground";
|
||||
case UIEditorTabStripHitTargetKind::Content:
|
||||
return "Content";
|
||||
case UIEditorTabStripHitTargetKind::Tab:
|
||||
if (target.index < items.size()) {
|
||||
return "Tab: " + items[target.index].title;
|
||||
}
|
||||
return "Tab";
|
||||
case UIEditorTabStripHitTargetKind::CloseButton:
|
||||
if (target.index < items.size()) {
|
||||
return "CloseButton: " + items[target.index].title;
|
||||
}
|
||||
return "CloseButton";
|
||||
case UIEditorTabStripHitTargetKind::None:
|
||||
default:
|
||||
return "None";
|
||||
}
|
||||
}
|
||||
|
||||
std::string JoinTabTitles(const std::vector<UIEditorTabStripItem>& items) {
|
||||
if (items.empty()) {
|
||||
return "(none)";
|
||||
}
|
||||
|
||||
std::ostringstream stream;
|
||||
for (std::size_t index = 0; index < items.size(); ++index) {
|
||||
if (index > 0u) {
|
||||
stream << " | ";
|
||||
}
|
||||
stream << items[index].title;
|
||||
if (!items[index].closable) {
|
||||
stream << " (locked)";
|
||||
}
|
||||
}
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
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)));
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case WM_MOUSELEAVE:
|
||||
if (app != nullptr) {
|
||||
app->HandleMouseLeave();
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case WM_LBUTTONUP:
|
||||
if (app != nullptr) {
|
||||
app->HandleClick(
|
||||
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) {
|
||||
if (wParam == VK_F12) {
|
||||
app->m_autoScreenshot.RequestCapture("manual_f12");
|
||||
} else {
|
||||
app->HandleKeyDown(static_cast<UINT>(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 Initialize(HINSTANCE hInstance, int nCmdShow) {
|
||||
m_captureRoot =
|
||||
ResolveRepoRootPath() / "tests/UI/Editor/integration/shell/tab_strip_basic/captures";
|
||||
m_autoScreenshot.Initialize(m_captureRoot);
|
||||
|
||||
WNDCLASSEXW windowClass = {};
|
||||
windowClass.cbSize = sizeof(windowClass);
|
||||
windowClass.style = CS_HREDRAW | CS_VREDRAW;
|
||||
windowClass.lpfnWndProc = &ScenarioApp::WndProc;
|
||||
windowClass.hInstance = hInstance;
|
||||
windowClass.hCursor = LoadCursorW(nullptr, IDC_ARROW);
|
||||
windowClass.lpszClassName = kWindowClassName;
|
||||
|
||||
m_windowClassAtom = RegisterClassExW(&windowClass);
|
||||
if (m_windowClassAtom == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_hwnd = CreateWindowExW(
|
||||
0,
|
||||
kWindowClassName,
|
||||
kWindowTitle,
|
||||
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
|
||||
CW_USEDEFAULT,
|
||||
CW_USEDEFAULT,
|
||||
1440,
|
||||
920,
|
||||
nullptr,
|
||||
nullptr,
|
||||
hInstance,
|
||||
this);
|
||||
if (m_hwnd == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ShowWindow(m_hwnd, nCmdShow);
|
||||
UpdateWindow(m_hwnd);
|
||||
|
||||
if (!m_renderer.Initialize(m_hwnd)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
void ResetScenario() {
|
||||
m_controller =
|
||||
BuildDefaultUIEditorWorkspaceController(BuildPanelRegistry(), BuildWorkspace());
|
||||
m_tabStripState = {};
|
||||
m_layout = {};
|
||||
m_tabItems.clear();
|
||||
m_hoverTarget = {};
|
||||
m_mousePosition = UIPoint(-1000.0f, -1000.0f);
|
||||
m_lastResult = "等待操作";
|
||||
m_navigationModel = {};
|
||||
}
|
||||
|
||||
void OnResize(UINT width, UINT height) {
|
||||
if (width == 0u || height == 0u) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_renderer.Resize(width, height);
|
||||
}
|
||||
|
||||
void HandleMouseMove(float x, float y) {
|
||||
m_mousePosition = UIPoint(x, y);
|
||||
TRACKMOUSEEVENT event = {};
|
||||
event.cbSize = sizeof(event);
|
||||
event.dwFlags = TME_LEAVE;
|
||||
event.hwndTrack = m_hwnd;
|
||||
TrackMouseEvent(&event);
|
||||
|
||||
m_resetButtonHovered = ContainsPoint(m_resetButtonRect, x, y);
|
||||
RefreshHoverTarget();
|
||||
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;
|
||||
InvalidateRect(m_hwnd, nullptr, FALSE);
|
||||
}
|
||||
|
||||
void HandleClick(float x, float 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();
|
||||
InvalidateRect(m_hwnd, nullptr, FALSE);
|
||||
}
|
||||
|
||||
void HandleKeyDown(UINT keyCode) {
|
||||
if (!m_tabStripState.focused) {
|
||||
return;
|
||||
}
|
||||
|
||||
RefreshTabItems();
|
||||
bool handled = true;
|
||||
bool changed = false;
|
||||
std::string action = {};
|
||||
|
||||
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) {
|
||||
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()) {
|
||||
DispatchCommand(
|
||||
UIEditorWorkspaceCommandKind::ActivatePanel,
|
||||
m_tabItems[selectedIndex].tabId,
|
||||
action + " -> " + m_tabItems[selectedIndex].title);
|
||||
}
|
||||
|
||||
InvalidateRect(m_hwnd, nullptr, FALSE);
|
||||
}
|
||||
|
||||
void DispatchCommand(
|
||||
UIEditorWorkspaceCommandKind kind,
|
||||
std::string_view panelId,
|
||||
std::string label) {
|
||||
UIEditorWorkspaceCommand command = {};
|
||||
command.kind = kind;
|
||||
command.panelId = std::string(panelId);
|
||||
|
||||
const UIEditorWorkspaceCommandResult result = m_controller.Dispatch(command);
|
||||
m_lastResult =
|
||||
std::move(label) + " -> " +
|
||||
std::string(GetUIEditorWorkspaceCommandStatusName(result.status)) +
|
||||
" | " +
|
||||
result.message;
|
||||
}
|
||||
|
||||
void RefreshTabItems() {
|
||||
const UIEditorWorkspaceModel& workspace = m_controller.GetWorkspace();
|
||||
const UIEditorPanelRegistry& registry = m_controller.GetPanelRegistry();
|
||||
const auto* tabStack = GetRootTabStack(workspace);
|
||||
|
||||
m_tabItems.clear();
|
||||
if (tabStack != nullptr) {
|
||||
for (const UIEditorWorkspaceNode& child : tabStack->children) {
|
||||
if (child.kind != UIEditorWorkspaceNodeKind::Panel) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const auto* sessionState =
|
||||
FindUIEditorPanelSessionState(m_controller.GetSession(), child.panel.panelId);
|
||||
if (sessionState == nullptr || !sessionState->open || !sessionState->visible) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const UIEditorPanelDescriptor* descriptor =
|
||||
FindUIEditorPanelDescriptor(registry, child.panel.panelId);
|
||||
UIEditorTabStripItem item = {};
|
||||
item.tabId = child.panel.panelId;
|
||||
item.title = child.panel.title;
|
||||
item.closable = descriptor != nullptr ? descriptor->canClose : true;
|
||||
m_tabItems.push_back(std::move(item));
|
||||
}
|
||||
}
|
||||
|
||||
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() {
|
||||
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 introRect(outerPadding, outerPadding, leftColumnWidth, 176.0f);
|
||||
const UIRect stateRect(outerPadding, 216.0f, leftColumnWidth, height - 236.0f);
|
||||
const UIRect previewCardRect(
|
||||
leftColumnWidth + outerPadding * 2.0f,
|
||||
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();
|
||||
|
||||
m_resetButtonRect = UIRect(
|
||||
stateRect.x + 16.0f,
|
||||
stateRect.y + 194.0f,
|
||||
stateRect.width - 32.0f,
|
||||
38.0f);
|
||||
|
||||
UIDrawData drawData = {};
|
||||
UIDrawList& drawList = drawData.EmplaceDrawList("EditorTabStripBasic");
|
||||
drawList.AddFilledRect(UIRect(0.0f, 0.0f, width, height), kWindowBg);
|
||||
|
||||
DrawCard(
|
||||
drawList,
|
||||
introRect,
|
||||
"测试功能:Editor TabStrip 基础层",
|
||||
"只验证 TabStrip header / hit-test / selection / close / keyboard,不包含任何业务面板。");
|
||||
drawList.AddText(
|
||||
UIPoint(introRect.x + 16.0f, introRect.y + 68.0f),
|
||||
"重点检查:tab 布局是否整齐;selected / hover / focus 是否正确;Close 后 active panel 是否回退正确。",
|
||||
kTextPrimary,
|
||||
12.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(introRect.x + 16.0f, introRect.y + 92.0f),
|
||||
"操作:点击 tab 切换;点击 X 关闭;Document C 没有 X;点击内容区后按 Left / Right / Home / End;Reset 恢复;F12 截图。",
|
||||
kTextMuted,
|
||||
12.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(introRect.x + 16.0f, introRect.y + 116.0f),
|
||||
"预期:Close 命中优先于 tab;键盘导航只在 focused 时生效;Document C 始终保留。",
|
||||
kTextWeak,
|
||||
12.0f);
|
||||
|
||||
DrawCard(
|
||||
drawList,
|
||||
stateRect,
|
||||
"状态回显",
|
||||
"这里直接回显 hover / focus / active panel / result,方便人工检查。");
|
||||
DrawButton(drawList, m_resetButtonRect, "Reset", m_resetButtonHovered);
|
||||
|
||||
const std::size_t selectedIndex =
|
||||
ResolveUIEditorTabStripSelectedIndex(m_tabItems, m_controller.GetWorkspace().activePanelId);
|
||||
const std::string selectedIndexText =
|
||||
selectedIndex == UIEditorTabStripInvalidIndex ? "(none)" : std::to_string(selectedIndex);
|
||||
const auto validation = m_controller.ValidateState();
|
||||
|
||||
drawList.AddText(
|
||||
UIPoint(stateRect.x + 16.0f, stateRect.y + 70.0f),
|
||||
"Hover: " + DescribeHitTarget(m_hoverTarget, m_tabItems),
|
||||
kTextPrimary,
|
||||
13.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(stateRect.x + 16.0f, stateRect.y + 96.0f),
|
||||
std::string("Focused: ") + (m_tabStripState.focused ? "On" : "Off"),
|
||||
kTextPrimary,
|
||||
13.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(stateRect.x + 16.0f, stateRect.y + 122.0f),
|
||||
"Active Panel: " +
|
||||
(m_controller.GetWorkspace().activePanelId.empty()
|
||||
? std::string("(none)")
|
||||
: m_controller.GetWorkspace().activePanelId),
|
||||
kTextPrimary,
|
||||
13.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(stateRect.x + 16.0f, stateRect.y + 148.0f),
|
||||
"Selected Index: " + selectedIndexText,
|
||||
kTextPrimary,
|
||||
13.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(stateRect.x + 16.0f, stateRect.y + 174.0f),
|
||||
"Tabs: " + JoinTabTitles(m_tabItems),
|
||||
kTextMuted,
|
||||
12.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(stateRect.x + 16.0f, stateRect.y + 250.0f),
|
||||
"Result: " + m_lastResult,
|
||||
kTextMuted,
|
||||
12.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(stateRect.x + 16.0f, stateRect.y + 276.0f),
|
||||
validation.IsValid() ? "Validation: OK" : "Validation: " + validation.message,
|
||||
validation.IsValid() ? kSuccess : kDanger,
|
||||
12.0f);
|
||||
|
||||
const std::string captureSummary =
|
||||
m_autoScreenshot.HasPendingCapture()
|
||||
? "截图排队中..."
|
||||
: (m_autoScreenshot.GetLastCaptureSummary().empty()
|
||||
? std::string("F12 -> tests/UI/Editor/integration/shell/tab_strip_basic/captures/")
|
||||
: m_autoScreenshot.GetLastCaptureSummary());
|
||||
drawList.AddText(
|
||||
UIPoint(stateRect.x + 16.0f, stateRect.y + 302.0f),
|
||||
captureSummary,
|
||||
kTextWeak,
|
||||
12.0f);
|
||||
|
||||
DrawCard(
|
||||
drawList,
|
||||
previewCardRect,
|
||||
"预览区",
|
||||
"这里只放一个 TabStrip 和一个 content placeholder,避免试验面板过杂。");
|
||||
|
||||
AppendUIEditorTabStripBackground(drawList, m_layout, m_tabStripState);
|
||||
AppendUIEditorTabStripForeground(drawList, m_layout, m_tabItems, m_tabStripState);
|
||||
|
||||
drawList.AddText(
|
||||
UIPoint(m_layout.contentRect.x + 20.0f, m_layout.contentRect.y + 22.0f),
|
||||
"Content Placeholder",
|
||||
kTextPrimary,
|
||||
18.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(m_layout.contentRect.x + 20.0f, m_layout.contentRect.y + 52.0f),
|
||||
"当前 active panel: " +
|
||||
(m_controller.GetWorkspace().activePanelId.empty()
|
||||
? std::string("(none)")
|
||||
: m_controller.GetWorkspace().activePanelId),
|
||||
kTextMuted,
|
||||
13.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(m_layout.contentRect.x + 20.0f, m_layout.contentRect.y + 76.0f),
|
||||
"这个区域只用于验证 TabStrip content frame 与 focus,不承载业务内容。",
|
||||
kTextWeak,
|
||||
12.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(m_layout.contentRect.x + 20.0f, m_layout.contentRect.y + 100.0f),
|
||||
"检查点:关闭 Document B 后,应自动回退到相邻 tab;Document C 无法关闭。",
|
||||
kTextWeak,
|
||||
12.0f);
|
||||
|
||||
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 = {};
|
||||
UIPoint m_mousePosition = UIPoint(-1000.0f, -1000.0f);
|
||||
UIEditorWorkspaceController m_controller = {};
|
||||
UIEditorTabStripState m_tabStripState = {};
|
||||
UIEditorTabStripLayout m_layout = {};
|
||||
std::vector<UIEditorTabStripItem> m_tabItems = {};
|
||||
UITabStripModel m_navigationModel = {};
|
||||
UIEditorTabStripHitTarget m_hoverTarget = {};
|
||||
UIRect m_resetButtonRect = {};
|
||||
bool m_resetButtonHovered = false;
|
||||
std::string m_lastResult = {};
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, LPWSTR, int nCmdShow) {
|
||||
return ScenarioApp().Run(hInstance, nCmdShow);
|
||||
}
|
||||
@@ -5,9 +5,12 @@ set(EDITOR_UI_UNIT_TEST_SOURCES
|
||||
test_ui_editor_command_dispatcher.cpp
|
||||
test_ui_editor_command_registry.cpp
|
||||
test_ui_editor_menu_model.cpp
|
||||
test_ui_editor_menu_session.cpp
|
||||
test_ui_editor_panel_registry.cpp
|
||||
test_ui_editor_collection_primitives.cpp
|
||||
test_ui_editor_panel_chrome.cpp
|
||||
test_ui_editor_panel_frame.cpp
|
||||
test_ui_editor_tab_strip.cpp
|
||||
test_ui_editor_shortcut_manager.cpp
|
||||
test_ui_editor_workspace_controller.cpp
|
||||
test_ui_editor_workspace_layout_persistence.cpp
|
||||
|
||||
274
tests/UI/Editor/unit/test_ui_editor_menu_session.cpp
Normal file
274
tests/UI/Editor/unit/test_ui_editor_menu_session.cpp
Normal file
@@ -0,0 +1,274 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <XCEditor/Core/UIEditorMenuSession.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace {
|
||||
|
||||
using XCEngine::UI::UIInputPath;
|
||||
using XCEngine::UI::Widgets::UIPopupDismissReason;
|
||||
using XCEngine::UI::Widgets::UIPopupOverlayEntry;
|
||||
using XCEngine::UI::Widgets::UIPopupPlacement;
|
||||
using XCEngine::UI::Editor::UIEditorMenuSession;
|
||||
|
||||
UIPopupOverlayEntry MakePopup(
|
||||
const char* popupId,
|
||||
const char* parentPopupId,
|
||||
UIInputPath surfacePath,
|
||||
UIInputPath anchorPath = {},
|
||||
UIPopupPlacement placement = UIPopupPlacement::BottomStart) {
|
||||
UIPopupOverlayEntry entry = {};
|
||||
entry.popupId = popupId;
|
||||
entry.parentPopupId = parentPopupId;
|
||||
entry.surfacePath = std::move(surfacePath);
|
||||
entry.anchorPath = std::move(anchorPath);
|
||||
entry.placement = placement;
|
||||
return entry;
|
||||
}
|
||||
|
||||
void ExpectClosedIds(
|
||||
const std::vector<std::string>& actual,
|
||||
std::initializer_list<const char*> expected) {
|
||||
ASSERT_EQ(actual.size(), expected.size());
|
||||
|
||||
std::size_t index = 0u;
|
||||
for (const char* popupId : expected) {
|
||||
EXPECT_EQ(actual[index], popupId);
|
||||
++index;
|
||||
}
|
||||
}
|
||||
|
||||
void ExpectOpenSubmenuIds(
|
||||
const UIEditorMenuSession& session,
|
||||
std::initializer_list<const char*> expected) {
|
||||
const auto& actual = session.GetOpenSubmenuItemIds();
|
||||
ASSERT_EQ(actual.size(), expected.size());
|
||||
|
||||
std::size_t index = 0u;
|
||||
for (const char* itemId : expected) {
|
||||
EXPECT_EQ(actual[index], itemId);
|
||||
++index;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST(UIEditorMenuSessionTest, OpenMenuBarRootTracksActiveMenuAndRootPopup) {
|
||||
UIEditorMenuSession session = {};
|
||||
|
||||
const auto result = session.OpenMenuBarRoot(
|
||||
"file",
|
||||
MakePopup("menu.file.root", "", UIInputPath{100u, 110u}, UIInputPath{1u, 2u}));
|
||||
|
||||
EXPECT_TRUE(result.changed);
|
||||
EXPECT_EQ(result.openRootMenuId, "file");
|
||||
EXPECT_EQ(result.openedPopupId, "menu.file.root");
|
||||
EXPECT_TRUE(result.closedPopupIds.empty());
|
||||
EXPECT_TRUE(session.IsMenuOpen("file"));
|
||||
EXPECT_TRUE(session.IsPopupOpen("menu.file.root"));
|
||||
ASSERT_EQ(session.GetPopupOverlayModel().GetPopupCount(), 1u);
|
||||
ASSERT_EQ(session.GetPopupStates().size(), 1u);
|
||||
EXPECT_TRUE(session.GetPopupStates().front().IsRootPopup());
|
||||
EXPECT_TRUE(session.GetOpenSubmenuItemIds().empty());
|
||||
}
|
||||
|
||||
TEST(UIEditorMenuSessionTest, HoverMenuBarRootReplacesOpenRootAndClearsSubmenuPath) {
|
||||
UIEditorMenuSession session = {};
|
||||
ASSERT_TRUE(session.OpenMenuBarRoot(
|
||||
"file",
|
||||
MakePopup("menu.file.root", "", UIInputPath{100u, 110u}, UIInputPath{1u, 2u}))
|
||||
.changed);
|
||||
ASSERT_TRUE(session.HoverSubmenu(
|
||||
"layout",
|
||||
MakePopup(
|
||||
"menu.file.layout",
|
||||
"menu.file.root",
|
||||
UIInputPath{200u, 210u},
|
||||
UIInputPath{100u, 110u, 120u},
|
||||
UIPopupPlacement::RightStart))
|
||||
.changed);
|
||||
|
||||
const auto result = session.HoverMenuBarRoot(
|
||||
"window",
|
||||
MakePopup("menu.window.root", "", UIInputPath{300u, 310u}, UIInputPath{3u, 4u}));
|
||||
|
||||
EXPECT_TRUE(result.changed);
|
||||
EXPECT_EQ(result.openRootMenuId, "window");
|
||||
EXPECT_EQ(result.dismissReason, UIPopupDismissReason::Programmatic);
|
||||
ExpectClosedIds(result.closedPopupIds, {"menu.file.root", "menu.file.layout"});
|
||||
EXPECT_TRUE(session.IsMenuOpen("window"));
|
||||
EXPECT_FALSE(session.IsMenuOpen("file"));
|
||||
EXPECT_TRUE(session.GetOpenSubmenuItemIds().empty());
|
||||
ASSERT_EQ(session.GetPopupOverlayModel().GetPopupCount(), 1u);
|
||||
EXPECT_EQ(session.GetPopupOverlayModel().GetRootPopup()->popupId, "menu.window.root");
|
||||
}
|
||||
|
||||
TEST(UIEditorMenuSessionTest, HoverSubmenuSwitchesSiblingBranchAndTruncatesDescendants) {
|
||||
UIEditorMenuSession session = {};
|
||||
ASSERT_TRUE(session.OpenMenuBarRoot(
|
||||
"file",
|
||||
MakePopup("menu.file.root", "", UIInputPath{100u, 110u}, UIInputPath{1u, 2u}))
|
||||
.changed);
|
||||
ASSERT_TRUE(session.HoverSubmenu(
|
||||
"layout",
|
||||
MakePopup(
|
||||
"menu.file.layout",
|
||||
"menu.file.root",
|
||||
UIInputPath{200u, 210u},
|
||||
UIInputPath{100u, 110u, 120u},
|
||||
UIPopupPlacement::RightStart))
|
||||
.changed);
|
||||
ASSERT_TRUE(session.HoverSubmenu(
|
||||
"advanced",
|
||||
MakePopup(
|
||||
"menu.file.advanced",
|
||||
"menu.file.layout",
|
||||
UIInputPath{300u, 310u},
|
||||
UIInputPath{200u, 210u, 220u},
|
||||
UIPopupPlacement::RightStart))
|
||||
.changed);
|
||||
|
||||
const auto result = session.HoverSubmenu(
|
||||
"export",
|
||||
MakePopup(
|
||||
"menu.file.export",
|
||||
"menu.file.root",
|
||||
UIInputPath{400u, 410u},
|
||||
UIInputPath{100u, 110u, 130u},
|
||||
UIPopupPlacement::RightStart));
|
||||
|
||||
EXPECT_TRUE(result.changed);
|
||||
ExpectClosedIds(result.closedPopupIds, {"menu.file.layout", "menu.file.advanced"});
|
||||
EXPECT_EQ(result.openedPopupId, "menu.file.export");
|
||||
ASSERT_EQ(session.GetPopupOverlayModel().GetPopupCount(), 2u);
|
||||
ExpectOpenSubmenuIds(session, {"export"});
|
||||
ASSERT_NE(session.FindPopupState("menu.file.export"), nullptr);
|
||||
EXPECT_EQ(session.FindPopupState("menu.file.export")->itemId, "export");
|
||||
}
|
||||
|
||||
TEST(UIEditorMenuSessionTest, HoveringAlreadyOpenSubmenuKeepsExistingDescendants) {
|
||||
UIEditorMenuSession session = {};
|
||||
ASSERT_TRUE(session.OpenMenuBarRoot(
|
||||
"file",
|
||||
MakePopup("menu.file.root", "", UIInputPath{100u, 110u}, UIInputPath{1u, 2u}))
|
||||
.changed);
|
||||
ASSERT_TRUE(session.HoverSubmenu(
|
||||
"layout",
|
||||
MakePopup(
|
||||
"menu.file.layout",
|
||||
"menu.file.root",
|
||||
UIInputPath{200u, 210u},
|
||||
UIInputPath{100u, 110u, 120u},
|
||||
UIPopupPlacement::RightStart))
|
||||
.changed);
|
||||
ASSERT_TRUE(session.HoverSubmenu(
|
||||
"advanced",
|
||||
MakePopup(
|
||||
"menu.file.advanced",
|
||||
"menu.file.layout",
|
||||
UIInputPath{300u, 310u},
|
||||
UIInputPath{200u, 210u, 220u},
|
||||
UIPopupPlacement::RightStart))
|
||||
.changed);
|
||||
|
||||
const auto result = session.HoverSubmenu(
|
||||
"layout",
|
||||
MakePopup(
|
||||
"menu.file.layout",
|
||||
"menu.file.root",
|
||||
UIInputPath{200u, 210u},
|
||||
UIInputPath{100u, 110u, 120u},
|
||||
UIPopupPlacement::RightStart));
|
||||
|
||||
EXPECT_FALSE(result.changed);
|
||||
EXPECT_EQ(result.openRootMenuId, "file");
|
||||
ASSERT_EQ(session.GetPopupOverlayModel().GetPopupCount(), 3u);
|
||||
ExpectOpenSubmenuIds(session, {"layout", "advanced"});
|
||||
}
|
||||
|
||||
TEST(UIEditorMenuSessionTest, PointerDismissInsideRootClosesOnlyDescendantSubmenus) {
|
||||
UIEditorMenuSession session = {};
|
||||
ASSERT_TRUE(session.OpenMenuBarRoot(
|
||||
"file",
|
||||
MakePopup("menu.file.root", "", UIInputPath{100u, 110u}, UIInputPath{1u, 2u}))
|
||||
.changed);
|
||||
ASSERT_TRUE(session.HoverSubmenu(
|
||||
"layout",
|
||||
MakePopup(
|
||||
"menu.file.layout",
|
||||
"menu.file.root",
|
||||
UIInputPath{200u, 210u},
|
||||
UIInputPath{100u, 110u, 120u},
|
||||
UIPopupPlacement::RightStart))
|
||||
.changed);
|
||||
|
||||
const auto result = session.DismissFromPointerDown(UIInputPath{100u, 110u, 130u});
|
||||
|
||||
EXPECT_TRUE(result.changed);
|
||||
EXPECT_EQ(result.dismissReason, UIPopupDismissReason::PointerOutside);
|
||||
ExpectClosedIds(result.closedPopupIds, {"menu.file.layout"});
|
||||
EXPECT_EQ(result.openRootMenuId, "file");
|
||||
EXPECT_TRUE(session.IsMenuOpen("file"));
|
||||
EXPECT_TRUE(session.GetOpenSubmenuItemIds().empty());
|
||||
ASSERT_EQ(session.GetPopupOverlayModel().GetPopupCount(), 1u);
|
||||
}
|
||||
|
||||
TEST(UIEditorMenuSessionTest, PointerDismissOutsideAllClosesEntireMenuChain) {
|
||||
UIEditorMenuSession session = {};
|
||||
ASSERT_TRUE(session.OpenMenuBarRoot(
|
||||
"file",
|
||||
MakePopup("menu.file.root", "", UIInputPath{100u, 110u}, UIInputPath{1u, 2u}))
|
||||
.changed);
|
||||
ASSERT_TRUE(session.HoverSubmenu(
|
||||
"layout",
|
||||
MakePopup(
|
||||
"menu.file.layout",
|
||||
"menu.file.root",
|
||||
UIInputPath{200u, 210u},
|
||||
UIInputPath{100u, 110u, 120u},
|
||||
UIPopupPlacement::RightStart))
|
||||
.changed);
|
||||
|
||||
const auto result = session.DismissFromPointerDown(UIInputPath{999u, 1000u});
|
||||
|
||||
EXPECT_TRUE(result.changed);
|
||||
EXPECT_EQ(result.dismissReason, UIPopupDismissReason::PointerOutside);
|
||||
ExpectClosedIds(result.closedPopupIds, {"menu.file.root", "menu.file.layout"});
|
||||
EXPECT_FALSE(result.HasOpenMenu());
|
||||
EXPECT_FALSE(session.HasOpenMenu());
|
||||
EXPECT_EQ(session.GetPopupOverlayModel().GetPopupCount(), 0u);
|
||||
}
|
||||
|
||||
TEST(UIEditorMenuSessionTest, EscapeDismissClosesTopmostPopupBeforeRoot) {
|
||||
UIEditorMenuSession session = {};
|
||||
ASSERT_TRUE(session.OpenMenuBarRoot(
|
||||
"file",
|
||||
MakePopup("menu.file.root", "", UIInputPath{100u, 110u}, UIInputPath{1u, 2u}))
|
||||
.changed);
|
||||
ASSERT_TRUE(session.HoverSubmenu(
|
||||
"layout",
|
||||
MakePopup(
|
||||
"menu.file.layout",
|
||||
"menu.file.root",
|
||||
UIInputPath{200u, 210u},
|
||||
UIInputPath{100u, 110u, 120u},
|
||||
UIPopupPlacement::RightStart))
|
||||
.changed);
|
||||
|
||||
auto result = session.DismissFromEscape();
|
||||
|
||||
EXPECT_TRUE(result.changed);
|
||||
EXPECT_EQ(result.dismissReason, UIPopupDismissReason::EscapeKey);
|
||||
ExpectClosedIds(result.closedPopupIds, {"menu.file.layout"});
|
||||
EXPECT_EQ(result.openRootMenuId, "file");
|
||||
ASSERT_EQ(session.GetPopupOverlayModel().GetPopupCount(), 1u);
|
||||
|
||||
result = session.DismissFromEscape();
|
||||
|
||||
EXPECT_TRUE(result.changed);
|
||||
EXPECT_EQ(result.dismissReason, UIPopupDismissReason::EscapeKey);
|
||||
ExpectClosedIds(result.closedPopupIds, {"menu.file.root"});
|
||||
EXPECT_FALSE(session.HasOpenMenu());
|
||||
EXPECT_EQ(session.GetPopupOverlayModel().GetPopupCount(), 0u);
|
||||
}
|
||||
165
tests/UI/Editor/unit/test_ui_editor_panel_frame.cpp
Normal file
165
tests/UI/Editor/unit/test_ui_editor_panel_frame.cpp
Normal file
@@ -0,0 +1,165 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <XCEngine/UI/DrawData.h>
|
||||
#include <XCEditor/Widgets/UIEditorPanelFrame.h>
|
||||
|
||||
namespace {
|
||||
|
||||
using XCEngine::UI::UIColor;
|
||||
using XCEngine::UI::UIDrawCommandType;
|
||||
using XCEngine::UI::UIDrawList;
|
||||
using XCEngine::UI::UIPoint;
|
||||
using XCEngine::UI::UIRect;
|
||||
using XCEngine::UI::Editor::Widgets::AppendUIEditorPanelFrameBackground;
|
||||
using XCEngine::UI::Editor::Widgets::AppendUIEditorPanelFrameForeground;
|
||||
using XCEngine::UI::Editor::Widgets::BuildUIEditorPanelFrameLayout;
|
||||
using XCEngine::UI::Editor::Widgets::HitTestUIEditorPanelFrame;
|
||||
using XCEngine::UI::Editor::Widgets::HitTestUIEditorPanelFrameAction;
|
||||
using XCEngine::UI::Editor::Widgets::ResolveUIEditorPanelFrameBorderColor;
|
||||
using XCEngine::UI::Editor::Widgets::ResolveUIEditorPanelFrameBorderThickness;
|
||||
using XCEngine::UI::Editor::Widgets::UIEditorPanelFrameAction;
|
||||
using XCEngine::UI::Editor::Widgets::UIEditorPanelFrameHitTarget;
|
||||
using XCEngine::UI::Editor::Widgets::UIEditorPanelFrameLayout;
|
||||
using XCEngine::UI::Editor::Widgets::UIEditorPanelFramePalette;
|
||||
using XCEngine::UI::Editor::Widgets::UIEditorPanelFrameState;
|
||||
using XCEngine::UI::Editor::Widgets::UIEditorPanelFrameText;
|
||||
|
||||
void ExpectColorEq(
|
||||
const UIColor& actual,
|
||||
const UIColor& expected) {
|
||||
EXPECT_FLOAT_EQ(actual.r, expected.r);
|
||||
EXPECT_FLOAT_EQ(actual.g, expected.g);
|
||||
EXPECT_FLOAT_EQ(actual.b, expected.b);
|
||||
EXPECT_FLOAT_EQ(actual.a, expected.a);
|
||||
}
|
||||
|
||||
TEST(UIEditorPanelFrameTest, LayoutBuildsHeaderBodyFooterAndActionRectsFromState) {
|
||||
UIEditorPanelFrameState state = {};
|
||||
state.active = true;
|
||||
state.pinned = true;
|
||||
state.closable = true;
|
||||
state.pinnable = true;
|
||||
state.showFooter = true;
|
||||
|
||||
const UIEditorPanelFrameLayout layout =
|
||||
BuildUIEditorPanelFrameLayout(UIRect(10.0f, 20.0f, 300.0f, 200.0f), state);
|
||||
|
||||
EXPECT_FLOAT_EQ(layout.headerRect.x, 10.0f);
|
||||
EXPECT_FLOAT_EQ(layout.headerRect.y, 20.0f);
|
||||
EXPECT_FLOAT_EQ(layout.headerRect.width, 300.0f);
|
||||
EXPECT_FLOAT_EQ(layout.headerRect.height, 36.0f);
|
||||
|
||||
EXPECT_TRUE(layout.hasFooter);
|
||||
EXPECT_FLOAT_EQ(layout.footerRect.y, 196.0f);
|
||||
EXPECT_FLOAT_EQ(layout.footerRect.height, 24.0f);
|
||||
|
||||
EXPECT_FLOAT_EQ(layout.bodyRect.x, 22.0f);
|
||||
EXPECT_FLOAT_EQ(layout.bodyRect.y, 68.0f);
|
||||
EXPECT_FLOAT_EQ(layout.bodyRect.width, 276.0f);
|
||||
EXPECT_FLOAT_EQ(layout.bodyRect.height, 116.0f);
|
||||
|
||||
EXPECT_TRUE(layout.showPinButton);
|
||||
EXPECT_TRUE(layout.showCloseButton);
|
||||
EXPECT_FLOAT_EQ(layout.closeButtonRect.x, 286.0f);
|
||||
EXPECT_FLOAT_EQ(layout.closeButtonRect.y, 32.0f);
|
||||
EXPECT_FLOAT_EQ(layout.closeButtonRect.width, 12.0f);
|
||||
EXPECT_FLOAT_EQ(layout.pinButtonRect.x, 268.0f);
|
||||
EXPECT_FLOAT_EQ(layout.pinButtonRect.y, 32.0f);
|
||||
}
|
||||
|
||||
TEST(UIEditorPanelFrameTest, BorderPolicyUsesFocusBeforeActiveBeforeHover) {
|
||||
const UIEditorPanelFramePalette palette = {};
|
||||
|
||||
UIEditorPanelFrameState hoveredOnly = {};
|
||||
hoveredOnly.hovered = true;
|
||||
UIEditorPanelFrameState activeOnly = hoveredOnly;
|
||||
activeOnly.active = true;
|
||||
UIEditorPanelFrameState focusedState = activeOnly;
|
||||
focusedState.focused = true;
|
||||
|
||||
ExpectColorEq(
|
||||
ResolveUIEditorPanelFrameBorderColor(hoveredOnly, palette),
|
||||
palette.hoveredBorderColor);
|
||||
ExpectColorEq(
|
||||
ResolveUIEditorPanelFrameBorderColor(activeOnly, palette),
|
||||
palette.activeBorderColor);
|
||||
ExpectColorEq(
|
||||
ResolveUIEditorPanelFrameBorderColor(focusedState, palette),
|
||||
palette.focusedBorderColor);
|
||||
|
||||
EXPECT_FLOAT_EQ(ResolveUIEditorPanelFrameBorderThickness(UIEditorPanelFrameState{}), 1.0f);
|
||||
EXPECT_FLOAT_EQ(ResolveUIEditorPanelFrameBorderThickness(hoveredOnly), 1.25f);
|
||||
EXPECT_FLOAT_EQ(ResolveUIEditorPanelFrameBorderThickness(activeOnly), 1.5f);
|
||||
EXPECT_FLOAT_EQ(ResolveUIEditorPanelFrameBorderThickness(focusedState), 2.0f);
|
||||
}
|
||||
|
||||
TEST(UIEditorPanelFrameTest, HitTestReturnsActionAndRegionTargetsFromLayout) {
|
||||
UIEditorPanelFrameState state = {};
|
||||
state.closable = true;
|
||||
state.pinnable = true;
|
||||
state.showFooter = true;
|
||||
|
||||
const UIEditorPanelFrameLayout layout =
|
||||
BuildUIEditorPanelFrameLayout(UIRect(10.0f, 20.0f, 300.0f, 200.0f), state);
|
||||
|
||||
EXPECT_EQ(
|
||||
HitTestUIEditorPanelFrameAction(layout, state, UIPoint(269.0f, 35.0f)),
|
||||
UIEditorPanelFrameAction::Pin);
|
||||
EXPECT_EQ(
|
||||
HitTestUIEditorPanelFrameAction(layout, state, UIPoint(287.0f, 35.0f)),
|
||||
UIEditorPanelFrameAction::Close);
|
||||
EXPECT_EQ(
|
||||
HitTestUIEditorPanelFrame(layout, state, UIPoint(40.0f, 35.0f)),
|
||||
UIEditorPanelFrameHitTarget::Header);
|
||||
EXPECT_EQ(
|
||||
HitTestUIEditorPanelFrame(layout, state, UIPoint(40.0f, 90.0f)),
|
||||
UIEditorPanelFrameHitTarget::Body);
|
||||
EXPECT_EQ(
|
||||
HitTestUIEditorPanelFrame(layout, state, UIPoint(40.0f, 205.0f)),
|
||||
UIEditorPanelFrameHitTarget::Footer);
|
||||
}
|
||||
|
||||
TEST(UIEditorPanelFrameTest, BackgroundAndForegroundEmitExpectedChromeAndActionCommands) {
|
||||
UIEditorPanelFrameState state = {};
|
||||
state.active = true;
|
||||
state.focused = true;
|
||||
state.pinned = true;
|
||||
state.closable = true;
|
||||
state.pinnable = true;
|
||||
state.showFooter = true;
|
||||
state.pinHovered = true;
|
||||
|
||||
const UIEditorPanelFramePalette palette = {};
|
||||
const UIEditorPanelFrameText text{
|
||||
"Inspector",
|
||||
"PanelFrame chrome contract",
|
||||
"focused | pinned | footer visible"
|
||||
};
|
||||
const UIEditorPanelFrameLayout layout =
|
||||
BuildUIEditorPanelFrameLayout(UIRect(20.0f, 30.0f, 320.0f, 220.0f), state);
|
||||
|
||||
UIDrawList background("PanelFrameBackground");
|
||||
AppendUIEditorPanelFrameBackground(background, layout, state, palette);
|
||||
|
||||
ASSERT_EQ(background.GetCommandCount(), 4u);
|
||||
const auto& backgroundCommands = background.GetCommands();
|
||||
EXPECT_EQ(backgroundCommands[0].type, UIDrawCommandType::FilledRect);
|
||||
EXPECT_EQ(backgroundCommands[1].type, UIDrawCommandType::RectOutline);
|
||||
EXPECT_EQ(backgroundCommands[2].type, UIDrawCommandType::FilledRect);
|
||||
EXPECT_EQ(backgroundCommands[3].type, UIDrawCommandType::FilledRect);
|
||||
ExpectColorEq(backgroundCommands[1].color, palette.focusedBorderColor);
|
||||
|
||||
UIDrawList foreground("PanelFrameForeground");
|
||||
AppendUIEditorPanelFrameForeground(foreground, layout, state, text, palette);
|
||||
|
||||
ASSERT_EQ(foreground.GetCommandCount(), 9u);
|
||||
const auto& foregroundCommands = foreground.GetCommands();
|
||||
EXPECT_EQ(foregroundCommands[0].type, UIDrawCommandType::Text);
|
||||
EXPECT_EQ(foregroundCommands[0].text, "Inspector");
|
||||
EXPECT_EQ(foregroundCommands[1].text, "PanelFrame chrome contract");
|
||||
EXPECT_EQ(foregroundCommands[2].text, "focused | pinned | footer visible");
|
||||
EXPECT_EQ(foregroundCommands[5].text, "P");
|
||||
EXPECT_EQ(foregroundCommands[8].text, "X");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
178
tests/UI/Editor/unit/test_ui_editor_tab_strip.cpp
Normal file
178
tests/UI/Editor/unit/test_ui_editor_tab_strip.cpp
Normal file
@@ -0,0 +1,178 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <XCEngine/UI/DrawData.h>
|
||||
#include <XCEditor/Widgets/UIEditorTabStrip.h>
|
||||
|
||||
namespace {
|
||||
|
||||
using XCEngine::UI::UIDrawCommandType;
|
||||
using XCEngine::UI::UIDrawList;
|
||||
using XCEngine::UI::UIPoint;
|
||||
using XCEngine::UI::UIRect;
|
||||
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::ResolveUIEditorTabStripDesiredHeaderLabelWidth;
|
||||
using XCEngine::UI::Editor::Widgets::ResolveUIEditorTabStripSelectedIndex;
|
||||
using XCEngine::UI::Editor::Widgets::ResolveUIEditorTabStripSelectedIndexAfterClose;
|
||||
using XCEngine::UI::Editor::Widgets::UIEditorTabStripHitTargetKind;
|
||||
using XCEngine::UI::Editor::Widgets::UIEditorTabStripInvalidIndex;
|
||||
using XCEngine::UI::Editor::Widgets::UIEditorTabStripItem;
|
||||
using XCEngine::UI::Editor::Widgets::UIEditorTabStripLayout;
|
||||
using XCEngine::UI::Editor::Widgets::UIEditorTabStripMetrics;
|
||||
using XCEngine::UI::Editor::Widgets::UIEditorTabStripState;
|
||||
|
||||
TEST(UIEditorTabStripTest, DesiredHeaderWidthReservesCloseButtonBudget) {
|
||||
UIEditorTabStripMetrics metrics = {};
|
||||
metrics.layoutMetrics.tabHorizontalPadding = 10.0f;
|
||||
metrics.estimatedGlyphWidth = 8.0f;
|
||||
metrics.closeButtonExtent = 14.0f;
|
||||
metrics.closeButtonGap = 6.0f;
|
||||
metrics.closeInsetRight = 14.0f;
|
||||
metrics.labelInsetX = 12.0f;
|
||||
|
||||
const float closableWidth = ResolveUIEditorTabStripDesiredHeaderLabelWidth(
|
||||
UIEditorTabStripItem{ "doc-a", "ABCD", true, 0.0f },
|
||||
metrics);
|
||||
const float fixedWidth = ResolveUIEditorTabStripDesiredHeaderLabelWidth(
|
||||
UIEditorTabStripItem{ "doc-b", "Ignored", false, 42.0f },
|
||||
metrics);
|
||||
|
||||
EXPECT_FLOAT_EQ(closableWidth, 58.0f);
|
||||
EXPECT_FLOAT_EQ(fixedWidth, 44.0f);
|
||||
}
|
||||
|
||||
TEST(UIEditorTabStripTest, SelectedIndexResolvesByTabIdAndFallsBackToValidRange) {
|
||||
const std::vector<UIEditorTabStripItem> items = {
|
||||
{ "doc-a", "Document A", true, 0.0f },
|
||||
{ "doc-b", "Document B", true, 0.0f },
|
||||
{ "doc-c", "Document C", false, 0.0f }
|
||||
};
|
||||
|
||||
EXPECT_EQ(ResolveUIEditorTabStripSelectedIndex(items, "doc-b"), 1u);
|
||||
EXPECT_EQ(ResolveUIEditorTabStripSelectedIndex(items, "missing", 2u), 2u);
|
||||
EXPECT_EQ(ResolveUIEditorTabStripSelectedIndex(items, "missing"), 0u);
|
||||
EXPECT_EQ(
|
||||
ResolveUIEditorTabStripSelectedIndex({}, "missing"),
|
||||
UIEditorTabStripInvalidIndex);
|
||||
}
|
||||
|
||||
TEST(UIEditorTabStripTest, ClosingTabsResolvesSelectionFallbackFromClosedIndex) {
|
||||
EXPECT_EQ(ResolveUIEditorTabStripSelectedIndexAfterClose(1u, 1u, 3u), 1u);
|
||||
EXPECT_EQ(ResolveUIEditorTabStripSelectedIndexAfterClose(2u, 2u, 3u), 1u);
|
||||
EXPECT_EQ(ResolveUIEditorTabStripSelectedIndexAfterClose(2u, 0u, 3u), 1u);
|
||||
EXPECT_EQ(
|
||||
ResolveUIEditorTabStripSelectedIndexAfterClose(0u, 0u, 1u),
|
||||
UIEditorTabStripInvalidIndex);
|
||||
}
|
||||
|
||||
TEST(UIEditorTabStripTest, LayoutUsesCoreTabArrangementAndBuildsCloseRects) {
|
||||
UIEditorTabStripMetrics metrics = {};
|
||||
metrics.layoutMetrics.headerHeight = 30.0f;
|
||||
metrics.layoutMetrics.tabMinWidth = 80.0f;
|
||||
metrics.layoutMetrics.tabHorizontalPadding = 12.0f;
|
||||
metrics.layoutMetrics.tabGap = 4.0f;
|
||||
metrics.closeButtonExtent = 12.0f;
|
||||
metrics.closeButtonGap = 6.0f;
|
||||
metrics.closeInsetRight = 12.0f;
|
||||
metrics.labelInsetX = 12.0f;
|
||||
|
||||
const std::vector<UIEditorTabStripItem> items = {
|
||||
{ "doc-a", "Document A", true, 48.0f },
|
||||
{ "doc-b", "Document B", false, 40.0f }
|
||||
};
|
||||
|
||||
UIEditorTabStripState state = {};
|
||||
state.selectedIndex = 0u;
|
||||
|
||||
const UIEditorTabStripLayout layout =
|
||||
BuildUIEditorTabStripLayout(UIRect(10.0f, 20.0f, 260.0f, 180.0f), items, state, metrics);
|
||||
|
||||
EXPECT_FLOAT_EQ(layout.headerRect.x, 10.0f);
|
||||
EXPECT_FLOAT_EQ(layout.headerRect.y, 20.0f);
|
||||
EXPECT_FLOAT_EQ(layout.headerRect.width, 260.0f);
|
||||
EXPECT_FLOAT_EQ(layout.headerRect.height, 30.0f);
|
||||
|
||||
EXPECT_FLOAT_EQ(layout.contentRect.x, 10.0f);
|
||||
EXPECT_FLOAT_EQ(layout.contentRect.y, 50.0f);
|
||||
EXPECT_FLOAT_EQ(layout.contentRect.width, 260.0f);
|
||||
EXPECT_FLOAT_EQ(layout.contentRect.height, 150.0f);
|
||||
|
||||
ASSERT_EQ(layout.tabHeaderRects.size(), 2u);
|
||||
EXPECT_FLOAT_EQ(layout.tabHeaderRects[0].x, 10.0f);
|
||||
EXPECT_FLOAT_EQ(layout.tabHeaderRects[0].width, 90.0f);
|
||||
EXPECT_FLOAT_EQ(layout.tabHeaderRects[1].x, 104.0f);
|
||||
EXPECT_FLOAT_EQ(layout.tabHeaderRects[1].width, 80.0f);
|
||||
|
||||
ASSERT_EQ(layout.closeButtonRects.size(), 2u);
|
||||
EXPECT_TRUE(layout.showCloseButtons[0]);
|
||||
EXPECT_FALSE(layout.showCloseButtons[1]);
|
||||
EXPECT_FLOAT_EQ(layout.closeButtonRects[0].x, 76.0f);
|
||||
EXPECT_FLOAT_EQ(layout.closeButtonRects[0].y, 29.0f);
|
||||
EXPECT_FLOAT_EQ(layout.closeButtonRects[0].width, 12.0f);
|
||||
EXPECT_FLOAT_EQ(layout.closeButtonRects[0].height, 12.0f);
|
||||
}
|
||||
|
||||
TEST(UIEditorTabStripTest, HitTestPrioritizesCloseButtonThenTabThenContent) {
|
||||
const std::vector<UIEditorTabStripItem> items = {
|
||||
{ "doc-a", "Document A", true, 48.0f },
|
||||
{ "doc-b", "Document B", false, 40.0f }
|
||||
};
|
||||
|
||||
UIEditorTabStripState state = {};
|
||||
state.selectedIndex = 0u;
|
||||
const UIEditorTabStripLayout layout =
|
||||
BuildUIEditorTabStripLayout(UIRect(10.0f, 20.0f, 260.0f, 180.0f), items, state);
|
||||
|
||||
const auto closeHit = HitTestUIEditorTabStrip(layout, state, UIPoint(85.0f, 34.0f));
|
||||
EXPECT_EQ(closeHit.kind, UIEditorTabStripHitTargetKind::CloseButton);
|
||||
EXPECT_EQ(closeHit.index, 0u);
|
||||
|
||||
const auto tabHit = HitTestUIEditorTabStrip(layout, state, UIPoint(40.0f, 34.0f));
|
||||
EXPECT_EQ(tabHit.kind, UIEditorTabStripHitTargetKind::Tab);
|
||||
EXPECT_EQ(tabHit.index, 0u);
|
||||
|
||||
const auto contentHit = HitTestUIEditorTabStrip(layout, state, UIPoint(40.0f, 70.0f));
|
||||
EXPECT_EQ(contentHit.kind, UIEditorTabStripHitTargetKind::Content);
|
||||
EXPECT_EQ(contentHit.index, UIEditorTabStripInvalidIndex);
|
||||
}
|
||||
|
||||
TEST(UIEditorTabStripTest, BackgroundAndForegroundEmitStableChromeCommands) {
|
||||
const std::vector<UIEditorTabStripItem> items = {
|
||||
{ "doc-a", "Document A", true, 48.0f },
|
||||
{ "doc-b", "Document B", false, 40.0f }
|
||||
};
|
||||
|
||||
UIEditorTabStripState state = {};
|
||||
state.selectedIndex = 0u;
|
||||
state.hoveredIndex = 1u;
|
||||
state.closeHoveredIndex = 0u;
|
||||
state.focused = true;
|
||||
|
||||
const UIEditorTabStripLayout layout =
|
||||
BuildUIEditorTabStripLayout(UIRect(10.0f, 20.0f, 260.0f, 180.0f), items, state);
|
||||
|
||||
UIDrawList background("TabStripBackground");
|
||||
AppendUIEditorTabStripBackground(background, layout, state);
|
||||
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[7].type, UIDrawCommandType::RectOutline);
|
||||
|
||||
UIDrawList foreground("TabStripForeground");
|
||||
AppendUIEditorTabStripForeground(foreground, layout, items, state);
|
||||
ASSERT_EQ(foreground.GetCommandCount(), 9u);
|
||||
const auto& foregroundCommands = foreground.GetCommands();
|
||||
EXPECT_EQ(foregroundCommands[0].type, UIDrawCommandType::PushClipRect);
|
||||
EXPECT_EQ(foregroundCommands[1].type, UIDrawCommandType::Text);
|
||||
EXPECT_EQ(foregroundCommands[1].text, "Document A");
|
||||
EXPECT_EQ(foregroundCommands[5].type, UIDrawCommandType::Text);
|
||||
EXPECT_EQ(foregroundCommands[5].text, "X");
|
||||
EXPECT_EQ(foregroundCommands[7].type, UIDrawCommandType::Text);
|
||||
EXPECT_EQ(foregroundCommands[7].text, "Document B");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
Reference in New Issue
Block a user