From 6b90c5c886bb97921e399bdad0279a748d60b596 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Thu, 5 Dec 2024 13:51:02 +0100 Subject: [PATCH] Add failing tests for #17699. --- .../Primitives/UniformGridTests.cs | 71 +++++++++++++++++++ tests/Avalonia.UnitTests/TestRoot.cs | 2 +- 2 files changed, 72 insertions(+), 1 deletion(-) diff --git a/tests/Avalonia.Controls.UnitTests/Primitives/UniformGridTests.cs b/tests/Avalonia.Controls.UnitTests/Primitives/UniformGridTests.cs index 340bd09611e..cbfdad43832 100644 --- a/tests/Avalonia.Controls.UnitTests/Primitives/UniformGridTests.cs +++ b/tests/Avalonia.Controls.UnitTests/Primitives/UniformGridTests.cs @@ -1,4 +1,5 @@ using Avalonia.Controls.Primitives; +using Avalonia.UnitTests; using Xunit; namespace Avalonia.Controls.UnitTests.Primitives @@ -140,5 +141,75 @@ public void Not_Visible_Children_Are_Ignored() // 2 * 2 grid Assert.Equal(new Size(2 * 50, 2 * 70), target.Bounds.Size); } + + [Fact] + public void Children_Do_Not_Overlap_With_125_Percent_Scaling_1() + { + // Issue #17699 + var target = new UniformGrid + { + Columns = 2, + Children = + { + new Border(), + new Border(), + new Border(), + new Border(), + } + }; + + var root = new TestRoot + { + LayoutScaling = 1.25, + Child = new Border + { + Width = 100, + Height = 100, + Child = target, + } + }; + + root.ExecuteInitialLayoutPass(); + + Assert.Equal(new(0, 0, 50.4, 50.4), target.Children[0].Bounds); + Assert.Equal(new(50.4, 0, 49.6, 50.4), target.Children[1].Bounds); + Assert.Equal(new(0, 50.4, 50.4, 49.6), target.Children[2].Bounds); + Assert.Equal(new(50.4, 50.4, 49.6, 49.6), target.Children[3].Bounds); + } + + [Fact] + public void Children_Do_Not_Overlap_With_125_Percent_Scaling_2() + { + // Issue #17699 + var target = new UniformGrid + { + Columns = 4, + Children = + { + new Border(), + new Border(), + new Border(), + new Border(), + } + }; + + var root = new TestRoot + { + LayoutScaling = 1.25, + Child = new Border + { + Width = 100, + Height = 100, + Child = target, + } + }; + + root.ExecuteInitialLayoutPass(); + + Assert.Equal(new(0, 0, 25.6, 100), target.Children[0].Bounds); + Assert.Equal(new(25.6, 0, 24.8, 100), target.Children[1].Bounds); + Assert.Equal(new(50.4, 0, 24.8, 100), target.Children[2].Bounds); + Assert.Equal(new(75.2, 0, 24.8, 100), target.Children[3].Bounds); + } } } diff --git a/tests/Avalonia.UnitTests/TestRoot.cs b/tests/Avalonia.UnitTests/TestRoot.cs index 788f2b3dae4..9ba304cab75 100644 --- a/tests/Avalonia.UnitTests/TestRoot.cs +++ b/tests/Avalonia.UnitTests/TestRoot.cs @@ -55,7 +55,7 @@ public TestRoot(bool useGlobalStyles, Control child) internal ILayoutManager LayoutManager { get; set; } ILayoutManager ILayoutRoot.LayoutManager => LayoutManager; - public double RenderScaling => 1; + public double RenderScaling => LayoutScaling; internal IRenderer Renderer { get; set; } internal IHitTester HitTester { get; set; }