feat: several fixes.

This commit is contained in:
rabbitism
2024-02-19 17:56:49 +08:00
parent 9b5db3ce87
commit 966db68423
5 changed files with 62 additions and 5 deletions

View File

@@ -14,7 +14,7 @@
FontFamily="{TemplateBinding FontFamily}"
Background="{TemplateBinding Background}"
FontWeight="{TemplateBinding FontWeight}"
FontStyle="{TemplateBinding FontSize}"
FontStyle="{TemplateBinding FontStyle}"
FontStretch="{TemplateBinding FontStretch}"
Text="{TemplateBinding InternalText, Mode=OneWay}" />
</ControlTemplate>
@@ -28,7 +28,7 @@
FontFamily="{TemplateBinding FontFamily}"
Background="{TemplateBinding Background}"
FontWeight="{TemplateBinding FontWeight}"
FontStyle="{TemplateBinding FontSize}"
FontStyle="{TemplateBinding FontStyle}"
FontStretch="{TemplateBinding FontStretch}"
Text="{TemplateBinding InternalText, Mode=OneWay}" />
</ControlTemplate>

View File

@@ -3,3 +3,4 @@ using Avalonia.Metadata;
[assembly:XmlnsPrefix("https://irihi.tech/ursa", "u")]
[assembly:XmlnsDefinition("https://irihi.tech/ursa", "Ursa")]
[assembly:XmlnsDefinition("https://irihi.tech/ursa", "Ursa.Controls")]
[assembly:XmlnsDefinition("https://irihi.tech/ursa", "Ursa.Controls.Shapes")]

View File

@@ -62,7 +62,15 @@ public class DateDisplay : NumberDisplayer<DateTime>
public override DateTime Interpolate(double progress, DateTime oldValue, DateTime newValue)
{
var diff = (newValue - oldValue).TotalSeconds;
return oldValue + TimeSpan.FromSeconds(diff * progress);
try
{
return oldValue + TimeSpan.FromSeconds(diff * progress);
}
catch
{
return oldValue;
}
}
}

View File

@@ -0,0 +1,45 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.Media;
namespace Ursa.Controls.Shapes;
public class PureCircle: Control
{
public static readonly StyledProperty<IBrush?> BackgroundProperty =
TemplatedControl.BackgroundProperty.AddOwner<PureCircle>();
public IBrush? Background
{
get => GetValue(BackgroundProperty);
set => SetValue(BackgroundProperty, value);
}
public static readonly StyledProperty<double> DiameterProperty = AvaloniaProperty.Register<PureCircle, double>(
nameof(Diameter));
public double Diameter
{
get => GetValue(DiameterProperty);
set => SetValue(DiameterProperty, value);
}
static PureCircle()
{
FocusableProperty.OverrideDefaultValue<PureCircle>(false);
AffectsMeasure<PureCircle>(DiameterProperty);
AffectsRender<PureCircle>(DiameterProperty, BackgroundProperty);
}
protected override Size MeasureOverride(Size availableSize)
{
return new Size(Diameter, Diameter);
}
public override void Render(DrawingContext context)
{
double value = Diameter / 2;
context.DrawEllipse(Background, null, new(value, value), value, value);
}
}

View File

@@ -1,6 +1,8 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.Controls.Shapes;
using Avalonia.Markup.Xaml.Templates;
using Avalonia.Media;
namespace Ursa.Controls.Shapes;
@@ -10,8 +12,8 @@ namespace Ursa.Controls.Shapes;
/// </summary>
public class PureRectangle: Control
{
public static readonly StyledProperty<IBrush?> BackgroundProperty = AvaloniaProperty.Register<PureRectangle, IBrush?>(
nameof(Background));
public static readonly StyledProperty<IBrush?> BackgroundProperty =
TemplatedControl.BackgroundProperty.AddOwner<PureRectangle>();
public IBrush? Background
{
@@ -21,6 +23,7 @@ public class PureRectangle: Control
static PureRectangle()
{
FocusableProperty.OverrideDefaultValue<PureRectangle>(false);
AffectsRender<PureRectangle>(BackgroundProperty);
}
public override void Render(DrawingContext context)