Skip to content

Commit

Permalink
Remove auto-margin properties from the examples (bevyengine#6535)
Browse files Browse the repository at this point in the history
# 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.
  • Loading branch information
garychia authored and taiyoungjang committed Dec 15, 2022
1 parent 1beea71 commit b5eb147
Show file tree
Hide file tree
Showing 6 changed files with 499 additions and 377 deletions.
39 changes: 25 additions & 14 deletions examples/ecs/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,29 +41,40 @@ fn setup(mut commands: Commands) {

fn setup_menu(mut commands: Commands, asset_server: Res<AssetServer>) {
let button_entity = commands
.spawn(ButtonBundle {
.spawn(NodeBundle {
style: Style {
size: Size::new(Val::Px(150.0), Val::Px(65.0)),
// center button
margin: UiRect::all(Val::Auto),
// horizontally center child text
size: Size::new(Val::Percent(100.0), Val::Percent(100.0)),
justify_content: JustifyContent::Center,
// vertically center child text
align_items: AlignItems::Center,
..default()
},
background_color: NORMAL_BUTTON.into(),
..default()
})
.with_children(|parent| {
parent.spawn(TextBundle::from_section(
"Play",
TextStyle {
font: asset_server.load("fonts/FiraSans-Bold.ttf"),
font_size: 40.0,
color: Color::rgb(0.9, 0.9, 0.9),
},
));
parent
.spawn(ButtonBundle {
style: Style {
size: Size::new(Val::Px(150.0), Val::Px(65.0)),
// horizontally center child text
justify_content: JustifyContent::Center,
// vertically center child text
align_items: AlignItems::Center,
..default()
},
background_color: NORMAL_BUTTON.into(),
..default()
})
.with_children(|parent| {
parent.spawn(TextBundle::from_section(
"Play",
TextStyle {
font: asset_server.load("fonts/FiraSans-Bold.ttf"),
font_size: 40.0,
color: Color::rgb(0.9, 0.9, 0.9),
},
));
});
})
.id();
commands.insert_resource(MenuData { button_entity });
Expand Down
4 changes: 2 additions & 2 deletions examples/games/alien_cake_addict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,9 +380,9 @@ fn display_score(mut commands: Commands, asset_server: Res<AssetServer>, game: R
commands
.spawn(NodeBundle {
style: Style {
margin: UiRect::all(Val::Auto),
justify_content: JustifyContent::Center,
size: Size::new(Val::Percent(100.0), Val::Percent(100.0)),
align_items: AlignItems::Center,
justify_content: JustifyContent::Center,
..default()
},
..default()
Expand Down
Loading

0 comments on commit b5eb147

Please sign in to comment.