Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion node-graph/nodes/text/src/text_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ impl TextContext {
let mut layout: Layout<()> = builder.build(text);

layout.break_all_lines(typesetting.max_width.map(|mw| mw as f32));
layout.align(typesetting.max_width.map(|max_w| max_w as f32), 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(Some(layout.full_width()));
layout.align(alignment_width, typesetting.align.into(), AlignmentOptions::default());
Comment on lines +85 to +87
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
//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());


Some(layout)
}
Expand Down