Skip to content

Commit

Permalink
Merge pull request #444 from irihitech/colorpicker
Browse files Browse the repository at this point in the history
Make ColorPicker dropdown button customizable.
  • Loading branch information
rabbitism authored Oct 18, 2024
2 parents a5b0a89 + 33f266f commit c56ce90
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 14 deletions.
56 changes: 44 additions & 12 deletions demo/Semi.Avalonia.Demo/Pages/ColorPickerDemo.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,42 +19,74 @@
<ColorView ColorSpectrumShape="Box" />
<ColorView Palette="{DynamicResource SemiColorPalette}" />
</StackPanel>
<StackPanel
VerticalAlignment="Top"
Orientation="Horizontal">
<StackPanel VerticalAlignment="Top" Orientation="Horizontal">
<ColorView
Name="SimpleColorViewTest"
Theme="{StaticResource SimpleColorView}"
HsvColor="hsv(120,11%,10%)"
IsAlphaVisible="True"
HsvColor="hsv(120,11%,10%)" />
Theme="{StaticResource SimpleColorView}" />
<StackPanel>
<TextBlock Text="{Binding #SimpleColorViewTest.HsvColor}" />
<TextBlock Text="{Binding #SimpleColorViewTest.Color}" />
</StackPanel>
</StackPanel>
<StackPanel HorizontalAlignment="Left" Orientation="Horizontal">
<ColorPicker ColorSpectrumShape="Ring">
<ColorPicker Margin="8" ColorSpectrumShape="Ring">
<ColorPicker.Palette>
<controls:FlatHalfColorPalette />
</ColorPicker.Palette>
</ColorPicker>
<ColorPicker ColorSpectrumShape="Box">
<ColorPicker Margin="8" ColorSpectrumShape="Box">
<ColorPicker.Palette>
<colorPicker:SemiColorLightPalette />
</ColorPicker.Palette>
</ColorPicker>

<ColorPicker ColorSpectrumShape="Box" Theme="{DynamicResource HexColorPicker}">
<ColorPicker
Margin="8"
ColorSpectrumShape="Box"
Theme="{DynamicResource HexColorPicker}">
<ColorPicker.Palette>
<colorPicker:SemiColorLightPalette />
</ColorPicker.Palette>
</ColorPicker>
</StackPanel>
<StackPanel HorizontalAlignment="Left" >
<TextBlock Text="Use Style to customize button"></TextBlock>
<ColorPicker
Margin="8"
Width="32"
HsvColor="hsv(120,11%,10%)"
>
<ColorPicker.Content>
<Border
Margin="1"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Background="{Binding $parent[ColorPicker].HsvColor,
Converter={StaticResource ToBrushConverter}}"
CornerRadius="1" />
</ColorPicker.Content>
<ColorPicker.Styles>
<Style Selector="DropDownButton">
<Setter Property="Padding" Value="0"/>
<Style Selector="^ /template/ PathIcon">
<Setter Property="IsVisible" Value="False"/>
</Style>
</Style>
</ColorPicker.Styles>
</ColorPicker>

</StackPanel>
<StackPanel HorizontalAlignment="Left" Orientation="Horizontal">
<ColorPicker Theme="{StaticResource SimpleColorPicker}"
HsvColor="hsv(120,11%,10%)" />
<ColorPicker Theme="{StaticResource HexSimpleColorPicker}"
HsvColor="hsv(120,11%,10%)" />
<ColorPicker
Margin="8"
HsvColor="hsv(120,11%,10%)"
Theme="{StaticResource SimpleColorPicker}" />
<ColorPicker
Margin="8"
HsvColor="hsv(120,11%,10%)"
Theme="{StaticResource HexSimpleColorPicker}" />
</StackPanel>
</StackPanel>
</ScrollViewer>
Expand Down
6 changes: 4 additions & 2 deletions src/Semi.Avalonia.ColorPicker/Controls/ColorPicker.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
<DropDownButton
Width="{TemplateBinding Width}"
Height="{TemplateBinding Height}"
Padding="0,0,10,0"
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch"
ClipToBounds="True"
Expand Down Expand Up @@ -473,6 +472,10 @@
</DropDownButton>
</ControlTemplate>
</Setter>

<Style Selector="^ /template/ DropDownButton">
<Setter Property="Padding" Value="0 0 10 0"></Setter>
</Style>
</ControlTheme>

<ControlTheme
Expand Down Expand Up @@ -523,7 +526,6 @@
<DropDownButton
Width="{TemplateBinding Width}"
Height="{TemplateBinding Height}"
Padding="0,0,10,0"
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch"
ClipToBounds="True"
Expand Down

0 comments on commit c56ce90

Please sign in to comment.