checkpoint: commit current workspace state
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
#include "UIEditorDetachedWindowPolicy.h"
|
||||
|
||||
namespace XCEngine::UI::Editor {
|
||||
|
||||
namespace {
|
||||
|
||||
bool IsRootPanelVisible(
|
||||
const UIEditorWorkspaceController& controller,
|
||||
std::string_view panelId) {
|
||||
const UIEditorPanelSessionState* panelState =
|
||||
FindUIEditorPanelSessionState(controller.GetSession(), panelId);
|
||||
return panelState != nullptr && panelState->open && panelState->visible;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
const UIEditorPanelDescriptor* ResolveUIEditorSingleVisibleRootPanelDescriptor(
|
||||
const UIEditorWorkspaceController& controller) {
|
||||
const UIEditorWorkspaceNode& root = controller.GetWorkspace().root;
|
||||
if (root.kind != UIEditorWorkspaceNodeKind::TabStack) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const UIEditorPanelRegistry& panelRegistry = controller.GetPanelRegistry();
|
||||
const UIEditorPanelDescriptor* visibleDescriptor = nullptr;
|
||||
std::size_t visibleCount = 0u;
|
||||
for (const UIEditorWorkspaceNode& child : root.children) {
|
||||
if (child.kind != UIEditorWorkspaceNodeKind::Panel ||
|
||||
!IsRootPanelVisible(controller, child.panel.panelId)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const UIEditorPanelDescriptor* descriptor =
|
||||
FindUIEditorPanelDescriptor(panelRegistry, child.panel.panelId);
|
||||
if (descriptor == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
++visibleCount;
|
||||
visibleDescriptor = descriptor;
|
||||
if (visibleCount > 1u) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
return visibleCount == 1u ? visibleDescriptor : nullptr;
|
||||
}
|
||||
|
||||
bool HasUIEditorSingleVisibleRootTab(
|
||||
const UIEditorWorkspaceController& controller) {
|
||||
return ResolveUIEditorSingleVisibleRootPanelDescriptor(controller) != nullptr;
|
||||
}
|
||||
|
||||
std::string ResolveUIEditorDetachedWorkspaceTitle(
|
||||
const UIEditorWorkspaceController& controller,
|
||||
std::string_view fallbackTitle) {
|
||||
const std::string& activePanelId = controller.GetWorkspace().activePanelId;
|
||||
if (const UIEditorPanelDescriptor* descriptor =
|
||||
FindUIEditorPanelDescriptor(controller.GetPanelRegistry(), activePanelId);
|
||||
descriptor != nullptr &&
|
||||
!descriptor->defaultTitle.empty()) {
|
||||
return descriptor->defaultTitle;
|
||||
}
|
||||
|
||||
return std::string(fallbackTitle);
|
||||
}
|
||||
|
||||
::XCEngine::UI::UISize ResolveUIEditorDetachedWorkspaceMinimumOuterSize(
|
||||
const UIEditorWorkspaceController& controller,
|
||||
const ::XCEngine::UI::UISize& fallbackSize) {
|
||||
if (const UIEditorPanelDescriptor* descriptor =
|
||||
ResolveUIEditorSingleVisibleRootPanelDescriptor(controller);
|
||||
descriptor != nullptr &&
|
||||
descriptor->minimumDetachedWindowSize.width > 0.0f &&
|
||||
descriptor->minimumDetachedWindowSize.height > 0.0f) {
|
||||
return descriptor->minimumDetachedWindowSize;
|
||||
}
|
||||
|
||||
return fallbackSize;
|
||||
}
|
||||
|
||||
} // namespace XCEngine::UI::Editor
|
||||
Reference in New Issue
Block a user