fixed #784 and optimized MeasureChild method
This commit is contained in:
1 parent
f7ede3385b
commit
f4d4bdde10
1 file changed
+24
-22
@@ -218,7 +218,7 @@ namespace HandyControl.Controls
|
|||||||
#region Calc AvailableSize
|
#region Calc AvailableSize
|
||||||
|
|
||||||
_childGraph.Reset(false);
|
_childGraph.Reset(false);
|
||||||
var boundingSize = _childGraph.GetBoundingSize(Width.IsNaN(), Height.IsNaN());
|
var boundingSize = _childGraph.GetBoundingSize(Width.IsNaN(), Height.IsNaN(), availableSize);
|
||||||
_childGraph.Reset();
|
_childGraph.Reset();
|
||||||
_childGraph.Measure(boundingSize);
|
_childGraph.Measure(boundingSize);
|
||||||
return boundingSize;
|
return boundingSize;
|
||||||
@@ -454,6 +454,8 @@ namespace HandyControl.Controls
|
|||||||
|
|
||||||
private void MeasureChild(GraphNode node)
|
private void MeasureChild(GraphNode node)
|
||||||
{
|
{
|
||||||
|
var availableSize = AvailableSize;
|
||||||
|
|
||||||
var child = node.Element;
|
var child = node.Element;
|
||||||
child.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
|
child.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
|
||||||
node.OriginDesiredSize = child.DesiredSize;
|
node.OriginDesiredSize = child.DesiredSize;
|
||||||
@@ -502,10 +504,10 @@ namespace HandyControl.Controls
|
|||||||
|
|
||||||
#region Measure
|
#region Measure
|
||||||
|
|
||||||
var availableHeight = AvailableSize.Height - node.Top - node.Bottom;
|
var availableHeight = availableSize.Height - node.Top - node.Bottom;
|
||||||
if (availableHeight.IsNaN())
|
if (availableHeight.IsNaN())
|
||||||
{
|
{
|
||||||
availableHeight = AvailableSize.Height;
|
availableHeight = availableSize.Height;
|
||||||
|
|
||||||
if (!node.Top.IsNaN() && node.Bottom.IsNaN())
|
if (!node.Top.IsNaN() && node.Bottom.IsNaN())
|
||||||
{
|
{
|
||||||
@@ -517,10 +519,10 @@ namespace HandyControl.Controls
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var availableWidth = AvailableSize.Width - node.Left - node.Right;
|
var availableWidth = availableSize.Width - node.Left - node.Right;
|
||||||
if (availableWidth.IsNaN())
|
if (availableWidth.IsNaN())
|
||||||
{
|
{
|
||||||
availableWidth = AvailableSize.Width;
|
availableWidth = availableSize.Width;
|
||||||
|
|
||||||
if (!node.Left.IsNaN() && node.Right.IsNaN())
|
if (!node.Left.IsNaN() && node.Right.IsNaN())
|
||||||
{
|
{
|
||||||
@@ -558,7 +560,7 @@ namespace HandyControl.Controls
|
|||||||
|
|
||||||
if (node.Left.IsNaN())
|
if (node.Left.IsNaN())
|
||||||
{
|
{
|
||||||
node.Left = AvailableSize.Width - node.RightOfNode.Right;
|
node.Left = availableSize.Width - node.RightOfNode.Right;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -571,7 +573,7 @@ namespace HandyControl.Controls
|
|||||||
|
|
||||||
if (node.Top.IsNaN())
|
if (node.Top.IsNaN())
|
||||||
{
|
{
|
||||||
node.Top = AvailableSize.Height - node.BelowNode.Bottom;
|
node.Top = availableSize.Height - node.BelowNode.Bottom;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -581,8 +583,8 @@ namespace HandyControl.Controls
|
|||||||
|
|
||||||
if (node.AlignHorizontalCenterWith != null)
|
if (node.AlignHorizontalCenterWith != null)
|
||||||
{
|
{
|
||||||
var halfWidthLeft = (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;
|
var halfWidthRight = (availableSize.Width - node.AlignHorizontalCenterWith.Left + node.AlignHorizontalCenterWith.Right - childSize.Width) * 0.5;
|
||||||
|
|
||||||
if (node.Left.IsNaN()) node.Left = halfWidthLeft;
|
if (node.Left.IsNaN()) node.Left = halfWidthLeft;
|
||||||
else node.Left = (node.Left + halfWidthLeft) * 0.5;
|
else node.Left = (node.Left + halfWidthLeft) * 0.5;
|
||||||
@@ -593,8 +595,8 @@ namespace HandyControl.Controls
|
|||||||
|
|
||||||
if (node.AlignVerticalCenterWith != null)
|
if (node.AlignVerticalCenterWith != null)
|
||||||
{
|
{
|
||||||
var halfHeightTop = (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;
|
var halfHeightBottom = (availableSize.Height - node.AlignVerticalCenterWith.Top + node.AlignVerticalCenterWith.Bottom - childSize.Height) * 0.5;
|
||||||
|
|
||||||
if (node.Top.IsNaN()) node.Top = halfHeightTop;
|
if (node.Top.IsNaN()) node.Top = halfHeightTop;
|
||||||
else node.Top = (node.Top + halfHeightTop) * 0.5;
|
else node.Top = (node.Top + halfHeightTop) * 0.5;
|
||||||
@@ -609,7 +611,7 @@ namespace HandyControl.Controls
|
|||||||
|
|
||||||
if (GetAlignHorizontalCenterWithPanel(child))
|
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;
|
if (node.Left.IsNaN()) node.Left = halfSubWidth;
|
||||||
else node.Left = (node.Left + halfSubWidth) * 0.5;
|
else node.Left = (node.Left + halfSubWidth) * 0.5;
|
||||||
@@ -620,7 +622,7 @@ namespace HandyControl.Controls
|
|||||||
|
|
||||||
if (GetAlignVerticalCenterWithPanel(child))
|
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;
|
if (node.Top.IsNaN()) node.Top = halfSubHeight;
|
||||||
else node.Top = (node.Top + halfSubHeight) * 0.5;
|
else node.Top = (node.Top + halfSubHeight) * 0.5;
|
||||||
@@ -634,37 +636,37 @@ namespace HandyControl.Controls
|
|||||||
if (node.Left.IsNaN())
|
if (node.Left.IsNaN())
|
||||||
{
|
{
|
||||||
if (!node.Right.IsNaN())
|
if (!node.Right.IsNaN())
|
||||||
node.Left = AvailableSize.Width - node.Right - childSize.Width;
|
node.Left = availableSize.Width - node.Right - childSize.Width;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
node.Left = 0;
|
node.Left = 0;
|
||||||
node.Right = AvailableSize.Width - childSize.Width;
|
node.Right = availableSize.Width - childSize.Width;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (!node.Left.IsNaN() && node.Right.IsNaN())
|
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.Top.IsNaN())
|
||||||
{
|
{
|
||||||
if (!node.Bottom.IsNaN())
|
if (!node.Bottom.IsNaN())
|
||||||
node.Top = AvailableSize.Height - node.Bottom - childSize.Height;
|
node.Top = availableSize.Height - node.Bottom - childSize.Height;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
node.Top = 0;
|
node.Top = 0;
|
||||||
node.Bottom = AvailableSize.Height - childSize.Height;
|
node.Bottom = availableSize.Height - childSize.Height;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (!node.Top.IsNaN() && node.Bottom.IsNaN())
|
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;
|
node.Measured = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Size GetBoundingSize(bool calcWidth, bool calcHeight)
|
public Size GetBoundingSize(bool calcWidth, bool calcHeight, Size availableSize)
|
||||||
{
|
{
|
||||||
var boundingSize = new Size();
|
var boundingSize = new Size();
|
||||||
|
|
||||||
@@ -675,8 +677,8 @@ namespace HandyControl.Controls
|
|||||||
boundingSize.Height = Math.Max(boundingSize.Height, size.Height);
|
boundingSize.Height = Math.Max(boundingSize.Height, size.Height);
|
||||||
}
|
}
|
||||||
|
|
||||||
boundingSize.Width = calcWidth ? boundingSize.Width : AvailableSize.Width;
|
boundingSize.Width = calcWidth ? Math.Max(availableSize.Width, boundingSize.Width) : availableSize.Width;
|
||||||
boundingSize.Height = calcHeight ? boundingSize.Height : AvailableSize.Height;
|
boundingSize.Height = calcHeight ? Math.Max(availableSize.Height, boundingSize.Height) : availableSize.Height;
|
||||||
return boundingSize;
|
return boundingSize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user