-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Utility methods for measuring text #111493
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
Conversation
goderbauer
left a comment
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.
LGTM
|
auto label is removed for flutter/flutter, pr: 111493, due to - The status or check suite Linux web_long_running_tests_5_5 has failed. Please fix the issues identified (or deflake) before re-applying this label. |
| static double computeWidth({ | ||
| required InlineSpan text, | ||
| TextAlign textAlign = TextAlign.start, | ||
| TextDirection? textDirection, |
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.
TextDirection must be non null I think?
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 was copied from the TextPainter ctor. I'd like to keep the types the same for ease of migration.
If we want to update this we should update the ctor as well.
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.
Ahh but I see what you're saying, on the regular object we can set this to some value later, whereas we can't with this method. Ok. In that case, I'll file a follow upt o make it non-nullable.
Now that
TextPainters must be disposed, it makes some sense to wrap this functionality in a utility method.In customer applications, it is very common to use a text painter to figure out the width of something you want to animate, and then immediately dispose of the painter. This is probably ok because of caching that SkParagraph will do.
I'm a little bit on the fence about whether we should be promoting this, but there are at least 100 callsites in Google's monorepo that use this pattern (likely with some cargo-culting since the code is basically the same everywhere) - so if there's some better way I'm open to hearing about it :)