Fix the Text2d
text anchor's incorrect horizontal alignment (#8019)
This commit is contained in:
parent
8aa217cc8b
commit
729458815c
@ -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;
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
use bevy::{
|
||||
prelude::*,
|
||||
sprite::Anchor,
|
||||
text::{BreakLineOn, Text2dBounds},
|
||||
};
|
||||
|
||||
@ -133,6 +134,29 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||
..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(
|
||||
|
Loading…
Reference in New Issue
Block a user