Skip to content

Commit 9a9a297

Browse files
committed
Fix: correctly apply max width/height in text bounding box
1 parent da51885 commit 9a9a297

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

node-graph/nodes/text/src/text_context.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,23 @@ impl TextContext {
107107

108108
/// Calculate the bounding box of text using the specified font and typesetting configuration
109109
pub fn bounding_box(&mut self, text: &str, font: &Font, font_cache: &FontCache, typesetting: TypesettingConfig, for_clipping_test: bool) -> DVec2 {
110-
if !for_clipping_test && let (Some(max_height), Some(max_width)) = (typesetting.max_height, typesetting.max_width) {
111-
return DVec2::new(max_width, max_height);
112-
}
113-
114110
let Some(layout) = self.layout_text(text, font, font_cache, typesetting) else {
115111
return DVec2::ZERO;
116112
};
117113

118-
DVec2::new(layout.full_width() as f64, layout.height() as f64)
114+
let layout_width = layout.full_width() as f64;
115+
let layout_height = layout.height() as f64;
116+
117+
// For clipping tests use of the actual layout dimensions to see if text overflows
118+
if for_clipping_test {
119+
return DVec2::new(layout_width, layout_height);
120+
}
121+
122+
// max_width/max_height used if set ,otherwise fall back to calculated layout dimensions
123+
let width = typesetting.max_width.unwrap_or(layout_width);
124+
let height = typesetting.max_height.unwrap_or(layout_height);
125+
126+
DVec2::new(width, height)
119127
}
120128

121129
/// Check if text lines are being clipped due to height constraints

0 commit comments

Comments
 (0)