feat(xcui): add editor command and menu foundations

This commit is contained in:
2026-04-06 18:05:34 +08:00
parent 4afeb19d25
commit f912e81ade
29 changed files with 3581 additions and 61 deletions

View File

@@ -1,2 +1,3 @@
add_subdirectory(panel_session_flow)
add_subdirectory(layout_persistence)
add_subdirectory(shortcut_dispatch)

View File

@@ -0,0 +1,29 @@
add_executable(editor_ui_shortcut_dispatch_validation WIN32
main.cpp
)
target_include_directories(editor_ui_shortcut_dispatch_validation PRIVATE
${CMAKE_SOURCE_DIR}/engine/include
${CMAKE_SOURCE_DIR}/new_editor/include
)
target_compile_definitions(editor_ui_shortcut_dispatch_validation PRIVATE
UNICODE
_UNICODE
XCENGINE_EDITOR_UI_TESTS_REPO_ROOT="${XCENGINE_EDITOR_UI_TESTS_REPO_ROOT_PATH}"
)
if(MSVC)
target_compile_options(editor_ui_shortcut_dispatch_validation PRIVATE /utf-8 /FS)
set_property(TARGET editor_ui_shortcut_dispatch_validation PROPERTY
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
endif()
target_link_libraries(editor_ui_shortcut_dispatch_validation PRIVATE
XCNewEditorLib
XCNewEditorHost
)
set_target_properties(editor_ui_shortcut_dispatch_validation PROPERTIES
OUTPUT_NAME "XCUIEditorShortcutDispatchValidation"
)

View File

@@ -0,0 +1,641 @@
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <XCNewEditor/Editor/UIEditorShortcutManager.h>
#include <XCNewEditor/Host/AutoScreenshot.h>
#include <XCNewEditor/Host/InputModifierTracker.h>
#include <XCNewEditor/Host/NativeRenderer.h>
#include <XCEngine/Input/InputTypes.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::Input::KeyCode;
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::GetUIEditorShortcutDispatchStatusName;
using XCEngine::NewEditor::GetUIEditorWorkspaceCommandStatusName;
using XCEngine::NewEditor::UIEditorCommandPanelSource;
using XCEngine::NewEditor::UIEditorCommandRegistry;
using XCEngine::NewEditor::UIEditorPanelRegistry;
using XCEngine::NewEditor::UIEditorShortcutDispatchResult;
using XCEngine::NewEditor::UIEditorShortcutDispatchStatus;
using XCEngine::NewEditor::UIEditorShortcutManager;
using XCEngine::NewEditor::UIEditorWorkspaceCommandKind;
using XCEngine::NewEditor::UIEditorWorkspaceController;
using XCEngine::NewEditor::UIEditorWorkspaceModel;
using XCEngine::NewEditor::UIEditorWorkspaceSplitAxis;
using XCEngine::UI::UIColor;
using XCEngine::UI::UIDrawData;
using XCEngine::UI::UIDrawList;
using XCEngine::UI::UIInputEvent;
using XCEngine::UI::UIInputEventType;
using XCEngine::UI::UIPoint;
using XCEngine::UI::UIRect;
using XCEngine::UI::UIShortcutBinding;
using XCEngine::UI::UIShortcutContext;
using XCEngine::UI::UIShortcutScope;
using XCEngine::XCUI::Host::AutoScreenshotController;
using XCEngine::XCUI::Host::InputModifierTracker;
using XCEngine::XCUI::Host::NativeRenderer;
constexpr const wchar_t* kWindowClassName = L"XCUIEditorShortcutDispatchValidation";
constexpr const wchar_t* kWindowTitle = L"XCUI Editor | Shortcut Dispatch";
constexpr XCEngine::UI::UIElementId kWindowOwnerId = 1u;
constexpr XCEngine::UI::UIElementId kDocumentsPanelOwnerId = 11u;
constexpr XCEngine::UI::UIElementId kDetailsPanelOwnerId = 22u;
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.29f, 0.29f, 0.29f, 1.0f);
constexpr UIColor kTextPrimary(0.94f, 0.94f, 0.94f, 1.0f);
constexpr UIColor kTextMuted(0.70f, 0.70f, 0.70f, 1.0f);
constexpr UIColor kAccent(0.82f, 0.82f, 0.82f, 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);
enum class ActionId : unsigned char {
ToggleTextInput = 0,
ResetScenario
};
struct ButtonState {
ActionId action = ActionId::ToggleTextInput;
std::string label = {};
UIRect rect = {};
};
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;
}
UIEditorCommandRegistry BuildCommandRegistry() {
UIEditorCommandRegistry registry = {};
registry.commands = {
{
"workspace.hide_active",
"Hide Active",
{ UIEditorWorkspaceCommandKind::HidePanel, UIEditorCommandPanelSource::ActivePanel, {} }
},
{
"workspace.close_doc_b",
"Close Doc B",
{ UIEditorWorkspaceCommandKind::ClosePanel, UIEditorCommandPanelSource::FixedPanelId, "doc-b" }
},
{
"workspace.open_doc_b",
"Open Doc B",
{ UIEditorWorkspaceCommandKind::OpenPanel, UIEditorCommandPanelSource::FixedPanelId, "doc-b" }
},
{
"workspace.activate_details",
"Activate Details",
{ UIEditorWorkspaceCommandKind::ActivatePanel, UIEditorCommandPanelSource::FixedPanelId, "details" }
},
{
"workspace.reset",
"Reset Workspace",
{ UIEditorWorkspaceCommandKind::ResetWorkspace, UIEditorCommandPanelSource::None, {} }
}
};
return registry;
}
UIShortcutBinding MakeBinding(
std::string commandId,
UIShortcutScope scope,
XCEngine::UI::UIElementId ownerId,
KeyCode keyCode) {
UIShortcutBinding binding = {};
binding.commandId = std::move(commandId);
binding.scope = scope;
binding.ownerId = ownerId;
binding.triggerEventType = UIInputEventType::KeyDown;
binding.chord.keyCode = static_cast<std::int32_t>(keyCode);
binding.chord.modifiers.control = true;
return binding;
}
UIEditorShortcutManager BuildShortcutManager() {
UIEditorShortcutManager manager(BuildCommandRegistry());
manager.RegisterBinding(MakeBinding("workspace.hide_active", UIShortcutScope::Global, 0u, KeyCode::H));
manager.RegisterBinding(MakeBinding("workspace.close_doc_b", UIShortcutScope::Global, 0u, KeyCode::W));
manager.RegisterBinding(MakeBinding("workspace.open_doc_b", UIShortcutScope::Global, 0u, KeyCode::O));
manager.RegisterBinding(MakeBinding("workspace.reset", UIShortcutScope::Global, 0u, KeyCode::R));
manager.RegisterBinding(MakeBinding("workspace.activate_details", UIShortcutScope::Panel, kDocumentsPanelOwnerId, KeyCode::P));
manager.RegisterBinding(MakeBinding("workspace.reset", UIShortcutScope::Panel, kDetailsPanelOwnerId, KeyCode::P));
return manager;
}
std::int32_t MapVirtualKeyToUIKeyCode(WPARAM wParam) {
switch (wParam) {
case 'H': return static_cast<std::int32_t>(KeyCode::H);
case 'O': return static_cast<std::int32_t>(KeyCode::O);
case 'P': return static_cast<std::int32_t>(KeyCode::P);
case 'R': return static_cast<std::int32_t>(KeyCode::R);
case 'T': return static_cast<std::int32_t>(KeyCode::T);
case 'W': return static_cast<std::int32_t>(KeyCode::W);
case VK_CONTROL: return static_cast<std::int32_t>(KeyCode::LeftCtrl);
case VK_F12: return static_cast<std::int32_t>(KeyCode::F12);
default: return static_cast<std::int32_t>(KeyCode::None);
}
}
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 JoinVisiblePanels(const UIEditorWorkspaceController& controller) {
const auto panels = 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();
}
XCEngine::UI::UIElementId ResolveCurrentPanelOwnerId(std::string_view activePanelId) {
return activePanelId == "details" ? kDetailsPanelOwnerId : kDocumentsPanelOwnerId;
}
std::string DescribeCurrentScope(std::string_view activePanelId) {
return activePanelId == "details" ? "Details Panel Scope" : "Documents Panel Scope";
}
UIColor ResolveShortcutStatusColor(UIEditorShortcutDispatchStatus status) {
switch (status) {
case UIEditorShortcutDispatchStatus::Dispatched: return kSuccess;
case UIEditorShortcutDispatchStatus::Suppressed: return kWarning;
case UIEditorShortcutDispatchStatus::Rejected: return kDanger;
case UIEditorShortcutDispatchStatus::NoMatch:
default:
return kTextMuted;
}
}
UIColor ResolveCommandStatusColor(UIEditorWorkspaceController& controller, const UIEditorShortcutDispatchResult& result) {
(void)controller;
if (!result.commandExecuted) {
return kTextMuted;
}
switch (result.commandResult.status) {
case XCEngine::NewEditor::UIEditorWorkspaceCommandStatus::Changed: return kSuccess;
case XCEngine::NewEditor::UIEditorWorkspaceCommandStatus::NoOp: return kWarning;
case XCEngine::NewEditor::UIEditorWorkspaceCommandStatus::Rejected: return kDanger;
}
return kTextMuted;
}
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->m_renderer.Resize(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->HandleKey(UIInputEventType::KeyDown, wParam, lParam);
}
return 0;
}
break;
case WM_KEYUP:
case WM_SYSKEYUP:
if (app != nullptr) {
app->HandleKey(UIInputEventType::KeyUp, wParam, lParam);
return 0;
}
break;
case WM_ERASEBKGND:
return 1;
case WM_DESTROY:
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,
1340,
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/shortcut_dispatch/captures").lexically_normal());
return true;
}
void Shutdown() {
m_autoScreenshot.Shutdown();
m_renderer.Shutdown();
if (m_hwnd != nullptr && IsWindow(m_hwnd)) {
DestroyWindow(m_hwnd);
}
if (m_windowClassAtom != 0 && m_hInstance != nullptr) {
UnregisterClassW(kWindowClassName, m_hInstance);
}
}
void ResetScenario() {
m_controller = BuildDefaultUIEditorWorkspaceController(BuildPanelRegistry(), BuildWorkspace());
m_shortcutManager = BuildShortcutManager();
m_textInputActive = false;
m_inputModifierTracker.Reset();
m_lastAction = "等待操作";
m_lastShortcutStatus = "Pending";
m_lastCommandStatus = "(none)";
m_lastMessage = "先按 Ctrl+P再看 Shortcut result 和 Command result 是不是分别变化。";
m_lastShortcutColor = kTextMuted;
m_lastCommandColor = kTextMuted;
}
UIShortcutContext BuildShortcutContext() const {
UIShortcutContext context = {};
const auto panelOwnerId = ResolveCurrentPanelOwnerId(m_controller.GetWorkspace().activePanelId);
context.commandScope.path = { kWindowOwnerId, panelOwnerId };
context.commandScope.windowId = kWindowOwnerId;
context.commandScope.panelId = panelOwnerId;
context.textInputActive = m_textInputActive;
return context;
}
void HandleClick(float x, float y) {
for (const ButtonState& button : m_buttons) {
if (!ContainsPoint(button.rect, x, y)) {
continue;
}
if (button.action == ActionId::ToggleTextInput) {
m_textInputActive = !m_textInputActive;
m_lastAction = "Toggle Text Input";
m_lastShortcutStatus = "Changed";
m_lastCommandStatus = "(none)";
m_lastMessage = m_textInputActive
? "text input active = true。现在按 Ctrl+H / Ctrl+PShortcut result 应为 Suppressed。"
: "text input active = false。快捷键恢复正常 dispatch。";
m_lastShortcutColor = kSuccess;
m_lastCommandColor = kTextMuted;
} else {
ResetScenario();
}
InvalidateRect(m_hwnd, nullptr, FALSE);
return;
}
}
void HandleKey(UIInputEventType type, WPARAM wParam, LPARAM lParam) {
UIInputEvent event = {};
event.type = type;
event.keyCode = MapVirtualKeyToUIKeyCode(wParam);
event.modifiers = m_inputModifierTracker.ApplyKeyMessage(type, wParam, lParam);
event.repeat = (static_cast<std::uint32_t>(lParam) & 0x40000000u) != 0u;
if (type == UIInputEventType::KeyUp || event.keyCode == static_cast<std::int32_t>(KeyCode::None)) {
return;
}
if (event.keyCode == static_cast<std::int32_t>(KeyCode::T) &&
!event.modifiers.control &&
!event.modifiers.alt &&
!event.modifiers.super) {
m_textInputActive = !m_textInputActive;
m_lastAction = "T";
m_lastShortcutStatus = "Changed";
m_lastCommandStatus = "(none)";
m_lastMessage = m_textInputActive
? "text input active = true。下一次 Ctrl 快捷键应被 Suppressed。"
: "text input active = false。下一次 Ctrl 快捷键应正常 dispatch。";
m_lastShortcutColor = kSuccess;
m_lastCommandColor = kTextMuted;
InvalidateRect(m_hwnd, nullptr, FALSE);
return;
}
if (event.keyCode == static_cast<std::int32_t>(KeyCode::LeftCtrl)) {
return;
}
const UIEditorShortcutDispatchResult result =
m_shortcutManager.Dispatch(event, BuildShortcutContext(), m_controller);
m_lastAction = DescribeKey(event.keyCode);
m_lastShortcutStatus = std::string(GetUIEditorShortcutDispatchStatusName(result.status));
m_lastShortcutColor = ResolveShortcutStatusColor(result.status);
if (result.commandExecuted) {
m_lastCommandStatus = std::string(GetUIEditorWorkspaceCommandStatusName(result.commandResult.status));
m_lastCommandColor = ResolveCommandStatusColor(m_controller, result);
m_lastMessage = result.message + " | " + result.commandDisplayName + " -> " + result.commandResult.message;
} else {
m_lastCommandStatus = "(none)";
m_lastCommandColor = kTextMuted;
m_lastMessage = result.message;
}
InvalidateRect(m_hwnd, nullptr, FALSE);
}
std::string DescribeKey(std::int32_t keyCode) const {
if (keyCode == static_cast<std::int32_t>(KeyCode::H)) return "Ctrl+H";
if (keyCode == static_cast<std::int32_t>(KeyCode::O)) return "Ctrl+O";
if (keyCode == static_cast<std::int32_t>(KeyCode::P)) return "Ctrl+P";
if (keyCode == static_cast<std::int32_t>(KeyCode::R)) return "Ctrl+R";
if (keyCode == static_cast<std::int32_t>(KeyCode::W)) return "Ctrl+W";
return "Key";
}
void RenderFrame() {
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));
const auto validation = m_controller.ValidateState();
const auto shortcutValidation = m_shortcutManager.ValidateConfiguration();
const auto shortcutContext = BuildShortcutContext();
UIDrawData drawData = {};
UIDrawList& drawList = drawData.EmplaceDrawList("Shortcut Dispatch");
drawList.AddFilledRect(UIRect(0.0f, 0.0f, width, height), kWindowBg);
const float margin = 20.0f;
const UIRect headerRect(margin, margin, width - margin * 2.0f, 178.0f);
const UIRect leftRect(margin, headerRect.y + headerRect.height + 16.0f, 320.0f, height - 254.0f);
const UIRect rightRect(leftRect.x + leftRect.width + 16.0f, leftRect.y, width - leftRect.width - margin * 2.0f - 16.0f, height - 254.0f);
const UIRect footerRect(margin, height - 100.0f, width - margin * 2.0f, 80.0f);
DrawCard(drawList, headerRect, "测试功能Editor Shortcut Dispatch", "只验证 shortcut match -> editor command -> workspace command dispatch。");
drawList.AddText(UIPoint(headerRect.x + 18.0f, headerRect.y + 70.0f), "1. 初始 active=doc-a按 Ctrl+P当前 documents scope 应命中 Activate Details。", kTextPrimary, 13.0f);
drawList.AddText(UIPoint(headerRect.x + 18.0f, headerRect.y + 92.0f), "2. active=details 后再按 Ctrl+P同一个 chord 应命中另一条 panel binding并执行 Reset。", kTextPrimary, 13.0f);
drawList.AddText(UIPoint(headerRect.x + 18.0f, headerRect.y + 114.0f), "3. 按 Ctrl+H验证 ActivePanel 参数源;按 Ctrl+W / Ctrl+O验证固定 panel 命令。", kTextPrimary, 13.0f);
drawList.AddText(UIPoint(headerRect.x + 18.0f, headerRect.y + 136.0f), "4. 点 Toggle Text Input 或按 T再按 Ctrl+H / Ctrl+PShortcut result 必须变成 Suppressed。", kTextPrimary, 13.0f);
drawList.AddText(UIPoint(headerRect.x + 18.0f, headerRect.y + 158.0f), "5. F12 保存截图。注意看 Footer 里 Shortcut result 和 Command result 是两层状态。", kTextPrimary, 13.0f);
DrawCard(drawList, leftRect, "操作区", "这里只放辅助按钮;真正的验证入口是键盘快捷键。");
DrawCard(drawList, rightRect, "状态摘要", "看当前 scope、text input、workspace 状态和 bindings。");
DrawCard(drawList, footerRect, "最近结果", "Shortcut result 不等于 Command result。");
m_buttons = {
{ ActionId::ToggleTextInput, m_textInputActive ? "Toggle Text Input: On" : "Toggle Text Input: Off", UIRect(leftRect.x + 18.0f, leftRect.y + 74.0f, leftRect.width - 36.0f, 46.0f) },
{ ActionId::ResetScenario, "Reset Scenario", UIRect(leftRect.x + 18.0f, leftRect.y + 132.0f, leftRect.width - 36.0f, 46.0f) }
};
for (const ButtonState& button : m_buttons) {
drawList.AddFilledRect(button.rect, kCardBorder, 8.0f);
drawList.AddRectOutline(button.rect, kTextMuted, 1.0f, 8.0f);
drawList.AddText(UIPoint(button.rect.x + 14.0f, button.rect.y + 13.0f), button.label, kTextPrimary, 13.0f);
}
drawList.AddText(UIPoint(leftRect.x + 18.0f, leftRect.y + 210.0f), "Bindings", kAccent, 15.0f);
drawList.AddText(UIPoint(leftRect.x + 18.0f, leftRect.y + 236.0f), "Ctrl+P documents -> Activate Details", kTextPrimary, 12.0f);
drawList.AddText(UIPoint(leftRect.x + 18.0f, leftRect.y + 256.0f), "Ctrl+P details -> Reset Workspace", kTextPrimary, 12.0f);
drawList.AddText(UIPoint(leftRect.x + 18.0f, leftRect.y + 276.0f), "Ctrl+H global -> Hide Active", kTextPrimary, 12.0f);
drawList.AddText(UIPoint(leftRect.x + 18.0f, leftRect.y + 296.0f), "Ctrl+W global -> Close Doc B", kTextPrimary, 12.0f);
drawList.AddText(UIPoint(leftRect.x + 18.0f, leftRect.y + 316.0f), "Ctrl+O global -> Open Doc B", kTextPrimary, 12.0f);
drawList.AddText(UIPoint(leftRect.x + 18.0f, leftRect.y + 336.0f), "Ctrl+R global -> Reset Workspace", kTextPrimary, 12.0f);
drawList.AddText(UIPoint(rightRect.x + 18.0f, rightRect.y + 74.0f), "Active panel: " + m_controller.GetWorkspace().activePanelId, kTextPrimary, 14.0f);
drawList.AddText(UIPoint(rightRect.x + 18.0f, rightRect.y + 98.0f), "Visible panels: " + JoinVisiblePanels(m_controller), kTextPrimary, 13.0f);
drawList.AddText(UIPoint(rightRect.x + 18.0f, rightRect.y + 122.0f), "Current panel scope: " + DescribeCurrentScope(m_controller.GetWorkspace().activePanelId), kTextPrimary, 13.0f);
drawList.AddText(UIPoint(rightRect.x + 18.0f, rightRect.y + 146.0f), "Panel owner id: " + std::to_string(shortcutContext.commandScope.panelId), kTextPrimary, 13.0f);
drawList.AddText(UIPoint(rightRect.x + 18.0f, rightRect.y + 170.0f), std::string("Text input active: ") + (m_textInputActive ? "true" : "false"), m_textInputActive ? kWarning : kSuccess, 13.0f);
drawList.AddText(UIPoint(rightRect.x + 18.0f, rightRect.y + 194.0f), validation.IsValid() ? "Workspace validation: OK" : "Workspace validation: " + validation.message, validation.IsValid() ? kSuccess : kDanger, 12.0f);
drawList.AddText(UIPoint(rightRect.x + 18.0f, rightRect.y + 216.0f), shortcutValidation.IsValid() ? "Shortcut manager validation: OK" : "Shortcut manager validation: " + shortcutValidation.message, shortcutValidation.IsValid() ? kSuccess : kDanger, 12.0f);
const std::vector<std::pair<std::string, std::string>> panelDefs = {
{ "doc-a", "Document A" },
{ "doc-b", "Document B" },
{ "details", "Details" }
};
float rowY = rightRect.y + 260.0f;
for (const auto& [panelId, label] : panelDefs) {
const auto* state = FindUIEditorPanelSessionState(m_controller.GetSession(), panelId);
std::string stateText = state == nullptr
? "missing"
: (!state->open ? "closed" : (!state->visible ? "hidden" : "visible"));
drawList.AddText(
UIPoint(rightRect.x + 18.0f, rowY),
label + ": " + stateText + (m_controller.GetWorkspace().activePanelId == panelId ? " | active" : ""),
ResolveCurrentPanelOwnerId(panelId) == shortcutContext.commandScope.panelId && panelId == "details"
? kAccent
: (ResolveCurrentPanelOwnerId(panelId) == shortcutContext.commandScope.panelId && panelId != "details" ? kAccent : kTextPrimary),
13.0f);
rowY += 22.0f;
}
drawList.AddText(UIPoint(footerRect.x + 18.0f, footerRect.y + 20.0f), "Last action: " + m_lastAction, kTextPrimary, 13.0f);
drawList.AddText(UIPoint(footerRect.x + 18.0f, footerRect.y + 40.0f), "Shortcut result: " + m_lastShortcutStatus, m_lastShortcutColor, 12.0f);
drawList.AddText(UIPoint(footerRect.x + 260.0f, footerRect.y + 40.0f), "Command result: " + m_lastCommandStatus, m_lastCommandColor, 12.0f);
drawList.AddText(UIPoint(footerRect.x + 18.0f, footerRect.y + 60.0f), m_lastMessage, kTextPrimary, 12.0f);
const std::string captureSummary =
m_autoScreenshot.HasPendingCapture()
? "截图排队中..."
: (m_autoScreenshot.GetLastCaptureSummary().empty()
? std::string("F12 -> tests/UI/Editor/integration/state/shortcut_dispatch/captures/")
: m_autoScreenshot.GetLastCaptureSummary());
drawList.AddText(UIPoint(footerRect.x + 870.0f, footerRect.y + 60.0f), captureSummary, kTextMuted, 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;
HINSTANCE m_hInstance = nullptr;
ATOM m_windowClassAtom = 0;
NativeRenderer m_renderer = {};
AutoScreenshotController m_autoScreenshot = {};
InputModifierTracker m_inputModifierTracker = {};
UIEditorWorkspaceController m_controller = {};
UIEditorShortcutManager m_shortcutManager = {};
bool m_textInputActive = false;
std::vector<ButtonState> m_buttons = {};
std::string m_lastAction = {};
std::string m_lastShortcutStatus = {};
std::string m_lastCommandStatus = {};
std::string m_lastMessage = {};
UIColor m_lastShortcutColor = kTextMuted;
UIColor m_lastCommandColor = kTextMuted;
};
} // namespace
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, LPWSTR, int nCmdShow) {
ScenarioApp app;
return app.Run(hInstance, nCmdShow);
}