-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
ComputedTextStyle
#21181
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: main
Are you sure you want to change the base?
ComputedTextStyle
#21181
Conversation
* Removed `TextFont` and `TextColor` from the `Text`, `Text2d`, and `TextSpan` requires, replaced with `ComputedTextStyle`. * `update_text_styles` updates the `ComputedTextStyle`s each frame from the text entities nearest ancestors with `TextFont` or `TextColor` components.
Your PR caused a change in the graphical output of an example or rendering test. This might be intentional, but it could also mean that something broke! If it's expected, please add the M-Deliberate-Rendering-Change label. If this change seems unrelated to your PR, you can consider updating your PR to target the latest main branch, either by rebasing or merging main into it. |
/// default font | ||
pub font: TextFont, | ||
/// default color | ||
pub color: Color, |
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 might also be a good place to stash the global default font size, although that might be a different PR. Maybe a TODO?
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 was thinking the global default font size would just be taken from the font_size
from the DefaultTextStyle
's TextFont
field. I left this part deliberately underdeveloped though because I wasn't sure what we wanted and it's probably better to deal with in another PR.
I propose adding a release note that covers all of the various font-related work we'd like to do. I'm happy to help with writing the text if needed. |
#[derive(Component, Default, Clone, Debug, Reflect)] | ||
#[reflect(Component, Default)] | ||
#[require(ThemedText, PropagateOver::<TextFont>::default())] | ||
#[require(ThemedText)] |
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.
Do we even need ThemedText
any more?
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.
Doesn't look like it, I thought I'd leave it for now though, and focus this PR on the text module changes.
Yeah, that would be a big help, there are so many changes, I'm not looking forward to it. I've got another couple of PRs that should be published tomorrow, that cover the relative font sizes and text span rework. |
I was thinking we should file a cover bug which links to all the various font-related changes we want to make in 0.18. |
I don't feel that happy with the name of the Maybe Also it should be possible to set a default text style per text implementation as well. Perhaps by adding a type parameter, have |
I don't have a problem with the name
My understanding is that it's an inherited default: it applies to any text entity that doesn't have an explicit style, nor has any ancestor that has an explicit style set. Part of the problem is that we don't have a word to describe the domain that encompasses all user interface hierarchies. If all Having a separate default for Text2D entities does make sense. I also think that introducing |
Objective
Propagate text styles down the tree, instead of setting them per node.
Work towards #21175
Solution
ComputedTextStyle
, required onText
,Text2d
, andTextSpan
.TextFont
andTextColor
fromText
,Text2d
, andTextSpan
.update_text_styles
. It updates eachComputedTextStyle
, from either the current entity or the nearest ancestor with aTextFont
orTextColor
.DefaultTextStyle
, used ifupdate_text_styles
can't find any ancestor with aTextColor
orTextFont
.update_text_styles
isn't optimised at all yet. Every frame (there's no change detection), from every text entity, it walks up the tree until it finds aTextColor
andTextFont
to use. It's okay as a reference implementation though, more concerned with synchronisation errors at this stage.Most existing code should work without changes. Because they are no longer required,
TextFont
andTextColor
aren't automatically inserted on text entities when ellided, so instead of the default font, they will use the font and color they inherit from their ancestors instead. And queries forTextFont
andTextColor
that assume the components presence may also fail now.Testing
The
text2d
,feathers
andtestbed_ui
examples all seem to be working correctly with only minor changes.