Browse Source

Rename `ShowAccentColors` to `IsAccentColorsVisible` and disable drop shadow when false

pull/8215/head
robloo 4 years ago
parent
commit
0bf3a6d944
  1. 2
      samples/ControlCatalog/Pages/ColorPickerPage.xaml
  2. 14
      src/Avalonia.Controls.ColorPicker/ColorPreviewer/ColorPreviewer.Properties.cs
  3. 32
      src/Avalonia.Controls.ColorPicker/ColorView/ColorView.Properties.cs
  4. 122
      src/Avalonia.Controls.ColorPicker/Themes/Default/ColorPreviewer.xaml
  5. 4
      src/Avalonia.Controls.ColorPicker/Themes/Fluent/ColorPicker.xaml
  6. 122
      src/Avalonia.Controls.ColorPicker/Themes/Fluent/ColorPreviewer.xaml
  7. 2
      src/Avalonia.Controls.ColorPicker/Themes/Fluent/ColorView.xaml

2
samples/ControlCatalog/Pages/ColorPickerPage.xaml

@ -47,7 +47,7 @@
ColorModel="Hsva"
HsvColor="{Binding HsvColor, ElementName=ColorSpectrum1}" />
<ColorPreviewer Grid.Row="5"
ShowAccentColors="True"
IsAccentColorsVisible="True"
HsvColor="{Binding HsvColor, ElementName=ColorSpectrum1}" />
</Grid>
<Grid Grid.Column="4"

14
src/Avalonia.Controls.ColorPicker/ColorPreviewer/ColorPreviewer.Properties.cs

@ -16,11 +16,11 @@ namespace Avalonia.Controls.Primitives
defaultBindingMode: BindingMode.TwoWay);
/// <summary>
/// Defines the <see cref="ShowAccentColors"/> property.
/// Defines the <see cref="IsAccentColorsVisible"/> property.
/// </summary>
public static readonly StyledProperty<bool> ShowAccentColorsProperty =
public static readonly StyledProperty<bool> IsAccentColorsVisibleProperty =
AvaloniaProperty.Register<ColorPreviewer, bool>(
nameof(ShowAccentColors),
nameof(IsAccentColorsVisible),
true);
/// <summary>
@ -38,13 +38,13 @@ namespace Avalonia.Controls.Primitives
}
/// <summary>
/// Gets or sets a value indicating whether accent colors are shown along
/// Gets or sets a value indicating whether accent colors are visible along
/// with the preview color.
/// </summary>
public bool ShowAccentColors
public bool IsAccentColorsVisible
{
get => GetValue(ShowAccentColorsProperty);
set => SetValue(ShowAccentColorsProperty, value);
get => GetValue(IsAccentColorsVisibleProperty);
set => SetValue(IsAccentColorsVisibleProperty, value);
}
}
}

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

@ -52,6 +52,14 @@ namespace Avalonia.Controls
defaultBindingMode: BindingMode.TwoWay,
coerce: CoerceHsvColor);
/// <summary>
/// Defines the <see cref="IsAccentColorsVisible"/> property.
/// </summary>
public static readonly StyledProperty<bool> IsAccentColorsVisibleProperty =
AvaloniaProperty.Register<ColorView, bool>(
nameof(IsAccentColorsVisible),
true);
/// <summary>
/// Defines the <see cref="IsAlphaEnabled"/> property.
/// </summary>
@ -220,14 +228,6 @@ namespace Avalonia.Controls
nameof(SelectedIndex),
(int)ColorViewTab.Spectrum);
/// <summary>
/// Defines the <see cref="ShowAccentColors"/> property.
/// </summary>
public static readonly StyledProperty<bool> ShowAccentColorsProperty =
AvaloniaProperty.Register<ColorView, bool>(
nameof(ShowAccentColors),
true);
/// <inheritdoc cref="ColorSpectrum.Color"/>
public Color Color
{
@ -267,6 +267,13 @@ namespace Avalonia.Controls
set => SetValue(HsvColorProperty, value);
}
/// <inheritdoc cref="ColorPreviewer.IsAccentColorsVisible"/>
public bool IsAccentColorsVisible
{
get => GetValue(IsAccentColorsVisibleProperty);
set => SetValue(IsAccentColorsVisibleProperty, value);
}
/// <summary>
/// Gets or sets a value indicating whether the alpha component is enabled.
/// When disabled (set to false) the alpha component will be fixed to maximum and
@ -325,7 +332,7 @@ namespace Avalonia.Controls
/// </summary>
/// <remarks>
/// Note that accent color visibility is controlled separately by
/// <see cref="ShowAccentColors"/>.
/// <see cref="IsAccentColorsVisible"/>.
/// </remarks>
public bool IsColorPreviewVisible
{
@ -484,12 +491,5 @@ namespace Avalonia.Controls
get => GetValue(SelectedIndexProperty);
set => SetValue(SelectedIndexProperty, value);
}
/// <inheritdoc cref="ColorPreviewer.ShowAccentColors"/>
public bool ShowAccentColors
{
get => GetValue(ShowAccentColorsProperty);
set => SetValue(ShowAccentColorsProperty, value);
}
}
}

122
src/Avalonia.Controls.ColorPicker/Themes/Default/ColorPreviewer.xaml

@ -14,69 +14,87 @@
<Setter Property="CornerRadius" Value="0" />
<Setter Property="Template">
<ControlTemplate TargetType="{x:Type ColorPreviewer}">
<Grid ColumnDefinitions="Auto,*,Auto">
<!-- Left accent colors -->
<Grid Grid.Column="0"
Height="{StaticResource ColorPreviewerAccentSectionHeight}"
Width="{StaticResource ColorPreviewerAccentSectionWidth}"
ColumnDefinitions="*,*"
Margin="0,0,-10,0"
VerticalAlignment="Center"
IsVisible="{TemplateBinding ShowAccentColors}">
<Border Grid.Column="0"
Grid.ColumnSpan="2"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Background="{StaticResource ColorControlCheckeredBackgroundBrush}" />
<Border x:Name="PART_AccentDecrement2Border"
Grid.Column="0"
CornerRadius="{TemplateBinding CornerRadius, Converter={StaticResource LeftCornerRadiusFilterConverter}}"
Tag="-2"
Background="{TemplateBinding HsvColor, Converter={StaticResource AccentColorConverter}, ConverterParameter='-2'}" />
<Border x:Name="PART_AccentDecrement1Border"
Grid.Column="1"
Tag="-1"
Background="{TemplateBinding HsvColor, Converter={StaticResource AccentColorConverter}, ConverterParameter='-1'}" />
</Grid>
<!-- Right accent colors -->
<Grid Grid.Column="2"
Height="{StaticResource ColorPreviewerAccentSectionHeight}"
Width="{StaticResource ColorPreviewerAccentSectionWidth}"
ColumnDefinitions="*,*"
Margin="-10,0,0,0"
VerticalAlignment="Center"
IsVisible="{TemplateBinding ShowAccentColors}">
<Border Grid.Column="0"
Grid.ColumnSpan="2"
<Panel>
<!-- Preview color with accents to the left and right -->
<Grid ColumnDefinitions="Auto,*,Auto"
IsVisible="{TemplateBinding IsAccentColorsVisible}">
<!-- Left accent colors -->
<Grid Grid.Column="0"
Height="{StaticResource ColorPreviewerAccentSectionHeight}"
Width="{StaticResource ColorPreviewerAccentSectionWidth}"
ColumnDefinitions="*,*"
Margin="0,0,-10,0"
VerticalAlignment="Center">
<Border Grid.Column="0"
Grid.ColumnSpan="2"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Background="{StaticResource ColorControlCheckeredBackgroundBrush}" />
<Border x:Name="PART_AccentDecrement2Border"
Grid.Column="0"
CornerRadius="{TemplateBinding CornerRadius, Converter={StaticResource LeftCornerRadiusFilterConverter}}"
Tag="-2"
Background="{TemplateBinding HsvColor, Converter={StaticResource AccentColorConverter}, ConverterParameter='-2'}" />
<Border x:Name="PART_AccentDecrement1Border"
Grid.Column="1"
Tag="-1"
Background="{TemplateBinding HsvColor, Converter={StaticResource AccentColorConverter}, ConverterParameter='-1'}" />
</Grid>
<!-- Right accent colors -->
<Grid Grid.Column="2"
Height="{StaticResource ColorPreviewerAccentSectionHeight}"
Width="{StaticResource ColorPreviewerAccentSectionWidth}"
ColumnDefinitions="*,*"
Margin="-10,0,0,0"
VerticalAlignment="Center">
<Border Grid.Column="0"
Grid.ColumnSpan="2"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Background="{StaticResource ColorControlCheckeredBackgroundBrush}" />
<Border x:Name="PART_AccentIncrement1Border"
Grid.Column="0"
Tag="1"
Background="{TemplateBinding HsvColor, Converter={StaticResource AccentColorConverter}, ConverterParameter='1'}" />
<Border x:Name="PART_AccentIncrement2Border"
Grid.Column="1"
CornerRadius="{TemplateBinding CornerRadius, Converter={StaticResource RightCornerRadiusFilterConverter}}"
Tag="2"
Background="{TemplateBinding HsvColor, Converter={StaticResource AccentColorConverter}, ConverterParameter='2'}" />
</Grid>
<!-- Preview color: Must be last for drop shadow Z-index -->
<Border Grid.Column="1"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Background="{StaticResource ColorControlCheckeredBackgroundBrush}" />
<Border x:Name="PART_AccentIncrement1Border"
Grid.Column="0"
Tag="1"
Background="{TemplateBinding HsvColor, Converter={StaticResource AccentColorConverter}, ConverterParameter='1'}" />
<Border x:Name="PART_AccentIncrement2Border"
Grid.Column="1"
CornerRadius="{TemplateBinding CornerRadius, Converter={StaticResource RightCornerRadiusFilterConverter}}"
Tag="2"
Background="{TemplateBinding HsvColor, Converter={StaticResource AccentColorConverter}, ConverterParameter='2'}" />
BoxShadow="0 0 10 2 #BF000000"
CornerRadius="{TemplateBinding CornerRadius}"
Margin="10">
<Panel>
<Border Background="{StaticResource ColorControlCheckeredBackgroundBrush}"
CornerRadius="{TemplateBinding CornerRadius}" />
<Border CornerRadius="{TemplateBinding CornerRadius}"
Background="{TemplateBinding HsvColor, Converter={StaticResource ToBrushConverter}}"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch" />
</Panel>
</Border>
</Grid>
<!-- Must be last for drop shadow Z-index -->
<Border Grid.Column="1"
BoxShadow="0 0 10 2 #BF000000"
CornerRadius="{TemplateBinding CornerRadius}"
Margin="10">
<!-- Only preview color -->
<Border CornerRadius="{TemplateBinding CornerRadius}"
IsVisible="{TemplateBinding IsAccentColorsVisible, Converter={x:Static BoolConverters.Not}}"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Margin="0,10,0,10">
<Panel>
<Border Background="{StaticResource ColorControlCheckeredBackgroundBrush}"
CornerRadius="{TemplateBinding CornerRadius}" />
<Border x:Name="PreviewBorder"
CornerRadius="{TemplateBinding CornerRadius}"
<Border CornerRadius="{TemplateBinding CornerRadius}"
Background="{TemplateBinding HsvColor, Converter={StaticResource ToBrushConverter}}"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch" />
</Panel>
</Border>
</Grid>
</Panel>
</ControlTemplate>
</Setter>
</Style>

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

@ -53,6 +53,7 @@
ColorSpectrumComponents="{TemplateBinding ColorSpectrumComponents}"
ColorSpectrumShape="{TemplateBinding ColorSpectrumShape}"
HsvColor="{Binding HsvColor, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}"
IsAccentColorsVisible="{TemplateBinding IsAccentColorsVisible}"
IsAlphaEnabled="{TemplateBinding IsAlphaEnabled}"
IsAlphaVisible="{TemplateBinding IsAlphaVisible}"
IsColorComponentsVisible="{TemplateBinding IsColorComponentsVisible}"
@ -73,8 +74,7 @@
PaletteColors="{TemplateBinding PaletteColors}"
PaletteColumnCount="{TemplateBinding PaletteColumnCount}"
Palette="{TemplateBinding Palette}"
SelectedIndex="{Binding SelectedIndex, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}"
ShowAccentColors="{TemplateBinding ShowAccentColors}" />
SelectedIndex="{Binding SelectedIndex, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}" />
</Flyout>
</DropDownButton.Flyout>
</DropDownButton>

122
src/Avalonia.Controls.ColorPicker/Themes/Fluent/ColorPreviewer.xaml

@ -14,69 +14,87 @@
<Setter Property="CornerRadius" Value="{DynamicResource ControlCornerRadius}" />
<Setter Property="Template">
<ControlTemplate TargetType="{x:Type ColorPreviewer}">
<Grid ColumnDefinitions="Auto,*,Auto">
<!-- Left accent colors -->
<Grid Grid.Column="0"
Height="{StaticResource ColorPreviewerAccentSectionHeight}"
Width="{StaticResource ColorPreviewerAccentSectionWidth}"
ColumnDefinitions="*,*"
Margin="0,0,-10,0"
VerticalAlignment="Center"
IsVisible="{TemplateBinding ShowAccentColors}">
<Border Grid.Column="0"
Grid.ColumnSpan="2"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Background="{StaticResource ColorControlCheckeredBackgroundBrush}" />
<Border x:Name="PART_AccentDecrement2Border"
Grid.Column="0"
CornerRadius="{TemplateBinding CornerRadius, Converter={StaticResource LeftCornerRadiusFilterConverter}}"
Tag="-2"
Background="{TemplateBinding HsvColor, Converter={StaticResource AccentColorConverter}, ConverterParameter='-2'}" />
<Border x:Name="PART_AccentDecrement1Border"
Grid.Column="1"
Tag="-1"
Background="{TemplateBinding HsvColor, Converter={StaticResource AccentColorConverter}, ConverterParameter='-1'}" />
</Grid>
<!-- Right accent colors -->
<Grid Grid.Column="2"
Height="{StaticResource ColorPreviewerAccentSectionHeight}"
Width="{StaticResource ColorPreviewerAccentSectionWidth}"
ColumnDefinitions="*,*"
Margin="-10,0,0,0"
VerticalAlignment="Center"
IsVisible="{TemplateBinding ShowAccentColors}">
<Border Grid.Column="0"
Grid.ColumnSpan="2"
<Panel>
<!-- Preview color with accents to the left and right -->
<Grid ColumnDefinitions="Auto,*,Auto"
IsVisible="{TemplateBinding IsAccentColorsVisible}">
<!-- Left accent colors -->
<Grid Grid.Column="0"
Height="{StaticResource ColorPreviewerAccentSectionHeight}"
Width="{StaticResource ColorPreviewerAccentSectionWidth}"
ColumnDefinitions="*,*"
Margin="0,0,-10,0"
VerticalAlignment="Center">
<Border Grid.Column="0"
Grid.ColumnSpan="2"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Background="{StaticResource ColorControlCheckeredBackgroundBrush}" />
<Border x:Name="PART_AccentDecrement2Border"
Grid.Column="0"
CornerRadius="{TemplateBinding CornerRadius, Converter={StaticResource LeftCornerRadiusFilterConverter}}"
Tag="-2"
Background="{TemplateBinding HsvColor, Converter={StaticResource AccentColorConverter}, ConverterParameter='-2'}" />
<Border x:Name="PART_AccentDecrement1Border"
Grid.Column="1"
Tag="-1"
Background="{TemplateBinding HsvColor, Converter={StaticResource AccentColorConverter}, ConverterParameter='-1'}" />
</Grid>
<!-- Right accent colors -->
<Grid Grid.Column="2"
Height="{StaticResource ColorPreviewerAccentSectionHeight}"
Width="{StaticResource ColorPreviewerAccentSectionWidth}"
ColumnDefinitions="*,*"
Margin="-10,0,0,0"
VerticalAlignment="Center">
<Border Grid.Column="0"
Grid.ColumnSpan="2"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Background="{StaticResource ColorControlCheckeredBackgroundBrush}" />
<Border x:Name="PART_AccentIncrement1Border"
Grid.Column="0"
Tag="1"
Background="{TemplateBinding HsvColor, Converter={StaticResource AccentColorConverter}, ConverterParameter='1'}" />
<Border x:Name="PART_AccentIncrement2Border"
Grid.Column="1"
CornerRadius="{TemplateBinding CornerRadius, Converter={StaticResource RightCornerRadiusFilterConverter}}"
Tag="2"
Background="{TemplateBinding HsvColor, Converter={StaticResource AccentColorConverter}, ConverterParameter='2'}" />
</Grid>
<!-- Preview color: Must be last for drop shadow Z-index -->
<Border Grid.Column="1"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Background="{StaticResource ColorControlCheckeredBackgroundBrush}" />
<Border x:Name="PART_AccentIncrement1Border"
Grid.Column="0"
Tag="1"
Background="{TemplateBinding HsvColor, Converter={StaticResource AccentColorConverter}, ConverterParameter='1'}" />
<Border x:Name="PART_AccentIncrement2Border"
Grid.Column="1"
CornerRadius="{TemplateBinding CornerRadius, Converter={StaticResource RightCornerRadiusFilterConverter}}"
Tag="2"
Background="{TemplateBinding HsvColor, Converter={StaticResource AccentColorConverter}, ConverterParameter='2'}" />
BoxShadow="0 0 10 2 #BF000000"
CornerRadius="{TemplateBinding CornerRadius}"
Margin="10">
<Panel>
<Border Background="{StaticResource ColorControlCheckeredBackgroundBrush}"
CornerRadius="{TemplateBinding CornerRadius}" />
<Border CornerRadius="{TemplateBinding CornerRadius}"
Background="{TemplateBinding HsvColor, Converter={StaticResource ToBrushConverter}}"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch" />
</Panel>
</Border>
</Grid>
<!-- Must be last for drop shadow Z-index -->
<Border Grid.Column="1"
BoxShadow="0 0 10 2 #BF000000"
CornerRadius="{TemplateBinding CornerRadius}"
Margin="10">
<!-- Only preview color -->
<Border CornerRadius="{TemplateBinding CornerRadius}"
IsVisible="{TemplateBinding IsAccentColorsVisible, Converter={x:Static BoolConverters.Not}}"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Margin="0,10,0,10">
<Panel>
<Border Background="{StaticResource ColorControlCheckeredBackgroundBrush}"
CornerRadius="{TemplateBinding CornerRadius}" />
<Border x:Name="PreviewBorder"
CornerRadius="{TemplateBinding CornerRadius}"
<Border CornerRadius="{TemplateBinding CornerRadius}"
Background="{TemplateBinding HsvColor, Converter={StaticResource ToBrushConverter}}"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch" />
</Panel>
</Border>
</Grid>
</Panel>
</ControlTemplate>
</Setter>
</Style>

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

@ -638,8 +638,8 @@
<!-- Previewer -->
<!-- Note that top/bottom margins have -5 to remove for drop shadow padding -->
<primitives:ColorPreviewer Grid.Row="1"
ShowAccentColors="{TemplateBinding ShowAccentColors}"
HsvColor="{Binding HsvColor, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}"
IsAccentColorsVisible="{TemplateBinding IsAccentColorsVisible}"
Margin="12,-5,12,7"
IsVisible="{TemplateBinding IsColorPreviewVisible}" />
</Grid>

Loading…
Cancel
Save