Skip to content

Commit

Permalink
Fix size of clipped text glyphs. (#8197)
Browse files Browse the repository at this point in the history
# Objective

Text glyphs that were clipped were not sized correctly because the
transform extracted from the `extract_text_uinodes` had a scaling on it
that wasn't accounted for.

fixes #8167

## Solution

Remove the scaling from the transform and multiply the size of the
glyphs by the inverse of the scale factor.
  • Loading branch information
ickshonpe authored Apr 5, 2023
1 parent ff9f223 commit 1a7f046
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions crates/bevy_ui/src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ pub fn extract_text_uinodes(
.map(|window| window.resolution.scale_factor() as f32)
.unwrap_or(1.0);

let scaling = Mat4::from_scale(Vec3::splat(scale_factor.recip()));
let inverse_scale_factor = scale_factor.recip();

for (stack_index, entity) in ui_stack.uinodes.iter().enumerate() {
if let Ok((uinode, global_transform, text, text_layout_info, visibility, clip)) =
Expand All @@ -306,10 +306,8 @@ pub fn extract_text_uinodes(
if !visibility.is_visible() || uinode.size().x == 0. || uinode.size().y == 0. {
continue;
}

let transform = global_transform.compute_matrix()
* Mat4::from_translation(-0.5 * uinode.size().extend(0.))
* scaling;
* Mat4::from_translation(-0.5 * uinode.size().extend(0.));

let mut color = Color::WHITE;
let mut current_section = usize::MAX;
Expand All @@ -326,13 +324,17 @@ pub fn extract_text_uinodes(
}
let atlas = texture_atlases.get(&atlas_info.texture_atlas).unwrap();

let mut rect = atlas.textures[atlas_info.glyph_index];
rect.min *= inverse_scale_factor;
rect.max *= inverse_scale_factor;
extracted_uinodes.uinodes.push(ExtractedUiNode {
stack_index,
transform: transform * Mat4::from_translation(position.extend(0.)),
transform: transform
* Mat4::from_translation(position.extend(0.) * inverse_scale_factor),
color,
rect: atlas.textures[atlas_info.glyph_index],
rect,
image: atlas.texture.clone_weak(),
atlas_size: Some(atlas.size),
atlas_size: Some(atlas.size * inverse_scale_factor),
clip: clip.map(|clip| clip.clip),
flip_x: false,
flip_y: false,
Expand Down

0 comments on commit 1a7f046

Please sign in to comment.