diff --git a/crates/bevy_ui/src/render/mod.rs b/crates/bevy_ui/src/render/mod.rs index 60dfd1fab65e7..c197637e4b416 100644 --- a/crates/bevy_ui/src/render/mod.rs +++ b/crates/bevy_ui/src/render/mod.rs @@ -21,7 +21,6 @@ use crate::{ use bevy_app::prelude::*; use bevy_asset::{load_internal_asset, AssetEvent, AssetId, Assets, Handle}; use bevy_ecs::prelude::*; -use bevy_math::Vec3Swizzles; use bevy_math::{Mat4, Rect, URect, UVec4, Vec2, Vec3, Vec4Swizzles}; use bevy_render::{ camera::Camera, @@ -636,19 +635,18 @@ pub fn extract_text_uinodes( continue; } - let mut affine = global_transform.affine(); - // Align the text to the nearest physical pixel: // * Translate by minus the text node's half-size // (The transform translates to the center of the node but the text coordinates are relative to the node's top left corner) // * Multiply the logical coordinates by the scale factor to get its position in physical coordinates // * Round the physical position to the nearest physical pixel // * Multiply by the rounded physical position by the inverse scale factor to return to logical coordinates - let logical_top_left = affine.translation.xy() - 0.5 * uinode.size(); + + let logical_top_left = -0.5 * uinode.size(); let physical_nearest_pixel = (logical_top_left * scale_factor).round(); let logical_top_left_nearest_pixel = physical_nearest_pixel * inverse_scale_factor; - affine.translation = logical_top_left_nearest_pixel.extend(0.).into(); - let transform = Mat4::from(affine); + let transform = Mat4::from(global_transform.affine()) + * Mat4::from_translation(logical_top_left_nearest_pixel.extend(0.)); let mut color = Color::WHITE; let mut current_section = usize::MAX;