use crate::{Node, Style, Val}; use bevy_asset::Assets; use bevy_ecs::{Changed, Entity, Local, Or, Query, QuerySet, Res, ResMut}; use bevy_math::Size; use bevy_render::{ draw::{Draw, DrawContext, Drawable}, mesh::Mesh, prelude::{Msaa, Visible}, renderer::RenderResourceBindings, texture::Texture, }; use bevy_sprite::{TextureAtlas, QUAD_HANDLE}; use bevy_text::{ CalculatedSize, DefaultTextPipeline, DrawableText, Font, FontAtlasSet, Text, TextError, }; use bevy_transform::prelude::GlobalTransform; 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) => scale_value(size, scale_factor), (Val::Auto, Val::Px(size), Val::Auto) => scale_value(size, scale_factor), _ => f32::MAX, } } /// Computes the size of a text block and updates the TextGlyphs with the /// new computed glyphs from the layout #[allow(clippy::too_many_arguments)] pub fn text_system( mut queued_text: 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: QuerySet<( Query, Changed