fix: text (partially)

This commit is contained in:
Nova
2025-09-03 13:16:57 -07:00
parent d6ad00bf53
commit a6a1195922

View File

@@ -85,7 +85,7 @@ fn spawn_text(
); );
let max_width = style.bounds.as_ref().map(|v| v.bounds.x); let max_width = style.bounds.as_ref().map(|v| v.bounds.x);
let max_height = style.bounds.as_ref().map(|v| v.bounds.x); let max_height = style.bounds.as_ref().map(|v| v.bounds.x);
let (width, _height) = let (width, height) =
text_glyphs.measure(max_width, max_height, &mut font_settings.font_system); text_glyphs.measure(max_width, max_height, &mut font_settings.font_system);
let char_meshes = generate_meshes( let char_meshes = generate_meshes(
bevy_mesh_text_3d::InputText::Simple { bevy_mesh_text_3d::InputText::Simple {
@@ -124,18 +124,6 @@ fn spawn_text(
else { else {
continue; continue;
}; };
let dist = char_meshes.iter().fold(f32::MAX, |dist, v| {
dist.min(
v.transform.translation.x
- meshes
.get(&v.mesh)
.unwrap()
.compute_aabb()
.unwrap_or_default()
.half_extents
.x,
)
});
// TODO: text align // TODO: text align
let letters = char_meshes let letters = char_meshes
.into_iter() .into_iter()
@@ -143,19 +131,20 @@ fn spawn_text(
cmds.spawn(( cmds.spawn((
Mesh3d(v.mesh), Mesh3d(v.mesh),
MeshMaterial3d(v.material), MeshMaterial3d(v.material),
// rotation is sus, might be related to the gltf coordinate system Transform::from_xyz(
Transform::from_rotation(Quat::from_rotation_y(f32::consts::PI)) // -dist +
* Transform::from_xyz( match style.text_align_x {
-dist XAlign::Left => 0.0,
+ match style.bounds.as_ref().map(|v| v.anchor_align_x) { XAlign::Center => width * -0.5,
Some(XAlign::Center) => width * -0.5, XAlign::Right => -width,
Some(XAlign::Right) => -width, },
Some(XAlign::Left) => 0.0, match style.text_align_y {
None => 0.0, YAlign::Top => height,
}, YAlign::Center => height * 0.5,
0.0, YAlign::Bottom => 0.0,
0.0, },
) * v.transform, 0.0,
) * v.transform,
)) ))
.id() .id()
}) })
@@ -186,7 +175,7 @@ impl FontDatabaseRegistry {
} }
} }
use super::{TextAspect, TextStyle, model::MaterialRegistry}; use super::{TextAspect, TextStyle, YAlign, model::MaterialRegistry};
static TEXT_REGISTRY: Registry<Text> = Registry::new(); static TEXT_REGISTRY: Registry<Text> = Registry::new();