From baca976c6f8db59e3ead00d87128d22265f23e0b Mon Sep 17 00:00:00 2001 From: Misaki Date: Sat, 28 Mar 2026 22:08:20 +0900 Subject: [PATCH] feat(docking): add DockRegionHighlight and DockingLayout --- .../Controls/Docking/DockRegionHighlight.cs | 12 ++++ .../Controls/Docking/DockRegionHighlight.xaml | 15 +++++ .../View/Controls/Docking/DockingLayout.cs | 67 +++++++++++++++++++ .../View/Controls/Docking/DockingLayout.xaml | 20 ++++++ 4 files changed, 114 insertions(+) create mode 100644 src/Editor/Ghost.Editor/View/Controls/Docking/DockRegionHighlight.cs create mode 100644 src/Editor/Ghost.Editor/View/Controls/Docking/DockRegionHighlight.xaml create mode 100644 src/Editor/Ghost.Editor/View/Controls/Docking/DockingLayout.cs create mode 100644 src/Editor/Ghost.Editor/View/Controls/Docking/DockingLayout.xaml diff --git a/src/Editor/Ghost.Editor/View/Controls/Docking/DockRegionHighlight.cs b/src/Editor/Ghost.Editor/View/Controls/Docking/DockRegionHighlight.cs new file mode 100644 index 0000000..6478653 --- /dev/null +++ b/src/Editor/Ghost.Editor/View/Controls/Docking/DockRegionHighlight.cs @@ -0,0 +1,12 @@ +using Microsoft.UI.Xaml.Controls; + +namespace Ghost.Editor.View.Controls.Docking; + +public class DockRegionHighlight : Control +{ + public DockRegionHighlight() + { + DefaultStyleKey = typeof(DockRegionHighlight); + IsHitTestVisible = false; + } +} diff --git a/src/Editor/Ghost.Editor/View/Controls/Docking/DockRegionHighlight.xaml b/src/Editor/Ghost.Editor/View/Controls/Docking/DockRegionHighlight.xaml new file mode 100644 index 0000000..99023f1 --- /dev/null +++ b/src/Editor/Ghost.Editor/View/Controls/Docking/DockRegionHighlight.xaml @@ -0,0 +1,15 @@ + + + + diff --git a/src/Editor/Ghost.Editor/View/Controls/Docking/DockingLayout.cs b/src/Editor/Ghost.Editor/View/Controls/Docking/DockingLayout.cs new file mode 100644 index 0000000..97754ff --- /dev/null +++ b/src/Editor/Ghost.Editor/View/Controls/Docking/DockingLayout.cs @@ -0,0 +1,67 @@ +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; + +namespace Ghost.Editor.View.Controls.Docking; + +[TemplatePart(Name = "PART_Content", Type = typeof(ContentPresenter))] +[TemplatePart(Name = "PART_OverlayCanvas", Type = typeof(Canvas))] +[TemplatePart(Name = "PART_Highlight", Type = typeof(DockRegionHighlight))] +public class DockingLayout : Control +{ + public static readonly DependencyProperty RootPanelProperty = DependencyProperty.Register( + nameof(RootPanel), typeof(DockPanel), typeof(DockingLayout), new PropertyMetadata(null, OnRootPanelChanged)); + + public DockPanel? RootPanel + { + get => (DockPanel?)GetValue(RootPanelProperty); + set => SetValue(RootPanelProperty, value); + } + + private Canvas? _overlayCanvas; + private DockRegionHighlight? _highlight; + + public DockingLayout() + { + DefaultStyleKey = typeof(DockingLayout); + } + + protected override void OnApplyTemplate() + { + base.OnApplyTemplate(); + _overlayCanvas = GetTemplateChild("PART_OverlayCanvas") as Canvas; + _highlight = GetTemplateChild("PART_Highlight") as DockRegionHighlight; + } + + private static void OnRootPanelChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + if (d is DockingLayout layout && e.NewValue is DockPanel panel) + { + panel.Root = layout; + } + } + + public void AddDocument(DockDocument document, DockTarget target, DockGroup? targetGroup = null) + { + if (RootPanel == null) + { + RootPanel = new DockPanel(); + } + + if (targetGroup == null) + { + if (RootPanel.Children.Count == 0) + { + var group = new DockGroup(); + group.AddChild(document); + RootPanel.AddChild(group); + return; + } + targetGroup = RootPanel.Children[0] as DockGroup; + } + + if (targetGroup != null) + { + targetGroup.AddChild(document); + } + } +} diff --git a/src/Editor/Ghost.Editor/View/Controls/Docking/DockingLayout.xaml b/src/Editor/Ghost.Editor/View/Controls/Docking/DockingLayout.xaml new file mode 100644 index 0000000..0604214 --- /dev/null +++ b/src/Editor/Ghost.Editor/View/Controls/Docking/DockingLayout.xaml @@ -0,0 +1,20 @@ + + + +