Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Text Icon Extension Support #43

Merged
merged 18 commits into from
Jun 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion samples/MauiIcons.Sample/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,13 @@
<Image Aspect="Center" Source="{fluentFilled:Icon Icon=AddSquare20Filled, IconColor=DarkGreen}"/>

</HorizontalStackLayout>


<HorizontalStackLayout HorizontalOptions="Center">
<Button Text="{fluent:Icon AddCircle20, IconColor=Violet, IconSize=Large}"/>
<Button Text="{fluentFilled:Icon AccessibilityCheckmark24Filled, IconColor=BlueViolet, IconSize=Large}"/>
<Button Text="{material:Icon ABC, IconColor=BlueViolet, IconSize=Large}"/>
<Button Text="{segoeFluent:Icon AdjustHologram, IconColor=BlueViolet, IconSize=Large}"/>
</HorizontalStackLayout>



Expand Down
3 changes: 2 additions & 1 deletion samples/MauiIcons.Sample/MauiIcons.Sample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

<PropertyGroup>
<TargetFrameworks>net6.0-android;net6.0-ios;net6.0-maccatalyst;net7.0-android;net7.0-ios;net7.0-maccatalyst</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net6.0-windows10.0.19041.0;net7.0-windows10.0.19041.0</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net6.0-windows10.0.19041.0;$(TargetFrameworks);net7.0-windows10.0.19041.0</TargetFrameworks>
<!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
<!-- <TargetFrameworks>$(TargetFrameworks);net6.0-tizen</TargetFrameworks> -->
<OutputType>Exe</OutputType>
<RootNamespace>MauiIcons.Sample</RootNamespace>
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
<ImplicitUsings>enable</ImplicitUsings>
<AccelerateBuildsInVisualStudio>true</AccelerateBuildsInVisualStudio>

<!-- Display name -->
<ApplicationTitle>MauiIcons.Sample</ApplicationTitle>
Expand Down
3 changes: 3 additions & 0 deletions src/MauiIcons.Core/Controls/BaseMauiIcon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace MauiIcons.Core;

[ContentProperty(nameof(Icon))]
public abstract class BaseMauiIcon : ContentView
{
public static readonly BindableProperty IconProperty = BindableProperty.Create(nameof(Icon), typeof(Enum), typeof(BaseMauiIcon), null);
Expand All @@ -16,6 +17,8 @@ public virtual Enum Icon
get => (Enum)GetValue(IconProperty);
set => SetValue(IconProperty, value);
}

[System.ComponentModel.TypeConverter(typeof(FontSizeConverter))]
public double IconSize
{
get => (double)GetValue(IconSizeProperty);
Expand Down
64 changes: 57 additions & 7 deletions src/MauiIcons.Core/Extensions/BaseIconExtension.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,72 @@
using MauiIcons.Core.Helpers;

namespace MauiIcons.Core;
public abstract class BaseIconExtension : IMarkupExtension<ImageSource>

[ContentProperty(nameof(Icon))]
public abstract class BaseIconExtension : IMarkupExtension<object>
{
public virtual Enum Icon { get; set; }
public Color IconColor { get; set; }

[System.ComponentModel.TypeConverter(typeof(FontSizeConverter))]
public double IconSize { get; set; } = 30.0;
public bool IconAutoScaling { get; set; }
protected abstract string IconFontFamily { get; set; }
public ImageSource ProvideValue(IServiceProvider serviceProvider)
public object ProvideValue(IServiceProvider serviceProvider)
{
return new FontImageSource() { Glyph = Icon is not null ? EnumHelper.GetEnumDescription(Icon) : string.Empty,
Color = IconColor ?? ThemeHelper.SetDefaultIconColor(), FontFamily = IconFontFamily, Size = IconSize,
FontAutoScalingEnabled = IconAutoScaling };
IProvideValueTarget provideValueTarget = serviceProvider.GetService(typeof(IProvideValueTarget)) as IProvideValueTarget;
Type returnType = (provideValueTarget.TargetProperty as BindableProperty)?.ReturnType;

if (returnType == typeof(string))
{
AssignFontFamily(provideValueTarget.TargetObject);
return Icon is not null ? EnumHelper.GetEnumDescription(Icon) : string.Empty;
}
if(returnType == typeof(ImageSource))
{
return new FontImageSource()
{
Glyph = Icon is not null ? EnumHelper.GetEnumDescription(Icon) : string.Empty,
Color = IconColor ?? ThemeHelper.SetDefaultIconColor(),
FontFamily = IconFontFamily,
Size = IconSize,
FontAutoScalingEnabled = IconAutoScaling
};
}
throw new NotSupportedException($"Icon Extension Doesn't Support {returnType}");
}

object IMarkupExtension.ProvideValue(IServiceProvider serviceProvider)
void AssignFontFamily(object targetObject)
{
return (this as IMarkupExtension<ImageSource>).ProvideValue(serviceProvider);
switch (targetObject)
{
case Button button:
button.FontFamily = IconFontFamily;
button.TextColor = IconColor ?? ThemeHelper.SetDefaultIconColor();
button.FontSize = IconSize;
break;
case Label label:
label.FontFamily = IconFontFamily;
label.TextColor = IconColor ?? ThemeHelper.SetDefaultIconColor();
label.FontSize = IconSize;
break;
case Entry entry:
entry.FontFamily = IconFontFamily;
entry.TextColor = IconColor ?? ThemeHelper.SetDefaultIconColor();
entry.FontSize = IconSize;
break;
case Editor editor:
editor.FontFamily = IconFontFamily;
editor.TextColor = IconColor ?? ThemeHelper.SetDefaultIconColor();
editor.FontSize = IconSize;
break;
case SearchBar searchBar:
searchBar.FontFamily = IconFontFamily;
searchBar.TextColor = IconColor ?? ThemeHelper.SetDefaultIconColor();
searchBar.FontSize = IconSize;
break;
default:
throw new NotSupportedException($"Icon Extension using Text Doesn't Support this Control {targetObject}");
}
}
}
6 changes: 3 additions & 3 deletions src/MauiIcons.Core/MauiIcons.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
<Description>Core Library for .Net Maui Icons</Description>
<PackageIcon>icon.png</PackageIcon>
<Product>$(AssemblyName) ($(TargetFramework))</Product>
<AssemblyVersion>1.1.1.0</AssemblyVersion>
<AssemblyFileVersion>1.1.1.0</AssemblyFileVersion>
<Version>1.1.1</Version>
<AssemblyVersion>1.1.5.0</AssemblyVersion>
<AssemblyFileVersion>1.1.5.0</AssemblyFileVersion>
<Version>1.1.5</Version>
<PackageVersion>$(Version)$(VersionSuffix)</PackageVersion>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<PackageTags>MauiIcons,Icon,Dotnet,Maui,Icons,Icon,MauiIcon,iOSIcon,AndroidIcon,Material,Fluent,Cuppertino,SegoeFluent</PackageTags>
Expand Down
7 changes: 6 additions & 1 deletion src/MauiIcons.Core/ReleaseNotes.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
v1.1.1
v1.1.5
• Added Icon Unicode Support for Icon Extension
• Added Direct Content Support
• Minor Enhancements and Fixes

v1.1.1
• Minor Enhancements and Fixes

v1.1.0
Expand Down
6 changes: 3 additions & 3 deletions src/MauiIcons.Fluent/MauiIcons.Fluent.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
<Description>Maui Icons - Fluent is a Icon Library to Resolves Icons or Font Icon Management on .Net Maui by Providing Controls with Complete Open Source Fluent Icon Collection Built into Library.</Description>
<PackageIcon>icon.png</PackageIcon>
<Product>$(AssemblyName) ($(TargetFramework))</Product>
<AssemblyVersion>1.1.1.0</AssemblyVersion>
<AssemblyFileVersion>1.1.1.0</AssemblyFileVersion>
<Version>1.1.1</Version>
<AssemblyVersion>1.1.5.0</AssemblyVersion>
<AssemblyFileVersion>1.1.5.0</AssemblyFileVersion>
<Version>1.1.5</Version>
<PackageVersion>$(Version)$(VersionSuffix)</PackageVersion>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<PackageTags>MauiIcons,Icon,Dotnet,Maui,Icons,Icon,MauiIcon,iOSIcon,AndroidIcon,Material,Fluent,Cuppertino,SegoeFluent</PackageTags>
Expand Down
7 changes: 6 additions & 1 deletion src/MauiIcons.Fluent/ReleaseNotes.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
v1.1.1
v1.1.5
• Added Icon Unicode Support for Icon Extension
• Added Direct Content Support
• Minor Enhancements and Fixes

v1.1.1
• Minor Enhancements and Fixes

v1.1.0
Expand Down
6 changes: 3 additions & 3 deletions src/MauiIcons.FluentFilled/MauiIcons.FluentFilled.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
<Description>Maui Icons - Fluent Filled is a Icon Library to Resolves Icons or Font Icon Management on .Net Maui by Providing Controls with Complete Open Source Fluent Icon Collection Built into Library.</Description>
<PackageIcon>icon.png</PackageIcon>
<Product>$(AssemblyName) ($(TargetFramework))</Product>
<AssemblyVersion>1.1.1.0</AssemblyVersion>
<AssemblyFileVersion>1.1.1.0</AssemblyFileVersion>
<Version>1.1.1</Version>
<AssemblyVersion>1.1.5.0</AssemblyVersion>
<AssemblyFileVersion>1.1.5.0</AssemblyFileVersion>
<Version>1.1.5</Version>
<PackageVersion>$(Version)$(VersionSuffix)</PackageVersion>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<PackageTags>MauiIcons,Icon,Dotnet,Maui,Icons,Icon,MauiIcon,iOSIcon,AndroidIcon,Material,Fluent,FluentFilled,Cuppertino,SegoeFluent</PackageTags>
Expand Down
7 changes: 6 additions & 1 deletion src/MauiIcons.FluentFilled/ReleaseNotes.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
v1.1.1
v1.1.5
• Added Icon Unicode Support for Icon Extension
• Added Direct Content Support
• Minor Enhancements and Fixes

v1.1.1
• Minor Enhancements and Fixes

v1.1.0
Expand Down
6 changes: 3 additions & 3 deletions src/MauiIcons.Material/MauiIcons.Material.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
<Description>Maui Icons - Material is a Library to Resolves Icons or Font Icon Management on .Net Maui by Providing Controls with Complete Material Icon Collection Built into Library.</Description>
<PackageIcon>icon.png</PackageIcon>
<Product>$(AssemblyName) ($(TargetFramework))</Product>
<AssemblyVersion>1.1.1.0</AssemblyVersion>
<AssemblyFileVersion>1.1.1.0</AssemblyFileVersion>
<Version>1.1.1</Version>
<AssemblyVersion>1.1.5.0</AssemblyVersion>
<AssemblyFileVersion>1.1.5.0</AssemblyFileVersion>
<Version>1.1.5</Version>
<PackageVersion>$(Version)$(VersionSuffix)</PackageVersion>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<PackageTags>MauiIcons,Icon,Dotnet,Maui,Icons,Icon,MauiIcon,iOSIcon,AndroidIcon,Material,Fluent,Cuppertino,SegoeFluent</PackageTags>
Expand Down
7 changes: 6 additions & 1 deletion src/MauiIcons.Material/ReleaseNotes.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
v1.1.1
v1.1.5
• Added Icon Unicode Support for Icon Extension
• Added Direct Content Support
• Minor Enhancements and Fixes

v1.1.1
• Minor Enhancements and Fixes

v1.1.0
Expand Down
6 changes: 3 additions & 3 deletions src/MauiIcons.SegoeFluent/MauiIcons.SegoeFluent.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
<Description>Maui Icons - Segoe Fluent is a Windows Default Icon Library to Resolves Icons or Font Icon Management on .Net Maui by Providing Controls with Complete Fluent Icon Collection Built into Library.</Description>
<PackageIcon>icon.png</PackageIcon>
<Product>$(AssemblyName) ($(TargetFramework))</Product>
<AssemblyVersion>1.1.1.0</AssemblyVersion>
<AssemblyFileVersion>1.1.1.0</AssemblyFileVersion>
<Version>1.1.1</Version>
<AssemblyVersion>1.1.5.0</AssemblyVersion>
<AssemblyFileVersion>1.1.5.0</AssemblyFileVersion>
<Version>1.1.5</Version>
<PackageVersion>$(Version)$(VersionSuffix)</PackageVersion>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<PackageTags>MauiIcons,Icon,Dotnet,Maui,Icons,Icon,MauiIcon,iOSIcon,AndroidIcon,Material,Fluent,Cuppertino,SegoeFluent</PackageTags>
Expand Down
7 changes: 6 additions & 1 deletion src/MauiIcons.SegoeFluent/ReleaseNotes.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
v1.1.1
v1.1.5
• Added Icon Unicode Support for Icon Extension
• Added Direct Content Support
• Minor Enhancements and Fixes

v1.1.1
• Minor Enhancements and Fixes

v1.1.0
Expand Down