Struct hecs_hierarchy::TreeBuilder
source · pub struct TreeBuilder<T> { /* private fields */ }
Expand description
Ergonomically construct trees without knowledge of world.
This struct builds the world using EntityBuilder
Example
use hecs_hierarchy::*;
use hecs::*;
struct Tree;
let mut world = World::default();
let mut builder = TreeBuilder::<Tree>::from(("root",));
builder.attach(("child 1",));
builder.attach({
let mut builder = TreeBuilder::new();
builder.add("child 2");
builder
});
let root = builder.spawn(&mut world);
assert_eq!(*world.get::<&&'static str>(root).unwrap(), "root");
for (a, b) in world
.descendants_depth_first::<Tree>(root)
.zip(["child 1", "child 2"])
{
assert_eq!(*world.get::<&&str>(a).unwrap(), b)
}
Implementations§
source§impl<T: Component> TreeBuilder<T>
impl<T: Component> TreeBuilder<T>
sourcepub fn reserve(&self, world: &impl GenericWorld) -> Entity
pub fn reserve(&self, world: &impl GenericWorld) -> Entity
Reserve the entity which this node will spawn
sourcepub fn spawn_deferred(
&mut self,
world: &impl GenericWorld,
cmd: &mut CommandBuffer
) -> Entity
pub fn spawn_deferred( &mut self, world: &impl GenericWorld, cmd: &mut CommandBuffer ) -> Entity
Spawn the whole tree into a commandbuffer. The world is required for reserving entities.
pub fn add_all(&mut self, component: impl Component + Clone) -> &mut Self
sourcepub fn add_bundle(&mut self, bundle: impl DynamicBundle) -> &mut Self
pub fn add_bundle(&mut self, bundle: impl DynamicBundle) -> &mut Self
Add a bundle to the root
sourcepub fn attach_tree(&mut self, child: Self) -> &mut Self
pub fn attach_tree(&mut self, child: Self) -> &mut Self
Atttach a new subtree
sourcepub fn attach_move(self, child: impl Into<Self>) -> Self
pub fn attach_move(self, child: impl Into<Self>) -> Self
Consuming variant of Self::attach.
This is useful for nesting to alleviate the need to save an intermediate builder
sourcepub fn attach_tree_move(self, child: impl Into<Self>) -> Self
pub fn attach_tree_move(self, child: impl Into<Self>) -> Self
Consuming variant of Self::attach_tree. This is useful for nesting to alleviate the need to save an intermediate builder
sourcepub fn root(&self) -> &EntityBuilder
pub fn root(&self) -> &EntityBuilder
Get a reference to the deferred tree builder’s root.
sourcepub fn root_mut(&mut self) -> &mut EntityBuilder
pub fn root_mut(&mut self) -> &mut EntityBuilder
Get a mutable reference to the deferred tree builder’s root.
sourcepub fn children_mut(&mut self) -> &mut Vec<TreeBuilder<T>>
pub fn children_mut(&mut self) -> &mut Vec<TreeBuilder<T>>
Get a mutable reference to the tree builder’s children.
Trait Implementations§
source§impl<B: DynamicBundle, T: Component> From<B> for TreeBuilder<T>
impl<B: DynamicBundle, T: Component> From<B> for TreeBuilder<T>
source§impl<T: Component> From<TreeBuilderClone<T>> for TreeBuilder<T>
impl<T: Component> From<TreeBuilderClone<T>> for TreeBuilder<T>
source§fn from(tree: TreeBuilderClone<T>) -> Self
fn from(tree: TreeBuilderClone<T>) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl<T> RefUnwindSafe for TreeBuilder<T>where
T: RefUnwindSafe,
impl<T> Send for TreeBuilder<T>where
T: Send,
impl<T> Sync for TreeBuilder<T>where
T: Sync,
impl<T> Unpin for TreeBuilder<T>where
T: Unpin,
impl<T> UnwindSafe for TreeBuilder<T>where
T: UnwindSafe,
Blanket Implementations§
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
Mutably borrows from an owned value. Read more