Skip to content

Commit 782c42b

Browse files
committed
Improved FontData and IconsPage
1 parent b5dfe73 commit 782c42b

File tree

2 files changed

+41
-6
lines changed

2 files changed

+41
-6
lines changed

PassXYZ.Vault/Views/IconsPage.xaml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,15 @@
2626
</ContentPage.ToolbarItems>
2727

2828
<Grid RowDefinitions="Auto,*">
29-
<Label x:Name="selectedIcon" Text="Please select a icon"
29+
<HorizontalStackLayout Margin="20" Grid.Row="0">
30+
<Picker ItemsSource="{Binding FontFamilyNames}" SelectedItem="{Binding SelectedFontFamilyName}" />
31+
32+
<Label x:Name="selectedIcon" Text="Please select a icon"
3033
HorizontalTextAlignment="Center"
3134
Margin="10"
32-
Grid.Row="0" />
35+
/>
36+
37+
</HorizontalStackLayout>
3338

3439
<ScrollView Grid.Row="1">
3540
<FlexLayout x:Name="flexLayout"

PassXYZ.Vault/Views/IconsPage.xaml.cs

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,58 @@ public partial class IconsPage : ContentPage
99
{
1010
Dictionary<string, string> glyphs;
1111
private Action<PxFontIcon> updateIcon;
12-
PxFontIcon selectedFontIcon = new PxFontIcon { FontFamily = "FontAwesomeBrands", Glyph = FontAwesomeBrands.FontAwesomeAlt };
12+
Type selectedFontFamilyType = FontData.FontFamily[nameof(FontType.FontAwesomeBrands)];
13+
PxFontIcon selectedFontIcon = new PxFontIcon { FontFamily = nameof(FontType.FontAwesomeBrands), Glyph = FontAwesomeBrands.FontAwesomeAlt };
14+
FontImageSource? selectedFontImageSource = default;
1315

1416
public IconsPage()
1517
{
1618
InitializeComponent();
1719
LoadIcons();
1820
Debug.WriteLine("Loading icons ...");
21+
this.BindingContext = this;
1922
}
2023

2124
public IconsPage(Action<PxFontIcon> callback) : this()
2225
{
2326
this.updateIcon = callback;
2427
}
2528

29+
List<string> fontFamilyNames = FontData.FontFamily.Keys.ToList();
30+
public List<string> FontFamilyNames { get => fontFamilyNames; }
31+
32+
string selectedFontFamilyName = nameof(FontType.FontAwesomeBrands);
33+
public string SelectedFontFamilyName
34+
{
35+
get => selectedFontFamilyName;
36+
set
37+
{
38+
if (selectedFontFamilyName != value)
39+
{
40+
selectedFontFamilyName = value;
41+
selectedFontFamilyType = FontData.FontFamily[value];
42+
//glyphs = FontData.GetGlyphs(selectedFontFamilyType);
43+
flexLayout.Children.Clear();
44+
LoadIcons();
45+
OnPropertyChanged();
46+
}
47+
}
48+
}
49+
2650
void OnImageButtonClicked(object? sender, EventArgs e)
2751
{
2852
if (sender is ImageButton imageButton && imageButton.Source is FontImageSource fontImageSource)
2953
{
3054
var glyph = glyphs.FirstOrDefault(x => x.Value == fontImageSource.Glyph);
3155
Debug.WriteLine($"ImageButton clicked with Glyph: {glyph.Key}");
3256
selectedIcon.Text = $"The selected icon is {glyph.Key}.";
33-
selectedFontIcon = new PxFontIcon { FontFamily = "FontAwesomeBrands", Glyph = glyph.Value };
57+
selectedFontIcon = new PxFontIcon { FontFamily = selectedFontFamilyName, Glyph = glyph.Value };
58+
if(selectedFontImageSource != null)
59+
{
60+
selectedFontImageSource.Color = Microsoft.Maui.Graphics.Colors.Black;
61+
}
62+
selectedFontImageSource = fontImageSource;
63+
fontImageSource.Color = (Color)Application.Current.Resources["Primary"];
3464
}
3565
else
3666
{
@@ -40,7 +70,7 @@ void OnImageButtonClicked(object? sender, EventArgs e)
4070

4171
async Task LoadIcons()
4272
{
43-
glyphs = FontData.GetGlyphs(typeof(FontAwesomeBrands));
73+
glyphs = FontData.GetGlyphs(selectedFontFamilyType);
4474

4575
await Task.Run(async () =>
4676
{
@@ -51,7 +81,7 @@ await Task.Run(async () =>
5181
{
5282
Source = new FontImageSource
5383
{
54-
FontFamily = "FontAwesomeBrands",
84+
FontFamily = selectedFontFamilyName,
5585
Glyph = glyph.Value,
5686
Size = 32,
5787
Color = Microsoft.Maui.Graphics.Colors.Black

0 commit comments

Comments
 (0)