feat(docking): add DockRegionHighlight and DockingLayout
This commit is contained in:
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
<ResourceDictionary
|
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:local="using:Ghost.Editor.View.Controls.Docking">
|
||||||
|
|
||||||
|
<Style TargetType="local:DockRegionHighlight">
|
||||||
|
<Setter Property="Template">
|
||||||
|
<Setter.Value>
|
||||||
|
<ControlTemplate TargetType="local:DockRegionHighlight">
|
||||||
|
<Border Background="#400078D7" BorderBrush="#800078D7" BorderThickness="2" CornerRadius="4" />
|
||||||
|
</ControlTemplate>
|
||||||
|
</Setter.Value>
|
||||||
|
</Setter>
|
||||||
|
</Style>
|
||||||
|
</ResourceDictionary>
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
<ResourceDictionary
|
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:local="using:Ghost.Editor.View.Controls.Docking">
|
||||||
|
|
||||||
|
<Style TargetType="local:DockingLayout">
|
||||||
|
<Setter Property="Template">
|
||||||
|
<Setter.Value>
|
||||||
|
<ControlTemplate TargetType="local:DockingLayout">
|
||||||
|
<Grid>
|
||||||
|
<ContentPresenter x:Name="PART_Content" Content="{TemplateBinding RootPanel}" />
|
||||||
|
<Canvas x:Name="PART_OverlayCanvas" IsHitTestVisible="False">
|
||||||
|
<local:DockRegionHighlight x:Name="PART_Highlight" Visibility="Collapsed" />
|
||||||
|
</Canvas>
|
||||||
|
</Grid>
|
||||||
|
</ControlTemplate>
|
||||||
|
</Setter.Value>
|
||||||
|
</Setter>
|
||||||
|
</Style>
|
||||||
|
</ResourceDictionary>
|
||||||
Reference in New Issue
Block a user