1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-01 14:20:04 -04:00

put PlacedRow::pos first in struct

This commit is contained in:
Emil Ernerfeldt
2025-03-30 17:52:13 +02:00
parent 1b1f0726ce
commit 20667a0592
3 changed files with 11 additions and 11 deletions

View File

@@ -119,7 +119,7 @@ impl TextShape {
*rect = transform.scaling * *rect; *rect = transform.scaling * *rect;
*mesh_bounds = transform.scaling * *mesh_bounds; *mesh_bounds = transform.scaling * *mesh_bounds;
for text::PlacedRow { row, pos } in rows { for text::PlacedRow { pos, row } in rows {
*pos *= transform.scaling; *pos *= transform.scaling;
let text::Row { let text::Row {

View File

@@ -208,6 +208,7 @@ fn rows_from_paragraphs(
if paragraph.glyphs.is_empty() { if paragraph.glyphs.is_empty() {
rows.push(PlacedRow { rows.push(PlacedRow {
pos: Pos2::ZERO,
row: Arc::new(Row { row: Arc::new(Row {
section_index_at_start: paragraph.section_index_at_start, section_index_at_start: paragraph.section_index_at_start,
glyphs: vec![], glyphs: vec![],
@@ -215,13 +216,13 @@ fn rows_from_paragraphs(
size: vec2(0.0, paragraph.empty_paragraph_height), size: vec2(0.0, paragraph.empty_paragraph_height),
ends_with_newline: !is_last_paragraph, ends_with_newline: !is_last_paragraph,
}), }),
pos: pos2(0.0, 0.0),
}); });
} else { } else {
let paragraph_max_x = paragraph.glyphs.last().unwrap().max_x(); let paragraph_max_x = paragraph.glyphs.last().unwrap().max_x();
if paragraph_max_x <= job.effective_wrap_width() { if paragraph_max_x <= job.effective_wrap_width() {
// Early-out optimization: the whole paragraph fits on one row. // Early-out optimization: the whole paragraph fits on one row.
rows.push(PlacedRow { rows.push(PlacedRow {
pos: pos2(0.0, f32::NAN),
row: Arc::new(Row { row: Arc::new(Row {
section_index_at_start: paragraph.section_index_at_start, section_index_at_start: paragraph.section_index_at_start,
glyphs: paragraph.glyphs, glyphs: paragraph.glyphs,
@@ -229,7 +230,6 @@ fn rows_from_paragraphs(
size: vec2(paragraph_max_x, 0.0), size: vec2(paragraph_max_x, 0.0),
ends_with_newline: !is_last_paragraph, ends_with_newline: !is_last_paragraph,
}), }),
pos: pos2(0.0, f32::NAN),
}); });
} else { } else {
line_break(&paragraph, job, &mut rows, elided); line_break(&paragraph, 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: // 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. // 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 { out_rows.push(PlacedRow {
pos: pos2(0.0, f32::NAN),
row: Arc::new(Row { row: Arc::new(Row {
section_index_at_start: paragraph.section_index_at_start, section_index_at_start: paragraph.section_index_at_start,
glyphs: vec![], glyphs: vec![],
visuals: Default::default(), visuals: Default::default(),
size: vec2(0.0, 0.0), size: Vec2::ZERO,
ends_with_newline: false, ends_with_newline: false,
}), }),
pos: pos2(0.0, f32::NAN),
}); });
row_start_x += first_row_indentation; row_start_x += first_row_indentation;
first_row_indentation = 0.0; first_row_indentation = 0.0;
@@ -301,6 +301,7 @@ fn line_break(
let paragraph_max_x = glyphs.last().unwrap().max_x(); let paragraph_max_x = glyphs.last().unwrap().max_x();
out_rows.push(PlacedRow { out_rows.push(PlacedRow {
pos: pos2(0.0, f32::NAN),
row: Arc::new(Row { row: Arc::new(Row {
section_index_at_start, section_index_at_start,
glyphs, glyphs,
@@ -308,7 +309,6 @@ fn line_break(
size: vec2(paragraph_max_x, 0.0), size: vec2(paragraph_max_x, 0.0),
ends_with_newline: false, ends_with_newline: false,
}), }),
pos: pos2(0.0, f32::NAN),
}); });
// Start a new row: // Start a new row:
@@ -343,6 +343,7 @@ fn line_break(
let paragraph_max_x = glyphs.last().unwrap().max_x(); let paragraph_max_x = glyphs.last().unwrap().max_x();
out_rows.push(PlacedRow { out_rows.push(PlacedRow {
pos: pos2(paragraph_min_x, 0.0),
row: Arc::new(Row { row: Arc::new(Row {
section_index_at_start, section_index_at_start,
glyphs, glyphs,
@@ -350,7 +351,6 @@ fn line_break(
size: vec2(paragraph_max_x - paragraph_min_x, 0.0), size: vec2(paragraph_max_x - paragraph_min_x, 0.0),
ends_with_newline: false, ends_with_newline: false,
}), }),
pos: pos2(paragraph_min_x, 0.0),
}); });
} }
} }

View File

@@ -550,13 +550,13 @@ pub struct Galley {
#[derive(Clone, Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub struct PlacedRow { pub struct PlacedRow {
/// The underlying row unpositioned [`Row`].
pub row: Arc<Row>,
/// The position of this [`Row`] relative to the galley. /// The position of this [`Row`] relative to the galley.
/// ///
/// This is rounded to the closest _pixel_ in order to produce crisp, pixel-perfect text. /// This is rounded to the closest _pixel_ in order to produce crisp, pixel-perfect text.
pub pos: Pos2, pub pos: Pos2,
/// The underlying row unpositioned [`Row`].
pub row: Arc<Row>,
} }
impl PlacedRow { impl PlacedRow {
@@ -827,8 +827,8 @@ impl Galley {
.union(Rect::from_min_size(new_pos, placed_row.size)); .union(Rect::from_min_size(new_pos, placed_row.size));
super::PlacedRow { super::PlacedRow {
row: placed_row.row.clone(),
pos: new_pos, pos: new_pos,
row: placed_row.row.clone(),
} }
})); }));