refactor(new_editor): snapshot hosted editor restructuring
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
#include "Platform/Win32/EditorWindowChromeController.h"
|
||||
|
||||
#include "Platform/Win32/EditorWindow.h"
|
||||
#include "Platform/Win32/EditorWindowConstants.h"
|
||||
#include "Platform/Win32/EditorWindowInternalState.h"
|
||||
#include "Platform/Win32/EditorWindowRuntimeController.h"
|
||||
#include "Platform/Win32/EditorWindowStyle.h"
|
||||
#include "Platform/Win32/EditorWindowState.h"
|
||||
#include "Platform/Win32/EditorWindowSupport.h"
|
||||
|
||||
#include <XCEditor/Foundation/UIEditorTheme.h>
|
||||
#include <XCEditor/Panels/UIEditorPanelRegistry.h>
|
||||
@@ -17,9 +16,9 @@
|
||||
|
||||
#include <windowsx.h>
|
||||
|
||||
namespace XCEngine::UI::Editor::App::Internal {
|
||||
namespace XCEngine::UI::Editor::App {
|
||||
|
||||
using namespace EditorWindowInternal;
|
||||
using namespace EditorWindowSupport;
|
||||
using ::XCEngine::UI::Layout::MeasureUITabStripHeaderWidth;
|
||||
using ::XCEngine::UI::UIColor;
|
||||
using ::XCEngine::UI::UIDrawList;
|
||||
@@ -31,6 +30,15 @@ namespace {
|
||||
constexpr float kTitleBarLogoExtent = 16.0f;
|
||||
constexpr float kTitleBarLogoInsetLeft = 8.0f;
|
||||
constexpr float kTitleBarLogoTextGap = 8.0f;
|
||||
constexpr float kTitleBarFrameStatsInsetRight = 12.0f;
|
||||
|
||||
bool IsRootPanelVisible(
|
||||
const UIEditorWorkspaceController& controller,
|
||||
std::string_view panelId) {
|
||||
const UIEditorPanelSessionState* panelState =
|
||||
FindUIEditorPanelSessionState(controller.GetSession(), panelId);
|
||||
return panelState != nullptr && panelState->open && panelState->visible;
|
||||
}
|
||||
|
||||
std::string ResolveDetachedTitleTabText(const EditorWindow& window) {
|
||||
const auto& workspaceController = window.GetWorkspaceController();
|
||||
@@ -49,6 +57,61 @@ std::string ResolveDetachedTitleTabText(const EditorWindow& window) {
|
||||
return std::string("Panel");
|
||||
}
|
||||
|
||||
const UIEditorPanelDescriptor* ResolveSingleVisibleRootPanelDescriptor(
|
||||
const EditorWindow& window) {
|
||||
const UIEditorWorkspaceController& workspaceController = window.GetWorkspaceController();
|
||||
const UIEditorWorkspaceNode& root = workspaceController.GetWorkspace().root;
|
||||
if (root.kind != UIEditorWorkspaceNodeKind::TabStack) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const UIEditorPanelRegistry& panelRegistry = workspaceController.GetPanelRegistry();
|
||||
const UIEditorPanelDescriptor* visibleDescriptor = nullptr;
|
||||
std::size_t visibleCount = 0u;
|
||||
for (const UIEditorWorkspaceNode& child : root.children) {
|
||||
if (child.kind != UIEditorWorkspaceNodeKind::Panel ||
|
||||
!IsRootPanelVisible(workspaceController, 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 IsToolWindow(const EditorWindow& window) {
|
||||
if (window.IsPrimary()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const UIEditorPanelDescriptor* descriptor =
|
||||
ResolveSingleVisibleRootPanelDescriptor(window);
|
||||
return descriptor != nullptr && descriptor->toolWindow;
|
||||
}
|
||||
|
||||
::XCEngine::UI::UISize ResolveMinimumOuterSize(const EditorWindow& window) {
|
||||
if (const UIEditorPanelDescriptor* descriptor =
|
||||
ResolveSingleVisibleRootPanelDescriptor(window);
|
||||
descriptor != nullptr &&
|
||||
descriptor->minimumDetachedWindowSize.width > 0.0f &&
|
||||
descriptor->minimumDetachedWindowSize.height > 0.0f) {
|
||||
return descriptor->minimumDetachedWindowSize;
|
||||
}
|
||||
|
||||
return ::XCEngine::UI::UISize(640.0f, 360.0f);
|
||||
}
|
||||
|
||||
float ResolveDetachedTabWidth(std::string_view text) {
|
||||
const Widgets::UIEditorTabStripMetrics& metrics = ResolveUIEditorTabStripMetrics();
|
||||
Widgets::UIEditorTabStripItem item = {};
|
||||
@@ -58,14 +121,6 @@ float ResolveDetachedTabWidth(std::string_view text) {
|
||||
return MeasureUITabStripHeaderWidth(desiredLabelWidth, metrics.layoutMetrics);
|
||||
}
|
||||
|
||||
bool IsRootPanelVisible(
|
||||
const UIEditorWorkspaceController& controller,
|
||||
std::string_view panelId) {
|
||||
const UIEditorPanelSessionState* panelState =
|
||||
FindUIEditorPanelSessionState(controller.GetSession(), panelId);
|
||||
return panelState != nullptr && panelState->open && panelState->visible;
|
||||
}
|
||||
|
||||
bool HasSingleVisibleRootTab(const UIEditorWorkspaceController& controller) {
|
||||
const UIEditorWorkspaceNode& root = controller.GetWorkspace().root;
|
||||
if (root.kind != UIEditorWorkspaceNodeKind::TabStack) {
|
||||
@@ -272,7 +327,12 @@ bool EditorWindowChromeController::HandleSystemCommand(
|
||||
bool EditorWindowChromeController::HandleGetMinMaxInfo(
|
||||
const EditorWindow& window,
|
||||
LPARAM lParam) const {
|
||||
return Host::HandleBorderlessWindowGetMinMaxInfo(window.m_state->window.hwnd, lParam);
|
||||
const ::XCEngine::UI::UISize minimumOuterSize = ResolveMinimumOuterSize(window);
|
||||
return Host::HandleBorderlessWindowGetMinMaxInfo(
|
||||
window.m_state->window.hwnd,
|
||||
lParam,
|
||||
static_cast<int>(minimumOuterSize.width),
|
||||
static_cast<int>(minimumOuterSize.height));
|
||||
}
|
||||
|
||||
LRESULT EditorWindowChromeController::HandleNcCalcSize(
|
||||
@@ -345,13 +405,14 @@ bool EditorWindowChromeController::HandleResizePointerMove(
|
||||
return false;
|
||||
}
|
||||
|
||||
const ::XCEngine::UI::UISize minimumOuterSize = ResolveMinimumOuterSize(window);
|
||||
RECT targetRect = Host::ComputeBorderlessWindowResizeRect(
|
||||
GetBorderlessResizeInitialWindowRect(),
|
||||
GetBorderlessResizeInitialScreenPoint(),
|
||||
currentScreenPoint,
|
||||
GetBorderlessResizeEdge(),
|
||||
640,
|
||||
360);
|
||||
static_cast<int>(minimumOuterSize.width),
|
||||
static_cast<int>(minimumOuterSize.height));
|
||||
const int width = targetRect.right - targetRect.left;
|
||||
const int height = targetRect.bottom - targetRect.top;
|
||||
if (width <= 0 || height <= 0) {
|
||||
@@ -660,6 +721,7 @@ Host::BorderlessWindowChromeLayout EditorWindowChromeController::ResolveChromeLa
|
||||
bool EditorWindowChromeController::ShouldUseDetachedTitleBarTabStrip(
|
||||
const EditorWindow& window) const {
|
||||
return !window.m_state->window.primary &&
|
||||
!IsToolWindow(window) &&
|
||||
HasSingleVisibleRootTab(window.m_runtime->GetWorkspaceController());
|
||||
}
|
||||
|
||||
@@ -686,11 +748,43 @@ void EditorWindowChromeController::AppendChrome(
|
||||
}
|
||||
|
||||
if (!window.m_state->window.primary) {
|
||||
if (window.m_runtime->GetTitleBarLogoIcon().IsValid()) {
|
||||
drawList.AddImage(
|
||||
BuildDetachedTitleLogoRect(layout),
|
||||
window.m_runtime->GetTitleBarLogoIcon(),
|
||||
UIColor(1.0f, 1.0f, 1.0f, 1.0f));
|
||||
if (useDetachedTitleBarTabStrip) {
|
||||
if (window.m_runtime->GetTitleBarLogoIcon().IsValid()) {
|
||||
drawList.AddImage(
|
||||
BuildDetachedTitleLogoRect(layout),
|
||||
window.m_runtime->GetTitleBarLogoIcon(),
|
||||
UIColor(1.0f, 1.0f, 1.0f, 1.0f));
|
||||
}
|
||||
} else {
|
||||
const float iconX = layout.titleBarRect.x + kTitleBarLogoInsetLeft;
|
||||
const float iconY =
|
||||
layout.titleBarRect.y +
|
||||
(std::max)(0.0f, (layout.titleBarRect.height - kTitleBarLogoExtent) * 0.5f);
|
||||
if (window.m_runtime->GetTitleBarLogoIcon().IsValid()) {
|
||||
drawList.AddImage(
|
||||
UIRect(iconX, iconY, kTitleBarLogoExtent, kTitleBarLogoExtent),
|
||||
window.m_runtime->GetTitleBarLogoIcon(),
|
||||
UIColor(1.0f, 1.0f, 1.0f, 1.0f));
|
||||
}
|
||||
|
||||
drawList.AddText(
|
||||
UIPoint(
|
||||
iconX +
|
||||
(window.m_runtime->GetTitleBarLogoIcon().IsValid()
|
||||
? (kTitleBarLogoExtent + kTitleBarLogoTextGap)
|
||||
: 4.0f),
|
||||
layout.titleBarRect.y +
|
||||
(std::max)(
|
||||
0.0f,
|
||||
(layout.titleBarRect.height - kBorderlessTitleBarFontSize) * 0.5f -
|
||||
1.0f)),
|
||||
IsToolWindow(window)
|
||||
? ResolveDetachedTitleTabText(window)
|
||||
: (window.m_state->window.titleText.empty()
|
||||
? std::string("XCEngine Editor")
|
||||
: window.m_state->window.titleText),
|
||||
kShellTextColor,
|
||||
kBorderlessTitleBarFontSize);
|
||||
}
|
||||
} else {
|
||||
const float iconX = layout.titleBarRect.x + kTitleBarLogoInsetLeft;
|
||||
@@ -708,6 +802,7 @@ void EditorWindowChromeController::AppendChrome(
|
||||
window.m_state->window.titleText.empty()
|
||||
? std::string("XCEngine Editor")
|
||||
: window.m_state->window.titleText;
|
||||
const std::string frameRateText = window.m_runtime->BuildFrameRateText();
|
||||
drawList.AddText(
|
||||
UIPoint(
|
||||
iconX +
|
||||
@@ -716,11 +811,32 @@ void EditorWindowChromeController::AppendChrome(
|
||||
: 4.0f),
|
||||
layout.titleBarRect.y +
|
||||
(std::max)(
|
||||
0.0f,
|
||||
(layout.titleBarRect.height - kBorderlessTitleBarFontSize) * 0.5f - 1.0f)),
|
||||
0.0f,
|
||||
(layout.titleBarRect.height - kBorderlessTitleBarFontSize) * 0.5f - 1.0f)),
|
||||
titleText,
|
||||
kShellTextColor,
|
||||
kBorderlessTitleBarFontSize);
|
||||
if (!frameRateText.empty()) {
|
||||
const float frameRateTextWidth =
|
||||
window.m_runtime->GetRenderer().MeasureTextWidth(
|
||||
UIEditorTextMeasureRequest{
|
||||
frameRateText,
|
||||
kBorderlessTitleBarFontSize });
|
||||
const float frameRateX =
|
||||
layout.dragRect.x + layout.dragRect.width -
|
||||
kTitleBarFrameStatsInsetRight - frameRateTextWidth;
|
||||
drawList.AddText(
|
||||
UIPoint(
|
||||
(std::max)(frameRateX, layout.dragRect.x + kTitleBarLogoInsetLeft),
|
||||
layout.titleBarRect.y +
|
||||
(std::max)(
|
||||
0.0f,
|
||||
(layout.titleBarRect.height - kBorderlessTitleBarFontSize) * 0.5f -
|
||||
1.0f)),
|
||||
frameRateText,
|
||||
kShellMutedTextColor,
|
||||
kBorderlessTitleBarFontSize);
|
||||
}
|
||||
}
|
||||
|
||||
Host::AppendBorderlessWindowChrome(
|
||||
@@ -858,4 +974,5 @@ void EditorWindowChromeController::ExecuteChromeAction(
|
||||
window.InvalidateHostWindow();
|
||||
}
|
||||
|
||||
} // namespace XCEngine::UI::Editor::App::Internal
|
||||
} // namespace XCEngine::UI::Editor::App
|
||||
|
||||
|
||||
Reference in New Issue
Block a user