mirror of
https://github.com/emilk/egui.git
synced 2026-09-01 06:10:06 -04:00
Fix bug in code transforming TextShape
This commit is contained in:
@@ -456,40 +456,7 @@ impl Shape {
|
|||||||
rect_shape.blur_width *= transform.scaling;
|
rect_shape.blur_width *= transform.scaling;
|
||||||
}
|
}
|
||||||
Self::Text(text_shape) => {
|
Self::Text(text_shape) => {
|
||||||
let TextShape {
|
text_shape.transform(transform);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
Self::Mesh(mesh) => {
|
Self::Mesh(mesh) => {
|
||||||
Arc::make_mut(mesh).transform(transform);
|
Arc::make_mut(mesh).transform(transform);
|
||||||
|
|||||||
@@ -89,6 +89,63 @@ impl TextShape {
|
|||||||
self.opacity_factor = opacity_factor;
|
self.opacity_factor = opacity_factor;
|
||||||
self
|
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 {
|
impl From<TextShape> for Shape {
|
||||||
|
|||||||
@@ -617,7 +617,9 @@ pub struct FontsAndCache {
|
|||||||
|
|
||||||
impl FontsAndCache {
|
impl FontsAndCache {
|
||||||
fn layout_job(&mut self, job: LayoutJob) -> Arc<Galley> {
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user