-
-
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
Conversation
* fixed `Size::width` and `Size::height` using `Val::DEFAULT` instead of `Val::AUTO` * added tests to ensure correct defaults. * Simplified the UI examples. Replaced explicit values with the flex property enums where possible, removed values that can be ellided, and removed the remaining use of auto margins.
Not sure whether the height/width fix needs a migration guide, as the functions are recent additions and it takes them to the natural behaviour you'd expect. |
Size
helper functions using the wrong default value and improve the UI examples
It looks like your PR is a breaking change, but you didn't provide a migration guide. Could you add some context on what users should update when this change get released in a new version of Bevy? |
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.
A couple of comments. Otherwise LGTM.
margin: UiRect { | ||
left: Val::Auto, | ||
right: Val::Auto, | ||
..default() | ||
}, |
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.
Auto margins are not the default (or should not be). For margins, "auto" means "take up available space". The default margin is zero.
margin: UiRect { | ||
left: Val::Auto, | ||
right: Val::Auto, | ||
..default() | ||
}, |
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.
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 comment
The 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.
The default for margins is Px(0.) as you'd expect.
In both cases, if you look above you can see that I replaced the auto margins with an AlignItems::Center
on the parent.
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.
Ah, gotcha.
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.
No wait the default is still Val::Undefined
, that fix is in the remove Val::Undefined
PR and hasn't been merged yet. It's getting hard to keep track, really do need these tests.
#[test] | ||
fn test_size_width() { | ||
let width = Val::Px(10.); | ||
|
||
assert_eq!( | ||
Size::width(width), | ||
Size { | ||
width, | ||
..Default::default() | ||
} | ||
); | ||
} | ||
|
||
#[test] | ||
fn test_size_height() { | ||
let height = Val::Px(7.); | ||
|
||
assert_eq!( | ||
Size::height(height), | ||
Size { | ||
height, | ||
..Default::default() | ||
} | ||
); | ||
} |
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
.
bors r+ |
…rove the UI examples (#7626) # Objective `Size::width` sets the `height` field to `Val::DEFAULT` which is `Val::Undefined`, but the default for `Size` `height` is `Val::Auto`. `Size::height` has the same problem, but with the `width` field. The UI examples specify numeric values in many places where they could either be elided or replaced by composition of the Flex enum properties. related: #7468 fixes: #6498 ## Solution Change `Size::width` so it sets `height` to `Val::AUTO` and change `Size::height` so it sets `width` to `Val::AUTO`. Added some tests so this doesn't happen again. ## Changelog Changed `Size::width` so it sets the `height` to `Val::AUTO`. Changed `Size::height` so it sets the `width` to `Val::AUTO`. Added tests to `geometry.rs` for `Size` and `UiRect` to ensure correct behaviour. Simplified the UI examples. Replaced numeric values with the Flex property enums or elided them where possible, and removed the remaining use of auto margins. ## Migration Guide The `Size::width` constructor function now sets the `height` to `Val::Auto` instead of `Val::Undefined`. The `Size::height` constructor function now sets the `width` to `Val::Auto` instead of `Val::Undefined`.
Pull request successfully merged into main. Build succeeded:
|
Size
helper functions using the wrong default value and improve the UI examples Size
helper functions using the wrong default value and improve the UI examples
…rove the UI examples (bevyengine#7626) # Objective `Size::width` sets the `height` field to `Val::DEFAULT` which is `Val::Undefined`, but the default for `Size` `height` is `Val::Auto`. `Size::height` has the same problem, but with the `width` field. The UI examples specify numeric values in many places where they could either be elided or replaced by composition of the Flex enum properties. related: bevyengine#7468 fixes: bevyengine#6498 ## Solution Change `Size::width` so it sets `height` to `Val::AUTO` and change `Size::height` so it sets `width` to `Val::AUTO`. Added some tests so this doesn't happen again. ## Changelog Changed `Size::width` so it sets the `height` to `Val::AUTO`. Changed `Size::height` so it sets the `width` to `Val::AUTO`. Added tests to `geometry.rs` for `Size` and `UiRect` to ensure correct behaviour. Simplified the UI examples. Replaced numeric values with the Flex property enums or elided them where possible, and removed the remaining use of auto margins. ## Migration Guide The `Size::width` constructor function now sets the `height` to `Val::Auto` instead of `Val::Undefined`. The `Size::height` constructor function now sets the `width` to `Val::Auto` instead of `Val::Undefined`.
…rove the UI examples (bevyengine#7626) # Objective `Size::width` sets the `height` field to `Val::DEFAULT` which is `Val::Undefined`, but the default for `Size` `height` is `Val::Auto`. `Size::height` has the same problem, but with the `width` field. The UI examples specify numeric values in many places where they could either be elided or replaced by composition of the Flex enum properties. related: bevyengine#7468 fixes: bevyengine#6498 ## Solution Change `Size::width` so it sets `height` to `Val::AUTO` and change `Size::height` so it sets `width` to `Val::AUTO`. Added some tests so this doesn't happen again. ## Changelog Changed `Size::width` so it sets the `height` to `Val::AUTO`. Changed `Size::height` so it sets the `width` to `Val::AUTO`. Added tests to `geometry.rs` for `Size` and `UiRect` to ensure correct behaviour. Simplified the UI examples. Replaced numeric values with the Flex property enums or elided them where possible, and removed the remaining use of auto margins. ## Migration Guide The `Size::width` constructor function now sets the `height` to `Val::Auto` instead of `Val::Undefined`. The `Size::height` constructor function now sets the `width` to `Val::Auto` instead of `Val::Undefined`.
Objective
Size::width
sets theheight
field toVal::DEFAULT
which isVal::Undefined
, but the default forSize
height
isVal::Auto
.Size::height
has the same problem, but with thewidth
field.The UI examples specify numeric values in many places where they could either be elided or replaced by composition of the Flex enum properties.
related: #7468
fixes: #6498
Solution
Change
Size::width
so it setsheight
toVal::AUTO
and changeSize::height
so it setswidth
toVal::AUTO
.Added some tests so this doesn't happen again.
Changelog
Changed
Size::width
so it sets theheight
toVal::AUTO
.Changed
Size::height
so it sets thewidth
toVal::AUTO
.Added tests to
geometry.rs
forSize
andUiRect
to ensure correct behaviour.Simplified the UI examples. Replaced numeric values with the Flex property enums or elided them where possible, and removed the remaining use of auto margins.
Migration Guide
The
Size::width
constructor function now sets theheight
toVal::Auto
instead ofVal::Undefined
.The
Size::height
constructor function now sets thewidth
toVal::Auto
instead ofVal::Undefined
.