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