-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
[Feature] Move LetterSpacing to TextElement as inherited attached property #20141
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
base: master
Are you sure you want to change the base?
[Feature] Move LetterSpacing to TextElement as inherited attached property #20141
Conversation
|
There is a breaking change: We can totally accept this minor change for v12, but it should not be backported to v11. |
|
Please read the following Contributor License Agreement (CLA). If you agree with the CLA, please reply with the following: Contributor License AgreementContribution License AgreementThis Contribution License Agreement ( “Agreement” ) is agreed to by the party signing below ( “You” ), 1. Definitions. “Code” means the computer software code, whether in human-readable or machine-executable form, “Project” means any of the projects owned or managed by AvaloniaUI OÜ and offered under a license “Submit” is the act of uploading, submitting, transmitting, or distributing code or other content to any “Submission” means the Code and any other copyrightable material Submitted by You, including any 2. Your Submission. You must agree to the terms of this Agreement before making a Submission to any 3. Originality of Work. You represent that each of Your Submissions is entirely Your 4. Your Employer. References to “employer” in this Agreement include Your employer or anyone else 5. Licenses. a. Copyright License. You grant AvaloniaUI OÜ, and those who receive the Submission directly b. Patent License. You grant AvaloniaUI OÜ, and those who receive the Submission directly or c. Other Rights Reserved. Each party reserves all rights not expressly granted in this Agreement. 6. Representations and Warranties. You represent that You are legally entitled to grant the above 7. Notice to AvaloniaUI OÜ. You agree to notify AvaloniaUI OÜ in writing of any facts or 8. Information about Submissions. You agree that contributions to Projects and information about 9. Governing Law/Jurisdiction. This Agreement is governed by the laws of the Republic of Estonia, and 10. Entire Agreement/Assignment. This Agreement is the entire agreement between the parties, and AvaloniaUI OÜ dedicates this Contribution License Agreement to the public domain according to the Creative Commons CC0 1. |
| </Button> | ||
| <Button Classes="accent">Accent</Button> | ||
| <Button LetterSpacing="0">Normal Spacing</Button> | ||
| <Button LetterSpacing="2.0">L o o s e S p a c i n g</Button> |
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.
Really nitpicking here, but seeing the difference between the different values would be better without the extra spaces in the string.
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.
Yeah, you are right. Removed the spaces, now it's obvious that the LetterSpacing property is what creates the spacing between characters.
| HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" | ||
| VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" /> | ||
| VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" | ||
| TextElement.LetterSpacing="{TemplateBinding LetterSpacing}" /> |
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.
This is an inherited property, we don't usually set it explicitly in templates (see also FontFamily, FontWeight, etc.)
Applicable to all modified templates.
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.
Yea, the WPF convention of letting all font/text properties be properly inherited needs to apply. For some reason in WinUI they started setting everything directly in Fluent. That was an issue and we had to undo a lot of it here and in FluentAvalonia. Definately don't want to take a step back.
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.
Good point. Removed all explicit TextElement.LetterSpacing="{TemplateBinding LetterSpacing}" bindings from templates. The property now inherits automatically through the visual tree, just like FontFamily, FontWeight, FontSize, and other inherited text properties.
|
|
||
|
|
||
| [Fact] | ||
| public void Button_LetterSpacing_Default_Value_Is_Zero() |
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 normally always advocating for more tests, but this time having those tests duplicated in Button, CheckBox, Label, and RadioButton doesn't provide much value, only added maintenance :)
We already have tests verifying that inherited styled properties are working as expected in the general case. The LetterSpacing-specific tests can be added only once.
|
You'll need to run |
|
It's awesome to see you on the Avalonia team now! I remember talking about your drawn controls for MAUI some time ago. Was some interesting work there and in MAUI itself. Anyway, welcome to Avalonia! |
Thanks so much! I appreciate it. |
This PR relocates the LetterSpacing property from
TextBlocktoTextElementas an inherited attached property, making it available across all templated controls (Button, CheckBox, Label, ToolTip, etc.). This change aligns LetterSpacing with the existing architecture used by FontFamily, FontSize, FontWeight, and other text properties.Usage Examples:
Screenshots with some examples:
Checkbox

RadioButton

Menu

ComboBox

Button

Checklist
Breaking changes
None. All existing code continues to work without modification.
Obsoletions / Deprecations
Fixed issues
Fixes #20119