Browse Source

upstream fix

916d3d12b2
pull/5783/head
Dan Walmsley 5 years ago
parent
commit
84bc8b682c
  1. 49
      src/Avalonia.Controls/RelativePanel.cs

49
src/Avalonia.Controls/RelativePanel.cs

@ -55,7 +55,10 @@ namespace Avalonia.Controls
_childGraph.Measure(availableSize);
_childGraph.Reset(false);
var boundingSize = _childGraph.GetBoundingSize(Width.IsNaN(), Height.IsNaN(), availableSize);
var calcWidth = Width.IsNaN() && HorizontalAlignment != HorizontalAlignment.Stretch;
var calcHeight = Height.IsNaN() && VerticalAlignment != VerticalAlignment.Stretch;
var boundingSize = _childGraph.GetBoundingSize(calcWidth, calcHeight);
_childGraph.Reset();
_childGraph.Measure(boundingSize);
return boundingSize;
@ -286,8 +289,6 @@ namespace Avalonia.Controls
private void MeasureChild(GraphNode node)
{
var availableSize = AvailableSize;
var child = node.Element;
child.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
node.OriginDesiredSize = child.DesiredSize;
@ -330,10 +331,10 @@ namespace Avalonia.Controls
: node.AlignBottomWithNode.Bottom * 0.5;
}
var availableHeight = availableSize.Height - node.Top - node.Bottom;
var availableHeight = AvailableSize.Height - node.Top - node.Bottom;
if (availableHeight.IsNaN())
{
availableHeight = availableSize.Height;
availableHeight = AvailableSize.Height;
if (!node.Top.IsNaN() && node.Bottom.IsNaN())
{
@ -345,10 +346,10 @@ namespace Avalonia.Controls
}
}
var availableWidth = availableSize.Width - node.Left - node.Right;
var availableWidth = AvailableSize.Width - node.Left - node.Right;
if (availableWidth.IsNaN())
{
availableWidth = availableSize.Width;
availableWidth = AvailableSize.Width;
if (!node.Left.IsNaN() && node.Right.IsNaN())
{
@ -382,7 +383,7 @@ namespace Avalonia.Controls
if (node.Left.IsNaN())
{
node.Left = availableSize.Width - node.RightOfNode.Right;
node.Left = AvailableSize.Width - node.RightOfNode.Right;
}
}
@ -395,14 +396,14 @@ namespace Avalonia.Controls
if (node.Top.IsNaN())
{
node.Top = availableSize.Height - node.BelowNode.Bottom;
node.Top = AvailableSize.Height - node.BelowNode.Bottom;
}
}
if (node.AlignHorizontalCenterWith != null)
{
var halfWidthLeft = (availableSize.Width + node.AlignHorizontalCenterWith.Left - node.AlignHorizontalCenterWith.Right - childSize.Width) * 0.5;
var halfWidthRight = (availableSize.Width - node.AlignHorizontalCenterWith.Left + node.AlignHorizontalCenterWith.Right - childSize.Width) * 0.5;
var halfWidthLeft = (AvailableSize.Width + node.AlignHorizontalCenterWith.Left - node.AlignHorizontalCenterWith.Right - childSize.Width) * 0.5;
var halfWidthRight = (AvailableSize.Width - node.AlignHorizontalCenterWith.Left + node.AlignHorizontalCenterWith.Right - childSize.Width) * 0.5;
if (node.Left.IsNaN())
node.Left = halfWidthLeft;
@ -417,8 +418,8 @@ namespace Avalonia.Controls
if (node.AlignVerticalCenterWith != null)
{
var halfHeightTop = (availableSize.Height + node.AlignVerticalCenterWith.Top - node.AlignVerticalCenterWith.Bottom - childSize.Height) * 0.5;
var halfHeightBottom = (availableSize.Height - node.AlignVerticalCenterWith.Top + node.AlignVerticalCenterWith.Bottom - childSize.Height) * 0.5;
var halfHeightTop = (AvailableSize.Height + node.AlignVerticalCenterWith.Top - node.AlignVerticalCenterWith.Bottom - childSize.Height) * 0.5;
var halfHeightBottom = (AvailableSize.Height - node.AlignVerticalCenterWith.Top + node.AlignVerticalCenterWith.Bottom - childSize.Height) * 0.5;
if (node.Top.IsNaN())
node.Top = halfHeightTop;
@ -433,7 +434,7 @@ namespace Avalonia.Controls
if (GetAlignHorizontalCenterWithPanel(child))
{
var halfSubWidth = (availableSize.Width - childSize.Width) * 0.5;
var halfSubWidth = (AvailableSize.Width - childSize.Width) * 0.5;
if (node.Left.IsNaN())
node.Left = halfSubWidth;
@ -448,7 +449,7 @@ namespace Avalonia.Controls
if (GetAlignVerticalCenterWithPanel(child))
{
var halfSubHeight = (availableSize.Height - childSize.Height) * 0.5;
var halfSubHeight = (AvailableSize.Height - childSize.Height) * 0.5;
if (node.Top.IsNaN())
node.Top = halfSubHeight;
@ -464,37 +465,37 @@ namespace Avalonia.Controls
if (node.Left.IsNaN())
{
if (!node.Right.IsNaN())
node.Left = availableSize.Width - node.Right - childSize.Width;
node.Left = AvailableSize.Width - node.Right - childSize.Width;
else
{
node.Left = 0;
node.Right = availableSize.Width - childSize.Width;
node.Right = AvailableSize.Width - childSize.Width;
}
}
else if (!node.Left.IsNaN() && node.Right.IsNaN())
{
node.Right = availableSize.Width - node.Left - childSize.Width;
node.Right = AvailableSize.Width - node.Left - childSize.Width;
}
if (node.Top.IsNaN())
{
if (!node.Bottom.IsNaN())
node.Top = availableSize.Height - node.Bottom - childSize.Height;
node.Top = AvailableSize.Height - node.Bottom - childSize.Height;
else
{
node.Top = 0;
node.Bottom = availableSize.Height - childSize.Height;
node.Bottom = AvailableSize.Height - childSize.Height;
}
}
else if (!node.Top.IsNaN() && node.Bottom.IsNaN())
{
node.Bottom = availableSize.Height - node.Top - childSize.Height;
node.Bottom = AvailableSize.Height - node.Top - childSize.Height;
}
node.Measured = true;
}
public Size GetBoundingSize(bool calcWidth, bool calcHeight, Size availableSize)
public Size GetBoundingSize(bool calcWidth, bool calcHeight)
{
var boundingSize = new Size();
@ -505,8 +506,8 @@ namespace Avalonia.Controls
boundingSize = boundingSize.WithHeight(Math.Max(boundingSize.Height, size.Height));
}
boundingSize = boundingSize.WithWidth(calcWidth ? Math.Max(availableSize.Width, boundingSize.Width) : availableSize.Width);
boundingSize = boundingSize.WithHeight(calcHeight ? Math.Max(availableSize.Height, boundingSize.Height) : availableSize.Height);
boundingSize = boundingSize.WithWidth(calcWidth ? boundingSize.Width : AvailableSize.Width);
boundingSize = boundingSize.WithHeight(calcHeight ? boundingSize.Height : AvailableSize.Height);
return boundingSize;
}
}

Loading…
Cancel
Save