Skip to content

Object-centered text layout #19559

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/bevy_text/src/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ impl TextPipeline {
let y =
line_y.round() + physical_glyph.y as f32 - top + glyph_size.y as f32 / 2.0;

let position = Vec2::new(x, y);
let position = Vec2::new(x, y) - 0.5 * box_size;

let pos_glyph = PositionedGlyph {
position,
Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_text/src/text2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,9 @@ pub fn extract_text2d_sprite(
text_bounds.height.unwrap_or(text_layout_info.size.y),
);

let top_left = (Anchor::TOP_LEFT.0 - anchor.as_vec()) * size;
let transform =
*global_transform * GlobalTransform::from_translation(top_left.extend(0.)) * scaling;
let transform = *global_transform
* GlobalTransform::from_translation((anchor.as_vec() * size).extend(0.))
* scaling;
let mut color = LinearRgba::WHITE;
let mut current_span = usize::MAX;

Expand Down
7 changes: 2 additions & 5 deletions crates/bevy_ui/src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -847,8 +847,7 @@ pub fn extract_text_sections(
continue;
};

let transform = global_transform.affine()
* bevy_math::Affine3A::from_translation((-0.5 * uinode.size()).extend(0.));
let transform = global_transform.affine();

for (
i,
Expand Down Expand Up @@ -945,9 +944,7 @@ pub fn extract_text_shadows(
};

let transform = global_transform.affine()
* Mat4::from_translation(
(-0.5 * uinode.size() + shadow.offset / uinode.inverse_scale_factor()).extend(0.),
);
* Mat4::from_translation((shadow.offset / uinode.inverse_scale_factor()).extend(0.));

for (
i,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
title: `TextLayoutInfo` now uses object-centered coordinates
pull_requests: [19559]
---

The glyph positions stored in `TextLayoutInfo` are now object-centered.