diff --git a/demo/Semi.Avalonia.Demo/Controls/ColorItemControl.axaml b/demo/Semi.Avalonia.Demo/Controls/ColorItemControl.axaml index a1274b3..505b54b 100644 --- a/demo/Semi.Avalonia.Demo/Controls/ColorItemControl.axaml +++ b/demo/Semi.Avalonia.Demo/Controls/ColorItemControl.axaml @@ -15,7 +15,8 @@ + Background="{TemplateBinding Background}" + CornerRadius="{TemplateBinding CornerRadius}"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/demo/Semi.Avalonia.Demo/Controls/FunctionalColorGroupControl.cs b/demo/Semi.Avalonia.Demo/Controls/FunctionalColorGroupControl.cs new file mode 100644 index 0000000..cd44ade --- /dev/null +++ b/demo/Semi.Avalonia.Demo/Controls/FunctionalColorGroupControl.cs @@ -0,0 +1,38 @@ +using System.Collections; +using Avalonia; +using Avalonia.Controls.Primitives; + +namespace Semi.Avalonia.Demo.Controls; + +public class FunctionalColorGroupControl: TemplatedControl +{ + public static readonly StyledProperty TitleProperty = AvaloniaProperty.Register( + nameof(Title)); + public string? Title + { + get => GetValue(TitleProperty); + set => SetValue(TitleProperty, value); + } + + public static readonly DirectProperty LightColorsProperty = AvaloniaProperty.RegisterDirect( + 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 DarkColorsProperty = AvaloniaProperty.RegisterDirect( + nameof(DarkColors), o => o.DarkColors, (o, v) => o.DarkColors = v); + private IEnumerable _darkColors; + public IEnumerable DarkColors + { + get => _darkColors; + set => SetAndRaise(DarkColorsProperty, ref _darkColors, value); + } + + +} \ No newline at end of file diff --git a/demo/Semi.Avalonia.Demo/Pages/PaletteDemo.axaml b/demo/Semi.Avalonia.Demo/Pages/PaletteDemo.axaml index 3ed09a5..8cf0b6b 100644 --- a/demo/Semi.Avalonia.Demo/Pages/PaletteDemo.axaml +++ b/demo/Semi.Avalonia.Demo/Pages/PaletteDemo.axaml @@ -17,6 +17,7 @@ + @@ -51,6 +52,10 @@ + @@ -101,6 +106,18 @@ + + + + + + + + + diff --git a/demo/Semi.Avalonia.Demo/ViewModels/PaletteDemoViewModel.cs b/demo/Semi.Avalonia.Demo/ViewModels/PaletteDemoViewModel.cs index 1b89ecb..747e0f2 100644 --- a/demo/Semi.Avalonia.Demo/ViewModels/PaletteDemoViewModel.cs +++ b/demo/Semi.Avalonia.Demo/ViewModels/PaletteDemoViewModel.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Collections.ObjectModel; using Avalonia.Controls; using Avalonia.Markup.Xaml; @@ -36,11 +37,14 @@ public class PaletteDemoViewModel: ObservableObject set => SetProperty(ref _darkLists, value); } + public ObservableCollection FunctionalColors { get; set; } = new(); + public PaletteDemoViewModel() { _lightResourceDictionary = (ResourceDictionary)AvaloniaXamlLoader.Load(new Uri("avares://Semi.Avalonia/Themes/Light/Palette.axaml")); _darkResourceDictionary = (ResourceDictionary)AvaloniaXamlLoader.Load(new Uri("avares://Semi.Avalonia/Themes/Dark/Palette.axaml")); InitializePalette(); + InitializeFunctionalColors(); WeakReferenceMessenger.Default.Register(this, OnClickColorItem); } @@ -62,6 +66,10 @@ public class PaletteDemoViewModel: ObservableObject } } + private void InitializeFunctionalColors() + { + FunctionalColors.Add(new FunctionalColorGroupViewModel("Primary", _lightResourceDictionary, _darkResourceDictionary, ColorTokens.PrimaryTokens)); + } private void OnClickColorItem(PaletteDemoViewModel vm, ColorItemViewModel item) { SelectedColor = item; @@ -96,7 +104,7 @@ public class ColorListViewModel: ObservableObject var key = "Semi" + color + i; if (resourceDictionary.TryGetValue(key, out var value)) { - if (value is SolidColorBrush brush) + if (value is ISolidColorBrush brush) { string name = color + " " + i; var item = new ColorItemViewModel(name, brush, key, light, i); @@ -147,7 +155,7 @@ public class ColorItemViewModel : ObservableObject set => SetProperty(ref _hex, value); } - public ColorItemViewModel(string colorDisplayName, IBrush brush, string resourceKey, bool light, int index) + public ColorItemViewModel(string colorDisplayName, ISolidColorBrush brush, string resourceKey, bool light, int index) { ColorDisplayName = colorDisplayName; Brush = brush; @@ -162,4 +170,55 @@ public class ColorItemViewModel : ObservableObject TextBrush = Brushes.White; } } +} + +public class FunctionalColorGroupViewModel : ObservableObject +{ + private string _title; + public string Title + { + get => _title; + set => SetProperty(ref _title, value); + } + + public ObservableCollection LightColors { get; set; } = new(); + public ObservableCollection DarkColors { get; set; } = new(); + + public FunctionalColorGroupViewModel(string title, IResourceDictionary lightDictionary, IResourceDictionary darkDictionary, IReadOnlyList> tokens) + { + Title = title; + foreach (var token in tokens) + { + string key = token.Item1; + string name = token.Item2; + if (lightDictionary.TryGetValue(key, out var lightValue)) + { + if (lightValue is ISolidColorBrush lightBrush) + { + LightColors.Add(new ColorItemViewModel(name, lightBrush, key, true, 0)); + } + } + if (darkDictionary.TryGetValue(key, out var darkValue)) + { + if (darkValue is ISolidColorBrush darkBrush) + { + DarkColors.Add(new ColorItemViewModel(name, darkBrush, key, true, 0)); + } + } + } + } +} + +public static class ColorTokens +{ + public static IReadOnlyList> PrimaryTokens { get; } = new List> + { + new ("SemiColorPrimary", "Primary"), + new ("SemiColorPrimaryPointerover", "Primary Pointerover"), + new ("SemiColorPrimaryPressed", "Primary Pressed"), + new ("SemiColorPrimaryDisabled", "Primary Disabled"), + new ("SemiColorPrimaryLight", "Primary Light"), + new ("SemiColorPrimaryLightPointerover", "Primary Light Pointerover"), + new ("SemiColorPrimaryLightActive", "Primary Light Active"), + }; } \ No newline at end of file diff --git a/src/Semi.Avalonia/Themes/Dark/Palette.axaml b/src/Semi.Avalonia/Themes/Dark/Palette.axaml index c5c8e70..923c8b5 100644 --- a/src/Semi.Avalonia/Themes/Dark/Palette.axaml +++ b/src/Semi.Avalonia/Themes/Dark/Palette.axaml @@ -166,85 +166,85 @@ - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Semi.Avalonia/Themes/Light/Palette.axaml b/src/Semi.Avalonia/Themes/Light/Palette.axaml index 4032938..c6b3898 100644 --- a/src/Semi.Avalonia/Themes/Light/Palette.axaml +++ b/src/Semi.Avalonia/Themes/Light/Palette.axaml @@ -214,37 +214,37 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +