Struct bevy::ui::node_bundles::TextBundle
pub struct TextBundle {Show 14 fields
pub node: Node,
pub style: Style,
pub text: Text,
pub text_layout_info: TextLayoutInfo,
pub text_flags: TextFlags,
pub calculated_size: ContentSize,
pub focus_policy: FocusPolicy,
pub transform: Transform,
pub global_transform: GlobalTransform,
pub visibility: Visibility,
pub inherited_visibility: InheritedVisibility,
pub view_visibility: ViewVisibility,
pub z_index: ZIndex,
pub background_color: BackgroundColor,
}
bevy_text
only.Expand description
A UI node that is text
The positioning of this node is controlled by the UI layout system. If you need manual control,
use Text2dBundle
.
Fields§
§node: Node
Describes the logical size of the node
style: Style
Styles which control the layout (size and position) of the node and its children In some cases these styles also affect how the node drawn/painted.
text: Text
Contains the text of the node
text_layout_info: TextLayoutInfo
Text layout information
text_flags: TextFlags
Text system flags
calculated_size: ContentSize
The calculated size based on the given image
focus_policy: FocusPolicy
Whether this node should block interaction with lower nodes
transform: Transform
The transform of the node
This component is automatically managed by the UI layout system.
To alter the position of the TextBundle
, use the properties of the Style
component.
global_transform: GlobalTransform
The global transform of the node
This component is automatically updated by the TransformPropagate
systems.
visibility: Visibility
Describes the visibility properties of the node
inherited_visibility: InheritedVisibility
Inherited visibility of an entity.
view_visibility: ViewVisibility
Algorithmically-computed indication of whether an entity is visible and should be extracted for rendering
z_index: ZIndex
Indicates the depth at which the node should appear in the UI
background_color: BackgroundColor
The background color that will fill the containing node
Implementations§
§impl TextBundle
impl TextBundle
pub fn from_section(value: impl Into<String>, style: TextStyle) -> TextBundle
pub fn from_section(value: impl Into<String>, style: TextStyle) -> TextBundle
Create a TextBundle
from a single section.
See Text::from_section
for usage.
Examples found in repository?
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
fn setup(mut commands: Commands) {
warn!(include_str!("warning_string.txt"));
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(3., 1., 5.).looking_at(Vec3::ZERO, Vec3::Y),
..default()
});
commands.spawn(TextBundle::from_section(
"",
TextStyle {
font_size: 30.,
..default()
},
));
}
More examples
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
fn setup_instructions(mut commands: Commands) {
commands.spawn(
TextBundle::from_section(
"",
TextStyle {
font_size: 20.0,
..default()
},
)
.with_style(Style {
position_type: PositionType::Absolute,
top: Val::Px(12.0),
left: Val::Px(12.0),
..default()
}),
);
}
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
fn print_logs(
mut events: EventReader<LogEvent>,
mut commands: Commands,
log_viewer_root: Query<Entity, With<LogViewerRoot>>,
) {
let root_entity = log_viewer_root.single();
commands.entity(root_entity).with_children(|child| {
for event in events.read() {
child.spawn(TextBundle::from_section(
&event.message,
TextStyle::default(),
));
}
});
}
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
fn infotext_system(mut commands: Commands) {
commands.spawn(Camera2dBundle::default());
commands.spawn(
TextBundle::from_section(
"Nothing to see in this window! Check the console output!",
TextStyle {
font_size: 50.0,
..default()
},
)
.with_style(Style {
align_self: AlignSelf::FlexEnd,
..default()
}),
);
}
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
fn spawn_text(
parent: &mut ChildBuilder,
asset_server: &Res<AssetServer>,
update_transform: impl UpdateTransform + Component,
) {
spawn_container(parent, update_transform, |parent| {
parent.spawn(TextBundle::from_section(
"Bevy",
TextStyle {
font: asset_server.load("fonts/FiraSans-Bold.ttf"),
font_size: 120.0,
..default()
},
));
});
}
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
fn setup_instructions(mut commands: Commands) {
commands.spawn(
TextBundle::from_section(
"Press Spacebar to Toggle Atmospheric Fog.\nPress S to Toggle Directional Light Fog Influence.",
TextStyle {
font_size: 20.0,
..default()
},
)
.with_style(Style {
position_type: PositionType::Absolute,
bottom: Val::Px(12.0),
left: Val::Px(12.0),
..default()
}),
);
}
- examples/window/window_resizing.rs
- examples/3d/color_grading.rs
- examples/gizmos/2d_gizmos.rs
- examples/ui/flex_layout.rs
- examples/ui/window_fallthrough.rs
- examples/dev_tools/fps_overlay.rs
- examples/games/loading_screen.rs
- examples/ui/font_atlas_debug.rs
- examples/3d/tonemapping.rs
- examples/stress_tests/many_buttons.rs
- examples/window/screenshot.rs
- examples/window/scale_factor_override.rs
- examples/ecs/state.rs
- examples/ecs/sub_states.rs
- examples/ui/button.rs
- examples/3d/generate_custom_mesh.rs
- examples/2d/wireframe_2d.rs
- examples/window/multiple_windows.rs
- examples/ui/ui_scaling.rs
- examples/gizmos/3d_gizmos.rs
- examples/2d/bloom_2d.rs
- examples/audio/spatial_audio_2d.rs
- examples/ui/ui_texture_slice.rs
- examples/3d/wireframe.rs
- examples/audio/spatial_audio_3d.rs
- examples/2d/bounding_2d.rs
- examples/3d/ssao.rs
- examples/ui/transparency_ui.rs
- examples/ui/size_constraints.rs
- examples/ui/ui_texture_atlas_slice.rs
- examples/3d/bloom_3d.rs
- examples/transforms/align.rs
- examples/games/alien_cake_addict.rs
- examples/time/virtual_time.rs
- examples/3d/anti_aliasing.rs
- examples/ui/render_ui_to_texture.rs
- examples/ui/text.rs
- examples/ecs/computed_states.rs
- examples/3d/pbr.rs
- examples/gizmos/light_gizmos.rs
- examples/3d/auto_exposure.rs
- examples/3d/spotlight.rs
- examples/games/game_menu.rs
- examples/ui/display_and_visibility.rs
- examples/ui/borders.rs
- examples/3d/split_screen.rs
- examples/ui/rounded_borders.rs
- examples/ui/text_debug.rs
- examples/3d/deferred_rendering.rs
- examples/3d/blend_modes.rs
- examples/ui/grid.rs
- examples/3d/transmission.rs
- examples/ui/ui.rs
pub fn from_sections(
sections: impl IntoIterator<Item = TextSection>
) -> TextBundle
pub fn from_sections( sections: impl IntoIterator<Item = TextSection> ) -> TextBundle
Create a TextBundle
from a list of sections.
See Text::from_sections
for usage.
Examples found in repository?
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.spawn(Camera2dBundle::default());
let text_style = TextStyle {
font: asset_server.load("fonts/FiraSans-Bold.ttf"),
font_size: 60.0,
..default()
};
commands.spawn((
TextBundle::from_sections([
TextSection::new("Contributor showcase", text_style.clone()),
TextSection::from_style(TextStyle {
font_size: 30.,
..text_style
}),
])
.with_style(Style {
position_type: PositionType::Absolute,
top: Val::Px(12.),
left: Val::Px(12.),
..default()
}),
ContributorDisplay,
));
}
More examples
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
fn setup_ui(mut commands: Commands) {
let style = TextStyle {
font_size: 24.0,
..default()
};
commands.spawn(
TextBundle::from_sections(vec![
TextSection::new(String::new(), style.clone()),
TextSection::new(String::new(), style.clone()),
TextSection::new("1/2: -/+ shutter angle (blur amount)\n", style.clone()),
TextSection::new("3/4: -/+ sample count (blur quality)\n", style.clone()),
TextSection::new("Spacebar: cycle camera\n", style.clone()),
])
.with_style(Style {
position_type: PositionType::Absolute,
top: Val::Px(12.0),
left: Val::Px(12.0),
..default()
}),
);
}
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
fn build_stepping_hint(mut commands: Commands, asset_server: Res<AssetServer>) {
let hint_text = if cfg!(feature = "bevy_debug_stepping") {
"Press ` to toggle stepping mode (S: step system, Space: step frame)"
} else {
"Bevy was compiled without stepping support. Run with `--features=bevy_debug_stepping` to enable stepping."
};
info!("{}", hint_text);
// stepping description box
commands.spawn((TextBundle::from_sections([TextSection::new(
hint_text,
TextStyle {
font: asset_server.load(FONT_MEDIUM),
font_size: 18.0,
color: FONT_COLOR,
},
)])
.with_style(Style {
position_type: PositionType::Absolute,
bottom: Val::Px(5.0),
left: Val::Px(5.0),
..default()
}),));
}
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
fn setup_ui(mut commands: Commands) {
commands.spawn(Camera2dBundle::default());
commands.spawn(
TextBundle::from_sections([
TextSection::new(
"Press A or B to trigger a one-shot system\n",
TextStyle {
font_size: 25.0,
..default()
},
),
TextSection::new(
"Last Triggered: ",
TextStyle {
font_size: 20.0,
..default()
},
),
TextSection::new(
"-",
TextStyle {
font_size: 20.0,
color: bevy::color::palettes::css::ORANGE.into(),
..default()
},
),
])
.with_text_justify(JustifyText::Center)
.with_style(Style {
align_self: AlignSelf::Center,
justify_self: JustifySelf::Center,
..default()
}),
);
}
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306
fn load_loading_screen(mut commands: Commands) {
let text_style = TextStyle {
font_size: 80.0,
..default()
};
// Spawn the UI and Loading screen camera.
commands.spawn((
Camera2dBundle {
camera: Camera {
order: 1,
..default()
},
..default()
},
LoadingScreen,
));
// Spawn the UI that will make up the loading screen.
commands
.spawn((
NodeBundle {
background_color: BackgroundColor(Color::BLACK),
style: Style {
height: Val::Percent(100.0),
width: Val::Percent(100.0),
justify_content: JustifyContent::Center,
align_items: AlignItems::Center,
..default()
},
..default()
},
LoadingScreen,
))
.with_children(|parent| {
parent.spawn(TextBundle::from_sections([TextSection::new(
"Loading...",
text_style.clone(),
)]));
});
}
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
fn detect_morphs(
mut commands: Commands,
morphs: Query<(Entity, &MorphWeights, Option<&Name>)>,
meshes: Res<Assets<Mesh>>,
scene_handle: Res<SceneHandle>,
mut setup: Local<bool>,
asset_server: Res<AssetServer>,
) {
let no_morphing = morphs.iter().len() == 0;
if no_morphing {
return;
}
if scene_handle.is_loaded && !*setup {
*setup = true;
} else {
return;
}
let mut detected = Vec::new();
for (entity, weights, name) in &morphs {
let target_names = weights
.first_mesh()
.and_then(|h| meshes.get(h))
.and_then(|m| m.morph_target_names());
let targets = Target::new(name, weights.weights(), target_names, entity);
detected.extend(targets);
}
detected.truncate(AVAILABLE_KEYS.len());
let style = TextStyle {
font: asset_server.load("assets/fonts/FiraMono-Medium.ttf"),
font_size: 13.0,
..default()
};
let mut sections = vec![
TextSection::new("Morph Target Controls\n", style.clone()),
TextSection::new("---------------\n", style.clone()),
];
let target_to_text =
|(i, target): (usize, &Target)| target.text_section(AVAILABLE_KEYS[i].name, style.clone());
sections.extend(detected.iter().enumerate().map(target_to_text));
commands.insert_resource(WeightsControl { weights: detected });
commands.spawn(TextBundle::from_sections(sections).with_style(Style {
position_type: PositionType::Absolute,
top: Val::Px(10.0),
left: Val::Px(10.0),
..default()
}));
}
- examples/math/render_primitives.rs
- examples/ui/ui_texture_atlas.rs
- examples/window/low_power.rs
- examples/ui/overflow_debug.rs
- examples/input/text_input.rs
- examples/ui/text.rs
- examples/stress_tests/bevymark.rs
- examples/gizmos/light_gizmos.rs
- examples/shader/shader_prepass.rs
- examples/games/game_menu.rs
- examples/games/breakout.rs
- examples/3d/parallax_mapping.rs
- examples/3d/shadow_biases.rs
- examples/ui/text_debug.rs
- examples/3d/lighting.rs
pub const fn with_text_justify(self, justify: JustifyText) -> TextBundle
pub const fn with_text_justify(self, justify: JustifyText) -> TextBundle
Returns this TextBundle
with a new JustifyText
on Text
.
Examples found in repository?
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434
fn spawn_button<T>(parent: &mut ChildBuilder, text_style: TextStyle, target: Entity)
where
T: Default + std::fmt::Debug + Send + Sync + 'static,
Target<T>: TargetUpdate,
{
parent
.spawn((
ButtonBundle {
style: Style {
align_self: AlignSelf::FlexStart,
padding: UiRect::axes(Val::Px(5.), Val::Px(1.)),
..Default::default()
},
image: UiImage::default().with_color(Color::BLACK.with_alpha(0.5)),
..Default::default()
},
Target::<T>::new(target),
))
.with_children(|builder| {
builder.spawn(
TextBundle::from_section(
format!("{}::{:?}", Target::<T>::NAME, T::default()),
text_style,
)
.with_text_justify(JustifyText::Center),
);
});
}
More examples
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
fn setup_ui(mut commands: Commands) {
commands.spawn(Camera2dBundle::default());
commands.spawn(
TextBundle::from_sections([
TextSection::new(
"Press A or B to trigger a one-shot system\n",
TextStyle {
font_size: 25.0,
..default()
},
),
TextSection::new(
"Last Triggered: ",
TextStyle {
font_size: 20.0,
..default()
},
),
TextSection::new(
"-",
TextStyle {
font_size: 20.0,
color: bevy::color::palettes::css::ORANGE.into(),
..default()
},
),
])
.with_text_justify(JustifyText::Center)
.with_style(Style {
align_self: AlignSelf::Center,
justify_self: JustifySelf::Center,
..default()
}),
);
}
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
fn setup_image_viewer_scene(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
camera_transform: Res<CameraTransform>,
) {
let mut transform = camera_transform.0;
transform.translation += *transform.forward();
// exr/hdr viewer (exr requires enabling bevy feature)
commands.spawn((
PbrBundle {
mesh: meshes.add(Rectangle::default()),
material: materials.add(StandardMaterial {
base_color_texture: None,
unlit: true,
..default()
}),
transform,
visibility: Visibility::Hidden,
..default()
},
SceneNumber(3),
HDRViewer,
));
commands
.spawn((
TextBundle::from_section(
"Drag and drop an HDR or EXR file",
TextStyle {
font_size: 36.0,
color: Color::BLACK,
..default()
},
)
.with_text_justify(JustifyText::Center)
.with_style(Style {
align_self: AlignSelf::Center,
margin: UiRect::all(Val::Auto),
..default()
}),
SceneNumber(3),
))
.insert(Visibility::Hidden);
}
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378
fn setup_text(
mut commands: Commands,
asset_server: Res<AssetServer>,
cameras: Query<(Entity, &Camera)>,
) {
let active_camera = cameras
.iter()
.find_map(|(entity, camera)| camera.is_active.then_some(entity))
.expect("run condition ensures existence");
let text = format!("{text}", text = PrimitiveSelected::default());
let font_size = 24.0;
let font: Handle<Font> = asset_server.load("fonts/FiraMono-Medium.ttf");
let style = TextStyle {
font,
font_size,
color: Color::WHITE,
};
let instructions = "Press 'C' to switch between 2D and 3D mode\n\
Press 'Up' or 'Down' to switch to the next/previous primitive";
let text = [
TextSection::new("Primitive: ", style.clone()),
TextSection::new(text, style.clone()),
TextSection::new("\n\n", style.clone()),
TextSection::new(instructions, style.clone()),
TextSection::new("\n\n", style.clone()),
TextSection::new(
"(If nothing is displayed, there's no rendering support yet)",
style.clone(),
),
];
commands
.spawn((
HeaderNode,
NodeBundle {
style: Style {
justify_self: JustifySelf::Center,
top: Val::Px(5.0),
..Default::default()
},
..Default::default()
},
TargetCamera(active_camera),
))
.with_children(|parent| {
parent.spawn((
HeaderText,
TextBundle::from_sections(text).with_text_justify(JustifyText::Center),
));
});
}
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
fn setup(mut commands: Commands, asset_server: Res<AssetServer>, mut time: ResMut<Time<Virtual>>) {
// start with double `Virtual` time resulting in one of the sprites moving at twice the speed
// of the other sprite which moves based on `Real` (unscaled) time
time.set_relative_speed(2.);
commands.spawn(Camera2dBundle::default());
let virtual_color = GOLD.into();
let sprite_scale = Vec2::splat(0.5).extend(1.);
let texture_handle = asset_server.load("branding/icon.png");
// the sprite moving based on real time
commands.spawn((
SpriteBundle {
texture: texture_handle.clone(),
transform: Transform::from_scale(sprite_scale),
..default()
},
RealTime,
));
// the sprite moving based on virtual time
commands.spawn((
SpriteBundle {
texture: texture_handle,
sprite: Sprite {
color: virtual_color,
..default()
},
transform: Transform {
scale: sprite_scale,
translation: Vec3::new(0., -160., 0.),
..default()
},
..default()
},
VirtualTime,
));
// info UI
let font_size = 40.;
commands
.spawn(NodeBundle {
style: Style {
display: Display::Flex,
justify_content: JustifyContent::SpaceBetween,
width: Val::Percent(100.),
position_type: PositionType::Absolute,
top: Val::Px(0.),
padding: UiRect::all(Val::Px(20.0)),
..default()
},
..default()
})
.with_children(|builder| {
// real time info
builder.spawn((
TextBundle::from_section(
"",
TextStyle {
font_size,
..default()
},
),
RealTime,
));
// keybindings
builder.spawn(
TextBundle::from_section(
"CONTROLS\nUn/Pause: Space\nSpeed+: Up\nSpeed-: Down",
TextStyle {
font_size,
color: Color::srgb(0.85, 0.85, 0.85),
..default()
},
)
.with_text_justify(JustifyText::Center),
);
// virtual time info
builder.spawn((
TextBundle::from_section(
"",
TextStyle {
font_size,
color: virtual_color,
..default()
},
)
.with_text_justify(JustifyText::Right),
VirtualTime,
));
});
}
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
// UI camera
commands.spawn(Camera2dBundle::default());
// Text with one section
commands.spawn((
// Create a TextBundle that has a Text with a single section.
TextBundle::from_section(
// Accepts a `String` or any type that converts into a `String`, such as `&str`
"hello\nbevy!",
TextStyle {
// This font is loaded and will be used instead of the default font.
font: asset_server.load("fonts/FiraSans-Bold.ttf"),
font_size: 100.0,
..default()
},
) // Set the justification of the Text
.with_text_justify(JustifyText::Center)
// Set the style of the TextBundle itself.
.with_style(Style {
position_type: PositionType::Absolute,
bottom: Val::Px(5.0),
right: Val::Px(5.0),
..default()
}),
ColorText,
));
// Text with multiple sections
commands.spawn((
// Create a TextBundle that has a Text with a list of sections.
TextBundle::from_sections([
TextSection::new(
"FPS: ",
TextStyle {
// This font is loaded and will be used instead of the default font.
font: asset_server.load("fonts/FiraSans-Bold.ttf"),
font_size: 60.0,
..default()
},
),
TextSection::from_style(if cfg!(feature = "default_font") {
TextStyle {
font_size: 60.0,
color: GOLD.into(),
// If no font is specified, the default font (a minimal subset of FiraMono) will be used.
..default()
}
} else {
// "default_font" feature is unavailable, load a font to use instead.
TextStyle {
font: asset_server.load("fonts/FiraMono-Medium.ttf"),
font_size: 60.0,
color: GOLD.into(),
}
}),
]),
FpsText,
));
#[cfg(feature = "default_font")]
commands.spawn(
// Here we are able to call the `From` method instead of creating a new `TextSection`.
// This will use the default font (a minimal subset of FiraMono) and apply the default styling.
TextBundle::from("From an &str into a TextBundle with the default font!").with_style(
Style {
position_type: PositionType::Absolute,
bottom: Val::Px(5.0),
left: Val::Px(15.0),
..default()
},
),
);
#[cfg(not(feature = "default_font"))]
commands.spawn(
TextBundle::from_section(
"Default font disabled",
TextStyle {
font: asset_server.load("fonts/FiraMono-Medium.ttf"),
..default()
},
)
.with_style(Style {
position_type: PositionType::Absolute,
bottom: Val::Px(5.0),
left: Val::Px(15.0),
..default()
}),
);
}
pub fn with_style(self, style: Style) -> TextBundle
pub fn with_style(self, style: Style) -> TextBundle
Returns this TextBundle
with a new Style
.
Examples found in repository?
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
fn setup_instructions(mut commands: Commands) {
commands.spawn(
TextBundle::from_section(
"",
TextStyle {
font_size: 20.0,
..default()
},
)
.with_style(Style {
position_type: PositionType::Absolute,
top: Val::Px(12.0),
left: Val::Px(12.0),
..default()
}),
);
}
More examples
304 305 306 307 308 309 310 311 312 313 314 315 316 317
fn spawn_text(commands: &mut Commands, app_status: &AppStatus, asset_server: &AssetServer) {
commands.spawn(
TextBundle {
text: app_status.create_text(asset_server),
..TextBundle::default()
}
.with_style(Style {
position_type: PositionType::Absolute,
bottom: Val::Px(10.0),
left: Val::Px(10.0),
..default()
}),
);
}
235 236 237 238 239 240 241 242 243 244 245 246 247 248
fn spawn_text(commands: &mut Commands, asset_server: &AssetServer, light_mode: &LightMode) {
commands.spawn(
TextBundle {
text: light_mode.create_help_text(asset_server),
..TextBundle::default()
}
.with_style(Style {
position_type: PositionType::Absolute,
bottom: Val::Px(10.0),
left: Val::Px(10.0),
..default()
}),
);
}
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
fn infotext_system(mut commands: Commands) {
commands.spawn(Camera2dBundle::default());
commands.spawn(
TextBundle::from_section(
"Nothing to see in this window! Check the console output!",
TextStyle {
font_size: 50.0,
..default()
},
)
.with_style(Style {
align_self: AlignSelf::FlexEnd,
..default()
}),
);
}
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
fn spawn_text(commands: &mut Commands, asset_server: &AssetServer, app_status: &AppStatus) {
// Create the text.
commands.spawn(
TextBundle {
text: app_status.create_text(asset_server),
..TextBundle::default()
}
.with_style(Style {
position_type: PositionType::Absolute,
bottom: Val::Px(10.0),
left: Val::Px(10.0),
..default()
}),
);
}
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
fn setup_instructions(mut commands: Commands) {
commands.spawn(
TextBundle::from_section(
"Press Spacebar to Toggle Atmospheric Fog.\nPress S to Toggle Directional Light Fog Influence.",
TextStyle {
font_size: 20.0,
..default()
},
)
.with_style(Style {
position_type: PositionType::Absolute,
bottom: Val::Px(12.0),
left: Val::Px(12.0),
..default()
}),
);
}
- examples/games/contributors.rs
- examples/3d/motion_blur.rs
- examples/games/stepping.rs
- examples/ui/window_fallthrough.rs
- examples/ecs/one_shot_systems.rs
- examples/3d/tonemapping.rs
- examples/window/screenshot.rs
- examples/window/scale_factor_override.rs
- examples/tools/scene_viewer/morph_viewer_plugin.rs
- examples/3d/generate_custom_mesh.rs
- examples/2d/wireframe_2d.rs
- examples/gizmos/3d_gizmos.rs
- examples/2d/bloom_2d.rs
- examples/window/low_power.rs
- examples/audio/spatial_audio_2d.rs
- examples/ui/overflow_debug.rs
- examples/3d/wireframe.rs
- examples/3d/visibility_range.rs
- examples/input/text_input.rs
- examples/audio/spatial_audio_3d.rs
- examples/2d/bounding_2d.rs
- examples/3d/ssao.rs
- examples/ui/size_constraints.rs
- examples/3d/bloom_3d.rs
- examples/transforms/align.rs
- examples/games/alien_cake_addict.rs
- examples/3d/anti_aliasing.rs
- examples/ui/text.rs
- examples/3d/pbr.rs
- examples/gizmos/light_gizmos.rs
- examples/3d/auto_exposure.rs
- examples/3d/spotlight.rs
- examples/shader/shader_prepass.rs
- examples/games/game_menu.rs
- examples/games/breakout.rs
- examples/3d/parallax_mapping.rs
- examples/ui/text_debug.rs
- examples/3d/deferred_rendering.rs
- examples/3d/blend_modes.rs
- examples/3d/lighting.rs
- examples/3d/transmission.rs
pub const fn with_background_color(self, color: Color) -> TextBundle
pub const fn with_background_color(self, color: Color) -> TextBundle
Returns this TextBundle
with a new BackgroundColor
.
pub const fn with_no_wrap(self) -> TextBundle
pub const fn with_no_wrap(self) -> TextBundle
Returns this TextBundle
with soft wrapping disabled.
Hard wrapping, where text contains an explicit linebreak such as the escape sequence \n
, will still occur.
Examples found in repository?
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
fn setup(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
asset_server: Res<AssetServer>,
) {
let base_color = Color::srgb(0.9, 0.2, 0.3);
let icosphere_mesh = meshes.add(Sphere::new(0.9).mesh().ico(7).unwrap());
// Opaque
let opaque = commands
.spawn((
PbrBundle {
mesh: icosphere_mesh.clone(),
material: materials.add(StandardMaterial {
base_color,
alpha_mode: AlphaMode::Opaque,
..default()
}),
transform: Transform::from_xyz(-4.0, 0.0, 0.0),
..default()
},
ExampleControls {
unlit: true,
color: true,
},
))
.id();
// Blend
let blend = commands
.spawn((
PbrBundle {
mesh: icosphere_mesh.clone(),
material: materials.add(StandardMaterial {
base_color,
alpha_mode: AlphaMode::Blend,
..default()
}),
transform: Transform::from_xyz(-2.0, 0.0, 0.0),
..default()
},
ExampleControls {
unlit: true,
color: true,
},
))
.id();
// Premultiplied
let premultiplied = commands
.spawn((
PbrBundle {
mesh: icosphere_mesh.clone(),
material: materials.add(StandardMaterial {
base_color,
alpha_mode: AlphaMode::Premultiplied,
..default()
}),
transform: Transform::from_xyz(0.0, 0.0, 0.0),
..default()
},
ExampleControls {
unlit: true,
color: true,
},
))
.id();
// Add
let add = commands
.spawn((
PbrBundle {
mesh: icosphere_mesh.clone(),
material: materials.add(StandardMaterial {
base_color,
alpha_mode: AlphaMode::Add,
..default()
}),
transform: Transform::from_xyz(2.0, 0.0, 0.0),
..default()
},
ExampleControls {
unlit: true,
color: true,
},
))
.id();
// Multiply
let multiply = commands
.spawn((
PbrBundle {
mesh: icosphere_mesh,
material: materials.add(StandardMaterial {
base_color,
alpha_mode: AlphaMode::Multiply,
..default()
}),
transform: Transform::from_xyz(4.0, 0.0, 0.0),
..default()
},
ExampleControls {
unlit: true,
color: true,
},
))
.id();
// Chessboard Plane
let black_material = materials.add(Color::BLACK);
let white_material = materials.add(Color::WHITE);
let plane_mesh = meshes.add(Plane3d::default().mesh().size(2.0, 2.0));
for x in -3..4 {
for z in -3..4 {
commands.spawn((
PbrBundle {
mesh: plane_mesh.clone(),
material: if (x + z) % 2 == 0 {
black_material.clone()
} else {
white_material.clone()
},
transform: Transform::from_xyz(x as f32 * 2.0, -1.0, z as f32 * 2.0),
..default()
},
ExampleControls {
unlit: false,
color: true,
},
));
}
}
// Light
commands.spawn(PointLightBundle {
transform: Transform::from_xyz(4.0, 8.0, 4.0),
..default()
});
// Camera
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(0.0, 2.5, 10.0).looking_at(Vec3::ZERO, Vec3::Y),
..default()
});
// Controls Text
let text_style = TextStyle {
font: asset_server.load("fonts/FiraMono-Medium.ttf"),
font_size: 18.0,
..default()
};
let label_text_style = TextStyle {
font: asset_server.load("fonts/FiraMono-Medium.ttf"),
font_size: 25.0,
color: ORANGE.into(),
};
commands.spawn(
TextBundle::from_section(
"Up / Down — Increase / Decrease Alpha\nLeft / Right — Rotate Camera\nH - Toggle HDR\nSpacebar — Toggle Unlit\nC — Randomize Colors",
text_style.clone(),
)
.with_style(Style {
position_type: PositionType::Absolute,
top: Val::Px(10.0),
left: Val::Px(10.0),
..default()
}),
);
commands.spawn((
TextBundle::from_section("", text_style).with_style(Style {
position_type: PositionType::Absolute,
top: Val::Px(10.0),
right: Val::Px(10.0),
..default()
}),
ExampleDisplay,
));
let mut label = |entity: Entity, label: &str| {
commands
.spawn((
NodeBundle {
style: Style {
position_type: PositionType::Absolute,
..default()
},
..default()
},
ExampleLabel { entity },
))
.with_children(|parent| {
parent.spawn(
TextBundle::from_section(label, label_text_style.clone())
.with_style(Style {
position_type: PositionType::Absolute,
bottom: Val::ZERO,
..default()
})
.with_no_wrap(),
);
});
};
label(opaque, "┌─ Opaque\n│\n│\n│\n│");
label(blend, "┌─ Blend\n│\n│\n│");
label(premultiplied, "┌─ Premultiplied\n│\n│");
label(add, "┌─ Add\n│");
label(multiply, "┌─ Multiply");
}
Trait Implementations§
§impl Debug for TextBundle
impl Debug for TextBundle
§impl Default for TextBundle
impl Default for TextBundle
§fn default() -> TextBundle
fn default() -> TextBundle
§impl<I> From<I> for TextBundlewhere
I: Into<TextSection>,
impl<I> From<I> for TextBundlewhere
I: Into<TextSection>,
§fn from(value: I) -> TextBundle
fn from(value: I) -> TextBundle
impl Bundle for TextBundle
impl DynamicBundle for TextBundle
Auto Trait Implementations§
impl Freeze for TextBundle
impl !RefUnwindSafe for TextBundle
impl Send for TextBundle
impl Sync for TextBundle
impl Unpin for TextBundle
impl !UnwindSafe for TextBundle
Blanket Implementations§
§impl<T, U> AsBindGroupShaderType<U> for T
impl<T, U> AsBindGroupShaderType<U> for T
§fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
T
ShaderType
for self
. When used in AsBindGroup
derives, it is safe to assume that all images in self
exist.source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
§impl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere
T: Default,
§fn from_world(_world: &mut World) -> T
fn from_world(_world: &mut World) -> T
Self
using data from the given World
.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
§impl<T> NoneValue for Twhere
T: Default,
impl<T> NoneValue for Twhere
T: Default,
type NoneType = T
§fn null_value() -> T
fn null_value() -> T
§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian()
.