PlateView improvements
This commit is contained in:
parent
44e229070f
commit
1c5d97b8a1
@ -10,7 +10,12 @@
|
|||||||
</Application.Styles>
|
</Application.Styles>
|
||||||
|
|
||||||
<Application.Resources>
|
<Application.Resources>
|
||||||
|
<ResourceDictionary>
|
||||||
|
<ResourceDictionary.MergedDictionaries>
|
||||||
|
<ResourceInclude Source="Resources/Colors.axaml"/>
|
||||||
|
</ResourceDictionary.MergedDictionaries>
|
||||||
<FontFamily x:Key="RoadNumbersFont">avares://Assets/Fonts/RoadNumbers2.0.otf</FontFamily>
|
<FontFamily x:Key="RoadNumbersFont">avares://Assets/Fonts/RoadNumbers2.0.otf</FontFamily>
|
||||||
|
</ResourceDictionary>
|
||||||
</Application.Resources>
|
</Application.Resources>
|
||||||
|
|
||||||
</Application>
|
</Application>
|
||||||
27
AutoCat/Extensions/DateConverter.cs
Normal file
27
AutoCat/Extensions/DateConverter.cs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
using System;
|
||||||
|
using System.Globalization;
|
||||||
|
using Avalonia.Data.Converters;
|
||||||
|
|
||||||
|
namespace AutoCat.Extensions;
|
||||||
|
|
||||||
|
public class DateConverter: IValueConverter
|
||||||
|
{
|
||||||
|
private static readonly DateTime Epoch = new(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
|
||||||
|
|
||||||
|
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||||
|
{
|
||||||
|
if (value is not double timestamp)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
if (timestamp == 0)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
var dateTime = Epoch.AddMilliseconds(timestamp).ToLocalTime();
|
||||||
|
return dateTime.ToString("g");
|
||||||
|
}
|
||||||
|
|
||||||
|
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
27
AutoCat/Extensions/MathExtension.cs
Normal file
27
AutoCat/Extensions/MathExtension.cs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
using System;
|
||||||
|
using System.Globalization;
|
||||||
|
using Avalonia.Data;
|
||||||
|
using Avalonia.Data.Converters;
|
||||||
|
using Avalonia.Markup.Xaml;
|
||||||
|
using Avalonia.Markup.Xaml.MarkupExtensions;
|
||||||
|
|
||||||
|
namespace AutoCat.Extensions;
|
||||||
|
|
||||||
|
public class MathExtension: MarkupExtension
|
||||||
|
{
|
||||||
|
public string Path { get; set; }
|
||||||
|
|
||||||
|
public double Mult { get; set; } = 1;
|
||||||
|
public double Add { get; set; } = 0;
|
||||||
|
|
||||||
|
public override object ProvideValue(IServiceProvider serviceProvider)
|
||||||
|
{
|
||||||
|
var binding = new ReflectionBindingExtension(Path)
|
||||||
|
{
|
||||||
|
Mode = BindingMode.OneWay,
|
||||||
|
Converter = new FuncValueConverter<double, object>(e => e*Mult + Add)
|
||||||
|
};
|
||||||
|
|
||||||
|
return binding.ProvideValue(serviceProvider);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -6,6 +6,7 @@
|
|||||||
xmlns:vm="using:AutoCat.ViewModels"
|
xmlns:vm="using:AutoCat.ViewModels"
|
||||||
xmlns:mocks="using:AutoCat.Mocks"
|
xmlns:mocks="using:AutoCat.Mocks"
|
||||||
xmlns:views="using:AutoCat.Views"
|
xmlns:views="using:AutoCat.Views"
|
||||||
|
xmlns:ext="using:AutoCat.Extensions"
|
||||||
mc:Ignorable="d" d:DesignWidth="350" d:DesignHeight="550"
|
mc:Ignorable="d" d:DesignWidth="350" d:DesignHeight="550"
|
||||||
x:Class="AutoCat.Pages.HistoryListPage"
|
x:Class="AutoCat.Pages.HistoryListPage"
|
||||||
x:DataType="vm:HistoryListViewModel"
|
x:DataType="vm:HistoryListViewModel"
|
||||||
@ -13,17 +14,35 @@
|
|||||||
DataContext="{utils:ViewModelProvider vm:HistoryListViewModel}"
|
DataContext="{utils:ViewModelProvider vm:HistoryListViewModel}"
|
||||||
Design.DataContext="mocks:HistoryListViewModelMock">
|
Design.DataContext="mocks:HistoryListViewModelMock">
|
||||||
|
|
||||||
|
<UserControl.Resources>
|
||||||
|
<ext:DateConverter x:Key="DateConverter"/>
|
||||||
|
</UserControl.Resources>
|
||||||
|
|
||||||
<ListBox ItemsSource="{Binding Vehicles}">
|
<ListBox ItemsSource="{Binding Vehicles}">
|
||||||
<ListBox.ItemTemplate>
|
<ListBox.ItemTemplate>
|
||||||
<DataTemplate>
|
<DataTemplate>
|
||||||
<StackPanel Orientation="Vertical">
|
<StackPanel Orientation="Vertical" Margin="0,4">
|
||||||
<Grid ColumnDefinitions="*">
|
<Grid ColumnDefinitions="*">
|
||||||
<TextBlock Text="{Binding Brand.Name.Original}"/>
|
<TextBlock Text="{Binding Brand.Name.Original}"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid ColumnDefinitions="* Auto" RowDefinitions="* *">
|
<Grid ColumnDefinitions="* Auto" RowDefinitions="*,*">
|
||||||
<views:PlateView Grid.RowSpan="2" Number="{Binding Number}"/>
|
<views:PlateView Grid.RowSpan="2" Number="{Binding Number}"/>
|
||||||
<TextBlock Grid.Column="1" Grid.Row="0" Text="{Binding UpdatedDate}"/>
|
<TextBlock
|
||||||
<TextBlock Grid.Column="1" Grid.Row="1" Text="{Binding AddedDate}"/>
|
Grid.Column="1"
|
||||||
|
Grid.Row="0"
|
||||||
|
Margin="16,0,0,0"
|
||||||
|
FontSize="11"
|
||||||
|
Foreground="{DynamicResource SecondaryText}"
|
||||||
|
VerticalAlignment="Bottom"
|
||||||
|
Text="{Binding UpdatedDate, Converter={StaticResource DateConverter}}"/>
|
||||||
|
<TextBlock
|
||||||
|
Grid.Column="1"
|
||||||
|
Grid.Row="1"
|
||||||
|
Margin="16,0,0,0"
|
||||||
|
FontSize="11"
|
||||||
|
Foreground="{DynamicResource TertiaryText}"
|
||||||
|
VerticalAlignment="Bottom"
|
||||||
|
Text="{Binding AddedDate, Converter={StaticResource DateConverter}}"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
xmlns:pages="clr-namespace:AutoCat.Pages"
|
xmlns:pages="clr-namespace:AutoCat.Pages"
|
||||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||||
x:Class="AutoCat.Pages.HistoryPage">
|
x:Class="AutoCat.Pages.HistoryPage">
|
||||||
<Grid ColumnDefinitions="400, Auto, *">
|
<Grid ColumnDefinitions="300, Auto, *">
|
||||||
<pages:HistoryListPage/>
|
<pages:HistoryListPage/>
|
||||||
<GridSplitter Grid.Column="1" ResizeDirection="Columns"/>
|
<GridSplitter Grid.Column="1" ResizeDirection="Columns"/>
|
||||||
<pages:ReportPage Grid.Column="2"/>
|
<pages:ReportPage Grid.Column="2"/>
|
||||||
|
|||||||
15
AutoCat/Resources/Colors.axaml
Normal file
15
AutoCat/Resources/Colors.axaml
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<ResourceDictionary xmlns="https://github.com/avaloniaui"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||||
|
|
||||||
|
<ResourceDictionary.ThemeDictionaries>
|
||||||
|
<ResourceDictionary x:Key="Default">
|
||||||
|
<SolidColorBrush x:Key="SecondaryText" Color="#666"/>
|
||||||
|
<SolidColorBrush x:Key="TertiaryText" Color="#999"/>
|
||||||
|
</ResourceDictionary>
|
||||||
|
<ResourceDictionary x:Key="Dark">
|
||||||
|
<SolidColorBrush x:Key="SecondaryText" Color="#999"/>
|
||||||
|
<SolidColorBrush x:Key="TertiaryText" Color="#666"/>
|
||||||
|
</ResourceDictionary>
|
||||||
|
</ResourceDictionary.ThemeDictionaries>
|
||||||
|
|
||||||
|
</ResourceDictionary>
|
||||||
@ -2,31 +2,52 @@
|
|||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="150"
|
xmlns:ext="clr-namespace:AutoCat.Extensions"
|
||||||
|
xmlns:views="clr-namespace:AutoCat.Views"
|
||||||
|
mc:Ignorable="d" d:DesignWidth="520" d:DesignHeight="112"
|
||||||
x:Class="AutoCat.Views.PlateView"
|
x:Class="AutoCat.Views.PlateView"
|
||||||
|
x:Name="PlateViewControl"
|
||||||
SizeChanged="UserControl_SizeChanged">
|
SizeChanged="UserControl_SizeChanged">
|
||||||
|
|
||||||
<Grid>
|
<Grid Height="{ext:Math Path=#PlateViewControl.Bounds.Width, Mult={x:Static views:PlateView.AspectRatio}}">
|
||||||
<Rectangle RadiusX="6" RadiusY="6" Fill="#ccc"/>
|
<Rectangle RadiusX="6" RadiusY="6" Fill="#ccc"/>
|
||||||
<Grid ColumnDefinitions="73*,27*">
|
<Grid ColumnDefinitions="73*,27*">
|
||||||
|
|
||||||
<Grid>
|
<Grid>
|
||||||
<Rectangle Grid.Column="0" RadiusX="4" RadiusY="4" VerticalAlignment="Stretch" Fill="#333" Margin="2"/>
|
<Rectangle Grid.Column="0" RadiusX="4" RadiusY="4" VerticalAlignment="Stretch" Fill="#333" Margin="2"/>
|
||||||
<TextBlock x:Name="NumberBox" Text="A123AA" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="#ccc"
|
<TextBlock x:Name="NumberBox"
|
||||||
FontSize="{Binding Height}"/>
|
Text="A163AA"
|
||||||
|
VerticalAlignment="Center"
|
||||||
|
HorizontalAlignment="Center"
|
||||||
|
TextAlignment="Center"
|
||||||
|
Foreground="#ccc"
|
||||||
|
FontSize="{ext:Math Path=#PlateViewControl.Bounds.Height, Mult=0.6}"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
<Rectangle Grid.Column="1" RadiusX="4" RadiusY="4" VerticalAlignment="Stretch" Fill="#333" Margin="0,2,2,2"/>
|
<Rectangle Grid.Column="1" RadiusX="4" RadiusY="4" VerticalAlignment="Stretch" Fill="#333" Margin="0,2,2,2"/>
|
||||||
<Grid Grid.Column="1" Margin="0,2,2,2" RowDefinitions="65*,35*">
|
<Grid Grid.Column="1" Margin="0,2,2,2" RowDefinitions="65*,35*">
|
||||||
<TextBlock Grid.Row="0" x:Name="RegionBox" VerticalAlignment="Center" HorizontalAlignment="Center"
|
<TextBlock Grid.Row="0"
|
||||||
Foreground="#ccc"/>
|
x:Name="RegionBox"
|
||||||
<Grid Grid.Row="1" Margin="3,1" x:Name="CountryRow" ColumnDefinitions="*,Auto">
|
Text="161"
|
||||||
<TextBlock Grid.Column="0" x:Name="CountryName" Text="RUS" VerticalAlignment="Center" TextAlignment="Center"/>
|
VerticalAlignment="Center"
|
||||||
<Grid Grid.Column="1" x:Name="FlagGrid" Margin="1" RowDefinitions="*,*,*">
|
HorizontalAlignment="Center"
|
||||||
|
Foreground="#ccc"
|
||||||
|
FontSize="{ext:Math Path=#PlateViewControl.Bounds.Height, Mult=0.35}"/>
|
||||||
|
<Grid Grid.Row="1" Margin="3,1" x:Name="CountryRow" ColumnDefinitions="Auto,*">
|
||||||
|
<TextBlock Grid.Column="0"
|
||||||
|
x:Name="CountryName"
|
||||||
|
Text="RUS"
|
||||||
|
VerticalAlignment="Center"
|
||||||
|
HorizontalAlignment="Center"
|
||||||
|
Foreground="#ccc"
|
||||||
|
FontSize="{ext:Math Path=#PlateViewControl.Bounds.Height, Mult=0.2}"/>
|
||||||
|
<!--
|
||||||
|
<Grid Grid.Column="2" x:Name="FlagGrid" Margin="1" RowDefinitions="*,*,*">
|
||||||
<Rectangle Grid.Row="0" Fill="White"/>
|
<Rectangle Grid.Row="0" Fill="White"/>
|
||||||
<Rectangle Grid.Row="1" Fill="Blue"/>
|
<Rectangle Grid.Row="1" Fill="Blue"/>
|
||||||
<Rectangle Grid.Row="2" Fill="Red"/>
|
<Rectangle Grid.Row="2" Fill="Red"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
-->
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|||||||
@ -25,7 +25,7 @@ public partial class PlateView : UserControl
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private const double AspectRatio = 112.0 / 520.0;
|
public const double AspectRatio = 112.0 / 520.0;
|
||||||
|
|
||||||
static PlateView()
|
static PlateView()
|
||||||
{
|
{
|
||||||
@ -47,25 +47,11 @@ public partial class PlateView : UserControl
|
|||||||
RegionBox.Text = number.Region();
|
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)
|
private void UserControl_SizeChanged(object sender, SizeChangedEventArgs e)
|
||||||
{
|
{
|
||||||
NumberBox.Margin = new Thickness(0, -e.NewSize.Height * 0.35, 0, 0);
|
if (Bounds.Height > 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;
|
|
||||||
|
|
||||||
if (CountryRow.Height > 0)
|
|
||||||
{
|
{
|
||||||
CountryName.FontSize = CountryRow.Height;
|
Console.WriteLine($"=== new height: {Bounds.Height}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user