feat: Add Dark/Light color palette.

This commit is contained in:
rabbitism 2023-03-26 20:57:03 +08:00
parent 43305be6bf
commit 1a512e589d
6 changed files with 73 additions and 9 deletions

View File

@ -2,6 +2,7 @@
x:Class="Semi.Avalonia.Demo.Pages.ColorPickerDemo"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:colorPicker="clr-namespace:Semi.Avalonia.ColorPicker;assembly=Semi.Avalonia.ColorPicker"
xmlns:controls="using:Avalonia.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
@ -15,11 +16,7 @@
Spacing="20">
<ColorView ColorSpectrumShape="Ring" />
<ColorView ColorSpectrumShape="Box" />
<ColorView>
<ColorView.Palette>
<controls:MaterialColorPalette />
</ColorView.Palette>
</ColorView>
<ColorView Palette="{DynamicResource SemiColorPalette}" />
</StackPanel>
<StackPanel HorizontalAlignment="Left" Orientation="Horizontal">
<ColorPicker ColorSpectrumShape="Ring">
@ -29,7 +26,7 @@
</ColorPicker>
<ColorPicker ColorSpectrumShape="Box">
<ColorPicker.Palette>
<controls:MaterialColorPalette />
<colorPicker:SemiColorLightPalette />
</ColorPicker.Palette>
</ColorPicker>
</StackPanel>

View File

@ -1,4 +1,7 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:colorPicker="clr-namespace:Semi.Avalonia.ColorPicker">
<!-- Add Resources Here -->
<SolidColorBrush x:Key="ColorViewRadioButtonForeground" Color="#54A9FF" />
<SolidColorBrush x:Key="ColorViewRadioButtonBackground" Color="#1C1F23" />
@ -40,4 +43,6 @@
<CornerRadius x:Key="ColorPreviewerCornerRadius">3</CornerRadius>
<BoxShadows x:Key="ColorPreviewerMainBoxShadow">0 0 14 0 #1AFFFFFF</BoxShadows>
<colorPicker:SemiColorDarkPalette x:Key="SemiColorPalette" />
</ResourceDictionary>

View File

@ -1,4 +1,7 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:colorPicker="clr-namespace:Semi.Avalonia.ColorPicker">
<!-- Add Resources Here -->
<SolidColorBrush x:Key="ColorViewRadioButtonForeground" Color="#0077FA" />
<SolidColorBrush x:Key="ColorViewRadioButtonBackground" Color="White" />
@ -40,4 +43,5 @@
<CornerRadius x:Key="ColorPreviewerCornerRadius">3</CornerRadius>
<BoxShadows x:Key="ColorPreviewerMainBoxShadow">0 0 14 0 #1A000000</BoxShadows>
<colorPicker:SemiColorLightPalette x:Key="SemiColorPalette" />
</ResourceDictionary>

View File

@ -0,0 +1,29 @@
using Avalonia.Controls;
using Avalonia.Media;
using Avalonia.Utilities;
namespace Semi.Avalonia.ColorPicker;
public class SemiColorDarkPalette: IColorPalette
{
private static readonly Color[,] Colors = new Color[,]
{
{
Color.FromUInt32(0xFF6C090B),
},
{
Color.FromUInt32(0xFF6C090B),
}
};
public Color GetColor(int colorIndex, int shadeIndex)
{
return Colors[
MathUtilities.Clamp(colorIndex, 0, ColorCount - 1),
MathUtilities.Clamp(shadeIndex, 0, ShadeCount - 1)
];
}
public int ColorCount => Colors.GetLength(0);
public int ShadeCount => Colors.GetLength(1);
}

View File

@ -0,0 +1,29 @@
using Avalonia.Controls;
using Avalonia.Media;
using Avalonia.Utilities;
namespace Semi.Avalonia.ColorPicker;
public class SemiColorLightPalette: IColorPalette
{
private static readonly Color[,] Colors = new Color[,]
{
{
Color.FromUInt32(0xFFFEF2ED),
},
{
Color.FromUInt32(0xFFFEF2ED),
}
};
public Color GetColor(int colorIndex, int shadeIndex)
{
return Colors[
MathUtilities.Clamp(colorIndex, 0, ColorCount - 1),
MathUtilities.Clamp(shadeIndex, 0, ShadeCount - 1)
];
}
public int ColorCount => Colors.GetLength(0);
public int ShadeCount => Colors.GetLength(1);
}