refactor(dock): extract UI creation helpers and use named constants
This commit is contained in:
@@ -15,6 +15,8 @@ namespace Ghost.Editor.View.Controls;
|
||||
public sealed partial class DockLayout : Control
|
||||
{
|
||||
private const string PART_ROOT_GRID = "PART_RootGrid";
|
||||
private const double MIN_PANE_SIZE = 100;
|
||||
private const double SPLITTER_THICKNESS = 4;
|
||||
|
||||
private readonly HashSet<DockNode> _subscribedNodes = new();
|
||||
|
||||
@@ -175,6 +177,19 @@ public sealed partial class DockLayout : Control
|
||||
private UIElement CreateUIForNode(DockNode node)
|
||||
{
|
||||
if (node is DockGroupNode groupNode)
|
||||
{
|
||||
return CreateGroupUI(groupNode);
|
||||
}
|
||||
else if (node is DockPanelNode panelNode)
|
||||
{
|
||||
return CreatePanelUI(panelNode);
|
||||
}
|
||||
|
||||
Debug.Fail($"Unsupported node type: {node.GetType().Name}");
|
||||
return new Grid(); // Fallback
|
||||
}
|
||||
|
||||
private UIElement CreateGroupUI(DockGroupNode groupNode)
|
||||
{
|
||||
var grid = new Grid();
|
||||
bool isHorizontal = groupNode.Orientation == Orientation.Horizontal;
|
||||
@@ -190,7 +205,7 @@ public sealed partial class DockLayout : Control
|
||||
grid.ColumnDefinitions.Add(new ColumnDefinition
|
||||
{
|
||||
Width = new GridLength(1, GridUnitType.Star),
|
||||
MinWidth = 100
|
||||
MinWidth = MIN_PANE_SIZE
|
||||
});
|
||||
Grid.SetColumn((FrameworkElement)childUI, i * 2);
|
||||
}
|
||||
@@ -199,7 +214,7 @@ public sealed partial class DockLayout : Control
|
||||
grid.RowDefinitions.Add(new RowDefinition
|
||||
{
|
||||
Height = new GridLength(1, GridUnitType.Star),
|
||||
MinHeight = 100
|
||||
MinHeight = MIN_PANE_SIZE
|
||||
});
|
||||
Grid.SetRow((FrameworkElement)childUI, i * 2);
|
||||
}
|
||||
@@ -214,7 +229,7 @@ public sealed partial class DockLayout : Control
|
||||
grid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });
|
||||
var splitter = new CommunityToolkit.WinUI.Controls.GridSplitter
|
||||
{
|
||||
Width = 4,
|
||||
Width = SPLITTER_THICKNESS,
|
||||
HorizontalAlignment = HorizontalAlignment.Center,
|
||||
ResizeDirection = CommunityToolkit.WinUI.Controls.GridSplitter.GridResizeDirection.Columns
|
||||
};
|
||||
@@ -226,7 +241,7 @@ public sealed partial class DockLayout : Control
|
||||
grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
|
||||
var splitter = new CommunityToolkit.WinUI.Controls.GridSplitter
|
||||
{
|
||||
Height = 4,
|
||||
Height = SPLITTER_THICKNESS,
|
||||
VerticalAlignment = VerticalAlignment.Center,
|
||||
ResizeDirection = CommunityToolkit.WinUI.Controls.GridSplitter.GridResizeDirection.Rows
|
||||
};
|
||||
@@ -238,7 +253,8 @@ public sealed partial class DockLayout : Control
|
||||
|
||||
return grid;
|
||||
}
|
||||
else if (node is DockPanelNode panelNode)
|
||||
|
||||
private UIElement CreatePanelUI(DockPanelNode panelNode)
|
||||
{
|
||||
var tabView = new Ghost.Editor.Controls.NavigationTabView
|
||||
{
|
||||
@@ -268,10 +284,6 @@ public sealed partial class DockLayout : Control
|
||||
return tabView;
|
||||
}
|
||||
|
||||
Debug.Fail($"Unsupported node type: {node.GetType().Name}");
|
||||
return new Grid(); // Fallback
|
||||
}
|
||||
|
||||
protected override void OnApplyTemplate()
|
||||
{
|
||||
base.OnApplyTemplate();
|
||||
|
||||
Reference in New Issue
Block a user