new_editor: close editor-layer app boundary
This commit is contained in:
129
new_editor/src/Workspace/UIEditorDetachedWindowPolicy.cpp
Normal file
129
new_editor/src/Workspace/UIEditorDetachedWindowPolicy.cpp
Normal file
@@ -0,0 +1,129 @@
|
||||
#include <XCEditor/Workspace/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;
|
||||
}
|
||||
|
||||
bool IsUIEditorDetachedWorkspaceToolWindow(
|
||||
const UIEditorWorkspaceController& controller) {
|
||||
if (const UIEditorPanelDescriptor* descriptor =
|
||||
ResolveUIEditorSingleVisibleRootPanelDescriptor(controller);
|
||||
descriptor != nullptr) {
|
||||
return descriptor->toolWindow;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
::XCEngine::UI::UISize ResolveUIEditorDetachedToolWindowMinimumContentSize(
|
||||
const UIEditorWorkspaceController& controller,
|
||||
const ::XCEngine::UI::UISize& fallbackContentSize,
|
||||
float detachedWindowChromeHeight) {
|
||||
if (const UIEditorPanelDescriptor* descriptor =
|
||||
ResolveUIEditorSingleVisibleRootPanelDescriptor(controller);
|
||||
descriptor != nullptr && descriptor->toolWindow) {
|
||||
const float minimumContentWidth =
|
||||
descriptor->minimumDetachedWindowSize.width > 0.0f
|
||||
? descriptor->minimumDetachedWindowSize.width
|
||||
: fallbackContentSize.width;
|
||||
const float minimumContentHeight =
|
||||
descriptor->minimumDetachedWindowSize.height > detachedWindowChromeHeight
|
||||
? descriptor->minimumDetachedWindowSize.height - detachedWindowChromeHeight
|
||||
: fallbackContentSize.height;
|
||||
return ::XCEngine::UI::UISize(minimumContentWidth, minimumContentHeight);
|
||||
}
|
||||
|
||||
return fallbackContentSize;
|
||||
}
|
||||
|
||||
::XCEngine::UI::UISize ResolveUIEditorDetachedPanelPreferredWindowSize(
|
||||
const UIEditorPanelRegistry& panelRegistry,
|
||||
std::string_view panelId,
|
||||
const ::XCEngine::UI::UISize& fallbackSize) {
|
||||
const UIEditorPanelDescriptor* descriptor =
|
||||
FindUIEditorPanelDescriptor(panelRegistry, panelId);
|
||||
if (descriptor == nullptr ||
|
||||
descriptor->preferredDetachedWindowSize.width <= 0.0f ||
|
||||
descriptor->preferredDetachedWindowSize.height <= 0.0f) {
|
||||
return fallbackSize;
|
||||
}
|
||||
|
||||
return descriptor->preferredDetachedWindowSize;
|
||||
}
|
||||
|
||||
} // namespace XCEngine::UI::Editor
|
||||
Reference in New Issue
Block a user