diff --git a/AutoCat/App.axaml b/AutoCat/App.axaml index 1c01ea2..227d3f2 100644 --- a/AutoCat/App.axaml +++ b/AutoCat/App.axaml @@ -6,9 +6,11 @@ RequestedThemeVariant="Default"> - + + + avares://Assets/Fonts/RoadNumbers2.0.otf + + \ No newline at end of file diff --git a/AutoCat/Assets/Fonts/RoadNumbers.otf b/AutoCat/Assets/Fonts/RoadNumbers.otf new file mode 100644 index 0000000..7f40a38 Binary files /dev/null and b/AutoCat/Assets/Fonts/RoadNumbers.otf differ diff --git a/AutoCat/Assets/Fonts/RoadNumbers2.0.otf b/AutoCat/Assets/Fonts/RoadNumbers2.0.otf new file mode 100644 index 0000000..390c01e Binary files /dev/null and b/AutoCat/Assets/Fonts/RoadNumbers2.0.otf differ diff --git a/AutoCat/Pages/HistoryListPage.axaml b/AutoCat/Pages/HistoryListPage.axaml index f161a09..913852c 100644 --- a/AutoCat/Pages/HistoryListPage.axaml +++ b/AutoCat/Pages/HistoryListPage.axaml @@ -5,6 +5,7 @@ xmlns:utils="using:AutoCat.Utils" xmlns:vm="using:AutoCat.ViewModels" xmlns:mocks="using:AutoCat.Mocks" + xmlns:views="using:AutoCat.Views" mc:Ignorable="d" d:DesignWidth="350" d:DesignHeight="550" x:Class="AutoCat.Pages.HistoryListPage" x:DataType="vm:HistoryListViewModel" @@ -20,7 +21,7 @@ - + diff --git a/AutoCat/Views/PlateNumber.cs b/AutoCat/Views/PlateNumber.cs new file mode 100644 index 0000000..40061ee --- /dev/null +++ b/AutoCat/Views/PlateNumber.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace AutoCat.Views; + +//[CreateFromString(MethodName = "AutoCat.Controls.PlateNumber.ConvertFromString")] +public class PlateNumber +{ + private readonly string _number; + private readonly string _numberEnglish; + + private readonly Dictionary _lettersMap = new() + { + { 'А', 'A' }, { 'В', 'B' }, { 'Е', 'E' }, { 'К', 'K' }, + { 'М', 'M' }, { 'Н', 'H' }, { 'О', 'O' }, { 'Р', 'P' }, + { 'С', 'C' }, { 'Т', 'T' }, { 'У', 'Y' }, { 'Х', 'X' } + }; + + private PlateNumber(string number) + { + this._number = number; + this._numberEnglish = string.Concat(number.Select(c => _lettersMap.TryGetValue(c, out var eng) ? eng : c)); + } + + public string AsString() + { + return _number; + } + + public string MainPart() + { + return _numberEnglish[..6]; + } + + public string Region() + { + return _numberEnglish[6..]; + } + + public static PlateNumber ConvertFromString(string number) + { + return new PlateNumber(number); + } +} \ No newline at end of file diff --git a/AutoCat/Views/PlateView.axaml b/AutoCat/Views/PlateView.axaml new file mode 100644 index 0000000..61acf13 --- /dev/null +++ b/AutoCat/Views/PlateView.axaml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/AutoCat/Views/PlateView.axaml.cs b/AutoCat/Views/PlateView.axaml.cs new file mode 100644 index 0000000..b1eff0a --- /dev/null +++ b/AutoCat/Views/PlateView.axaml.cs @@ -0,0 +1,61 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Markup.Xaml; + +namespace AutoCat.Views; + +public partial class PlateView : UserControl +{ + #region Dependency properties + + public static readonly StyledProperty NumberProperty = + AvaloniaProperty.Register(nameof(Number), inherits: true); + + #endregion + + #region Properties + + public PlateNumber Number + { + get => (PlateNumber)GetValue(NumberProperty); + set => SetValue(NumberProperty, value); + } + + #endregion + + private const double AspectRatio = 112.0 / 520.0; + + public PlateView() + { + InitializeComponent(); + } + + /* + private static void OnNumberChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + if (d is not PlateView plateNumber || e.NewValue is not PlateNumber number) + return; + + plateNumber.NumberBox.Text = number.MainPart(); + plateNumber.RegionBox.Text = number.Region(); + } + */ + + protected override Size MeasureOverride(Size availableSize) + { + var newAspect = availableSize.Height / availableSize.Width; + + return newAspect >= AspectRatio + ? new Size(availableSize.Width, availableSize.Width * AspectRatio) + : new Size(availableSize.Height / AspectRatio, availableSize.Height); + } + + private void UserControl_SizeChanged(object sender, SizeChangedEventArgs e) + { + NumberBox.Margin = new Thickness(0, -e.NewSize.Height * 0.35, 0, 0); + RegionBox.FontSize = e.NewSize.Height * 0.65; + RegionBox.Margin = new Thickness(0, -RegionBox.FontSize * 0.3, 0, 0); + FlagGrid.Width = FlagGrid.Height * 1.5; + CountryName.FontSize = CountryRow.Height; + } +} \ No newline at end of file