From 156463b1525d574e02b4d147b23d272314312cd7 Mon Sep 17 00:00:00 2001 From: ickshonpe Date: Fri, 24 Mar 2023 19:23:55 +0000 Subject: [PATCH 1/2] Text glyphs that were clipped were not sized correctly because the transform extracted from the `extract_text_nodes` had a scaling on it that wasn't accounted for. Fixed this by removing the scaling from the transform and multiplying the size of the glyph's by the scale factor. --- crates/bevy_ui/src/render/mod.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/crates/bevy_ui/src/render/mod.rs b/crates/bevy_ui/src/render/mod.rs index 146b358da0f1d..7cf7b495e1529 100644 --- a/crates/bevy_ui/src/render/mod.rs +++ b/crates/bevy_ui/src/render/mod.rs @@ -296,7 +296,8 @@ 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)) = @@ -306,10 +307,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; @@ -326,13 +325,16 @@ 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, From a8e48351c50167289e450fc45bbfa0e92db2267a Mon Sep 17 00:00:00 2001 From: ickshonpe Date: Fri, 24 Mar 2023 19:32:11 +0000 Subject: [PATCH 2/2] cargo fmt --- crates/bevy_ui/src/render/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/bevy_ui/src/render/mod.rs b/crates/bevy_ui/src/render/mod.rs index 7cf7b495e1529..947411c47d37e 100644 --- a/crates/bevy_ui/src/render/mod.rs +++ b/crates/bevy_ui/src/render/mod.rs @@ -296,8 +296,7 @@ pub fn extract_text_uinodes( .map(|window| window.resolution.scale_factor() as f32) .unwrap_or(1.0); - let inverse_scale_factor = 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)) = @@ -330,7 +329,8 @@ pub fn extract_text_uinodes( rect.max *= inverse_scale_factor; extracted_uinodes.uinodes.push(ExtractedUiNode { stack_index, - transform: transform * Mat4::from_translation(position.extend(0.) * inverse_scale_factor), + transform: transform + * Mat4::from_translation(position.extend(0.) * inverse_scale_factor), color, rect, image: atlas.texture.clone_weak(),