Contain XCUI ImGui adapters behind explicit host seams

This commit is contained in:
2026-04-05 13:24:14 +08:00
parent 56f596548d
commit f943a07862
23 changed files with 1134 additions and 290 deletions

View File

@@ -10,6 +10,17 @@ constexpr std::size_t ToIndex(XCUIShellPanelId panelId) {
return static_cast<std::size_t>(panelId);
}
constexpr std::string_view kViewMenuLabel = "View";
constexpr std::string_view kXCUIDemoShortcut = "Ctrl+1";
constexpr std::string_view kXCUILayoutLabShortcut = "Ctrl+2";
constexpr std::string_view kImGuiDemoShortcut = "Ctrl+3";
constexpr std::string_view kNativeBackdropShortcut = "Ctrl+Shift+B";
constexpr std::string_view kPulseAccentShortcut = "Ctrl+Shift+P";
constexpr std::string_view kNativeXCUIOverlayShortcut = "Ctrl+Shift+O";
constexpr std::string_view kHostedPreviewHudShortcut = "Ctrl+Shift+H";
constexpr std::string_view kNativeDemoPanelPreviewShortcut = "Ctrl+Alt+1";
constexpr std::string_view kNativeLayoutLabPreviewShortcut = "Ctrl+Alt+2";
} // namespace
XCUIShellChromeState::XCUIShellChromeState() {
@@ -29,7 +40,7 @@ XCUIShellChromeState::XCUIShellChromeState() {
"new_editor.panels.xcui_layout_lab",
true,
true,
XCUIShellHostedPreviewMode::LegacyImGui
XCUIShellHostedPreviewMode::HostedPresenter
};
}
@@ -104,7 +115,7 @@ XCUIShellHostedPreviewMode XCUIShellChromeState::GetHostedPreviewMode(XCUIShellP
const XCUIShellPanelChromeState* panelState = TryGetPanelState(panelId);
return panelState != nullptr
? panelState->previewMode
: XCUIShellHostedPreviewMode::LegacyImGui;
: XCUIShellHostedPreviewMode::HostedPresenter;
}
XCUIShellHostedPreviewState XCUIShellChromeState::GetHostedPreviewState(XCUIShellPanelId panelId) const {
@@ -115,15 +126,15 @@ XCUIShellHostedPreviewState XCUIShellChromeState::GetHostedPreviewState(XCUIShel
return panelState->previewMode == XCUIShellHostedPreviewMode::NativeOffscreen
? XCUIShellHostedPreviewState::NativeOffscreen
: XCUIShellHostedPreviewState::LegacyImGui;
: XCUIShellHostedPreviewState::HostedPresenter;
}
bool XCUIShellChromeState::IsNativeHostedPreviewActive(XCUIShellPanelId panelId) const {
return GetHostedPreviewState(panelId) == XCUIShellHostedPreviewState::NativeOffscreen;
}
bool XCUIShellChromeState::IsLegacyHostedPreviewActive(XCUIShellPanelId panelId) const {
return GetHostedPreviewState(panelId) == XCUIShellHostedPreviewState::LegacyImGui;
bool XCUIShellChromeState::IsHostedPresenterPreviewActive(XCUIShellPanelId panelId) const {
return GetHostedPreviewState(panelId) == XCUIShellHostedPreviewState::HostedPresenter;
}
bool XCUIShellChromeState::SetHostedPreviewMode(
@@ -146,7 +157,7 @@ bool XCUIShellChromeState::ToggleHostedPreviewMode(XCUIShellPanelId panelId) {
panelState->previewMode =
panelState->previewMode == XCUIShellHostedPreviewMode::NativeOffscreen
? XCUIShellHostedPreviewMode::LegacyImGui
? XCUIShellHostedPreviewMode::HostedPresenter
: XCUIShellHostedPreviewMode::NativeOffscreen;
return true;
}
@@ -205,15 +216,8 @@ bool XCUIShellChromeState::ToggleViewToggle(XCUIShellViewToggleId toggleId) {
}
bool XCUIShellChromeState::HasCommand(std::string_view commandId) const {
return commandId == GetPanelVisibilityCommandId(XCUIShellPanelId::XCUIDemo) ||
commandId == GetPanelVisibilityCommandId(XCUIShellPanelId::XCUILayoutLab) ||
commandId == GetViewToggleCommandId(XCUIShellViewToggleId::ImGuiDemoWindow) ||
commandId == GetViewToggleCommandId(XCUIShellViewToggleId::NativeBackdrop) ||
commandId == GetViewToggleCommandId(XCUIShellViewToggleId::PulseAccent) ||
commandId == GetViewToggleCommandId(XCUIShellViewToggleId::NativeXCUIOverlay) ||
commandId == GetViewToggleCommandId(XCUIShellViewToggleId::HostedPreviewHud) ||
commandId == GetPanelPreviewModeCommandId(XCUIShellPanelId::XCUIDemo) ||
commandId == GetPanelPreviewModeCommandId(XCUIShellPanelId::XCUILayoutLab);
XCUIShellCommandDescriptor descriptor = {};
return TryGetCommandDescriptor(commandId, descriptor);
}
bool XCUIShellChromeState::InvokeCommand(std::string_view commandId) {
@@ -248,6 +252,142 @@ bool XCUIShellChromeState::InvokeCommand(std::string_view commandId) {
return false;
}
bool XCUIShellChromeState::TryGetCommandDescriptor(
std::string_view commandId,
XCUIShellCommandDescriptor& outDescriptor) const {
outDescriptor = {};
outDescriptor.checkable = false;
outDescriptor.enabled = false;
const auto tryBuildPanelVisibilityDescriptor =
[this, commandId, &outDescriptor](
XCUIShellPanelId panelId,
std::string_view shortcut) {
if (commandId != GetPanelVisibilityCommandId(panelId)) {
return false;
}
const XCUIShellPanelChromeState* panelState = TryGetPanelState(panelId);
if (panelState == nullptr) {
return false;
}
outDescriptor.label = panelState->panelTitle;
outDescriptor.shortcut = shortcut;
outDescriptor.commandId = commandId;
outDescriptor.checkable = true;
outDescriptor.checked = panelState->visible;
outDescriptor.enabled = true;
return true;
};
if (tryBuildPanelVisibilityDescriptor(XCUIShellPanelId::XCUIDemo, kXCUIDemoShortcut)) {
return true;
}
if (tryBuildPanelVisibilityDescriptor(XCUIShellPanelId::XCUILayoutLab, kXCUILayoutLabShortcut)) {
return true;
}
if (commandId == GetViewToggleCommandId(XCUIShellViewToggleId::ImGuiDemoWindow)) {
outDescriptor.label = "ImGui Demo";
outDescriptor.shortcut = kImGuiDemoShortcut;
outDescriptor.commandId = commandId;
outDescriptor.checkable = true;
outDescriptor.checked = GetViewToggle(XCUIShellViewToggleId::ImGuiDemoWindow);
outDescriptor.enabled = true;
return true;
}
if (commandId == GetViewToggleCommandId(XCUIShellViewToggleId::NativeBackdrop)) {
outDescriptor.label = "Native Backdrop";
outDescriptor.shortcut = kNativeBackdropShortcut;
outDescriptor.commandId = commandId;
outDescriptor.checkable = true;
outDescriptor.checked = GetViewToggle(XCUIShellViewToggleId::NativeBackdrop);
outDescriptor.enabled = true;
return true;
}
if (commandId == GetViewToggleCommandId(XCUIShellViewToggleId::PulseAccent)) {
outDescriptor.label = "Pulse Accent";
outDescriptor.shortcut = kPulseAccentShortcut;
outDescriptor.commandId = commandId;
outDescriptor.checkable = true;
outDescriptor.checked = GetViewToggle(XCUIShellViewToggleId::PulseAccent);
outDescriptor.enabled = true;
return true;
}
if (commandId == GetViewToggleCommandId(XCUIShellViewToggleId::NativeXCUIOverlay)) {
outDescriptor.label = "Native XCUI Overlay";
outDescriptor.shortcut = kNativeXCUIOverlayShortcut;
outDescriptor.commandId = commandId;
outDescriptor.checkable = true;
outDescriptor.checked = GetViewToggle(XCUIShellViewToggleId::NativeXCUIOverlay);
outDescriptor.enabled = true;
return true;
}
if (commandId == GetViewToggleCommandId(XCUIShellViewToggleId::HostedPreviewHud)) {
outDescriptor.label = "Hosted Preview HUD";
outDescriptor.shortcut = kHostedPreviewHudShortcut;
outDescriptor.commandId = commandId;
outDescriptor.checkable = true;
outDescriptor.checked = GetViewToggle(XCUIShellViewToggleId::HostedPreviewHud);
outDescriptor.enabled = true;
return true;
}
if (commandId == GetPanelPreviewModeCommandId(XCUIShellPanelId::XCUIDemo)) {
outDescriptor.label = "Native Demo Panel Preview";
outDescriptor.shortcut = kNativeDemoPanelPreviewShortcut;
outDescriptor.commandId = commandId;
outDescriptor.checkable = true;
outDescriptor.checked = IsNativeHostedPreviewActive(XCUIShellPanelId::XCUIDemo);
outDescriptor.enabled = true;
return true;
}
if (commandId == GetPanelPreviewModeCommandId(XCUIShellPanelId::XCUILayoutLab)) {
outDescriptor.label = "Native Layout Lab Preview";
outDescriptor.shortcut = kNativeLayoutLabPreviewShortcut;
outDescriptor.commandId = commandId;
outDescriptor.checkable = true;
outDescriptor.checked = IsNativeHostedPreviewActive(XCUIShellPanelId::XCUILayoutLab);
outDescriptor.enabled = true;
return true;
}
return false;
}
XCUIShellMenuDescriptor XCUIShellChromeState::BuildViewMenuDescriptor() const {
XCUIShellMenuDescriptor descriptor = {};
descriptor.label = kViewMenuLabel;
descriptor.items.reserve(10u);
const auto appendCommandItem = [this, &descriptor](std::string_view commandId) {
XCUIShellCommandDescriptor commandDescriptor = {};
if (!TryGetCommandDescriptor(commandId, commandDescriptor)) {
return;
}
XCUIShellMenuItemDescriptor item = {};
item.kind = XCUIShellMenuItemKind::Command;
item.command = commandDescriptor;
descriptor.items.push_back(item);
};
appendCommandItem(GetPanelVisibilityCommandId(XCUIShellPanelId::XCUIDemo));
appendCommandItem(GetPanelVisibilityCommandId(XCUIShellPanelId::XCUILayoutLab));
appendCommandItem(GetViewToggleCommandId(XCUIShellViewToggleId::ImGuiDemoWindow));
descriptor.items.push_back({ XCUIShellMenuItemKind::Separator, {} });
appendCommandItem(GetViewToggleCommandId(XCUIShellViewToggleId::NativeBackdrop));
appendCommandItem(GetViewToggleCommandId(XCUIShellViewToggleId::PulseAccent));
appendCommandItem(GetViewToggleCommandId(XCUIShellViewToggleId::NativeXCUIOverlay));
appendCommandItem(GetViewToggleCommandId(XCUIShellViewToggleId::HostedPreviewHud));
appendCommandItem(GetPanelPreviewModeCommandId(XCUIShellPanelId::XCUIDemo));
appendCommandItem(GetPanelPreviewModeCommandId(XCUIShellPanelId::XCUILayoutLab));
return descriptor;
}
std::string_view XCUIShellChromeState::GetPanelVisibilityCommandId(XCUIShellPanelId panelId) {
switch (panelId) {
case XCUIShellPanelId::XCUIDemo: