|
|
@@ -518,17 +518,25 @@ namespace Avalonia.Layout
|
|
|
var width = measured.Width;
|
|
|
var height = measured.Height;
|
|
|
|
|
|
- if (!double.IsNaN(Width))
|
|
|
{
|
|
|
- width = Width;
|
|
|
+ double widthCache = Width;
|
|
|
+
|
|
|
+ if (!double.IsNaN(widthCache))
|
|
|
+ {
|
|
|
+ width = widthCache;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
width = Math.Min(width, MaxWidth);
|
|
|
width = Math.Max(width, MinWidth);
|
|
|
|
|
|
- if (!double.IsNaN(Height))
|
|
|
{
|
|
|
- height = Height;
|
|
|
+ double heightCache = Height;
|
|
|
+
|
|
|
+ if (!double.IsNaN(heightCache))
|
|
|
+ {
|
|
|
+ height = heightCache;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
height = Math.Min(height, MaxHeight);
|
|
|
@@ -562,11 +570,19 @@ namespace Avalonia.Layout
|
|
|
double width = 0;
|
|
|
double height = 0;
|
|
|
|
|
|
- foreach (ILayoutable child in this.GetVisualChildren())
|
|
|
+ var visualChildren = VisualChildren;
|
|
|
+ var visualCount = visualChildren.Count;
|
|
|
+
|
|
|
+ for (var i = 0; i < visualCount; i++)
|
|
|
{
|
|
|
- child.Measure(availableSize);
|
|
|
- width = Math.Max(width, child.DesiredSize.Width);
|
|
|
- height = Math.Max(height, child.DesiredSize.Height);
|
|
|
+ IVisual visual = visualChildren[i];
|
|
|
+
|
|
|
+ if (visual is ILayoutable layoutable)
|
|
|
+ {
|
|
|
+ layoutable.Measure(availableSize);
|
|
|
+ width = Math.Max(width, layoutable.DesiredSize.Width);
|
|
|
+ height = Math.Max(height, layoutable.DesiredSize.Height);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return new Size(width, height);
|
|
|
@@ -594,6 +610,7 @@ namespace Avalonia.Layout
|
|
|
var verticalAlignment = VerticalAlignment;
|
|
|
var size = availableSizeMinusMargins;
|
|
|
var scale = GetLayoutScale();
|
|
|
+ var useLayoutRounding = UseLayoutRounding;
|
|
|
|
|
|
if (horizontalAlignment != HorizontalAlignment.Stretch)
|
|
|
{
|
|
|
@@ -607,7 +624,7 @@ namespace Avalonia.Layout
|
|
|
|
|
|
size = LayoutHelper.ApplyLayoutConstraints(this, size);
|
|
|
|
|
|
- if (UseLayoutRounding)
|
|
|
+ if (useLayoutRounding)
|
|
|
{
|
|
|
size = new Size(
|
|
|
Math.Ceiling(size.Width * scale) / scale,
|
|
|
@@ -641,7 +658,7 @@ namespace Avalonia.Layout
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
- if (UseLayoutRounding)
|
|
|
+ if (useLayoutRounding)
|
|
|
{
|
|
|
originX = Math.Floor(originX * scale) / scale;
|
|
|
originY = Math.Floor(originY * scale) / scale;
|
|
|
@@ -658,9 +675,19 @@ namespace Avalonia.Layout
|
|
|
/// <returns>The actual size used.</returns>
|
|
|
protected virtual Size ArrangeOverride(Size finalSize)
|
|
|
{
|
|
|
- foreach (ILayoutable child in this.GetVisualChildren().OfType<ILayoutable>())
|
|
|
+ var arrangeRect = new Rect(finalSize);
|
|
|
+
|
|
|
+ var visualChildren = VisualChildren;
|
|
|
+ var visualCount = visualChildren.Count;
|
|
|
+
|
|
|
+ for (var i = 0; i < visualCount; i++)
|
|
|
{
|
|
|
- child.Arrange(new Rect(finalSize));
|
|
|
+ IVisual visual = visualChildren[i];
|
|
|
+
|
|
|
+ if (visual is ILayoutable layoutable)
|
|
|
+ {
|
|
|
+ layoutable.Arrange(arrangeRect);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return finalSize;
|