Skip to content

Commit 585dac0

Browse files
committed
Remove auto-margin properties from the examples (bevyengine#6535)
# Objective Fixes bevyengine#6498. ## Solution Adding a parent node with properties AlignItems::Center and JustifyContent::Center to centered child nodes and removing their auto-margin properties.
1 parent 96e09f0 commit 585dac0

File tree

6 files changed

+499
-377
lines changed

6 files changed

+499
-377
lines changed

examples/ecs/state.rs

+25-14
Original file line numberDiff line numberDiff line change
@@ -41,29 +41,40 @@ fn setup(mut commands: Commands) {
4141

4242
fn setup_menu(mut commands: Commands, asset_server: Res<AssetServer>) {
4343
let button_entity = commands
44-
.spawn(ButtonBundle {
44+
.spawn(NodeBundle {
4545
style: Style {
46-
size: Size::new(Val::Px(150.0), Val::Px(65.0)),
4746
// center button
48-
margin: UiRect::all(Val::Auto),
49-
// horizontally center child text
47+
size: Size::new(Val::Percent(100.0), Val::Percent(100.0)),
5048
justify_content: JustifyContent::Center,
51-
// vertically center child text
5249
align_items: AlignItems::Center,
5350
..default()
5451
},
55-
background_color: NORMAL_BUTTON.into(),
5652
..default()
5753
})
5854
.with_children(|parent| {
59-
parent.spawn(TextBundle::from_section(
60-
"Play",
61-
TextStyle {
62-
font: asset_server.load("fonts/FiraSans-Bold.ttf"),
63-
font_size: 40.0,
64-
color: Color::rgb(0.9, 0.9, 0.9),
65-
},
66-
));
55+
parent
56+
.spawn(ButtonBundle {
57+
style: Style {
58+
size: Size::new(Val::Px(150.0), Val::Px(65.0)),
59+
// horizontally center child text
60+
justify_content: JustifyContent::Center,
61+
// vertically center child text
62+
align_items: AlignItems::Center,
63+
..default()
64+
},
65+
background_color: NORMAL_BUTTON.into(),
66+
..default()
67+
})
68+
.with_children(|parent| {
69+
parent.spawn(TextBundle::from_section(
70+
"Play",
71+
TextStyle {
72+
font: asset_server.load("fonts/FiraSans-Bold.ttf"),
73+
font_size: 40.0,
74+
color: Color::rgb(0.9, 0.9, 0.9),
75+
},
76+
));
77+
});
6778
})
6879
.id();
6980
commands.insert_resource(MenuData { button_entity });

examples/games/alien_cake_addict.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -380,9 +380,9 @@ fn display_score(mut commands: Commands, asset_server: Res<AssetServer>, game: R
380380
commands
381381
.spawn(NodeBundle {
382382
style: Style {
383-
margin: UiRect::all(Val::Auto),
384-
justify_content: JustifyContent::Center,
383+
size: Size::new(Val::Percent(100.0), Val::Percent(100.0)),
385384
align_items: AlignItems::Center,
385+
justify_content: JustifyContent::Center,
386386
..default()
387387
},
388388
..default()

0 commit comments

Comments
 (0)