From b2556d62f5e5c6869ef8baf890a5688d024a93e5 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Mon, 16 May 2022 11:40:25 +0200 Subject: [PATCH 1/2] Fix some layout rounding issues. Fixes for #8092: - Always round sizes up, not to the nearest pixel, thereby ensuring that `DesiredSize`s don't get rounded down where possible. - Apply rounding to `Padding` and `BorderThickness` in measure pass as well as arrange pass, to ensure that `DesiredSize` takes this rounding into account. --- src/Avalonia.Base/Layout/LayoutHelper.cs | 71 ++++++++- src/Avalonia.Base/Layout/Layoutable.cs | 24 +-- src/Avalonia.Base/Point.cs | 14 +- .../DataGridColumn.cs | 2 +- .../Presenters/ContentPresenter.cs | 4 +- .../Layout/LayoutableTests.cs | 31 ---- .../Layout/LayoutableTests_LayoutRounding.cs | 140 ++++++++++++++++++ .../Rendering/SceneGraph/SceneBuilderTests.cs | 1 + .../BorderTests.cs | 65 ++++++++ .../DecoratorTests.cs | 41 +++++ .../ContentPresenterTests_Layout.cs | 66 ++++++++- .../Primitives/TrackTests.cs | 4 +- tests/Avalonia.UnitTests/TestRoot.cs | 7 +- ...estrictedHeight_VerticalAlign.expected.png | Bin 752 -> 767 bytes ...estrictedHeight_VerticalAlign.expected.png | Bin 557 -> 532 bytes 15 files changed, 414 insertions(+), 56 deletions(-) create mode 100644 tests/Avalonia.Base.UnitTests/Layout/LayoutableTests_LayoutRounding.cs diff --git a/src/Avalonia.Base/Layout/LayoutHelper.cs b/src/Avalonia.Base/Layout/LayoutHelper.cs index d24be57d2b..404d19906a 100644 --- a/src/Avalonia.Base/Layout/LayoutHelper.cs +++ b/src/Avalonia.Base/Layout/LayoutHelper.cs @@ -36,11 +36,28 @@ namespace Avalonia.Layout public static Size MeasureChild(ILayoutable? control, Size availableSize, Thickness padding, Thickness borderThickness) { - return MeasureChild(control, availableSize, padding + borderThickness); + if (IsParentLayoutRounded(control, out double scale)) + { + padding = RoundLayoutThickness(padding, scale, scale); + borderThickness = RoundLayoutThickness(borderThickness, scale, scale); + } + + if (control != null) + { + control.Measure(availableSize.Deflate(padding + borderThickness)); + return control.DesiredSize.Inflate(padding + borderThickness); + } + + return new Size().Inflate(padding + borderThickness); } public static Size MeasureChild(ILayoutable? control, Size availableSize, Thickness padding) { + if (IsParentLayoutRounded(control, out double scale)) + { + padding = RoundLayoutThickness(padding, scale, scale); + } + if (control != null) { control.Measure(availableSize.Deflate(padding)); @@ -137,7 +154,7 @@ namespace Avalonia.Layout /// /// Rounds a size to integer values for layout purposes, compensating for high DPI screen - /// coordinates. + /// coordinates by rounding the size up to the nearest pixel. /// /// Input size. /// DPI along x-dimension. @@ -149,9 +166,9 @@ namespace Avalonia.Layout /// associated with the UseLayoutRounding property and should not be used as a general rounding /// utility. /// - public static Size RoundLayoutSize(Size size, double dpiScaleX, double dpiScaleY) + public static Size RoundLayoutSizeUp(Size size, double dpiScaleX, double dpiScaleY) { - return new Size(RoundLayoutValue(size.Width, dpiScaleX), RoundLayoutValue(size.Height, dpiScaleY)); + return new Size(RoundLayoutValueUp(size.Width, dpiScaleX), RoundLayoutValueUp(size.Height, dpiScaleY)); } /// @@ -178,10 +195,9 @@ namespace Avalonia.Layout ); } - - /// - /// Calculates the value to be used for layout rounding at high DPI. + /// Calculates the value to be used for layout rounding at high DPI by rounding the value + /// up or down to the nearest pixel. /// /// Input value to be rounded. /// Ratio of screen's DPI to layout DPI @@ -217,7 +233,46 @@ namespace Avalonia.Layout return newValue; } - + + /// + /// Calculates the value to be used for layout rounding at high DPI by rounding the value up + /// to the nearest pixel. + /// + /// Input value to be rounded. + /// Ratio of screen's DPI to layout DPI + /// Adjusted value that will produce layout rounding on screen at high dpi. + /// + /// This is a layout helper method. It takes DPI into account and also does not return + /// the rounded value if it is unacceptable for layout, e.g. Infinity or NaN. It's a helper + /// associated with the UseLayoutRounding property and should not be used as a general rounding + /// utility. + /// + public static double RoundLayoutValueUp(double value, double dpiScale) + { + double newValue; + + // If DPI == 1, don't use DPI-aware rounding. + if (!MathUtilities.IsOne(dpiScale)) + { + newValue = Math.Ceiling(value * dpiScale) / dpiScale; + + // If rounding produces a value unacceptable to layout (NaN, Infinity or MaxValue), + // use the original value. + if (double.IsNaN(newValue) || + double.IsInfinity(newValue) || + MathUtilities.AreClose(newValue, double.MaxValue)) + { + newValue = value; + } + } + else + { + newValue = Math.Ceiling(value); + } + + return newValue; + } + /// /// Calculates the min and max height for a control. Ported from WPF. /// diff --git a/src/Avalonia.Base/Layout/Layoutable.cs b/src/Avalonia.Base/Layout/Layoutable.cs index df7aa937a0..0b74d5915a 100644 --- a/src/Avalonia.Base/Layout/Layoutable.cs +++ b/src/Avalonia.Base/Layout/Layoutable.cs @@ -549,6 +549,14 @@ namespace Avalonia.Layout if (IsVisible) { var margin = Margin; + var useLayoutRounding = UseLayoutRounding; + var scale = 1.0; + + if (useLayoutRounding) + { + scale = LayoutHelper.GetLayoutScale(this); + margin = LayoutHelper.RoundLayoutThickness(margin, scale, scale); + } ApplyStyling(); ApplyTemplate(); @@ -585,16 +593,14 @@ namespace Avalonia.Layout height = Math.Min(height, MaxHeight); height = Math.Max(height, MinHeight); - width = Math.Min(width, availableSize.Width); - height = Math.Min(height, availableSize.Height); - - if (UseLayoutRounding) + if (useLayoutRounding) { - var scale = LayoutHelper.GetLayoutScale(this); - width = LayoutHelper.RoundLayoutValue(width, scale); - height = LayoutHelper.RoundLayoutValue(height, scale); + (width, height) = LayoutHelper.RoundLayoutSizeUp(new Size(width, height), scale, scale); } + width = Math.Min(width, availableSize.Width); + height = Math.Min(height, availableSize.Height); + return NonNegative(new Size(width, height).Inflate(margin)); } else @@ -679,8 +685,8 @@ namespace Avalonia.Layout if (useLayoutRounding) { - size = LayoutHelper.RoundLayoutSize(size, scale, scale); - availableSizeMinusMargins = LayoutHelper.RoundLayoutSize(availableSizeMinusMargins, scale, scale); + size = LayoutHelper.RoundLayoutSizeUp(size, scale, scale); + availableSizeMinusMargins = LayoutHelper.RoundLayoutSizeUp(availableSizeMinusMargins, scale, scale); } size = ArrangeOverride(size).Constrain(size); diff --git a/src/Avalonia.Base/Point.cs b/src/Avalonia.Base/Point.cs index 67e7d71fbc..2f226caff4 100644 --- a/src/Avalonia.Base/Point.cs +++ b/src/Avalonia.Base/Point.cs @@ -192,7 +192,7 @@ namespace Avalonia } /// - /// Returns a boolean indicating whether the point is equal to the other given point. + /// Returns a boolean indicating whether the point is equal to the other given point (bitwise). /// /// The other point to test equality against. /// True if this point is equal to other; False otherwise. @@ -204,6 +204,18 @@ namespace Avalonia // ReSharper enable CompareOfFloatsByEqualityOperator } + /// + /// Returns a boolean indicating whether the point is equal to the other given point + /// (numerically). + /// + /// The other point to test equality against. + /// True if this point is equal to other; False otherwise. + public bool NearlyEquals(Point other) + { + return MathUtilities.AreClose(_x, other._x) && + MathUtilities.AreClose(_y, other._y); + } + /// /// Checks for equality between a point and an object. /// diff --git a/src/Avalonia.Controls.DataGrid/DataGridColumn.cs b/src/Avalonia.Controls.DataGrid/DataGridColumn.cs index f3ea48ff80..c415f477d4 100644 --- a/src/Avalonia.Controls.DataGrid/DataGridColumn.cs +++ b/src/Avalonia.Controls.DataGrid/DataGridColumn.cs @@ -855,7 +855,7 @@ namespace Avalonia.Controls if (OwningGrid != null && OwningGrid.UseLayoutRounding) { var scale = LayoutHelper.GetLayoutScale(HeaderCell); - var roundSize = LayoutHelper.RoundLayoutSize(new Size(leftEdge + ActualWidth, 1), scale, scale); + var roundSize = LayoutHelper.RoundLayoutSizeUp(new Size(leftEdge + ActualWidth, 1), scale, scale); LayoutRoundedWidth = roundSize.Width - leftEdge; } else diff --git a/src/Avalonia.Controls/Presenters/ContentPresenter.cs b/src/Avalonia.Controls/Presenters/ContentPresenter.cs index 996cb29534..c67678837b 100644 --- a/src/Avalonia.Controls/Presenters/ContentPresenter.cs +++ b/src/Avalonia.Controls/Presenters/ContentPresenter.cs @@ -635,8 +635,8 @@ namespace Avalonia.Controls.Presenters if (useLayoutRounding) { - sizeForChild = LayoutHelper.RoundLayoutSize(sizeForChild, scale, scale); - availableSize = LayoutHelper.RoundLayoutSize(availableSize, scale, scale); + sizeForChild = LayoutHelper.RoundLayoutSizeUp(sizeForChild, scale, scale); + availableSize = LayoutHelper.RoundLayoutSizeUp(availableSize, scale, scale); } switch (horizontalContentAlignment) diff --git a/tests/Avalonia.Base.UnitTests/Layout/LayoutableTests.cs b/tests/Avalonia.Base.UnitTests/Layout/LayoutableTests.cs index 87fa8cf1f3..f5adaf904e 100644 --- a/tests/Avalonia.Base.UnitTests/Layout/LayoutableTests.cs +++ b/tests/Avalonia.Base.UnitTests/Layout/LayoutableTests.cs @@ -173,37 +173,6 @@ namespace Avalonia.Base.UnitTests.Layout target.Verify(x => x.InvalidateMeasure(root), Times.Once()); } - [Theory] - [InlineData(16, 6, 5.333333333333333)] - [InlineData(18, 10, 4)] - public void UseLayoutRounding_Arranges_Center_Alignment_Correctly_With_Fractional_Scaling( - double containerWidth, - double childWidth, - double expectedX) - { - Border target; - var root = new TestRoot - { - LayoutScaling = 1.5, - UseLayoutRounding = true, - Child = new Decorator - { - Width = containerWidth, - Height = 100, - Child = target = new Border - { - Width = childWidth, - HorizontalAlignment = HorizontalAlignment.Center, - } - } - }; - - root.Measure(new Size(100, 100)); - root.Arrange(new Rect(target.DesiredSize)); - - Assert.Equal(new Rect(expectedX, 0, childWidth, 100), target.Bounds); - } - [Fact] public void LayoutUpdated_Is_Called_At_End_Of_Layout_Pass() { diff --git a/tests/Avalonia.Base.UnitTests/Layout/LayoutableTests_LayoutRounding.cs b/tests/Avalonia.Base.UnitTests/Layout/LayoutableTests_LayoutRounding.cs new file mode 100644 index 0000000000..77f1a8882d --- /dev/null +++ b/tests/Avalonia.Base.UnitTests/Layout/LayoutableTests_LayoutRounding.cs @@ -0,0 +1,140 @@ +using Avalonia.Controls; +using Avalonia.Layout; +using Avalonia.UnitTests; +using Xunit; +using Xunit.Sdk; + +namespace Avalonia.Base.UnitTests.Layout +{ + public class LayoutableTests_LayoutRounding + { + [Theory] + [InlineData(100, 100)] + [InlineData(101, 101.33333333333333)] + [InlineData(103, 103.33333333333333)] + public void Measure_Adjusts_DesiredSize_Upwards_When_Constraint_Allows(double desiredSize, double expectedSize) + { + var target = new TestLayoutable(new Size(desiredSize, desiredSize)); + var root = CreateRoot(1.5, target); + + root.LayoutManager.ExecuteInitialLayoutPass(); + + Assert.Equal(new Size(expectedSize, expectedSize), target.DesiredSize); + } + + [Fact] + public void Measure_Constrains_Adjusted_DesiredSize_To_Constraint() + { + var target = new TestLayoutable(new Size(101, 101)); + var root = CreateRoot(1.5, target, constraint: new Size(101, 101)); + + root.LayoutManager.ExecuteInitialLayoutPass(); + + // Desired width/height with layout rounding is 101.3333 but constraint is 101,101 so + // layout rounding should be ignored. + Assert.Equal(new Size(101, 101), target.DesiredSize); + } + + [Fact] + public void Measure_Adjusts_DesiredSize_Upwards_When_Margin_Present() + { + var target = new TestLayoutable(new Size(101, 101), margin: 1); + var root = CreateRoot(1.5, target); + + root.LayoutManager.ExecuteInitialLayoutPass(); + + // - 1 pixel margin is rounded up to 1.3333; for both sides it is 2.6666 + // - Size of 101 gets rounded up to 101.3333 + // - Final size = 101.3333 + 2.6666 = 104 + AssertEqual(new Size(104, 104), target.DesiredSize); + } + + [Fact] + public void Arrange_Adjusts_Bounds_Upwards_With_Margin() + { + var target = new TestLayoutable(new Size(101, 101), margin: 1); + var root = CreateRoot(1.5, target); + + root.LayoutManager.ExecuteInitialLayoutPass(); + + // - 1 pixel margin is rounded up to 1.3333 + // - Size of 101 gets rounded up to 101.3333 + AssertEqual(new Point(1.3333333333333333, 1.3333333333333333), target.Bounds.Position); + AssertEqual(new Size(101.33333333333333, 101.33333333333333), target.Bounds.Size); + } + + [Theory] + [InlineData(16, 6, 5.333333333333333)] + [InlineData(18, 10, 4)] + public void Arranges_Center_Alignment_Correctly_With_Fractional_Scaling( + double containerWidth, + double childWidth, + double expectedX) + { + Border target; + var root = new TestRoot + { + LayoutScaling = 1.5, + UseLayoutRounding = true, + Child = new Decorator + { + Width = containerWidth, + Height = 100, + Child = target = new Border + { + Width = childWidth, + HorizontalAlignment = HorizontalAlignment.Center, + } + } + }; + + root.Measure(new Size(100, 100)); + root.Arrange(new Rect(target.DesiredSize)); + + Assert.Equal(new Rect(expectedX, 0, childWidth, 100), target.Bounds); + } + + private static TestRoot CreateRoot( + double scaling, + Control child, + Size? constraint = null) + { + return new TestRoot + { + LayoutScaling = scaling, + UseLayoutRounding = true, + Child = child, + ClientSize = constraint ?? new Size(1000, 1000), + }; + } + + private static void AssertEqual(Point expected, Point actual) + { + if (!expected.NearlyEquals(actual)) + { + throw new EqualException(expected, actual); + } + } + + private static void AssertEqual(Size expected, Size actual) + { + if (!expected.NearlyEquals(actual)) + { + throw new EqualException(expected, actual); + } + } + + private class TestLayoutable : Control + { + private Size _desiredSize; + + public TestLayoutable(Size desiredSize, double margin = 0) + { + _desiredSize = desiredSize; + Margin = new Thickness(margin); + } + + protected override Size MeasureOverride(Size availableSize) => _desiredSize; + } + } +} diff --git a/tests/Avalonia.Base.UnitTests/Rendering/SceneGraph/SceneBuilderTests.cs b/tests/Avalonia.Base.UnitTests/Rendering/SceneGraph/SceneBuilderTests.cs index 01afe85b8b..be873c4b67 100644 --- a/tests/Avalonia.Base.UnitTests/Rendering/SceneGraph/SceneBuilderTests.cs +++ b/tests/Avalonia.Base.UnitTests/Rendering/SceneGraph/SceneBuilderTests.cs @@ -805,6 +805,7 @@ namespace Avalonia.Base.UnitTests.Rendering.SceneGraph Canvas canvas; var tree = new TestRoot { + ClientSize = new Size(100, 100), Child = decorator = new Decorator { Margin = new Thickness(0, 10, 0, 0), diff --git a/tests/Avalonia.Controls.UnitTests/BorderTests.cs b/tests/Avalonia.Controls.UnitTests/BorderTests.cs index ab33eaaff9..7af7d1cee2 100644 --- a/tests/Avalonia.Controls.UnitTests/BorderTests.cs +++ b/tests/Avalonia.Controls.UnitTests/BorderTests.cs @@ -1,6 +1,8 @@ +using Avalonia.Layout; using Avalonia.Media; using Avalonia.Rendering; using Avalonia.UnitTests; +using Avalonia.VisualTree; using Moq; using Xunit; @@ -60,5 +62,68 @@ namespace Avalonia.Controls.UnitTests renderer.Verify(x => x.AddDirty(target), Times.Once); } + + public class UseLayoutRounding + { + [Fact] + public void Measure_Rounds_Padding() + { + var target = new Border + { + Padding = new Thickness(1), + Child = new Canvas + { + Width = 101, + Height = 101, + } + }; + + var root = CreatedRoot(1.5, target); + + root.LayoutManager.ExecuteInitialLayoutPass(); + + // - 1 pixel padding is rounded up to 1.3333; for both sides it is 2.6666 + // - Size of 101 gets rounded up to 101.3333 + // - Desired size = 101.3333 + 2.6666 = 104 + Assert.Equal(new Size(104, 104), target.DesiredSize); + } + + [Fact] + public void Measure_Rounds_BorderThickness() + { + var target = new Border + { + BorderThickness = new Thickness(1), + Child = new Canvas + { + Width = 101, + Height = 101, + } + }; + + var root = CreatedRoot(1.5, target); + + root.LayoutManager.ExecuteInitialLayoutPass(); + + // - 1 pixel border thickness is rounded up to 1.3333; for both sides it is 2.6666 + // - Size of 101 gets rounded up to 101.3333 + // - Desired size = 101.3333 + 2.6666 = 104 + Assert.Equal(new Size(104, 104), target.DesiredSize); + } + + private static TestRoot CreatedRoot( + double scaling, + Control child, + Size? constraint = null) + { + return new TestRoot + { + LayoutScaling = scaling, + UseLayoutRounding = true, + Child = child, + ClientSize = constraint ?? new Size(1000, 1000), + }; + } + } } } diff --git a/tests/Avalonia.Controls.UnitTests/DecoratorTests.cs b/tests/Avalonia.Controls.UnitTests/DecoratorTests.cs index 65749efbf9..fe58cd4c7f 100644 --- a/tests/Avalonia.Controls.UnitTests/DecoratorTests.cs +++ b/tests/Avalonia.Controls.UnitTests/DecoratorTests.cs @@ -1,6 +1,7 @@ using System.Collections.Specialized; using System.Linq; using Avalonia.LogicalTree; +using Avalonia.UnitTests; using Xunit; namespace Avalonia.Controls.UnitTests @@ -116,5 +117,45 @@ namespace Avalonia.Controls.UnitTests Assert.Equal(new Size(16, 16), target.DesiredSize); } + + public class UseLayoutRounding + { + [Fact] + public void Measure_Rounds_Padding() + { + var target = new Decorator + { + Padding = new Thickness(1), + Child = new Canvas + { + Width = 101, + Height = 101, + } + }; + + var root = CreatedRoot(1.5, target); + + root.LayoutManager.ExecuteInitialLayoutPass(); + + // - 1 pixel padding is rounded up to 1.3333; for both sides it is 2.6666 + // - Size of 101 gets rounded up to 101.3333 + // - Desired size = 101.3333 + 2.6666 = 104 + Assert.Equal(new Size(104, 104), target.DesiredSize); + } + + private static TestRoot CreatedRoot( + double scaling, + Control child, + Size? constraint = null) + { + return new TestRoot + { + LayoutScaling = scaling, + UseLayoutRounding = true, + Child = child, + ClientSize = constraint ?? new Size(1000, 1000), + }; + } + } } } diff --git a/tests/Avalonia.Controls.UnitTests/Presenters/ContentPresenterTests_Layout.cs b/tests/Avalonia.Controls.UnitTests/Presenters/ContentPresenterTests_Layout.cs index ed44fbfc32..e82050528f 100644 --- a/tests/Avalonia.Controls.UnitTests/Presenters/ContentPresenterTests_Layout.cs +++ b/tests/Avalonia.Controls.UnitTests/Presenters/ContentPresenterTests_Layout.cs @@ -1,5 +1,6 @@ using Avalonia.Controls.Presenters; using Avalonia.Layout; +using Avalonia.UnitTests; using Xunit; namespace Avalonia.Controls.UnitTests.Presenters @@ -232,5 +233,68 @@ namespace Avalonia.Controls.UnitTests.Presenters Assert.Equal(new Rect(32, 32, 0, 0), content.Bounds); } + + public class UseLayoutRounding + { + [Fact] + public void Measure_Rounds_Padding() + { + var target = new ContentPresenter + { + Padding = new Thickness(1), + Content = new Canvas + { + Width = 101, + Height = 101, + } + }; + + var root = CreatedRoot(1.5, target); + + root.LayoutManager.ExecuteInitialLayoutPass(); + + // - 1 pixel padding is rounded up to 1.3333; for both sides it is 2.6666 + // - Size of 101 gets rounded up to 101.3333 + // - Desired size = 101.3333 + 2.6666 = 104 + Assert.Equal(new Size(104, 104), target.DesiredSize); + } + + [Fact] + public void Measure_Rounds_BorderThickness() + { + var target = new ContentPresenter + { + BorderThickness = new Thickness(1), + Content = new Canvas + { + Width = 101, + Height = 101, + } + }; + + var root = CreatedRoot(1.5, target); + + root.LayoutManager.ExecuteInitialLayoutPass(); + + // - 1 pixel border thickness is rounded up to 1.3333; for both sides it is 2.6666 + // - Size of 101 gets rounded up to 101.3333 + // - Desired size = 101.3333 + 2.6666 = 104 + Assert.Equal(new Size(104, 104), target.DesiredSize); + } + + private static TestRoot CreatedRoot( + double scaling, + Control child, + Size? constraint = null) + { + return new TestRoot + { + LayoutScaling = scaling, + UseLayoutRounding = true, + Child = child, + ClientSize = constraint ?? new Size(1000, 1000), + }; + } + } } -} \ No newline at end of file +} diff --git a/tests/Avalonia.Controls.UnitTests/Primitives/TrackTests.cs b/tests/Avalonia.Controls.UnitTests/Primitives/TrackTests.cs index 59276a94d0..f4001a8ca1 100644 --- a/tests/Avalonia.Controls.UnitTests/Primitives/TrackTests.cs +++ b/tests/Avalonia.Controls.UnitTests/Primitives/TrackTests.cs @@ -67,7 +67,7 @@ namespace Avalonia.Controls.UnitTests.Primitives target.Measure(new Size(100, 100)); target.Arrange(new Rect(0, 0, 100, 100)); - Assert.Equal(new Rect(33, 0, 33, 12), thumb.Bounds); + Assert.Equal(new Rect(33, 0, 34, 12), thumb.Bounds); } [Fact] @@ -92,7 +92,7 @@ namespace Avalonia.Controls.UnitTests.Primitives target.Measure(new Size(100, 100)); target.Arrange(new Rect(0, 0, 100, 100)); - Assert.Equal(new Rect(0, 33, 12, 33), thumb.Bounds); + Assert.Equal(new Rect(0, 33, 12, 34), thumb.Bounds); } [Fact] diff --git a/tests/Avalonia.UnitTests/TestRoot.cs b/tests/Avalonia.UnitTests/TestRoot.cs index 4601dd7e5b..41e29a85c4 100644 --- a/tests/Avalonia.UnitTests/TestRoot.cs +++ b/tests/Avalonia.UnitTests/TestRoot.cs @@ -41,7 +41,7 @@ namespace Avalonia.UnitTests Child = child; } - public Size ClientSize { get; set; } = new Size(100, 100); + public Size ClientSize { get; set; } = new Size(1000, 1000); public Size MaxClientSize { get; set; } = Size.Infinity; @@ -110,5 +110,10 @@ namespace Avalonia.UnitTests } Visit(this, true); } + + protected override Size MeasureOverride(Size availableSize) + { + return base.MeasureOverride(ClientSize); + } } } diff --git a/tests/TestFiles/Direct2D1/Controls/TextBlock/RestrictedHeight_VerticalAlign.expected.png b/tests/TestFiles/Direct2D1/Controls/TextBlock/RestrictedHeight_VerticalAlign.expected.png index e8624fa457f37565fdc483c474424991e7b696d3..8ca7acb845855a306af678ca22bf356780b0cba5 100644 GIT binary patch delta 679 zcmV;Y0$Ba<1^)$*K~kwnL_t(|UhUekZWBQe#_=;P6++?#fR>V$0tr#VYaoFHqUQ}j zqTo5`httHZz&q=s2Hqv))HO`Y32D$yLd9>u&fZ`DxwlC}=FnUCDFn zb~hwfB%e-?y6(N?m3510L7y(9cZxMYmZy?;*7ZBU6*{8087t3497`|8dQtY)w2jpd zI48ECk8!M=KM(V@`+Pai$bR5kf9XB6Z)|uhd2QVdQz!pLdV0cBZb@`8HRag;K+M;? z;aHdSi`N5*K2`Hla({5Vt(ZOZ#NSvK4$N0EeFe#vL8PG9QqUXUpNcg}-LZ0FO;UF( z=Ij4hlf?awSyyP(qe}|-ZJRF&dLiyeK3W$J+vcl@g4WHd?g*yxM3N(Nf2xO0VUmpqHFGSJWiy@&1&RWbC@rm ztb!hX=IF_7iN`(3BkN9*wOMz~y2TtNqsE0K)nnFRNDefgl-zmV71Czl57L(8d1Q-wI5&g@gbA N002ovPDHLkV1j5cRr>${ delta 663 zcmV;I0%-mJ1@HxsK~kDYL_t(|UhUgIa??N*$8nhhgpv-9Kst&PbZ~-{bWo>HI%eP$ zbliY0bTFi#WQHbHCZVECE@0mCYC&Ev)~@tc(Vy>U=9gVr&L&sF5? z2a=zgt*ZJWIdk3Ow4gWZj_kMw*zr#C&2{Yze1z^>+>Eo|l*ZA6u^yCDYTA#}F7b|b z1-+DUQlBp7XTR-n+9lr6_JMtu-Y0j%e~v?mF0?|+c*2;U(Dpd(9@K4;4-y?YmRFK4 z^g(@eT|_WHMd&L`zBFy;-KXYy|(KU{b8zDnNKxsvFW zH-0;ezHL90^u_#aD^}3IBtx9|jEVjQPyh0jnrD(F8Df4|Lt|DbXw1sJ6tu3b_2LwN zfr_3W`0X%Otk(2a znEu5s`c3DXRyVzJM1r%nkRJ0aMM(FjDeD5@R(^af#<|TF^PCdjI796AKN{2Wx1| x3I&Z>NnUc)osL*?lhFbeli&gb8GzoZ>JL{KmA-v_Vov}7002ovPDHLkV1ik5Q|$l% diff --git a/tests/TestFiles/Skia/Controls/TextBlock/RestrictedHeight_VerticalAlign.expected.png b/tests/TestFiles/Skia/Controls/TextBlock/RestrictedHeight_VerticalAlign.expected.png index 7bd622050e00416936f55efbc6d96232c67bd8c8..a76c6a5b2a824ec785875d92dd0b38407e3049c3 100644 GIT binary patch delta 490 zcmZ3>GKFP=N&RV07srr_IdAW5%)1;Q!uDXlX#W9ggKvom4qEyL4~4P0&0{{ck2_jY zz?fNE$h%Z>(W=lXQ?j31ZCk(J|C5mA@slS#KgDbNF)^S4hwFN;%CwgrT&UI0`gre( zyBn{Z`^PAr`Jt|XYkILgL&iym%_{3BPpMbF-QIRwbLpF=FDusivZW`ln|z07Z}8Ve zAHMMX-Jp@P^FYYz`%&?e|M>j%d7pLG=tA@w(@X6Ni@OMP+s%{|8UZRef2 zOxJB?{S~_W*Ou5%Gj2?N7|#)W?H1GDRgZPpV+}8q9Cgq?Fkj{U;Tz2DaF{%vno$(gm^S9kO54e|f1`v3Z(cq0>#J*i*%C*Mn*p3gV8zGmi= zcRgFP)>dv@6<_N1-{NIR@src0`e9#J_nmMI=P`-C@@dwgWy2)Tif!}f*BA9YQBr<>Yv<0+ed$LhGhl$6qoFtRV$DAqv>tEFoHy;= zjj8AUHLmvgqjP}4f0`Ym-l@|ncRSzK*B<`-V%Iyxa-Mt3j*FJP@}0!LwOcIxMdrlE z`EBc_9=&?AZmz%QzU4W~PG3(r%l<3q)s%g)(bchAU-i5`|6g~~!uOv(cvj{7-f@I; zZO^|R^Na=Arn~kV?eHzSTz#h~bwk)M4ct2k#G&)%(W*Dsx)C6j$|eyBU2 z#3_f(+TH&xR=QqWGxcS(?x8Q~dmJTy>788NygzpSjqgWi)>y6GoVM2Iepc=R`^UZi z3We58xyrynyb(IzS%pj{N(kv(qntpW!+KP9r*m+Cc8U!>XmlI yb8njNTQ2ZS)p@fv+pJj4eL2tLs~9ojqI);H&U7`F+X Date: Mon, 16 May 2022 17:08:53 +0200 Subject: [PATCH 2/2] Fix comparison. --- .../Converters/MenuScrollingVisibilityConverter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Avalonia.Controls/Converters/MenuScrollingVisibilityConverter.cs b/src/Avalonia.Controls/Converters/MenuScrollingVisibilityConverter.cs index 6ab2f4c517..9d859a753a 100644 --- a/src/Avalonia.Controls/Converters/MenuScrollingVisibilityConverter.cs +++ b/src/Avalonia.Controls/Converters/MenuScrollingVisibilityConverter.cs @@ -26,7 +26,7 @@ namespace Avalonia.Controls.Converters if (visibility == ScrollBarVisibility.Auto) { - if (extent == viewport) + if (MathUtilities.AreClose(extent, viewport)) { return false; }