use crate::{CalculatedSize, Style, Val}; use bevy_asset::Assets; use bevy_ecs::{ entity::Entity, query::{Changed, Or, With}, system::{Local, ParamSet, Query, Res, ResMut}, }; use bevy_math::Size; use bevy_render::texture::Image; use bevy_sprite::TextureAtlas; use bevy_text::{DefaultTextPipeline, Font, FontAtlasSet, Text, TextError}; use bevy_window::{WindowId, 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) => scale_value(size, scale_factor), (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, clippy::type_complexity)] pub fn text_system( mut queued_text: Local, mut last_scale_factor: Local, mut textures: ResMut>, fonts: Res>, windows: Res, mut texture_atlases: ResMut>, mut font_atlas_set_storage: ResMut>, mut text_pipeline: ResMut, mut text_queries: ParamSet<( Query, Changed