From 09a58d0c146a45a14ebf7acfa4e0bf7e4699b91a Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Thu, 9 Jul 2020 12:58:39 -0300 Subject: [PATCH] realtive panel no longer cares about the declaration order. and measures to the largest child when not stretched. --- src/Avalonia.Controls/RelativePanel.cs | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/Avalonia.Controls/RelativePanel.cs b/src/Avalonia.Controls/RelativePanel.cs index 033a5559f5..07137e3d1a 100644 --- a/src/Avalonia.Controls/RelativePanel.cs +++ b/src/Avalonia.Controls/RelativePanel.cs @@ -16,12 +16,16 @@ namespace Avalonia.Controls protected override Size MeasureOverride(Size availableSize) { - foreach (var child in Children) + var maxSize = new Size(); + + foreach (var child in Children.OfType()) { - child?.Measure(availableSize); + child.Measure(availableSize); + maxSize = maxSize.WithWidth(Math.Max(maxSize.Width, child.DesiredSize.Width)); + maxSize = maxSize.WithHeight(Math.Max(maxSize.Height, child.DesiredSize.Height)); } - return availableSize; + return maxSize; } protected override Size ArrangeOverride(Size arrangeSize) @@ -183,11 +187,14 @@ namespace Avalonia.Controls _nodeDic.Clear(); } - public bool CheckCyclic() => CheckCyclic(_nodeDic.Values, null); + public bool CheckCyclic() => CheckCyclic(_nodeDic.Values, null, null); - private bool CheckCyclic(IEnumerable nodes, HashSet? set) + private bool CheckCyclic(IEnumerable nodes, GraphNode? waitNode, HashSet? set) { - set ??= new HashSet(); + if (set == null) + { + set = new HashSet(); + } foreach (var node in nodes) { @@ -206,9 +213,13 @@ namespace Avalonia.Controls if (!set.Add(node.Element)) return true; - return CheckCyclic(node.OutgoingNodes, set); + return CheckCyclic(node.OutgoingNodes, node.Arranged ? null : node, set); } + if (waitNode != null) + { + ArrangeChild(waitNode); + } return false; }