Text
Text
- String
Description
The top-level UI text component.
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 [
ComputedTextBlock
]. SeeTextSpan
for the component used by children of entities with [Text
].Note that
Transform
on this entity is managed automatically by the UI layout system.# use bevy_asset::Handle; # use bevy_color::Color; # use bevy_color::palettes::basic::BLUE; # use bevy_ecs::world::World; # use bevy_text::{Font, JustifyText, TextLayout, TextFont, TextColor}; # use bevy_ui::prelude::Text; # # let font_handle: Handle<Font> = Default::default(); # let mut world = World::default(); # // Basic usage. world.spawn(Text::new("hello world!")); // With non-default style. world.spawn(( Text::new("hello world!"), TextFont { font: font_handle.clone().into(), font_size: 60.0, ..Default::default() }, TextColor(BLUE.into()), )); // With text justification. world.spawn(( Text::new("hello world\nand bevy!"), TextLayout::new_with_justify(JustifyText::Center) ));