From 25da82279f02f4a344c806879b0cea765025c3d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hubert=20G=C5=82uchowski?= Date: Thu, 5 Dec 2024 18:27:38 +0100 Subject: [PATCH] Fix text horizontal alignment --- crates/epaint/src/text/text_layout.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/crates/epaint/src/text/text_layout.rs b/crates/epaint/src/text/text_layout.rs index 4217bffb064..2d4c30a92b2 100644 --- a/crates/epaint/src/text/text_layout.rs +++ b/crates/epaint/src/text/text_layout.rs @@ -113,7 +113,7 @@ pub fn layout(fonts: &mut FontsImpl, job: Arc) -> Galley { let justify_row = justify && !placed_row.ends_with_newline && !is_last_row; halign_and_justify_row( point_scale, - Arc::get_mut(&mut placed_row.row).unwrap(), + placed_row, job.halign, job.wrap.max_width, justify_row, @@ -512,11 +512,13 @@ fn replace_last_glyph_with_overflow_character( /// Ignores the Y coordinate. fn halign_and_justify_row( point_scale: PointScale, - row: &mut Row, + placed_row: &mut PlacedRow, halign: Align, wrap_width: f32, justify: bool, ) { + let row = Arc::get_mut(&mut placed_row.row).unwrap(); + if row.glyphs.is_empty() { return; } @@ -584,7 +586,8 @@ fn halign_and_justify_row( / (num_spaces_in_range as f32); } - let mut translate_x = target_min_x - original_min_x - extra_x_per_glyph * glyph_range.0 as f32; + placed_row.pos.x = point_scale.round_to_pixel(target_min_x); + let mut translate_x = -original_min_x - extra_x_per_glyph * glyph_range.0 as f32; for glyph in &mut row.glyphs { glyph.pos.x += translate_x;