From 46c93b70bf0af6498e937ae4f360eeb8ea429486 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Sat, 26 Mar 2016 19:58:13 +0100 Subject: [PATCH] Fix layout error. --- src/Perspex.Layout/Layoutable.cs | 6 ++---- tests/Perspex.Layout.UnitTests/ArrangeTests.cs | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/Perspex.Layout/Layoutable.cs b/src/Perspex.Layout/Layoutable.cs index 9caa836d30..4de6f59107 100644 --- a/src/Perspex.Layout/Layoutable.cs +++ b/src/Perspex.Layout/Layoutable.cs @@ -534,14 +534,12 @@ namespace Perspex.Layout if (horizontalAlignment != HorizontalAlignment.Stretch) { - size = size.WithWidth(Math.Min(size.Width, DesiredSize.Width) - - margin.Left - margin.Right); + size = size.WithWidth(Math.Min(size.Width, DesiredSize.Width - margin.Left - margin.Right)); } if (verticalAlignment != VerticalAlignment.Stretch) { - size = size.WithHeight(Math.Min(size.Height, DesiredSize.Height) - - margin.Top - margin.Bottom); + size = size.WithHeight(Math.Min(size.Height, DesiredSize.Height - margin.Top - margin.Bottom)); } size = LayoutHelper.ApplyLayoutConstraints(this, size); diff --git a/tests/Perspex.Layout.UnitTests/ArrangeTests.cs b/tests/Perspex.Layout.UnitTests/ArrangeTests.cs index ceb69ec8ca..e6f11b8c46 100644 --- a/tests/Perspex.Layout.UnitTests/ArrangeTests.cs +++ b/tests/Perspex.Layout.UnitTests/ArrangeTests.cs @@ -58,6 +58,23 @@ namespace Perspex.Layout.UnitTests Assert.Equal(new Size(184, 184), target.ArrangeFinalSize); } + [Fact] + public void ArrangeOverride_Receives_Requested_Size_When_Arranged_To_DesiredSize() + { + var target = new TestControl + { + MeasureResult = new Size(100, 100), + HorizontalAlignment = HorizontalAlignment.Center, + VerticalAlignment = VerticalAlignment.Center, + Margin = new Thickness(8), + }; + + target.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); + target.Arrange(new Rect(target.DesiredSize)); + + Assert.Equal(new Size(100, 100), target.ArrangeFinalSize); + } + [Fact] public void Arrange_With_IsMeasureValid_False_Calls_Measure() {