Skip to content
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

Fix size of clipped text glyphs. #8197

Merged
merged 2 commits into from
Apr 5, 2023
Merged
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
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