FIX: Made text alignment work when max width is disabled#4025
FIX: Made text alignment work when max width is disabled#4025Chetansahney wants to merge 2 commits intoGraphiteEditor:masterfrom
Conversation
There was a problem hiding this comment.
Code Review
This pull request modifies the text alignment logic in text_context.rs to ensure alignment works correctly when a maximum width is not specified, by falling back to the layout's full width. The review feedback suggests using the more idiomatic or_else method for the fallback value and correcting a minor spacing issue in a code comment.
| //To make text alignment work when the max width is disabled | ||
| let alignment_width = typesetting.max_width.map(|max_w| max_w as f32).or(Some(layout.full_width())); | ||
| layout.align(alignment_width, typesetting.align.into(), AlignmentOptions::default()); |
There was a problem hiding this comment.
The comment is missing a space after the slashes. Additionally, while layout.full_width() is likely inexpensive, using or_else is a more idiomatic way to provide a fallback value in Rust as it avoids unnecessary evaluation when max_width is present.
| //To make text alignment work when the max width is disabled | |
| let alignment_width = typesetting.max_width.map(|max_w| max_w as f32).or(Some(layout.full_width())); | |
| layout.align(alignment_width, typesetting.align.into(), AlignmentOptions::default()); | |
| // To make text alignment work when the max width is disabled | |
| let alignment_width = typesetting.max_width.map(|max_w| max_w as f32).or_else(|| Some(layout.full_width())); | |
| layout.align(alignment_width, typesetting.align.into(), AlignmentOptions::default()); |
|
@Chetansahney It would be helpful if you could attach the before after video clips. Thankyou. |
Fixes #4011
This PR fixes the issue where text alignment settings (Center/Right/Justify) were ignored unless a Max Width was set. I've updated the logic so that the text block now calculates its own width based on the longest line, allowing alignment to work correctly relative to the text's own bounding box.
Key Changes
Enabled alignment support for text nodes without a defined Max Width.
Updated the layout engine to use the dynamic width of the text rows as the alignment basis.