feat: add clock template.

This commit is contained in:
rabbitism
2024-04-21 22:58:31 +08:00
parent 14d3958873
commit 3815a5114c
5 changed files with 68 additions and 7 deletions

View File

@@ -9,12 +9,6 @@
d:DesignWidth="800"
mc:Ignorable="d">
<Grid>
<u:ClockTicks
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
HourTickWidth="4"
MinuteTickWidth="1"
HourTickForeground="Black"
MinuteTickForeground="Red" />
<u:Clock HorizontalAlignment="Left"></u:Clock>
</Grid>
</UserControl>

View File

@@ -0,0 +1,21 @@
<ResourceDictionary
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:iri="https://irihi.tech/shared"
xmlns:u="https://irihi.tech/ursa">
<!-- Add Resources Here -->
<ControlTheme x:Key="{x:Type u:Clock}" TargetType="u:Clock">
<Setter Property="Template">
<ControlTemplate TargetType="u:Clock">
<Grid>
<u:ClockTicks HorizontalAlignment="{TemplateBinding HorizontalAlignment}" HourTickForeground="{DynamicResource SemiGrey6}" MinuteTickForeground="{DynamicResource SemiGrey4}" />
<Rectangle Width="8" Height="100" Fill="White" />
<Rectangle Width="4" />
<iri:PureCircle
Diameter="16"
Background="Red" />
</Grid>
</ControlTemplate>
</Setter>
</ControlTheme>
</ResourceDictionary>

View File

@@ -6,6 +6,7 @@
<ResourceInclude Source="ButtonGroup.axaml" />
<ResourceInclude Source="Breadcrumb.axaml" />
<ResourceInclude Source="ControlClassesInput.axaml" />
<ResourceInclude Source="Clock.axaml" />
<ResourceInclude Source="Dialog.axaml" />
<ResourceInclude Source="DialogShared.axaml" />
<ResourceInclude Source="DisableContainer.axaml" />

View File

@@ -35,5 +35,38 @@ public class Clock: TemplatedControl
get => GetValue(ShowMinuteTicksProperty);
set => SetValue(ShowMinuteTicksProperty, value);
}
public static readonly StyledProperty<double> HourHandMarginProperty = AvaloniaProperty.Register<Clock, double>(
nameof(HourHandMargin));
public double HourHandMargin
{
get => GetValue(HourHandMarginProperty);
set => SetValue(HourHandMarginProperty, value);
}
public static readonly StyledProperty<double> MinuteHandMarginProperty = AvaloniaProperty.Register<Clock, double>(
nameof(MinuteHandMargin));
public double MinuteHandMargin
{
get => GetValue(MinuteHandMarginProperty);
set => SetValue(MinuteHandMarginProperty, value);
}
protected override Size MeasureOverride(Size availableSize)
{
double min = Math.Min(availableSize.Height, availableSize.Width);
var newSize = new Size(min, min);
var size = base.MeasureOverride(newSize);
return size;
}
protected override Size ArrangeOverride(Size finalSize)
{
double min = Math.Min(finalSize.Height, finalSize.Width);
var newSize = new Size(min, min);
var size = base.ArrangeOverride(newSize);
return size;
}
}

View File

@@ -86,6 +86,18 @@ public class ClockTicks: Control
AffectsRender<ClockTicks>(ShowHourTicksProperty);
}
protected override Size MeasureOverride(Size availableSize)
{
double minSize= Math.Min(availableSize.Width, availableSize.Height);
return new Size(minSize, minSize);
}
protected override Size ArrangeOverride(Size finalSize)
{
var minSize = Math.Min(finalSize.Width, finalSize.Height);
return new Size(minSize, minSize);
}
public override void Render(DrawingContext context)
{
base.Render(context);