mirror of
https://github.com/bevyengine/bevy
synced 2024-11-22 04:33:37 +00:00
Fix text measurement when multiple font sizes are present (#15669)
# Objective - Fixes https://github.com/bevyengine/bevy/issues/15659 ## Solution - Add up line heights to get text block height instead of using `Metrics`, which only records the largest line height. ## Testing - [x] Fixed issue shown in https://github.com/bevyengine/bevy/pull/15622
This commit is contained in:
parent
7c03ca2562
commit
0b5a360585
1 changed files with 5 additions and 7 deletions
|
@ -455,15 +455,13 @@ fn get_attrs<'a>(
|
|||
|
||||
/// Calculate the size of the text area for the given buffer.
|
||||
fn buffer_dimensions(buffer: &Buffer) -> Vec2 {
|
||||
let width = buffer
|
||||
let (width, height) = buffer
|
||||
.layout_runs()
|
||||
.map(|run| run.line_w)
|
||||
.reduce(f32::max)
|
||||
.unwrap_or(0.0);
|
||||
let line_height = buffer.metrics().line_height.ceil();
|
||||
let height = buffer.layout_runs().count() as f32 * line_height;
|
||||
.map(|run| (run.line_w, run.line_height))
|
||||
.reduce(|(w1, h1), (w2, h2)| (w1.max(w2), h1 + h2))
|
||||
.unwrap_or((0.0, 0.0));
|
||||
|
||||
Vec2::new(width.ceil(), height).ceil()
|
||||
Vec2::new(width, height).ceil()
|
||||
}
|
||||
|
||||
/// Discards stale data cached in `FontSystem`.
|
||||
|
|
Loading…
Reference in a new issue