Skip to content

Commit 76ab6a9

Browse files
authored
Update state/states example to use children! macro (#18250)
# Objective Contributes to #18238 Updates the `state/states` example to use the `children!` macro. Note that this example also requires `--features bevy_dev_tools` ## Solution Updates examples to use the Improved Spawning API merged in #17521 ## Testing - Did you test these changes? If so, how? - Opened the examples before and after and verified the same behavior was observed. I did this on Ubuntu 24.04.2 LTS using `--features wayland`. - Are there any parts that need more testing? - Other OS's and features can't hurt, but this is such a small change it shouldn't be a problem. - How can other people (reviewers) test your changes? Is there anything specific they need to know? - Run the examples yourself with and without these changes. - If relevant, what platforms did you test these changes on, and are there any important ones you can't test? - see above --- ## Showcase n/a ## Migration Guide n/a
1 parent bfe932d commit 76ab6a9

File tree

1 file changed

+29
-32
lines changed

1 file changed

+29
-32
lines changed

examples/state/states.rs

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -51,40 +51,37 @@ fn setup(mut commands: Commands) {
5151

5252
fn setup_menu(mut commands: Commands) {
5353
let button_entity = commands
54-
.spawn(Node {
55-
// center button
56-
width: Val::Percent(100.),
57-
height: Val::Percent(100.),
58-
justify_content: JustifyContent::Center,
59-
align_items: AlignItems::Center,
60-
..default()
61-
})
62-
.with_children(|parent| {
63-
parent
64-
.spawn((
65-
Button,
66-
Node {
67-
width: Val::Px(150.),
68-
height: Val::Px(65.),
69-
// horizontally center child text
70-
justify_content: JustifyContent::Center,
71-
// vertically center child text
72-
align_items: AlignItems::Center,
54+
.spawn((
55+
Node {
56+
// center button
57+
width: Val::Percent(100.),
58+
height: Val::Percent(100.),
59+
justify_content: JustifyContent::Center,
60+
align_items: AlignItems::Center,
61+
..default()
62+
},
63+
children![(
64+
Button,
65+
Node {
66+
width: Val::Px(150.),
67+
height: Val::Px(65.),
68+
// horizontally center child text
69+
justify_content: JustifyContent::Center,
70+
// vertically center child text
71+
align_items: AlignItems::Center,
72+
..default()
73+
},
74+
BackgroundColor(NORMAL_BUTTON),
75+
children![(
76+
Text::new("Play"),
77+
TextFont {
78+
font_size: 33.0,
7379
..default()
7480
},
75-
BackgroundColor(NORMAL_BUTTON),
76-
))
77-
.with_children(|parent| {
78-
parent.spawn((
79-
Text::new("Play"),
80-
TextFont {
81-
font_size: 33.0,
82-
..default()
83-
},
84-
TextColor(Color::srgb(0.9, 0.9, 0.9)),
85-
));
86-
});
87-
})
81+
TextColor(Color::srgb(0.9, 0.9, 0.9)),
82+
)],
83+
)],
84+
))
8885
.id();
8986
commands.insert_resource(MenuData { button_entity });
9087
}

0 commit comments

Comments
 (0)