From bda11dfdf1b557664531eaaef79bdd17af53b52a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Su=C3=A1rez?= Date: Tue, 4 Apr 2023 16:39:43 +0200 Subject: [PATCH 1/8] Fix Border corners clipping mistake on Windows --- .../BorderGalleries/BorderClipPlayground.xaml | 9 +++--- src/Core/src/Platform/Windows/ContentPanel.cs | 31 +++++++++++++------ .../src/Platform/Windows/StrokeExtensions.cs | 6 ++-- .../net-windows/PublicAPI.Shipped.txt | 1 - .../net-windows/PublicAPI.Unshipped.txt | 1 + 5 files changed, 30 insertions(+), 18 deletions(-) diff --git a/src/Controls/samples/Controls.Sample/Pages/Core/BorderGalleries/BorderClipPlayground.xaml b/src/Controls/samples/Controls.Sample/Pages/Core/BorderGalleries/BorderClipPlayground.xaml index f5ea28b6079b..1fa74b102257 100644 --- a/src/Controls/samples/Controls.Sample/Pages/Core/BorderGalleries/BorderClipPlayground.xaml +++ b/src/Controls/samples/Controls.Sample/Pages/Core/BorderGalleries/BorderClipPlayground.xaml @@ -17,13 +17,14 @@ - + - + diff --git a/src/Core/src/Platform/Windows/ContentPanel.cs b/src/Core/src/Platform/Windows/ContentPanel.cs index f1099f84db34..977c2cb1580d 100644 --- a/src/Core/src/Platform/Windows/ContentPanel.cs +++ b/src/Core/src/Platform/Windows/ContentPanel.cs @@ -15,7 +15,7 @@ namespace Microsoft.Maui.Platform public class ContentPanel : Panel { readonly Path? _borderPath; - IShape? _borderShape; + IBorderStroke? _borderStroke; FrameworkElement? _content; internal Path? BorderPath => _borderPath; @@ -75,9 +75,9 @@ void ContentPanelSizeChanged(object sender, UI.Xaml.SizeChangedEventArgs e) if (_borderPath == null) return; - _borderPath.UpdatePath(_borderShape, ActualWidth, ActualHeight); + _borderPath.UpdatePath(_borderStroke?.Shape, ActualWidth, ActualHeight); UpdateContent(); - UpdateClip(_borderShape); + UpdateClip(_borderStroke?.Shape); } internal void EnsureBorderPath() @@ -96,18 +96,21 @@ public void UpdateBackground(Paint? background) _borderPath.UpdateBackground(background); } - public void UpdateBorderShape(IShape borderShape) + public void UpdateBorderStroke(IBorderStroke borderStroke) { - _borderShape = borderShape; + if (borderStroke is null) + return; + + _borderStroke = borderStroke; if (_borderPath == null) return; - _borderPath.UpdateBorderShape(_borderShape, ActualWidth, ActualHeight); + _borderPath.UpdateBorderShape(_borderStroke.Shape, ActualWidth, ActualHeight); UpdateContent(); - UpdateClip(_borderShape); + UpdateClip(_borderStroke.Shape); } - + void AddContent(FrameworkElement? content) { if (content == null) @@ -146,8 +149,18 @@ void UpdateClip(IShape? borderShape) var visual = ElementCompositionPreview.GetElementVisual(Content); var compositor = visual.Compositor; + var pathSize = new Graphics.Rect(0, 0, width, height); - var clipPath = clipGeometry.PathForBounds(pathSize); + PathF? clipPath; + + if (clipGeometry is IRoundRectangle roundRectangle) + { + var strokeThickness = (float)(_borderStroke?.StrokeThickness ?? 0); + clipPath = roundRectangle.InnerPathForBounds(pathSize, strokeThickness); + } + else + clipPath = clipGeometry?.PathForBounds(pathSize); + var device = CanvasDevice.GetSharedDevice(); var geometry = clipPath.AsPath(device); diff --git a/src/Core/src/Platform/Windows/StrokeExtensions.cs b/src/Core/src/Platform/Windows/StrokeExtensions.cs index b0798cbd699a..687a06160f33 100644 --- a/src/Core/src/Platform/Windows/StrokeExtensions.cs +++ b/src/Core/src/Platform/Windows/StrokeExtensions.cs @@ -4,12 +4,10 @@ public static class StrokeExtensions { public static void UpdateStrokeShape(this ContentPanel platformView, IBorderStroke border) { - var shape = border.Shape; - - if (shape == null) + if (border is null) return; - platformView.UpdateBorderShape(shape); + platformView.UpdateBorderStroke(border); } public static void UpdateStroke(this ContentPanel platformView, IBorderStroke border) diff --git a/src/Core/src/PublicAPI/net-windows/PublicAPI.Shipped.txt b/src/Core/src/PublicAPI/net-windows/PublicAPI.Shipped.txt index 257f2151379e..02b55674f9ad 100644 --- a/src/Core/src/PublicAPI/net-windows/PublicAPI.Shipped.txt +++ b/src/Core/src/PublicAPI/net-windows/PublicAPI.Shipped.txt @@ -1551,7 +1551,6 @@ Microsoft.Maui.Platform.ColorExtensions Microsoft.Maui.Platform.ContentPanel Microsoft.Maui.Platform.ContentPanel.ContentPanel() -> void Microsoft.Maui.Platform.ContentPanel.UpdateBackground(Microsoft.Maui.Graphics.Paint? background) -> void -Microsoft.Maui.Platform.ContentPanel.UpdateBorderShape(Microsoft.Maui.Graphics.IShape! borderShape) -> void Microsoft.Maui.Platform.ControlExtensions Microsoft.Maui.Platform.DatePickerExtensions Microsoft.Maui.Platform.ElementExtensions diff --git a/src/Core/src/PublicAPI/net-windows/PublicAPI.Unshipped.txt b/src/Core/src/PublicAPI/net-windows/PublicAPI.Unshipped.txt index f7e7b81f6a37..ae2f8eafc742 100644 --- a/src/Core/src/PublicAPI/net-windows/PublicAPI.Unshipped.txt +++ b/src/Core/src/PublicAPI/net-windows/PublicAPI.Unshipped.txt @@ -2,6 +2,7 @@ Microsoft.Maui.IApplication.UserAppTheme.get -> Microsoft.Maui.ApplicationModel.AppTheme Microsoft.Maui.Hosting.MauiApp.DisposeAsync() -> System.Threading.Tasks.ValueTask Microsoft.Maui.Layouts.FlexBasis.Equals(Microsoft.Maui.Layouts.FlexBasis other) -> bool +Microsoft.Maui.Platform.ContentPanel.UpdateBorderStroke(Microsoft.Maui.IBorderStroke! borderStroke) -> void Microsoft.Maui.Platform.MauiWebView.MauiWebView(Microsoft.Maui.Handlers.WebViewHandler! handler) -> void Microsoft.Maui.SizeRequest.Equals(Microsoft.Maui.SizeRequest other) -> bool override Microsoft.Maui.Handlers.ContentViewHandler.DisconnectHandler(Microsoft.Maui.Platform.ContentPanel! platformView) -> void From d61d149ebd6af0c8e2407a3199663bd5a9152c28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Su=C3=A1rez?= <6755973+jsuarezruiz@users.noreply.github.com> Date: Wed, 31 May 2023 10:57:33 +0200 Subject: [PATCH 2/8] Updated impl --- src/Core/src/Platform/Windows/ContentPanel.cs | 13 ++++++++++++- .../PublicAPI/net-windows/PublicAPI.Unshipped.txt | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/Core/src/Platform/Windows/ContentPanel.cs b/src/Core/src/Platform/Windows/ContentPanel.cs index 1b4e5342f025..488693adde35 100644 --- a/src/Core/src/Platform/Windows/ContentPanel.cs +++ b/src/Core/src/Platform/Windows/ContentPanel.cs @@ -97,7 +97,18 @@ public void UpdateBackground(Paint? background) _borderPath.UpdateBackground(background); } - public void UpdateBorderStroke(IBorderStroke borderStroke) + [Obsolete("Use Microsoft.Maui.Platform.UpdateBorderStroke instead")] + public void UpdateBorderShape(IShape borderShape) + { + if (borderShape is null || _borderPath is null) + return; + + _borderPath.UpdateBorderShape(borderShape, ActualWidth, ActualHeight); + UpdateContent(); + UpdateClip(borderShape); + } + + internal void UpdateBorderStroke(IBorderStroke borderStroke) { if (borderStroke is null) return; diff --git a/src/Core/src/PublicAPI/net-windows/PublicAPI.Unshipped.txt b/src/Core/src/PublicAPI/net-windows/PublicAPI.Unshipped.txt index a047959869fd..5b79e1bfa6fd 100644 --- a/src/Core/src/PublicAPI/net-windows/PublicAPI.Unshipped.txt +++ b/src/Core/src/PublicAPI/net-windows/PublicAPI.Unshipped.txt @@ -11,7 +11,7 @@ Microsoft.Maui.ICommandMapper Microsoft.Maui.ICommandMapper.Add(string! key, System.Action! action) -> void Microsoft.Maui.ICommandMapper.Add(string! key, System.Action! action) -> void Microsoft.Maui.Layouts.FlexBasis.Equals(Microsoft.Maui.Layouts.FlexBasis other) -> bool -Microsoft.Maui.Platform.ContentPanel.UpdateBorderStroke(Microsoft.Maui.IBorderStroke! borderStroke) -> void +Microsoft.Maui.Platform.ContentPanel.UpdateBorderShape(Microsoft.Maui.Graphics.IShape! borderShape) -> void Microsoft.Maui.Platform.MauiWebView.MauiWebView(Microsoft.Maui.Handlers.WebViewHandler! handler) -> void Microsoft.Maui.SizeRequest.Equals(Microsoft.Maui.SizeRequest other) -> bool override Microsoft.Maui.Handlers.ContentViewHandler.DisconnectHandler(Microsoft.Maui.Platform.ContentPanel! platformView) -> void From 7110f6a6fe3cfefb74cefa08946e1710a51103e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Su=C3=A1rez?= Date: Thu, 22 Jun 2023 10:00:33 +0200 Subject: [PATCH 3/8] Created method to avoid duplicated code --- src/Core/src/Platform/Windows/ContentPanel.cs | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/Core/src/Platform/Windows/ContentPanel.cs b/src/Core/src/Platform/Windows/ContentPanel.cs index 488693adde35..b3e42a32a3cc 100644 --- a/src/Core/src/Platform/Windows/ContentPanel.cs +++ b/src/Core/src/Platform/Windows/ContentPanel.cs @@ -100,14 +100,9 @@ public void UpdateBackground(Paint? background) [Obsolete("Use Microsoft.Maui.Platform.UpdateBorderStroke instead")] public void UpdateBorderShape(IShape borderShape) { - if (borderShape is null || _borderPath is null) - return; - - _borderPath.UpdateBorderShape(borderShape, ActualWidth, ActualHeight); - UpdateContent(); - UpdateClip(borderShape); + UpdateBorder(borderShape); } - + internal void UpdateBorderStroke(IBorderStroke borderStroke) { if (borderStroke is null) @@ -115,14 +110,22 @@ internal void UpdateBorderStroke(IBorderStroke borderStroke) _borderStroke = borderStroke; - if (_borderPath == null) + if (_borderStroke is null) return; - _borderPath.UpdateBorderShape(_borderStroke.Shape, ActualWidth, ActualHeight); + UpdateBorder(_borderStroke.Shape); + } + + void UpdateBorder(IShape? strokeShape) + { + if (strokeShape is null || _borderPath is null) + return; + + _borderPath.UpdateBorderShape(strokeShape, ActualWidth, ActualHeight); UpdateContent(); - UpdateClip(_borderStroke.Shape); + UpdateClip(strokeShape); } - + void AddContent(FrameworkElement? content) { if (content == null) From 1a93828520b133ff77eda22e86adba8879b86a40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Su=C3=A1rez?= Date: Thu, 22 Jun 2023 10:22:10 +0200 Subject: [PATCH 4/8] Revert uneccesary changes --- src/Core/src/PublicAPI/net-windows/PublicAPI.Shipped.txt | 1 + src/Core/src/PublicAPI/net-windows/PublicAPI.Unshipped.txt | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Core/src/PublicAPI/net-windows/PublicAPI.Shipped.txt b/src/Core/src/PublicAPI/net-windows/PublicAPI.Shipped.txt index 02b55674f9ad..257f2151379e 100644 --- a/src/Core/src/PublicAPI/net-windows/PublicAPI.Shipped.txt +++ b/src/Core/src/PublicAPI/net-windows/PublicAPI.Shipped.txt @@ -1551,6 +1551,7 @@ Microsoft.Maui.Platform.ColorExtensions Microsoft.Maui.Platform.ContentPanel Microsoft.Maui.Platform.ContentPanel.ContentPanel() -> void Microsoft.Maui.Platform.ContentPanel.UpdateBackground(Microsoft.Maui.Graphics.Paint? background) -> void +Microsoft.Maui.Platform.ContentPanel.UpdateBorderShape(Microsoft.Maui.Graphics.IShape! borderShape) -> void Microsoft.Maui.Platform.ControlExtensions Microsoft.Maui.Platform.DatePickerExtensions Microsoft.Maui.Platform.ElementExtensions diff --git a/src/Core/src/PublicAPI/net-windows/PublicAPI.Unshipped.txt b/src/Core/src/PublicAPI/net-windows/PublicAPI.Unshipped.txt index 0b46624fa6f1..31164b188d41 100644 --- a/src/Core/src/PublicAPI/net-windows/PublicAPI.Unshipped.txt +++ b/src/Core/src/PublicAPI/net-windows/PublicAPI.Unshipped.txt @@ -13,7 +13,6 @@ Microsoft.Maui.ICommandMapper Microsoft.Maui.ICommandMapper.Add(string! key, System.Action! action) -> void Microsoft.Maui.ICommandMapper.Add(string! key, System.Action! action) -> void Microsoft.Maui.Layouts.FlexBasis.Equals(Microsoft.Maui.Layouts.FlexBasis other) -> bool -Microsoft.Maui.Platform.ContentPanel.UpdateBorderShape(Microsoft.Maui.Graphics.IShape! borderShape) -> void Microsoft.Maui.Platform.ImageSourcePartLoader.ImageSourcePartLoader(Microsoft.Maui.Handlers.IImageSourcePartSetter! handler) -> void Microsoft.Maui.Platform.MauiWebView.MauiWebView(Microsoft.Maui.Handlers.WebViewHandler! handler) -> void Microsoft.Maui.SizeRequest.Equals(Microsoft.Maui.SizeRequest other) -> bool From 30d99e7b26e21ebc71e88f7d0772619d9637666c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Su=C3=A1rez?= Date: Thu, 13 Jul 2023 11:08:36 +0200 Subject: [PATCH 5/8] Changes in clipping sizing --- src/Core/src/Platform/Windows/ContentPanel.cs | 42 ++++++++++++------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/src/Core/src/Platform/Windows/ContentPanel.cs b/src/Core/src/Platform/Windows/ContentPanel.cs index 70579d15dcb3..f6098170ad6a 100644 --- a/src/Core/src/Platform/Windows/ContentPanel.cs +++ b/src/Core/src/Platform/Windows/ContentPanel.cs @@ -52,9 +52,15 @@ void ContentPanelSizeChanged(object sender, UI.Xaml.SizeChangedEventArgs e) if (_borderPath == null) return; - _borderPath.UpdatePath(_borderStroke?.Shape, ActualWidth, ActualHeight); + var width = e.NewSize.Width; + var height = e.NewSize.Height; + + if (width <= 0 || height <= 0) + return; + + _borderPath.UpdatePath(_borderStroke?.Shape, width, height); UpdateContent(); - UpdateClip(_borderStroke?.Shape); + UpdateClip(_borderStroke?.Shape, width, height); } internal void EnsureBorderPath() @@ -99,7 +105,14 @@ void UpdateBorder(IShape? strokeShape) _borderPath.UpdateBorderShape(strokeShape, ActualWidth, ActualHeight); UpdateContent(); - UpdateClip(strokeShape); + + var width = ActualWidth; + var height = ActualHeight; + + if (width <= 0 || height <= 0) + return; + + UpdateClip(strokeShape, width, height); } void AddContent(FrameworkElement? content) @@ -121,20 +134,17 @@ void UpdateContent() Content.RenderTransform = new TranslateTransform() { X = -strokeThickness, Y = -strokeThickness }; } - void UpdateClip(IShape? borderShape) + void UpdateClip(IShape? borderShape, double width, double height) { - if (Content == null) + if (Content is null) return; - var clipGeometry = borderShape; - - if (clipGeometry == null) + if (height <= 0 && width <= 0) return; - double width = ActualWidth; - double height = ActualHeight; + var clipGeometry = borderShape; - if (height <= 0 && width <= 0) + if (clipGeometry is null) return; var visual = ElementCompositionPreview.GetElementVisual(Content); @@ -144,13 +154,15 @@ void UpdateClip(IShape? borderShape) var pathSize = new Graphics.Rect(0, 0, width, height); PathF? clipPath; - if (clipGeometry is IRoundRectangle roundRectangle) + if (clipGeometry is IRoundRectangle roundedRectangle) { - var strokeThickness = (float)(_borderStroke?.StrokeThickness ?? 0); - clipPath = roundRectangle.InnerPathForBounds(pathSize, strokeThickness); + float strokeThickness = (float)(_borderPath?.StrokeThickness ?? 0); + clipPath = roundedRectangle.InnerPathForBounds(pathSize, strokeThickness / 2); } else - clipPath = clipGeometry?.PathForBounds(pathSize); + { + clipPath = clipGeometry.PathForBounds(pathSize); + } var device = CanvasDevice.GetSharedDevice(); var geometry = clipPath.AsPath(device); From 7b5ba62ed21fd8a1dda43a8dfe0194a31ffc43d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Su=C3=A1rez?= Date: Thu, 13 Jul 2023 11:08:45 +0200 Subject: [PATCH 6/8] Fix Rui issue --- src/Controls/src/Core/Border/Border.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Controls/src/Core/Border/Border.cs b/src/Controls/src/Core/Border/Border.cs index 5c1cb706da39..21c94d191446 100644 --- a/src/Controls/src/Core/Border/Border.cs +++ b/src/Controls/src/Core/Border/Border.cs @@ -316,7 +316,7 @@ void OnStrokeDashArrayChanged(object? sender, NotifyCollectionChangedEventArgs e void UpdateStrokeShape() { - if (StrokeShape is Shape strokeShape) + if (StrokeShape is Shape strokeShape && StrokeThickness == 0) { strokeShape.StrokeThickness = StrokeThickness; } From 6af3205788a648a6c7e17b314da8408552b6e930 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Su=C3=A1rez?= Date: Thu, 13 Jul 2023 12:47:41 +0200 Subject: [PATCH 7/8] Added device tests --- .../Elements/Border/BorderTests.Windows.cs | 58 +++++++++++++++++++ .../Elements/Border/BorderTests.cs | 13 +++++ src/Core/src/Platform/Windows/ContentPanel.cs | 4 ++ .../Border/BorderHandlerTests.Windows.cs | 36 +++++++++++- 4 files changed, 109 insertions(+), 2 deletions(-) create mode 100644 src/Controls/tests/DeviceTests/Elements/Border/BorderTests.Windows.cs diff --git a/src/Controls/tests/DeviceTests/Elements/Border/BorderTests.Windows.cs b/src/Controls/tests/DeviceTests/Elements/Border/BorderTests.Windows.cs new file mode 100644 index 000000000000..f1abf3a396f9 --- /dev/null +++ b/src/Controls/tests/DeviceTests/Elements/Border/BorderTests.Windows.cs @@ -0,0 +1,58 @@ +using Xunit; +using Microsoft.Maui.Controls; +using Microsoft.Maui.Graphics; +using Microsoft.Maui.Controls.Shapes; +using Microsoft.Maui.Handlers; +using Microsoft.UI.Xaml.Hosting; +using Microsoft.Maui.Platform; +using System.Threading.Tasks; +using Microsoft.UI.Composition; + +namespace Microsoft.Maui.DeviceTests +{ + public partial class BorderTests : ControlsHandlerTestBase + { + [Theory(DisplayName = "Inner CornerRadius Initializes Correctly")] + [InlineData(0)] + [InlineData(12)] + [InlineData(24)] + public async Task InnerCornerRadiusInitializesCorrectly(int cornerRadius) + { + SetupBuilder(); + + var expected = Colors.Red; + + var border = new Border() + { + Content = new Label { Text = "Background", TextColor = Colors.White }, + StrokeShape = new RoundRectangle { CornerRadius = cornerRadius }, + Background = new SolidPaint(expected), + StrokeThickness = 0, + HeightRequest = 100, + WidthRequest = 300 + }; + + await AttachAndRun(border, (handler) => + { + var contentPanel = GetNativeBorder(handler as BorderHandler); + var content = contentPanel.Content; + var visual = ElementCompositionPreview.GetElementVisual(content); + + var clip = visual.Clip as CompositionGeometricClip; + Assert.NotNull(clip); + + var geometry = clip.Geometry as CompositionPathGeometry; + var path = geometry.Path; + Assert.NotNull(path); + + Assert.True(contentPanel.IsInnerPath); + }); + + await AssertColorAtPoint(border, expected, typeof(BorderHandler), cornerRadius, cornerRadius); + } + + ContentPanel GetNativeBorder(BorderHandler borderHandler) => + borderHandler.PlatformView; + + } +} \ No newline at end of file diff --git a/src/Controls/tests/DeviceTests/Elements/Border/BorderTests.cs b/src/Controls/tests/DeviceTests/Elements/Border/BorderTests.cs index 2b4a1c9a08c9..4b8f2d858fea 100644 --- a/src/Controls/tests/DeviceTests/Elements/Border/BorderTests.cs +++ b/src/Controls/tests/DeviceTests/Elements/Border/BorderTests.cs @@ -11,6 +11,19 @@ namespace Microsoft.Maui.DeviceTests [Category(TestCategory.Border)] public partial class BorderTests : ControlsHandlerTestBase { + void SetupBuilder() + { + EnsureHandlerCreated(builder => + { + builder.ConfigureMauiHandlers(handlers => + { + handlers.AddHandler(); + handlers.AddHandler(); + handlers.AddHandler(); + }); + }); + } + [Fact(DisplayName = "Rounded Rectangle Border occupies correct space")] public async Task RoundedRectangleBorderLayoutIsCorrect() { diff --git a/src/Core/src/Platform/Windows/ContentPanel.cs b/src/Core/src/Platform/Windows/ContentPanel.cs index f6098170ad6a..3692d4c0d063 100644 --- a/src/Core/src/Platform/Windows/ContentPanel.cs +++ b/src/Core/src/Platform/Windows/ContentPanel.cs @@ -30,6 +30,8 @@ internal FrameworkElement? Content } } + internal bool IsInnerPath { get; private set; } + protected override global::Windows.Foundation.Size ArrangeOverride(global::Windows.Foundation.Size finalSize) { var actual = base.ArrangeOverride(finalSize); @@ -158,10 +160,12 @@ void UpdateClip(IShape? borderShape, double width, double height) { float strokeThickness = (float)(_borderPath?.StrokeThickness ?? 0); clipPath = roundedRectangle.InnerPathForBounds(pathSize, strokeThickness / 2); + IsInnerPath = true; } else { clipPath = clipGeometry.PathForBounds(pathSize); + IsInnerPath = false; } var device = CanvasDevice.GetSharedDevice(); diff --git a/src/Core/tests/DeviceTests/Handlers/Border/BorderHandlerTests.Windows.cs b/src/Core/tests/DeviceTests/Handlers/Border/BorderHandlerTests.Windows.cs index b49f66f8d391..5dfbd5ca913a 100644 --- a/src/Core/tests/DeviceTests/Handlers/Border/BorderHandlerTests.Windows.cs +++ b/src/Core/tests/DeviceTests/Handlers/Border/BorderHandlerTests.Windows.cs @@ -1,10 +1,42 @@ -using System; -using System.Threading.Tasks; +using System.Threading.Tasks; +using Microsoft.Maui.DeviceTests.Stubs; +using Microsoft.UI.Xaml.Hosting; +using Xunit; namespace Microsoft.Maui.DeviceTests { public partial class BorderHandlerTests { + [Theory(DisplayName = "Inner CornerRadius Initializes Correctly")] + [InlineData(0)] + [InlineData(12)] + [InlineData(24)] + public async Task InnerCornerRadiusInitializesCorrectly(int cornerRadius) + { + var expected = cornerRadius; + + var border = new BorderStub() + { + Content = new LabelStub { Text = "Background", TextColor = Colors.White }, + Shape = new RoundRectangleShapeStub { CornerRadius = cornerRadius}, + Background = new SolidPaintStub(Colors.White), + Stroke = new SolidPaintStub(Colors.Black), + StrokeThickness = 2, + Height = 100, + Width = 300 + }; + + await AttachAndRun(border, (handler) => + { + var contentPanel = GetNativeBorder(handler); + var content = contentPanel.Content; + var visual = ElementCompositionPreview.GetElementVisual(content); + + var clip = visual.Clip; + Assert.NotNull(clip); + }); + } + ContentPanel GetNativeBorder(BorderHandler borderHandler) => borderHandler.PlatformView; } From b0b5c1cfe1d4d7c6a257449c2cf55a8abd7be37e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Su=C3=A1rez?= Date: Thu, 13 Jul 2023 12:49:54 +0200 Subject: [PATCH 8/8] Remove unnecessary changes --- .../Border/BorderHandlerTests.Windows.cs | 37 +------------------ 1 file changed, 1 insertion(+), 36 deletions(-) diff --git a/src/Core/tests/DeviceTests/Handlers/Border/BorderHandlerTests.Windows.cs b/src/Core/tests/DeviceTests/Handlers/Border/BorderHandlerTests.Windows.cs index 5dfbd5ca913a..9d1711496fe3 100644 --- a/src/Core/tests/DeviceTests/Handlers/Border/BorderHandlerTests.Windows.cs +++ b/src/Core/tests/DeviceTests/Handlers/Border/BorderHandlerTests.Windows.cs @@ -1,42 +1,7 @@ -using System.Threading.Tasks; -using Microsoft.Maui.DeviceTests.Stubs; -using Microsoft.UI.Xaml.Hosting; -using Xunit; - -namespace Microsoft.Maui.DeviceTests +namespace Microsoft.Maui.DeviceTests { public partial class BorderHandlerTests { - [Theory(DisplayName = "Inner CornerRadius Initializes Correctly")] - [InlineData(0)] - [InlineData(12)] - [InlineData(24)] - public async Task InnerCornerRadiusInitializesCorrectly(int cornerRadius) - { - var expected = cornerRadius; - - var border = new BorderStub() - { - Content = new LabelStub { Text = "Background", TextColor = Colors.White }, - Shape = new RoundRectangleShapeStub { CornerRadius = cornerRadius}, - Background = new SolidPaintStub(Colors.White), - Stroke = new SolidPaintStub(Colors.Black), - StrokeThickness = 2, - Height = 100, - Width = 300 - }; - - await AttachAndRun(border, (handler) => - { - var contentPanel = GetNativeBorder(handler); - var content = contentPanel.Content; - var visual = ElementCompositionPreview.GetElementVisual(content); - - var clip = visual.Clip; - Assert.NotNull(clip); - }); - } - ContentPanel GetNativeBorder(BorderHandler borderHandler) => borderHandler.PlatformView; }