Skip to content

Commit

Permalink
chore: add Ellipse and Rectangle Fill
Browse files Browse the repository at this point in the history
  • Loading branch information
RafaelMendesRosa committed Aug 24, 2023
1 parent 9e0763c commit e6eaa79
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down
35 changes: 26 additions & 9 deletions src/Uno.Toolkit.Skia.WinUI/Controls/Shadows/ShadowContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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 { })
{
Expand All @@ -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<CornerRadius>(element, "CornerRadius", out var value) ? value : default(CornerRadius?),
};

cornerRadius = localCornerRadius ?? new CornerRadius(0);
return localCornerRadius != null;
}
Expand Down

0 comments on commit e6eaa79

Please sign in to comment.