diff --git a/crates/bevy_text/src/text2d.rs b/crates/bevy_text/src/text2d.rs index 36448baab7..03dd84d073 100644 --- a/crates/bevy_text/src/text2d.rs +++ b/crates/bevy_text/src/text2d.rs @@ -11,7 +11,6 @@ use bevy_ecs::component::Component; use bevy_ecs::{ change_detection::{DetectChanges, Ref}, entity::Entity, - event::EventReader, prelude::{ReflectComponent, With}, query::{Changed, Without}, system::{Commands, Local, Query, Res, ResMut}, @@ -30,7 +29,7 @@ use bevy_sprite::{Anchor, ExtractedSprite, ExtractedSprites, SpriteSource, Textu use bevy_transform::components::Transform; use bevy_transform::prelude::GlobalTransform; use bevy_utils::HashSet; -use bevy_window::{PrimaryWindow, Window, WindowScaleFactorChanged}; +use bevy_window::{PrimaryWindow, Window}; /// [`Text2dBundle`] was removed in favor of required components. /// The core component is now [`Text2d`] which can contain a single text segment. @@ -235,12 +234,12 @@ pub fn extract_text2d_sprite( /// It does not modify or observe existing ones. #[allow(clippy::too_many_arguments)] pub fn update_text2d_layout( + mut last_scale_factor: Local, // Text items which should be reprocessed again, generally when the font hasn't loaded yet. mut queue: Local>, mut textures: ResMut>, fonts: Res>, windows: Query<&Window, With>, - mut scale_factor_changed: EventReader, mut texture_atlases: ResMut>, mut font_atlas_sets: ResMut, mut text_pipeline: ResMut, @@ -255,9 +254,6 @@ pub fn update_text2d_layout( mut font_system: ResMut, mut swash_cache: ResMut, ) { - // We need to consume the entire iterator, hence `last` - let factor_changed = scale_factor_changed.read().last().is_some(); - // TODO: Support window-independent scaling: https://github.com/bevyengine/bevy/issues/5621 let scale_factor = windows .get_single() @@ -266,6 +262,9 @@ pub fn update_text2d_layout( let inverse_scale_factor = scale_factor.recip(); + let factor_changed = *last_scale_factor != scale_factor; + *last_scale_factor = scale_factor; + for (entity, block, bounds, text_layout_info, mut computed) in &mut text_query { if factor_changed || computed.needs_rerender() @@ -359,7 +358,7 @@ mod tests { use bevy_app::{App, Update}; use bevy_asset::{load_internal_binary_asset, Handle}; - use bevy_ecs::{event::Events, schedule::IntoSystemConfigs}; + use bevy_ecs::schedule::IntoSystemConfigs; use crate::{detect_text_needs_rerender, TextIterScratch}; @@ -374,7 +373,6 @@ mod tests { .init_resource::>() .init_resource::>() .init_resource::() - .init_resource::>() .init_resource::() .init_resource::() .init_resource::()