-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
ASTextNode2 to ignore certain text alignments while calculating intrinsic size #1166
ASTextNode2 to ignore certain text alignments while calculating intrinsic size #1166
Conversation
…sic size ASTextNode2 uses ASTextLayout to calculate its layout and bounding rect. When the constrained width that is used for layout calculation is inf/max, ASTextLayout doesn't ignore right/center/natural text alignment but takes it into account. That results in an unreasonable size (and position). Fix by detecting when the node is calculating intrinsic size and force its layout alignment to be left. Other alignments should still work when the max width is finite/reasonable.
f995daf
to
a139d66
Compare
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.
Hey Huy! This fix seems fine for the problem, though I would love to get @wiseoldduck 's take as well since he knows the text situation super good. I pestered him over chat.
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.
Looks good to me! Minor comments.
Source/ASTextNode2.mm
Outdated
|
||
|
||
// If constrained width is max/inf, the text node is calculating its intrinsic size. | ||
const BOOL calculatingIntrinsicSize = (_textContainer.size.width >= ASTextContainerMaxSize.width); |
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.
Does Texture ever use the isVerticalForm
property? We should probably just delete it, but if not maybe check for it here.
Source/ASTextNode2.mm
Outdated
@@ -321,18 +324,31 @@ - (NSArray *)exclusionPaths | |||
return _textContainer.exclusionPaths; | |||
} | |||
|
|||
- (void)prepareAttributedString:(NSMutableAttributedString *)attributedString | |||
- (void)prepareAttributedString:(NSMutableAttributedString *)attributedString forIntrinsicSize:(BOOL)isForIntrinsicSize |
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 method name implies the second parameter is a CGSize
, to me something like isForIntrinsicSize
would imply a BOOL
.
cf8991a
to
24365db
Compare
Awesome! Thank you for reviewing, @Adlai-Holler and @wiseoldduck. |
🚫 CI failed with log |
🚫 CI failed with log |
…nsic size (#1166) ASTextNode2 uses ASTextLayout to calculate its layout and bounding rect. When the constrained width that is used for layout calculation is inf/max (e.g when the node is inside a horizontal stack), ASTextLayout doesn't ignore its right/center/natural text alignment but takes it into account. That results in an unreasonable size (and position). Fix by detecting when the node is calculating intrinsic size and force its layout alignment to be left. Other alignments should still work when the max width is finite/reasonable.
…nsic size (TextureGroup#1166) ASTextNode2 uses ASTextLayout to calculate its layout and bounding rect. When the constrained width that is used for layout calculation is inf/max (e.g when the node is inside a horizontal stack), ASTextLayout doesn't ignore its right/center/natural text alignment but takes it into account. That results in an unreasonable size (and position). Fix by detecting when the node is calculating intrinsic size and force its layout alignment to be left. Other alignments should still work when the max width is finite/reasonable.
ASTextNode2 uses ASTextLayout to calculate its layout and bounding rect. When the constrained width that is used for layout calculation is inf/max (e.g when the node is inside a horizontal stack), ASTextLayout doesn't ignore its right/center/natural text alignment but takes it into account. That results in an unreasonable size (and position).
Fix by detecting when the node is calculating intrinsic size and force its layout alignment to be left. Other alignments should still work when the max width is finite/reasonable.