1
0
mirror of https://github.com/emilk/egui.git synced 2026-06-27 07:03:14 -04:00

Fix bug in code transforming TextShape

This commit is contained in:
Emil Ernerfeldt
2025-03-30 16:50:05 +02:00
parent 7824e2ac18
commit 4ee4572f02
3 changed files with 61 additions and 35 deletions

View File

@@ -456,40 +456,7 @@ impl Shape {
rect_shape.blur_width *= transform.scaling;
}
Self::Text(text_shape) => {
let TextShape {
pos,
galley,
underline,
fallback_color: _,
override_text_color: _,
opacity_factor: _,
angle: _,
} = text_shape;
*pos = transform * *pos;
underline.width *= transform.scaling;
let Galley {
job: _,
rows,
elided: _,
rect,
mesh_bounds,
num_vertices: _,
num_indices: _,
pixels_per_point: _,
} = Arc::make_mut(galley);
for placed_row in rows {
let row = Arc::make_mut(&mut placed_row.row);
row.visuals.mesh_bounds = transform.scaling * row.visuals.mesh_bounds;
for v in &mut row.visuals.mesh.vertices {
v.pos *= transform.scaling;
}
}
*mesh_bounds = transform.scaling * *mesh_bounds;
*rect = transform.scaling * *rect;
text_shape.transform(transform);
}
Self::Mesh(mesh) => {
Arc::make_mut(mesh).transform(transform);

View File

@@ -89,6 +89,63 @@ impl TextShape {
self.opacity_factor = opacity_factor;
self
}
/// Move the shape by this many points, in-place.
pub fn transform(&mut self, transform: emath::TSTransform) {
let Self {
pos,
galley,
underline,
fallback_color: _,
override_text_color: _,
opacity_factor: _,
angle: _,
} = self;
*pos = transform * *pos;
underline.width *= transform.scaling;
let Galley {
job: _,
rows,
elided: _,
rect,
mesh_bounds,
num_vertices: _,
num_indices: _,
pixels_per_point: _,
} = Arc::make_mut(galley);
*rect = transform.scaling * *rect;
*mesh_bounds = transform.scaling * *mesh_bounds;
for text::PlacedRow { row, pos } in rows {
*pos *= transform.scaling;
let text::Row {
section_index_at_start: _,
glyphs: _, // TODO(emilk): would it make sense to transform these?
size,
visuals,
ends_with_newline: _,
} = Arc::make_mut(row);
*size *= transform.scaling;
let text::RowVisuals {
mesh,
mesh_bounds,
glyph_index_start: _,
glyph_vertex_range: _,
} = visuals;
*mesh_bounds = transform.scaling * *mesh_bounds;
for v in &mut mesh.vertices {
v.pos *= transform.scaling;
}
}
}
}
impl From<TextShape> for Shape {

View File

@@ -617,7 +617,9 @@ pub struct FontsAndCache {
impl FontsAndCache {
fn layout_job(&mut self, job: LayoutJob) -> Arc<Galley> {
self.galley_cache.layout(&mut self.fonts, job, true)
let allow_split_paragraphs = true; // Optimization for editing text with many paragraphs.
self.galley_cache
.layout(&mut self.fonts, job, allow_split_paragraphs)
}
}