From 1b1f0726ce97f0732fb4a96e96c208185b7000e4 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Sun, 30 Mar 2025 17:23:21 +0200 Subject: [PATCH] Simplify Galley bounding rect calulcation --- crates/epaint/src/text/text_layout.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/crates/epaint/src/text/text_layout.rs b/crates/epaint/src/text/text_layout.rs index ff7a284fc..d88d54783 100644 --- a/crates/epaint/src/text/text_layout.rs +++ b/crates/epaint/src/text/text_layout.rs @@ -611,8 +611,7 @@ fn galley_from_rows( ) -> Galley { let mut first_row_min_height = job.first_row_min_height; let mut cursor_y = 0.0; - let mut min_x: f32 = 0.0; - let mut max_x: f32 = 0.0; + for placed_row in &mut rows { let mut max_row_height = first_row_min_height.max(placed_row.rect().height()); let row = Arc::make_mut(&mut placed_row.row); @@ -640,21 +639,23 @@ fn galley_from_rows( placed_row.pos.y = cursor_y; row.size.y = max_row_height; - min_x = min_x.min(placed_row.rect().min.x); - max_x = max_x.max(placed_row.rect().max.x); cursor_y += max_row_height; cursor_y = point_scale.round_to_pixel(cursor_y); // TODO(emilk): it would be better to do the calculations in pixels instead. } let format_summary = format_summary(&job); + let mut rect = Rect::ZERO; let mut mesh_bounds = Rect::NOTHING; let mut num_vertices = 0; let mut num_indices = 0; for placed_row in &mut rows { + rect = rect.union(placed_row.rect()); + let row = Arc::make_mut(&mut placed_row.row); row.visuals = tessellate_row(point_scale, &job, &format_summary, row); + mesh_bounds = mesh_bounds.union(row.visuals.mesh_bounds.translate(placed_row.pos.to_vec2())); num_vertices += row.visuals.mesh.vertices.len(); @@ -669,8 +670,6 @@ fn galley_from_rows( } } - let rect = Rect::from_min_max(pos2(min_x, 0.0), pos2(max_x, cursor_y)); - let mut galley = Galley { job, rows,