#Hierarchy with children![] macro question

20 messages · Page 1 of 1 (latest)

strong herald
#
world.spawn((
        Name::new("root"),
        Node {
            width: percent(100),
            height: percent(100),
            align_items: AlignItems::Center,
            justify_content: JustifyContent::Center,
            flex_direction: FlexDirection::Column,
            ..default()
        },
));

i would like to link 4 node to the root, not chained them just (1 parent ,4 children)
if i add 4 children![Node{..default}] to the root bundle my runtime panic how to do this properly ?

deft vale
strong herald
#
    command
        .spawn((
            Name::new("root"),
            Node {
                width: percent(100),
                height: percent(100),
                align_items: AlignItems::Center,
                justify_content: JustifyContent::Center,
                flex_direction: FlexDirection::Column,
                ..default()
            },
        ))
        .with_children(|parent| {
            parent.spawn((
                Name::new("zone1"),
                Zone1,
                Node {
                    position_type: PositionType::Absolute,
                    left: px(0),
                    top: px(0),
                    width: percent(50),
                    height: percent(50),
                    ..Default::default()
                },
                BackgroundColor(YELLOW.into()),
            ));
        })
        .with_children(|parent| {
            parent.spawn((
                Name::new("zone2"),
                Zone1,
                Node {
                    position_type: PositionType::Absolute,
                    right: px(0),
                    top: px(0),
                    width: percent(50),
                    height: percent(50),
                    ..Default::default()
                },
                BackgroundColor(PURPLE.into()),
            ));
        })
strong herald
deft vale
#

what's the code that panics?

strong herald
strong herald
# deft vale what's the code that panics?

this one does not compile :```
command.spawn((
Name::new("root"),
Node {
width: percent(100),
height: percent(100),
align_items: AlignItems::Center,
justify_content: JustifyContent::Center,
flex_direction: FlexDirection::Column,
..default()
},
children![(
Name::new("zone1"),
Zone1,
Node {
position_type: PositionType::Absolute,
left: px(0),
top: px(0),
width: percent(50),
height: percent(50),
..Default::default()
},
BackgroundColor(YELLOW.into()),
)],
children![(
Name::new("zone2"),
Zone2,
Node {
position_type: PositionType::Absolute,
right: px(0),
top: px(0),
width: percent(50),
height: percent(50),
..Default::default()
},
BackgroundColor(PURPLE.into()),
)],
));

deft vale
#

try this

command.spawn((
    Name::new("root"),
    Node {
        width: percent(100),
        height: percent(100),
        align_items: AlignItems::Center,
        justify_content: JustifyContent::Center,
        flex_direction: FlexDirection::Column,
        ..default()
    },
    children![
        (
            Name::new("zone1"),
            Zone1,
            Node {
                position_type: PositionType::Absolute,
                left: px(0),
                top: px(0),
                width: percent(50),
                height: percent(50),
                ..Default::default()
            },
            BackgroundColor(YELLOW.into()),
        ),
        (
            Name::new("zone2"),
            Zone2,
            Node {
                position_type: PositionType::Absolute,
                right: px(0),
                top: px(0),
                width: percent(50),
                height: percent(50),
                ..Default::default()
            },
            BackgroundColor(PURPLE.into()),
        )
    ],
));
strong herald
#

oh nice thanks

deft vale
#

in essence you're doing this

Children::spawn(Spawn((Name::new("zone1"), ...)),
Children::spawn(Spawn((Name::new("zone2"), ...)),

which involves having Children twice in one bundle

#

which bevy doesn't like

flat grail
#

even on the code with with_children you could have multiple calls to parent.spawn in a single place without needing to chain them

strong herald
#

but strange things maybe you can tell me what i did wrong: command.spawn(( Name::new("root"), Node { width: percent(100), height: percent(100), align_items: AlignItems::Center, justify_content: JustifyContent::Center, flex_direction: FlexDirection::Column, ..default() }, children![( Name::new("zone1"), Zone1, Node { position_type: PositionType::Absolute, left: px(0), top: px(0), width: percent(50), height: percent(50), ..Default::default() }, BackgroundColor(YELLOW.into()), children![ Text::new("Text zone 1"), TextFont { font_size: 50.0, ..default() }, TextColor(BLUE.into()), Node { position_type: PositionType::Absolute, top: px(5), left: px(5), ..default() }, ] )], )); This code does not update the (color/size) of the text children (the default value sim inherited since it's white)...

flat grail
#
Root
- Child1
  - Grandchild1 (Text)
  - Grandchild2 (TextFont)
  - Grandchild3 (TextColor)
  - Grandchild4 (Node)
#

Missed the parentheses

strong herald
#

the code compile the text is displayed the link parent/child work but the size and color of the last children does not care of the settings TextFont and TextColor maybe it's macro bug ?

flat grail
#

The macro expects a list of bundles, a single component is a bundle, and a tuple of components is also a bundle, the second children has 4 distinct bundles because there is no parentheses to make it into a single tuple bundle

strong herald
#

Oh !