feat: change hand length.

This commit is contained in:
rabbitism
2024-04-23 22:02:17 +08:00
parent db6ba785dd
commit 823bb2ee8c
2 changed files with 34 additions and 7 deletions

View File

@@ -1,7 +1,7 @@
<ResourceDictionary
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:iri="https://irihi.tech/shared"
xmlns:converter="clr-namespace:Ursa.Themes.Semi.Converters"
xmlns:u="https://irihi.tech/ursa">
<!-- Add Resources Here -->
<ControlTheme x:Key="{x:Type u:Clock}" TargetType="u:Clock">
@@ -18,8 +18,8 @@
<UniformGrid Rows="2" IsVisible="{TemplateBinding ShowHourHand}">
<Border
Width="16"
Margin="0,16,0,0"
VerticalAlignment="Stretch"
Height="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Bounds.Width, Converter={x:Static converter:ClockHandLengthConverter.Hour}}"
VerticalAlignment="Bottom"
Background="{TemplateBinding HandBrush}"
CornerRadius="8" />
<UniformGrid.RenderTransform>
@@ -29,8 +29,8 @@
<UniformGrid Rows="2" IsVisible="{TemplateBinding ShowMinuteHand}">
<Border
Width="8"
Margin="0,8,0,0"
VerticalAlignment="Stretch"
Height="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Bounds.Width, Converter={x:Static converter:ClockHandLengthConverter.Minute}}"
VerticalAlignment="Bottom"
Background="{TemplateBinding HandBrush}"
CornerRadius="4" />
<UniformGrid.RenderTransform>
@@ -40,8 +40,8 @@
<UniformGrid Rows="2" IsVisible="{TemplateBinding ShowSecondHand}">
<Border
Width="4"
Margin="0,4,0,0"
VerticalAlignment="Stretch"
Height="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Bounds.Width, Converter={x:Static converter:ClockHandLengthConverter.Second}}"
VerticalAlignment="Bottom"
Background="{TemplateBinding HandBrush}"
CornerRadius="4" />
<UniformGrid.RenderTransform>

View File

@@ -0,0 +1,27 @@
using System.Globalization;
using Avalonia.Data.Converters;
namespace Ursa.Themes.Semi.Converters;
public class ClockHandLengthConverter(double ratio) : IValueConverter
{
public static ClockHandLengthConverter Hour { get; } = new(1-0.618);
public static ClockHandLengthConverter Minute { get; } = new(0.618);
public static ClockHandLengthConverter Second { get; } = new(1);
private double _ratio = ratio;
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is double d)
{
return d * ratio / 2;
}
return 0.0;
}
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}