From dc8e576a97d864acf1f83f04c798ca162d9fb8ea Mon Sep 17 00:00:00 2001 From: MartyIX <203266+MartyIX@users.noreply.github.com> Date: Sat, 11 May 2024 21:05:20 +0200 Subject: [PATCH 1/3] Code style --- src/Core/src/Platform/Windows/ContentPanel.cs | 30 +++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/src/Core/src/Platform/Windows/ContentPanel.cs b/src/Core/src/Platform/Windows/ContentPanel.cs index b380699c1b94..00f53554e003 100644 --- a/src/Core/src/Platform/Windows/ContentPanel.cs +++ b/src/Core/src/Platform/Windows/ContentPanel.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Numerics; using Microsoft.Graphics.Canvas; using Microsoft.Maui.Graphics; @@ -8,7 +7,6 @@ using Microsoft.UI.Composition; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Hosting; -using Microsoft.UI.Xaml.Media; using Microsoft.UI.Xaml.Shapes; namespace Microsoft.Maui.Platform @@ -55,16 +53,20 @@ public ContentPanel() SizeChanged += ContentPanelSizeChanged; } - void ContentPanelSizeChanged(object sender, UI.Xaml.SizeChangedEventArgs e) + void ContentPanelSizeChanged(object sender, SizeChangedEventArgs e) { if (_borderPath is null) + { return; + } var width = e.NewSize.Width; var height = e.NewSize.Height; if (width <= 0 || height <= 0) + { return; + } _borderPath.UpdatePath(_borderStroke?.Shape, width, height); UpdateClip(_borderStroke?.Shape, width, height); @@ -81,7 +83,9 @@ internal void EnsureBorderPath() public void UpdateBackground(Paint? background) { if (_borderPath == null) + { return; + } _borderPath.UpdateBackground(background); } @@ -95,12 +99,16 @@ public void UpdateBorderShape(IShape borderShape) internal void UpdateBorderStroke(IBorderStroke borderStroke) { if (borderStroke is null) + { return; + } _borderStroke = borderStroke; if (_borderStroke is null) + { return; + } UpdateBorder(_borderStroke.Shape); } @@ -108,7 +116,9 @@ internal void UpdateBorderStroke(IBorderStroke borderStroke) void UpdateBorder(IShape? strokeShape) { if (strokeShape is null || _borderPath is null) + { return; + } _borderPath.UpdateBorderShape(strokeShape, ActualWidth, ActualHeight); @@ -116,7 +126,9 @@ void UpdateBorder(IShape? strokeShape) var height = ActualHeight; if (width <= 0 || height <= 0) + { return; + } UpdateClip(strokeShape, width, height); } @@ -124,7 +136,9 @@ void UpdateBorder(IShape? strokeShape) void AddContent(FrameworkElement? content) { if (content == null) + { return; + } if (!Children.Contains(_content)) Children.Add(_content); @@ -133,15 +147,21 @@ void AddContent(FrameworkElement? content) void UpdateClip(IShape? borderShape, double width, double height) { if (Content is null) + { return; + } if (height <= 0 && width <= 0) + { return; + } var clipGeometry = borderShape; if (clipGeometry is null) + { return; + } var visual = ElementCompositionPreview.GetElementVisual(Content); var compositor = visual.Compositor; @@ -149,7 +169,7 @@ void UpdateClip(IShape? borderShape, double width, double height) PathF? clipPath; float strokeThickness = (float)(_borderPath?.StrokeThickness ?? 0); // The path size should consider the space taken by the border (top and bottom, left and right) - var pathSize = new Graphics.Rect(0, 0, width - strokeThickness * 2, height - strokeThickness * 2); + var pathSize = new Rect(0, 0, width - strokeThickness * 2, height - strokeThickness * 2); if (clipGeometry is IRoundRectangle roundedRectangle) { From 43bd39804da429824b7b007bb1168b21995fb697 Mon Sep 17 00:00:00 2001 From: MartyIX <203266+MartyIX@users.noreply.github.com> Date: Sat, 11 May 2024 21:06:25 +0200 Subject: [PATCH 2/3] is null --- src/Core/src/Platform/Windows/ContentPanel.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Core/src/Platform/Windows/ContentPanel.cs b/src/Core/src/Platform/Windows/ContentPanel.cs index 00f53554e003..48d91cd41940 100644 --- a/src/Core/src/Platform/Windows/ContentPanel.cs +++ b/src/Core/src/Platform/Windows/ContentPanel.cs @@ -82,7 +82,7 @@ internal void EnsureBorderPath() public void UpdateBackground(Paint? background) { - if (_borderPath == null) + if (_borderPath is null) { return; } @@ -135,7 +135,7 @@ void UpdateBorder(IShape? strokeShape) void AddContent(FrameworkElement? content) { - if (content == null) + if (content is null) { return; } From 50567205e9d18a4281ad8890106d11fa4594fdb9 Mon Sep 17 00:00:00 2001 From: MartyIX <203266+MartyIX@users.noreply.github.com> Date: Sat, 11 May 2024 21:06:12 +0200 Subject: [PATCH 3/3] Cache children --- src/Core/src/Platform/Windows/ContentPanel.cs | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/Core/src/Platform/Windows/ContentPanel.cs b/src/Core/src/Platform/Windows/ContentPanel.cs index 48d91cd41940..cffde30922b8 100644 --- a/src/Core/src/Platform/Windows/ContentPanel.cs +++ b/src/Core/src/Platform/Windows/ContentPanel.cs @@ -48,7 +48,7 @@ public class ContentPanel : MauiPanel public ContentPanel() { _borderPath = new Path(); - EnsureBorderPath(); + EnsureBorderPath(containsCheck: false); SizeChanged += ContentPanelSizeChanged; } @@ -72,9 +72,18 @@ void ContentPanelSizeChanged(object sender, SizeChangedEventArgs e) UpdateClip(_borderStroke?.Shape, width, height); } - internal void EnsureBorderPath() + internal void EnsureBorderPath(bool containsCheck = true) { - if (!Children.Contains(_borderPath)) + if (containsCheck) + { + var children = Children; + + if (!children.Contains(_borderPath)) + { + children.Add(_borderPath); + } + } + else { Children.Add(_borderPath); } @@ -140,8 +149,12 @@ void AddContent(FrameworkElement? content) return; } - if (!Children.Contains(_content)) - Children.Add(_content); + var children = Children; + + if (!children.Contains(_content)) + { + children.Add(_content); + } } void UpdateClip(IShape? borderShape, double width, double height)