-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Build-in support for Icons #4087
Comments
Actually it is inspired with UWP icons. There are two common ways to do the think:
<CustomControl.Icon>
<SymbolIcon Symbol="Refresh" />
</CustomControl.Icon> And in CustomControl,xaml: <ContentPresenter Content="{TemplatedBinding Icon}" /> With that approach everything looks good until we need to share icon between controls (we can't share visual element between parents).
<CustomControl.Icon>
<SymbolIconSource Symbol="Refresh" />
</CustomControl.Icon> And in CustomControl,xaml: <IconSourceElement IconSource="{TemplatedBinding Icon}" />
<!-- And we can add second one -->
<IconSourceElement IconSource="{TemplatedBinding Icon}" /> Apart from "API dualism" there are another disadvantages with inconsistency: microsoft/microsoft-ui-xaml#1494 |
Note, that icons should be somewhat compatible with exportable menus. So we need a way to rasterize those as PNG on the UI thread. |
Perhaps we can require icon classes to implement a method to obtain a png. I guess in most of the vector cases you can render the control itself and return the result bitmap. In my project we have a custom icon presenter which is very similar to symbol icons. For databinding purposes you generally want to use some kind of resource identifier and then resolve geometry in the control itself. |
Those might be using bitmap-based brushes. We kinda want to have bitmaps to live in GPU memory, so rendering such icons will either require locking the GPU context or have to be async. |
Xamarin.Forms also has something similar - https://github.com/IeuanWalker/Xamarin.Forms.Breadcrumb#separator-customization Interesting that ImageSource property is used in Image class, so you can set FontImageSource in the image. |
Figure I may as well add my two cents on this...for my Mechanism for Avalonia library, I implemented an icon property for all controls...I decided to use Thus I feel that having the option to use In addition to this, I also toyed with implementing an
Unfortunately, since Mechanism is only a library which augments Avalonia with some new controls and such, I was forced to implement this as an Attached Property, which is...not ideal, as far as I'm concerned. That same inability to add non-attached properties to existing controls also prevented me from doing something which I strongly believe should be done for a built-in implementation of icons: Another thing I'd wondered about is which controls should have this property. Besides the obvious answer of "all controls that have a a) Controls that inherit from Thoughts? Side note: If and/or when a decision is made on this topic, I'd be happy to take a crack at implementing it. |
@Splitwirez I have implementation based on icons from UWP - https://github.com/AvaloniaUI/Avalonia/tree/feature/icons In master branch we already have IconElement and PathIcon. PathIcon/FontIcon/ImageIcon are simple templated controls, that can't be reused neither in UWP nor in Avalonia. IconSource approach similar to your Template approach, but with more specific API, that doesn't allows anything, and in same type it's possible to create TypeConverter that will convert "avares://" paths to the ImageIcon or ImageIconSource. And unlikely UWP implementation, in my branch it's possible to create new IconElement/IconSource pairs (for example, some specific types for FontAwesome icons, that shouldn't be included in the Avalonia repo, but must be possible to implement as third party library).
What difference between IconGap and Margin? If it's related to the content near icon, probably it shouldn't be included in the Icon type itself.
It's not so obvious for me. Why all controls with Content property should have an icon? I.e. in case of Button you should be able to put your icon inside of Content property, or combine icon with another content with StackPanel (or any other panel). |
Also it would be nice to have AnimatedIcon in the future, see specs and implementation from WinUI repo. |
@kekekeks about rendering these icons to achieve bitmap source usable with native menus. Upd: not to mention, it's probably never be possible to make animated icon work with native menus, unless using its first frame as an image. |
So a summary of reasons
SymbolIcon as @maxkatz6 stated elsewhere is better left to 3rd parties libraries for several reasons: package size, font licensing, variations, keeping up-to-date, etc. |
@robloo About |
@Splitwirez Yes,
Your point where it would be a good idea to abstract this in Avalonia: Avalonia would have pre-defined symbols for zoom_in, add, remove, etc... would be nice. However, again, that would require some default implementation of these symbols in Avalonia itself and the above mentioned issues.
|
@Splitwirez FluentAvalonia is updating the SymbolIcon to support what we discussed here and then some. It has a lot of symbols (505 total). It might be good to try that out for your use cases and give feedback over on the other repo. If it becomes widely used perhaps SymbolIcon could come into Avalonia itself based on FluentAvalonia's implementation. Glyphs themselves are fully open source and so is the new font used to implement them. |
Oh nice, thanks for the heads-up. So uh...is that on the https://github.com/amwx/FluentAvalonia/tree/IconElement-fixes branch, or is there somewhere else I should be looking? |
|
Might be interesting dotnet/wpf#8647 |
If we want to create some templated menu that should also support icons, or some kind of NavigationView with icons, we would need to provide some way to customize/define those icons.
Problem:
Current solution:
Use either Image, Viewbox + Path, TextBlock + specific font.
It isn't possible to provide developer-friendly way to change icon with a property.
Upd: actually, it is possible with Control or object, which could be used inside of ContentPresenter.
Possible icon types:
The text was updated successfully, but these errors were encountered: