refactor(new_editor): extract window content boundary

This commit is contained in:
2026-04-22 20:32:56 +08:00
parent 6efbaf450e
commit e251b77d0d
19 changed files with 1223 additions and 234 deletions

View File

@@ -5,10 +5,13 @@
#include "Platform/Win32/EditorWindowSupport.h"
#include "Support/EmbeddedPngLoader.h"
#include <XCEditor/Docking/UIEditorDockHostTransfer.h>
#include <algorithm>
#include <cassert>
#include <chrono>
#include <cstdio>
#include <cmath>
#include <cstdio>
#include <utility>
namespace XCEngine::UI::Editor::App {
@@ -24,9 +27,8 @@ constexpr float kFrameStatsDisplayRefreshIntervalSeconds = 0.25f;
}
EditorWindowRuntimeController::EditorWindowRuntimeController(
UIEditorWorkspaceController workspaceController)
: m_workspaceController(std::move(workspaceController)) {
}
std::unique_ptr<EditorWindowContentController> contentController)
: m_contentController(std::move(contentController)) {}
EditorWindowRuntimeController::~EditorWindowRuntimeController() = default;
@@ -34,43 +36,127 @@ bool EditorWindowRuntimeController::IsReady() const {
return m_ready;
}
const UIEditorWorkspaceController* EditorWindowRuntimeController::TryGetWorkspaceController() const {
return m_contentController != nullptr
? m_contentController->TryGetWorkspaceController()
: nullptr;
}
UIEditorWorkspaceController* EditorWindowRuntimeController::TryGetMutableWorkspaceController() {
return m_contentController != nullptr
? m_contentController->TryGetMutableWorkspaceController()
: nullptr;
}
const UIEditorWorkspaceController& EditorWindowRuntimeController::GetWorkspaceController() const {
return m_workspaceController;
const UIEditorWorkspaceController* workspaceController = TryGetWorkspaceController();
assert(workspaceController != nullptr);
return *workspaceController;
}
UIEditorWorkspaceController& EditorWindowRuntimeController::GetMutableWorkspaceController() {
return m_workspaceController;
UIEditorWorkspaceController* workspaceController = TryGetMutableWorkspaceController();
assert(workspaceController != nullptr);
return *workspaceController;
}
void EditorWindowRuntimeController::ReplaceWorkspaceController(
UIEditorWorkspaceController workspaceController) {
m_workspaceController = std::move(workspaceController);
}
const EditorShellRuntime& EditorWindowRuntimeController::GetShellRuntime() const {
return m_shellRuntime;
}
EditorShellRuntime& EditorWindowRuntimeController::GetShellRuntime() {
return m_shellRuntime;
assert(m_contentController != nullptr);
m_contentController->ReplaceWorkspaceController(std::move(workspaceController));
}
const UIEditorShellInteractionFrame& EditorWindowRuntimeController::GetShellFrame() const {
return m_shellRuntime.GetShellFrame();
assert(m_contentController != nullptr);
return m_contentController->GetShellFrame();
}
const UIEditorShellInteractionState& EditorWindowRuntimeController::GetShellInteractionState()
const {
return m_shellRuntime.GetShellInteractionState();
assert(m_contentController != nullptr);
return m_contentController->GetShellInteractionState();
}
void EditorWindowRuntimeController::SetExternalDockHostDropPreview(
const Widgets::UIEditorDockHostDropPreviewState& preview) {
m_shellRuntime.SetExternalDockHostDropPreview(preview);
assert(m_contentController != nullptr);
m_contentController->SetExternalDockHostDropPreview(preview);
}
void EditorWindowRuntimeController::ClearExternalDockHostDropPreview() {
m_shellRuntime.ClearExternalDockHostDropPreview();
if (m_contentController != nullptr) {
m_contentController->ClearExternalDockHostDropPreview();
}
}
bool EditorWindowRuntimeController::TryResolveDockTabDragHotspot(
std::string_view nodeId,
std::string_view panelId,
const ::XCEngine::UI::UIPoint& point,
::XCEngine::UI::UIPoint& outHotspot) const {
return m_contentController != nullptr &&
m_contentController->TryResolveDockTabDragHotspot(
nodeId,
panelId,
point,
outHotspot);
}
UIEditorDockHostTabDropTarget EditorWindowRuntimeController::ResolveDockTabDropTarget(
const ::XCEngine::UI::UIPoint& point) const {
assert(m_contentController != nullptr);
return m_contentController->ResolveDockTabDropTarget(point);
}
bool EditorWindowRuntimeController::HasHostedContentCapture() const {
return m_contentController != nullptr &&
m_contentController->HasHostedContentCapture();
}
bool EditorWindowRuntimeController::HasShellInteractiveCapture() const {
return m_contentController != nullptr &&
m_contentController->HasShellInteractiveCapture();
}
bool EditorWindowRuntimeController::HasInteractiveCapture() const {
return m_contentController != nullptr &&
m_contentController->HasInteractiveCapture();
}
EditorWindowContentCursorKind EditorWindowRuntimeController::GetHostedContentCursorKind() const {
return m_contentController != nullptr
? m_contentController->GetHostedContentCursorKind()
: EditorWindowContentCursorKind::Arrow;
}
EditorWindowContentCursorKind EditorWindowRuntimeController::GetDockCursorKind() const {
return m_contentController != nullptr
? m_contentController->GetDockCursorKind()
: EditorWindowContentCursorKind::Arrow;
}
::XCEngine::UI::UISize EditorWindowRuntimeController::ResolveMinimumOuterSize() const {
assert(m_contentController != nullptr);
return m_contentController->ResolveMinimumOuterSize();
}
bool EditorWindowRuntimeController::ShouldUseDetachedTitleBarTabStrip() const {
return m_contentController != nullptr &&
m_contentController->ShouldUseDetachedTitleBarTabStrip();
}
std::string EditorWindowRuntimeController::ResolveTabStripTitleText(
std::string_view fallbackTitle) const {
return m_contentController != nullptr
? m_contentController->ResolveTabStripTitleText(fallbackTitle)
: std::string(fallbackTitle);
}
std::string EditorWindowRuntimeController::ResolveDetachedWindowTitleText(
std::string_view fallbackWindowTitle) const {
return m_contentController != nullptr
? m_contentController->ResolveDetachedWindowTitleText(fallbackWindowTitle)
: std::string(fallbackWindowTitle);
}
void EditorWindowRuntimeController::SetDpiScale(float dpiScale) {
@@ -142,9 +228,15 @@ bool EditorWindowRuntimeController::Initialize(
}
editorContext.AttachTextMeasurer(m_textSystem);
m_shellRuntime.Initialize(repoRoot, m_textureHost, m_textSystem);
m_shellRuntime.AttachViewportWindowRenderer(m_windowRenderer);
m_shellRuntime.SetViewportSurfacePresentationEnabled(
assert(m_contentController != nullptr);
m_contentController->Initialize(EditorWindowContentInitializationContext{
.repoRoot = repoRoot,
.editorContext = editorContext,
.textureHost = m_textureHost,
.textMeasurer = m_textSystem,
.viewportRenderer = m_windowRenderer,
});
m_contentController->SetViewportSurfacePresentationEnabled(
attachResult.hasViewportSurfacePresentation);
std::string titleBarLogoError = {};
@@ -155,16 +247,19 @@ bool EditorWindowRuntimeController::Initialize(
titleBarLogoError)) {
LogRuntimeTrace("icons", "titlebar logo_icon.png: " + titleBarLogoError);
}
if (!m_shellRuntime.GetBuiltInIconError().empty()) {
LogRuntimeTrace("icons", m_shellRuntime.GetBuiltInIconError());
if (const UIEditorWorkspaceController* workspaceController = TryGetWorkspaceController();
workspaceController != nullptr) {
LogRuntimeTrace(
"app",
"shell runtime initialized: " +
editorContext.DescribeWorkspaceState(
*workspaceController,
m_contentController->GetShellInteractionState()));
} else {
LogRuntimeTrace("app", "window content initialized: non-workspace content");
}
LogRuntimeTrace(
"app",
"shell runtime initialized: " +
editorContext.DescribeWorkspaceState(
m_workspaceController,
m_shellRuntime.GetShellInteractionState()));
ResetFrameTiming();
m_ready = true;
@@ -186,8 +281,10 @@ void EditorWindowRuntimeController::Shutdown() {
"window-close",
"EditorWindowRuntimeController::Shutdown stage=ScreenshotController");
m_screenshotController.Shutdown();
LogRuntimeTrace("window-close", "EditorWindowRuntimeController::Shutdown stage=ShellRuntime");
m_shellRuntime.Shutdown();
LogRuntimeTrace("window-close", "EditorWindowRuntimeController::Shutdown stage=WindowContent");
if (m_contentController != nullptr) {
m_contentController->Shutdown();
}
LogRuntimeTrace("window-close", "EditorWindowRuntimeController::Shutdown stage=RenderLoopDetach");
m_windowRenderLoop.Detach();
LogRuntimeTrace("window-close", "EditorWindowRuntimeController::Shutdown stage=UiRenderer");
@@ -205,7 +302,9 @@ void EditorWindowRuntimeController::Shutdown() {
}
void EditorWindowRuntimeController::ResetInteractionState() {
m_shellRuntime.ResetInteractionState();
if (m_contentController != nullptr) {
m_contentController->ResetInteractionState();
}
ResetFrameTiming();
}
@@ -216,8 +315,10 @@ bool EditorWindowRuntimeController::ApplyResize(UINT width, UINT height) {
const Host::D3D12WindowRenderLoopResizeResult resizeResult =
m_windowRenderLoop.ApplyResize(width, height);
m_shellRuntime.SetViewportSurfacePresentationEnabled(
resizeResult.hasViewportSurfacePresentation);
if (m_contentController != nullptr) {
m_contentController->SetViewportSurfacePresentationEnabled(
resizeResult.hasViewportSurfacePresentation);
}
if (!resizeResult.windowRendererWarning.empty()) {
LogRuntimeTrace("present", resizeResult.windowRendererWarning);
@@ -263,6 +364,20 @@ Host::D3D12WindowRenderLoopPresentResult EditorWindowRuntimeController::Present(
return result;
}
EditorWindowFrameTransferRequests EditorWindowRuntimeController::UpdateAndAppend(
const EditorWindowContentFrameContext& context,
::XCEngine::UI::UIDrawData& drawData) {
assert(m_contentController != nullptr);
return m_contentController->UpdateAndAppend(context, drawData);
}
void EditorWindowRuntimeController::RenderRequestedViewports(
const ::XCEngine::Rendering::RenderContext& renderContext) {
if (m_contentController != nullptr) {
m_contentController->RenderRequestedViewports(renderContext);
}
}
void EditorWindowRuntimeController::RequestManualScreenshot(std::string reason) {
m_screenshotController.RequestCapture(std::move(reason));
}
@@ -352,4 +467,3 @@ void EditorWindowRuntimeController::RefreshDisplayedFrameStats() {
}
} // namespace XCEngine::UI::Editor::App