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() ..Default::default()
}) })
.add(Rotator) .add(Rotator)
.add_children(|child_builder| { .add_children(|builder| {
// cube // cube
child_builder.add_entity(MeshEntity { builder.add_entity(MeshEntity {
mesh: cube_handle, mesh: cube_handle,
material: StandardMaterial { material: StandardMaterial {
albedo: math::vec4(0.5, 0.4, 0.3, 1.0).into(), 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), math::vec4(0.1, 0.1, 1.0, 1.0),
), ),
}) })
.add_children(|child_builder| { .add_children(|builder| {
child_builder.add_entity(UiEntity { builder.add_entity(UiEntity {
node: Node::new( node: Node::new(
math::vec2(0.0, 0.0), math::vec2(0.0, 0.0),
Anchors::new(0.0, 1.0, 0.0, 1.0), Anchors::new(0.0, 1.0, 0.0, 1.0),

View file

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