From 99899d49cc93cdec3832f7b5ecad867fdd421e07 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 1 Dec 2023 15:04:08 +0100 Subject: Clamp `text::measure` to `Buffer::size` --- graphics/src/text.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'graphics/src/text.rs') diff --git a/graphics/src/text.rs b/graphics/src/text.rs index 7261900e..fc7694c2 100644 --- a/graphics/src/text.rs +++ b/graphics/src/text.rs @@ -76,7 +76,12 @@ pub fn measure(buffer: &cosmic_text::Buffer) -> Size { (run.line_w.max(width), total_lines + 1) }); - Size::new(width, total_lines as f32 * buffer.metrics().line_height) + let (max_width, max_height) = buffer.size(); + + Size::new( + width.min(max_width), + (total_lines as f32 * buffer.metrics().line_height).min(max_height), + ) } /// Returns the attributes of the given [`Font`]. -- cgit