From cad52351a8933da0594100e5dfd00965cfa2fde5 Mon Sep 17 00:00:00 2001 From: Aathif_Mahir Date: Sat, 20 Jul 2024 14:38:20 +0530 Subject: [PATCH 01/89] Refactor --- .../{EnumToStringConverter.cs => IconToGlyphConverter.cs} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename src/MauiIcons.Core/Converters/{EnumToStringConverter.cs => IconToGlyphConverter.cs} (90%) diff --git a/src/MauiIcons.Core/Converters/EnumToStringConverter.cs b/src/MauiIcons.Core/Converters/IconToGlyphConverter.cs similarity index 90% rename from src/MauiIcons.Core/Converters/EnumToStringConverter.cs rename to src/MauiIcons.Core/Converters/IconToGlyphConverter.cs index f40f7fd..6d5aa0e 100644 --- a/src/MauiIcons.Core/Converters/EnumToStringConverter.cs +++ b/src/MauiIcons.Core/Converters/IconToGlyphConverter.cs @@ -2,7 +2,7 @@ using System.Globalization; namespace MauiIcons.Core.Converters; -internal sealed class EnumToStringConverter : IValueConverter +internal sealed class IconToGlyphConverter : IValueConverter { public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture) { From a4b05ac87a16cbf89c877e5b185a5bf211ba7759 Mon Sep 17 00:00:00 2001 From: Aathif_Mahir Date: Sat, 20 Jul 2024 14:39:38 +0530 Subject: [PATCH 02/89] Refactor --- src/MauiIcons.Core/Helpers/EnumHelper.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MauiIcons.Core/Helpers/EnumHelper.cs b/src/MauiIcons.Core/Helpers/EnumHelper.cs index 91d94cb..7dd7f01 100644 --- a/src/MauiIcons.Core/Helpers/EnumHelper.cs +++ b/src/MauiIcons.Core/Helpers/EnumHelper.cs @@ -39,7 +39,7 @@ public static string GetFontFamily(this TEnum? value) where TEnum : struc return value.GetType().Name; } - public static string GetFontFamily(this TEnum? value) where TEnum : Enum + public static string GetFontFamily(this TEnum value) where TEnum : Enum? { if (value is null) return string.Empty; return value.GetType().Name; From 21eba53e86cb9b7264e81e9293608f000c2c981c Mon Sep 17 00:00:00 2001 From: Aathif_Mahir Date: Sat, 20 Jul 2024 14:55:18 +0530 Subject: [PATCH 03/89] New BaseIcon --- src/MauiIcons.Core/Controls/BaseIcon.cs | 46 +++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/MauiIcons.Core/Controls/BaseIcon.cs diff --git a/src/MauiIcons.Core/Controls/BaseIcon.cs b/src/MauiIcons.Core/Controls/BaseIcon.cs new file mode 100644 index 0000000..9e5a28f --- /dev/null +++ b/src/MauiIcons.Core/Controls/BaseIcon.cs @@ -0,0 +1,46 @@ +using Microsoft.Maui.Graphics.Converters; + +namespace MauiIcons.Core; +public class BaseIcon : ContentView +{ + public static readonly BindableProperty IconProperty = BindableProperty.Create(nameof(Icon), typeof(Enum), typeof(BaseIcon), null); + public static readonly BindableProperty IconSizeProperty = BindableProperty.Create(nameof(IconSize), typeof(double), typeof(BaseIcon), 30.0); + public static readonly BindableProperty IconColorProperty = BindableProperty.Create(nameof(IconColor), typeof(Color), typeof(BaseIcon), null); + public static readonly BindableProperty IconBackgroundColorProperty = BindableProperty.Create(nameof(IconBackgroundColor), typeof(Color), typeof(BaseIcon), null); + public static readonly BindableProperty IconAutoScalingProperty = BindableProperty.Create(nameof(IconAutoScaling), typeof(bool), typeof(BaseIcon), false); + + public Enum? Icon + { + get => (Enum?)GetValue(IconProperty); + set => SetValue(IconProperty, value); + } + + [System.ComponentModel.TypeConverter(typeof(FontSizeConverter))] + public double IconSize + { + get => (double)GetValue(IconSizeProperty); + set => SetValue(IconSizeProperty, value); + } + + [System.ComponentModel.TypeConverter(typeof(ColorTypeConverter))] + public Color IconColor + { + get => (Color)GetValue(IconColorProperty); + set => SetValue(IconColorProperty, value); + } + + [System.ComponentModel.TypeConverter(typeof(ColorTypeConverter))] + public Color IconBackgroundColor + { + get => (Color)GetValue(IconBackgroundColorProperty); + set => SetValue(IconBackgroundColorProperty, value); + } + + public bool IconAutoScaling + { + get => (bool)GetValue(IconAutoScalingProperty); + set => SetValue(IconAutoScalingProperty, value); + } + + +} From fa48a92efaf96267a44ae00c50ee15c20d43f1b7 Mon Sep 17 00:00:00 2001 From: Aathif_Mahir Date: Sat, 20 Jul 2024 14:55:33 +0530 Subject: [PATCH 04/89] Maui Icon Attached --- .../Controls/MauiIcon.Attached.cs | 157 ++++++++++++++++++ 1 file changed, 157 insertions(+) create mode 100644 src/MauiIcons.Core/Controls/MauiIcon.Attached.cs diff --git a/src/MauiIcons.Core/Controls/MauiIcon.Attached.cs b/src/MauiIcons.Core/Controls/MauiIcon.Attached.cs new file mode 100644 index 0000000..9b102c5 --- /dev/null +++ b/src/MauiIcons.Core/Controls/MauiIcon.Attached.cs @@ -0,0 +1,157 @@ +using MauiIcons.Core.Converters; +using MauiIcons.Core.Helpers; + +namespace MauiIcons.Core; +public partial class MauiIcon +{ + public static new readonly BindableProperty IconProperty = BindableProperty.CreateAttached("Icon", typeof(BaseIcon), typeof(MauiIcon), null, propertyChanged: OnIconPropertyChanged); + + private static void OnIconPropertyChanged(BindableObject bindable, object oldValue, object newValue) + { + if (newValue is null || newValue is not BaseIcon) + return; + + BaseIcon baseIcon = (BaseIcon)newValue; + switch (bindable) + { + case Button button: + button.SetValue(Button.FontFamilyProperty, baseIcon.Icon.GetFontFamily()); + button.SetBinding(Button.TextProperty, new Binding(nameof(baseIcon.Icon), source: baseIcon, mode: BindingMode.OneWay, + converter: new IconToGlyphConverter())); + button.SetBinding(Button.TextColorProperty, new Binding(nameof(baseIcon.IconColor), source: baseIcon, mode: BindingMode.OneWay, + converter: new DefaultColorConverter(), converterParameter: button.TextColor)); + button.SetBinding(Button.BackgroundColorProperty, new Binding(nameof(baseIcon.IconBackgroundColor), source: baseIcon, mode: BindingMode.OneWay, + converter: new DefaultColorConverter(), converterParameter: button.BackgroundColor)); + button.SetBinding(Button.FontSizeProperty, new Binding(nameof(baseIcon.IconSize), source: baseIcon, mode: BindingMode.OneWay)); + button.SetBinding(Button.FontAutoScalingEnabledProperty, new Binding(nameof(baseIcon.IconAutoScaling), source: baseIcon, mode: BindingMode.OneWay)); + break; + + case Label label: + label.SetValue(Label.FontFamilyProperty, baseIcon.Icon.GetFontFamily()); + label.SetBinding(Label.TextProperty, new Binding(nameof(baseIcon.Icon), source: baseIcon, mode: BindingMode.OneWay, + converter: new IconToGlyphConverter())); + label.SetBinding(Label.TextColorProperty, new Binding(nameof(baseIcon.IconColor), source: baseIcon, mode: BindingMode.OneWay, + converter: new DefaultColorConverter(), converterParameter: label.TextColor)); + label.SetBinding(Label.BackgroundColorProperty, new Binding(nameof(baseIcon.IconBackgroundColor), source: baseIcon, mode: BindingMode.OneWay, + converter: new DefaultColorConverter(), converterParameter: label.BackgroundColor)); + label.SetBinding(Label.FontSizeProperty, new Binding(nameof(baseIcon.IconSize), source: baseIcon, mode: BindingMode.OneWay)); + label.SetBinding(Label.FontAutoScalingEnabledProperty, new Binding(nameof(baseIcon.IconAutoScaling), source: baseIcon, mode: BindingMode.OneWay)); + break; + + case Span span: + span.SetValue(Span.FontFamilyProperty, baseIcon.Icon.GetFontFamily()); + span.SetBinding(Span.TextProperty, new Binding(nameof(baseIcon.Icon), source: baseIcon, mode: BindingMode.OneWay, + converter: new IconToGlyphConverter())); + span.SetBinding(Span.TextColorProperty, new Binding(nameof(baseIcon.IconColor), source: baseIcon, mode: BindingMode.OneWay, + converter: new DefaultColorConverter(), converterParameter: span.TextColor)); + span.SetBinding(Span.BackgroundColorProperty, new Binding(nameof(baseIcon.IconBackgroundColor), source: baseIcon, mode: BindingMode.OneWay, + converter: new DefaultColorConverter(), converterParameter: span.BackgroundColor)); + span.SetBinding(Span.FontSizeProperty, new Binding(nameof(baseIcon.IconSize), source: baseIcon, mode: BindingMode.OneWay)); + span.SetBinding(Span.FontAutoScalingEnabledProperty, new Binding(nameof(baseIcon.IconAutoScaling), source: baseIcon, mode: BindingMode.OneWay)); + break; + + case Entry entry: + entry.SetValue(Entry.FontFamilyProperty, baseIcon.Icon.GetFontFamily()); + entry.SetBinding(Entry.TextProperty, new Binding(nameof(baseIcon.Icon), source: baseIcon, mode: BindingMode.OneWay, + converter: new IconToGlyphConverter())); + entry.SetBinding(Entry.TextColorProperty, new Binding(nameof(baseIcon.IconColor), source: baseIcon, mode: BindingMode.OneWay, + converter: new DefaultColorConverter(), converterParameter: entry.TextColor)); + entry.SetBinding(Entry.BackgroundColorProperty, new Binding(nameof(baseIcon.IconBackgroundColor), source: baseIcon, mode: BindingMode.OneWay, + converter: new DefaultColorConverter(), converterParameter: entry.BackgroundColor)); + entry.SetBinding(Entry.FontSizeProperty, new Binding(nameof(baseIcon.IconSize), source: baseIcon, mode: BindingMode.OneWay)); + entry.SetBinding(Entry.FontAutoScalingEnabledProperty, new Binding(nameof(baseIcon.IconAutoScaling), source: baseIcon, mode: BindingMode.OneWay)); + break; + + case Editor editor: + editor.SetValue(Editor.FontFamilyProperty, baseIcon.Icon.GetFontFamily()); + editor.SetBinding(Editor.TextProperty, new Binding(nameof(baseIcon.Icon), source: baseIcon, mode: BindingMode.OneWay, + converter: new IconToGlyphConverter())); + editor.SetBinding(Editor.TextColorProperty, new Binding(nameof(baseIcon.IconColor), source: baseIcon, mode: BindingMode.OneWay, + converter: new DefaultColorConverter(), converterParameter: editor.TextColor)); + editor.SetBinding(Editor.BackgroundColorProperty, new Binding(nameof(baseIcon.IconBackgroundColor), source: baseIcon, mode: BindingMode.OneWay, + converter: new DefaultColorConverter(), converterParameter: editor.BackgroundColor)); + editor.SetBinding(Editor.FontSizeProperty, new Binding(nameof(baseIcon.IconSize), source: baseIcon, mode: BindingMode.OneWay)); + editor.SetBinding(Editor.FontAutoScalingEnabledProperty, new Binding(nameof(baseIcon.IconAutoScaling), source: baseIcon, mode: BindingMode.OneWay)); + break; + + case SearchBar searchBar: + searchBar.SetValue(SearchBar.FontFamilyProperty, baseIcon.Icon.GetFontFamily()); + searchBar.SetBinding(SearchBar.TextProperty, new Binding(nameof(baseIcon.Icon), source: baseIcon, mode: BindingMode.OneWay, + converter: new IconToGlyphConverter())); + searchBar.SetBinding(SearchBar.TextColorProperty, new Binding(nameof(baseIcon.IconColor), source: baseIcon, mode: BindingMode.OneWay, + converter: new DefaultColorConverter(), converterParameter: searchBar.TextColor)); + searchBar.SetBinding(SearchBar.BackgroundColorProperty, new Binding(nameof(baseIcon.IconBackgroundColor), source: baseIcon, mode: BindingMode.OneWay, + converter: new DefaultColorConverter(), converterParameter: searchBar.BackgroundColor)); + searchBar.SetBinding(SearchBar.FontSizeProperty, new Binding(nameof(baseIcon.IconSize), source: baseIcon, mode: BindingMode.OneWay)); + searchBar.SetBinding(SearchBar.FontAutoScalingEnabledProperty, new Binding(nameof(baseIcon.IconAutoScaling), source: baseIcon, mode: BindingMode.OneWay)); + break; + + case MauiIcon mauiIcon: + mauiIcon.SetBinding(MauiIcon.IconValueProperty, new Binding(nameof(baseIcon.Icon), source: baseIcon, mode: BindingMode.OneWay)); + mauiIcon.SetBinding(MauiIcon.IconColorProperty, new Binding(nameof(baseIcon.IconColor), source: baseIcon, mode: BindingMode.OneWay, + converter: new DefaultColorConverter(), converterParameter: mauiIcon.IconColor)); + mauiIcon.SetBinding(MauiIcon.IconBackgroundColorProperty, new Binding(nameof(baseIcon.IconBackgroundColor), source: baseIcon, mode: BindingMode.OneWay, + converter: new DefaultColorConverter(), converterParameter: mauiIcon.IconBackgroundColor)); + mauiIcon.SetBinding(MauiIcon.IconSizeProperty, new Binding(nameof(baseIcon.IconSize), source: baseIcon, mode: BindingMode.OneWay)); + mauiIcon.SetBinding(MauiIcon.IconAutoScalingProperty, new Binding(nameof(baseIcon.IconAutoScaling), source: baseIcon, mode: BindingMode.OneWay)); + break; + + case Image image: + image.SetValue(Image.SourceProperty, new FontImageSource()); + ((FontImageSource)image.Source).SetBinding(FontImageSource.GlyphProperty, new Binding(nameof(baseIcon.Icon), source: baseIcon, mode: BindingMode.OneWay, + converter: new IconToGlyphConverter())); + ((FontImageSource)image.Source).SetValue(FontImageSource.FontFamilyProperty, baseIcon.Icon.GetFontFamily()); + ((FontImageSource)image.Source).SetBinding(FontImageSource.SizeProperty, new Binding(nameof(baseIcon.IconSize), source: baseIcon, mode: BindingMode.OneWay)); + ((FontImageSource)image.Source).SetBinding(FontImageSource.ColorProperty, new Binding(nameof(baseIcon.IconColor), source: baseIcon, mode: BindingMode.OneWay, + converter: new DefaultColorConverter(), converterParameter: ((FontImageSource)image.Source).Color)); + ((FontImageSource)image.Source).SetBinding(FontImageSource.FontAutoScalingEnabledProperty, new Binding(nameof(baseIcon.IconAutoScaling), source: baseIcon, mode: BindingMode.OneWay)); + break; + + case ImageButton imageButton: + imageButton.SetValue(ImageButton.SourceProperty, new FontImageSource()); + ((FontImageSource)imageButton.Source).SetBinding(FontImageSource.GlyphProperty, new Binding(nameof(baseIcon.Icon), source: baseIcon, mode: BindingMode.OneWay, + converter: new IconToGlyphConverter())); + ((FontImageSource)imageButton.Source).SetValue(FontImageSource.FontFamilyProperty, baseIcon.Icon.GetFontFamily()); + ((FontImageSource)imageButton.Source).SetBinding(FontImageSource.SizeProperty, new Binding(nameof(baseIcon.IconSize), source: baseIcon, mode: BindingMode.OneWay)); + ((FontImageSource)imageButton.Source).SetBinding(FontImageSource.ColorProperty, new Binding(nameof(baseIcon.IconColor), source: baseIcon, mode: BindingMode.OneWay, + converter: new DefaultColorConverter(), converterParameter: ((FontImageSource)imageButton.Source).Color)); + ((FontImageSource)imageButton.Source).SetBinding(FontImageSource.FontAutoScalingEnabledProperty, new Binding(nameof(baseIcon.IconAutoScaling), source: baseIcon, mode: BindingMode.OneWay)); + break; + + case ImageCell imageCell: + imageCell.SetValue(ImageCell.ImageSourceProperty, new FontImageSource()); + ((FontImageSource)imageCell.ImageSource).SetBinding(FontImageSource.GlyphProperty, new Binding(nameof(baseIcon.Icon), source: baseIcon, mode: BindingMode.OneWay, + converter: new IconToGlyphConverter())); + ((FontImageSource)imageCell.ImageSource).SetValue(FontImageSource.FontFamilyProperty, baseIcon.Icon.GetFontFamily()); + ((FontImageSource)imageCell.ImageSource).SetBinding(FontImageSource.SizeProperty, new Binding(nameof(baseIcon.IconSize), source: baseIcon, mode: BindingMode.OneWay)); + ((FontImageSource)imageCell.ImageSource).SetBinding(FontImageSource.ColorProperty, new Binding(nameof(baseIcon.IconColor), source: baseIcon, mode: BindingMode.OneWay, + converter: new DefaultColorConverter(), converterParameter: ((FontImageSource)imageCell.ImageSource).Color)); + ((FontImageSource)imageCell.ImageSource).SetBinding(FontImageSource.FontAutoScalingEnabledProperty, new Binding(nameof(baseIcon.IconAutoScaling), source: baseIcon, mode: BindingMode.OneWay)); + break; + + case FontImageSource fontImageSource: + fontImageSource.SetValue(FontImageSource.FontFamilyProperty, baseIcon.Icon.GetFontFamily()); + fontImageSource.SetBinding(FontImageSource.GlyphProperty, new Binding(nameof(baseIcon.Icon), source: baseIcon, mode: BindingMode.OneWay, + converter: new IconToGlyphConverter())); + fontImageSource.SetBinding(FontImageSource.SizeProperty, new Binding(nameof(baseIcon.IconSize), source: baseIcon, mode: BindingMode.OneWay)); + fontImageSource.SetBinding(FontImageSource.ColorProperty, new Binding(nameof(baseIcon.IconColor), source: baseIcon, mode: BindingMode.OneWay, + converter: new DefaultColorConverter(), converterParameter: fontImageSource.Color)); + fontImageSource.SetBinding(FontImageSource.FontAutoScalingEnabledProperty, new Binding(nameof(baseIcon.IconAutoScaling), source: baseIcon, mode: BindingMode.OneWay)); + break; + + default: + throw new MauiIconsExpection($"MauiIcons extension doesn't support this control {bindable}"); + } + } + + + public static BaseIcon? GetIcon(BindableObject view) + { + return (BaseIcon?)view.GetValue(IconProperty); + } + + public static void SetIcon(BindableObject view, BaseIcon? value) + { + view.SetValue(IconProperty, value); + } +} From ce8706fa8c6baf54c9514833a6f17dbadc04de97 Mon Sep 17 00:00:00 2001 From: Aathif_Mahir Date: Sat, 20 Jul 2024 14:55:45 +0530 Subject: [PATCH 05/89] MauiIcon Enhancements --- src/MauiIcons.Core/Controls/IMauiIcon.cs | 5 +- src/MauiIcons.Core/Controls/MauiIcon.cs | 72 +++++++----------------- 2 files changed, 20 insertions(+), 57 deletions(-) diff --git a/src/MauiIcons.Core/Controls/IMauiIcon.cs b/src/MauiIcons.Core/Controls/IMauiIcon.cs index a3d5307..cc84f83 100644 --- a/src/MauiIcons.Core/Controls/IMauiIcon.cs +++ b/src/MauiIcons.Core/Controls/IMauiIcon.cs @@ -3,14 +3,11 @@ namespace MauiIcons.Core; public interface IMauiIcon { - -#nullable enable /// /// Gets or sets the icon enum value. /// - Enum? Icon { get; } + Enum? IconValue { get; } -#nullable disable /// /// Gets or sets the size of the icon. diff --git a/src/MauiIcons.Core/Controls/MauiIcon.cs b/src/MauiIcons.Core/Controls/MauiIcon.cs index fa8bbd5..6317812 100644 --- a/src/MauiIcons.Core/Controls/MauiIcon.cs +++ b/src/MauiIcons.Core/Controls/MauiIcon.cs @@ -3,13 +3,11 @@ using Microsoft.Maui.Graphics.Converters; namespace MauiIcons.Core; -public sealed class MauiIcon : ContentView, IMauiIcon + +public sealed partial class MauiIcon : BaseIcon, IMauiIcon { - public static readonly BindableProperty IconProperty = BindableProperty.Create(nameof(Icon), typeof(Enum), typeof(MauiIcon), null); - public static readonly BindableProperty IconSizeProperty = BindableProperty.Create(nameof(IconSize), typeof(double), typeof(MauiIcon), 30.0); - public static readonly BindableProperty IconColorProperty = BindableProperty.Create(nameof(IconColor), typeof(Color), typeof(MauiIcon), null); - public static readonly BindableProperty IconBackgroundColorProperty = BindableProperty.Create(nameof(IconBackgroundColor), typeof(Color), typeof(MauiIcon), null); - public static readonly BindableProperty IconAutoScalingProperty = BindableProperty.Create(nameof(IconAutoScaling), typeof(bool), typeof(MauiIcon), false); + public static readonly BindableProperty IconValueProperty = BindableProperty.Create(nameof(IconValue), typeof(Enum), typeof(MauiIcon), null); + public static readonly BindableProperty IconSuffixProperty = BindableProperty.Create(nameof(IconSuffix), typeof(string), typeof(MauiIcon), null, propertyChanged: IconSuffixPropertyChanged); public static readonly BindableProperty IconSuffixFontFamilyProperty = BindableProperty.Create(nameof(IconSuffixFontFamily), typeof(string), typeof(MauiIcon), null); public static readonly BindableProperty IconSuffixFontSizeProperty = BindableProperty.Create(nameof(IconSuffixFontSize), typeof(double), typeof(MauiIcon), 20.0); @@ -25,39 +23,10 @@ public sealed class MauiIcon : ContentView, IMauiIcon private static void IconSuffixPropertyChanged(BindableObject bindable, object oldValue, object newValue) => ((MauiIcon)bindable)._iconSuffixSpacer.Text = !string.IsNullOrEmpty((string)newValue) ? " " : null; - -#nullable enable - public Enum? Icon - { - get => (Enum?)GetValue(IconProperty); - set => SetValue(IconProperty, value); - } -#nullable disable - - [System.ComponentModel.TypeConverter(typeof(FontSizeConverter))] - public double IconSize - { - get => (double)GetValue(IconSizeProperty); - set => SetValue(IconSizeProperty, value); - } - - [System.ComponentModel.TypeConverter(typeof(ColorTypeConverter))] - public Color IconColor - { - get => (Color)GetValue(IconColorProperty); - set => SetValue(IconColorProperty, value); - } - - [System.ComponentModel.TypeConverter(typeof(ColorTypeConverter))] - public Color IconBackgroundColor - { - get => (Color)GetValue(IconBackgroundColorProperty); - set => SetValue(IconBackgroundColorProperty, value); - } - public bool IconAutoScaling + public Enum? IconValue { - get => (bool)GetValue(IconAutoScalingProperty); - set => SetValue(IconAutoScalingProperty, value); + get => (Enum)GetValue(IconValueProperty); + set => SetValue(IconValueProperty, value); } public string IconSuffix { @@ -136,25 +105,23 @@ public MauiIcon() Loaded += async (s, r) => { RemoveContentBasedOnPlatformAndIdiom(); - _iconSpan.FontFamily = Icon.GetFontFamily(); + _iconSpan.FontFamily = IconValue.GetFontFamily(); await AnimateIcon(_rootLabel); }; } - private Label _rootLabel; - private Span _iconSpan; + private Label _rootLabel = new(); + private Span _iconSpan = new(); private readonly Span _iconSuffixSpacer = new(); - private Span _suffixSpan; + private Span _suffixSpan = new(); private Label BuildIconControl() { - _iconSpan = new(); - _iconSpan.SetBinding(Span.TextProperty, new Binding(nameof(Icon), converter: new EnumToStringConverter(), source: this)); + _iconSpan.SetBinding(Span.TextProperty, new Binding(nameof(IconValue), converter: new IconToGlyphConverter(), source: this)); _iconSpan.SetBinding(Span.FontAutoScalingEnabledProperty, new Binding(nameof(IconAutoScaling), source: this)); _iconSpan.SetBinding(Span.FontSizeProperty, new Binding(nameof(IconSize), source: this)); _iconSpan.SetBinding(Span.TextColorProperty, new Binding(nameof(IconColor), source: this)); _iconSpan.SetBinding(Span.BackgroundColorProperty, new Binding(nameof(IconBackgroundColor), source: this)); - _suffixSpan = new(); _suffixSpan.SetBinding(Span.TextProperty, new Binding(nameof(IconSuffix), source: this)); _suffixSpan.SetBinding(Span.FontAutoScalingEnabledProperty, new Binding(nameof(IconSuffixAutoScaling), source: this)); _suffixSpan.SetBinding(Span.FontSizeProperty, new Binding(nameof(IconSuffixFontSize), source: this)); @@ -162,7 +129,6 @@ private Label BuildIconControl() _suffixSpan.SetBinding(Span.TextColorProperty, new Binding(nameof(IconSuffixTextColor), source: this)); _suffixSpan.SetBinding(Span.BackgroundColorProperty, new Binding(nameof(IconSuffixBackgroundColor), source: this)); - _rootLabel = new(); _rootLabel.SetBinding(Label.BackgroundColorProperty, new Binding(nameof(IconAndSuffixBackgroundColor), source: this)); _rootLabel.FormattedText = new FormattedString(); _rootLabel.FormattedText.Spans.Add(_iconSpan); @@ -196,9 +162,9 @@ private async Task AnimateIcon(Label label) { Source = new FontImageSource() { - Glyph = baseIcon.Icon.GetDescription(), + Glyph = baseIcon.IconValue.GetDescription(), Color = baseIcon.IconColor.SetDefaultOrAssignedColor(), - FontFamily = baseIcon.Icon.GetFontFamily(), + FontFamily = baseIcon.IconValue.GetFontFamily(), Size = baseIcon.IconSize, FontAutoScalingEnabled = baseIcon.IconAutoScaling, }, @@ -207,9 +173,9 @@ private async Task AnimateIcon(Label label) public static explicit operator FontImageSource(MauiIcon mi) => new() { - Glyph = mi.Icon.GetDescription(), + Glyph = mi.IconValue.GetDescription(), Color = mi.IconColor.SetDefaultOrAssignedColor(), - FontFamily = mi.Icon.GetFontFamily(), + FontFamily = mi.IconValue.GetFontFamily(), Size = mi.IconSize, FontAutoScalingEnabled = mi.IconAutoScaling, }; @@ -217,7 +183,7 @@ private async Task AnimateIcon(Label label) public static explicit operator Label(MauiIcon mi) { var label = mi._rootLabel; - mi._iconSpan.FontFamily = mi.Icon.GetFontFamily(); + mi._iconSpan.FontFamily = mi.IconValue.GetFontFamily(); label.Loaded += async (s, r) => { await mi.AnimateIcon(label); @@ -229,8 +195,8 @@ public static explicit operator Button(MauiIcon mi) { var button = new Button { - Text = mi.Icon.GetDescription(), - FontFamily = mi.Icon.GetFontFamily(), + Text = mi.IconValue.GetDescription(), + FontFamily = mi.IconValue.GetFontFamily(), FontSize = mi.IconSize, FontAutoScalingEnabled = mi.IconAutoScaling }; From 4f550a111a14ed4ceebfad3645446e39947312c4 Mon Sep 17 00:00:00 2001 From: Aathif_Mahir Date: Sat, 20 Jul 2024 14:56:25 +0530 Subject: [PATCH 06/89] Xaml Markup Extension Improvements --- .../Extensions/BaseIconExtension.cs | 46 +++++++++++++++---- 1 file changed, 37 insertions(+), 9 deletions(-) diff --git a/src/MauiIcons.Core/Extensions/BaseIconExtension.cs b/src/MauiIcons.Core/Extensions/BaseIconExtension.cs index 1b55063..44e32d2 100644 --- a/src/MauiIcons.Core/Extensions/BaseIconExtension.cs +++ b/src/MauiIcons.Core/Extensions/BaseIconExtension.cs @@ -47,10 +47,10 @@ public bool IconAutoScaling } [System.ComponentModel.TypeConverter(typeof(ListStringTypeConverter))] - public IList OnPlatforms { get; set; } = new List(); + public IList OnPlatforms { get; set; } = []; [System.ComponentModel.TypeConverter(typeof(ListStringTypeConverter))] - public IList OnIdioms { get; set; } = new List(); + public IList OnIdioms { get; set; } = []; public BindingBase ProvideValue(IServiceProvider serviceProvider) { @@ -68,7 +68,7 @@ object IMarkupExtension.ProvideValue(IServiceProvider serviceProvider) => Binding SetMauiIconBasedOnType(object targetObject, Type? returnType) { - if(returnType == typeof(Enum)) + if (returnType == typeof(Enum)) return SetFontProperties(targetObject, disableConverter: true); if (returnType == typeof(string)) @@ -77,6 +77,14 @@ Binding SetMauiIconBasedOnType(object targetObject, Type? returnType) if (returnType == typeof(ImageSource) || returnType == typeof(FontImageSource)) return SetImageSourceProperties(); + if(returnType == typeof(BaseIcon)) + return SetBaseIconProperties(); + + if (returnType is null && targetObject is Setter setter) + return setter.Property.DeclaringType != typeof(MauiIcon) + ? throw new MauiIconsExpection("MauiIcons doesn't support Style Setter to be used in conjunction with Xaml Extension.") + : SetBaseIconProperties(); + if (returnType is null && (targetObject is On or OnPlatform or OnPlatform or OnPlatformExtension or OnIdiom or OnIdiom @@ -84,9 +92,6 @@ or OnIdiom or OnIdiom throw new MauiIconsExpection("MauiIcons doesn't support Maui OnPlatform or OnIdiom," + "Therefore it is recommended to utilize MauiIcon's integrated Custom OnPlatform or OnIdiom functionalities."); - else if (returnType is null && targetObject is Setter) - throw new MauiIconsExpection("MauiIcons doesn't support Style Setter to be used in conjunction with Xaml Extension."); - throw new MauiIconsExpection($"MauiIcons Extension does not provide {returnType} support"); } @@ -96,7 +101,7 @@ Binding SetFontProperties(object targetObject, bool disableConverter = false) { case Button button: button.FontFamily = Icon.GetFontFamily(); - button.SetBinding(Button.TextColorProperty, new Binding(nameof(IconColor), source: this, mode: BindingMode.OneWay, + button.SetBinding(Button.TextColorProperty, new Binding(nameof(IconColor), source: this, mode: BindingMode.OneWay, converter: new DefaultColorConverter(), converterParameter: button.TextColor)); button.SetBinding(Button.BackgroundColorProperty, new Binding(nameof(IconBackgroundColor), source: this, mode: BindingMode.OneWay, converter: new DefaultColorConverter(), converterParameter: button.BackgroundColor)); @@ -166,13 +171,13 @@ Binding SetFontProperties(object targetObject, bool disableConverter = false) default: throw new MauiIconsExpection($"MauiIcons extension doesn't support this control {targetObject}"); } - return new Binding(nameof(Icon), mode: BindingMode.OneWay, converter: !disableConverter ? new EnumToStringConverter() : null, source: this); + return new Binding(nameof(Icon), mode: BindingMode.OneWay, converter: !disableConverter ? new IconToGlyphConverter() : null, source: this); } Binding SetImageSourceProperties() { InternalSource = new FontImageSource(); - ((FontImageSource)InternalSource).SetBinding(FontImageSource.GlyphProperty, new Binding(nameof(Icon), mode: BindingMode.OneWay, converter: new EnumToStringConverter(), source: this)); + ((FontImageSource)InternalSource).SetBinding(FontImageSource.GlyphProperty, new Binding(nameof(Icon), mode: BindingMode.OneWay, converter: new IconToGlyphConverter(), source: this)); ((FontImageSource)InternalSource).FontFamily = Icon.GetFontFamily(); ((FontImageSource)InternalSource).SetBinding(FontImageSource.SizeProperty, new Binding(nameof(IconSize), source: this)); ((FontImageSource)InternalSource).SetBinding(FontImageSource.ColorProperty, new Binding(nameof(IconColor), source: this, @@ -181,7 +186,19 @@ Binding SetImageSourceProperties() return new Binding(nameof(InternalSource), mode: BindingMode.OneWay, source: this); } + Binding SetBaseIconProperties() + { + InternalBaseSource = new BaseIcon(); + InternalBaseSource.SetBinding(BaseIcon.IconProperty, new Binding(nameof(Icon), mode: BindingMode.OneWay, source: this)); + InternalBaseSource.SetBinding(BaseIcon.IconSizeProperty, new Binding(nameof(IconSize), source: this)); + InternalBaseSource.SetBinding(BaseIcon.IconColorProperty, new Binding(nameof(IconColor), source: this)); + InternalBaseSource.SetBinding(BaseIcon.IconBackgroundColorProperty, new Binding(nameof(IconBackgroundColor), source: this)); + InternalBaseSource.SetBinding(BaseIcon.IconAutoScalingProperty, new Binding(nameof(IconAutoScaling), source: this)); + return new Binding(nameof(InternalBaseSource), mode: BindingMode.OneWay, source: this); + } + public static readonly BindableProperty InternalSourceProperty = BindableProperty.Create(nameof(InternalSource), typeof(ImageSource), typeof(BaseIconExtension), null); + public static readonly BindableProperty InternalBaseSourceProperty = BindableProperty.Create(nameof(InternalBaseSource), typeof(BaseIcon), typeof(BaseIconExtension), null); /// /// This is Used Internally, Don't Use it in XAML or CodeBehind @@ -191,5 +208,16 @@ public ImageSource InternalSource get => (ImageSource)GetValue(InternalSourceProperty); set => SetValue(InternalSourceProperty, value); } + + /// + /// This is Used Internally, Don't Use it in XAML or CodeBehind + /// + public BaseIcon InternalBaseSource + { + get => (BaseIcon)GetValue(InternalBaseSourceProperty); + set => SetValue(InternalBaseSourceProperty, value); + } + + } From b27d3ae95ba582df54094deb46a49ab7744dfd35 Mon Sep 17 00:00:00 2001 From: Aathif_Mahir Date: Sat, 20 Jul 2024 14:56:40 +0530 Subject: [PATCH 07/89] Sample Updates --- samples/MauiIcons.Sample/MainPage.xaml | 28 +++++++++++++ samples/MauiIcons.Sample/MainPage.xaml.cs | 39 +++++++++++++++++++ .../Extensions/MauiIconMarkupExtension.cs | 2 +- 3 files changed, 68 insertions(+), 1 deletion(-) diff --git a/samples/MauiIcons.Sample/MainPage.xaml b/samples/MauiIcons.Sample/MainPage.xaml index 3fbea29..76718ee 100644 --- a/samples/MauiIcons.Sample/MainPage.xaml +++ b/samples/MauiIcons.Sample/MainPage.xaml @@ -5,8 +5,15 @@ xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:MauiIcons.Sample" xmlns:mi="http://www.aathifmahir.com/dotnet/2022/maui/icons" + x:Name="thisRoot" x:DataType="local:MainPage"> + + + + uint EntranceAnimationDuration { get; } + + /// + /// Gets or Sets the type of on-click animation for the element. + /// + AnimationType OnClickAnimationType { get; } + + /// + /// Gets or sets the duration of the on-click animation for the element. + /// + uint OnClickAnimationDuration { get; } + /// /// Gets or sets the Platforms that control should render. /// From bed1d1145929513a7332a0e599efc27dc8615108 Mon Sep 17 00:00:00 2001 From: Aathif Mahir Date: Tue, 1 Oct 2024 18:00:15 +0530 Subject: [PATCH 63/89] Main Docs: Fix --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index c88c7d9..6c2d3df 100644 --- a/README.md +++ b/README.md @@ -104,16 +104,16 @@ if you came across this issue dotnet/maui#7503 when using new namespace, Make su `Xaml` ```xml - - - + + + ``` `C#` ```csharp // Traditional C# -new MauiIcon() {Icon = CupertinoIcons.AppBadge, IconColor = Colors.Green}; -new MauiIcon() {Icon = FluentIcons.Accounts, IconColor = Colors.Blue}; -new MauiIcon() {Icon = MaterialIcons.ABC, IconColor = Colors.Yellow}; +new MauiIcon() {Value = CupertinoIcons.AppBadge, IconColor = Colors.Green}; +new MauiIcon() {Value = FluentIcons.Accounts, IconColor = Colors.Blue}; +new MauiIcon() {Value = MaterialIcons.ABC, IconColor = Colors.Yellow}; // C# Markup new MauiIcon().Icon(CupertinoIcons.AntFill).IconColor(Colors.Purple); From 04bfe3c50a2813c103c125ffdb3e200d607a196f Mon Sep 17 00:00:00 2001 From: Aathif Mahir Date: Tue, 1 Oct 2024 18:01:35 +0530 Subject: [PATCH 64/89] Main Docs: Fix --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6c2d3df..6761c67 100644 --- a/README.md +++ b/README.md @@ -146,16 +146,22 @@ The below example Binds to MyIcon and MyColor Properties Which Present in Code B xmlns:mi="http://www.aathifmahir.com/dotnet/2022/maui/icons" x:Name="thisRoot"> - From 46e907f0832c6428f8044282e8993ff76a070b88 Mon Sep 17 00:00:00 2001 From: Aathif Mahir Date: Tue, 1 Oct 2024 18:02:41 +0530 Subject: [PATCH 65/89] Main Docs: Fix 1 --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6761c67..14d2fae 100644 --- a/README.md +++ b/README.md @@ -147,7 +147,7 @@ The below example Binds to MyIcon and MyColor Properties Which Present in Code B x:Name="thisRoot">