-
Notifications
You must be signed in to change notification settings - Fork 53
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
Added: Support for coloured vector icons. #1681
Conversation
…ng between instances.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure why we're doing DIY SVG rendering, the Avalonia Svg
control does all of this already. I thought we'd just update our usage of the control with the viewbox and color.
I tried variants of else if (change.Property == ForegroundProperty && Content is Avalonia.Svg.Skia.Svg svg)
{
if (change.NewValue is not SolidColorBrush brush) return;
var css = $".Black {{ fill: {brush.ToHexColour()}; }}";
// ToHexColour() I made myself as an extension
Avalonia.Svg.Skia.Svg.SetCss(svg, css);
} Unfortunately I found that the CSS styling that's part of the Avalonia SVG package applied only to styling classes. i.e. For every SVG we download, we'd need to manually add a class to each path so we can then style it. Then, at runtime, to change the colour once we got there, we'd convert the brush into hex, make a string out of it. Then the Svg library would pick up that string, have to do a class lookup, create a new brush, etc. It felt very silly and inefficient at that point. If we ever needed to animate with colour transitions; that would also be very far from ideal. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No extra comments from me.
For development efficiency, it would be nice if we didn't have to cherry pick out parts of the SVG to put in the constructor, and just be able to paste the entire thing. But it is probably not worth the time investment to implement such a thing to save a couple of minutes on every icon add.
Co-authored-by: erri120 <[email protected]>
Co-authored-by: erri120 <[email protected]>
Co-authored-by: erri120 <[email protected]>
Co-authored-by: erri120 <[email protected]>
Co-authored-by: erri120 <[email protected]>
Fixes #1666
This adds support for coloured icons that can have a ViewBox and thus match design.
Not much more needs to be said.
I also wound up doing some additional research for more efficiently loading vectors in the future; including some alternative file formats, how to integrate, etc. but I decided to relegate carrying out that need into my own personal time; as for the purposes of the project, what we have is sufficiently good enough.
Misc Note: Doing this also exposed to me just how inefficient our use of icons in some regards are.
Give for example Projectanker icons.
These:
And we repeat this for every icon we load, for example, every individual tree row on AdvancedInstaller.
In addition, changing a colour on a Projectanker icon repeats the entire same process, from scratch. oof, when technically one could just change the brush.
In any case, my implementation reuses the data when possible, so the actual icon controls are cheap to create.