From 47f916ca80b89a0dacf6dcce65979b894838d05c Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Fri, 28 Mar 2025 15:27:56 +0100 Subject: [PATCH] Fix wrong mesh_bounds --- crates/epaint/src/text/text_layout.rs | 5 +++-- crates/epaint/src/text/text_layout_types.rs | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/crates/epaint/src/text/text_layout.rs b/crates/epaint/src/text/text_layout.rs index 473b9cfff..dd51f6f72 100644 --- a/crates/epaint/src/text/text_layout.rs +++ b/crates/epaint/src/text/text_layout.rs @@ -74,7 +74,7 @@ pub fn layout(fonts: &mut FontsImpl, job: Arc) -> Galley { return Galley { job, rows: Default::default(), - rect: Rect::from_min_max(Pos2::ZERO, Pos2::ZERO), + rect: Rect::ZERO, mesh_bounds: Rect::NOTHING, num_vertices: 0, num_indices: 0, @@ -655,7 +655,8 @@ fn galley_from_rows( for placed_row in &mut rows { let row = Arc::get_mut(&mut placed_row.row).unwrap(); row.visuals = tessellate_row(point_scale, &job, &format_summary, row); - mesh_bounds = mesh_bounds.union(row.visuals.mesh_bounds); + mesh_bounds = + mesh_bounds.union(row.visuals.mesh_bounds.translate(placed_row.pos.to_vec2())); num_vertices += row.visuals.mesh.vertices.len(); num_indices += row.visuals.mesh.indices.len(); } diff --git a/crates/epaint/src/text/text_layout_types.rs b/crates/epaint/src/text/text_layout_types.rs index 22e7cd203..ca5b8a22a 100644 --- a/crates/epaint/src/text/text_layout_types.rs +++ b/crates/epaint/src/text/text_layout_types.rs @@ -872,14 +872,14 @@ impl Galley { rows: Vec::new(), elided: false, rect: emath::Rect::ZERO, - mesh_bounds: emath::Rect::ZERO, + mesh_bounds: emath::Rect::NOTHING, num_vertices: 0, num_indices: 0, pixels_per_point, }; for (i, galley) in galleys.iter().enumerate() { - let current_offset = emath::vec2(0.0, merged_galley.rect.height()); + let current_offset = Vec2::new(0.0, merged_galley.rect.height()); let mut rows = galley.rows.iter(); // As documented in `Row::ends_with_newline`, a '\n' will always create a