UI examples clean up (#9479)

# 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.
This commit is contained in:
ickshonpe 2023-08-23 13:49:10 +01:00 committed by GitHub
parent 20c85b5fc3
commit 373f1eeb1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 1 additions and 13 deletions

View File

@ -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,

View File

@ -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()
},

View File

@ -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()

View File

@ -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),

View File

@ -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 {

View File

@ -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()
},

View File

@ -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,

View File

@ -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()
},