Build XCEditor dock host workspace shell compose
This commit is contained in:
@@ -1,21 +1,17 @@
|
||||
set(EDITOR_UI_WORKSPACE_SHELL_COMPOSE_RESOURCES
|
||||
View.xcui
|
||||
${CMAKE_SOURCE_DIR}/tests/UI/Editor/integration/shared/themes/editor_validation.xctheme
|
||||
)
|
||||
|
||||
add_executable(editor_ui_workspace_shell_compose_validation WIN32
|
||||
main.cpp
|
||||
${EDITOR_UI_WORKSPACE_SHELL_COMPOSE_RESOURCES}
|
||||
)
|
||||
|
||||
target_include_directories(editor_ui_workspace_shell_compose_validation PRIVATE
|
||||
${CMAKE_SOURCE_DIR}/tests/UI/Editor/integration/shared/src
|
||||
${CMAKE_SOURCE_DIR}/new_editor/include
|
||||
${CMAKE_SOURCE_DIR}/new_editor/app
|
||||
${CMAKE_SOURCE_DIR}/engine/include
|
||||
)
|
||||
|
||||
target_compile_definitions(editor_ui_workspace_shell_compose_validation PRIVATE
|
||||
UNICODE
|
||||
_UNICODE
|
||||
XCENGINE_EDITOR_UI_TESTS_REPO_ROOT="${XCENGINE_EDITOR_UI_TESTS_REPO_ROOT_PATH}"
|
||||
)
|
||||
|
||||
if(MSVC)
|
||||
@@ -25,11 +21,10 @@ if(MSVC)
|
||||
endif()
|
||||
|
||||
target_link_libraries(editor_ui_workspace_shell_compose_validation PRIVATE
|
||||
editor_ui_integration_host
|
||||
XCUIEditorLib
|
||||
XCUIEditorHost
|
||||
)
|
||||
|
||||
set_target_properties(editor_ui_workspace_shell_compose_validation PROPERTIES
|
||||
OUTPUT_NAME "XCUIEditorWorkspaceShellComposeValidation"
|
||||
)
|
||||
|
||||
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}" FILES View.xcui)
|
||||
|
||||
@@ -1,8 +1,806 @@
|
||||
#include "Application.h"
|
||||
#ifndef NOMINMAX
|
||||
#define NOMINMAX
|
||||
#endif
|
||||
|
||||
#include <XCEditor/Core/UIEditorPanelRegistry.h>
|
||||
#include <XCEditor/Core/UIEditorWorkspaceController.h>
|
||||
#include <XCEditor/Core/UIEditorWorkspaceModel.h>
|
||||
#include <XCEditor/Widgets/UIEditorDockHost.h>
|
||||
#include "Host/AutoScreenshot.h"
|
||||
#include "Host/NativeRenderer.h"
|
||||
|
||||
#include <XCEngine/UI/DrawData.h>
|
||||
#include <XCEngine/UI/Widgets/UISplitterInteraction.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::BeginUISplitterDrag;
|
||||
using XCEngine::UI::Widgets::EndUISplitterDrag;
|
||||
using XCEngine::UI::Widgets::UISplitterDragState;
|
||||
using XCEngine::UI::Widgets::UpdateUISplitterDrag;
|
||||
using XCEngine::UI::Editor::BuildDefaultUIEditorWorkspaceController;
|
||||
using XCEngine::UI::Editor::BuildUIEditorWorkspacePanel;
|
||||
using XCEngine::UI::Editor::BuildUIEditorWorkspaceSplit;
|
||||
using XCEngine::UI::Editor::BuildUIEditorWorkspaceTabStack;
|
||||
using XCEngine::UI::Editor::FindUIEditorWorkspaceNode;
|
||||
using XCEngine::UI::Editor::GetUIEditorWorkspaceCommandStatusName;
|
||||
using XCEngine::UI::Editor::GetUIEditorWorkspaceLayoutOperationStatusName;
|
||||
using XCEngine::UI::Editor::Host::AutoScreenshotController;
|
||||
using XCEngine::UI::Editor::Host::NativeRenderer;
|
||||
using XCEngine::UI::Editor::TrySetUIEditorWorkspaceSplitRatio;
|
||||
using XCEngine::UI::Editor::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::UIEditorWorkspaceSplitAxis;
|
||||
using XCEngine::UI::Editor::Widgets::AppendUIEditorDockHostBackground;
|
||||
using XCEngine::UI::Editor::Widgets::AppendUIEditorDockHostForeground;
|
||||
using XCEngine::UI::Editor::Widgets::BuildUIEditorDockHostLayout;
|
||||
using XCEngine::UI::Editor::Widgets::FindUIEditorDockHostSplitterLayout;
|
||||
using XCEngine::UI::Editor::Widgets::HitTestUIEditorDockHost;
|
||||
using XCEngine::UI::Editor::Widgets::UIEditorDockHostHitTarget;
|
||||
using XCEngine::UI::Editor::Widgets::UIEditorDockHostHitTargetKind;
|
||||
using XCEngine::UI::Editor::Widgets::UIEditorDockHostLayout;
|
||||
using XCEngine::UI::Editor::Widgets::UIEditorDockHostState;
|
||||
using XCEngine::UI::Editor::Widgets::UIEditorTabStripInvalidIndex;
|
||||
|
||||
constexpr const wchar_t* kWindowClassName = L"XCUIEditorWorkspaceShellComposeValidation";
|
||||
constexpr const wchar_t* kWindowTitle = L"XCUI Editor | Workspace Shell Compose";
|
||||
|
||||
constexpr UIColor kWindowBg(0.14f, 0.14f, 0.14f, 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.63f, 0.76f, 0.63f, 1.0f);
|
||||
constexpr UIColor kDanger(0.82f, 0.50f, 0.50f, 1.0f);
|
||||
constexpr UIColor kButtonBg(0.26f, 0.26f, 0.26f, 1.0f);
|
||||
constexpr UIColor kButtonHoveredBg(0.34f, 0.34f, 0.34f, 1.0f);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
bool AreTargetsEqual(
|
||||
const UIEditorDockHostHitTarget& lhs,
|
||||
const UIEditorDockHostHitTarget& rhs) {
|
||||
return lhs.kind == rhs.kind &&
|
||||
lhs.nodeId == rhs.nodeId &&
|
||||
lhs.panelId == rhs.panelId &&
|
||||
lhs.index == rhs.index;
|
||||
}
|
||||
|
||||
void DrawCard(
|
||||
UIDrawList& drawList,
|
||||
const UIRect& rect,
|
||||
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 = {
|
||||
{ "hierarchy", "Hierarchy", {}, true, true, false },
|
||||
{ "doc-a", "Document A", {}, true, true, true },
|
||||
{ "doc-b", "Document B", {}, true, true, true },
|
||||
{ "doc-c", "Document C", {}, true, true, false },
|
||||
{ "inspector", "Inspector", {}, true, true, true },
|
||||
{ "console", "Console", {}, true, true, true }
|
||||
};
|
||||
return registry;
|
||||
}
|
||||
|
||||
UIEditorWorkspaceModel BuildWorkspace() {
|
||||
UIEditorWorkspaceModel workspace = {};
|
||||
workspace.root = BuildUIEditorWorkspaceSplit(
|
||||
"root-top-bottom",
|
||||
UIEditorWorkspaceSplitAxis::Vertical,
|
||||
0.76f,
|
||||
BuildUIEditorWorkspaceSplit(
|
||||
"top-left-right",
|
||||
UIEditorWorkspaceSplitAxis::Horizontal,
|
||||
0.22f,
|
||||
BuildUIEditorWorkspacePanel("hierarchy-node", "hierarchy", "Hierarchy", true),
|
||||
BuildUIEditorWorkspaceSplit(
|
||||
"center-right-split",
|
||||
UIEditorWorkspaceSplitAxis::Horizontal,
|
||||
0.72f,
|
||||
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),
|
||||
BuildUIEditorWorkspacePanel("inspector-node", "inspector", "Inspector", true))),
|
||||
BuildUIEditorWorkspacePanel("console-node", "console", "Console", true));
|
||||
workspace.activePanelId = "doc-a";
|
||||
return workspace;
|
||||
}
|
||||
|
||||
std::string DescribeHitTarget(const UIEditorDockHostHitTarget& target) {
|
||||
switch (target.kind) {
|
||||
case UIEditorDockHostHitTargetKind::SplitterHandle:
|
||||
return "Splitter: " + target.nodeId;
|
||||
case UIEditorDockHostHitTargetKind::TabStripBackground:
|
||||
return "TabStripBackground: " + target.nodeId;
|
||||
case UIEditorDockHostHitTargetKind::Tab:
|
||||
return "Tab: " + target.panelId;
|
||||
case UIEditorDockHostHitTargetKind::TabCloseButton:
|
||||
return "TabClose: " + target.panelId;
|
||||
case UIEditorDockHostHitTargetKind::PanelHeader:
|
||||
return "PanelHeader: " + target.panelId;
|
||||
case UIEditorDockHostHitTargetKind::PanelBody:
|
||||
return "PanelBody: " + target.panelId;
|
||||
case UIEditorDockHostHitTargetKind::PanelFooter:
|
||||
return "PanelFooter: " + target.panelId;
|
||||
case UIEditorDockHostHitTargetKind::PanelCloseButton:
|
||||
return "PanelClose: " + target.panelId;
|
||||
case UIEditorDockHostHitTargetKind::None:
|
||||
default:
|
||||
return "None";
|
||||
}
|
||||
}
|
||||
|
||||
std::string JoinVisiblePanelIds(const UIEditorWorkspaceController& controller) {
|
||||
const auto panels = XCEngine::UI::Editor::CollectUIEditorWorkspaceVisiblePanels(
|
||||
controller.GetWorkspace(),
|
||||
controller.GetSession());
|
||||
if (panels.empty()) {
|
||||
return "(none)";
|
||||
}
|
||||
|
||||
std::ostringstream stream;
|
||||
for (std::size_t index = 0; index < panels.size(); ++index) {
|
||||
if (index > 0u) {
|
||||
stream << ", ";
|
||||
}
|
||||
stream << panels[index].panelId;
|
||||
}
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
std::string FormatSplitRatio(
|
||||
const UIEditorWorkspaceController& controller,
|
||||
std::string_view nodeId) {
|
||||
const UIEditorWorkspaceNode* node =
|
||||
FindUIEditorWorkspaceNode(controller.GetWorkspace(), nodeId);
|
||||
if (node == nullptr || node->kind != UIEditorWorkspaceNodeKind::Split) {
|
||||
return std::string(nodeId) + ": n/a";
|
||||
}
|
||||
|
||||
std::ostringstream stream;
|
||||
stream.setf(std::ios::fixed, std::ios::floatfield);
|
||||
stream.precision(2);
|
||||
stream << nodeId << ": " << node->splitRatio;
|
||||
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_LBUTTONDOWN:
|
||||
if (app != nullptr) {
|
||||
app->HandleLeftButtonDown(
|
||||
static_cast<float>(GET_X_LPARAM(lParam)),
|
||||
static_cast<float>(GET_Y_LPARAM(lParam)));
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case WM_LBUTTONUP:
|
||||
if (app != nullptr) {
|
||||
app->HandleLeftButtonUp(
|
||||
static_cast<float>(GET_X_LPARAM(lParam)),
|
||||
static_cast<float>(GET_Y_LPARAM(lParam)));
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case WM_KEYDOWN:
|
||||
case WM_SYSKEYDOWN:
|
||||
if (app != nullptr && 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_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/workspace_shell_compose/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,
|
||||
1480,
|
||||
940,
|
||||
nullptr,
|
||||
nullptr,
|
||||
hInstance,
|
||||
this);
|
||||
if (m_hwnd == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ShowWindow(m_hwnd, nCmdShow);
|
||||
UpdateWindow(m_hwnd);
|
||||
|
||||
if (!m_renderer.Initialize(m_hwnd)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
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_dockState = {};
|
||||
m_layout = {};
|
||||
m_dragState = {};
|
||||
m_dragSplitterNodeId.clear();
|
||||
m_mousePosition = UIPoint(-1000.0f, -1000.0f);
|
||||
m_resetHovered = false;
|
||||
m_lastResult = "等待操作";
|
||||
UpdateSceneRects();
|
||||
RefreshLayout();
|
||||
UpdateHoverTarget();
|
||||
}
|
||||
|
||||
void OnResize(UINT width, UINT height) {
|
||||
if (width == 0u || height == 0u) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_renderer.Resize(width, height);
|
||||
UpdateSceneRects();
|
||||
}
|
||||
|
||||
void UpdateSceneRects() {
|
||||
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));
|
||||
|
||||
constexpr float outerPadding = 20.0f;
|
||||
constexpr float leftColumnWidth = 380.0f;
|
||||
m_introRect = UIRect(outerPadding, outerPadding, leftColumnWidth, 192.0f);
|
||||
m_stateRect = UIRect(outerPadding, 228.0f, leftColumnWidth, height - 248.0f);
|
||||
m_previewCardRect = UIRect(
|
||||
leftColumnWidth + outerPadding * 2.0f,
|
||||
outerPadding,
|
||||
width - leftColumnWidth - outerPadding * 3.0f,
|
||||
height - outerPadding * 2.0f);
|
||||
m_previewRect = UIRect(
|
||||
m_previewCardRect.x + 20.0f,
|
||||
m_previewCardRect.y + 20.0f,
|
||||
m_previewCardRect.width - 40.0f,
|
||||
m_previewCardRect.height - 40.0f);
|
||||
m_resetButtonRect = UIRect(
|
||||
m_stateRect.x + 16.0f,
|
||||
m_stateRect.y + 220.0f,
|
||||
m_stateRect.width - 32.0f,
|
||||
38.0f);
|
||||
}
|
||||
|
||||
void RefreshLayout() {
|
||||
m_layout = BuildUIEditorDockHostLayout(
|
||||
m_previewRect,
|
||||
m_controller.GetPanelRegistry(),
|
||||
m_controller.GetWorkspace(),
|
||||
m_controller.GetSession(),
|
||||
m_dockState);
|
||||
}
|
||||
|
||||
void UpdateHoverTarget() {
|
||||
UIEditorDockHostHitTarget hoveredTarget = HitTestUIEditorDockHost(m_layout, m_mousePosition);
|
||||
if (!AreTargetsEqual(hoveredTarget, m_dockState.hoveredTarget)) {
|
||||
m_dockState.hoveredTarget = std::move(hoveredTarget);
|
||||
RefreshLayout();
|
||||
}
|
||||
}
|
||||
|
||||
void HandleMouseMove(float x, float y) {
|
||||
m_mousePosition = UIPoint(x, y);
|
||||
TRACKMOUSEEVENT event = {};
|
||||
event.cbSize = sizeof(event);
|
||||
event.dwFlags = TME_LEAVE;
|
||||
event.hwndTrack = m_hwnd;
|
||||
TrackMouseEvent(&event);
|
||||
|
||||
UpdateSceneRects();
|
||||
m_resetHovered = ContainsPoint(m_resetButtonRect, x, y);
|
||||
|
||||
if (m_dragState.active) {
|
||||
XCEngine::UI::Layout::UISplitterLayoutResult draggedLayout = {};
|
||||
if (UpdateUISplitterDrag(m_dragState, m_mousePosition, draggedLayout)) {
|
||||
ApplyDraggedSplitterRatio(draggedLayout.splitRatio);
|
||||
} else {
|
||||
RefreshLayout();
|
||||
}
|
||||
m_dockState.hoveredTarget = {
|
||||
UIEditorDockHostHitTargetKind::SplitterHandle,
|
||||
m_dragSplitterNodeId,
|
||||
{},
|
||||
UIEditorTabStripInvalidIndex
|
||||
};
|
||||
m_dockState.activeSplitterNodeId = m_dragSplitterNodeId;
|
||||
RefreshLayout();
|
||||
InvalidateRect(m_hwnd, nullptr, FALSE);
|
||||
return;
|
||||
}
|
||||
|
||||
RefreshLayout();
|
||||
UpdateHoverTarget();
|
||||
InvalidateRect(m_hwnd, nullptr, FALSE);
|
||||
}
|
||||
|
||||
void HandleMouseLeave() {
|
||||
if (m_dragState.active) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_mousePosition = UIPoint(-1000.0f, -1000.0f);
|
||||
m_resetHovered = false;
|
||||
m_dockState.hoveredTarget = {};
|
||||
RefreshLayout();
|
||||
InvalidateRect(m_hwnd, nullptr, FALSE);
|
||||
}
|
||||
|
||||
void HandleLeftButtonDown(float x, float y) {
|
||||
UpdateSceneRects();
|
||||
m_mousePosition = UIPoint(x, y);
|
||||
m_dockState.focused = true;
|
||||
RefreshLayout();
|
||||
UpdateHoverTarget();
|
||||
|
||||
const UIEditorDockHostHitTarget hit = m_dockState.hoveredTarget;
|
||||
if (hit.kind != UIEditorDockHostHitTargetKind::SplitterHandle) {
|
||||
InvalidateRect(m_hwnd, nullptr, FALSE);
|
||||
return;
|
||||
}
|
||||
|
||||
const auto* splitter = FindUIEditorDockHostSplitterLayout(m_layout, hit.nodeId);
|
||||
if (splitter == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!BeginUISplitterDrag(
|
||||
1u,
|
||||
splitter->axis == UIEditorWorkspaceSplitAxis::Horizontal
|
||||
? XCEngine::UI::Layout::UILayoutAxis::Horizontal
|
||||
: XCEngine::UI::Layout::UILayoutAxis::Vertical,
|
||||
splitter->bounds,
|
||||
splitter->splitterLayout,
|
||||
splitter->constraints,
|
||||
splitter->metrics,
|
||||
m_mousePosition,
|
||||
m_dragState)) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_dragSplitterNodeId = splitter->nodeId;
|
||||
m_dockState.activeSplitterNodeId = splitter->nodeId;
|
||||
SetCapture(m_hwnd);
|
||||
m_lastResult = "开始拖拽 splitter: " + splitter->nodeId;
|
||||
RefreshLayout();
|
||||
InvalidateRect(m_hwnd, nullptr, FALSE);
|
||||
}
|
||||
|
||||
void HandleLeftButtonUp(float x, float y) {
|
||||
UpdateSceneRects();
|
||||
m_mousePosition = UIPoint(x, y);
|
||||
|
||||
if (m_dragState.active) {
|
||||
XCEngine::UI::Layout::UISplitterLayoutResult draggedLayout = {};
|
||||
if (UpdateUISplitterDrag(m_dragState, m_mousePosition, draggedLayout)) {
|
||||
ApplyDraggedSplitterRatio(draggedLayout.splitRatio);
|
||||
}
|
||||
|
||||
EndUISplitterDrag(m_dragState);
|
||||
m_dockState.activeSplitterNodeId.clear();
|
||||
if (GetCapture() == m_hwnd) {
|
||||
ReleaseCapture();
|
||||
}
|
||||
m_lastResult = "结束拖拽 splitter: " + m_dragSplitterNodeId;
|
||||
m_dragSplitterNodeId.clear();
|
||||
RefreshLayout();
|
||||
UpdateHoverTarget();
|
||||
InvalidateRect(m_hwnd, nullptr, FALSE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ContainsPoint(m_resetButtonRect, x, y)) {
|
||||
ResetScenario();
|
||||
InvalidateRect(m_hwnd, nullptr, FALSE);
|
||||
return;
|
||||
}
|
||||
|
||||
RefreshLayout();
|
||||
UpdateHoverTarget();
|
||||
ExecuteClick(m_dockState.hoveredTarget);
|
||||
RefreshLayout();
|
||||
UpdateHoverTarget();
|
||||
InvalidateRect(m_hwnd, nullptr, FALSE);
|
||||
}
|
||||
|
||||
void ExecuteClick(const UIEditorDockHostHitTarget& hit) {
|
||||
switch (hit.kind) {
|
||||
case UIEditorDockHostHitTargetKind::Tab:
|
||||
DispatchWorkspaceCommand(
|
||||
UIEditorWorkspaceCommandKind::ActivatePanel,
|
||||
hit.panelId,
|
||||
"Activate Tab");
|
||||
return;
|
||||
case UIEditorDockHostHitTargetKind::TabCloseButton:
|
||||
DispatchWorkspaceCommand(
|
||||
UIEditorWorkspaceCommandKind::ClosePanel,
|
||||
hit.panelId,
|
||||
"Close Tab");
|
||||
return;
|
||||
case UIEditorDockHostHitTargetKind::PanelHeader:
|
||||
case UIEditorDockHostHitTargetKind::PanelBody:
|
||||
case UIEditorDockHostHitTargetKind::PanelFooter:
|
||||
DispatchWorkspaceCommand(
|
||||
UIEditorWorkspaceCommandKind::ActivatePanel,
|
||||
hit.panelId,
|
||||
"Activate Panel");
|
||||
return;
|
||||
case UIEditorDockHostHitTargetKind::PanelCloseButton:
|
||||
DispatchWorkspaceCommand(
|
||||
UIEditorWorkspaceCommandKind::ClosePanel,
|
||||
hit.panelId,
|
||||
"Close Panel");
|
||||
return;
|
||||
case UIEditorDockHostHitTargetKind::TabStripBackground:
|
||||
m_lastResult = "DockHost focus = On";
|
||||
return;
|
||||
case UIEditorDockHostHitTargetKind::None:
|
||||
default:
|
||||
m_dockState.focused = false;
|
||||
m_lastResult = "DockHost focus = Off";
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void DispatchWorkspaceCommand(
|
||||
UIEditorWorkspaceCommandKind kind,
|
||||
std::string_view panelId,
|
||||
std::string_view label) {
|
||||
UIEditorWorkspaceCommand command = {};
|
||||
command.kind = kind;
|
||||
command.panelId = std::string(panelId);
|
||||
|
||||
const UIEditorWorkspaceCommandResult result = m_controller.Dispatch(command);
|
||||
m_lastResult =
|
||||
std::string(label) + " -> " +
|
||||
std::string(GetUIEditorWorkspaceCommandStatusName(result.status)) +
|
||||
" | " +
|
||||
result.message;
|
||||
}
|
||||
|
||||
void ApplyDraggedSplitterRatio(float splitRatio) {
|
||||
auto snapshot = m_controller.CaptureLayoutSnapshot();
|
||||
if (!TrySetUIEditorWorkspaceSplitRatio(snapshot.workspace, m_dragSplitterNodeId, splitRatio)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const auto result = m_controller.RestoreLayoutSnapshot(snapshot);
|
||||
std::ostringstream stream;
|
||||
stream.setf(std::ios::fixed, std::ios::floatfield);
|
||||
stream.precision(2);
|
||||
stream << "Drag " << m_dragSplitterNodeId << " -> "
|
||||
<< GetUIEditorWorkspaceLayoutOperationStatusName(result.status)
|
||||
<< " | ratio=" << splitRatio;
|
||||
m_lastResult = stream.str();
|
||||
RefreshLayout();
|
||||
}
|
||||
|
||||
void RenderFrame() {
|
||||
UpdateSceneRects();
|
||||
RefreshLayout();
|
||||
UpdateHoverTarget();
|
||||
|
||||
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));
|
||||
|
||||
UIDrawData drawData = {};
|
||||
UIDrawList& drawList = drawData.EmplaceDrawList("EditorWorkspaceShellCompose");
|
||||
drawList.AddFilledRect(UIRect(0.0f, 0.0f, width, height), kWindowBg);
|
||||
|
||||
DrawCard(
|
||||
drawList,
|
||||
m_introRect,
|
||||
"测试功能:DockHost / Workspace Compose 基础层",
|
||||
"只验证 DockHost 真实 compose、splitter drag、tab host、panel frame 联动,不包含业务面板。");
|
||||
drawList.AddText(
|
||||
UIPoint(m_introRect.x + 16.0f, m_introRect.y + 68.0f),
|
||||
"重点检查:三条 splitter 的 resize 是否稳定;关闭面板后 branch 是否正确 collapse;点击 tab / panel 是否同步 active。",
|
||||
kTextPrimary,
|
||||
12.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(m_introRect.x + 16.0f, m_introRect.y + 92.0f),
|
||||
"操作:拖拽 Hierarchy / Documents / Inspector / Console 之间的 splitter;点击 Document A/B/C;点 X 关闭 tab 或 side panel;Reset 恢复;F12 截图。",
|
||||
kTextMuted,
|
||||
12.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(m_introRect.x + 16.0f, m_introRect.y + 116.0f),
|
||||
"预期:splitter 会被最小尺寸 clamp;Document C 没有 X;Inspector/Console 关闭后对应分支会收拢,不应留下歪掉的空洞。",
|
||||
kTextWeak,
|
||||
12.0f);
|
||||
|
||||
DrawCard(
|
||||
drawList,
|
||||
m_stateRect,
|
||||
"状态回显",
|
||||
"这里直接回显 hover / focus / dragging / active panel / split ratio,方便人工检查。");
|
||||
DrawButton(drawList, m_resetButtonRect, "Reset", m_resetHovered);
|
||||
|
||||
const auto validation = m_controller.ValidateState();
|
||||
drawList.AddText(
|
||||
UIPoint(m_stateRect.x + 16.0f, m_stateRect.y + 70.0f),
|
||||
"Hover: " + DescribeHitTarget(m_dockState.hoveredTarget),
|
||||
kTextPrimary,
|
||||
13.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(m_stateRect.x + 16.0f, m_stateRect.y + 96.0f),
|
||||
std::string("Focused: ") + (m_dockState.focused ? "On" : "Off"),
|
||||
kTextPrimary,
|
||||
13.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(m_stateRect.x + 16.0f, m_stateRect.y + 122.0f),
|
||||
"Dragging: " + (m_dragSplitterNodeId.empty() ? std::string("(none)") : m_dragSplitterNodeId),
|
||||
kTextPrimary,
|
||||
13.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(m_stateRect.x + 16.0f, m_stateRect.y + 148.0f),
|
||||
"Active Panel: " + m_controller.GetWorkspace().activePanelId,
|
||||
kTextPrimary,
|
||||
13.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(m_stateRect.x + 16.0f, m_stateRect.y + 174.0f),
|
||||
"Visible Panels: " + JoinVisiblePanelIds(m_controller),
|
||||
kTextMuted,
|
||||
12.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(m_stateRect.x + 16.0f, m_stateRect.y + 280.0f),
|
||||
FormatSplitRatio(m_controller, "root-top-bottom"),
|
||||
kTextPrimary,
|
||||
12.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(m_stateRect.x + 16.0f, m_stateRect.y + 302.0f),
|
||||
FormatSplitRatio(m_controller, "top-left-right"),
|
||||
kTextPrimary,
|
||||
12.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(m_stateRect.x + 16.0f, m_stateRect.y + 324.0f),
|
||||
FormatSplitRatio(m_controller, "center-right-split"),
|
||||
kTextPrimary,
|
||||
12.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(m_stateRect.x + 16.0f, m_stateRect.y + 356.0f),
|
||||
"Result: " + m_lastResult,
|
||||
kTextMuted,
|
||||
12.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(m_stateRect.x + 16.0f, m_stateRect.y + 382.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/workspace_shell_compose/captures/")
|
||||
: m_autoScreenshot.GetLastCaptureSummary());
|
||||
drawList.AddText(
|
||||
UIPoint(m_stateRect.x + 16.0f, m_stateRect.y + 408.0f),
|
||||
captureSummary,
|
||||
kTextWeak,
|
||||
12.0f);
|
||||
|
||||
DrawCard(
|
||||
drawList,
|
||||
m_previewCardRect,
|
||||
"预览区",
|
||||
"这里只保留一个 DockHost 试验场,不混入业务 UI。");
|
||||
|
||||
AppendUIEditorDockHostBackground(drawList, m_layout);
|
||||
AppendUIEditorDockHostForeground(drawList, m_layout);
|
||||
|
||||
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 = {};
|
||||
UIEditorWorkspaceController m_controller = {};
|
||||
UIEditorDockHostState m_dockState = {};
|
||||
UIEditorDockHostLayout m_layout = {};
|
||||
UISplitterDragState m_dragState = {};
|
||||
std::string m_dragSplitterNodeId = {};
|
||||
UIPoint m_mousePosition = UIPoint(-1000.0f, -1000.0f);
|
||||
UIRect m_introRect = {};
|
||||
UIRect m_stateRect = {};
|
||||
UIRect m_previewCardRect = {};
|
||||
UIRect m_previewRect = {};
|
||||
UIRect m_resetButtonRect = {};
|
||||
bool m_resetHovered = false;
|
||||
std::string m_lastResult = {};
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, LPWSTR, int nCmdShow) {
|
||||
return XCEngine::Tests::EditorUI::RunEditorUIValidationApp(
|
||||
hInstance,
|
||||
nCmdShow,
|
||||
"editor.shell.workspace_shell_compose");
|
||||
return ScenarioApp().Run(hInstance, nCmdShow);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user