From 9499bab92f154400661d7e48b4a064a589db1ab3 Mon Sep 17 00:00:00 2001 From: rabbitism Date: Sat, 11 Feb 2023 15:50:39 +0800 Subject: [PATCH 01/11] feat: setup colors. --- .../Pages/PaletteDemo.axaml | 34 ++++ .../Pages/PaletteDemo.axaml.cs | 13 ++ .../Semi.Avalonia.Demo.csproj | 2 +- .../ViewModels/PaletteDemoViewModel.cs | 17 ++ demo/Semi.Avalonia.Demo/Views/MainView.axaml | 3 + src/Semi.Avalonia/Themes/Dark/Palette.axaml | 166 ++++++++++++++++- src/Semi.Avalonia/Themes/Light/Palette.axaml | 169 +++++++++++++++++- 7 files changed, 397 insertions(+), 7 deletions(-) create mode 100644 demo/Semi.Avalonia.Demo/Pages/PaletteDemo.axaml create mode 100644 demo/Semi.Avalonia.Demo/Pages/PaletteDemo.axaml.cs create mode 100644 demo/Semi.Avalonia.Demo/ViewModels/PaletteDemoViewModel.cs diff --git a/demo/Semi.Avalonia.Demo/Pages/PaletteDemo.axaml b/demo/Semi.Avalonia.Demo/Pages/PaletteDemo.axaml new file mode 100644 index 0000000..b0206c4 --- /dev/null +++ b/demo/Semi.Avalonia.Demo/Pages/PaletteDemo.axaml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + diff --git a/demo/Semi.Avalonia.Demo/Pages/PaletteDemo.axaml.cs b/demo/Semi.Avalonia.Demo/Pages/PaletteDemo.axaml.cs new file mode 100644 index 0000000..d9c359b --- /dev/null +++ b/demo/Semi.Avalonia.Demo/Pages/PaletteDemo.axaml.cs @@ -0,0 +1,13 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Markup.Xaml; + +namespace Semi.Avalonia.Demo.Pages; + +public partial class PaletteDemo : UserControl +{ + public PaletteDemo() + { + InitializeComponent(); + } +} \ No newline at end of file diff --git a/demo/Semi.Avalonia.Demo/Semi.Avalonia.Demo.csproj b/demo/Semi.Avalonia.Demo/Semi.Avalonia.Demo.csproj index 7d026cc..545f3dc 100644 --- a/demo/Semi.Avalonia.Demo/Semi.Avalonia.Demo.csproj +++ b/demo/Semi.Avalonia.Demo/Semi.Avalonia.Demo.csproj @@ -49,6 +49,6 @@ - + diff --git a/demo/Semi.Avalonia.Demo/ViewModels/PaletteDemoViewModel.cs b/demo/Semi.Avalonia.Demo/ViewModels/PaletteDemoViewModel.cs new file mode 100644 index 0000000..a4f7904 --- /dev/null +++ b/demo/Semi.Avalonia.Demo/ViewModels/PaletteDemoViewModel.cs @@ -0,0 +1,17 @@ +using Avalonia.Controls; +using CommunityToolkit.Mvvm.ComponentModel; + +namespace Semi.Avalonia.Demo.ViewModels; + +public class PaletteDemoViewModel: ObservableObject +{ + private string[] _colors = { "Amber","Blue","Cyan","Green","Grey","Indigo","LightBlue","LightGreen","Lime","Orange","Pink","Purple","Red","Teal","Violet","Yellow" }; +} + +public class ColorSeries: ObservableObject +{ + internal void Initialize(IResourceDictionary resourceDictionary, string color) + { + + } +} \ No newline at end of file diff --git a/demo/Semi.Avalonia.Demo/Views/MainView.axaml b/demo/Semi.Avalonia.Demo/Views/MainView.axaml index 0074644..5633d11 100644 --- a/demo/Semi.Avalonia.Demo/Views/MainView.axaml +++ b/demo/Semi.Avalonia.Demo/Views/MainView.axaml @@ -56,6 +56,9 @@ + + + diff --git a/src/Semi.Avalonia/Themes/Dark/Palette.axaml b/src/Semi.Avalonia/Themes/Dark/Palette.axaml index 779852d..5bf6dbc 100644 --- a/src/Semi.Avalonia/Themes/Dark/Palette.axaml +++ b/src/Semi.Avalonia/Themes/Dark/Palette.axaml @@ -1,4 +1,164 @@ - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Semi.Avalonia/Themes/Light/Palette.axaml b/src/Semi.Avalonia/Themes/Light/Palette.axaml index 779852d..2c5523d 100644 --- a/src/Semi.Avalonia/Themes/Light/Palette.axaml +++ b/src/Semi.Avalonia/Themes/Light/Palette.axaml @@ -1,4 +1,167 @@ - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 7fd45c7342fd2959453d837c8e90585d972879ca Mon Sep 17 00:00:00 2001 From: rabbitism Date: Sat, 11 Feb 2023 23:04:07 +0800 Subject: [PATCH 02/11] feat: load resources from dictionary. --- demo/Semi.Avalonia.Demo.Desktop/App.axaml | 3 +- .../Pages/PaletteDemo.axaml | 63 +++++++++++--- .../Pages/PaletteDemo.axaml.cs | 2 + .../Themes/ToggleButton.axaml | 1 - .../ViewModels/PaletteDemoViewModel.cs | 87 +++++++++++++++++++ 5 files changed, 141 insertions(+), 15 deletions(-) diff --git a/demo/Semi.Avalonia.Demo.Desktop/App.axaml b/demo/Semi.Avalonia.Demo.Desktop/App.axaml index cb85fcd..9628b3e 100644 --- a/demo/Semi.Avalonia.Demo.Desktop/App.axaml +++ b/demo/Semi.Avalonia.Demo.Desktop/App.axaml @@ -2,7 +2,8 @@ x:Class="Semi.Avalonia.Demo.Desktop.App" xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" - xmlns:local="using:Semi.Avalonia.Demo.Desktop"> + xmlns:local="using:Semi.Avalonia.Demo.Desktop" + RequestedThemeVariant="Dark"> diff --git a/demo/Semi.Avalonia.Demo/Pages/PaletteDemo.axaml b/demo/Semi.Avalonia.Demo/Pages/PaletteDemo.axaml index b0206c4..7ec3669 100644 --- a/demo/Semi.Avalonia.Demo/Pages/PaletteDemo.axaml +++ b/demo/Semi.Avalonia.Demo/Pages/PaletteDemo.axaml @@ -4,31 +4,68 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:viewModels="clr-namespace:Semi.Avalonia.Demo.ViewModels" d:DesignHeight="450" d:DesignWidth="800" mc:Ignorable="d"> + + + - - - - - - + + + + + + + + + + + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/demo/Semi.Avalonia.Demo/Pages/PaletteDemo.axaml.cs b/demo/Semi.Avalonia.Demo/Pages/PaletteDemo.axaml.cs index d9c359b..321e719 100644 --- a/demo/Semi.Avalonia.Demo/Pages/PaletteDemo.axaml.cs +++ b/demo/Semi.Avalonia.Demo/Pages/PaletteDemo.axaml.cs @@ -1,6 +1,7 @@ using Avalonia; using Avalonia.Controls; using Avalonia.Markup.Xaml; +using Semi.Avalonia.Demo.ViewModels; namespace Semi.Avalonia.Demo.Pages; @@ -9,5 +10,6 @@ public partial class PaletteDemo : UserControl public PaletteDemo() { InitializeComponent(); + this.DataContext = new PaletteDemoViewModel(); } } \ No newline at end of file diff --git a/demo/Semi.Avalonia.Demo/Themes/ToggleButton.axaml b/demo/Semi.Avalonia.Demo/Themes/ToggleButton.axaml index 6a113d4..e3c7231 100644 --- a/demo/Semi.Avalonia.Demo/Themes/ToggleButton.axaml +++ b/demo/Semi.Avalonia.Demo/Themes/ToggleButton.axaml @@ -27,7 +27,6 @@ - diff --git a/demo/Semi.Avalonia.Demo/ViewModels/PaletteDemoViewModel.cs b/demo/Semi.Avalonia.Demo/ViewModels/PaletteDemoViewModel.cs index a4f7904..515c832 100644 --- a/demo/Semi.Avalonia.Demo/ViewModels/PaletteDemoViewModel.cs +++ b/demo/Semi.Avalonia.Demo/ViewModels/PaletteDemoViewModel.cs @@ -1,4 +1,8 @@ +using System; +using System.Collections.ObjectModel; using Avalonia.Controls; +using Avalonia.Markup.Xaml; +using Avalonia.Media; using CommunityToolkit.Mvvm.ComponentModel; namespace Semi.Avalonia.Demo.ViewModels; @@ -6,12 +10,95 @@ namespace Semi.Avalonia.Demo.ViewModels; public class PaletteDemoViewModel: ObservableObject { private string[] _colors = { "Amber","Blue","Cyan","Green","Grey","Indigo","LightBlue","LightGreen","Lime","Orange","Pink","Purple","Red","Teal","Violet","Yellow" }; + private ObservableCollection _series; + + public ObservableCollection Series + { + get => _series; + set => SetProperty(ref _series, value); + } + + public PaletteDemoViewModel() + { + Series = new ObservableCollection(); + var resouceDictionary = (ResourceDictionary)(AvaloniaXamlLoader.Load(new Uri("avares://Semi.Avalonia/Themes/Light/Palette.axaml"))); + foreach (var color in _colors) + { + ColorSeries s = new ColorSeries(); + s.Initialize(resouceDictionary, color); + Series.Add(s); + } + } } public class ColorSeries: ObservableObject { + private ObservableCollection? _colors; + + public ObservableCollection? Color + { + get => _colors; + set => SetProperty(ref _colors, value); + } + + private string? _seriesName; + + public string? SeriesName + { + get => _seriesName; + set => SetProperty(ref _seriesName, value); + } + internal void Initialize(IResourceDictionary resourceDictionary, string color) { + SeriesName = color; + Color = new ObservableCollection(); + for (int i = 0; i < 10; i++) + { + var key = "Semi" + color + i; + if (resourceDictionary.TryGetValue(key, out var value)) + { + if (value is SolidColorBrush brush) + { + string name = color + " " + i; + var item = new ColorItemViewModel(name, brush, key); + Color.Add(item); + } + } + } + } +} + +public class ColorItemViewModel : ObservableObject +{ + + private IBrush _color; + public IBrush Color + { + get => _color; + set => SetProperty(ref _color, value); + } + + private string _name; + public string Name + { + get => _name; + set => SetProperty(ref _name, value); + } + + private string _resourceKey; + + public string ResourceKey + { + get => _resourceKey; + set => SetProperty(ref _resourceKey, value); + } + + public ColorItemViewModel(string name, IBrush color, string resourceKey) + { + Name = name; + Color = color; + ResourceKey = resourceKey; } } \ No newline at end of file From 888d115ca8d56bfbfa1677e68803fec78f2f853f Mon Sep 17 00:00:00 2001 From: rabbitism Date: Sun, 12 Feb 2023 00:56:45 +0800 Subject: [PATCH 03/11] feat: Add ColorItemControl and color detail preview. --- .../Controls/ColorItemControl.axaml | 43 +++++++++ .../Controls/ColorItemControl.cs | 39 ++++++++ .../Pages/PaletteDemo.axaml | 92 +++++++++++++------ .../Semi.Avalonia.Demo.csproj | 4 - .../ViewModels/PaletteDemoViewModel.cs | 77 +++++++++++++--- 5 files changed, 214 insertions(+), 41 deletions(-) create mode 100644 demo/Semi.Avalonia.Demo/Controls/ColorItemControl.axaml create mode 100644 demo/Semi.Avalonia.Demo/Controls/ColorItemControl.cs diff --git a/demo/Semi.Avalonia.Demo/Controls/ColorItemControl.axaml b/demo/Semi.Avalonia.Demo/Controls/ColorItemControl.axaml new file mode 100644 index 0000000..479f9ba --- /dev/null +++ b/demo/Semi.Avalonia.Demo/Controls/ColorItemControl.axaml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/demo/Semi.Avalonia.Demo/Controls/ColorItemControl.cs b/demo/Semi.Avalonia.Demo/Controls/ColorItemControl.cs new file mode 100644 index 0000000..04c8000 --- /dev/null +++ b/demo/Semi.Avalonia.Demo/Controls/ColorItemControl.cs @@ -0,0 +1,39 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Controls.Primitives; +using Avalonia.Input; +using CommunityToolkit.Mvvm.Messaging; +using Semi.Avalonia.Demo.ViewModels; + +namespace Semi.Avalonia.Demo.Controls; + +public class ColorItemControl : TemplatedControl +{ + public static readonly StyledProperty ColorNameProperty = AvaloniaProperty.Register( + nameof(ColorName)); + + public string? ColorName + { + get => GetValue(ColorNameProperty); + set => SetValue(ColorNameProperty, value); + } + + public static readonly StyledProperty HexProperty = AvaloniaProperty.Register( + nameof(Hex)); + + public string? Hex + { + get => GetValue(HexProperty); + set => SetValue(HexProperty, value); + } + + protected override void OnPointerPressed(PointerPressedEventArgs e) + { + base.OnPointerPressed(e); + if (this.DataContext is ColorItemViewModel v) + { + WeakReferenceMessenger.Default.Send(v); + } + + } +} \ 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 7ec3669..c90235e 100644 --- a/demo/Semi.Avalonia.Demo/Pages/PaletteDemo.axaml +++ b/demo/Semi.Avalonia.Demo/Pages/PaletteDemo.axaml @@ -2,6 +2,7 @@ x:Class="Semi.Avalonia.Demo.Pages.PaletteDemo" xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:controls="clr-namespace:Semi.Avalonia.Demo.Controls" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:viewModels="clr-namespace:Semi.Avalonia.Demo.ViewModels" @@ -11,6 +12,13 @@ + + + + + + + - - - + + + @@ -41,29 +54,56 @@ - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/demo/Semi.Avalonia.Demo/Semi.Avalonia.Demo.csproj b/demo/Semi.Avalonia.Demo/Semi.Avalonia.Demo.csproj index 545f3dc..ad24460 100644 --- a/demo/Semi.Avalonia.Demo/Semi.Avalonia.Demo.csproj +++ b/demo/Semi.Avalonia.Demo/Semi.Avalonia.Demo.csproj @@ -47,8 +47,4 @@ - - - - diff --git a/demo/Semi.Avalonia.Demo/ViewModels/PaletteDemoViewModel.cs b/demo/Semi.Avalonia.Demo/ViewModels/PaletteDemoViewModel.cs index 515c832..8cf0939 100644 --- a/demo/Semi.Avalonia.Demo/ViewModels/PaletteDemoViewModel.cs +++ b/demo/Semi.Avalonia.Demo/ViewModels/PaletteDemoViewModel.cs @@ -4,30 +4,61 @@ using Avalonia.Controls; using Avalonia.Markup.Xaml; using Avalonia.Media; using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Messaging; namespace Semi.Avalonia.Demo.ViewModels; public class PaletteDemoViewModel: ObservableObject { private string[] _colors = { "Amber","Blue","Cyan","Green","Grey","Indigo","LightBlue","LightGreen","Lime","Orange","Pink","Purple","Red","Teal","Violet","Yellow" }; - private ObservableCollection _series; + private ObservableCollection _lightSeries; - public ObservableCollection Series + private ColorItemViewModel _selectedColor; + + public ColorItemViewModel SelectedColor { - get => _series; - set => SetProperty(ref _series, value); + get => _selectedColor; + set => SetProperty(ref _selectedColor, value); + } + + public ObservableCollection LightSeries + { + get => _lightSeries; + set => SetProperty(ref _lightSeries, value); + } + + private ObservableCollection _darkSeries; + + public ObservableCollection DarkSeries + { + get => _darkSeries; + set => SetProperty(ref _darkSeries, value); } public PaletteDemoViewModel() { - Series = new ObservableCollection(); - var resouceDictionary = (ResourceDictionary)(AvaloniaXamlLoader.Load(new Uri("avares://Semi.Avalonia/Themes/Light/Palette.axaml"))); + LightSeries = new ObservableCollection(); + var lightResourceDictionary = (ResourceDictionary)(AvaloniaXamlLoader.Load(new Uri("avares://Semi.Avalonia/Themes/Light/Palette.axaml"))); foreach (var color in _colors) { ColorSeries s = new ColorSeries(); - s.Initialize(resouceDictionary, color); - Series.Add(s); + s.Initialize(lightResourceDictionary, color, true); + LightSeries.Add(s); } + DarkSeries = new ObservableCollection(); + var darkResouceDictionary = (ResourceDictionary)(AvaloniaXamlLoader.Load(new Uri("avares://Semi.Avalonia/Themes/Dark/Palette.axaml"))); + foreach (var color in _colors) + { + ColorSeries s = new ColorSeries(); + s.Initialize(darkResouceDictionary, color, false); + DarkSeries.Add(s); + } + WeakReferenceMessenger.Default.Register(this, OnClickColorItem); + } + + private void OnClickColorItem(PaletteDemoViewModel vm, ColorItemViewModel item) + { + SelectedColor = item; } } @@ -49,7 +80,7 @@ public class ColorSeries: ObservableObject set => SetProperty(ref _seriesName, value); } - internal void Initialize(IResourceDictionary resourceDictionary, string color) + internal void Initialize(IResourceDictionary resourceDictionary, string color, bool light) { SeriesName = color; Color = new ObservableCollection(); @@ -62,7 +93,7 @@ public class ColorSeries: ObservableObject if (value is SolidColorBrush brush) { string name = color + " " + i; - var item = new ColorItemViewModel(name, brush, key); + var item = new ColorItemViewModel(name, brush, key, light, i); Color.Add(item); } } @@ -79,6 +110,13 @@ public class ColorItemViewModel : ObservableObject get => _color; set => SetProperty(ref _color, value); } + + private IBrush _textColor; + public IBrush TextColor + { + get => _textColor; + set => SetProperty(ref _textColor, value); + } private string _name; public string Name @@ -94,11 +132,28 @@ public class ColorItemViewModel : ObservableObject get => _resourceKey; set => SetProperty(ref _resourceKey, value); } + + private string _hex; + + public string Hex + { + get => _hex; + set => SetProperty(ref _hex, value); + } - public ColorItemViewModel(string name, IBrush color, string resourceKey) + public ColorItemViewModel(string name, IBrush color, string resourceKey, bool light, int index) { Name = name; Color = color; ResourceKey = resourceKey; + Hex = color.ToString().ToUpperInvariant(); + if ((light && index < 5) || (!light && index > 5)) + { + TextColor = Brushes.Black; + } + else + { + TextColor = Brushes.White; + } } } \ No newline at end of file From bf87bfeb9012c967953e01f8fd74ec2afe1e9965 Mon Sep 17 00:00:00 2001 From: rabbitism Date: Mon, 13 Feb 2023 00:14:56 +0800 Subject: [PATCH 04/11] feat: add color preview control. --- .../Controls/ColorDetailControl.axaml | 109 ++++++++++++++++++ .../Controls/ColorDetailControl.cs | 91 +++++++++++++++ .../Controls/ColorItemControl.axaml | 2 +- .../Pages/PaletteDemo.axaml | 37 +++--- .../ViewModels/PaletteDemoViewModel.cs | 104 +++++++++-------- src/Semi.Avalonia/Themes/Dark/SplitView.axaml | 2 +- 6 files changed, 274 insertions(+), 71 deletions(-) create mode 100644 demo/Semi.Avalonia.Demo/Controls/ColorDetailControl.axaml create mode 100644 demo/Semi.Avalonia.Demo/Controls/ColorDetailControl.cs diff --git a/demo/Semi.Avalonia.Demo/Controls/ColorDetailControl.axaml b/demo/Semi.Avalonia.Demo/Controls/ColorDetailControl.axaml new file mode 100644 index 0000000..81d842e --- /dev/null +++ b/demo/Semi.Avalonia.Demo/Controls/ColorDetailControl.axaml @@ -0,0 +1,109 @@ + + M5 7C3.89543 7 3 7.89543 3 9V19C3 20.1046 3.89543 21 5 21H15C16.1046 21 17 20.1046 17 19V9C17 7.89543 16.1046 7 15 7H5Z,M7 4C7 2.89543 7.89543 2 9 2H20C21.1046 2 22 2.89543 22 4V15C22 16.1046 21.1046 17 20 17H19V8C19 6 18 5 16 5H7V4Z + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/demo/Semi.Avalonia.Demo/Controls/ColorDetailControl.cs b/demo/Semi.Avalonia.Demo/Controls/ColorDetailControl.cs new file mode 100644 index 0000000..0dfc7d8 --- /dev/null +++ b/demo/Semi.Avalonia.Demo/Controls/ColorDetailControl.cs @@ -0,0 +1,91 @@ +using System.Globalization; +using Avalonia; +using Avalonia.Controls.Primitives; +using Avalonia.Input.Platform; +using Avalonia.Media; +using Avalonia.Media.Immutable; + +namespace Semi.Avalonia.Demo.Controls; + +public class ColorDetailControl: TemplatedControl +{ + public const string KEY_ResourceKey = "ResourceKey"; + public const string KEY_Hex = "Hex"; + public const string KEY_Opacity = "Opacity"; + + public static readonly StyledProperty ResourceKeyProperty = AvaloniaProperty.Register( + nameof(ResourceKey)); + public string? ResourceKey + { + get => GetValue(ResourceKeyProperty); + set => SetValue(ResourceKeyProperty, value); + } + + public static readonly StyledProperty ResourceNameProperty = AvaloniaProperty.Register( + nameof(ResourceName)); + + public string? ResourceName + { + get => GetValue(ResourceNameProperty); + set => SetValue(ResourceNameProperty, value); + } + + public static readonly DirectProperty HexProperty = AvaloniaProperty.RegisterDirect( + nameof(Hex), o => o.Hex); + private string? _hex; + public string? Hex + { + get => _hex; + private set => SetAndRaise(HexProperty, ref _hex, value); + } + + public static readonly DirectProperty OpacityNumberProperty = AvaloniaProperty.RegisterDirect( + nameof(OpacityNumber), o => o.OpacityNumber); + private string? _opacityNumber; + public string? OpacityNumber + { + get => _opacityNumber; + private set => SetAndRaise(OpacityNumberProperty, ref _opacityNumber, value); + } + + + static ColorDetailControl() + { + BackgroundProperty.Changed.AddClassHandler((o, e) => o.OnBackgroundChanged(e)); + } + + private void OnBackgroundChanged(AvaloniaPropertyChangedEventArgs args) + { + var color = args.GetNewValue(); + if (color is ISolidColorBrush b) + { + Hex = b.Color.ToString().ToUpperInvariant(); + OpacityNumber = b.Opacity.ToString(CultureInfo.InvariantCulture); + } + } + + public async void Copy(object o) + { + string? text = null; + if (o is string s) + { + switch (s) + { + case KEY_ResourceKey: text = ResourceKey; + break; + case KEY_Hex: text = Hex; + break; + case KEY_Opacity: text = OpacityNumber; + break; + default: text = string.Empty; break; + } + } + + if (Application.Current is { Clipboard: { } c }) + { + await c.SetTextAsync(text??string.Empty); + } + + } + +} \ No newline at end of file diff --git a/demo/Semi.Avalonia.Demo/Controls/ColorItemControl.axaml b/demo/Semi.Avalonia.Demo/Controls/ColorItemControl.axaml index 479f9ba..a1274b3 100644 --- a/demo/Semi.Avalonia.Demo/Controls/ColorItemControl.axaml +++ b/demo/Semi.Avalonia.Demo/Controls/ColorItemControl.axaml @@ -27,7 +27,7 @@ Name="PART_HexTextBlock" Padding="8" VerticalAlignment="Bottom" - FontSize="8" + FontSize="10" Foreground="{TemplateBinding Foreground}" IsVisible="False" Opacity="0.8" diff --git a/demo/Semi.Avalonia.Demo/Pages/PaletteDemo.axaml b/demo/Semi.Avalonia.Demo/Pages/PaletteDemo.axaml index c90235e..3ed09a5 100644 --- a/demo/Semi.Avalonia.Demo/Pages/PaletteDemo.axaml +++ b/demo/Semi.Avalonia.Demo/Pages/PaletteDemo.axaml @@ -16,6 +16,7 @@ + @@ -31,6 +32,7 @@ - - - + - - + - + @@ -80,21 +77,21 @@ - + - + diff --git a/demo/Semi.Avalonia.Demo/ViewModels/PaletteDemoViewModel.cs b/demo/Semi.Avalonia.Demo/ViewModels/PaletteDemoViewModel.cs index 8cf0939..1b89ecb 100644 --- a/demo/Semi.Avalonia.Demo/ViewModels/PaletteDemoViewModel.cs +++ b/demo/Semi.Avalonia.Demo/ViewModels/PaletteDemoViewModel.cs @@ -10,9 +10,10 @@ namespace Semi.Avalonia.Demo.ViewModels; public class PaletteDemoViewModel: ObservableObject { - private string[] _colors = { "Amber","Blue","Cyan","Green","Grey","Indigo","LightBlue","LightGreen","Lime","Orange","Pink","Purple","Red","Teal","Violet","Yellow" }; - private ObservableCollection _lightSeries; - + private readonly string[] _predefinedColorNames = { "Amber","Blue","Cyan","Green","Grey","Indigo","LightBlue","LightGreen","Lime","Orange","Pink","Purple","Red","Teal","Violet","Yellow" }; + private IResourceDictionary _lightResourceDictionary; + private IResourceDictionary _darkResourceDictionary; + private ColorItemViewModel _selectedColor; public ColorItemViewModel SelectedColor @@ -20,49 +21,54 @@ public class PaletteDemoViewModel: ObservableObject get => _selectedColor; set => SetProperty(ref _selectedColor, value); } - - public ObservableCollection LightSeries - { - get => _lightSeries; - set => SetProperty(ref _lightSeries, value); - } - private ObservableCollection _darkSeries; - - public ObservableCollection DarkSeries + + private ObservableCollection _lightLists; + public ObservableCollection LightLists { - get => _darkSeries; - set => SetProperty(ref _darkSeries, value); + get => _lightLists; + set => SetProperty(ref _lightLists, value); + } + private ObservableCollection _darkLists; + public ObservableCollection DarkLists + { + get => _darkLists; + set => SetProperty(ref _darkLists, value); } public PaletteDemoViewModel() { - LightSeries = new ObservableCollection(); - var lightResourceDictionary = (ResourceDictionary)(AvaloniaXamlLoader.Load(new Uri("avares://Semi.Avalonia/Themes/Light/Palette.axaml"))); - foreach (var color in _colors) - { - ColorSeries s = new ColorSeries(); - s.Initialize(lightResourceDictionary, color, true); - LightSeries.Add(s); - } - DarkSeries = new ObservableCollection(); - var darkResouceDictionary = (ResourceDictionary)(AvaloniaXamlLoader.Load(new Uri("avares://Semi.Avalonia/Themes/Dark/Palette.axaml"))); - foreach (var color in _colors) - { - ColorSeries s = new ColorSeries(); - s.Initialize(darkResouceDictionary, color, false); - DarkSeries.Add(s); - } + _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(); WeakReferenceMessenger.Default.Register(this, OnClickColorItem); } + private void InitializePalette() + { + LightLists = new ObservableCollection(); + foreach (var color in _predefinedColorNames) + { + ColorListViewModel s = new ColorListViewModel(); + s.Initialize(_lightResourceDictionary, color, true); + LightLists.Add(s); + } + DarkLists = new ObservableCollection(); + foreach (var color in _predefinedColorNames) + { + ColorListViewModel s = new ColorListViewModel(); + s.Initialize(_darkResourceDictionary, color, false); + DarkLists.Add(s); + } + } + private void OnClickColorItem(PaletteDemoViewModel vm, ColorItemViewModel item) { SelectedColor = item; } } -public class ColorSeries: ObservableObject +public class ColorListViewModel: ObservableObject { private ObservableCollection? _colors; @@ -104,25 +110,25 @@ public class ColorSeries: ObservableObject public class ColorItemViewModel : ObservableObject { - private IBrush _color; - public IBrush Color + private IBrush _brush; + public IBrush Brush { - get => _color; - set => SetProperty(ref _color, value); + get => _brush; + set => SetProperty(ref _brush, value); } - private IBrush _textColor; - public IBrush TextColor + private IBrush _textBrush; + public IBrush TextBrush { - get => _textColor; - set => SetProperty(ref _textColor, value); + get => _textBrush; + set => SetProperty(ref _textBrush, value); } - private string _name; - public string Name + private string _colorDisplayName; + public string ColorDisplayName { - get => _name; - set => SetProperty(ref _name, value); + get => _colorDisplayName; + set => SetProperty(ref _colorDisplayName, value); } private string _resourceKey; @@ -141,19 +147,19 @@ public class ColorItemViewModel : ObservableObject set => SetProperty(ref _hex, value); } - public ColorItemViewModel(string name, IBrush color, string resourceKey, bool light, int index) + public ColorItemViewModel(string colorDisplayName, IBrush brush, string resourceKey, bool light, int index) { - Name = name; - Color = color; + ColorDisplayName = colorDisplayName; + Brush = brush; ResourceKey = resourceKey; - Hex = color.ToString().ToUpperInvariant(); + Hex = brush.ToString().ToUpperInvariant(); if ((light && index < 5) || (!light && index > 5)) { - TextColor = Brushes.Black; + TextBrush = Brushes.Black; } else { - TextColor = Brushes.White; + TextBrush = Brushes.White; } } } \ No newline at end of file diff --git a/src/Semi.Avalonia/Themes/Dark/SplitView.axaml b/src/Semi.Avalonia/Themes/Dark/SplitView.axaml index 3d12d13..ff349b5 100644 --- a/src/Semi.Avalonia/Themes/Dark/SplitView.axaml +++ b/src/Semi.Avalonia/Themes/Dark/SplitView.axaml @@ -9,5 +9,5 @@ 00:00:00.1 0.1,0.9,0.2,1.0 - + From 235865c9256f09ac947f8b26aa3a05e2f9046d48 Mon Sep 17 00:00:00 2001 From: rabbitism Date: Mon, 13 Feb 2023 00:55:14 +0800 Subject: [PATCH 05/11] feat: Add functional colors in resource. --- src/Semi.Avalonia/Themes/Dark/Palette.axaml | 86 +++++++++++++++++++ src/Semi.Avalonia/Themes/Light/Palette.axaml | 89 +++++++++++++++++++- 2 files changed, 172 insertions(+), 3 deletions(-) diff --git a/src/Semi.Avalonia/Themes/Dark/Palette.axaml b/src/Semi.Avalonia/Themes/Dark/Palette.axaml index 5bf6dbc..c5c8e70 100644 --- a/src/Semi.Avalonia/Themes/Dark/Palette.axaml +++ b/src/Semi.Avalonia/Themes/Dark/Palette.axaml @@ -161,4 +161,90 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Semi.Avalonia/Themes/Light/Palette.axaml b/src/Semi.Avalonia/Themes/Light/Palette.axaml index 2c5523d..4032938 100644 --- a/src/Semi.Avalonia/Themes/Light/Palette.axaml +++ b/src/Semi.Avalonia/Themes/Light/Palette.axaml @@ -161,7 +161,90 @@ - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From b06e7c64439969bccb97afad26f40d712094ff28 Mon Sep 17 00:00:00 2001 From: rabbitism Date: Mon, 13 Feb 2023 02:17:38 +0800 Subject: [PATCH 06/11] feat: add color group control. --- .../Controls/ColorItemControl.axaml | 3 +- .../FunctionalColorGroupControl.axaml | 89 +++++++++++++++ .../Controls/FunctionalColorGroupControl.cs | 38 ++++++ .../Pages/PaletteDemo.axaml | 17 +++ .../ViewModels/PaletteDemoViewModel.cs | 63 +++++++++- src/Semi.Avalonia/Themes/Dark/Palette.axaml | 108 +++++++++--------- src/Semi.Avalonia/Themes/Light/Palette.axaml | 66 +++++------ 7 files changed, 294 insertions(+), 90 deletions(-) create mode 100644 demo/Semi.Avalonia.Demo/Controls/FunctionalColorGroupControl.axaml create mode 100644 demo/Semi.Avalonia.Demo/Controls/FunctionalColorGroupControl.cs 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 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From f3bb040dc9c189d109bf89b50d8a830f41875064 Mon Sep 17 00:00:00 2001 From: rabbitism Date: Mon, 13 Feb 2023 02:55:29 +0800 Subject: [PATCH 07/11] feat: add more resources. --- demo/Semi.Avalonia.Demo.Desktop/App.axaml | 2 +- .../FunctionalColorGroupControl.axaml | 83 ++++++++---- .../Controls/FunctionalColorGroupControl.cs | 2 - .../Pages/PaletteDemo.axaml.cs | 12 +- .../ViewModels/PaletteDemoViewModel.cs | 127 +++++++++++++++++- 5 files changed, 196 insertions(+), 30 deletions(-) diff --git a/demo/Semi.Avalonia.Demo.Desktop/App.axaml b/demo/Semi.Avalonia.Demo.Desktop/App.axaml index 9628b3e..c12b782 100644 --- a/demo/Semi.Avalonia.Demo.Desktop/App.axaml +++ b/demo/Semi.Avalonia.Demo.Desktop/App.axaml @@ -3,7 +3,7 @@ xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:Semi.Avalonia.Demo.Desktop" - RequestedThemeVariant="Dark"> + RequestedThemeVariant="Light"> diff --git a/demo/Semi.Avalonia.Demo/Controls/FunctionalColorGroupControl.axaml b/demo/Semi.Avalonia.Demo/Controls/FunctionalColorGroupControl.axaml index 30bd77f..fcd80cd 100644 --- a/demo/Semi.Avalonia.Demo/Controls/FunctionalColorGroupControl.axaml +++ b/demo/Semi.Avalonia.Demo/Controls/FunctionalColorGroupControl.axaml @@ -19,6 +19,17 @@ + + + + + + + @@ -30,20 +41,24 @@ Binding="{Binding ColorDisplayName}" CanUserSort="False" Header="Name" /> - + - - - - + + + + + + + + @@ -53,6 +68,17 @@ + + + + + + + @@ -60,21 +86,28 @@ - - + + - - - - + + + + + + + + diff --git a/demo/Semi.Avalonia.Demo/Controls/FunctionalColorGroupControl.cs b/demo/Semi.Avalonia.Demo/Controls/FunctionalColorGroupControl.cs index cd44ade..b7bbb44 100644 --- a/demo/Semi.Avalonia.Demo/Controls/FunctionalColorGroupControl.cs +++ b/demo/Semi.Avalonia.Demo/Controls/FunctionalColorGroupControl.cs @@ -22,9 +22,7 @@ public class FunctionalColorGroupControl: TemplatedControl 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; diff --git a/demo/Semi.Avalonia.Demo/Pages/PaletteDemo.axaml.cs b/demo/Semi.Avalonia.Demo/Pages/PaletteDemo.axaml.cs index 321e719..d21b6b6 100644 --- a/demo/Semi.Avalonia.Demo/Pages/PaletteDemo.axaml.cs +++ b/demo/Semi.Avalonia.Demo/Pages/PaletteDemo.axaml.cs @@ -1,5 +1,7 @@ +using System.Threading.Tasks; using Avalonia; using Avalonia.Controls; +using Avalonia.Controls.Primitives; using Avalonia.Markup.Xaml; using Semi.Avalonia.Demo.ViewModels; @@ -10,6 +12,14 @@ public partial class PaletteDemo : UserControl public PaletteDemo() { InitializeComponent(); - this.DataContext = new PaletteDemoViewModel(); + + } + + protected override async void OnApplyTemplate(TemplateAppliedEventArgs e) + { + base.OnApplyTemplate(e); + PaletteDemoViewModel? vm = new PaletteDemoViewModel(); + vm.InitializeResources(); + DataContext = vm; } } \ No newline at end of file diff --git a/demo/Semi.Avalonia.Demo/ViewModels/PaletteDemoViewModel.cs b/demo/Semi.Avalonia.Demo/ViewModels/PaletteDemoViewModel.cs index 747e0f2..33f98f1 100644 --- a/demo/Semi.Avalonia.Demo/ViewModels/PaletteDemoViewModel.cs +++ b/demo/Semi.Avalonia.Demo/ViewModels/PaletteDemoViewModel.cs @@ -43,9 +43,13 @@ public class PaletteDemoViewModel: ObservableObject { _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")); + WeakReferenceMessenger.Default.Register(this, OnClickColorItem); + } + + public void InitializeResources() + { InitializePalette(); InitializeFunctionalColors(); - WeakReferenceMessenger.Default.Register(this, OnClickColorItem); } private void InitializePalette() @@ -69,6 +73,18 @@ public class PaletteDemoViewModel: ObservableObject private void InitializeFunctionalColors() { FunctionalColors.Add(new FunctionalColorGroupViewModel("Primary", _lightResourceDictionary, _darkResourceDictionary, ColorTokens.PrimaryTokens)); + FunctionalColors.Add(new FunctionalColorGroupViewModel("Secondary", _lightResourceDictionary, _darkResourceDictionary, ColorTokens.SecondaryTokens)); + FunctionalColors.Add(new FunctionalColorGroupViewModel("Tertiary", _lightResourceDictionary, _darkResourceDictionary, ColorTokens.TertiaryTokens)); + FunctionalColors.Add(new FunctionalColorGroupViewModel("Information", _lightResourceDictionary, _darkResourceDictionary, ColorTokens.InformationTokens)); + FunctionalColors.Add(new FunctionalColorGroupViewModel("Success", _lightResourceDictionary, _darkResourceDictionary, ColorTokens.SuccessTokens)); + FunctionalColors.Add(new FunctionalColorGroupViewModel("Warning", _lightResourceDictionary, _darkResourceDictionary, ColorTokens.WarningTokens)); + FunctionalColors.Add(new FunctionalColorGroupViewModel("Danger", _lightResourceDictionary, _darkResourceDictionary, ColorTokens.DangerTokens)); + FunctionalColors.Add(new FunctionalColorGroupViewModel("Text", _lightResourceDictionary, _darkResourceDictionary, ColorTokens.TextTokens)); + FunctionalColors.Add(new FunctionalColorGroupViewModel("Link", _lightResourceDictionary, _darkResourceDictionary, ColorTokens.LinkTokens)); + FunctionalColors.Add(new FunctionalColorGroupViewModel("Background", _lightResourceDictionary, _darkResourceDictionary, ColorTokens.BackgroundTokens)); + FunctionalColors.Add(new FunctionalColorGroupViewModel("Fill", _lightResourceDictionary, _darkResourceDictionary, ColorTokens.FillTokens)); + 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) { @@ -221,4 +237,113 @@ public static class ColorTokens new ("SemiColorPrimaryLightPointerover", "Primary Light Pointerover"), new ("SemiColorPrimaryLightActive", "Primary Light Active"), }; + + public static IReadOnlyList> SecondaryTokens { get; } = new List> + { + new ("SemiColorSecondary", "Secondary"), + new ("SemiColorSecondaryPointerover", "Secondary Pointerover"), + new ("SemiColorSecondaryPressed", "Secondary Pressed"), + new ("SemiColorSecondaryDisabled", "Secondary Disabled"), + new ("SemiColorSecondaryLight", "Secondary Light"), + new ("SemiColorSecondaryLightPointerover", "Secondary Light Pointerover"), + new ("SemiColorSecondaryLightActive", "Secondary Light Active"), + }; + + public static IReadOnlyList> TertiaryTokens { get; } = new List> + { + new ("SemiColorTertiary", "Tertiary"), + new ("SemiColorTertiaryPointerover", "Tertiary Pointerover"), + new ("SemiColorTertiaryPressed", "Tertiary Pressed"), + new ("SemiColorTertiaryLight", "Tertiary Light"), + new ("SemiColorTertiaryLightPointerover", "Tertiary Light Pointerover"), + new ("SemiColorTertiaryLightActive", "Tertiary Light Active"), + }; + + public static IReadOnlyList> InformationTokens { get; } = new List> + { + new ("SemiColorInformation", "Information"), + new ("SemiColorInformationPointerover", "Information Pointerover"), + new ("SemiColorInformationPressed", "Information Pressed"), + new ("SemiColorInformationDisabled", "Information Disabled"), + new ("SemiColorInformationLight", "Information Light"), + new ("SemiColorInformationLightPointerover", "Information Light Pointerover"), + new ("SemiColorInformationLightActive", "Information Light Active"), + }; + + public static IReadOnlyList> SuccessTokens { get; } = new List> + { + new ("SemiColorSuccess", "Success"), + new ("SemiColorSuccessPointerover", "Success Pointerover"), + new ("SemiColorSuccessPressed", "Success Pressed"), + new ("SemiColorSuccessDisabled", "Success Disabled"), + new ("SemiColorSuccessLight", "Success Light"), + new ("SemiColorSuccessLightPointerover", "Success Light Pointerover"), + new ("SemiColorSuccessLightActive", "Success Light Active"), + }; + + public static IReadOnlyList> WarningTokens { get; } = new List> + { + new ("SemiColorWarning", "Warning"), + new ("SemiColorWarningPointerover", "Warning Pointerover"), + new ("SemiColorWarningPressed", "Warning Pressed"), + new ("SemiColorWarningLight", "Warning Light"), + new ("SemiColorWarningLightPointerover", "Warning Light Pointerover"), + new ("SemiColorWarningLightActive", "Warning Light Active"), + }; + + public static IReadOnlyList> DangerTokens { get; } = new List> + { + new ("SemiColorDanger", "Danger"), + new ("SemiColorDangerPointerover", "Danger Pointerover"), + new ("SemiColorDangerPressed", "Danger Pressed"), + new ("SemiColorDangerLight", "Danger Light"), + new ("SemiColorDangerLightPointerover", "Danger Light Pointerover"), + new ("SemiColorDangerLightActive", "Danger Light Active"), + }; + + public static IReadOnlyList> TextTokens { get; } = new List> + { + new ("SemiColorText0", "Text 0"), + new ("SemiColorText1", "Text 1"), + new ("SemiColorText2", "Text 2"), + new ("SemiColorText3", "Text 3"), + }; + + public static IReadOnlyList> LinkTokens { get; } = new List> + { + new ("SemiColorLink", "Link"), + new ("SemiColorLinkPointerover", "Link Pointerover"), + new ("SemiColorLinkActive", "Link Active"), + new ("SemiColorLinkVisited", "Link Visited"), + }; + + public static IReadOnlyList> BackgroundTokens { get; } = new List> + { + new ("SemiColorBackground0", "Background 0"), + new ("SemiColorBackground1", "Background 1"), + new ("SemiColorBackground2", "Background 2"), + new ("SemiColorBackground3", "Background 3"), + new ("SemiColorBackground4", "Background 4"), + }; + + public static IReadOnlyList> FillTokens { get; } = new List> + { + new ("SemiColorFill0", "Fill 0"), + new ("SemiColorFill1", "Fill 1"), + new ("SemiColorFill2", "Fill 2"), + }; + + public static IReadOnlyList> BorderTokens { get; } = new List> + { + new ("SemiColorBorder", "Border"), + }; + + public static IReadOnlyList> DisabledTokens { get; } = new List> + { + new ("SemiColorDisabledText", "Disabled Text"), + new ("SemiColorDisabledBorder", "Disabled Border"), + new ("SemiColorDisabledBackground", "Disabled Background"), + new ("SemiColorDisabledFill", "Disabled Fill"), + }; + } \ No newline at end of file From 03e9056c8269c8786e4e326ae133f6ffb4f0d042 Mon Sep 17 00:00:00 2001 From: rabbitism Date: Mon, 13 Feb 2023 03:29:56 +0800 Subject: [PATCH 08/11] fix: fix toggle style. --- .../Pages/PaletteDemo.axaml | 24 ++++++++++-------- .../Pages/PaletteDemo.axaml.cs | 6 ++++- .../Themes/ToggleButton.axaml | 25 +++++++++++++++++++ 3 files changed, 43 insertions(+), 12 deletions(-) diff --git a/demo/Semi.Avalonia.Demo/Pages/PaletteDemo.axaml b/demo/Semi.Avalonia.Demo/Pages/PaletteDemo.axaml index 8cf0b6b..eb707e0 100644 --- a/demo/Semi.Avalonia.Demo/Pages/PaletteDemo.axaml +++ b/demo/Semi.Avalonia.Demo/Pages/PaletteDemo.axaml @@ -15,6 +15,7 @@ + @@ -34,18 +35,19 @@ Name="toggle" HorizontalAlignment="Right" IsChecked="True" - Theme="{DynamicResource BorderlessToggleButton}"> - - + Theme="{DynamicResource SplitViewToggleButton}" /> - + + + + diff --git a/demo/Semi.Avalonia.Demo/Pages/PaletteDemo.axaml.cs b/demo/Semi.Avalonia.Demo/Pages/PaletteDemo.axaml.cs index d21b6b6..4ef2ecf 100644 --- a/demo/Semi.Avalonia.Demo/Pages/PaletteDemo.axaml.cs +++ b/demo/Semi.Avalonia.Demo/Pages/PaletteDemo.axaml.cs @@ -3,6 +3,7 @@ using Avalonia; using Avalonia.Controls; using Avalonia.Controls.Primitives; using Avalonia.Markup.Xaml; +using Avalonia.Threading; using Semi.Avalonia.Demo.ViewModels; namespace Semi.Avalonia.Demo.Pages; @@ -19,7 +20,10 @@ public partial class PaletteDemo : UserControl { base.OnApplyTemplate(e); PaletteDemoViewModel? vm = new PaletteDemoViewModel(); - vm.InitializeResources(); + await Dispatcher.UIThread.InvokeAsync(() => + { + vm.InitializeResources(); + }); DataContext = vm; } } \ No newline at end of file diff --git a/demo/Semi.Avalonia.Demo/Themes/ToggleButton.axaml b/demo/Semi.Avalonia.Demo/Themes/ToggleButton.axaml index e3c7231..140bf91 100644 --- a/demo/Semi.Avalonia.Demo/Themes/ToggleButton.axaml +++ b/demo/Semi.Avalonia.Demo/Themes/ToggleButton.axaml @@ -29,4 +29,29 @@ + + + + + + + + + + + + From 958a682f6031500595c3ea9bf78cfa2adbcf8131 Mon Sep 17 00:00:00 2001 From: rabbitism Date: Mon, 13 Feb 2023 03:41:49 +0800 Subject: [PATCH 09/11] feat: Add Column width. --- .../Controls/FunctionalColorGroupControl.axaml | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/demo/Semi.Avalonia.Demo/Controls/FunctionalColorGroupControl.axaml b/demo/Semi.Avalonia.Demo/Controls/FunctionalColorGroupControl.axaml index fcd80cd..2fec1e7 100644 --- a/demo/Semi.Avalonia.Demo/Controls/FunctionalColorGroupControl.axaml +++ b/demo/Semi.Avalonia.Demo/Controls/FunctionalColorGroupControl.axaml @@ -19,7 +19,7 @@ - + - + @@ -38,10 +38,11 @@ - + - + - + - + @@ -87,10 +88,11 @@ - + - + Date: Mon, 13 Feb 2023 11:10:23 +0800 Subject: [PATCH 10/11] fix: fix some color inconsistency issue. --- .../Controls/ColorItemControl.axaml | 1 + src/Semi.Avalonia.DataGrid/Dark.axaml | 4 ++-- src/Semi.Avalonia/Controls/ListBox.axaml | 3 +++ src/Semi.Avalonia/Controls/ScrollViewer.axaml | 13 +++++++++++-- src/Semi.Avalonia/Themes/Dark/Border.axaml | 2 +- src/Semi.Avalonia/Themes/Dark/Button.axaml | 6 +++--- src/Semi.Avalonia/Themes/Dark/ListBox.axaml | 4 ++-- src/Semi.Avalonia/Themes/Dark/TreeView.axaml | 2 +- src/Semi.Avalonia/Themes/Light/Button.axaml | 7 ++++--- 9 files changed, 28 insertions(+), 14 deletions(-) diff --git a/demo/Semi.Avalonia.Demo/Controls/ColorItemControl.axaml b/demo/Semi.Avalonia.Demo/Controls/ColorItemControl.axaml index 505b54b..25b4bd9 100644 --- a/demo/Semi.Avalonia.Demo/Controls/ColorItemControl.axaml +++ b/demo/Semi.Avalonia.Demo/Controls/ColorItemControl.axaml @@ -9,6 +9,7 @@ + diff --git a/src/Semi.Avalonia.DataGrid/Dark.axaml b/src/Semi.Avalonia.DataGrid/Dark.axaml index 1814448..ad74cb4 100644 --- a/src/Semi.Avalonia.DataGrid/Dark.axaml +++ b/src/Semi.Avalonia.DataGrid/Dark.axaml @@ -29,8 +29,8 @@ - - + + M7.43934 19.7957C6.85355 19.2099 6.85355 18.2601 7.43934 17.6744L13.0962 12.0175L7.43934 6.36065C6.85355 5.77486 6.85355 4.82511 7.43934 4.23933C8.02513 3.65354 8.97487 3.65354 9.56066 4.23933L16.2782 10.9568C16.864 11.5426 16.864 12.4924 16.2782 13.0782L9.56066 19.7957C8.97487 20.3815 8.02513 20.3815 7.43934 19.7957Z diff --git a/src/Semi.Avalonia/Controls/ListBox.axaml b/src/Semi.Avalonia/Controls/ListBox.axaml index c01249d..88b3ac6 100644 --- a/src/Semi.Avalonia/Controls/ListBox.axaml +++ b/src/Semi.Avalonia/Controls/ListBox.axaml @@ -80,6 +80,9 @@ diff --git a/src/Semi.Avalonia/Controls/ScrollViewer.axaml b/src/Semi.Avalonia/Controls/ScrollViewer.axaml index aadb4ba..4372c99 100644 --- a/src/Semi.Avalonia/Controls/ScrollViewer.axaml +++ b/src/Semi.Avalonia/Controls/ScrollViewer.axaml @@ -147,12 +147,12 @@ +