tweak add_children

This commit is contained in:
Carter Anderson 2020-03-09 02:08:27 -07:00
parent 8eec5653b6
commit e4550aaab2
3 changed files with 11 additions and 14 deletions

View file

@ -38,9 +38,9 @@ fn setup(world: &mut World, resources: &mut Resources) {
..Default::default()
})
.add(Rotator)
.add_children(|child_builder| {
.add_children(|builder| {
// cube
child_builder.add_entity(MeshEntity {
builder.add_entity(MeshEntity {
mesh: cube_handle,
material: StandardMaterial {
albedo: math::vec4(0.5, 0.4, 0.3, 1.0).into(),

View file

@ -111,8 +111,8 @@ fn setup(world: &mut World, resources: &mut Resources) {
math::vec4(0.1, 0.1, 1.0, 1.0),
),
})
.add_children(|child_builder| {
child_builder.add_entity(UiEntity {
.add_children(|builder| {
builder.add_entity(UiEntity {
node: Node::new(
math::vec2(0.0, 0.0),
Anchors::new(0.0, 1.0, 0.0, 1.0),

View file

@ -72,18 +72,15 @@ impl<'a> WorldBuilder<'a> {
self
}
pub fn add_children(self, build_children: impl Fn(WorldBuilder) -> WorldBuilder) -> Self {
let mut child_builder = WorldBuilder {
world: self.world,
parent_entity: self.current_entity,
current_entity: None,
};
pub fn add_children(mut self, build_children: impl Fn(WorldBuilder) -> WorldBuilder) -> Self {
self.parent_entity = self.current_entity;
self.current_entity = None;
child_builder = build_children(child_builder);
self = build_children(self);
child_builder.current_entity = child_builder.parent_entity;
child_builder.parent_entity = None;
child_builder
self.current_entity = self.parent_entity;
self.parent_entity = None;
self
}
fn add_parent_to_current_entity(&mut self) {