mirror of
https://github.com/emilk/egui.git
synced 2026-09-02 06:40:06 -04:00
Make the section index private so we don't need to calculate it corectly
This commit is contained in:
@@ -1094,17 +1094,17 @@ mod tests {
|
|||||||
|
|
||||||
for (i, row) in whole.rows.iter().enumerate() {
|
for (i, row) in whole.rows.iter().enumerate() {
|
||||||
println!(
|
println!(
|
||||||
"Whole row {i}: section_index_at_start={}, first glyph section_index: {:?}",
|
"Whole row {i}: section_index_at_start={}, first glyph section_index: {:?}",
|
||||||
row.row.section_index_at_start,
|
row.row.section_index_at_start,
|
||||||
row.row.glyphs.first().map(|g| g.section_index)
|
row.row.glyphs.first().map(|g| g.section_index)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
for (i, row) in split.rows.iter().enumerate() {
|
for (i, row) in split.rows.iter().enumerate() {
|
||||||
println!(
|
println!(
|
||||||
"Split row {i}: section_index_at_start={}, first glyph section_index: {:?}",
|
"Split row {i}: section_index_at_start={}, first glyph section_index: {:?}",
|
||||||
row.row.section_index_at_start,
|
row.row.section_index_at_start,
|
||||||
row.row.glyphs.first().map(|g| g.section_index)
|
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.
|
// Don't compare for equaliity; but format with a specific precision and make sure we hit that.
|
||||||
|
|||||||
@@ -664,13 +664,10 @@ fn galley_from_rows(
|
|||||||
mesh_bounds.union(row.visuals.mesh_bounds.translate(placed_row.pos.to_vec2()));
|
mesh_bounds.union(row.visuals.mesh_bounds.translate(placed_row.pos.to_vec2()));
|
||||||
num_vertices += row.visuals.mesh.vertices.len();
|
num_vertices += row.visuals.mesh.vertices.len();
|
||||||
num_indices += row.visuals.mesh.indices.len();
|
num_indices += row.visuals.mesh.indices.len();
|
||||||
}
|
|
||||||
|
|
||||||
// Fill in correct section_index_at_start for each row:
|
row.section_index_at_start = u32::MAX; // No longer in use.
|
||||||
for placed in &mut rows {
|
for glyph in &mut row.glyphs {
|
||||||
let row = Arc::make_mut(&mut placed.row);
|
glyph.section_index = u32::MAX; // No longer in use.
|
||||||
if let Some(first_glyph) = row.glyphs.first_mut() {
|
|
||||||
row.section_index_at_start = first_glyph.section_index;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -578,8 +578,12 @@ impl std::ops::Deref for PlacedRow {
|
|||||||
#[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 Row {
|
pub struct Row {
|
||||||
/// This is included in case there are no glyphs
|
/// This is included in case there are no glyphs.
|
||||||
pub section_index_at_start: 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_at_start: u32,
|
||||||
|
|
||||||
/// One for each `char`.
|
/// One for each `char`.
|
||||||
pub glyphs: Vec<Glyph>,
|
pub glyphs: Vec<Glyph>,
|
||||||
@@ -669,7 +673,11 @@ pub struct Glyph {
|
|||||||
pub uv_rect: UvRect,
|
pub uv_rect: UvRect,
|
||||||
|
|
||||||
/// Index into [`LayoutJob::sections`]. Decides color etc.
|
/// 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 {
|
impl Glyph {
|
||||||
@@ -841,17 +849,6 @@ impl Galley {
|
|||||||
merged_galley.elided |= galley.elided;
|
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 {
|
if merged_galley.job.round_output_to_gui {
|
||||||
merged_galley.round_output_to_gui();
|
merged_galley.round_output_to_gui();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user