Browse Source

Remove 'Custom' term from Palette properties

pull/8215/head
robloo 4 years ago
parent
commit
03b080ae04
  1. 122
      src/Avalonia.Controls.ColorPicker/ColorView/ColorView.Properties.cs
  2. 12
      src/Avalonia.Controls.ColorPicker/ColorView/ColorView.cs
  3. 6
      src/Avalonia.Controls.ColorPicker/Themes/Fluent/ColorPicker.xaml
  4. 6
      src/Avalonia.Controls.ColorPicker/Themes/Fluent/ColorView.xaml

122
src/Avalonia.Controls.ColorPicker/ColorView/ColorView.Properties.cs

@ -44,30 +44,6 @@ namespace Avalonia.Controls
nameof(ColorSpectrumShape),
ColorSpectrumShape.Box);
/// <summary>
/// Defines the <see cref="CustomPaletteColors"/> property.
/// </summary>
public static readonly DirectProperty<ColorView, ObservableCollection<Color>> CustomPaletteColorsProperty =
AvaloniaProperty.RegisterDirect<ColorView, ObservableCollection<Color>>(
nameof(CustomPaletteColors),
o => o.CustomPaletteColors);
/// <summary>
/// Defines the <see cref="CustomPaletteColumnCount"/> property.
/// </summary>
public static readonly StyledProperty<int> CustomPaletteColumnCountProperty =
AvaloniaProperty.Register<ColorView, int>(
nameof(CustomPaletteColumnCount),
4);
/// <summary>
/// Defines the <see cref="CustomPalette"/> property.
/// </summary>
public static readonly StyledProperty<IColorPalette?> CustomPaletteProperty =
AvaloniaProperty.Register<ColorView, IColorPalette?>(
nameof(CustomPalette),
null);
/// <summary>
/// Defines the <see cref="HsvColor"/> property.
/// </summary>
@ -197,6 +173,30 @@ namespace Avalonia.Controls
nameof(MinValue),
0);
/// <summary>
/// Defines the <see cref="PaletteColors"/> property.
/// </summary>
public static readonly DirectProperty<ColorView, ObservableCollection<Color>> PaletteColorsProperty =
AvaloniaProperty.RegisterDirect<ColorView, ObservableCollection<Color>>(
nameof(PaletteColors),
o => o.PaletteColors);
/// <summary>
/// Defines the <see cref="PaletteColumnCount"/> property.
/// </summary>
public static readonly StyledProperty<int> PaletteColumnCountProperty =
AvaloniaProperty.Register<ColorView, int>(
nameof(PaletteColumnCount),
4);
/// <summary>
/// Defines the <see cref="Palette"/> property.
/// </summary>
public static readonly StyledProperty<IColorPalette?> PaletteProperty =
AvaloniaProperty.Register<ColorView, IColorPalette?>(
nameof(Palette),
null);
/// <summary>
/// Defines the <see cref="SelectedIndex"/> property.
/// </summary>
@ -245,35 +245,6 @@ namespace Avalonia.Controls
set => SetValue(ColorSpectrumShapeProperty, value);
}
/// <summary>
/// Gets the list of custom palette colors.
/// </summary>
public ObservableCollection<Color> CustomPaletteColors
{
get => _customPaletteColors;
}
/// <summary>
/// Gets or sets the number of colors in each row (section) of the custom color palette.
/// Within a standard palette, rows are shades and columns are colors.
/// </summary>
public int CustomPaletteColumnCount
{
get => GetValue(CustomPaletteColumnCountProperty);
set => SetValue(CustomPaletteColumnCountProperty, value);
}
/// <summary>
/// Gets or sets the custom color palette.
/// This will automatically set <see cref="CustomPaletteColors"/> and <see cref="CustomPaletteColumnCount"/>
/// overwriting any existing values.
/// </summary>
public IColorPalette? CustomPalette
{
get => GetValue(CustomPaletteProperty);
set => SetValue(CustomPaletteProperty, value);
}
/// <inheritdoc cref="ColorSpectrum.HsvColor"/>
public HsvColor HsvColor
{
@ -420,6 +391,51 @@ namespace Avalonia.Controls
set => SetValue(MinValueProperty, value);
}
/// <summary>
/// Gets the list of individual colors in the palette.
/// </summary>
/// <remarks>
/// This is not commonly set manually. Instead, it should be set automatically by
/// providing an <see cref="IColorPalette"/> to the <see cref="Palette"/> property.
/// <br/><br/>
/// Also note that this property is what should be bound in the control template.
/// <see cref="Palette"/> is too high-level to use on its own.
/// </remarks>
public ObservableCollection<Color> PaletteColors
{
get => _paletteColors;
}
/// <summary>
/// Gets or sets the number of colors in each row (section) of the color palette.
/// Within a standard palette, rows are shades and columns are colors.
/// </summary>
/// <remarks>
/// This is not commonly set manually. Instead, it should be set automatically by
/// providing an <see cref="IColorPalette"/> to the <see cref="Palette"/> property.
/// <br/><br/>
/// Also note that this property is what should be bound in the control template.
/// <see cref="Palette"/> is too high-level to use on its own.
/// </remarks>
public int PaletteColumnCount
{
get => GetValue(PaletteColumnCountProperty);
set => SetValue(PaletteColumnCountProperty, value);
}
/// <summary>
/// Gets or sets the color palette.
/// </summary>
/// <remarks>
/// This will automatically set both <see cref="PaletteColors"/> and
/// <see cref="PaletteColumnCount"/> overwriting any existing values.
/// </remarks>
public IColorPalette? Palette
{
get => GetValue(PaletteProperty);
set => SetValue(PaletteProperty, value);
}
/// <summary>
/// Gets or sets the index of the selected tab/panel/page (subview).
/// </summary>

12
src/Avalonia.Controls.ColorPicker/ColorView/ColorView.cs

@ -25,7 +25,7 @@ namespace Avalonia.Controls
private TextBox? _hexTextBox;
private TabControl? _tabControl;
private ObservableCollection<Color> _customPaletteColors = new ObservableCollection<Color>();
private ObservableCollection<Color> _paletteColors = new ObservableCollection<Color>();
private ColorToHexConverter colorToHexConverter = new ColorToHexConverter();
protected bool ignorePropertyChanged = false;
@ -214,22 +214,22 @@ namespace Avalonia.Controls
ignorePropertyChanged = false;
}
else if (change.Property == CustomPaletteProperty)
else if (change.Property == PaletteProperty)
{
IColorPalette? palette = CustomPalette;
IColorPalette? palette = Palette;
// Any custom palette change must be automatically synced with the
// bound properties controlling the palette grid
if (palette != null)
{
CustomPaletteColumnCount = palette.ColorCount;
CustomPaletteColors.Clear();
PaletteColumnCount = palette.ColorCount;
PaletteColors.Clear();
for (int shadeIndex = 0; shadeIndex < palette.ShadeCount; shadeIndex++)
{
for (int colorIndex = 0; colorIndex < palette.ColorCount; colorIndex++)
{
CustomPaletteColors.Add(palette.GetColor(colorIndex, shadeIndex));
PaletteColors.Add(palette.GetColor(colorIndex, shadeIndex));
}
}
}

6
src/Avalonia.Controls.ColorPicker/Themes/Fluent/ColorPicker.xaml

@ -46,15 +46,13 @@
<DropDownButton.Flyout>
<Flyout FlyoutPresenterClasses="NoPadding">
<!-- Skip the following:
- CustomPaletteColors
- PaletteColors
-->
<ColorView x:Name="FlyoutColorView"
Color="{Binding Color, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}"
ColorModel="{Binding ColorModel, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}"
ColorSpectrumComponents="{TemplateBinding ColorSpectrumComponents}"
ColorSpectrumShape="{TemplateBinding ColorSpectrumShape}"
CustomPaletteColumnCount="{TemplateBinding CustomPaletteColumnCount}"
CustomPalette="{TemplateBinding CustomPalette}"
HsvColor="{Binding HsvColor, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}"
IsAlphaEnabled="{TemplateBinding IsAlphaEnabled}"
IsAlphaVisible="{TemplateBinding IsAlphaVisible}"
@ -71,6 +69,8 @@
MinHue="{TemplateBinding MinHue}"
MinSaturation="{TemplateBinding MinSaturation}"
MinValue="{TemplateBinding MinValue}"
PaletteColumnCount="{TemplateBinding PaletteColumnCount}"
Palette="{TemplateBinding Palette}"
SelectedIndex="{Binding SelectedIndex, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}"
ShowAccentColors="{TemplateBinding ShowAccentColors}" />
</Flyout>

6
src/Avalonia.Controls.ColorPicker/Themes/Fluent/ColorView.xaml

@ -81,7 +81,7 @@
<Style Selector="ColorView">
<Setter Property="CornerRadius" Value="{DynamicResource ControlCornerRadius}" />
<Setter Property="CustomPalette">
<Setter Property="Palette">
<local:FluentColorPalette />
</Setter>
<Setter Property="Template">
@ -198,7 +198,7 @@
Data="{DynamicResource ColorViewPaletteIconGeometry}" />
</Border>
</TabItem.Header>
<ListBox Items="{TemplateBinding CustomPaletteColors}"
<ListBox Items="{TemplateBinding PaletteColors}"
SelectedItem="{Binding Color, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}"
UseLayoutRounding="False"
Margin="12">
@ -259,7 +259,7 @@
</ListBox.ItemTemplate>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Columns="{Binding $parent[ColorView].CustomPaletteColumnCount}" />
<UniformGrid Columns="{Binding $parent[ColorView].PaletteColumnCount}" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>

Loading…
Cancel
Save