Fix the Text2d
text anchor's incorrect horizontal alignment (#8019)
This commit is contained in:
parent
f1cc6b609f
commit
fb6583eae6
@ -103,7 +103,7 @@ pub fn extract_text2d_sprite(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let text_glyphs = &text_layout_info.glyphs;
|
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 alignment_offset = text_layout_info.size * text_anchor;
|
||||||
let mut color = Color::WHITE;
|
let mut color = Color::WHITE;
|
||||||
let mut current_section = usize::MAX;
|
let mut current_section = usize::MAX;
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
use bevy::{
|
use bevy::{
|
||||||
prelude::*,
|
prelude::*,
|
||||||
|
sprite::Anchor,
|
||||||
text::{BreakLineOn, Text2dBounds},
|
text::{BreakLineOn, Text2dBounds},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -133,6 +134,29 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
|||||||
..default()
|
..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(
|
fn animate_translation(
|
||||||
|
Loading…
Reference in New Issue
Block a user