From ad3a67901de3b4366a8128292852491465a6af9a Mon Sep 17 00:00:00 2001 From: ickshonpe Date: Fri, 10 Mar 2023 10:13:00 +0000 Subject: [PATCH 1/3] changes: * Fixed `Text2d` text anchor point being wrongly inverted on the Y axis. * Added use of `text_anchor` to the `Text2d` example. --- crates/bevy_text/src/text2d.rs | 2 +- examples/2d/text2d.rs | 26 +++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/crates/bevy_text/src/text2d.rs b/crates/bevy_text/src/text2d.rs index 13f9d1340590f..aac6c400feac2 100644 --- a/crates/bevy_text/src/text2d.rs +++ b/crates/bevy_text/src/text2d.rs @@ -103,7 +103,7 @@ pub fn extract_text2d_sprite( } let text_glyphs = &text_layout_info.glyphs; - let text_anchor = anchor.as_vec() * Vec2::new(1., -1.) - 0.5; + let text_anchor = -(anchor.as_vec() + 0.5); let alignment_offset = text_layout_info.size * text_anchor; let mut color = Color::WHITE; let mut current_section = usize::MAX; diff --git a/examples/2d/text2d.rs b/examples/2d/text2d.rs index e920ab5062557..53b3d12a30463 100644 --- a/examples/2d/text2d.rs +++ b/examples/2d/text2d.rs @@ -7,7 +7,7 @@ use bevy::{ prelude::*, - text::{BreakLineOn, Text2dBounds}, + text::{BreakLineOn, Text2dBounds}, sprite::Anchor, }; fn main() { @@ -133,6 +133,30 @@ fn setup(mut commands: Commands, asset_server: Res) { ..default() }); }); + + + for (text_anchor, color) in [ + (Anchor::TopLeft, Color::RED), + (Anchor::TopRight, Color::GREEN), + (Anchor::BottomRight, Color::BLUE), + (Anchor::BottomLeft, Color::YELLOW), + ] { + commands.spawn(Text2dBundle { + text: Text { + sections: vec![TextSection::new( + format!(" Anchor::{text_anchor:?} "), + TextStyle { + color, + ..slightly_smaller_text_style.clone() + }, + )], + ..Default::default() + }, + transform: Transform::from_translation(250. * Vec3::Y), + text_anchor, + ..default() + }); + } } fn animate_translation( From fc8a9072fe640d8ba5c7a6be6bdd32598a40e19d Mon Sep 17 00:00:00 2001 From: ickshonpe Date: Fri, 10 Mar 2023 10:13:00 +0000 Subject: [PATCH 2/3] changes: * Fixed `Text2d` text anchor point being wrongly inverted on the X axis. * Added use of `text_anchor` to the `Text2d` example. --- crates/bevy_text/src/text2d.rs | 2 +- examples/2d/text2d.rs | 26 +++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/crates/bevy_text/src/text2d.rs b/crates/bevy_text/src/text2d.rs index 13f9d1340590f..aac6c400feac2 100644 --- a/crates/bevy_text/src/text2d.rs +++ b/crates/bevy_text/src/text2d.rs @@ -103,7 +103,7 @@ pub fn extract_text2d_sprite( } let text_glyphs = &text_layout_info.glyphs; - let text_anchor = anchor.as_vec() * Vec2::new(1., -1.) - 0.5; + let text_anchor = -(anchor.as_vec() + 0.5); let alignment_offset = text_layout_info.size * text_anchor; let mut color = Color::WHITE; let mut current_section = usize::MAX; diff --git a/examples/2d/text2d.rs b/examples/2d/text2d.rs index e920ab5062557..53b3d12a30463 100644 --- a/examples/2d/text2d.rs +++ b/examples/2d/text2d.rs @@ -7,7 +7,7 @@ use bevy::{ prelude::*, - text::{BreakLineOn, Text2dBounds}, + text::{BreakLineOn, Text2dBounds}, sprite::Anchor, }; fn main() { @@ -133,6 +133,30 @@ fn setup(mut commands: Commands, asset_server: Res) { ..default() }); }); + + + for (text_anchor, color) in [ + (Anchor::TopLeft, Color::RED), + (Anchor::TopRight, Color::GREEN), + (Anchor::BottomRight, Color::BLUE), + (Anchor::BottomLeft, Color::YELLOW), + ] { + commands.spawn(Text2dBundle { + text: Text { + sections: vec![TextSection::new( + format!(" Anchor::{text_anchor:?} "), + TextStyle { + color, + ..slightly_smaller_text_style.clone() + }, + )], + ..Default::default() + }, + transform: Transform::from_translation(250. * Vec3::Y), + text_anchor, + ..default() + }); + } } fn animate_translation( From b0797d3f9ee5477da4c0f93e06a647001fa3079b Mon Sep 17 00:00:00 2001 From: ickshonpe Date: Fri, 10 Mar 2023 10:30:52 +0000 Subject: [PATCH 3/3] cargo fmt --- examples/2d/text2d.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/2d/text2d.rs b/examples/2d/text2d.rs index 53b3d12a30463..100379e5aa3cc 100644 --- a/examples/2d/text2d.rs +++ b/examples/2d/text2d.rs @@ -7,7 +7,8 @@ use bevy::{ prelude::*, - text::{BreakLineOn, Text2dBounds}, sprite::Anchor, + sprite::Anchor, + text::{BreakLineOn, Text2dBounds}, }; fn main() { @@ -134,7 +135,6 @@ fn setup(mut commands: Commands, asset_server: Res) { }); }); - for (text_anchor, color) in [ (Anchor::TopLeft, Color::RED), (Anchor::TopRight, Color::GREEN), @@ -146,7 +146,7 @@ fn setup(mut commands: Commands, asset_server: Res) { sections: vec![TextSection::new( format!(" Anchor::{text_anchor:?} "), TextStyle { - color, + color, ..slightly_smaller_text_style.clone() }, )], @@ -156,7 +156,7 @@ fn setup(mut commands: Commands, asset_server: Res) { text_anchor, ..default() }); - } + } } fn animate_translation(