mirror of
https://github.com/bevyengine/bevy
synced 2024-11-14 00:47:32 +00:00
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:
parent
b4071ca370
commit
a6be9b4ccd
27 changed files with 89 additions and 87 deletions
|
@ -65,7 +65,7 @@ pub use text_access::*;
|
|||
pub mod prelude {
|
||||
#[doc(hidden)]
|
||||
pub use crate::{
|
||||
Font, JustifyText, LineBreak, Text2d, TextBlock, TextError, TextReader2d, TextSpan,
|
||||
Font, JustifyText, LineBreak, Text2d, TextError, TextLayout, TextReader2d, TextSpan,
|
||||
TextStyle, TextWriter2d,
|
||||
};
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ use cosmic_text::{Attrs, Buffer, Family, Metrics, Shaping, Wrap};
|
|||
|
||||
use crate::{
|
||||
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`]
|
||||
|
@ -203,7 +203,7 @@ impl TextPipeline {
|
|||
fonts: &Assets<Font>,
|
||||
text_spans: impl Iterator<Item = (Entity, usize, &'a str, &'a TextStyle)>,
|
||||
scale_factor: f64,
|
||||
block: &TextBlock,
|
||||
layout: &TextLayout,
|
||||
bounds: TextBounds,
|
||||
font_atlas_sets: &mut FontAtlasSets,
|
||||
texture_atlases: &mut Assets<TextureAtlasLayout>,
|
||||
|
@ -229,8 +229,8 @@ impl TextPipeline {
|
|||
let update_result = self.update_buffer(
|
||||
fonts,
|
||||
text_spans,
|
||||
block.linebreak,
|
||||
block.justify,
|
||||
layout.linebreak,
|
||||
layout.justify,
|
||||
bounds,
|
||||
scale_factor,
|
||||
computed,
|
||||
|
@ -337,7 +337,7 @@ impl TextPipeline {
|
|||
fonts: &Assets<Font>,
|
||||
text_spans: impl Iterator<Item = (Entity, usize, &'a str, &'a TextStyle)>,
|
||||
scale_factor: f64,
|
||||
block: &TextBlock,
|
||||
layout: &TextLayout,
|
||||
computed: &mut ComputedTextBlock,
|
||||
font_system: &mut CosmicFontSystem,
|
||||
) -> Result<TextMeasureInfo, TextError> {
|
||||
|
@ -350,8 +350,8 @@ impl TextPipeline {
|
|||
self.update_buffer(
|
||||
fonts,
|
||||
text_spans,
|
||||
block.linebreak,
|
||||
block.justify,
|
||||
layout.linebreak,
|
||||
layout.justify,
|
||||
MIN_WIDTH_CONTENT_BOUNDS,
|
||||
scale_factor,
|
||||
computed,
|
||||
|
@ -386,7 +386,7 @@ impl TextPipeline {
|
|||
/// Render information for a corresponding text block.
|
||||
///
|
||||
/// 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)]
|
||||
#[reflect(Component, Default, Debug)]
|
||||
pub struct TextLayoutInfo {
|
||||
|
|
|
@ -25,18 +25,20 @@ impl Default for CosmicBuffer {
|
|||
}
|
||||
}
|
||||
|
||||
/// A sub-entity of a [`TextBlock`].
|
||||
/// A sub-entity of a [`ComputedTextBlock`].
|
||||
///
|
||||
/// Returned by [`ComputedTextBlock::entities`].
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct TextEntity {
|
||||
/// The 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,
|
||||
}
|
||||
|
||||
/// Computed information for a [`TextBlock`].
|
||||
/// Computed information for a text block.
|
||||
///
|
||||
/// See [`TextLayout`].
|
||||
///
|
||||
/// Automatically updated by 2d and UI text systems.
|
||||
#[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
|
||||
/// `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`.
|
||||
pub(crate) buffer: CosmicBuffer,
|
||||
/// 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.
|
||||
///
|
||||
/// Includes:
|
||||
/// - [`TextBlock`] changes.
|
||||
/// - [`TextLayout`] changes.
|
||||
/// - [`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
|
||||
// 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
|
||||
// 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.
|
||||
pub(crate) needs_rerender: bool,
|
||||
}
|
||||
|
@ -103,7 +105,7 @@ impl Default for ComputedTextBlock {
|
|||
#[derive(Component, Debug, Copy, Clone, Default, Reflect)]
|
||||
#[reflect(Component, Default, Debug)]
|
||||
#[require(ComputedTextBlock, TextLayoutInfo)]
|
||||
pub struct TextBlock {
|
||||
pub struct TextLayout {
|
||||
/// The text's internal alignment.
|
||||
/// Should not affect its position within a container.
|
||||
pub justify: JustifyText,
|
||||
|
@ -111,41 +113,41 @@ pub struct TextBlock {
|
|||
pub linebreak: LineBreak,
|
||||
}
|
||||
|
||||
impl TextBlock {
|
||||
/// Makes a new [`TextBlock`].
|
||||
impl TextLayout {
|
||||
/// Makes a new [`TextLayout`].
|
||||
pub const fn new(justify: JustifyText, linebreak: LineBreak) -> Self {
|
||||
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 {
|
||||
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 {
|
||||
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.
|
||||
pub fn new_with_no_wrap() -> Self {
|
||||
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 {
|
||||
self.justify = justify;
|
||||
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 {
|
||||
self.linebreak = linebreak;
|
||||
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.
|
||||
pub const fn with_no_wrap(mut self) -> Self {
|
||||
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.
|
||||
///
|
||||
|
@ -163,13 +165,13 @@ impl TextBlock {
|
|||
# use bevy_color::Color;
|
||||
# use bevy_color::palettes::basic::{RED, BLUE};
|
||||
# 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 mut world = World::default();
|
||||
#
|
||||
world.spawn((
|
||||
TextBlock::default(),
|
||||
TextLayout::default(),
|
||||
TextStyle {
|
||||
font: font_handle.clone().into(),
|
||||
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.
|
||||
#[derive(Component, Clone, Debug, Reflect)]
|
||||
#[reflect(Component, Default, Debug)]
|
||||
|
@ -285,7 +287,7 @@ pub struct 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 {
|
||||
self.font_smoothing = font_smoothing;
|
||||
self
|
||||
|
@ -358,23 +360,23 @@ pub fn detect_text_needs_rerender<Root: Component>(
|
|||
Or<(
|
||||
Changed<Root>,
|
||||
Changed<TextStyle>,
|
||||
Changed<TextBlock>,
|
||||
Changed<TextLayout>,
|
||||
Changed<Children>,
|
||||
)>,
|
||||
With<Root>,
|
||||
With<TextStyle>,
|
||||
With<TextBlock>,
|
||||
With<TextLayout>,
|
||||
),
|
||||
>,
|
||||
changed_spans: Query<
|
||||
(Entity, Option<&Parent>, Has<TextBlock>),
|
||||
(Entity, Option<&Parent>, Has<TextLayout>),
|
||||
(
|
||||
Or<(
|
||||
Changed<TextSpan>,
|
||||
Changed<TextStyle>,
|
||||
Changed<Children>,
|
||||
Changed<Parent>, // Included to detect broken text block hierarchies.
|
||||
Added<TextBlock>,
|
||||
Added<TextLayout>,
|
||||
)>,
|
||||
With<TextSpan>,
|
||||
With<TextStyle>,
|
||||
|
@ -389,7 +391,7 @@ pub fn detect_text_needs_rerender<Root: Component>(
|
|||
// Root entity:
|
||||
// - Root component changed.
|
||||
// - TextStyle on root changed.
|
||||
// - TextBlock changed.
|
||||
// - TextLayout changed.
|
||||
// - Root children changed (can include additions and removals).
|
||||
for root in changed_roots.iter() {
|
||||
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).
|
||||
for (entity, maybe_span_parent, has_text_block) in changed_spans.iter() {
|
||||
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",
|
||||
entity, core::any::type_name::<Root>());
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::pipeline::CosmicFontSystem;
|
||||
use crate::{
|
||||
ComputedTextBlock, Font, FontAtlasSets, LineBreak, PositionedGlyph, SwashCache, TextBlock,
|
||||
TextBounds, TextError, TextLayoutInfo, TextPipeline, TextReader, TextRoot, TextSpanAccess,
|
||||
ComputedTextBlock, Font, FontAtlasSets, LineBreak, PositionedGlyph, SwashCache, TextBounds,
|
||||
TextError, TextLayout, TextLayoutInfo, TextPipeline, TextReader, TextRoot, TextSpanAccess,
|
||||
TextStyle, TextWriter, YAxisOrientation,
|
||||
};
|
||||
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)
|
||||
///
|
||||
/// 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.
|
||||
/// 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::palettes::basic::BLUE;
|
||||
# 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 mut world = World::default();
|
||||
|
@ -71,14 +71,14 @@ world.spawn((
|
|||
// With text justification.
|
||||
world.spawn((
|
||||
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)]
|
||||
#[reflect(Component, Default, Debug)]
|
||||
#[require(
|
||||
TextBlock,
|
||||
TextLayout,
|
||||
TextStyle,
|
||||
TextBounds,
|
||||
Anchor,
|
||||
|
@ -230,7 +230,7 @@ pub fn update_text2d_layout(
|
|||
mut text_pipeline: ResMut<TextPipeline>,
|
||||
mut text_query: Query<(
|
||||
Entity,
|
||||
Ref<TextBlock>,
|
||||
Ref<TextLayout>,
|
||||
Ref<TextBounds>,
|
||||
&mut TextLayoutInfo,
|
||||
&mut ComputedTextBlock,
|
||||
|
|
|
@ -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.
|
||||
#[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.
|
||||
#[derive(SystemParam)]
|
||||
|
|
|
@ -19,7 +19,7 @@ use bevy_render::{camera::Camera, texture::Image, view::Visibility};
|
|||
use bevy_sprite::TextureAtlasLayout;
|
||||
use bevy_text::{
|
||||
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,
|
||||
};
|
||||
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.
|
||||
///
|
||||
/// 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.
|
||||
///
|
||||
|
@ -62,7 +62,7 @@ impl Default for TextNodeFlags {
|
|||
# use bevy_color::Color;
|
||||
# use bevy_color::palettes::basic::BLUE;
|
||||
# use bevy_ecs::World;
|
||||
# use bevy_text::{Font, JustifyText, TextBlock, TextStyle};
|
||||
# use bevy_text::{Font, JustifyText, TextLayout, TextStyle};
|
||||
# use bevy_ui::Text;
|
||||
#
|
||||
# let font_handle: Handle<Font> = Default::default();
|
||||
|
@ -84,14 +84,14 @@ world.spawn((
|
|||
// With text justification.
|
||||
world.spawn((
|
||||
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)]
|
||||
#[reflect(Component, Default, Debug)]
|
||||
#[require(
|
||||
TextBlock,
|
||||
TextLayout,
|
||||
TextStyle,
|
||||
TextNodeFlags,
|
||||
Node,
|
||||
|
@ -205,7 +205,7 @@ fn create_text_measure<'a>(
|
|||
fonts: &Assets<Font>,
|
||||
scale_factor: f64,
|
||||
spans: impl Iterator<Item = (Entity, usize, &'a str, &'a TextStyle)>,
|
||||
block: Ref<TextBlock>,
|
||||
block: Ref<TextLayout>,
|
||||
text_pipeline: &mut TextPipeline,
|
||||
mut content_size: Mut<ContentSize>,
|
||||
mut text_flags: Mut<TextNodeFlags>,
|
||||
|
@ -263,7 +263,7 @@ pub fn measure_text_system(
|
|||
mut text_query: Query<
|
||||
(
|
||||
Entity,
|
||||
Ref<TextBlock>,
|
||||
Ref<TextLayout>,
|
||||
&mut ContentSize,
|
||||
&mut TextNodeFlags,
|
||||
&mut ComputedTextBlock,
|
||||
|
@ -329,7 +329,7 @@ fn queue_text(
|
|||
textures: &mut Assets<Image>,
|
||||
scale_factor: f32,
|
||||
inverse_scale_factor: f32,
|
||||
block: &TextBlock,
|
||||
block: &TextLayout,
|
||||
node: Ref<Node>,
|
||||
mut text_flags: Mut<TextNodeFlags>,
|
||||
text_layout_info: Mut<TextLayoutInfo>,
|
||||
|
@ -408,7 +408,7 @@ pub fn text_system(
|
|||
mut text_query: Query<(
|
||||
Entity,
|
||||
Ref<Node>,
|
||||
&TextBlock,
|
||||
&TextLayout,
|
||||
&mut TextLayoutInfo,
|
||||
&mut TextNodeFlags,
|
||||
&mut ComputedTextBlock,
|
||||
|
|
|
@ -88,7 +88,7 @@ fn spawn_sprites(
|
|||
builder.spawn((
|
||||
Text2d::new(label),
|
||||
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),
|
||||
bevy::sprite::Anchor::TopCenter,
|
||||
));
|
||||
|
|
|
@ -47,21 +47,21 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
|||
commands.spawn((
|
||||
Text2d::new("translation"),
|
||||
text_style.clone(),
|
||||
TextBlock::new_with_justify(text_justification),
|
||||
TextLayout::new_with_justify(text_justification),
|
||||
AnimateTranslation,
|
||||
));
|
||||
// Demonstrate changing rotation
|
||||
commands.spawn((
|
||||
Text2d::new("rotation"),
|
||||
text_style.clone(),
|
||||
TextBlock::new_with_justify(text_justification),
|
||||
TextLayout::new_with_justify(text_justification),
|
||||
AnimateRotation,
|
||||
));
|
||||
// Demonstrate changing scale
|
||||
commands.spawn((
|
||||
Text2d::new("scale"),
|
||||
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)),
|
||||
AnimateScale,
|
||||
));
|
||||
|
@ -82,7 +82,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
|||
builder.spawn((
|
||||
Text2d::new("this text wraps in the box\n(Unicode linebreaks)"),
|
||||
slightly_smaller_text_style.clone(),
|
||||
TextBlock::new(JustifyText::Left, LineBreak::WordBoundary),
|
||||
TextLayout::new(JustifyText::Left, LineBreak::WordBoundary),
|
||||
// Wrap text in the rectangle
|
||||
TextBounds::from(box_size),
|
||||
// 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((
|
||||
Text2d::new("this text wraps in the box\n(AnyCharacter linebreaks)"),
|
||||
slightly_smaller_text_style.clone(),
|
||||
TextBlock::new(JustifyText::Left, LineBreak::AnyCharacter),
|
||||
TextLayout::new(JustifyText::Left, LineBreak::AnyCharacter),
|
||||
// Wrap text in the rectangle
|
||||
TextBounds::from(other_box_size),
|
||||
// ensure the text is drawn on top of the box
|
||||
|
|
|
@ -280,7 +280,7 @@ fn create_label(
|
|||
commands.spawn((
|
||||
Text2d::new(text),
|
||||
text_style,
|
||||
TextBlock::new_with_justify(JustifyText::Center),
|
||||
TextLayout::new_with_justify(JustifyText::Center),
|
||||
Transform {
|
||||
translation: Vec3::new(translation.0, translation.1, translation.2),
|
||||
..default()
|
||||
|
|
|
@ -216,7 +216,7 @@ fn setup(
|
|||
bottom: Val::ZERO,
|
||||
..default()
|
||||
},
|
||||
TextBlock::default().with_no_wrap(),
|
||||
TextLayout::default().with_no_wrap(),
|
||||
));
|
||||
});
|
||||
};
|
||||
|
|
|
@ -177,7 +177,7 @@ fn setup_image_viewer_scene(
|
|||
color: Color::BLACK,
|
||||
..default()
|
||||
},
|
||||
TextBlock::new_with_justify(JustifyText::Center),
|
||||
TextLayout::new_with_justify(JustifyText::Center),
|
||||
Style {
|
||||
align_self: AlignSelf::Center,
|
||||
margin: UiRect::all(Val::Auto),
|
||||
|
|
|
@ -178,7 +178,7 @@ fn setup(
|
|||
color: Color::Srgba(Srgba::RED),
|
||||
..default()
|
||||
},
|
||||
TextBlock::new_with_justify(JustifyText::Center),
|
||||
TextLayout::new_with_justify(JustifyText::Center),
|
||||
))
|
||||
// Mark as an animation target.
|
||||
.insert(AnimationTarget {
|
||||
|
|
|
@ -277,7 +277,7 @@ fn setup_node_rects(commands: &mut Commands) {
|
|||
color: ANTIQUE_WHITE.into(),
|
||||
..default()
|
||||
},
|
||||
TextBlock::new_with_justify(JustifyText::Center),
|
||||
TextLayout::new_with_justify(JustifyText::Center),
|
||||
))
|
||||
.id();
|
||||
|
||||
|
|
|
@ -341,7 +341,7 @@ fn add_mask_group_control(parent: &mut ChildBuilder, label: &str, width: Val, ma
|
|||
} else {
|
||||
selected_button_text_style.clone()
|
||||
},
|
||||
TextBlock::new_with_justify(JustifyText::Center),
|
||||
TextLayout::new_with_justify(JustifyText::Center),
|
||||
Style {
|
||||
flex_grow: 1.0,
|
||||
margin: UiRect::vertical(Val::Px(3.0)),
|
||||
|
|
|
@ -187,7 +187,7 @@ fn setup_ui(mut commands: Commands) {
|
|||
color: Color::BLACK,
|
||||
..Default::default()
|
||||
},
|
||||
TextBlock::new_with_justify(JustifyText::Right),
|
||||
TextLayout::new_with_justify(JustifyText::Right),
|
||||
LoadingText,
|
||||
));
|
||||
});
|
||||
|
|
|
@ -60,7 +60,7 @@ fn spawn_text(mut commands: Commands, mut reader: EventReader<StreamEvent>) {
|
|||
commands.spawn((
|
||||
Text2d::new(event.0.to_string()),
|
||||
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),
|
||||
));
|
||||
}
|
||||
|
|
|
@ -94,7 +94,7 @@ fn setup_ui(mut commands: Commands) {
|
|||
commands
|
||||
.spawn((
|
||||
Text::default(),
|
||||
TextBlock::new_with_justify(JustifyText::Center),
|
||||
TextLayout::new_with_justify(JustifyText::Center),
|
||||
Style {
|
||||
align_self: AlignSelf::Center,
|
||||
justify_self: JustifySelf::Center,
|
||||
|
|
|
@ -384,7 +384,7 @@ fn setup_text(mut commands: Commands, cameras: Query<(Entity, &Camera)>) {
|
|||
p.spawn((
|
||||
Text::default(),
|
||||
HeaderText,
|
||||
TextBlock::new_with_justify(JustifyText::Center),
|
||||
TextLayout::new_with_justify(JustifyText::Center),
|
||||
))
|
||||
.with_children(|p| {
|
||||
p.spawn(TextSpan::new("Primitive: "));
|
||||
|
|
|
@ -127,7 +127,7 @@ fn setup_scene(
|
|||
color: Color::BLACK,
|
||||
..default()
|
||||
},
|
||||
TextBlock::new_with_justify(JustifyText::Center),
|
||||
TextLayout::new_with_justify(JustifyText::Center),
|
||||
));
|
||||
}
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ fn setup(mut commands: Commands) {
|
|||
font_size: 4.,
|
||||
..Default::default()
|
||||
};
|
||||
let text_block = TextBlock {
|
||||
let text_block = TextLayout {
|
||||
justify: JustifyText::Left,
|
||||
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 {
|
||||
block.set_changed();
|
||||
}
|
||||
|
|
|
@ -68,7 +68,7 @@ fn spawn(mut commands: Commands, asset_server: Res<AssetServer>) {
|
|||
commands
|
||||
.spawn((
|
||||
Text2d::default(),
|
||||
TextBlock {
|
||||
TextLayout {
|
||||
justify: JustifyText::Center,
|
||||
linebreak: LineBreak::AnyCharacter,
|
||||
},
|
||||
|
|
|
@ -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),
|
||||
..default()
|
||||
},
|
||||
TextBlock::new_with_justify(JustifyText::Center),
|
||||
TextLayout::new_with_justify(JustifyText::Center),
|
||||
));
|
||||
|
||||
// virtual time info
|
||||
|
@ -119,7 +119,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>, mut time: ResMu
|
|||
color: virtual_color,
|
||||
..default()
|
||||
},
|
||||
TextBlock::new_with_justify(JustifyText::Right),
|
||||
TextLayout::new_with_justify(JustifyText::Right),
|
||||
VirtualTime,
|
||||
));
|
||||
});
|
||||
|
|
|
@ -96,7 +96,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
|||
}).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"),
|
||||
text_style.clone(),
|
||||
TextBlock::new_with_justify(JustifyText::Center),
|
||||
TextLayout::new_with_justify(JustifyText::Center),
|
||||
Style {
|
||||
margin: UiRect::bottom(Val::Px(10.)),
|
||||
..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"),
|
||||
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-"),
|
||||
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."),
|
||||
text_style
|
||||
|
@ -414,7 +414,7 @@ where
|
|||
builder.spawn((
|
||||
Text(format!("{}::{:?}", Target::<T>::NAME, T::default())),
|
||||
text_style,
|
||||
TextBlock::new_with_justify(JustifyText::Center),
|
||||
TextLayout::new_with_justify(JustifyText::Center),
|
||||
));
|
||||
});
|
||||
}
|
||||
|
|
|
@ -279,7 +279,7 @@ fn spawn_button(
|
|||
},
|
||||
..text_style
|
||||
},
|
||||
TextBlock::new_with_justify(JustifyText::Center),
|
||||
TextLayout::new_with_justify(JustifyText::Center),
|
||||
));
|
||||
});
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
|||
..default()
|
||||
},
|
||||
// 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.
|
||||
Style {
|
||||
position_type: PositionType::Absolute,
|
||||
|
|
|
@ -77,7 +77,7 @@ fn infotext_system(mut commands: Commands, asset_server: Res<AssetServer>) {
|
|||
color: YELLOW.into(),
|
||||
..default()
|
||||
},
|
||||
TextBlock::new_with_justify(JustifyText::Right),
|
||||
TextLayout::new_with_justify(JustifyText::Right),
|
||||
Style {
|
||||
max_width: Val::Px(300.),
|
||||
..default()
|
||||
|
@ -121,7 +121,7 @@ fn infotext_system(mut commands: Commands, asset_server: Res<AssetServer>) {
|
|||
color: Color::srgb(0.8, 0.2, 0.7),
|
||||
..default()
|
||||
},
|
||||
TextBlock::new_with_justify(JustifyText::Center),
|
||||
TextLayout::new_with_justify(JustifyText::Center),
|
||||
Style {
|
||||
max_width: Val::Px(400.),
|
||||
..default()
|
||||
|
@ -136,7 +136,7 @@ fn infotext_system(mut commands: Commands, asset_server: Res<AssetServer>) {
|
|||
color: YELLOW.into(),
|
||||
..default()
|
||||
},
|
||||
TextBlock::new_with_justify(JustifyText::Left),
|
||||
TextLayout::new_with_justify(JustifyText::Left),
|
||||
Style {
|
||||
max_width: Val::Px(300.),
|
||||
..default()
|
||||
|
@ -152,7 +152,7 @@ fn infotext_system(mut commands: Commands, asset_server: Res<AssetServer>) {
|
|||
color: GREEN_YELLOW.into(),
|
||||
..default()
|
||||
},
|
||||
TextBlock::new_with_justify(JustifyText::Justified),
|
||||
TextLayout::new_with_justify(JustifyText::Justified),
|
||||
Style {
|
||||
max_width: Val::Px(300.),
|
||||
..default()
|
||||
|
|
|
@ -122,7 +122,7 @@ fn spawn(mut commands: Commands, asset_server: Res<AssetServer>) {
|
|||
commands.entity(column_id).with_child((
|
||||
Text(message.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.)),
|
||||
));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue