From d9878b39335564454ef1e92494bd4d32d64866c2 Mon Sep 17 00:00:00 2001 From: Rafael Rosa Date: Thu, 24 Aug 2023 17:27:38 -0300 Subject: [PATCH] chore: add Ellipse and Rectangle Fill --- .../Controls/Shadows/ShadowContainer.Paint.cs | 14 +++++++- .../Controls/Shadows/ShadowContainer.cs | 35 ++++++++++++++----- 2 files changed, 39 insertions(+), 10 deletions(-) diff --git a/src/Uno.Toolkit.Skia.WinUI/Controls/Shadows/ShadowContainer.Paint.cs b/src/Uno.Toolkit.Skia.WinUI/Controls/Shadows/ShadowContainer.Paint.cs index 14cdad866..b315bb1ed 100644 --- a/src/Uno.Toolkit.Skia.WinUI/Controls/Shadows/ShadowContainer.Paint.cs +++ b/src/Uno.Toolkit.Skia.WinUI/Controls/Shadows/ShadowContainer.Paint.cs @@ -8,6 +8,8 @@ using Microsoft.Extensions.Logging; using Uno.Extensions; using Uno.Logging; +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Shapes; #if IS_WINUI using Microsoft.UI.Xaml.Media; @@ -343,14 +345,20 @@ private bool TryGetContentBackground(out Brush? background) background = null; return false; } - background = _currentContent switch { Control control => control.Background, Panel panel => panel.Background, Border border => border.Background, + Shape shape => shape.Background, _ => null, }; + background ??= _currentContent switch + { + Shape Shape => Shape.Fill, + _ => null, + }; + return background != null; } @@ -368,6 +376,10 @@ private bool TrySetContentBackground(SolidColorBrush background) case Border border: border.Background = background; break; + case Shape shape: + shape.Background = background; + shape.Fill = background; + break; default: return false; } diff --git a/src/Uno.Toolkit.Skia.WinUI/Controls/Shadows/ShadowContainer.cs b/src/Uno.Toolkit.Skia.WinUI/Controls/Shadows/ShadowContainer.cs index 6e3258378..efd7fba05 100644 --- a/src/Uno.Toolkit.Skia.WinUI/Controls/Shadows/ShadowContainer.cs +++ b/src/Uno.Toolkit.Skia.WinUI/Controls/Shadows/ShadowContainer.cs @@ -4,6 +4,7 @@ #if IS_WINUI using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Shapes; using SkiaSharp.Views.Windows; #else using Windows.UI.Xaml; @@ -121,18 +122,23 @@ protected override void OnContentChanged(object oldContent, object newContent) ContentPresenter _ => ContentPresenter.CornerRadiusProperty, Border _ => Border.CornerRadiusProperty, Control _ => Control.CornerRadiusProperty, - RelativePanel _ => RelativePanel.CornerRadiusProperty, + Rectangle _ => Rectangle.RadiusXProperty, + Ellipse _ => Ellipse.WidthProperty, + RelativePanel _ => RelativePanel.CornerRadiusProperty, _ => default, }; + SetCornerRadiusDependencyProperty(newElement, cornerRadiusProperty); - if (cornerRadiusProperty != null) + + var complementarCornerRadiusProperty = newElement switch { - _cornerRadiusChanged.Disposable = newElement.RegisterDisposablePropertyChangedCallback( - cornerRadiusProperty, - (s, dp) => OnCornerRadiusChanged(s, dp) - ); - } + Rectangle _ => Rectangle.RadiusYProperty, + Ellipse _ => Ellipse.HeightProperty, + _ => default, + }; + + SetCornerRadiusDependencyProperty(newElement, complementarCornerRadiusProperty); } _cornerRadius = cornerRadius; @@ -142,7 +148,17 @@ protected override void OnContentChanged(object oldContent, object newContent) base.OnContentChanged(oldContent, newContent); } - private void OnCornerRadiusChanged(DependencyObject sender, DependencyProperty dp) + private void SetCornerRadiusDependencyProperty(FrameworkElement newElement, DependencyProperty? cornerRadiusProperty) + { + if (cornerRadiusProperty != null) + { + _cornerRadiusChanged.Disposable = newElement.RegisterDisposablePropertyChangedCallback( + cornerRadiusProperty, + (s, dp) => OnCornerRadiusChanged(s, dp) + ); + } + } + private void OnCornerRadiusChanged(DependencyObject sender, DependencyProperty dp) { if (_currentContent is { }) { @@ -163,9 +179,10 @@ private static bool TryGetCornerRadius(FrameworkElement element, out CornerRadiu RelativePanel relativePanel => relativePanel.CornerRadius, Grid grid => grid.CornerRadius, Border border => border.CornerRadius, + Rectangle border => new CornerRadius(border.RadiusY == 0 ? 0 : (border.RadiusX / border.RadiusY) * (border.Width > border.Height ? border.Width : border.Height)), + Ellipse ellipse => new CornerRadius(ellipse.Height == 0 ? 0: (ellipse.Width / ellipse.Height / 2) * (ellipse.Width > ellipse.Height ? ellipse.Width : ellipse.Height)), _ => VisualTreeHelperEx.TryGetDpValue(element, "CornerRadius", out var value) ? value : default(CornerRadius?), }; - cornerRadius = localCornerRadius ?? new CornerRadius(0); return localCornerRadius != null; }