79 lines
2.3 KiB
C#
79 lines
2.3 KiB
C#
using AutoCatCore.Model;
|
|
using Avalonia;
|
|
using Avalonia.Controls;
|
|
|
|
namespace AutoCat.Views;
|
|
|
|
public partial class PlateView : UserControl
|
|
{
|
|
#region Dependency properties
|
|
|
|
public static readonly StyledProperty<string> NumberProperty =
|
|
AvaloniaProperty.Register<PlateView, string>(nameof(Number));
|
|
|
|
#endregion
|
|
|
|
#region Properties
|
|
|
|
public string Number
|
|
{
|
|
get => GetValue(NumberProperty);
|
|
set => SetValue(NumberProperty, value);
|
|
}
|
|
|
|
#endregion
|
|
|
|
public const double AspectRatio = 112.0 / 520.0;
|
|
|
|
static PlateView()
|
|
{
|
|
NumberProperty.Changed.AddClassHandler<PlateView>((v, e) => v.NumberChanged(e));
|
|
}
|
|
|
|
public PlateView()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void NumberChanged(AvaloniaPropertyChangedEventArgs e)
|
|
{
|
|
if (e.NewValue is not string newNumber)
|
|
return;
|
|
|
|
var number = new PlateNumber(newNumber);
|
|
NumberBox.Text = number.MainPart();
|
|
RegionBox.Text = number.Region();
|
|
}
|
|
|
|
private void UserControl_SizeChanged(object sender, SizeChangedEventArgs e)
|
|
{
|
|
if(Bounds.Height <= 0)
|
|
return;
|
|
|
|
var frameWidth = Bounds.Height * 0.05;
|
|
var outerRadius = Bounds.Height * 0.15;
|
|
var innerRadius = outerRadius - frameWidth;
|
|
|
|
MainRect.RadiusX = outerRadius;
|
|
MainRect.RadiusY = outerRadius;
|
|
|
|
NumberRect.Margin = new Thickness(frameWidth, frameWidth, frameWidth / 2, frameWidth);
|
|
NumberRect.RadiusX = innerRadius;
|
|
NumberRect.RadiusY = innerRadius;
|
|
|
|
RegionRect.Margin = new Thickness(frameWidth / 2, frameWidth, frameWidth, frameWidth);
|
|
RegionRect.RadiusX = innerRadius;
|
|
RegionRect.RadiusY = innerRadius;
|
|
RegionGrid.Margin = new Thickness(frameWidth, frameWidth * 2, frameWidth * 2, frameWidth * 2);
|
|
|
|
NumberBox.Margin = new Thickness(0, outerRadius, 0, 0);
|
|
NumberBox.FontSize = Bounds.Height;
|
|
RegionBox.FontSize = Bounds.Height * 0.72;
|
|
RegionBox.Margin = new Thickness(0, Bounds.Height * 0.12, 0, 0);
|
|
CountryName.FontSize = Bounds.Height * 0.23;
|
|
|
|
CountryRow.Spacing = Bounds.Height * 0.06;
|
|
FlagGrid.Width = Bounds.Height * 0.35;
|
|
FlagGrid.Height = Bounds.Height * 0.2;
|
|
}
|
|
} |