From ba6c8eaae52eda55e5180c43bde2a647b143f029 Mon Sep 17 00:00:00 2001 From: ssdfasd <2156608475@qq.com> Date: Sun, 5 Apr 2026 20:46:24 +0800 Subject: [PATCH] Replace new_editor with native XCUI shell sandbox --- .../Rendering/Passes/BuiltinObjectIdPass.h | 2 +- .../src/UI/Runtime/UIScreenDocumentHost.cpp | 144 +- new_editor/CMakeLists.txt | 192 +- new_editor/README.md | 16 - new_editor/resources/xcui_demo_theme.xctheme | 24 - new_editor/resources/xcui_demo_view.xcui | 89 - .../resources/xcui_layout_lab_theme.xctheme | 21 - .../resources/xcui_layout_lab_view.xcui | 118 - new_editor/src/Application.cpp | 1333 +++------- new_editor/src/Application.h | 478 +--- new_editor/src/ApplicationDefaultShell.cpp | 138 -- new_editor/src/ApplicationLegacyImGui.cpp | 655 ----- new_editor/src/AutoScreenshot.cpp | 148 ++ new_editor/src/AutoScreenshot.h | 54 + new_editor/src/NativeRenderer.cpp | 487 ++++ new_editor/src/NativeRenderer.h | 67 + new_editor/src/Platform/D3D12WindowRenderer.h | 7 - .../D3D12WindowRendererImGuiInterop.h | 83 - .../src/Rendering/MainWindowBackdropPass.cpp | 275 -- .../src/Rendering/MainWindowBackdropPass.h | 41 - .../MainWindowNativeBackdropRenderer.cpp | 44 - .../MainWindowNativeBackdropRenderer.h | 39 - new_editor/src/SandboxFrameBuilder.cpp | 334 +++ new_editor/src/SandboxFrameBuilder.h | 17 + new_editor/src/UI/ImGuiBackendBridge.h | 3 - .../src/XCUIBackend/IEditorHostCompositor.h | 66 - .../src/XCUIBackend/IWindowUICompositor.h | 68 - .../src/XCUIBackend/IXCUITextAtlasProvider.h | 90 - .../src/XCUIBackend/ImGuiHostCompositor.cpp | 111 - .../XCUIBackend/ImGuiTextAtlasProvider.cpp | 223 -- .../src/XCUIBackend/ImGuiTextAtlasProvider.h | 35 - .../src/XCUIBackend/ImGuiTransitionBackend.h | 193 -- .../src/XCUIBackend/ImGuiWindowUICompositor.h | 84 - .../ImGuiXCUIHostedPreviewPresenter.h | 89 - .../src/XCUIBackend/ImGuiXCUIInputAdapter.cpp | 226 -- .../src/XCUIBackend/ImGuiXCUIInputAdapter.h | 22 - .../src/XCUIBackend/ImGuiXCUIInputSource.h | 56 - .../XCUIBackend/ImGuiXCUIPanelCanvasHost.h | 248 -- .../XCUIBackend/LegacyImGuiHostInterop.cpp | 51 - .../src/XCUIBackend/LegacyImGuiHostInterop.h | 33 - .../XCUIBackend/NativeWindowUICompositor.cpp | 282 --- .../XCUIBackend/NativeWindowUICompositor.h | 76 - .../XCUIBackend/NativeXCUIPanelCanvasHost.h | 291 --- .../src/XCUIBackend/NullXCUIPanelCanvasHost.h | 67 - .../src/XCUIBackend/UITextureRegistration.h | 31 - .../XCUIBackend/XCUIAssetDocumentSource.cpp | 750 ------ .../src/XCUIBackend/XCUIAssetDocumentSource.h | 148 -- .../src/XCUIBackend/XCUIDemoRuntime.cpp | 2208 ----------------- new_editor/src/XCUIBackend/XCUIDemoRuntime.h | 79 - .../XCUIBackend/XCUIEditorCommandRouter.cpp | 210 -- .../src/XCUIBackend/XCUIEditorCommandRouter.h | 101 - .../src/XCUIBackend/XCUIEditorFontSetup.cpp | 71 - .../src/XCUIBackend/XCUIEditorFontSetup.h | 11 - .../XCUIBackend/XCUIHostedPreviewPresenter.h | 336 --- .../src/XCUIBackend/XCUIInputBridge.cpp | 587 ----- new_editor/src/XCUIBackend/XCUIInputBridge.h | 159 -- .../src/XCUIBackend/XCUILayoutLabRuntime.cpp | 1859 -------------- .../src/XCUIBackend/XCUILayoutLabRuntime.h | 90 - .../src/XCUIBackend/XCUINativeShellLayout.h | 227 -- .../src/XCUIBackend/XCUIPanelCanvasHost.h | 113 - .../XCUIBackend/XCUIRHICommandCompiler.cpp | 590 ----- .../src/XCUIBackend/XCUIRHICommandCompiler.h | 119 - .../src/XCUIBackend/XCUIRHICommandSupport.h | 267 -- .../src/XCUIBackend/XCUIRHIRenderBackend.cpp | 582 ----- .../src/XCUIBackend/XCUIRHIRenderBackend.h | 120 - .../src/XCUIBackend/XCUIShellChromeState.cpp | 414 ---- .../src/XCUIBackend/XCUIShellChromeState.h | 135 - .../XCUIStandaloneTextAtlasProvider.cpp | 842 ------- .../XCUIStandaloneTextAtlasProvider.h | 39 - new_editor/src/main.cpp | 3 +- new_editor/src/panels/Panel.cpp | 44 - new_editor/src/panels/Panel.h | 29 - new_editor/src/panels/XCUIDemoPanel.cpp | 154 -- new_editor/src/panels/XCUIDemoPanel.h | 91 - new_editor/src/panels/XCUILayoutLabPanel.cpp | 240 -- new_editor/src/panels/XCUILayoutLabPanel.h | 78 - .../schemas/editor_inspector_shell.xcschema | 21 + new_editor/ui/themes/editor_shell.xctheme | 32 + new_editor/ui/views/editor_shell.xcui | 82 + tests/Core/UI/test_ui_runtime.cpp | 127 + tests/NewEditor/CMakeLists.txt | 975 +------- ...est_application_shell_command_bindings.cpp | 399 --- .../test_imgui_text_atlas_provider.cpp | 90 - .../test_imgui_window_ui_compositor.cpp | 334 --- .../test_imgui_xcui_input_adapter.cpp | 91 - .../test_imgui_xcui_panel_canvas_host.cpp | 17 - .../test_legacy_imgui_host_interop.cpp | 72 - ...in_window_native_backdrop_renderer_api.cpp | 32 - .../test_native_window_ui_compositor.cpp | 446 ---- .../test_native_xcui_panel_canvas_host.cpp | 172 -- ...st_new_editor_imgui_transition_backend.cpp | 306 --- .../NewEditor/test_sandbox_frame_builder.cpp | 54 + .../test_structured_editor_shell.cpp | 91 + .../test_xcui_asset_document_source.cpp | 257 -- tests/NewEditor/test_xcui_demo_panel.cpp | 248 -- tests/NewEditor/test_xcui_demo_runtime.cpp | 617 ----- .../test_xcui_editor_command_router.cpp | 205 -- .../test_xcui_hosted_preview_presenter.cpp | 827 ------ tests/NewEditor/test_xcui_input_bridge.cpp | 146 -- .../NewEditor/test_xcui_layout_lab_panel.cpp | 526 ---- .../test_xcui_layout_lab_runtime.cpp | 532 ---- .../test_xcui_native_shell_layout.cpp | 133 - .../NewEditor/test_xcui_panel_canvas_host.cpp | 111 - .../test_xcui_rhi_command_compiler.cpp | 271 -- .../test_xcui_rhi_command_support.cpp | 202 -- .../test_xcui_rhi_render_backend.cpp | 710 ------ .../test_xcui_shell_chrome_state.cpp | 314 --- ...st_xcui_standalone_text_atlas_provider.cpp | 157 -- 108 files changed, 2041 insertions(+), 24403 deletions(-) delete mode 100644 new_editor/README.md delete mode 100644 new_editor/resources/xcui_demo_theme.xctheme delete mode 100644 new_editor/resources/xcui_demo_view.xcui delete mode 100644 new_editor/resources/xcui_layout_lab_theme.xctheme delete mode 100644 new_editor/resources/xcui_layout_lab_view.xcui delete mode 100644 new_editor/src/ApplicationDefaultShell.cpp delete mode 100644 new_editor/src/ApplicationLegacyImGui.cpp create mode 100644 new_editor/src/AutoScreenshot.cpp create mode 100644 new_editor/src/AutoScreenshot.h create mode 100644 new_editor/src/NativeRenderer.cpp create mode 100644 new_editor/src/NativeRenderer.h delete mode 100644 new_editor/src/Platform/D3D12WindowRenderer.h delete mode 100644 new_editor/src/Platform/D3D12WindowRendererImGuiInterop.h delete mode 100644 new_editor/src/Rendering/MainWindowBackdropPass.cpp delete mode 100644 new_editor/src/Rendering/MainWindowBackdropPass.h delete mode 100644 new_editor/src/Rendering/MainWindowNativeBackdropRenderer.cpp delete mode 100644 new_editor/src/Rendering/MainWindowNativeBackdropRenderer.h create mode 100644 new_editor/src/SandboxFrameBuilder.cpp create mode 100644 new_editor/src/SandboxFrameBuilder.h delete mode 100644 new_editor/src/UI/ImGuiBackendBridge.h delete mode 100644 new_editor/src/XCUIBackend/IEditorHostCompositor.h delete mode 100644 new_editor/src/XCUIBackend/IWindowUICompositor.h delete mode 100644 new_editor/src/XCUIBackend/IXCUITextAtlasProvider.h delete mode 100644 new_editor/src/XCUIBackend/ImGuiHostCompositor.cpp delete mode 100644 new_editor/src/XCUIBackend/ImGuiTextAtlasProvider.cpp delete mode 100644 new_editor/src/XCUIBackend/ImGuiTextAtlasProvider.h delete mode 100644 new_editor/src/XCUIBackend/ImGuiTransitionBackend.h delete mode 100644 new_editor/src/XCUIBackend/ImGuiWindowUICompositor.h delete mode 100644 new_editor/src/XCUIBackend/ImGuiXCUIHostedPreviewPresenter.h delete mode 100644 new_editor/src/XCUIBackend/ImGuiXCUIInputAdapter.cpp delete mode 100644 new_editor/src/XCUIBackend/ImGuiXCUIInputAdapter.h delete mode 100644 new_editor/src/XCUIBackend/ImGuiXCUIInputSource.h delete mode 100644 new_editor/src/XCUIBackend/ImGuiXCUIPanelCanvasHost.h delete mode 100644 new_editor/src/XCUIBackend/LegacyImGuiHostInterop.cpp delete mode 100644 new_editor/src/XCUIBackend/LegacyImGuiHostInterop.h delete mode 100644 new_editor/src/XCUIBackend/NativeWindowUICompositor.cpp delete mode 100644 new_editor/src/XCUIBackend/NativeWindowUICompositor.h delete mode 100644 new_editor/src/XCUIBackend/NativeXCUIPanelCanvasHost.h delete mode 100644 new_editor/src/XCUIBackend/NullXCUIPanelCanvasHost.h delete mode 100644 new_editor/src/XCUIBackend/UITextureRegistration.h delete mode 100644 new_editor/src/XCUIBackend/XCUIAssetDocumentSource.cpp delete mode 100644 new_editor/src/XCUIBackend/XCUIAssetDocumentSource.h delete mode 100644 new_editor/src/XCUIBackend/XCUIDemoRuntime.cpp delete mode 100644 new_editor/src/XCUIBackend/XCUIDemoRuntime.h delete mode 100644 new_editor/src/XCUIBackend/XCUIEditorCommandRouter.cpp delete mode 100644 new_editor/src/XCUIBackend/XCUIEditorCommandRouter.h delete mode 100644 new_editor/src/XCUIBackend/XCUIEditorFontSetup.cpp delete mode 100644 new_editor/src/XCUIBackend/XCUIEditorFontSetup.h delete mode 100644 new_editor/src/XCUIBackend/XCUIHostedPreviewPresenter.h delete mode 100644 new_editor/src/XCUIBackend/XCUIInputBridge.cpp delete mode 100644 new_editor/src/XCUIBackend/XCUIInputBridge.h delete mode 100644 new_editor/src/XCUIBackend/XCUILayoutLabRuntime.cpp delete mode 100644 new_editor/src/XCUIBackend/XCUILayoutLabRuntime.h delete mode 100644 new_editor/src/XCUIBackend/XCUINativeShellLayout.h delete mode 100644 new_editor/src/XCUIBackend/XCUIPanelCanvasHost.h delete mode 100644 new_editor/src/XCUIBackend/XCUIRHICommandCompiler.cpp delete mode 100644 new_editor/src/XCUIBackend/XCUIRHICommandCompiler.h delete mode 100644 new_editor/src/XCUIBackend/XCUIRHICommandSupport.h delete mode 100644 new_editor/src/XCUIBackend/XCUIRHIRenderBackend.cpp delete mode 100644 new_editor/src/XCUIBackend/XCUIRHIRenderBackend.h delete mode 100644 new_editor/src/XCUIBackend/XCUIShellChromeState.cpp delete mode 100644 new_editor/src/XCUIBackend/XCUIShellChromeState.h delete mode 100644 new_editor/src/XCUIBackend/XCUIStandaloneTextAtlasProvider.cpp delete mode 100644 new_editor/src/XCUIBackend/XCUIStandaloneTextAtlasProvider.h delete mode 100644 new_editor/src/panels/Panel.cpp delete mode 100644 new_editor/src/panels/Panel.h delete mode 100644 new_editor/src/panels/XCUIDemoPanel.cpp delete mode 100644 new_editor/src/panels/XCUIDemoPanel.h delete mode 100644 new_editor/src/panels/XCUILayoutLabPanel.cpp delete mode 100644 new_editor/src/panels/XCUILayoutLabPanel.h create mode 100644 new_editor/ui/schemas/editor_inspector_shell.xcschema create mode 100644 new_editor/ui/themes/editor_shell.xctheme create mode 100644 new_editor/ui/views/editor_shell.xcui delete mode 100644 tests/NewEditor/test_application_shell_command_bindings.cpp delete mode 100644 tests/NewEditor/test_imgui_text_atlas_provider.cpp delete mode 100644 tests/NewEditor/test_imgui_window_ui_compositor.cpp delete mode 100644 tests/NewEditor/test_imgui_xcui_input_adapter.cpp delete mode 100644 tests/NewEditor/test_imgui_xcui_panel_canvas_host.cpp delete mode 100644 tests/NewEditor/test_legacy_imgui_host_interop.cpp delete mode 100644 tests/NewEditor/test_main_window_native_backdrop_renderer_api.cpp delete mode 100644 tests/NewEditor/test_native_window_ui_compositor.cpp delete mode 100644 tests/NewEditor/test_native_xcui_panel_canvas_host.cpp delete mode 100644 tests/NewEditor/test_new_editor_imgui_transition_backend.cpp create mode 100644 tests/NewEditor/test_sandbox_frame_builder.cpp create mode 100644 tests/NewEditor/test_structured_editor_shell.cpp delete mode 100644 tests/NewEditor/test_xcui_asset_document_source.cpp delete mode 100644 tests/NewEditor/test_xcui_demo_panel.cpp delete mode 100644 tests/NewEditor/test_xcui_demo_runtime.cpp delete mode 100644 tests/NewEditor/test_xcui_editor_command_router.cpp delete mode 100644 tests/NewEditor/test_xcui_hosted_preview_presenter.cpp delete mode 100644 tests/NewEditor/test_xcui_input_bridge.cpp delete mode 100644 tests/NewEditor/test_xcui_layout_lab_panel.cpp delete mode 100644 tests/NewEditor/test_xcui_layout_lab_runtime.cpp delete mode 100644 tests/NewEditor/test_xcui_native_shell_layout.cpp delete mode 100644 tests/NewEditor/test_xcui_panel_canvas_host.cpp delete mode 100644 tests/NewEditor/test_xcui_rhi_command_compiler.cpp delete mode 100644 tests/NewEditor/test_xcui_rhi_command_support.cpp delete mode 100644 tests/NewEditor/test_xcui_rhi_render_backend.cpp delete mode 100644 tests/NewEditor/test_xcui_shell_chrome_state.cpp delete mode 100644 tests/NewEditor/test_xcui_standalone_text_atlas_provider.cpp diff --git a/engine/include/XCEngine/Rendering/Passes/BuiltinObjectIdPass.h b/engine/include/XCEngine/Rendering/Passes/BuiltinObjectIdPass.h index 7ebc6f5b..15aa7c8e 100644 --- a/engine/include/XCEngine/Rendering/Passes/BuiltinObjectIdPass.h +++ b/engine/include/XCEngine/Rendering/Passes/BuiltinObjectIdPass.h @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include #include diff --git a/engine/src/UI/Runtime/UIScreenDocumentHost.cpp b/engine/src/UI/Runtime/UIScreenDocumentHost.cpp index 08d3b689..20752f64 100644 --- a/engine/src/UI/Runtime/UIScreenDocumentHost.cpp +++ b/engine/src/UI/Runtime/UIScreenDocumentHost.cpp @@ -32,7 +32,10 @@ namespace Layout = XCEngine::UI::Layout; constexpr float kDefaultFontSize = 16.0f; constexpr float kSmallFontSize = 13.0f; +constexpr float kButtonFontSize = 14.0f; constexpr float kApproximateGlyphWidth = 0.56f; +constexpr float kHeaderTextInset = 12.0f; +constexpr float kHeaderTextGap = 2.0f; struct RuntimeLayoutNode { const UIDocumentNode* source = nullptr; @@ -71,6 +74,10 @@ float MeasureTextHeight(float fontSize) { return fontSize + 6.0f; } +float ComputeCenteredTextTop(const UIRect& rect, float fontSize) { + return rect.y + (std::max)(0.0f, std::floor((rect.height - fontSize) * 0.5f)); +} + const UIDocumentAttribute* FindAttribute(const UIDocumentNode& node, const char* name) { for (const UIDocumentAttribute& attribute : node.attributes) { if (attribute.name == name) { @@ -89,6 +96,43 @@ std::string GetAttribute( return attribute != nullptr ? ToStdString(attribute->value) : fallback; } +float MeasureHeaderTextWidth(const UIDocumentNode& node) { + float width = 0.0f; + + const std::string title = GetAttribute(node, "title"); + if (!title.empty()) { + width = (std::max)(width, MeasureTextWidth(title, kDefaultFontSize)); + } + + const std::string subtitle = GetAttribute(node, "subtitle"); + if (!subtitle.empty()) { + width = (std::max)(width, MeasureTextWidth(subtitle, kSmallFontSize)); + } + + return width; +} + +float MeasureHeaderHeight(const UIDocumentNode& node) { + const std::string title = GetAttribute(node, "title"); + const std::string subtitle = GetAttribute(node, "subtitle"); + if (title.empty() && subtitle.empty()) { + return 0.0f; + } + + float headerHeight = kHeaderTextInset; + if (!title.empty()) { + headerHeight += MeasureTextHeight(kDefaultFontSize); + } + if (!subtitle.empty()) { + if (!title.empty()) { + headerHeight += kHeaderTextGap; + } + headerHeight += MeasureTextHeight(kSmallFontSize); + } + + return headerHeight; +} + bool TryParseFloat(const std::string& text, float& outValue) { if (text.empty()) { return false; @@ -139,6 +183,38 @@ Layout::UILayoutThickness ParsePadding( return Layout::UILayoutThickness::Uniform(ParseFloatAttribute(node, "padding", fallback)); } +Layout::UILayoutItem BuildLayoutItem( + const RuntimeLayoutNode& child, + Layout::UILayoutAxis parentAxis) { + Layout::UILayoutItem item = {}; + item.desiredContentSize = child.desiredSize; + item.width = ParseLengthAttribute(*child.source, "width"); + item.height = ParseLengthAttribute(*child.source, "height"); + + // Pixel-authored lengths act as requested extents, but never below the measured content floor. + if (item.width.unit == Layout::UILayoutLengthUnit::Pixels && + item.width.value < child.desiredSize.width) { + item.minSize.width = child.desiredSize.width; + } + + if (item.height.unit == Layout::UILayoutLengthUnit::Pixels && + item.height.value < child.desiredSize.height) { + item.minSize.height = child.desiredSize.height; + } + + if (parentAxis == Layout::UILayoutAxis::Vertical && + item.width.unit == Layout::UILayoutLengthUnit::Auto) { + item.horizontalAlignment = Layout::UILayoutAlignment::Stretch; + } + + if (parentAxis == Layout::UILayoutAxis::Horizontal && + item.height.unit == Layout::UILayoutLengthUnit::Auto) { + item.verticalAlignment = Layout::UILayoutAlignment::Stretch; + } + + return item; +} + std::string ResolveNodeText(const UIDocumentNode& node) { const std::string text = GetAttribute(node, "text"); if (!text.empty()) { @@ -175,31 +251,31 @@ Color ResolveBackgroundColor(const UIDocumentNode& node) { const std::string tagName = ToStdString(node.tagName); if (tagName == "View") { - return Color(0.08f, 0.09f, 0.11f, 1.0f); + return Color(0.11f, 0.11f, 0.11f, 1.0f); } if (tone == "accent") { - return Color(0.19f, 0.31f, 0.52f, 1.0f); + return Color(0.25f, 0.25f, 0.25f, 1.0f); } if (tone == "accent-alt") { - return Color(0.24f, 0.26f, 0.39f, 1.0f); + return Color(0.22f, 0.22f, 0.22f, 1.0f); } if (tagName == "Button") { - return Color(0.20f, 0.23f, 0.29f, 1.0f); + return Color(0.24f, 0.24f, 0.24f, 1.0f); } - return Color(0.13f, 0.15f, 0.18f, 1.0f); + return Color(0.16f, 0.16f, 0.16f, 1.0f); } Color ResolveBorderColor(const UIDocumentNode& node) { const std::string tone = GetAttribute(node, "tone"); if (tone == "accent") { - return Color(0.31f, 0.56f, 0.90f, 1.0f); + return Color(0.42f, 0.42f, 0.42f, 1.0f); } if (tone == "accent-alt") { - return Color(0.47f, 0.51f, 0.76f, 1.0f); + return Color(0.34f, 0.34f, 0.34f, 1.0f); } - return Color(0.25f, 0.28f, 0.33f, 1.0f); + return Color(0.30f, 0.30f, 0.30f, 1.0f); } RuntimeLayoutNode BuildLayoutTree(const UIDocumentNode& source) { @@ -246,42 +322,32 @@ UISize MeasureNode(RuntimeLayoutNode& node) { std::vector items = {}; items.reserve(node.children.size()); for (RuntimeLayoutNode& child : node.children) { - Layout::UILayoutItem item = {}; - item.desiredContentSize = MeasureNode(child); - item.width = ParseLengthAttribute(*child.source, "width"); - item.height = ParseLengthAttribute(*child.source, "height"); + MeasureNode(child); + Layout::UILayoutItem item = BuildLayoutItem(child, options.axis); items.push_back(item); } const auto measured = Layout::MeasureStackLayout(options, items); node.desiredSize = measured.desiredSize; - const std::string title = GetAttribute(source, "title"); - const std::string subtitle = GetAttribute(source, "subtitle"); - float headerHeight = 0.0f; - if (!title.empty()) { - headerHeight += MeasureTextHeight(kDefaultFontSize); - } - if (!subtitle.empty()) { - if (headerHeight > 0.0f) { - headerHeight += 4.0f; - } - headerHeight += MeasureTextHeight(kSmallFontSize); - } + const float headerHeight = MeasureHeaderHeight(source); + const float headerTextWidth = MeasureHeaderTextWidth(source); node.desiredSize.width = (std::max)( node.desiredSize.width, - MeasureTextWidth(ResolveNodeText(source), kDefaultFontSize) + options.padding.Horizontal()); + headerTextWidth > 0.0f + ? headerTextWidth + options.padding.Horizontal() + : MeasureTextWidth(ResolveNodeText(source), kDefaultFontSize) + options.padding.Horizontal()); node.desiredSize.height += headerHeight; float explicitWidth = 0.0f; if (TryParseFloat(GetAttribute(source, "width"), explicitWidth)) { - node.desiredSize.width = explicitWidth; + node.desiredSize.width = (std::max)(node.desiredSize.width, explicitWidth); } float explicitHeight = 0.0f; if (TryParseFloat(GetAttribute(source, "height"), explicitHeight)) { - node.desiredSize.height = explicitHeight; + node.desiredSize.height = (std::max)(node.desiredSize.height, explicitHeight); } return node.desiredSize; @@ -308,16 +374,7 @@ void ArrangeNode(RuntimeLayoutNode& node, const UIRect& rect) { source, tagName == "View" ? 16.0f : 12.0f); - float headerHeight = 0.0f; - if (!GetAttribute(source, "title").empty()) { - headerHeight += MeasureTextHeight(kDefaultFontSize); - } - if (!GetAttribute(source, "subtitle").empty()) { - if (headerHeight > 0.0f) { - headerHeight += 4.0f; - } - headerHeight += MeasureTextHeight(kSmallFontSize); - } + const float headerHeight = MeasureHeaderHeight(source); UIRect contentRect = rect; contentRect.y += headerHeight; @@ -326,10 +383,7 @@ void ArrangeNode(RuntimeLayoutNode& node, const UIRect& rect) { std::vector items = {}; items.reserve(node.children.size()); for (RuntimeLayoutNode& child : node.children) { - Layout::UILayoutItem item = {}; - item.desiredContentSize = child.desiredSize; - item.width = ParseLengthAttribute(*child.source, "width"); - item.height = ParseLengthAttribute(*child.source, "height"); + Layout::UILayoutItem item = BuildLayoutItem(child, options.axis); items.push_back(item); } @@ -359,7 +413,7 @@ void EmitNode( const std::string title = GetAttribute(source, "title"); const std::string subtitle = GetAttribute(source, "subtitle"); - float textY = node.rect.y + 12.0f; + float textY = node.rect.y + kHeaderTextInset; if (!title.empty()) { drawList.AddText( UIPoint(node.rect.x + 12.0f, textY), @@ -367,7 +421,7 @@ void EmitNode( ToUIColor(Color(0.94f, 0.95f, 0.97f, 1.0f)), kDefaultFontSize); ++stats.textCommandCount; - textY += MeasureTextHeight(kDefaultFontSize) + 2.0f; + textY += MeasureTextHeight(kDefaultFontSize) + kHeaderTextGap; } if (!subtitle.empty()) { @@ -390,10 +444,10 @@ void EmitNode( if (tagName == "Button" && title.empty() && subtitle.empty()) { drawList.AddText( - UIPoint(node.rect.x + 12.0f, node.rect.y + 12.0f), + UIPoint(node.rect.x + 12.0f, ComputeCenteredTextTop(node.rect, kButtonFontSize)), ResolveNodeText(source), ToUIColor(Color(0.95f, 0.97f, 1.0f, 1.0f)), - kDefaultFontSize); + kButtonFontSize); ++stats.textCommandCount; } diff --git a/new_editor/CMakeLists.txt b/new_editor/CMakeLists.txt index 5acbba4d..34c26927 100644 --- a/new_editor/CMakeLists.txt +++ b/new_editor/CMakeLists.txt @@ -1,171 +1,77 @@ cmake_minimum_required(VERSION 3.15) - -if(MSVC AND POLICY CMP0141) - cmake_policy(SET CMP0141 NEW) -endif() - project(XCNewEditor VERSION 0.1 LANGUAGES CXX) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) -add_definitions(-DUNICODE -D_UNICODE) +file(TO_CMAKE_PATH "${CMAKE_SOURCE_DIR}" XCNEWEDITOR_REPO_ROOT_PATH) -set(XCENGINE_ROOT_DIR "") -if(EXISTS "${CMAKE_SOURCE_DIR}/engine/CMakeLists.txt") - set(XCENGINE_ROOT_DIR "${CMAKE_SOURCE_DIR}") -elseif(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/../engine/CMakeLists.txt") - set(XCENGINE_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/..") -else() - message(FATAL_ERROR "Unable to locate XCEngine root directory from new_editor.") -endif() - -if(NOT TARGET XCEngine) - add_subdirectory(${XCENGINE_ROOT_DIR}/engine ${CMAKE_CURRENT_BINARY_DIR}/engine_dependency) -endif() - -set(IMGUI_SOURCE_DIR "${CMAKE_BINARY_DIR}/_deps/imgui-src") -if(NOT EXISTS "${IMGUI_SOURCE_DIR}/imgui.cpp") - include(FetchContent) - FetchContent_Declare( - imgui_new_editor - GIT_REPOSITORY https://gitee.com/mirrors/imgui.git - GIT_TAG docking - GIT_SHALLOW TRUE - ) - FetchContent_MakeAvailable(imgui_new_editor) - set(IMGUI_SOURCE_DIR "${imgui_new_editor_SOURCE_DIR}") -endif() - -if(NOT EXISTS "${IMGUI_SOURCE_DIR}/imgui.cpp") - message(FATAL_ERROR "ImGui source was not found at ${IMGUI_SOURCE_DIR}.") -endif() - -set(NEW_EDITOR_SOURCES - src/main.cpp - src/Application.cpp - src/ApplicationDefaultShell.cpp - src/panels/Panel.cpp - src/Rendering/MainWindowBackdropPass.cpp - src/Rendering/MainWindowNativeBackdropRenderer.cpp - src/XCUIBackend/NativeWindowUICompositor.cpp - src/XCUIBackend/XCUIAssetDocumentSource.cpp - src/XCUIBackend/XCUIEditorCommandRouter.cpp - src/XCUIBackend/XCUIInputBridge.cpp - src/XCUIBackend/XCUIShellChromeState.cpp - src/XCUIBackend/XCUIRHICommandCompiler.cpp - src/XCUIBackend/XCUIRHIRenderBackend.cpp - src/XCUIBackend/XCUIStandaloneTextAtlasProvider.cpp - src/XCUIBackend/XCUIDemoRuntime.cpp - src/XCUIBackend/XCUILayoutLabRuntime.cpp +set(NEW_EDITOR_RESOURCE_FILES + ui/views/editor_shell.xcui + ui/themes/editor_shell.xctheme + ui/schemas/editor_inspector_shell.xcschema ) -set(NEW_EDITOR_IMGUI_COMPAT_SOURCES - src/ApplicationLegacyImGui.cpp - src/panels/XCUIDemoPanel.cpp - src/panels/XCUILayoutLabPanel.cpp - src/XCUIBackend/ImGuiXCUIInputAdapter.cpp - src/XCUIBackend/LegacyImGuiHostInterop.cpp - src/XCUIBackend/ImGuiHostCompositor.cpp - src/XCUIBackend/XCUIEditorFontSetup.cpp - ${IMGUI_SOURCE_DIR}/imgui.cpp - ${IMGUI_SOURCE_DIR}/imgui_demo.cpp - ${IMGUI_SOURCE_DIR}/imgui_draw.cpp - ${IMGUI_SOURCE_DIR}/imgui_tables.cpp - ${IMGUI_SOURCE_DIR}/imgui_widgets.cpp - ${IMGUI_SOURCE_DIR}/backends/imgui_impl_win32.cpp - ${IMGUI_SOURCE_DIR}/backends/imgui_impl_dx12.cpp +add_library(XCNewEditorLib STATIC + src/SandboxFrameBuilder.cpp ) -add_library(XCNewEditorImGuiCompat STATIC ${NEW_EDITOR_IMGUI_COMPAT_SOURCES}) -add_executable(${PROJECT_NAME} WIN32 ${NEW_EDITOR_SOURCES}) - -set(NEW_EDITOR_COMMON_INCLUDE_DIRS - ${CMAKE_CURRENT_SOURCE_DIR}/src - ${XCENGINE_ROOT_DIR}/engine/include +target_include_directories(XCNewEditorLib + PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src + ${CMAKE_SOURCE_DIR}/engine/include ) -set(NEW_EDITOR_IMGUI_COMPAT_INCLUDE_DIRS - ${NEW_EDITOR_COMMON_INCLUDE_DIRS} - ${IMGUI_SOURCE_DIR} - ${IMGUI_SOURCE_DIR}/backends -) - -target_include_directories(XCNewEditorImGuiCompat PRIVATE ${NEW_EDITOR_IMGUI_COMPAT_INCLUDE_DIRS}) - -target_include_directories(${PROJECT_NAME} PRIVATE ${NEW_EDITOR_COMMON_INCLUDE_DIRS}) - -file(TO_CMAKE_PATH "${XCENGINE_ROOT_DIR}" XCENGINE_ROOT_DIR_CMAKE) - -target_compile_definitions(XCNewEditorImGuiCompat PRIVATE +target_compile_definitions(XCNewEditorLib PUBLIC UNICODE _UNICODE - NOMINMAX - XCENGINE_NEW_EDITOR_REPO_ROOT="${XCENGINE_ROOT_DIR_CMAKE}" ) -target_compile_options(XCNewEditorImGuiCompat PRIVATE /utf-8) - -target_compile_definitions(${PROJECT_NAME} PRIVATE - UNICODE - _UNICODE - NOMINMAX - XCENGINE_NEW_EDITOR_REPO_ROOT="${XCENGINE_ROOT_DIR_CMAKE}" -) -target_compile_options(${PROJECT_NAME} PRIVATE /utf-8) if(MSVC) - target_compile_options(XCNewEditorImGuiCompat PRIVATE /FS) - target_compile_options(${PROJECT_NAME} PRIVATE /FS) - set_property(TARGET XCNewEditorImGuiCompat PROPERTY + target_compile_options(XCNewEditorLib PRIVATE /utf-8 /FS) + set_property(TARGET XCNewEditorLib PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>DLL") - set_target_properties(XCNewEditorImGuiCompat PROPERTIES - MSVC_DEBUG_INFORMATION_FORMAT "$<$:Embedded>" - COMPILE_PDB_NAME "XCNewEditorImGuiCompat-compile" - COMPILE_PDB_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/new_editor/compile-pdb-compat" - COMPILE_PDB_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}/new_editor/compile-pdb-compat/Debug" - COMPILE_PDB_OUTPUT_DIRECTORY_RELEASE "${CMAKE_BINARY_DIR}/new_editor/compile-pdb-compat/Release" - COMPILE_PDB_OUTPUT_DIRECTORY_MINSIZEREL "${CMAKE_BINARY_DIR}/new_editor/compile-pdb-compat/MinSizeRel" - COMPILE_PDB_OUTPUT_DIRECTORY_RELWITHDEBINFO "${CMAKE_BINARY_DIR}/new_editor/compile-pdb-compat/RelWithDebInfo" - PDB_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/new_editor/pdb-compat" - PDB_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}/new_editor/pdb-compat/Debug" - PDB_OUTPUT_DIRECTORY_RELEASE "${CMAKE_BINARY_DIR}/new_editor/pdb-compat/Release" - PDB_OUTPUT_DIRECTORY_MINSIZEREL "${CMAKE_BINARY_DIR}/new_editor/pdb-compat/MinSizeRel" - PDB_OUTPUT_DIRECTORY_RELWITHDEBINFO "${CMAKE_BINARY_DIR}/new_editor/pdb-compat/RelWithDebInfo") - target_link_options(${PROJECT_NAME} PRIVATE - $<$:/INCREMENTAL:NO>) - set_property(TARGET ${PROJECT_NAME} PROPERTY - MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>DLL") - set_target_properties(${PROJECT_NAME} PROPERTIES - MSVC_DEBUG_INFORMATION_FORMAT "$<$:Embedded>" - COMPILE_PDB_NAME "XCNewEditor-compile" - COMPILE_PDB_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/new_editor/compile-pdb" - COMPILE_PDB_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}/new_editor/compile-pdb/Debug" - COMPILE_PDB_OUTPUT_DIRECTORY_RELEASE "${CMAKE_BINARY_DIR}/new_editor/compile-pdb/Release" - COMPILE_PDB_OUTPUT_DIRECTORY_MINSIZEREL "${CMAKE_BINARY_DIR}/new_editor/compile-pdb/MinSizeRel" - COMPILE_PDB_OUTPUT_DIRECTORY_RELWITHDEBINFO "${CMAKE_BINARY_DIR}/new_editor/compile-pdb/RelWithDebInfo" - VS_GLOBAL_UseMultiToolTask "false" - ) endif() -target_link_libraries(XCNewEditorImGuiCompat PRIVATE +target_link_libraries(XCNewEditorLib PUBLIC XCEngine - d3d12.lib - dxgi.lib - user32 - gdi32 ) -target_link_libraries(${PROJECT_NAME} PRIVATE - XCEngine - d3d12.lib - dxgi.lib - user32 - gdi32 +add_executable(XCNewEditorApp WIN32 + src/main.cpp + src/Application.cpp + src/AutoScreenshot.cpp + src/NativeRenderer.cpp + ${NEW_EDITOR_RESOURCE_FILES} ) -set_target_properties(${PROJECT_NAME} PROPERTIES +target_include_directories(XCNewEditorApp PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/src + ${CMAKE_SOURCE_DIR}/engine/include +) + +target_compile_definitions(XCNewEditorApp PRIVATE + UNICODE + _UNICODE + XCNEWEDITOR_REPO_ROOT="${XCNEWEDITOR_REPO_ROOT_PATH}" +) + +if(MSVC) + target_compile_options(XCNewEditorApp PRIVATE /utf-8 /FS) + set_property(TARGET XCNewEditorApp PROPERTY + MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>DLL") +endif() + +target_link_libraries(XCNewEditorApp PRIVATE + XCNewEditorLib + d2d1.lib + dwrite.lib + windowscodecs.lib +) + +set_target_properties(XCNewEditorApp PROPERTIES OUTPUT_NAME "XCNewEditor" - RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/new_editor/bin" - PDB_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/new_editor/bin" - VS_DEBUGGER_WORKING_DIRECTORY "${XCENGINE_ROOT_DIR}" + RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin" ) + +source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}" FILES ${NEW_EDITOR_RESOURCE_FILES}) diff --git a/new_editor/README.md b/new_editor/README.md deleted file mode 100644 index 69bb68f3..00000000 --- a/new_editor/README.md +++ /dev/null @@ -1,16 +0,0 @@ -# new_editor XCUI sandbox - -`new_editor` is an **isolated playground** for the XCUI experiment. It is intentionally separated from the main `editor` so you can redesign the UI stack without destabilizing the current ImGui-based editor. - -## Current scope -- Provides a minimal Win32 + ImGui host (scaffolded elsewhere) that links the engine and XCUI code. -- Hosts a single demo panel that loads XCUI documents and reroutes draw commands through `ImGuiTransitionBackend`. -- Bundles themed XCUI documents under `resources/` so the demo can run without touching the primary editor's assets. - -## Resources -`resources/xcui_demo_view.xcui` describes the card layout, placeholder texts, and debug markers the demo renders. `resources/xcui_demo_theme.xctheme` defines colors, spacing, and tokenized styles that the runtime resolves. - -## Next steps -1. Expand the demo UI to exercise more layout primitives (stack, grid, overlays) and token-based styling. -2. Hook the runtime into actual document hot-reload so the panel responds to source edits. -3. Use `new_editor` to prototype a native XCUI shell before deciding whether to migrate the real editor. diff --git a/new_editor/resources/xcui_demo_theme.xctheme b/new_editor/resources/xcui_demo_theme.xctheme deleted file mode 100644 index 5ccb70bb..00000000 --- a/new_editor/resources/xcui_demo_theme.xctheme +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/new_editor/resources/xcui_demo_view.xcui b/new_editor/resources/xcui_demo_view.xcui deleted file mode 100644 index 7ff13898..00000000 --- a/new_editor/resources/xcui_demo_view.xcui +++ /dev/null @@ -1,89 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -