1
0
mirror of https://github.com/emilk/egui.git synced 2026-06-26 22:53:14 -04:00

Make the section index private so we don't need to calculate it corectly

This commit is contained in:
Emil Ernerfeldt
2025-03-30 20:03:47 +02:00
parent 22ea9e91bd
commit 8a33a6a6ce
3 changed files with 22 additions and 28 deletions

View File

@@ -1094,17 +1094,17 @@ mod tests {
for (i, row) in whole.rows.iter().enumerate() {
println!(
"Whole row {i}: section_index_at_start={}, first glyph section_index: {:?}",
row.row.section_index_at_start,
row.row.glyphs.first().map(|g| g.section_index)
);
"Whole row {i}: section_index_at_start={}, first glyph section_index: {:?}",
row.row.section_index_at_start,
row.row.glyphs.first().map(|g| g.section_index)
);
}
for (i, row) in split.rows.iter().enumerate() {
println!(
"Split row {i}: section_index_at_start={}, first glyph section_index: {:?}",
row.row.section_index_at_start,
row.row.glyphs.first().map(|g| g.section_index)
);
"Split row {i}: section_index_at_start={}, first glyph section_index: {:?}",
row.row.section_index_at_start,
row.row.glyphs.first().map(|g| g.section_index)
);
}
// Don't compare for equaliity; but format with a specific precision and make sure we hit that.

View File

@@ -664,13 +664,10 @@ fn galley_from_rows(
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();
}
// Fill in correct section_index_at_start for each row:
for placed in &mut rows {
let row = Arc::make_mut(&mut placed.row);
if let Some(first_glyph) = row.glyphs.first_mut() {
row.section_index_at_start = first_glyph.section_index;
row.section_index_at_start = u32::MAX; // No longer in use.
for glyph in &mut row.glyphs {
glyph.section_index = u32::MAX; // No longer in use.
}
}

View File

@@ -578,8 +578,12 @@ impl std::ops::Deref for PlacedRow {
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub struct Row {
/// This is included in case there are no glyphs
pub section_index_at_start: u32,
/// This is included in case there are no glyphs.
///
/// Only used during layout, then set to an invalid value in order to
/// enable the paragraph-concat optimization path without having to
/// adjust `section_index` when concatting.
pub(crate) section_index_at_start: u32,
/// One for each `char`.
pub glyphs: Vec<Glyph>,
@@ -669,7 +673,11 @@ pub struct Glyph {
pub uv_rect: UvRect,
/// Index into [`LayoutJob::sections`]. Decides color etc.
pub section_index: u32,
///
/// Only used during layout, then set to an invalid value in order to
/// enable the paragraph-concat optimization path without having to
/// adjust `section_index` when concatting.
pub(crate) section_index: u32,
}
impl Glyph {
@@ -841,17 +849,6 @@ impl Galley {
merged_galley.elided |= galley.elided;
}
for placed in &mut merged_galley.rows {
let section_index_at_start = placed.row.glyphs.first().map(|g| g.section_index);
if let Some(section_index_at_start) = section_index_at_start {
if placed.row.section_index_at_start != section_index_at_start {
// This `make_mut` is slow, so only do it when necessary.
let row = Arc::make_mut(&mut placed.row);
row.section_index_at_start = section_index_at_start;
}
}
}
if merged_galley.job.round_output_to_gui {
merged_galley.round_output_to_gui();
}