Skip to content

Commit

Permalink
UI examples clean up (#9479)
Browse files Browse the repository at this point in the history
# Objective

Fix a few issues with some of the examples:

* Root UI nodes have an implicit parent with `FlexDirection::Row` and
`AlignItems::Stretch` set. Only a width constraint is needed to fill the
viewport. Specifying ```height: Val::Percent(100.)``` is unnecessary and
can cause confusing overflow behaviour.

* The default for position and size constraint properties is
`Val::Auto`. Setting `left: Val::Auto`, `max_height: Val::Auto`, etc
does nothing.


## Solution

Delete those lines. There should be no observable differences in the
behaviours of any of the examples.

Also changed a padding setting in the `flex_layout` example to use the
`axes` helper function.
  • Loading branch information
ickshonpe authored Aug 23, 2023
1 parent 20c85b5 commit 373f1ee
Show file tree
Hide file tree
Showing 8 changed files with 1 addition and 13 deletions.
1 change: 0 additions & 1 deletion examples/games/game_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ mod game {
NodeBundle {
style: Style {
width: Val::Percent(100.0),
height: Val::Percent(100.0),
// center children
align_items: AlignItems::Center,
justify_content: JustifyContent::Center,
Expand Down
1 change: 0 additions & 1 deletion examples/mobile/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ fn setup_scene(
position_type: PositionType::Absolute,
left: Val::Px(50.0),
right: Val::Px(50.0),
top: Val::Auto,
bottom: Val::Px(50.0),
..default()
},
Expand Down
1 change: 0 additions & 1 deletion examples/ui/display_and_visibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,6 @@ where
.spawn((
ButtonBundle {
style: Style {
//height: Val::Px(24.),
align_self: AlignSelf::FlexStart,
padding: UiRect::axes(Val::Px(5.), Val::Px(1.)),
..Default::default()
Expand Down
7 changes: 1 addition & 6 deletions examples/ui/flex_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,7 @@ fn spawn_nested_text_bundle(
.spawn(NodeBundle {
style: Style {
margin,
padding: UiRect {
top: Val::Px(1.),
left: Val::Px(5.),
right: Val::Px(5.),
bottom: Val::Px(1.),
},
padding: UiRect::axes(Val::Px(5.), Val::Px(1.)),
..Default::default()
},
background_color: BackgroundColor(background_color),
Expand Down
1 change: 0 additions & 1 deletion examples/ui/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ fn spawn_layout(mut commands: Commands, asset_server: Res<AssetServer>) {
width: Val::Percent(60.),
height: Val::Px(300.),
max_width: Val::Px(600.),
max_height: Val::Auto,
..default()
},
background_color: BackgroundColor(Color::Rgba {
Expand Down
1 change: 0 additions & 1 deletion examples/ui/overflow_debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
.spawn(NodeBundle {
style: Style {
width: Val::Percent(100.),
height: Val::Percent(100.),
flex_direction: FlexDirection::Column,
..default()
},
Expand Down
1 change: 0 additions & 1 deletion examples/ui/relative_cursor_position.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
.spawn(NodeBundle {
style: Style {
width: Val::Percent(100.),
height: Val::Percent(100.),
align_items: AlignItems::Center,
justify_content: JustifyContent::Center,
flex_direction: FlexDirection::Column,
Expand Down
1 change: 0 additions & 1 deletion examples/ui/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
.spawn(NodeBundle {
style: Style {
width: Val::Percent(100.0),
height: Val::Percent(100.0),
justify_content: JustifyContent::SpaceBetween,
..default()
},
Expand Down

0 comments on commit 373f1ee

Please sign in to comment.