From 20667a059226de1b92ee51005a030a0b482e622e Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Sun, 30 Mar 2025 17:52:13 +0200 Subject: [PATCH] put `PlacedRow::pos` first in struct --- crates/epaint/src/shapes/text_shape.rs | 2 +- crates/epaint/src/text/text_layout.rs | 12 ++++++------ crates/epaint/src/text/text_layout_types.rs | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/crates/epaint/src/shapes/text_shape.rs b/crates/epaint/src/shapes/text_shape.rs index d7fe8a479..e88213b93 100644 --- a/crates/epaint/src/shapes/text_shape.rs +++ b/crates/epaint/src/shapes/text_shape.rs @@ -119,7 +119,7 @@ impl TextShape { *rect = transform.scaling * *rect; *mesh_bounds = transform.scaling * *mesh_bounds; - for text::PlacedRow { row, pos } in rows { + for text::PlacedRow { pos, row } in rows { *pos *= transform.scaling; let text::Row { diff --git a/crates/epaint/src/text/text_layout.rs b/crates/epaint/src/text/text_layout.rs index d88d54783..1012fbd84 100644 --- a/crates/epaint/src/text/text_layout.rs +++ b/crates/epaint/src/text/text_layout.rs @@ -208,6 +208,7 @@ fn rows_from_paragraphs( if paragraph.glyphs.is_empty() { rows.push(PlacedRow { + pos: Pos2::ZERO, row: Arc::new(Row { section_index_at_start: paragraph.section_index_at_start, glyphs: vec![], @@ -215,13 +216,13 @@ fn rows_from_paragraphs( size: vec2(0.0, paragraph.empty_paragraph_height), ends_with_newline: !is_last_paragraph, }), - pos: pos2(0.0, 0.0), }); } else { let paragraph_max_x = paragraph.glyphs.last().unwrap().max_x(); if paragraph_max_x <= job.effective_wrap_width() { // Early-out optimization: the whole paragraph fits on one row. rows.push(PlacedRow { + pos: pos2(0.0, f32::NAN), row: Arc::new(Row { section_index_at_start: paragraph.section_index_at_start, glyphs: paragraph.glyphs, @@ -229,7 +230,6 @@ fn rows_from_paragraphs( size: vec2(paragraph_max_x, 0.0), ends_with_newline: !is_last_paragraph, }), - pos: pos2(0.0, f32::NAN), }); } else { line_break(¶graph, job, &mut rows, elided); @@ -275,14 +275,14 @@ fn line_break( // Allow the first row to be completely empty, because we know there will be more space on the next row: // TODO(emilk): this records the height of this first row as zero, though that is probably fine since first_row_indentation usually comes with a first_row_min_height. out_rows.push(PlacedRow { + pos: pos2(0.0, f32::NAN), row: Arc::new(Row { section_index_at_start: paragraph.section_index_at_start, glyphs: vec![], visuals: Default::default(), - size: vec2(0.0, 0.0), + size: Vec2::ZERO, ends_with_newline: false, }), - pos: pos2(0.0, f32::NAN), }); row_start_x += first_row_indentation; first_row_indentation = 0.0; @@ -301,6 +301,7 @@ fn line_break( let paragraph_max_x = glyphs.last().unwrap().max_x(); out_rows.push(PlacedRow { + pos: pos2(0.0, f32::NAN), row: Arc::new(Row { section_index_at_start, glyphs, @@ -308,7 +309,6 @@ fn line_break( size: vec2(paragraph_max_x, 0.0), ends_with_newline: false, }), - pos: pos2(0.0, f32::NAN), }); // Start a new row: @@ -343,6 +343,7 @@ fn line_break( let paragraph_max_x = glyphs.last().unwrap().max_x(); out_rows.push(PlacedRow { + pos: pos2(paragraph_min_x, 0.0), row: Arc::new(Row { section_index_at_start, glyphs, @@ -350,7 +351,6 @@ fn line_break( size: vec2(paragraph_max_x - paragraph_min_x, 0.0), ends_with_newline: false, }), - pos: pos2(paragraph_min_x, 0.0), }); } } diff --git a/crates/epaint/src/text/text_layout_types.rs b/crates/epaint/src/text/text_layout_types.rs index 731f85219..0e59a215b 100644 --- a/crates/epaint/src/text/text_layout_types.rs +++ b/crates/epaint/src/text/text_layout_types.rs @@ -550,13 +550,13 @@ pub struct Galley { #[derive(Clone, Debug, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] pub struct PlacedRow { - /// The underlying row unpositioned [`Row`]. - pub row: Arc, - /// The position of this [`Row`] relative to the galley. /// /// This is rounded to the closest _pixel_ in order to produce crisp, pixel-perfect text. pub pos: Pos2, + + /// The underlying row unpositioned [`Row`]. + pub row: Arc, } impl PlacedRow { @@ -827,8 +827,8 @@ impl Galley { .union(Rect::from_min_size(new_pos, placed_row.size)); super::PlacedRow { - row: placed_row.row.clone(), pos: new_pos, + row: placed_row.row.clone(), } }));