Files
@ 4778889395e8
Branch filter:
Location: ATITD-Tools/Desert-Paint-Codex/Views/PaintSwatchView.axaml.cs - annotation
4778889395e8
2.5 KiB
text/x-csharp
Change the displayed permeutation count to display using locale-specific number formatting (with comma / dot separators). Fix a crash when starting a new round of recipe generation after recipe generation completed during a previous run.
40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 | using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using Avalonia.Media;
using DesertPaintCodex.Models;
using DesertPaintCodex.Services;
namespace DesertPaintCodex.Views
{
public class PaintSwatchView : UserControl
{
private static readonly SolidColorBrush NoColor = new();
public static readonly DirectProperty<PaintSwatchView, PaintColor?> ColorProperty = AvaloniaProperty.RegisterDirect<PaintSwatchView, PaintColor?>( nameof(Color),
o => o.Color,
(o, v) => o.Color = v);
private PaintColor? _color;
public PaintColor? Color { get => _color; set => SetAndRaise(ColorProperty, ref _color, value); }
public static readonly StyledProperty<bool> ShowNameProperty = AvaloniaProperty.Register<PaintSwatchView, bool>(nameof(ShowName));
public bool ShowName { get => GetValue(ShowNameProperty); set => SetValue(ShowNameProperty, value); }
private readonly Border _colorSwatch;
private readonly TextBlock _hexCode;
private readonly TextBlock _colorName;
public PaintSwatchView()
{
InitializeComponent();
_colorSwatch = this.FindControl<Border>("ColorSwatch");
_hexCode = this.FindControl<TextBlock>("HexCode");
_colorName = this.FindControl<TextBlock>("ColorName");
ColorProperty.Changed.AddClassHandler<PaintSwatchView>((x, _) => x.UpdateColor());
ShowNameProperty.Changed.AddClassHandler<PaintSwatchView>((x, _) => x.UpdateColorName());
UpdateColor();
}
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
private void UpdateColor()
{
UpdateColorSwatch();
UpdateHexCode();
UpdateColorName();
}
private void UpdateColorSwatch()
{
_colorSwatch.Background = Color == null ? NoColor : new SolidColorBrush(new Color(0xFF, Color.Red, Color.Green, Color.Blue));
}
private void UpdateHexCode()
{
_hexCode.Text = Color?.ToHexString() ?? string.Empty;
}
private void UpdateColorName()
{
if (!ShowName)
{
_colorName.IsVisible = false;
}
else
{
_colorName.IsVisible = true;
_colorName.Text = Color == null ? "[Unknown]" : PaletteService.FindNearest(Color);
}
}
}
}
|