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

Custom icons #20

Open
montex12 opened this issue Jun 17, 2023 · 6 comments
Open

Custom icons #20

montex12 opened this issue Jun 17, 2023 · 6 comments
Labels
enhancement New feature or request

Comments

@montex12
Copy link

Hello, is it possible to add custom icons?

I have some SVG files that I would like to integrate in Material.Icons so I can use the same API for Material Icons and Custom Icons.

Thanks

@SKProCH
Copy link
Owner

SKProCH commented Jun 17, 2023

Hello, @montex12

Unfortunately, this will not be the easiest task at the moment. Everything rests on the fact that this library is based on the fact that all the icons are enum elements, and it will be difficult to just expand them. The only way I see - you could take code for Material.Icons, add enum element in MaterialIconEnum.cs, and data for it in MaterialIconDataProvider.PathData.cs, then build and plug dll locally. In theory, this could work.

I've had a few thoughts on how to make this more extensible, but so far I don't think any of them will work.

@SKProCH SKProCH added the enhancement New feature or request label Aug 11, 2023
@amywarble
Copy link
Contributor

amywarble commented Dec 8, 2023

Could the MaterialIconDataProvider.Instance property be made public and writable? If we could set the provider at application startup, we could override ProvideData (which is already virtual) to return custom SVG code for certain icons in the enumeration and defer back to the library implementation for anything not overridden.

We wouldn't be able to add new icons, but we could override existing icons. That would be sufficient for my needs.

I am currently doing this using reflection:

public class CustomIconProvider : MaterialIconDataProvider
{
    public override string ProvideData(MaterialIconKind kind)
    {
        return kind switch
        {
            MaterialIconKind.TrophyVariant => "...",
            _ => base.ProvideData(kind)
        };
    }
}


internal static class Program
{
    public static int Main(string[] args)
    {
        typeof(MaterialIconDataProvider)
            .GetField("_instance", BindingFlags.Static | BindingFlags.NonPublic)!
            .SetValue(null, new CustomIconProvider());

        return BuildAvaloniaApp()
            .StartWithClassicDesktopLifetime(args);
    }
}

@SKProCH
Copy link
Owner

SKProCH commented Dec 8, 2023

Hm, nice suggestion, actually!

I'll try to implement it on the weekend, or you can send a PR

@amywarble
Copy link
Contributor

I would be happy to make a PR this weekend.

@amywarble
Copy link
Contributor

Opened PR #27

@SKProCH
Copy link
Owner

SKProCH commented Dec 9, 2023

Merged. Thanks. I'll publish as a new version a bit later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants