Skip to content

Commit 25da822

Browse files
committed
Fix text horizontal alignment
1 parent c6592ec commit 25da822

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

crates/epaint/src/text/text_layout.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ pub fn layout(fonts: &mut FontsImpl, job: Arc<LayoutJob>) -> Galley {
113113
let justify_row = justify && !placed_row.ends_with_newline && !is_last_row;
114114
halign_and_justify_row(
115115
point_scale,
116-
Arc::get_mut(&mut placed_row.row).unwrap(),
116+
placed_row,
117117
job.halign,
118118
job.wrap.max_width,
119119
justify_row,
@@ -512,11 +512,13 @@ fn replace_last_glyph_with_overflow_character(
512512
/// Ignores the Y coordinate.
513513
fn halign_and_justify_row(
514514
point_scale: PointScale,
515-
row: &mut Row,
515+
placed_row: &mut PlacedRow,
516516
halign: Align,
517517
wrap_width: f32,
518518
justify: bool,
519519
) {
520+
let row = Arc::get_mut(&mut placed_row.row).unwrap();
521+
520522
if row.glyphs.is_empty() {
521523
return;
522524
}
@@ -584,7 +586,8 @@ fn halign_and_justify_row(
584586
/ (num_spaces_in_range as f32);
585587
}
586588

587-
let mut translate_x = target_min_x - original_min_x - extra_x_per_glyph * glyph_range.0 as f32;
589+
placed_row.pos.x = point_scale.round_to_pixel(target_min_x);
590+
let mut translate_x = -original_min_x - extra_x_per_glyph * glyph_range.0 as f32;
588591

589592
for glyph in &mut row.glyphs {
590593
glyph.pos.x += translate_x;

0 commit comments

Comments
 (0)