Rename TextBlock to TextLayout (#15797)

# Objective

- Improve clarity when spawning a text block. See [this
discussion](https://github.com/bevyengine/bevy/pull/15591/#discussion_r1787083571).

## Solution

- Rename `TextBlock` to `TextLayout`.
This commit is contained in:
UkoeHB 2024-10-09 15:58:27 -05:00 committed by GitHub
parent b4071ca370
commit a6be9b4ccd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
27 changed files with 89 additions and 87 deletions

View file

@ -65,7 +65,7 @@ pub use text_access::*;
pub mod prelude { pub mod prelude {
#[doc(hidden)] #[doc(hidden)]
pub use crate::{ pub use crate::{
Font, JustifyText, LineBreak, Text2d, TextBlock, TextError, TextReader2d, TextSpan, Font, JustifyText, LineBreak, Text2d, TextError, TextLayout, TextReader2d, TextSpan,
TextStyle, TextWriter2d, TextStyle, TextWriter2d,
}; };
} }

View file

@ -17,7 +17,7 @@ use cosmic_text::{Attrs, Buffer, Family, Metrics, Shaping, Wrap};
use crate::{ use crate::{
error::TextError, ComputedTextBlock, Font, FontAtlasSets, FontSmoothing, JustifyText, error::TextError, ComputedTextBlock, Font, FontAtlasSets, FontSmoothing, JustifyText,
LineBreak, PositionedGlyph, TextBlock, TextBounds, TextEntity, TextStyle, YAxisOrientation, LineBreak, PositionedGlyph, TextBounds, TextEntity, TextLayout, TextStyle, YAxisOrientation,
}; };
/// A wrapper resource around a [`cosmic_text::FontSystem`] /// A wrapper resource around a [`cosmic_text::FontSystem`]
@ -203,7 +203,7 @@ impl TextPipeline {
fonts: &Assets<Font>, fonts: &Assets<Font>,
text_spans: impl Iterator<Item = (Entity, usize, &'a str, &'a TextStyle)>, text_spans: impl Iterator<Item = (Entity, usize, &'a str, &'a TextStyle)>,
scale_factor: f64, scale_factor: f64,
block: &TextBlock, layout: &TextLayout,
bounds: TextBounds, bounds: TextBounds,
font_atlas_sets: &mut FontAtlasSets, font_atlas_sets: &mut FontAtlasSets,
texture_atlases: &mut Assets<TextureAtlasLayout>, texture_atlases: &mut Assets<TextureAtlasLayout>,
@ -229,8 +229,8 @@ impl TextPipeline {
let update_result = self.update_buffer( let update_result = self.update_buffer(
fonts, fonts,
text_spans, text_spans,
block.linebreak, layout.linebreak,
block.justify, layout.justify,
bounds, bounds,
scale_factor, scale_factor,
computed, computed,
@ -337,7 +337,7 @@ impl TextPipeline {
fonts: &Assets<Font>, fonts: &Assets<Font>,
text_spans: impl Iterator<Item = (Entity, usize, &'a str, &'a TextStyle)>, text_spans: impl Iterator<Item = (Entity, usize, &'a str, &'a TextStyle)>,
scale_factor: f64, scale_factor: f64,
block: &TextBlock, layout: &TextLayout,
computed: &mut ComputedTextBlock, computed: &mut ComputedTextBlock,
font_system: &mut CosmicFontSystem, font_system: &mut CosmicFontSystem,
) -> Result<TextMeasureInfo, TextError> { ) -> Result<TextMeasureInfo, TextError> {
@ -350,8 +350,8 @@ impl TextPipeline {
self.update_buffer( self.update_buffer(
fonts, fonts,
text_spans, text_spans,
block.linebreak, layout.linebreak,
block.justify, layout.justify,
MIN_WIDTH_CONTENT_BOUNDS, MIN_WIDTH_CONTENT_BOUNDS,
scale_factor, scale_factor,
computed, computed,
@ -386,7 +386,7 @@ impl TextPipeline {
/// Render information for a corresponding text block. /// Render information for a corresponding text block.
/// ///
/// Contains scaled glyphs and their size. Generated via [`TextPipeline::queue_text`] when an entity has /// Contains scaled glyphs and their size. Generated via [`TextPipeline::queue_text`] when an entity has
/// [`TextBlock`] and [`ComputedTextBlock`] components. /// [`TextLayout`] and [`ComputedTextBlock`] components.
#[derive(Component, Clone, Default, Debug, Reflect)] #[derive(Component, Clone, Default, Debug, Reflect)]
#[reflect(Component, Default, Debug)] #[reflect(Component, Default, Debug)]
pub struct TextLayoutInfo { pub struct TextLayoutInfo {

View file

@ -25,18 +25,20 @@ impl Default for CosmicBuffer {
} }
} }
/// A sub-entity of a [`TextBlock`]. /// A sub-entity of a [`ComputedTextBlock`].
/// ///
/// Returned by [`ComputedTextBlock::entities`]. /// Returned by [`ComputedTextBlock::entities`].
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
pub struct TextEntity { pub struct TextEntity {
/// The entity. /// The entity.
pub entity: Entity, pub entity: Entity,
/// Records the hierarchy depth of the entity within a `TextBlock`. /// Records the hierarchy depth of the entity within a `TextLayout`.
pub depth: usize, pub depth: usize,
} }
/// Computed information for a [`TextBlock`]. /// Computed information for a text block.
///
/// See [`TextLayout`].
/// ///
/// Automatically updated by 2d and UI text systems. /// Automatically updated by 2d and UI text systems.
#[derive(Component, Debug, Clone)] #[derive(Component, Debug, Clone)]
@ -45,7 +47,7 @@ pub struct ComputedTextBlock {
/// ///
/// This is private because buffer contents are always refreshed from ECS state when writing glyphs to /// This is private because buffer contents are always refreshed from ECS state when writing glyphs to
/// `TextLayoutInfo`. If you want to control the buffer contents manually or use the `cosmic-text` /// `TextLayoutInfo`. If you want to control the buffer contents manually or use the `cosmic-text`
/// editor, then you need to not use `TextBlock` and instead manually implement the conversion to /// editor, then you need to not use `TextLayout` and instead manually implement the conversion to
/// `TextLayoutInfo`. /// `TextLayoutInfo`.
pub(crate) buffer: CosmicBuffer, pub(crate) buffer: CosmicBuffer,
/// Entities for all text spans in the block, including the root-level text. /// Entities for all text spans in the block, including the root-level text.
@ -55,12 +57,12 @@ pub struct ComputedTextBlock {
/// Flag set when any change has been made to this block that should cause it to be rerendered. /// Flag set when any change has been made to this block that should cause it to be rerendered.
/// ///
/// Includes: /// Includes:
/// - [`TextBlock`] changes. /// - [`TextLayout`] changes.
/// - [`TextStyle`] or `Text2d`/`Text`/`TextSpan` changes anywhere in the block's entity hierarchy. /// - [`TextStyle`] or `Text2d`/`Text`/`TextSpan` changes anywhere in the block's entity hierarchy.
// TODO: This encompasses both structural changes like font size or justification and non-structural // TODO: This encompasses both structural changes like font size or justification and non-structural
// changes like text color and font smoothing. This field currently causes UI to 'remeasure' text, even if // changes like text color and font smoothing. This field currently causes UI to 'remeasure' text, even if
// the actual changes are non-structural and can be handled by only rerendering and not remeasuring. A full // the actual changes are non-structural and can be handled by only rerendering and not remeasuring. A full
// solution would probably require splitting TextBlock and TextStyle into structural/non-structural // solution would probably require splitting TextLayout and TextStyle into structural/non-structural
// components for more granular change detection. A cost/benefit analysis is needed. // components for more granular change detection. A cost/benefit analysis is needed.
pub(crate) needs_rerender: bool, pub(crate) needs_rerender: bool,
} }
@ -103,7 +105,7 @@ impl Default for ComputedTextBlock {
#[derive(Component, Debug, Copy, Clone, Default, Reflect)] #[derive(Component, Debug, Copy, Clone, Default, Reflect)]
#[reflect(Component, Default, Debug)] #[reflect(Component, Default, Debug)]
#[require(ComputedTextBlock, TextLayoutInfo)] #[require(ComputedTextBlock, TextLayoutInfo)]
pub struct TextBlock { pub struct TextLayout {
/// The text's internal alignment. /// The text's internal alignment.
/// Should not affect its position within a container. /// Should not affect its position within a container.
pub justify: JustifyText, pub justify: JustifyText,
@ -111,41 +113,41 @@ pub struct TextBlock {
pub linebreak: LineBreak, pub linebreak: LineBreak,
} }
impl TextBlock { impl TextLayout {
/// Makes a new [`TextBlock`]. /// Makes a new [`TextLayout`].
pub const fn new(justify: JustifyText, linebreak: LineBreak) -> Self { pub const fn new(justify: JustifyText, linebreak: LineBreak) -> Self {
Self { justify, linebreak } Self { justify, linebreak }
} }
/// Makes a new [`TextBlock`] with the specified [`JustifyText`]. /// Makes a new [`TextLayout`] with the specified [`JustifyText`].
pub fn new_with_justify(justify: JustifyText) -> Self { pub fn new_with_justify(justify: JustifyText) -> Self {
Self::default().with_justify(justify) Self::default().with_justify(justify)
} }
/// Makes a new [`TextBlock`] with the specified [`LineBreak`]. /// Makes a new [`TextLayout`] with the specified [`LineBreak`].
pub fn new_with_linebreak(linebreak: LineBreak) -> Self { pub fn new_with_linebreak(linebreak: LineBreak) -> Self {
Self::default().with_linebreak(linebreak) Self::default().with_linebreak(linebreak)
} }
/// Makes a new [`TextBlock`] with soft wrapping disabled. /// Makes a new [`TextLayout`] with soft wrapping disabled.
/// Hard wrapping, where text contains an explicit linebreak such as the escape sequence `\n`, will still occur. /// Hard wrapping, where text contains an explicit linebreak such as the escape sequence `\n`, will still occur.
pub fn new_with_no_wrap() -> Self { pub fn new_with_no_wrap() -> Self {
Self::default().with_no_wrap() Self::default().with_no_wrap()
} }
/// Returns this [`TextBlock`] with the specified [`JustifyText`]. /// Returns this [`TextLayout`] with the specified [`JustifyText`].
pub const fn with_justify(mut self, justify: JustifyText) -> Self { pub const fn with_justify(mut self, justify: JustifyText) -> Self {
self.justify = justify; self.justify = justify;
self self
} }
/// Returns this [`TextBlock`] with the specified [`LineBreak`]. /// Returns this [`TextLayout`] with the specified [`LineBreak`].
pub const fn with_linebreak(mut self, linebreak: LineBreak) -> Self { pub const fn with_linebreak(mut self, linebreak: LineBreak) -> Self {
self.linebreak = linebreak; self.linebreak = linebreak;
self self
} }
/// Returns this [`TextBlock`] with soft wrapping disabled. /// Returns this [`TextLayout`] with soft wrapping disabled.
/// Hard wrapping, where text contains an explicit linebreak such as the escape sequence `\n`, will still occur. /// Hard wrapping, where text contains an explicit linebreak such as the escape sequence `\n`, will still occur.
pub const fn with_no_wrap(mut self) -> Self { pub const fn with_no_wrap(mut self) -> Self {
self.linebreak = LineBreak::NoWrap; self.linebreak = LineBreak::NoWrap;
@ -153,7 +155,7 @@ impl TextBlock {
} }
} }
/// A span of UI text in a tree of spans under an entity with [`TextBlock`], such as `Text` or `Text2d`. /// A span of UI text in a tree of spans under an entity with [`TextLayout`] and `Text` or `Text2d`.
/// ///
/// Spans are collected in hierarchy traversal order into a [`ComputedTextBlock`] for layout. /// Spans are collected in hierarchy traversal order into a [`ComputedTextBlock`] for layout.
/// ///
@ -163,13 +165,13 @@ impl TextBlock {
# use bevy_color::Color; # use bevy_color::Color;
# use bevy_color::palettes::basic::{RED, BLUE}; # use bevy_color::palettes::basic::{RED, BLUE};
# use bevy_ecs::World; # use bevy_ecs::World;
# use bevy_text::{Font, TextBlock, TextStyle, TextSection}; # use bevy_text::{Font, TextLayout, TextStyle, TextSection};
# let font_handle: Handle<Font> = Default::default(); # let font_handle: Handle<Font> = Default::default();
# let mut world = World::default(); # let mut world = World::default();
# #
world.spawn(( world.spawn((
TextBlock::default(), TextLayout::default(),
TextStyle { TextStyle {
font: font_handle.clone().into(), font: font_handle.clone().into(),
font_size: 60.0, font_size: 60.0,
@ -257,7 +259,7 @@ impl From<JustifyText> for cosmic_text::Align {
} }
} }
/// `TextStyle` determines the style of a text span within a [`TextBlock`], specifically /// `TextStyle` determines the style of a text span within a [`ComputedTextBlock`], specifically
/// the font face, the font size, and the color. /// the font face, the font size, and the color.
#[derive(Component, Clone, Debug, Reflect)] #[derive(Component, Clone, Debug, Reflect)]
#[reflect(Component, Default, Debug)] #[reflect(Component, Default, Debug)]
@ -285,7 +287,7 @@ pub struct TextStyle {
} }
impl TextStyle { impl TextStyle {
/// Returns this [`TextBlock`] with the specified [`FontSmoothing`]. /// Returns this [`TextStyle`] with the specified [`FontSmoothing`].
pub const fn with_font_smoothing(mut self, font_smoothing: FontSmoothing) -> Self { pub const fn with_font_smoothing(mut self, font_smoothing: FontSmoothing) -> Self {
self.font_smoothing = font_smoothing; self.font_smoothing = font_smoothing;
self self
@ -358,23 +360,23 @@ pub fn detect_text_needs_rerender<Root: Component>(
Or<( Or<(
Changed<Root>, Changed<Root>,
Changed<TextStyle>, Changed<TextStyle>,
Changed<TextBlock>, Changed<TextLayout>,
Changed<Children>, Changed<Children>,
)>, )>,
With<Root>, With<Root>,
With<TextStyle>, With<TextStyle>,
With<TextBlock>, With<TextLayout>,
), ),
>, >,
changed_spans: Query< changed_spans: Query<
(Entity, Option<&Parent>, Has<TextBlock>), (Entity, Option<&Parent>, Has<TextLayout>),
( (
Or<( Or<(
Changed<TextSpan>, Changed<TextSpan>,
Changed<TextStyle>, Changed<TextStyle>,
Changed<Children>, Changed<Children>,
Changed<Parent>, // Included to detect broken text block hierarchies. Changed<Parent>, // Included to detect broken text block hierarchies.
Added<TextBlock>, Added<TextLayout>,
)>, )>,
With<TextSpan>, With<TextSpan>,
With<TextStyle>, With<TextStyle>,
@ -389,7 +391,7 @@ pub fn detect_text_needs_rerender<Root: Component>(
// Root entity: // Root entity:
// - Root component changed. // - Root component changed.
// - TextStyle on root changed. // - TextStyle on root changed.
// - TextBlock changed. // - TextLayout changed.
// - Root children changed (can include additions and removals). // - Root children changed (can include additions and removals).
for root in changed_roots.iter() { for root in changed_roots.iter() {
let Ok((_, Some(mut computed), _)) = computed.get_mut(root) else { let Ok((_, Some(mut computed), _)) = computed.get_mut(root) else {
@ -406,7 +408,7 @@ pub fn detect_text_needs_rerender<Root: Component>(
// - Span children changed (can include additions and removals). // - Span children changed (can include additions and removals).
for (entity, maybe_span_parent, has_text_block) in changed_spans.iter() { for (entity, maybe_span_parent, has_text_block) in changed_spans.iter() {
if has_text_block { if has_text_block {
warn_once!("found entity {:?} with a TextSpan that has a TextBlock, which should only be on root \ warn_once!("found entity {:?} with a TextSpan that has a TextLayout, which should only be on root \
text entities (that have {}); this warning only prints once", text entities (that have {}); this warning only prints once",
entity, core::any::type_name::<Root>()); entity, core::any::type_name::<Root>());
} }

View file

@ -1,7 +1,7 @@
use crate::pipeline::CosmicFontSystem; use crate::pipeline::CosmicFontSystem;
use crate::{ use crate::{
ComputedTextBlock, Font, FontAtlasSets, LineBreak, PositionedGlyph, SwashCache, TextBlock, ComputedTextBlock, Font, FontAtlasSets, LineBreak, PositionedGlyph, SwashCache, TextBounds,
TextBounds, TextError, TextLayoutInfo, TextPipeline, TextReader, TextRoot, TextSpanAccess, TextError, TextLayout, TextLayoutInfo, TextPipeline, TextReader, TextRoot, TextSpanAccess,
TextStyle, TextWriter, YAxisOrientation, TextStyle, TextWriter, YAxisOrientation,
}; };
use bevy_asset::Assets; use bevy_asset::Assets;
@ -38,9 +38,9 @@ use bevy_window::{PrimaryWindow, Window, WindowScaleFactorChanged};
/// [Example usage.](https://github.com/bevyengine/bevy/blob/latest/examples/2d/text2d.rs) /// [Example usage.](https://github.com/bevyengine/bevy/blob/latest/examples/2d/text2d.rs)
/// ///
/// The string in this component is the first 'text span' in a hierarchy of text spans that are collected into /// The string in this component is the first 'text span' in a hierarchy of text spans that are collected into
/// a [`TextBlock`]. See [`TextSpan`](crate::TextSpan) for the component used by children of entities with [`Text2d`]. /// a [`ComputedTextBlock`]. See [`TextSpan`](crate::TextSpan) for the component used by children of entities with [`Text2d`].
/// ///
/// With `Text2d` the `justify` field of [`TextBlock`] only affects the internal alignment of a block of text and not its /// With `Text2d` the `justify` field of [`TextLayout`] only affects the internal alignment of a block of text and not its
/// relative position, which is controlled by the [`Anchor`] component. /// relative position, which is controlled by the [`Anchor`] component.
/// This means that for a block of text consisting of only one line that doesn't wrap, the `justify` field will have no effect. /// This means that for a block of text consisting of only one line that doesn't wrap, the `justify` field will have no effect.
/// ///
@ -50,7 +50,7 @@ use bevy_window::{PrimaryWindow, Window, WindowScaleFactorChanged};
# use bevy_color::Color; # use bevy_color::Color;
# use bevy_color::palettes::basic::BLUE; # use bevy_color::palettes::basic::BLUE;
# use bevy_ecs::World; # use bevy_ecs::World;
# use bevy_text::{Font, JustifyText, Text2d, TextBlock, TextStyle}; # use bevy_text::{Font, JustifyText, Text2d, TextLayout, TextStyle};
# #
# let font_handle: Handle<Font> = Default::default(); # let font_handle: Handle<Font> = Default::default();
# let mut world = World::default(); # let mut world = World::default();
@ -71,14 +71,14 @@ world.spawn((
// With text justification. // With text justification.
world.spawn(( world.spawn((
Text2d::new("hello world\nand bevy!"), Text2d::new("hello world\nand bevy!"),
TextBlock::new_with_justify(JustifyText::Center) TextLayout::new_with_justify(JustifyText::Center)
)); ));
``` ```
*/ */
#[derive(Component, Clone, Debug, Default, Deref, DerefMut, Reflect)] #[derive(Component, Clone, Debug, Default, Deref, DerefMut, Reflect)]
#[reflect(Component, Default, Debug)] #[reflect(Component, Default, Debug)]
#[require( #[require(
TextBlock, TextLayout,
TextStyle, TextStyle,
TextBounds, TextBounds,
Anchor, Anchor,
@ -230,7 +230,7 @@ pub fn update_text2d_layout(
mut text_pipeline: ResMut<TextPipeline>, mut text_pipeline: ResMut<TextPipeline>,
mut text_query: Query<( mut text_query: Query<(
Entity, Entity,
Ref<TextBlock>, Ref<TextLayout>,
Ref<TextBounds>, Ref<TextBounds>,
&mut TextLayoutInfo, &mut TextLayoutInfo,
&mut ComputedTextBlock, &mut ComputedTextBlock,

View file

@ -42,7 +42,7 @@ impl TextIterScratch {
} }
} }
/// System parameter for reading text spans in a [`TextBlock`](crate::TextBlock). /// System parameter for reading text spans in a text block.
/// ///
/// `R` is the root text component, and `S` is the text span component on children. /// `R` is the root text component, and `S` is the text span component on children.
#[derive(SystemParam)] #[derive(SystemParam)]
@ -184,7 +184,7 @@ impl<'a, R: TextRoot> Drop for TextSpanIter<'a, R> {
} }
} }
/// System parameter for reading and writing text spans in a [`TextBlock`](crate::TextBlock). /// System parameter for reading and writing text spans in a text block.
/// ///
/// `R` is the root text component, and `S` is the text span component on children. /// `R` is the root text component, and `S` is the text span component on children.
#[derive(SystemParam)] #[derive(SystemParam)]

View file

@ -19,7 +19,7 @@ use bevy_render::{camera::Camera, texture::Image, view::Visibility};
use bevy_sprite::TextureAtlasLayout; use bevy_sprite::TextureAtlasLayout;
use bevy_text::{ use bevy_text::{
scale_value, ComputedTextBlock, CosmicFontSystem, Font, FontAtlasSets, LineBreak, SwashCache, scale_value, ComputedTextBlock, CosmicFontSystem, Font, FontAtlasSets, LineBreak, SwashCache,
TextBlock, TextBounds, TextError, TextLayoutInfo, TextMeasureInfo, TextPipeline, TextReader, TextBounds, TextError, TextLayout, TextLayoutInfo, TextMeasureInfo, TextPipeline, TextReader,
TextRoot, TextSpanAccess, TextStyle, TextWriter, YAxisOrientation, TextRoot, TextSpanAccess, TextStyle, TextWriter, YAxisOrientation,
}; };
use bevy_transform::components::Transform; use bevy_transform::components::Transform;
@ -52,7 +52,7 @@ impl Default for TextNodeFlags {
/// Adding [`Text`] to an entity will pull in required components for setting up a UI text node. /// Adding [`Text`] to an entity will pull in required components for setting up a UI text node.
/// ///
/// The string in this component is the first 'text span' in a hierarchy of text spans that are collected into /// The string in this component is the first 'text span' in a hierarchy of text spans that are collected into
/// a [`TextBlock`]. See [`TextSpan`](bevy_text::TextSpan) for the component used by children of entities with [`Text`]. /// a [`ComputedTextBlock`]. See [`TextSpan`](bevy_text::TextSpan) for the component used by children of entities with [`Text`].
/// ///
/// Note that [`Transform`] on this entity is managed automatically by the UI layout system. /// Note that [`Transform`] on this entity is managed automatically by the UI layout system.
/// ///
@ -62,7 +62,7 @@ impl Default for TextNodeFlags {
# use bevy_color::Color; # use bevy_color::Color;
# use bevy_color::palettes::basic::BLUE; # use bevy_color::palettes::basic::BLUE;
# use bevy_ecs::World; # use bevy_ecs::World;
# use bevy_text::{Font, JustifyText, TextBlock, TextStyle}; # use bevy_text::{Font, JustifyText, TextLayout, TextStyle};
# use bevy_ui::Text; # use bevy_ui::Text;
# #
# let font_handle: Handle<Font> = Default::default(); # let font_handle: Handle<Font> = Default::default();
@ -84,14 +84,14 @@ world.spawn((
// With text justification. // With text justification.
world.spawn(( world.spawn((
Text::new("hello world\nand bevy!"), Text::new("hello world\nand bevy!"),
TextBlock::new_with_justify(JustifyText::Center) TextLayout::new_with_justify(JustifyText::Center)
)); ));
``` ```
*/ */
#[derive(Component, Debug, Default, Clone, Deref, DerefMut, Reflect)] #[derive(Component, Debug, Default, Clone, Deref, DerefMut, Reflect)]
#[reflect(Component, Default, Debug)] #[reflect(Component, Default, Debug)]
#[require( #[require(
TextBlock, TextLayout,
TextStyle, TextStyle,
TextNodeFlags, TextNodeFlags,
Node, Node,
@ -205,7 +205,7 @@ fn create_text_measure<'a>(
fonts: &Assets<Font>, fonts: &Assets<Font>,
scale_factor: f64, scale_factor: f64,
spans: impl Iterator<Item = (Entity, usize, &'a str, &'a TextStyle)>, spans: impl Iterator<Item = (Entity, usize, &'a str, &'a TextStyle)>,
block: Ref<TextBlock>, block: Ref<TextLayout>,
text_pipeline: &mut TextPipeline, text_pipeline: &mut TextPipeline,
mut content_size: Mut<ContentSize>, mut content_size: Mut<ContentSize>,
mut text_flags: Mut<TextNodeFlags>, mut text_flags: Mut<TextNodeFlags>,
@ -263,7 +263,7 @@ pub fn measure_text_system(
mut text_query: Query< mut text_query: Query<
( (
Entity, Entity,
Ref<TextBlock>, Ref<TextLayout>,
&mut ContentSize, &mut ContentSize,
&mut TextNodeFlags, &mut TextNodeFlags,
&mut ComputedTextBlock, &mut ComputedTextBlock,
@ -329,7 +329,7 @@ fn queue_text(
textures: &mut Assets<Image>, textures: &mut Assets<Image>,
scale_factor: f32, scale_factor: f32,
inverse_scale_factor: f32, inverse_scale_factor: f32,
block: &TextBlock, block: &TextLayout,
node: Ref<Node>, node: Ref<Node>,
mut text_flags: Mut<TextNodeFlags>, mut text_flags: Mut<TextNodeFlags>,
text_layout_info: Mut<TextLayoutInfo>, text_layout_info: Mut<TextLayoutInfo>,
@ -408,7 +408,7 @@ pub fn text_system(
mut text_query: Query<( mut text_query: Query<(
Entity, Entity,
Ref<Node>, Ref<Node>,
&TextBlock, &TextLayout,
&mut TextLayoutInfo, &mut TextLayoutInfo,
&mut TextNodeFlags, &mut TextNodeFlags,
&mut ComputedTextBlock, &mut ComputedTextBlock,

View file

@ -88,7 +88,7 @@ fn spawn_sprites(
builder.spawn(( builder.spawn((
Text2d::new(label), Text2d::new(label),
text_style, text_style,
TextBlock::new_with_justify(JustifyText::Center), TextLayout::new_with_justify(JustifyText::Center),
Transform::from_xyz(0., -0.5 * size.y - 10., 0.0), Transform::from_xyz(0., -0.5 * size.y - 10., 0.0),
bevy::sprite::Anchor::TopCenter, bevy::sprite::Anchor::TopCenter,
)); ));

View file

@ -47,21 +47,21 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.spawn(( commands.spawn((
Text2d::new("translation"), Text2d::new("translation"),
text_style.clone(), text_style.clone(),
TextBlock::new_with_justify(text_justification), TextLayout::new_with_justify(text_justification),
AnimateTranslation, AnimateTranslation,
)); ));
// Demonstrate changing rotation // Demonstrate changing rotation
commands.spawn(( commands.spawn((
Text2d::new("rotation"), Text2d::new("rotation"),
text_style.clone(), text_style.clone(),
TextBlock::new_with_justify(text_justification), TextLayout::new_with_justify(text_justification),
AnimateRotation, AnimateRotation,
)); ));
// Demonstrate changing scale // Demonstrate changing scale
commands.spawn(( commands.spawn((
Text2d::new("scale"), Text2d::new("scale"),
text_style, text_style,
TextBlock::new_with_justify(text_justification), TextLayout::new_with_justify(text_justification),
Transform::from_translation(Vec3::new(400.0, 0.0, 0.0)), Transform::from_translation(Vec3::new(400.0, 0.0, 0.0)),
AnimateScale, AnimateScale,
)); ));
@ -82,7 +82,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
builder.spawn(( builder.spawn((
Text2d::new("this text wraps in the box\n(Unicode linebreaks)"), Text2d::new("this text wraps in the box\n(Unicode linebreaks)"),
slightly_smaller_text_style.clone(), slightly_smaller_text_style.clone(),
TextBlock::new(JustifyText::Left, LineBreak::WordBoundary), TextLayout::new(JustifyText::Left, LineBreak::WordBoundary),
// Wrap text in the rectangle // Wrap text in the rectangle
TextBounds::from(box_size), TextBounds::from(box_size),
// ensure the text is drawn on top of the box // ensure the text is drawn on top of the box
@ -101,7 +101,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
builder.spawn(( builder.spawn((
Text2d::new("this text wraps in the box\n(AnyCharacter linebreaks)"), Text2d::new("this text wraps in the box\n(AnyCharacter linebreaks)"),
slightly_smaller_text_style.clone(), slightly_smaller_text_style.clone(),
TextBlock::new(JustifyText::Left, LineBreak::AnyCharacter), TextLayout::new(JustifyText::Left, LineBreak::AnyCharacter),
// Wrap text in the rectangle // Wrap text in the rectangle
TextBounds::from(other_box_size), TextBounds::from(other_box_size),
// ensure the text is drawn on top of the box // ensure the text is drawn on top of the box

View file

@ -280,7 +280,7 @@ fn create_label(
commands.spawn(( commands.spawn((
Text2d::new(text), Text2d::new(text),
text_style, text_style,
TextBlock::new_with_justify(JustifyText::Center), TextLayout::new_with_justify(JustifyText::Center),
Transform { Transform {
translation: Vec3::new(translation.0, translation.1, translation.2), translation: Vec3::new(translation.0, translation.1, translation.2),
..default() ..default()

View file

@ -216,7 +216,7 @@ fn setup(
bottom: Val::ZERO, bottom: Val::ZERO,
..default() ..default()
}, },
TextBlock::default().with_no_wrap(), TextLayout::default().with_no_wrap(),
)); ));
}); });
}; };

View file

@ -177,7 +177,7 @@ fn setup_image_viewer_scene(
color: Color::BLACK, color: Color::BLACK,
..default() ..default()
}, },
TextBlock::new_with_justify(JustifyText::Center), TextLayout::new_with_justify(JustifyText::Center),
Style { Style {
align_self: AlignSelf::Center, align_self: AlignSelf::Center,
margin: UiRect::all(Val::Auto), margin: UiRect::all(Val::Auto),

View file

@ -178,7 +178,7 @@ fn setup(
color: Color::Srgba(Srgba::RED), color: Color::Srgba(Srgba::RED),
..default() ..default()
}, },
TextBlock::new_with_justify(JustifyText::Center), TextLayout::new_with_justify(JustifyText::Center),
)) ))
// Mark as an animation target. // Mark as an animation target.
.insert(AnimationTarget { .insert(AnimationTarget {

View file

@ -277,7 +277,7 @@ fn setup_node_rects(commands: &mut Commands) {
color: ANTIQUE_WHITE.into(), color: ANTIQUE_WHITE.into(),
..default() ..default()
}, },
TextBlock::new_with_justify(JustifyText::Center), TextLayout::new_with_justify(JustifyText::Center),
)) ))
.id(); .id();

View file

@ -341,7 +341,7 @@ fn add_mask_group_control(parent: &mut ChildBuilder, label: &str, width: Val, ma
} else { } else {
selected_button_text_style.clone() selected_button_text_style.clone()
}, },
TextBlock::new_with_justify(JustifyText::Center), TextLayout::new_with_justify(JustifyText::Center),
Style { Style {
flex_grow: 1.0, flex_grow: 1.0,
margin: UiRect::vertical(Val::Px(3.0)), margin: UiRect::vertical(Val::Px(3.0)),

View file

@ -187,7 +187,7 @@ fn setup_ui(mut commands: Commands) {
color: Color::BLACK, color: Color::BLACK,
..Default::default() ..Default::default()
}, },
TextBlock::new_with_justify(JustifyText::Right), TextLayout::new_with_justify(JustifyText::Right),
LoadingText, LoadingText,
)); ));
}); });

View file

@ -60,7 +60,7 @@ fn spawn_text(mut commands: Commands, mut reader: EventReader<StreamEvent>) {
commands.spawn(( commands.spawn((
Text2d::new(event.0.to_string()), Text2d::new(event.0.to_string()),
text_style.clone(), text_style.clone(),
TextBlock::new_with_justify(JustifyText::Center), TextLayout::new_with_justify(JustifyText::Center),
Transform::from_xyz(per_frame as f32 * 100.0, 300.0, 0.0), Transform::from_xyz(per_frame as f32 * 100.0, 300.0, 0.0),
)); ));
} }

View file

@ -94,7 +94,7 @@ fn setup_ui(mut commands: Commands) {
commands commands
.spawn(( .spawn((
Text::default(), Text::default(),
TextBlock::new_with_justify(JustifyText::Center), TextLayout::new_with_justify(JustifyText::Center),
Style { Style {
align_self: AlignSelf::Center, align_self: AlignSelf::Center,
justify_self: JustifySelf::Center, justify_self: JustifySelf::Center,

View file

@ -384,7 +384,7 @@ fn setup_text(mut commands: Commands, cameras: Query<(Entity, &Camera)>) {
p.spawn(( p.spawn((
Text::default(), Text::default(),
HeaderText, HeaderText,
TextBlock::new_with_justify(JustifyText::Center), TextLayout::new_with_justify(JustifyText::Center),
)) ))
.with_children(|p| { .with_children(|p| {
p.spawn(TextSpan::new("Primitive: ")); p.spawn(TextSpan::new("Primitive: "));

View file

@ -127,7 +127,7 @@ fn setup_scene(
color: Color::BLACK, color: Color::BLACK,
..default() ..default()
}, },
TextBlock::new_with_justify(JustifyText::Center), TextLayout::new_with_justify(JustifyText::Center),
)); ));
} }

View file

@ -50,7 +50,7 @@ fn setup(mut commands: Commands) {
font_size: 4., font_size: 4.,
..Default::default() ..Default::default()
}; };
let text_block = TextBlock { let text_block = TextLayout {
justify: JustifyText::Left, justify: JustifyText::Left,
linebreak: LineBreak::AnyCharacter, linebreak: LineBreak::AnyCharacter,
}; };
@ -89,7 +89,7 @@ fn setup(mut commands: Commands) {
)); ));
} }
fn force_text_recomputation(mut text_query: Query<&mut TextBlock>) { fn force_text_recomputation(mut text_query: Query<&mut TextLayout>) {
for mut block in &mut text_query { for mut block in &mut text_query {
block.set_changed(); block.set_changed();
} }

View file

@ -68,7 +68,7 @@ fn spawn(mut commands: Commands, asset_server: Res<AssetServer>) {
commands commands
.spawn(( .spawn((
Text2d::default(), Text2d::default(),
TextBlock { TextLayout {
justify: JustifyText::Center, justify: JustifyText::Center,
linebreak: LineBreak::AnyCharacter, linebreak: LineBreak::AnyCharacter,
}, },

View file

@ -108,7 +108,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>, mut time: ResMu
color: Color::srgb(0.85, 0.85, 0.85), color: Color::srgb(0.85, 0.85, 0.85),
..default() ..default()
}, },
TextBlock::new_with_justify(JustifyText::Center), TextLayout::new_with_justify(JustifyText::Center),
)); ));
// virtual time info // virtual time info
@ -119,7 +119,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>, mut time: ResMu
color: virtual_color, color: virtual_color,
..default() ..default()
}, },
TextBlock::new_with_justify(JustifyText::Right), TextLayout::new_with_justify(JustifyText::Right),
VirtualTime, VirtualTime,
)); ));
}); });

View file

@ -96,7 +96,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
}).with_children(|parent| { }).with_children(|parent| {
parent.spawn((Text::new("Use the panel on the right to change the Display and Visibility properties for the respective nodes of the panel on the left"), parent.spawn((Text::new("Use the panel on the right to change the Display and Visibility properties for the respective nodes of the panel on the left"),
text_style.clone(), text_style.clone(),
TextBlock::new_with_justify(JustifyText::Center), TextLayout::new_with_justify(JustifyText::Center),
Style { Style {
margin: UiRect::bottom(Val::Px(10.)), margin: UiRect::bottom(Val::Px(10.)),
..Default::default() ..Default::default()
@ -154,11 +154,11 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
builder.spawn((Text::new("Display::None\nVisibility::Hidden\nVisibility::Inherited"), builder.spawn((Text::new("Display::None\nVisibility::Hidden\nVisibility::Inherited"),
TextStyle { color: HIDDEN_COLOR, ..text_style.clone() }, TextStyle { color: HIDDEN_COLOR, ..text_style.clone() },
TextBlock::new_with_justify(JustifyText::Center), TextLayout::new_with_justify(JustifyText::Center),
)); ));
builder.spawn((Text::new("-\n-\n-"), builder.spawn((Text::new("-\n-\n-"),
TextStyle { color: DARK_GRAY.into(), ..text_style.clone() }, TextStyle { color: DARK_GRAY.into(), ..text_style.clone() },
TextBlock::new_with_justify(JustifyText::Center), TextLayout::new_with_justify(JustifyText::Center),
)); ));
builder.spawn((Text::new("The UI Node and its descendants will not be visible and will not be allotted any space in the UI layout.\nThe UI Node will not be visible but will still occupy space in the UI layout.\nThe UI node will inherit the visibility property of its parent. If it has no parent it will be visible."), builder.spawn((Text::new("The UI Node and its descendants will not be visible and will not be allotted any space in the UI layout.\nThe UI Node will not be visible but will still occupy space in the UI layout.\nThe UI node will inherit the visibility property of its parent. If it has no parent it will be visible."),
text_style text_style
@ -414,7 +414,7 @@ where
builder.spawn(( builder.spawn((
Text(format!("{}::{:?}", Target::<T>::NAME, T::default())), Text(format!("{}::{:?}", Target::<T>::NAME, T::default())),
text_style, text_style,
TextBlock::new_with_justify(JustifyText::Center), TextLayout::new_with_justify(JustifyText::Center),
)); ));
}); });
} }

View file

@ -279,7 +279,7 @@ fn spawn_button(
}, },
..text_style ..text_style
}, },
TextBlock::new_with_justify(JustifyText::Center), TextLayout::new_with_justify(JustifyText::Center),
)); ));
}); });
} }

View file

@ -39,7 +39,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
..default() ..default()
}, },
// Set the justification of the Text // Set the justification of the Text
TextBlock::new_with_justify(JustifyText::Center), TextLayout::new_with_justify(JustifyText::Center),
// Set the style of the Node itself. // Set the style of the Node itself.
Style { Style {
position_type: PositionType::Absolute, position_type: PositionType::Absolute,

View file

@ -77,7 +77,7 @@ fn infotext_system(mut commands: Commands, asset_server: Res<AssetServer>) {
color: YELLOW.into(), color: YELLOW.into(),
..default() ..default()
}, },
TextBlock::new_with_justify(JustifyText::Right), TextLayout::new_with_justify(JustifyText::Right),
Style { Style {
max_width: Val::Px(300.), max_width: Val::Px(300.),
..default() ..default()
@ -121,7 +121,7 @@ fn infotext_system(mut commands: Commands, asset_server: Res<AssetServer>) {
color: Color::srgb(0.8, 0.2, 0.7), color: Color::srgb(0.8, 0.2, 0.7),
..default() ..default()
}, },
TextBlock::new_with_justify(JustifyText::Center), TextLayout::new_with_justify(JustifyText::Center),
Style { Style {
max_width: Val::Px(400.), max_width: Val::Px(400.),
..default() ..default()
@ -136,7 +136,7 @@ fn infotext_system(mut commands: Commands, asset_server: Res<AssetServer>) {
color: YELLOW.into(), color: YELLOW.into(),
..default() ..default()
}, },
TextBlock::new_with_justify(JustifyText::Left), TextLayout::new_with_justify(JustifyText::Left),
Style { Style {
max_width: Val::Px(300.), max_width: Val::Px(300.),
..default() ..default()
@ -152,7 +152,7 @@ fn infotext_system(mut commands: Commands, asset_server: Res<AssetServer>) {
color: GREEN_YELLOW.into(), color: GREEN_YELLOW.into(),
..default() ..default()
}, },
TextBlock::new_with_justify(JustifyText::Justified), TextLayout::new_with_justify(JustifyText::Justified),
Style { Style {
max_width: Val::Px(300.), max_width: Val::Px(300.),
..default() ..default()

View file

@ -122,7 +122,7 @@ fn spawn(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.entity(column_id).with_child(( commands.entity(column_id).with_child((
Text(message.clone()), Text(message.clone()),
text_style.clone(), text_style.clone(),
TextBlock::new(JustifyText::Left, linebreak), TextLayout::new(JustifyText::Left, linebreak),
BackgroundColor(Color::srgb(0.8 - j as f32 * 0.2, 0., 0.)), BackgroundColor(Color::srgb(0.8 - j as f32 * 0.2, 0., 0.)),
)); ));
} }