You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.7 KiB
62 lines
1.7 KiB
|
1 month ago
|
using System;
|
||
|
|
using Avalonia;
|
||
|
|
using Avalonia.Controls;
|
||
|
|
|
||
|
|
namespace AuroraDesk.Presentation.Controls;
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 垂直均匀分布子元素的面板,用于渲染节点左右侧连接点。
|
||
|
|
/// </summary>
|
||
|
|
public class ConnectorColumnPanel : Panel
|
||
|
|
{
|
||
|
|
protected override Size MeasureOverride(Size availableSize)
|
||
|
|
{
|
||
|
|
var maxWidth = 0d;
|
||
|
|
var totalHeight = 0d;
|
||
|
|
|
||
|
|
foreach (var child in Children)
|
||
|
|
{
|
||
|
|
child.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
|
||
|
|
var desired = child.DesiredSize;
|
||
|
|
maxWidth = Math.Max(maxWidth, desired.Width);
|
||
|
|
totalHeight += desired.Height;
|
||
|
|
}
|
||
|
|
|
||
|
|
var height = double.IsInfinity(availableSize.Height) ? totalHeight : availableSize.Height;
|
||
|
|
return new Size(maxWidth, height);
|
||
|
|
}
|
||
|
|
|
||
|
|
protected override Size ArrangeOverride(Size finalSize)
|
||
|
|
{
|
||
|
|
var count = Children.Count;
|
||
|
|
if (count == 0)
|
||
|
|
{
|
||
|
|
return finalSize;
|
||
|
|
}
|
||
|
|
|
||
|
|
var totalHeight = 0d;
|
||
|
|
foreach (var child in Children)
|
||
|
|
{
|
||
|
|
totalHeight += child.DesiredSize.Height;
|
||
|
|
}
|
||
|
|
|
||
|
|
var availableHeight = finalSize.Height;
|
||
|
|
var spacing = count > 0
|
||
|
|
? Math.Max(0, (availableHeight - totalHeight) / (count + 1))
|
||
|
|
: 0;
|
||
|
|
|
||
|
|
var currentY = spacing;
|
||
|
|
foreach (var child in Children)
|
||
|
|
{
|
||
|
|
var childHeight = child.DesiredSize.Height;
|
||
|
|
var childWidth = Math.Min(child.DesiredSize.Width, finalSize.Width);
|
||
|
|
var x = (finalSize.Width - childWidth) / 2;
|
||
|
|
child.Arrange(new Rect(x, currentY, childWidth, childHeight));
|
||
|
|
currentY += childHeight + spacing;
|
||
|
|
}
|
||
|
|
|
||
|
|
return finalSize;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|