misc: format codes.
(cherry picked from commit d1d235a1200b589b3dec7e1cf2c7adbf465adc85)
This commit is contained in:
parent
c87f6a8112
commit
ebdb0b1b93
@ -6,31 +6,36 @@ namespace Semi.Avalonia.Demo.Controls;
|
||||
|
||||
public class FunctionalColorGroupControl : TemplatedControl
|
||||
{
|
||||
public static readonly StyledProperty<string?> TitleProperty = AvaloniaProperty.Register<FunctionalColorGroupControl, string?>(
|
||||
nameof(Title));
|
||||
public static readonly StyledProperty<string?> TitleProperty =
|
||||
AvaloniaProperty.Register<FunctionalColorGroupControl, string?>(nameof(Title));
|
||||
|
||||
public string? Title
|
||||
{
|
||||
get => GetValue(TitleProperty);
|
||||
set => SetValue(TitleProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DirectProperty<FunctionalColorGroupControl, IEnumerable?> LightColorsProperty = AvaloniaProperty.RegisterDirect<FunctionalColorGroupControl, IEnumerable?>(
|
||||
nameof(LightColors), o => o.LightColors, (o, v) => o.LightColors = v);
|
||||
public static readonly DirectProperty<FunctionalColorGroupControl, IEnumerable?> LightColorsProperty =
|
||||
AvaloniaProperty.RegisterDirect<FunctionalColorGroupControl, IEnumerable?>(nameof(LightColors),
|
||||
o => o.LightColors, (o, v) => o.LightColors = v);
|
||||
|
||||
private IEnumerable? _lightColors;
|
||||
|
||||
public IEnumerable? LightColors
|
||||
{
|
||||
get => _lightColors;
|
||||
set => SetAndRaise(LightColorsProperty, ref _lightColors, value);
|
||||
}
|
||||
|
||||
public static readonly DirectProperty<FunctionalColorGroupControl, IEnumerable?> DarkColorsProperty = AvaloniaProperty.RegisterDirect<FunctionalColorGroupControl, IEnumerable?>(
|
||||
nameof(DarkColors), o => o.DarkColors, (o, v) => o.DarkColors = v);
|
||||
public static readonly DirectProperty<FunctionalColorGroupControl, IEnumerable?> DarkColorsProperty =
|
||||
AvaloniaProperty.RegisterDirect<FunctionalColorGroupControl, IEnumerable?>(nameof(DarkColors),
|
||||
o => o.DarkColors, (o, v) => o.DarkColors = v);
|
||||
|
||||
private IEnumerable? _darkColors;
|
||||
|
||||
public IEnumerable? DarkColors
|
||||
{
|
||||
get => _darkColors;
|
||||
set => SetAndRaise(DarkColorsProperty, ref _darkColors, value);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -2,7 +2,6 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.Media;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
@ -12,12 +11,13 @@ namespace Semi.Avalonia.Demo.ViewModels;
|
||||
public class PaletteDemoViewModel : ObservableObject
|
||||
{
|
||||
private readonly string[] _predefinedColorNames =
|
||||
{
|
||||
[
|
||||
"Red", "Pink", "Purple", "Violet", "Indigo",
|
||||
"Blue", "LightBlue", "Cyan", "Teal", "Green",
|
||||
"LightGreen", "Lime", "Yellow", "Amber", "Orange",
|
||||
"Grey"
|
||||
};
|
||||
];
|
||||
|
||||
private readonly IResourceDictionary? _lightResourceDictionary;
|
||||
private readonly IResourceDictionary? _darkResourceDictionary;
|
||||
|
||||
@ -31,19 +31,22 @@ public class PaletteDemoViewModel: ObservableObject
|
||||
|
||||
|
||||
private ObservableCollection<ColorListViewModel>? _lightLists;
|
||||
|
||||
public ObservableCollection<ColorListViewModel>? LightLists
|
||||
{
|
||||
get => _lightLists;
|
||||
set => SetProperty(ref _lightLists, value);
|
||||
}
|
||||
|
||||
private ObservableCollection<ColorListViewModel>? _darkLists;
|
||||
|
||||
public ObservableCollection<ColorListViewModel>? DarkLists
|
||||
{
|
||||
get => _darkLists;
|
||||
set => SetProperty(ref _darkLists, value);
|
||||
}
|
||||
|
||||
public ObservableCollection<FunctionalColorGroupViewModel> FunctionalColors { get; set; } = new();
|
||||
public ObservableCollection<FunctionalColorGroupViewModel> FunctionalColors { get; set; } = [];
|
||||
|
||||
public PaletteDemoViewModel()
|
||||
{
|
||||
@ -60,14 +63,15 @@ public class PaletteDemoViewModel: ObservableObject
|
||||
|
||||
private void InitializePalette()
|
||||
{
|
||||
LightLists = new ObservableCollection<ColorListViewModel>();
|
||||
LightLists = [];
|
||||
foreach (var color in _predefinedColorNames)
|
||||
{
|
||||
ColorListViewModel s = new ColorListViewModel();
|
||||
s.Initialize(_lightResourceDictionary, color, true);
|
||||
LightLists.Add(s);
|
||||
}
|
||||
DarkLists = new ObservableCollection<ColorListViewModel>();
|
||||
|
||||
DarkLists = [];
|
||||
foreach (var color in _predefinedColorNames)
|
||||
{
|
||||
ColorListViewModel s = new ColorListViewModel();
|
||||
@ -92,6 +96,7 @@ public class PaletteDemoViewModel: ObservableObject
|
||||
FunctionalColors.Add(new FunctionalColorGroupViewModel("Border", _lightResourceDictionary, _darkResourceDictionary, ColorTokens.BorderTokens));
|
||||
FunctionalColors.Add(new FunctionalColorGroupViewModel("Disabled", _lightResourceDictionary, _darkResourceDictionary, ColorTokens.DisabledTokens));
|
||||
}
|
||||
|
||||
private void OnClickColorItem(PaletteDemoViewModel vm, ColorItemViewModel item)
|
||||
{
|
||||
SelectedColor = item;
|
||||
@ -122,10 +127,11 @@ public class ColorListViewModel: ObservableObject
|
||||
{
|
||||
return;
|
||||
}
|
||||
SeriesName = color;
|
||||
Color = new ObservableCollection<ColorItemViewModel>();
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
SeriesName = color;
|
||||
Color = [];
|
||||
|
||||
for (var i = 0; i < 10; i++)
|
||||
{
|
||||
var key = "Semi" + color + i;
|
||||
if (resourceDictionary.TryGetValue(key, out var value))
|
||||
@ -144,8 +150,8 @@ public class ColorListViewModel: ObservableObject
|
||||
|
||||
public class ColorItemViewModel : ObservableObject
|
||||
{
|
||||
|
||||
private IBrush _brush = null!;
|
||||
|
||||
public IBrush Brush
|
||||
{
|
||||
get => _brush;
|
||||
@ -153,6 +159,7 @@ public class ColorItemViewModel : ObservableObject
|
||||
}
|
||||
|
||||
private IBrush _textBrush = null!;
|
||||
|
||||
public IBrush TextBrush
|
||||
{
|
||||
get => _textBrush;
|
||||
@ -160,6 +167,7 @@ public class ColorItemViewModel : ObservableObject
|
||||
}
|
||||
|
||||
private string _colorDisplayName = null!;
|
||||
|
||||
public string ColorDisplayName
|
||||
{
|
||||
get => _colorDisplayName;
|
||||
@ -190,7 +198,8 @@ public class ColorItemViewModel : ObservableObject
|
||||
set => SetProperty(ref _hex, value);
|
||||
}
|
||||
|
||||
public ColorItemViewModel(string colorDisplayName, ISolidColorBrush brush, string resourceKey, bool light, int index)
|
||||
public ColorItemViewModel(string colorDisplayName, ISolidColorBrush brush, string resourceKey, bool light,
|
||||
int index)
|
||||
{
|
||||
ColorDisplayName = colorDisplayName;
|
||||
Brush = brush;
|
||||
@ -210,22 +219,22 @@ public class ColorItemViewModel : ObservableObject
|
||||
public class FunctionalColorGroupViewModel : ObservableObject
|
||||
{
|
||||
private string _title = null!;
|
||||
|
||||
public string Title
|
||||
{
|
||||
get => _title;
|
||||
set => SetProperty(ref _title, value);
|
||||
}
|
||||
|
||||
public ObservableCollection<ColorItemViewModel> LightColors { get; set; } = new();
|
||||
public ObservableCollection<ColorItemViewModel> DarkColors { get; set; } = new();
|
||||
public ObservableCollection<ColorItemViewModel> LightColors { get; set; } = [];
|
||||
public ObservableCollection<ColorItemViewModel> DarkColors { get; set; } = [];
|
||||
|
||||
public FunctionalColorGroupViewModel(string title, IResourceDictionary? lightDictionary, IResourceDictionary? darkDictionary, IReadOnlyList<Tuple<string, string>> tokens)
|
||||
public FunctionalColorGroupViewModel(string title, IResourceDictionary? lightDictionary,
|
||||
IResourceDictionary? darkDictionary, IReadOnlyList<Tuple<string, string>> tokens)
|
||||
{
|
||||
Title = title;
|
||||
foreach (var token in tokens)
|
||||
foreach (var (key, name) in tokens)
|
||||
{
|
||||
string key = token.Item1;
|
||||
string name = token.Item2;
|
||||
if (lightDictionary?.TryGetValue(key, out var lightValue) ?? false)
|
||||
{
|
||||
if (lightValue is ISolidColorBrush lightBrush)
|
||||
@ -365,5 +374,4 @@ public static class ColorTokens
|
||||
new("SemiColorDisabledBackground", "Disabled Background"),
|
||||
new("SemiColorDisabledFill", "Disabled Fill"),
|
||||
};
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user