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

ASTextNode2 to ignore certain text alignments while calculating intrinsic size #1166

Merged

Conversation

nguyenhuy
Copy link
Member

@nguyenhuy nguyenhuy commented Oct 10, 2018

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.

@nguyenhuy nguyenhuy changed the title Fix ASTextNode2 to ignore certain alignments while calculating intrinsic size ASTextNode2 to ignore certain alignments while calculating intrinsic size Oct 10, 2018
@nguyenhuy nguyenhuy changed the title ASTextNode2 to ignore certain alignments while calculating intrinsic size ASTextNode2 to ignore certain text alignments while calculating intrinsic size Oct 10, 2018
…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.
Copy link
Member

@Adlai-Holler Adlai-Holler left a 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.

Copy link
Member

@wiseoldduck wiseoldduck left a 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.



// If constrained width is max/inf, the text node is calculating its intrinsic size.
const BOOL calculatingIntrinsicSize = (_textContainer.size.width >= ASTextContainerMaxSize.width);
Copy link
Member

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.

@@ -321,18 +324,31 @@ - (NSArray *)exclusionPaths
return _textContainer.exclusionPaths;
}

- (void)prepareAttributedString:(NSMutableAttributedString *)attributedString
- (void)prepareAttributedString:(NSMutableAttributedString *)attributedString forIntrinsicSize:(BOOL)isForIntrinsicSize
Copy link
Member

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.

@nguyenhuy nguyenhuy force-pushed the HN-ASTextNode2-Alignment-Inf-Width branch from cf8991a to 24365db Compare October 11, 2018 01:37
@nguyenhuy
Copy link
Member Author

nguyenhuy commented Oct 11, 2018

Awesome! Thank you for reviewing, @Adlai-Holler and @wiseoldduck.

@ghost
Copy link

ghost commented Oct 11, 2018

🚫 CI failed with log

@ghost
Copy link

ghost commented Oct 11, 2018

🚫 CI failed with log

@nguyenhuy nguyenhuy merged commit 70329f5 into TextureGroup:master Oct 11, 2018
@nguyenhuy nguyenhuy deleted the HN-ASTextNode2-Alignment-Inf-Width branch October 11, 2018 04:40
nguyenhuy added a commit that referenced this pull request Oct 11, 2018
…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.
mikezucc pushed a commit to mikezucc/Texture that referenced this pull request Nov 7, 2018
…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.
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.

None yet

3 participants