feat(dock): implement basic recursive tree renderer
This commit is contained in:
76
src/Editor/Ghost.Editor/View/Controls/DockLayout.cs
Normal file
76
src/Editor/Ghost.Editor/View/Controls/DockLayout.cs
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
using Ghost.Editor.Core.Controls.Internal.Docking;
|
||||||
|
using Microsoft.UI.Xaml;
|
||||||
|
using Microsoft.UI.Xaml.Controls;
|
||||||
|
|
||||||
|
namespace Ghost.Editor.View.Controls;
|
||||||
|
|
||||||
|
public sealed partial class DockLayout : Control
|
||||||
|
{
|
||||||
|
public DockLayout()
|
||||||
|
{
|
||||||
|
DefaultStyleKey = typeof(DockLayout);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DockGroupNode? Root
|
||||||
|
{
|
||||||
|
get => (DockGroupNode?)GetValue(RootProperty);
|
||||||
|
set => SetValue(RootProperty, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static readonly DependencyProperty RootProperty =
|
||||||
|
DependencyProperty.Register("Root", typeof(DockGroupNode), typeof(DockLayout), new PropertyMetadata(null, OnRootChanged));
|
||||||
|
|
||||||
|
private static void OnRootChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||||
|
{
|
||||||
|
if (d is DockLayout layout)
|
||||||
|
{
|
||||||
|
layout.RenderTree();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RenderTree()
|
||||||
|
{
|
||||||
|
if (GetTemplateChild("PART_RootGrid") is Grid rootGrid)
|
||||||
|
{
|
||||||
|
rootGrid.Children.Clear();
|
||||||
|
if (Root != null)
|
||||||
|
{
|
||||||
|
var ui = CreateUIForNode(Root);
|
||||||
|
rootGrid.Children.Add(ui);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private UIElement CreateUIForNode(DockNode node)
|
||||||
|
{
|
||||||
|
if (node is DockGroupNode groupNode)
|
||||||
|
{
|
||||||
|
// Simple visualizer for now, full grid logic in next step
|
||||||
|
var grid = new Grid();
|
||||||
|
foreach (var child in groupNode.Children)
|
||||||
|
{
|
||||||
|
grid.Children.Add(CreateUIForNode(child));
|
||||||
|
}
|
||||||
|
return grid;
|
||||||
|
}
|
||||||
|
else if (node is DockPanelNode panelNode)
|
||||||
|
{
|
||||||
|
// NOTE: NavigationTabView is expected to be implemented in a future task or exists in a namespace not yet fully visible.
|
||||||
|
// For now, we use a placeholder if it's not found, but the task specifies using it.
|
||||||
|
// If it fails to compile, I will check for the correct namespace.
|
||||||
|
return new Ghost.Editor.Controls.NavigationTabView
|
||||||
|
{
|
||||||
|
TabItemsSource = panelNode.Items,
|
||||||
|
HorizontalAlignment = HorizontalAlignment.Stretch,
|
||||||
|
VerticalAlignment = VerticalAlignment.Stretch
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return new Grid(); // Fallback
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnApplyTemplate()
|
||||||
|
{
|
||||||
|
base.OnApplyTemplate();
|
||||||
|
RenderTree();
|
||||||
|
}
|
||||||
|
}
|
||||||
15
src/Editor/Ghost.Editor/View/Controls/DockLayout.xaml
Normal file
15
src/Editor/Ghost.Editor/View/Controls/DockLayout.xaml
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<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">
|
||||||
|
<Style TargetType="local:DockLayout">
|
||||||
|
<Setter Property="Template">
|
||||||
|
<Setter.Value>
|
||||||
|
<ControlTemplate TargetType="local:DockLayout">
|
||||||
|
<Grid x:Name="PART_RootGrid" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" />
|
||||||
|
</ControlTemplate>
|
||||||
|
</Setter.Value>
|
||||||
|
</Setter>
|
||||||
|
</Style>
|
||||||
|
</ResourceDictionary>
|
||||||
Reference in New Issue
Block a user