From 2114286aca870a4f58a69ef22de1bec34d5c5db1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Sat, 15 Jun 2024 10:59:54 +0200 Subject: [PATCH 1/3] text position: use size instead of bounds --- crates/bevy_text/src/pipeline.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/bevy_text/src/pipeline.rs b/crates/bevy_text/src/pipeline.rs index e6d945a7a9b84..efc1b2b7a087b 100644 --- a/crates/bevy_text/src/pipeline.rs +++ b/crates/bevy_text/src/pipeline.rs @@ -89,8 +89,8 @@ impl TextPipeline { let h_anchor = match text_alignment { JustifyText::Left => 0.0, - JustifyText::Center => bounds.x * 0.5, - JustifyText::Right => bounds.x * 1.0, + JustifyText::Center => size.x * 0.5, + JustifyText::Right => size.x * 1.0, } .floor(); From ca08057cfd7d248bf05c766a50bc108aec74385b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Sat, 15 Jun 2024 12:34:01 +0200 Subject: [PATCH 2/3] use bound when finit --- crates/bevy_text/src/pipeline.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/bevy_text/src/pipeline.rs b/crates/bevy_text/src/pipeline.rs index efc1b2b7a087b..0e11c53baa107 100644 --- a/crates/bevy_text/src/pipeline.rs +++ b/crates/bevy_text/src/pipeline.rs @@ -87,10 +87,12 @@ impl TextPipeline { let size = compute_text_bounds(§ion_glyphs, |index| scaled_fonts[index]).size(); + let h_limit = bounds.x.is_finite().then_some(bounds.x).unwrap_or(size.x); + let h_anchor = match text_alignment { JustifyText::Left => 0.0, - JustifyText::Center => size.x * 0.5, - JustifyText::Right => size.x * 1.0, + JustifyText::Center => h_limit * 0.5, + JustifyText::Right => h_limit * 1.0, } .floor(); From 3f1a5dd08e2d6def39bfa16a8d2e65dc035628bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Sat, 15 Jun 2024 13:08:01 +0200 Subject: [PATCH 3/3] clippy is not funny --- crates/bevy_text/src/pipeline.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/bevy_text/src/pipeline.rs b/crates/bevy_text/src/pipeline.rs index 0e11c53baa107..298857997e896 100644 --- a/crates/bevy_text/src/pipeline.rs +++ b/crates/bevy_text/src/pipeline.rs @@ -87,7 +87,11 @@ impl TextPipeline { let size = compute_text_bounds(§ion_glyphs, |index| scaled_fonts[index]).size(); - let h_limit = bounds.x.is_finite().then_some(bounds.x).unwrap_or(size.x); + let h_limit = if bounds.x.is_finite() { + bounds.x + } else { + size.x + }; let h_anchor = match text_alignment { JustifyText::Left => 0.0,