use crate::{CalculatedSize, Size, Style, UiScale, Val}; use bevy_asset::Assets; use bevy_ecs::{ entity::Entity, query::{Changed, Or, With}, system::{Commands, Local, ParamSet, Query, Res, ResMut}, }; use bevy_math::Vec2; use bevy_render::texture::Image; use bevy_sprite::TextureAtlas; use bevy_text::{ Font, FontAtlasSet, Text, TextError, TextLayoutInfo, TextPipeline, TextSettings, YAxisOrientation, }; use bevy_window::Windows; #[derive(Debug, Default)] pub struct QueuedText { entities: Vec, } fn scale_value(value: f32, factor: f64) -> f32 { (value as f64 * factor) as f32 } /// Defines how `min_size`, `size`, and `max_size` affects the bounds of a text /// block. pub fn text_constraint(min_size: Val, size: Val, max_size: Val, scale_factor: f64) -> f32 { // Needs support for percentages match (min_size, size, max_size) { (_, _, Val::Px(max)) => scale_value(max, scale_factor), (Val::Px(min), _, _) => scale_value(min, scale_factor), (Val::Undefined, Val::Px(size), Val::Undefined) | (Val::Auto, Val::Px(size), Val::Auto) => { scale_value(size, scale_factor) } _ => f32::MAX, } } /// Updates the layout and size information whenever the text or style is changed. /// This information is computed by the `TextPipeline` on insertion, then stored. #[allow(clippy::too_many_arguments)] pub fn text_system( mut commands: Commands, mut queued_text: Local, mut last_scale_factor: Local, mut textures: ResMut>, fonts: Res>, windows: Res, text_settings: Res, ui_scale: Res, mut texture_atlases: ResMut>, mut font_atlas_set_storage: ResMut>, mut text_pipeline: ResMut, mut text_queries: ParamSet<( Query, Changed