Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/bevy_dev_tools/src/fps_overlay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ fn setup(
FpsText,
Pickable::IGNORE,
))
.with_child((TextSpan::default(), overlay_config.text_config.clone()));
.spawn_child((TextSpan::default(), overlay_config.text_config.clone()));

let font_size = overlay_config.text_config.font_size;
p.spawn((
Expand Down
20 changes: 20 additions & 0 deletions crates/bevy_ecs/src/hierarchy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,17 @@ impl<'w> EntityWorldMut<'w> {
/// For efficient spawning of multiple children, use [`with_children`].
///
/// [`with_children`]: EntityWorldMut::with_children
#[deprecated = "Use spawn_child instead"]
pub fn with_child(&mut self, bundle: impl Bundle) -> &mut Self {
self.spawn_child(bundle)
}

/// Spawns the passed bundle and adds it to this entity as a child.
///
/// For efficient spawning of multiple children, use [`with_children`].
///
/// [`with_children`]: EntityWorldMut::with_children
pub fn spawn_child(&mut self, bundle: impl Bundle) -> &mut Self {
let parent = self.id();
self.world_scope(|world| {
world.spawn((bundle, ChildOf(parent)));
Expand Down Expand Up @@ -484,7 +494,17 @@ impl<'a> EntityCommands<'a> {
/// For efficient spawning of multiple children, use [`with_children`].
///
/// [`with_children`]: EntityCommands::with_children
#[deprecated = "Use spawn_child instead"]
pub fn with_child(&mut self, bundle: impl Bundle) -> &mut Self {
self.spawn_child(bundle)
}

/// Spawns the passed bundle and adds it to this entity as a child.
///
/// For efficient spawning of multiple children, use [`with_children`].
///
/// [`with_children`]: EntityCommands::with_children
pub fn spawn_child(&mut self, bundle: impl Bundle) -> &mut Self {
self.with_related::<ChildOf>(bundle);
self
}
Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_ui/src/experimental/ghost_hierarchy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,16 +217,16 @@ mod tests {
parent.spawn((A(2), Node::default()));
parent
.spawn((A(3), GhostNode))
.with_child((A(4), Node::default()));
.spawn_child((A(4), Node::default()));
});

// Ghost root
world.spawn((A(5), GhostNode)).with_children(|parent| {
parent.spawn((A(6), Node::default()));
parent
.spawn((A(7), GhostNode))
.with_child((A(8), Node::default()))
.with_child(A(9));
.spawn_child((A(8), Node::default()))
.spawn_child(A(9));
});

let mut system_state = SystemState::<(UiRootNodes, Query<&A>)>::new(world);
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_ui/src/layout/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ mod tests {
let world = app.world_mut();

// spawn an invalid UI root node
let root_node = world.spawn(()).with_child(Node::default()).id();
let root_node = world.spawn(()).spawn_child(Node::default()).id();

app.update();
let world = app.world_mut();
Expand Down
2 changes: 1 addition & 1 deletion examples/3d/spherical_area_lights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fn setup(
Transform::from_xyz(position_range.start + percent * pos_len, 0.3, 0.0)
.with_scale(Vec3::splat(radius)),
))
.with_child(PointLight {
.spawn_child(PointLight {
radius,
color: Color::srgb(0.2, 0.2, 1.0),
..default()
Expand Down
2 changes: 1 addition & 1 deletion examples/camera/first_person_view_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ fn spawn_text(mut commands: Commands) {
left: px(12),
..default()
})
.with_child(Text::new(concat!(
.spawn_child(Text::new(concat!(
"Move the camera with your mouse.\n",
"Press arrow up to decrease the FOV of the world model.\n",
"Press arrow down to increase the FOV of the world model."
Expand Down
2 changes: 1 addition & 1 deletion examples/ecs/error_handling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ fn setup(

// Add sample points as children of the sphere:
for point in distribution.sample_iter(&mut seeded_rng).take(10000) {
sphere.with_child((
sphere.spawn_child((
Mesh3d(point_mesh.clone()),
MeshMaterial3d(point_material.clone()),
Transform::from_translation(point),
Expand Down
2 changes: 1 addition & 1 deletion examples/ecs/iter_combinations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ fn generate_bodies(
Transform::from_scale(Vec3::splat(star_radius)),
Star,
))
.with_child(PointLight {
.spawn_child(PointLight {
color: Color::WHITE,
range: 100.0,
radius: star_radius,
Expand Down
2 changes: 1 addition & 1 deletion examples/games/contributors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
..default()
},
))
.with_child((
.spawn_child((
TextSpan::default(),
TextFont {
font_size: 30.,
Expand Down
4 changes: 2 additions & 2 deletions examples/games/loading_screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ fn setup(mut commands: Commands) {
},
BackgroundColor(Color::NONE),
))
.with_child((Text::new("Press 1 or 2 to load a new scene."), text_style));
.spawn_child((Text::new("Press 1 or 2 to load a new scene."), text_style));
}

// Selects the level you want to load.
Expand Down Expand Up @@ -256,7 +256,7 @@ fn load_loading_screen(mut commands: Commands) {
BackgroundColor(Color::BLACK),
LoadingScreen,
))
.with_child((Text::new("Loading..."), text_style.clone()));
.spawn_child((Text::new("Loading..."), text_style.clone()));
}

// Determines when to show the loading screen
Expand Down
2 changes: 1 addition & 1 deletion examples/gizmos/light_gizmos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ fn setup(
..default()
},
))
.with_child(TextSpan(gizmo_color_text(light_config)));
.spawn_child(TextSpan(gizmo_color_text(light_config)));
}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/mobile/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ fn setup_scene(
..default()
},
))
.with_child((
.spawn_child((
Text::new("Test Button"),
TextFont {
font_size: 30.0,
Expand Down
2 changes: 1 addition & 1 deletion examples/stress_tests/many_buttons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ fn spawn_button(
},
TextColor(Color::srgb(0.5, 0.2, 0.2)),
))
.with_child((
.spawn_child((
TextSpan(format!("{row}")),
TextFont {
font_size: FONT_SIZE,
Expand Down
2 changes: 1 addition & 1 deletion examples/stress_tests/many_glyphs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ fn setup(mut commands: Commands, args: Res<Args>) {
width: px(1000),
..Default::default()
})
.with_child((Text(text_string.clone()), text_font.clone(), text_block));
.spawn_child((Text(text_string.clone()), text_font.clone(), text_block));
});
}

Expand Down
2 changes: 1 addition & 1 deletion examples/testbed/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ mod text_wrap {
];

for (j, message) in messages.into_iter().enumerate() {
commands.entity(root).with_child((
commands.entity(root).spawn_child((
Text(message.clone()),
TextLayout::new(Justify::Left, linebreak),
BackgroundColor(Color::srgb(0.8 - j as f32 * 0.3, 0., 0.)),
Expand Down
2 changes: 1 addition & 1 deletion examples/ui/auto_directional_navigation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ fn setup_scattered_ui(mut commands: Commands, mut input_focus: ResMut<InputFocus
BackgroundColor::from(NORMAL_BUTTON),
Name::new(format!("Button {}", i + 1)),
))
.with_child((
.spawn_child((
Text::new(format!("Button {}", i + 1)),
TextLayout {
justify: Justify::Center,
Expand Down
2 changes: 1 addition & 1 deletion examples/ui/directional_navigation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ fn setup_ui(
Name::new(button_name.clone()),
))
// Add a text element to the button
.with_child((
.spawn_child((
Text::new(button_name),
// And center the text if it flows onto multiple lines
TextLayout {
Expand Down
8 changes: 4 additions & 4 deletions examples/ui/ghost_nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {

// Ghost UI root
commands.spawn(GhostNode).with_children(|ghost_root| {
ghost_root.spawn(Node::default()).with_child(create_label(
ghost_root.spawn(Node::default()).spawn_child(create_label(
"This text node is rendered under a ghost root",
font_handle.clone(),
));
Expand All @@ -55,16 +55,16 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
// These buttons are being treated as children of layout_parent in the context of UI
ghost_parent
.spawn(create_button())
.with_child(create_label("0", font_handle.clone()));
.spawn_child(create_label("0", font_handle.clone()));
ghost_parent
.spawn(create_button())
.with_child(create_label("0", font_handle.clone()));
.spawn_child(create_label("0", font_handle.clone()));
});

// A normal child using the layout parent counter
layout_parent
.spawn(create_button())
.with_child(create_label("0", font_handle.clone()));
.spawn_child(create_label("0", font_handle.clone()));
});
});
}
Expand Down
4 changes: 2 additions & 2 deletions examples/ui/overflow_clip_margin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
},
BackgroundColor(Color::srgb(0.25, 0.25, 0.25)),
))
.with_child(Text(format!("{overflow_clip_margin:#?}")));
.spawn_child(Text(format!("{overflow_clip_margin:#?}")));

parent
.spawn((
Expand All @@ -77,7 +77,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
},
BackgroundColor(LIGHT_CYAN.into()),
))
.with_child((
.spawn_child((
ImageNode::new(image.clone()),
Node {
min_width: px(100),
Expand Down
2 changes: 1 addition & 1 deletion examples/ui/overflow_debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
},
Instructions,
))
.with_child((
.spawn_child((
TextSpan::new(format!("{:?}", Overflow::clip())),
text_font.clone(),
));
Expand Down
4 changes: 2 additions & 2 deletions examples/ui/size_constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ fn spawn_button_row(
align_items: AlignItems::Center,
..default()
},))
.with_child((Text::new(label), text_style.clone()));
.spawn_child((Text::new(label), text_style.clone()));

// spawn row buttons
parent.spawn(Node::default()).with_children(|parent| {
Expand Down Expand Up @@ -243,7 +243,7 @@ fn spawn_button(
INACTIVE_INNER_COLOR
}),
))
.with_child((
.spawn_child((
Text::new(label),
text_style.0,
TextColor(if active {
Expand Down
2 changes: 1 addition & 1 deletion examples/ui/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
..default()
},
))
.with_child((
.spawn_child((
TextSpan::default(),
if cfg!(feature = "default_font") {
(
Expand Down
2 changes: 1 addition & 1 deletion examples/ui/text_wrap_debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ fn spawn(mut commands: Commands, asset_server: Res<AssetServer>) {
];

for (j, message) in messages.into_iter().enumerate() {
commands.entity(column_id).with_child((
commands.entity(column_id).spawn_child((
Text(message.clone()),
text_font.clone(),
TextLayout::new(Justify::Left, linebreak),
Expand Down
2 changes: 1 addition & 1 deletion examples/ui/ui_drag_and_drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ fn setup(mut commands: Commands) {
core::mem::swap(&mut a.grid_column, &mut b.grid_column);
}
})
.with_child((Text::new(format!("{i}")), Pickable::IGNORE));
.spawn_child((Text::new(format!("{i}")), Pickable::IGNORE));
}
}
});
Expand Down
4 changes: 2 additions & 2 deletions examples/ui/ui_texture_atlas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ fn setup(
));
parent
.spawn((Text::new("press "), text_font.clone()))
.with_child((
.spawn_child((
TextSpan::new("space"),
TextColor(YELLOW.into()),
text_font.clone(),
))
.with_child((TextSpan::new(" to advance frames"), text_font));
.spawn_child((TextSpan::new(" to advance frames"), text_font));
});
}

Expand Down
2 changes: 1 addition & 1 deletion examples/ui/ui_texture_slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
..default()
},
))
.with_child((
.spawn_child((
Text::new("Button"),
TextFont {
font: asset_server.load("fonts/FiraSans-Bold.ttf"),
Expand Down
4 changes: 2 additions & 2 deletions examples/window/multi_window_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ fn setup_scene(mut commands: Commands) {
// camera with the `IsDefaultUiCamera` marker component. When that fails (neither
// camera spawned here has an `IsDefaultUiCamera`), it queries for the
// first camera targeting the primary window and uses that.
commands.spawn(node.clone()).with_child((
commands.spawn(node.clone()).spawn_child((
Text::new("UI Text Primary Window"),
text_font.clone(),
TextShadow::default(),
));

commands
.spawn((node, UiTargetCamera(secondary_window_camera)))
.with_child((
.spawn_child((
Text::new("UI Text Secondary Window"),
text_font.clone(),
TextShadow::default(),
Expand Down
4 changes: 2 additions & 2 deletions examples/window/multiple_windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ fn setup_scene(mut commands: Commands, asset_server: Res<AssetServer>) {
// Since we are using multiple cameras, we need to specify which camera UI should be rendered to
UiTargetCamera(first_window_camera),
))
.with_child((Text::new("First window"), TextShadow::default()));
.spawn_child((Text::new("First window"), TextShadow::default()));

commands
.spawn((node, UiTargetCamera(second_window_camera)))
.with_child((Text::new("Second window"), TextShadow::default()));
.spawn_child((Text::new("Second window"), TextShadow::default()));
}
2 changes: 1 addition & 1 deletion examples/window/window_resizing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fn setup_ui(mut commands: Commands) {
..default()
})
// Text where we display current resolution
.with_child((
.spawn_child((
Text::new("Resolution"),
TextFont {
font_size: 42.0,
Expand Down