Clamp text::measure to Buffer::size

This commit is contained in:
Héctor Ramón Jiménez 2023-12-01 15:04:08 +01:00
parent 7f8b17604a
commit 99899d49cc
No known key found for this signature in database
GPG key ID: 7CC46565708259A7

View file

@ -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`].