Skip to content

Commit 74c635e

Browse files
Colin MackayColin Mackay
authored andcommitted
Add colour picker
1 parent 452ff0b commit 74c635e

File tree

4 files changed

+34
-7
lines changed

4 files changed

+34
-7
lines changed

src/Stravaig.Icons.Example/App.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
<Application.Styles>
1313
<FluentTheme />
14+
<StyleInclude Source="avares://Avalonia.Controls.ColorPicker/Themes/Fluent/Fluent.xaml" />
1415
<StyleInclude Source="Styles/AppDefaultStyles.axaml" />
1516
</Application.Styles>
1617
</Application>

src/Stravaig.Icons.Example/Stravaig.Icons.Example.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
<ItemGroup>
1616
<PackageReference Include="Avalonia" Version="11.3.9"/>
17+
<PackageReference Include="Avalonia.Controls.ColorPicker" Version="11.3.9" />
1718
<PackageReference Include="Avalonia.Desktop" Version="11.3.9"/>
1819
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.3.9"/>
1920
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.3.9"/>

src/Stravaig.Icons.Example/ViewModels/PhosphorIconDemoViewModel.cs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Avalonia.Controls;
2+
using Avalonia.Media;
23
using CommunityToolkit.Mvvm.ComponentModel;
34
using Stravaig.Avalonia.Controls.Icons;
45
using System;
@@ -22,12 +23,11 @@ public partial class PhosphorIconDemoViewModel : ViewModelBase
2223
[ObservableProperty]
2324
private int _iconSize;
2425

25-
partial void OnSelectedIconTypeIndexChanged(int? value)
26-
{
27-
if (value.HasValue)
28-
SelectedIconType = IconTypes[value.Value].Key;
29-
Trace.WriteLine($"Selected Icon Type Index Changed to {value}. Type is now {SelectedIconType}.");
30-
}
26+
[ObservableProperty]
27+
private HsvColor _colour;
28+
29+
[ObservableProperty]
30+
private string _rgbColour;
3131

3232
public PhosphorIconDemoViewModel()
3333
{
@@ -36,11 +36,24 @@ public PhosphorIconDemoViewModel()
3636
_selectedIconTypeIndex = 0;
3737
_selectedIconType = IconTypes[0].Key;
3838
_iconSize = 24;
39+
_colour = new HsvColor(Color.FromRgb(0x80, 0x80, 0x80));
40+
_rgbColour = _colour.ToRgb().ToString();
3941
}
4042

4143
public List<KeyValuePair<PhosphorIconName, string>> Icons { get; } = Enum.GetValues<PhosphorIconName>().Select(n => new KeyValuePair<PhosphorIconName, string>(n, n.ToString())).ToList();
4244

4345
public List<KeyValuePair<PhosphorIconType, string>> IconTypes { get; } = Enum.GetValues<PhosphorIconType>().Select(t => new KeyValuePair<PhosphorIconType, string>(t, t.ToString())).ToList();
4446

47+
partial void OnColourChanged(HsvColor value)
48+
{
49+
RgbColour = Colour.ToRgb().ToString();
50+
}
51+
52+
partial void OnSelectedIconTypeIndexChanged(int? value)
53+
{
54+
if (value.HasValue)
55+
SelectedIconType = IconTypes[value.Value].Key;
56+
Trace.WriteLine($"Selected Icon Type Index Changed to {value}. Type is now {SelectedIconType}.");
57+
}
4558

4659
}

src/Stravaig.Icons.Example/Views/PhosphorIconDemoView.axaml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
Margin="5"
3030
VerticalAlignment="Center"
3131
Classes="H2"
32-
Text="Style"/>
32+
Text="Style:"/>
3333
<ComboBox ItemsSource="{Binding IconTypes}"
3434
SelectedIndex="{Binding SelectedIconTypeIndex}">
3535
<ComboBox.ItemTemplate>
@@ -68,6 +68,18 @@
6868
VerticalAlignment="Center"/>
6969
</StackPanel>
7070

71+
<StackPanel Orientation="Horizontal">
72+
<TextBlock Classes="H2" Margin="5" Text="Colour:"/>
73+
<ColorPicker
74+
ColorModel="Rgba"
75+
Width="200"
76+
HsvColor="{Binding Colour}" />
77+
<TextBlock
78+
Margin="5"
79+
VerticalAlignment="Center"
80+
Text="{Binding RgbColour}"/>
81+
</StackPanel>
82+
7183
<ItemsControl Name="IconsItemsControl" ItemsSource="{Binding Icons}">
7284
<ItemsControl.ItemsPanel>
7385
<ItemsPanelTemplate>

0 commit comments

Comments
 (0)