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

fix markup extension for avalonia #11

Closed
wants to merge 1 commit into from

Conversation

StefanKoell
Copy link
Contributor

  • rename markup extension class to SymbolIconExt to avoid conflicts for style selectors
  • remove default values in the markup extension (nullable props) to allow style selectors set property values
  • remove default values in SymbolIcon ctor to allow style selectors set property values
  • little bit of code cleanup to make analyzers happy

* rename markup extension class to SymbolIconExt to avoid conflicts for style selectors
* remove default values in the markup extension (nullable props) to allow style selectors set property values
* remove default values in SymbolIcon ctor to allow style selectors set property values
* little bit of code cleanup to make analyzers happy
@davidxuang
Copy link
Owner

davidxuang commented Jun 7, 2024

No, this UseSegoeMetricsDefaultValue implementation is wrong. It needs to supplied by a callback. like in

DependencyProperty.Register(nameof(UseSegoeMetrics), typeof(bool), typeof(SymbolIcon), PropertyMetadata.Create(() => UseSegoeMetricsDefaultValue, OnSymbolPropertiesChanged));
, which Avalonia did not implement. It may be logical to allow global value only for this property.

Maybe make the property Lazy<> will also do, but I'm not sure, plus this solution has a racing issue.

@StefanKoell
Copy link
Contributor Author

I did test this and for me it worked when I used the AppBuilderExtension to set the internal static UseSegoeMetricsDefaultValue to true. I double checked the results. Where do you see a potential racing condition?

@davidxuang
Copy link
Owner

I did test this and for me it worked when I used the AppBuilderExtension to set the internal static UseSegoeMetricsDefaultValue to true. I double checked the results. Where do you see a potential racing condition?

Weird. I suppose that all static fields has to be initialized before it can be changed, so the property would have been created before UseSegoeMetricsDefaultValue could be altered.

@StefanKoell
Copy link
Contributor Author

I think it works because the AppBuilder extension is currently the only way to alter the default and this is executed before the whole Avalonia infrastructure is built. So at the time the styled properties are set, the static default value is already set. That's my guess at least. If it should be possible to alter the value afterwards, it has to be implemented differently but in that case, the ability to use style selectors to "override" the value will be gone.

A bit off topic but this setting is a mystery to me. Is there any documentation what value this should be? Is it encouraged to set it to true?

@davidxuang
Copy link
Owner

davidxuang commented Jun 7, 2024

A bit off topic but this setting is a mystery to me. Is there any documentation what value this should be? Is it encouraged to set it to true?

It enables a modified version of fluentui-system-icons, so that it looks more similar to Segoe fonts. Check https://github.com/davidxuang/FluentIcons/blob/master/seagull-icons/README.md.

The most significant change is that Segoe uses a stroke width of 1/16 (of size of bounding square) while fluentui-system-icons uses 1/20 and has a large padding. This is done by removing padding and re-drawing some symbols which are out of bound. Re-drawing are done by hand (https://github.com/davidxuang/FluentIcons/tree/master/seagull-icons/override) or semi-automated composition (https://github.com/davidxuang/FluentIcons/blob/master/seagull-icons/transform.ts).

@StefanKoell
Copy link
Contributor Author

It enables a modified version of fluentui-system-icons, so that it looks more similar to Segoe fonts. Check https://github.com/davidxuang/FluentIcons/blob/master/seagull-icons/README.md.

The most significant change is that Segoe uses a stroke width of 1/16 (of size of bounding square) while fluentui-system-icons uses 1/20 and has a large padding. This is done by removing padding and re-drawing some symbols which are out of bound. Re-drawing are done by hand (https://github.com/davidxuang/FluentIcons/tree/master/seagull-icons/override) or semi-automated composition (https://github.com/davidxuang/FluentIcons/blob/master/seagull-icons/transform.ts).

Thanks for the clarifications. This explains a couple of things. I have other icon sources as well and they are designed according to the fluent system guidelines (smaller appearance, padding around, etc.). So in this case I need to keep the UseSegoeMetricsDefaultValue set to false and compensate with the FontSize to align the icon sizes. The icons from my other source doesn't allow me to remove the padding/change the stroke width.

Regarding the PR:
Do you think the implementation as it is in the PR is OK or should set the value in the ctor again. It will not have any impact for me as I'm not using the UseSegoeMetricsDefaultValue = true

@davidxuang
Copy link
Owner

I didn't see it in the changelog, but is there any issue caused by inheriting MarkupExtension?

Regarding the PR: Do you think the implementation as it is in the PR is OK or should set the value in the ctor again. It will not have any impact for me as I'm not using the UseSegoeMetricsDefaultValue = true

I need more tests on this.

@StefanKoell
Copy link
Contributor Author

I think the requirement to inherit from MarkupExtension is deprecated IIRC. The official docs show MarkupExtension as a standalone class: https://docs.avaloniaui.net/docs/concepts/markupextensions

I also briefly looked at the Avalonia source code and most MarkupExtensions are not inheriting from MarkupExtension:
https://github.com/AvaloniaUI/Avalonia/tree/f140033e420ee39b16dcc0621d5580f94d5bcb2c/src/Markup/Avalonia.Markup.Xaml/MarkupExtensions

davidxuang added a commit that referenced this pull request Jun 7, 2024
…selectors happy. (#11)

Co-authored-by: Stefan Koell <stefan.koell@royalapps.com>
davidxuang added a commit that referenced this pull request Jun 7, 2024
…selectors happy. (#11)

Co-authored-by: Stefan Koell <stefan.koell@royalapps.com>
davidxuang added a commit that referenced this pull request Jun 7, 2024
Make style selectors happy. (#11)

Co-authored-by: Stefan Koell <stefan.koell@royalapps.com>
@davidxuang
Copy link
Owner

Issues addressed.

@davidxuang davidxuang closed this Jun 7, 2024
@StefanKoell StefanKoell deleted the markupext-fixes branch June 7, 2024 16:07
davidxuang added a commit that referenced this pull request Jun 8, 2024
Make style selectors happy.

Co-authored-by: Stefan Koell <stefan.koell@royalapps.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants