-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Merged by Bors] - Fix the Size
helper functions using the wrong default value and improve the UI examples
#7626
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) { | |
commands | ||
.spawn(NodeBundle { | ||
style: Style { | ||
size: Size::new(Val::Percent(100.0), Val::Percent(100.0)), | ||
size: Size::width(Val::Percent(100.0)), | ||
justify_content: JustifyContent::SpaceBetween, | ||
..default() | ||
}, | ||
|
@@ -35,7 +35,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) { | |
parent | ||
.spawn(NodeBundle { | ||
style: Style { | ||
size: Size::new(Val::Px(200.0), Val::Percent(100.0)), | ||
size: Size::width(Val::Px(200.0)), | ||
border: UiRect::all(Val::Px(2.0)), | ||
..default() | ||
}, | ||
|
@@ -47,7 +47,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) { | |
parent | ||
.spawn(NodeBundle { | ||
style: Style { | ||
size: Size::new(Val::Percent(100.0), Val::Percent(100.0)), | ||
size: Size::width(Val::Percent(100.0)), | ||
..default() | ||
}, | ||
background_color: Color::rgb(0.15, 0.15, 0.15).into(), | ||
|
@@ -77,7 +77,8 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) { | |
style: Style { | ||
flex_direction: FlexDirection::Column, | ||
justify_content: JustifyContent::Center, | ||
size: Size::new(Val::Px(200.0), Val::Percent(100.0)), | ||
align_items: AlignItems::Center, | ||
size: Size::width(Val::Px(200.0)), | ||
..default() | ||
}, | ||
background_color: Color::rgb(0.15, 0.15, 0.15).into(), | ||
|
@@ -95,12 +96,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) { | |
}, | ||
) | ||
.with_style(Style { | ||
size: Size::new(Val::Undefined, Val::Px(25.)), | ||
margin: UiRect { | ||
left: Val::Auto, | ||
right: Val::Auto, | ||
..default() | ||
}, | ||
Comment on lines
-99
to
-103
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Auto margins are not the default (or should not be). For margins, "auto" means "take up available space". The default margin is zero. |
||
size: Size::height(Val::Px(25.)), | ||
..default() | ||
}), | ||
); | ||
|
@@ -109,8 +105,8 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) { | |
.spawn(NodeBundle { | ||
style: Style { | ||
flex_direction: FlexDirection::Column, | ||
align_self: AlignSelf::Center, | ||
size: Size::new(Val::Percent(100.0), Val::Percent(50.0)), | ||
align_self: AlignSelf::Stretch, | ||
size: Size::height(Val::Percent(50.0)), | ||
overflow: Overflow::Hidden, | ||
..default() | ||
}, | ||
|
@@ -126,6 +122,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) { | |
flex_direction: FlexDirection::Column, | ||
flex_grow: 1.0, | ||
max_size: Size::UNDEFINED, | ||
align_items: AlignItems::Center, | ||
..default() | ||
}, | ||
..default() | ||
|
@@ -148,11 +145,6 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) { | |
.with_style(Style { | ||
flex_shrink: 0., | ||
size: Size::new(Val::Undefined, Val::Px(20.)), | ||
margin: UiRect { | ||
left: Val::Auto, | ||
right: Val::Auto, | ||
..default() | ||
}, | ||
Comment on lines
-151
to
-155
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Auto margins are not the default (or should not be). For margins, "auto" means "take up available space". The default margin is zero. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh I couldn't work out what you meant here for a moment. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, gotcha. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No wait the default is still |
||
..default() | ||
}), | ||
); | ||
|
@@ -211,7 +203,8 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) { | |
.with_children(|parent| { | ||
parent.spawn(NodeBundle { | ||
style: Style { | ||
size: Size::new(Val::Px(100.0), Val::Px(100.0)), | ||
// Take the size of the parent node. | ||
size: Size::all(Val::Percent(100.)), | ||
position_type: PositionType::Absolute, | ||
position: UiRect { | ||
left: Val::Px(20.0), | ||
|
@@ -225,7 +218,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) { | |
}); | ||
parent.spawn(NodeBundle { | ||
style: Style { | ||
size: Size::new(Val::Px(100.0), Val::Px(100.0)), | ||
size: Size::all(Val::Percent(100.)), | ||
position_type: PositionType::Absolute, | ||
position: UiRect { | ||
left: Val::Px(40.0), | ||
|
@@ -239,7 +232,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) { | |
}); | ||
parent.spawn(NodeBundle { | ||
style: Style { | ||
size: Size::new(Val::Px(100.0), Val::Px(100.0)), | ||
size: Size::all(Val::Percent(100.)), | ||
position_type: PositionType::Absolute, | ||
position: UiRect { | ||
left: Val::Px(60.0), | ||
|
@@ -254,7 +247,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) { | |
// alpha test | ||
parent.spawn(NodeBundle { | ||
style: Style { | ||
size: Size::new(Val::Px(100.0), Val::Px(100.0)), | ||
size: Size::all(Val::Percent(100.)), | ||
position_type: PositionType::Absolute, | ||
position: UiRect { | ||
left: Val::Px(80.0), | ||
|
@@ -272,7 +265,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) { | |
parent | ||
.spawn(NodeBundle { | ||
style: Style { | ||
size: Size::new(Val::Percent(100.0), Val::Percent(100.0)), | ||
size: Size::width(Val::Percent(100.)), | ||
position_type: PositionType::Absolute, | ||
justify_content: JustifyContent::Center, | ||
align_items: AlignItems::FlexStart, | ||
|
@@ -284,7 +277,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) { | |
// bevy logo (image) | ||
parent.spawn(ImageBundle { | ||
style: Style { | ||
size: Size::new(Val::Px(500.0), Val::Auto), | ||
size: Size::width(Val::Px(500.0)), | ||
..default() | ||
}, | ||
image: asset_server.load("branding/bevy_logo_dark_big.png").into(), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems to me that it might be better if these tested that you get
Auto
rather than..Default::default()
. If the default changed this test wouldn't catch the issue.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The purpose of these two tests is to ensure that the helper functions return the same result as setting the field directly and leaving the rest of the struct as default (whatever default it is) as a user would naturally assume.
I'll put in a separate assertion to ensure the default is
Auto
.