feat(xcui): advance core and editor validation flow
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
add_executable(editor_ui_panel_session_flow_validation WIN32
|
||||
main.cpp
|
||||
)
|
||||
|
||||
target_include_directories(editor_ui_panel_session_flow_validation PRIVATE
|
||||
${CMAKE_SOURCE_DIR}/engine/include
|
||||
${CMAKE_SOURCE_DIR}/new_editor/include
|
||||
)
|
||||
|
||||
target_compile_definitions(editor_ui_panel_session_flow_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_session_flow_validation PRIVATE /utf-8 /FS)
|
||||
set_property(TARGET editor_ui_panel_session_flow_validation PROPERTY
|
||||
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
|
||||
endif()
|
||||
|
||||
target_link_libraries(editor_ui_panel_session_flow_validation PRIVATE
|
||||
XCNewEditorLib
|
||||
XCNewEditorHost
|
||||
)
|
||||
|
||||
set_target_properties(editor_ui_panel_session_flow_validation PROPERTIES
|
||||
OUTPUT_NAME "XCUIEditorPanelSessionFlowValidation"
|
||||
)
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
648
tests/UI/Editor/integration/state/panel_session_flow/main.cpp
Normal file
648
tests/UI/Editor/integration/state/panel_session_flow/main.cpp
Normal file
@@ -0,0 +1,648 @@
|
||||
#ifndef NOMINMAX
|
||||
#define NOMINMAX
|
||||
#endif
|
||||
|
||||
#include <XCNewEditor/Editor/UIEditorWorkspaceController.h>
|
||||
#include <XCNewEditor/Host/AutoScreenshot.h>
|
||||
#include <XCNewEditor/Host/NativeRenderer.h>
|
||||
|
||||
#include <XCEngine/UI/DrawData.h>
|
||||
|
||||
#include <windows.h>
|
||||
#include <windowsx.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <filesystem>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#ifndef XCENGINE_EDITOR_UI_TESTS_REPO_ROOT
|
||||
#define XCENGINE_EDITOR_UI_TESTS_REPO_ROOT "."
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
|
||||
using XCEngine::NewEditor::BuildDefaultUIEditorWorkspaceController;
|
||||
using XCEngine::NewEditor::BuildUIEditorWorkspacePanel;
|
||||
using XCEngine::NewEditor::BuildUIEditorWorkspaceSplit;
|
||||
using XCEngine::NewEditor::BuildUIEditorWorkspaceTabStack;
|
||||
using XCEngine::NewEditor::CollectUIEditorWorkspaceVisiblePanels;
|
||||
using XCEngine::NewEditor::FindUIEditorPanelSessionState;
|
||||
using XCEngine::NewEditor::GetUIEditorWorkspaceCommandKindName;
|
||||
using XCEngine::NewEditor::GetUIEditorWorkspaceCommandStatusName;
|
||||
using XCEngine::NewEditor::UIEditorPanelRegistry;
|
||||
using XCEngine::NewEditor::UIEditorWorkspaceCommand;
|
||||
using XCEngine::NewEditor::UIEditorWorkspaceCommandKind;
|
||||
using XCEngine::NewEditor::UIEditorWorkspaceCommandResult;
|
||||
using XCEngine::NewEditor::UIEditorWorkspaceController;
|
||||
using XCEngine::NewEditor::UIEditorWorkspaceModel;
|
||||
using XCEngine::NewEditor::UIEditorWorkspaceSession;
|
||||
using XCEngine::NewEditor::UIEditorWorkspaceSplitAxis;
|
||||
using XCEngine::UI::UIColor;
|
||||
using XCEngine::UI::UIDrawData;
|
||||
using XCEngine::UI::UIDrawList;
|
||||
using XCEngine::UI::UIPoint;
|
||||
using XCEngine::UI::UIRect;
|
||||
using XCEngine::XCUI::Host::AutoScreenshotController;
|
||||
using XCEngine::XCUI::Host::NativeRenderer;
|
||||
|
||||
constexpr const wchar_t* kWindowClassName = L"XCUIEditorPanelSessionFlowValidation";
|
||||
constexpr const wchar_t* kWindowTitle = L"XCUI Editor | Panel Session 状态流";
|
||||
|
||||
constexpr UIColor kWindowBg(0.15f, 0.15f, 0.15f, 1.0f);
|
||||
constexpr UIColor kCardBg(0.20f, 0.20f, 0.20f, 1.0f);
|
||||
constexpr UIColor kCardBorder(0.29f, 0.29f, 0.29f, 1.0f);
|
||||
constexpr UIColor kTextPrimary(0.94f, 0.94f, 0.94f, 1.0f);
|
||||
constexpr UIColor kTextMuted(0.72f, 0.72f, 0.72f, 1.0f);
|
||||
constexpr UIColor kAccent(0.33f, 0.55f, 0.84f, 1.0f);
|
||||
constexpr UIColor kSuccess(0.43f, 0.71f, 0.47f, 1.0f);
|
||||
constexpr UIColor kWarning(0.78f, 0.60f, 0.30f, 1.0f);
|
||||
constexpr UIColor kDanger(0.78f, 0.34f, 0.34f, 1.0f);
|
||||
constexpr UIColor kButtonEnabled(0.32f, 0.32f, 0.32f, 1.0f);
|
||||
constexpr UIColor kButtonDisabled(0.24f, 0.24f, 0.24f, 1.0f);
|
||||
constexpr UIColor kButtonBorder(0.44f, 0.44f, 0.44f, 1.0f);
|
||||
|
||||
enum class ActionId : unsigned char {
|
||||
HideActive = 0,
|
||||
ShowDocA,
|
||||
CloseDocB,
|
||||
OpenDocB,
|
||||
ActivateDetails,
|
||||
Reset
|
||||
};
|
||||
|
||||
struct ButtonState {
|
||||
ActionId action = ActionId::HideActive;
|
||||
std::string label = {};
|
||||
UIRect rect = {};
|
||||
bool enabled = 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();
|
||||
}
|
||||
|
||||
UIEditorPanelRegistry BuildPanelRegistry() {
|
||||
UIEditorPanelRegistry registry = {};
|
||||
registry.panels = {
|
||||
{ "doc-a", "Document A", {}, true, true, true },
|
||||
{ "doc-b", "Document B", {}, true, true, true },
|
||||
{ "details", "Details", {}, true, true, true }
|
||||
};
|
||||
return registry;
|
||||
}
|
||||
|
||||
UIEditorWorkspaceModel BuildWorkspace() {
|
||||
UIEditorWorkspaceModel workspace = {};
|
||||
workspace.root = BuildUIEditorWorkspaceSplit(
|
||||
"root-split",
|
||||
UIEditorWorkspaceSplitAxis::Horizontal,
|
||||
0.66f,
|
||||
BuildUIEditorWorkspaceTabStack(
|
||||
"document-tabs",
|
||||
{
|
||||
BuildUIEditorWorkspacePanel("doc-a-node", "doc-a", "Document A", true),
|
||||
BuildUIEditorWorkspacePanel("doc-b-node", "doc-b", "Document B", true)
|
||||
},
|
||||
0u),
|
||||
BuildUIEditorWorkspacePanel("details-node", "details", "Details", true));
|
||||
workspace.activePanelId = "doc-a";
|
||||
return workspace;
|
||||
}
|
||||
|
||||
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 JoinVisiblePanelIds(
|
||||
const UIEditorWorkspaceModel& workspace,
|
||||
const UIEditorWorkspaceSession& session) {
|
||||
const auto panels = CollectUIEditorWorkspaceVisiblePanels(workspace, session);
|
||||
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 DescribePanelState(
|
||||
const UIEditorWorkspaceSession& session,
|
||||
std::string_view panelId,
|
||||
std::string_view displayName) {
|
||||
const auto* state = FindUIEditorPanelSessionState(session, panelId);
|
||||
if (state == nullptr) {
|
||||
return std::string(displayName) + ": missing";
|
||||
}
|
||||
|
||||
std::string visibility = {};
|
||||
if (!state->open) {
|
||||
visibility = "closed";
|
||||
} else if (!state->visible) {
|
||||
visibility = "hidden";
|
||||
} else {
|
||||
visibility = "visible";
|
||||
}
|
||||
|
||||
return std::string(displayName) + ": " + visibility;
|
||||
}
|
||||
|
||||
UIColor ResolvePanelStateColor(
|
||||
const UIEditorWorkspaceSession& session,
|
||||
std::string_view panelId) {
|
||||
const auto* state = FindUIEditorPanelSessionState(session, panelId);
|
||||
if (state == nullptr) {
|
||||
return kDanger;
|
||||
}
|
||||
|
||||
if (!state->open) {
|
||||
return kDanger;
|
||||
}
|
||||
|
||||
if (!state->visible) {
|
||||
return kWarning;
|
||||
}
|
||||
|
||||
return kSuccess;
|
||||
}
|
||||
|
||||
void DrawCard(
|
||||
UIDrawList& drawList,
|
||||
const UIRect& rect,
|
||||
std::string_view title,
|
||||
std::string_view subtitle = {}) {
|
||||
drawList.AddFilledRect(rect, kCardBg, 12.0f);
|
||||
drawList.AddRectOutline(rect, kCardBorder, 1.0f, 12.0f);
|
||||
drawList.AddText(UIPoint(rect.x + 18.0f, rect.y + 16.0f), std::string(title), kTextPrimary, 17.0f);
|
||||
if (!subtitle.empty()) {
|
||||
drawList.AddText(UIPoint(rect.x + 18.0f, rect.y + 42.0f), std::string(subtitle), kTextMuted, 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_PAINT:
|
||||
if (app != nullptr) {
|
||||
PAINTSTRUCT paintStruct = {};
|
||||
BeginPaint(hwnd, &paintStruct);
|
||||
app->RenderFrame();
|
||||
EndPaint(hwnd, &paintStruct);
|
||||
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->HandleShortcut(static_cast<UINT>(wParam));
|
||||
}
|
||||
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_hInstance = hInstance;
|
||||
ResetScenario();
|
||||
|
||||
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,
|
||||
1320,
|
||||
860,
|
||||
nullptr,
|
||||
nullptr,
|
||||
hInstance,
|
||||
this);
|
||||
if (m_hwnd == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ShowWindow(m_hwnd, nCmdShow);
|
||||
UpdateWindow(m_hwnd);
|
||||
|
||||
if (!m_renderer.Initialize(m_hwnd)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_autoScreenshot.Initialize(
|
||||
(ResolveRepoRootPath() / "tests/UI/Editor/integration/state/panel_session_flow/captures")
|
||||
.lexically_normal());
|
||||
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 && m_hInstance != nullptr) {
|
||||
UnregisterClassW(kWindowClassName, m_hInstance);
|
||||
m_windowClassAtom = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void ResetScenario() {
|
||||
m_controller =
|
||||
BuildDefaultUIEditorWorkspaceController(BuildPanelRegistry(), BuildWorkspace());
|
||||
m_hasLastCommandResult = false;
|
||||
m_lastActionSummary = "等待操作:先点 Hide Active,确认命令结果为 Changed,并检查 active/visible 状态联动。";
|
||||
}
|
||||
|
||||
void OnResize(UINT width, UINT height) {
|
||||
if (width == 0 || height == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_renderer.Resize(width, height);
|
||||
}
|
||||
|
||||
void RenderFrame() {
|
||||
if (m_hwnd == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
RECT clientRect = {};
|
||||
GetClientRect(m_hwnd, &clientRect);
|
||||
const float width = static_cast<float>((std::max)(clientRect.right - clientRect.left, 1L));
|
||||
const float height = static_cast<float>((std::max)(clientRect.bottom - clientRect.top, 1L));
|
||||
|
||||
UIDrawData drawData = {};
|
||||
BuildDrawData(drawData, width, height);
|
||||
|
||||
const bool framePresented = m_renderer.Render(drawData);
|
||||
m_autoScreenshot.CaptureIfRequested(
|
||||
m_renderer,
|
||||
drawData,
|
||||
static_cast<unsigned int>(width),
|
||||
static_cast<unsigned int>(height),
|
||||
framePresented);
|
||||
}
|
||||
|
||||
void HandleClick(float x, float y) {
|
||||
for (const ButtonState& button : m_buttons) {
|
||||
if (button.enabled && ContainsPoint(button.rect, x, y)) {
|
||||
DispatchAction(button.action);
|
||||
InvalidateRect(m_hwnd, nullptr, FALSE);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void HandleShortcut(UINT keyCode) {
|
||||
switch (keyCode) {
|
||||
case '1':
|
||||
DispatchAction(ActionId::HideActive);
|
||||
break;
|
||||
case '2':
|
||||
DispatchAction(ActionId::ShowDocA);
|
||||
break;
|
||||
case '3':
|
||||
DispatchAction(ActionId::CloseDocB);
|
||||
break;
|
||||
case '4':
|
||||
DispatchAction(ActionId::OpenDocB);
|
||||
break;
|
||||
case '5':
|
||||
DispatchAction(ActionId::ActivateDetails);
|
||||
break;
|
||||
case 'R':
|
||||
DispatchAction(ActionId::Reset);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
InvalidateRect(m_hwnd, nullptr, FALSE);
|
||||
}
|
||||
|
||||
void DispatchAction(ActionId action) {
|
||||
std::string label = {};
|
||||
UIEditorWorkspaceCommand command = {};
|
||||
|
||||
switch (action) {
|
||||
case ActionId::HideActive:
|
||||
label = "Hide Active";
|
||||
command.kind = UIEditorWorkspaceCommandKind::HidePanel;
|
||||
command.panelId = m_controller.GetWorkspace().activePanelId;
|
||||
break;
|
||||
case ActionId::ShowDocA:
|
||||
label = "Show Doc A";
|
||||
command.kind = UIEditorWorkspaceCommandKind::ShowPanel;
|
||||
command.panelId = "doc-a";
|
||||
break;
|
||||
case ActionId::CloseDocB:
|
||||
label = "Close Doc B";
|
||||
command.kind = UIEditorWorkspaceCommandKind::ClosePanel;
|
||||
command.panelId = "doc-b";
|
||||
break;
|
||||
case ActionId::OpenDocB:
|
||||
label = "Open Doc B";
|
||||
command.kind = UIEditorWorkspaceCommandKind::OpenPanel;
|
||||
command.panelId = "doc-b";
|
||||
break;
|
||||
case ActionId::ActivateDetails:
|
||||
label = "Activate Details";
|
||||
command.kind = UIEditorWorkspaceCommandKind::ActivatePanel;
|
||||
command.panelId = "details";
|
||||
break;
|
||||
case ActionId::Reset:
|
||||
label = "Reset";
|
||||
command.kind = UIEditorWorkspaceCommandKind::ResetWorkspace;
|
||||
break;
|
||||
}
|
||||
|
||||
m_lastCommandResult = m_controller.Dispatch(command);
|
||||
m_hasLastCommandResult = true;
|
||||
m_lastActionSummary =
|
||||
label + " -> " +
|
||||
std::string(GetUIEditorWorkspaceCommandStatusName(m_lastCommandResult.status));
|
||||
}
|
||||
|
||||
bool IsButtonEnabled(ActionId action) const {
|
||||
const UIEditorWorkspaceModel& workspace = m_controller.GetWorkspace();
|
||||
const UIEditorWorkspaceSession& session = m_controller.GetSession();
|
||||
switch (action) {
|
||||
case ActionId::HideActive: {
|
||||
if (workspace.activePanelId.empty()) {
|
||||
return false;
|
||||
}
|
||||
const auto* state = FindUIEditorPanelSessionState(session, workspace.activePanelId);
|
||||
return state != nullptr && state->open && state->visible;
|
||||
}
|
||||
case ActionId::ShowDocA: {
|
||||
const auto* state = FindUIEditorPanelSessionState(session, "doc-a");
|
||||
return state != nullptr && state->open && !state->visible;
|
||||
}
|
||||
case ActionId::CloseDocB: {
|
||||
const auto* state = FindUIEditorPanelSessionState(session, "doc-b");
|
||||
return state != nullptr && state->open;
|
||||
}
|
||||
case ActionId::OpenDocB: {
|
||||
const auto* state = FindUIEditorPanelSessionState(session, "doc-b");
|
||||
return state != nullptr && !state->open;
|
||||
}
|
||||
case ActionId::ActivateDetails: {
|
||||
const auto* state = FindUIEditorPanelSessionState(session, "details");
|
||||
return state != nullptr &&
|
||||
state->open &&
|
||||
state->visible &&
|
||||
workspace.activePanelId != "details";
|
||||
}
|
||||
case ActionId::Reset:
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void BuildDrawData(UIDrawData& drawData, float width, float height) {
|
||||
const UIEditorWorkspaceModel& workspace = m_controller.GetWorkspace();
|
||||
const UIEditorWorkspaceSession& session = m_controller.GetSession();
|
||||
const auto validation = m_controller.ValidateState();
|
||||
|
||||
UIDrawList& drawList = drawData.EmplaceDrawList("Editor Panel Session Flow");
|
||||
drawList.AddFilledRect(UIRect(0.0f, 0.0f, width, height), kWindowBg);
|
||||
|
||||
const float margin = 20.0f;
|
||||
const UIRect headerRect(margin, margin, width - margin * 2.0f, 170.0f);
|
||||
const UIRect actionRect(margin, headerRect.y + headerRect.height + 16.0f, 320.0f, height - 246.0f);
|
||||
const UIRect stateRect(actionRect.x + actionRect.width + 16.0f, actionRect.y, width - actionRect.width - margin * 2.0f - 16.0f, height - 246.0f);
|
||||
const UIRect footerRect(margin, height - 96.0f, width - margin * 2.0f, 76.0f);
|
||||
|
||||
DrawCard(drawList, headerRect, "测试功能:Editor Command Dispatch + Workspace Controller", "只验证命令分发、状态变更结果和 panel session 联动;不验证业务面板。");
|
||||
drawList.AddText(UIPoint(headerRect.x + 18.0f, headerRect.y + 70.0f), "1. 点 `1 Hide Active`,Result 应是 Changed;active 从 doc-a 切到 doc-b,selected tab 也同步到 B。", kTextPrimary, 13.0f);
|
||||
drawList.AddText(UIPoint(headerRect.x + 18.0f, headerRect.y + 92.0f), "2. 再点 `1 Hide Active`,如果当前 panel 已 hidden,Result 应变成 NoOp,而不是乱改状态。", kTextPrimary, 13.0f);
|
||||
drawList.AddText(UIPoint(headerRect.x + 18.0f, headerRect.y + 114.0f), "3. 点 `3 Close Doc B` 后再点 `5 Activate Details` / `4 Open Doc B`,检查 Changed / Rejected / NoOp 是否符合提示。", kTextPrimary, 13.0f);
|
||||
drawList.AddText(UIPoint(headerRect.x + 18.0f, headerRect.y + 136.0f), "4. `R Reset` 必须把状态拉回基线;按 `F12` 保存当前窗口截图。", kTextPrimary, 13.0f);
|
||||
|
||||
DrawCard(drawList, actionRect, "操作区", "每个按钮都会先生成 command,再交给 Workspace Controller 分发。");
|
||||
DrawCard(drawList, stateRect, "状态摘要", "重点检查 active panel、visible panels、selected tab index 和每个 panel session 状态。");
|
||||
DrawCard(drawList, footerRect, "最近结果", "这块显示 last command、status、message 与当前 validation。");
|
||||
|
||||
m_buttons.clear();
|
||||
const std::vector<std::pair<ActionId, std::string>> buttonDefs = {
|
||||
{ ActionId::HideActive, "1 Hide Active" },
|
||||
{ ActionId::ShowDocA, "2 Show Doc A" },
|
||||
{ ActionId::CloseDocB, "3 Close Doc B" },
|
||||
{ ActionId::OpenDocB, "4 Open Doc B" },
|
||||
{ ActionId::ActivateDetails, "5 Activate Details" },
|
||||
{ ActionId::Reset, "R Reset" }
|
||||
};
|
||||
|
||||
float buttonY = actionRect.y + 72.0f;
|
||||
for (const auto& [action, label] : buttonDefs) {
|
||||
ButtonState button = {};
|
||||
button.action = action;
|
||||
button.label = label;
|
||||
button.rect = UIRect(actionRect.x + 18.0f, buttonY, actionRect.width - 36.0f, 46.0f);
|
||||
button.enabled = IsButtonEnabled(action);
|
||||
m_buttons.push_back(button);
|
||||
|
||||
drawList.AddFilledRect(
|
||||
button.rect,
|
||||
button.enabled ? kButtonEnabled : kButtonDisabled,
|
||||
8.0f);
|
||||
drawList.AddRectOutline(button.rect, kButtonBorder, 1.0f, 8.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(button.rect.x + 14.0f, button.rect.y + 13.0f),
|
||||
button.label,
|
||||
button.enabled ? kTextPrimary : kTextMuted,
|
||||
13.0f);
|
||||
buttonY += 58.0f;
|
||||
}
|
||||
|
||||
const float leftX = stateRect.x + 18.0f;
|
||||
drawList.AddText(UIPoint(leftX, stateRect.y + 70.0f), "Current active panel:", kTextMuted, 12.0f);
|
||||
drawList.AddText(UIPoint(leftX, stateRect.y + 90.0f), workspace.activePanelId.empty() ? "(none)" : workspace.activePanelId, kAccent, 15.0f);
|
||||
|
||||
drawList.AddText(UIPoint(leftX, stateRect.y + 124.0f), "Visible panels:", kTextMuted, 12.0f);
|
||||
drawList.AddText(UIPoint(leftX, stateRect.y + 144.0f), JoinVisiblePanelIds(workspace, session), kTextPrimary, 14.0f);
|
||||
|
||||
drawList.AddText(UIPoint(leftX, stateRect.y + 178.0f), "Selected tab index:", kTextMuted, 12.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(leftX, stateRect.y + 198.0f),
|
||||
std::to_string(workspace.root.children.front().selectedTabIndex),
|
||||
kTextPrimary,
|
||||
14.0f);
|
||||
|
||||
const float pillX = leftX;
|
||||
const float pillY = stateRect.y + 244.0f;
|
||||
const std::vector<std::pair<std::string, std::string>> panelDefs = {
|
||||
{ "doc-a", "Document A" },
|
||||
{ "doc-b", "Document B" },
|
||||
{ "details", "Details" }
|
||||
};
|
||||
|
||||
float rowY = pillY;
|
||||
for (const auto& [panelId, label] : panelDefs) {
|
||||
const UIRect rowRect(leftX, rowY, stateRect.width - 36.0f, 54.0f);
|
||||
drawList.AddFilledRect(rowRect, UIColor(0.17f, 0.17f, 0.17f, 1.0f), 8.0f);
|
||||
drawList.AddRectOutline(rowRect, kCardBorder, 1.0f, 8.0f);
|
||||
drawList.AddFilledRect(
|
||||
UIRect(rowRect.x + 12.0f, rowRect.y + 15.0f, 10.0f, 10.0f),
|
||||
ResolvePanelStateColor(session, panelId),
|
||||
5.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(rowRect.x + 32.0f, rowRect.y + 11.0f),
|
||||
DescribePanelState(session, panelId, label),
|
||||
kTextPrimary,
|
||||
14.0f);
|
||||
const bool active = workspace.activePanelId == panelId;
|
||||
drawList.AddText(
|
||||
UIPoint(rowRect.x + 32.0f, rowRect.y + 31.0f),
|
||||
active ? "active = true" : "active = false",
|
||||
active ? kAccent : kTextMuted,
|
||||
12.0f);
|
||||
rowY += 64.0f;
|
||||
}
|
||||
|
||||
drawList.AddText(UIPoint(footerRect.x + 18.0f, footerRect.y + 28.0f), m_lastActionSummary, kTextPrimary, 13.0f);
|
||||
if (m_hasLastCommandResult) {
|
||||
drawList.AddText(
|
||||
UIPoint(footerRect.x + 18.0f, footerRect.y + 48.0f),
|
||||
"Last command: " +
|
||||
std::string(GetUIEditorWorkspaceCommandKindName(m_lastCommandResult.kind)) +
|
||||
" | Status: " +
|
||||
std::string(GetUIEditorWorkspaceCommandStatusName(m_lastCommandResult.status)) +
|
||||
" | " +
|
||||
m_lastCommandResult.message,
|
||||
m_lastCommandResult.status == XCEngine::NewEditor::UIEditorWorkspaceCommandStatus::Rejected
|
||||
? kDanger
|
||||
: (m_lastCommandResult.status == XCEngine::NewEditor::UIEditorWorkspaceCommandStatus::NoOp
|
||||
? kWarning
|
||||
: kSuccess),
|
||||
12.0f);
|
||||
}
|
||||
drawList.AddText(
|
||||
UIPoint(footerRect.x + 18.0f, footerRect.y + 66.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/state/panel_session_flow/captures/")
|
||||
: m_autoScreenshot.GetLastCaptureSummary());
|
||||
drawList.AddText(UIPoint(footerRect.x + 530.0f, footerRect.y + 66.0f), captureSummary, kTextMuted, 12.0f);
|
||||
}
|
||||
|
||||
HWND m_hwnd = nullptr;
|
||||
HINSTANCE m_hInstance = nullptr;
|
||||
ATOM m_windowClassAtom = 0;
|
||||
NativeRenderer m_renderer = {};
|
||||
AutoScreenshotController m_autoScreenshot = {};
|
||||
UIEditorWorkspaceController m_controller = {};
|
||||
std::vector<ButtonState> m_buttons = {};
|
||||
UIEditorWorkspaceCommandResult m_lastCommandResult = {};
|
||||
bool m_hasLastCommandResult = false;
|
||||
std::string m_lastActionSummary = {};
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, LPWSTR, int nCmdShow) {
|
||||
ScenarioApp app;
|
||||
return app.Run(hInstance, nCmdShow);
|
||||
}
|
||||
Reference in New Issue
Block a user