feat: Clip.
This commit is contained in:
@@ -34,6 +34,8 @@
|
||||
</u:Avatar.HoverMask>
|
||||
</u:Avatar>
|
||||
<u:Avatar Source="../Assets/Ursa.ico" />
|
||||
<u:Avatar Source="../Assets/IRIHI.png" />
|
||||
<u:Avatar Source="../Assets/WORLD.png" />
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<u:Avatar Classes="Red" />
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
<ResourceDictionary
|
||||
xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:u="https://irihi.tech/ursa">
|
||||
xmlns:u="https://irihi.tech/ursa"
|
||||
xmlns:converters="clr-namespace:Ursa.Converters;assembly=Ursa">
|
||||
<converters:DivideByTwoConverter x:Key="DivideByTwoConverter" />
|
||||
<ControlTheme x:Key="{x:Type u:Avatar}" TargetType="{x:Type u:Avatar}">
|
||||
<Setter Property="Foreground" Value="White" />
|
||||
<Setter Property="Background" Value="{DynamicResource SemiGrey3}" />
|
||||
@@ -13,12 +15,21 @@
|
||||
<Setter Property="Template">
|
||||
<ControlTemplate TargetType="{x:Type u:Avatar}">
|
||||
<Panel>
|
||||
<Panel.Clip>
|
||||
<EllipseGeometry
|
||||
Center="{Binding #PART_Ellipse.Bounds.Center}"
|
||||
RadiusX="{Binding #PART_Ellipse.Bounds.Width, Converter={StaticResource DivideByTwoConverter}}"
|
||||
RadiusY="{Binding #PART_Ellipse.Bounds.Height, Converter={StaticResource DivideByTwoConverter}}" />
|
||||
</Panel.Clip>
|
||||
<Ellipse
|
||||
Name="PART_Ellipse"
|
||||
Fill="Transparent"/>
|
||||
<Ellipse
|
||||
Fill="{TemplateBinding Background}"
|
||||
IsVisible="{TemplateBinding Source,Converter={x:Static ObjectConverters.IsNull}}" />
|
||||
IsVisible="{TemplateBinding Source, Converter={x:Static ObjectConverters.IsNull}}" />
|
||||
<ContentPresenter
|
||||
Name="PART_ContentPresenter"
|
||||
IsVisible="{TemplateBinding Source,Converter={x:Static ObjectConverters.IsNull}}"
|
||||
IsVisible="{TemplateBinding Source, Converter={x:Static ObjectConverters.IsNull}}"
|
||||
CornerRadius="{TemplateBinding CornerRadius}"
|
||||
Content="{TemplateBinding Content}"
|
||||
HorizontalContentAlignment="Center"
|
||||
|
||||
22
src/Ursa/Converters/DivideByTwoConverter.cs
Normal file
22
src/Ursa/Converters/DivideByTwoConverter.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System.Globalization;
|
||||
using Avalonia.Data.Converters;
|
||||
|
||||
namespace Ursa.Converters;
|
||||
|
||||
public class DivideByTwoConverter : IValueConverter
|
||||
{
|
||||
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is double d)
|
||||
{
|
||||
return d / 2;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user