Trait bevy::prelude::BuildChildren
[−]pub trait BuildChildren {
fn with_children(
&mut self,
f: impl FnOnce(&mut ChildBuilder<'_, '_, '_>)
) -> &mut Self;
fn add_children<T>(
&mut self,
f: impl FnOnce(&mut ChildBuilder<'_, '_, '_>) -> T
) -> T;
fn push_children(&mut self, children: &[Entity]) -> &mut Self;
fn insert_children(&mut self, index: usize, children: &[Entity]) -> &mut Self;
fn remove_children(&mut self, children: &[Entity]) -> &mut Self;
fn add_child(&mut self, child: Entity) -> &mut Self;
}
Expand description
Trait defining how to build children
Required Methods
fn with_children(
&mut self,
f: impl FnOnce(&mut ChildBuilder<'_, '_, '_>)
) -> &mut Self
fn with_children(
&mut self,
f: impl FnOnce(&mut ChildBuilder<'_, '_, '_>)
) -> &mut Self
Creates a ChildBuilder
with the given children built in the given closure
Compared to add_children
, this method returns self
to allow chaining.
fn add_children<T>(
&mut self,
f: impl FnOnce(&mut ChildBuilder<'_, '_, '_>) -> T
) -> T
fn add_children<T>(
&mut self,
f: impl FnOnce(&mut ChildBuilder<'_, '_, '_>) -> T
) -> T
Creates a ChildBuilder
with the given children built in the given closure
Compared to with_children
, this method returns the
the value returned from the closure, but doesn’t allow chaining.
Example
let mut parent_commands = commands.spawn();
let child_id = parent_commands.add_children(|parent| {
parent.spawn().id()
});
parent_commands.insert(SomethingElse);
commands.entity(child_id).with_children(|parent| {
parent.spawn().insert(MoreStuff);
});
fn push_children(&mut self, children: &[Entity]) -> &mut Self
fn push_children(&mut self, children: &[Entity]) -> &mut Self
Pushes children to the back of the builder’s children
fn insert_children(&mut self, index: usize, children: &[Entity]) -> &mut Self
fn insert_children(&mut self, index: usize, children: &[Entity]) -> &mut Self
Inserts children at the given index
fn remove_children(&mut self, children: &[Entity]) -> &mut Self
fn remove_children(&mut self, children: &[Entity]) -> &mut Self
Removes the given children