-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Add Val::Zero
#9533
Comments
Having different representations of zero is annoying but I'm not sure another variant would help. Like now we not only have I've suggested before that we change all the UI functions to take impl From<f32> for Val {
fn from(value: f32) -> Self {
Val::Px(value)
}
} to enable: margin: UiRect::all(0.0), It wasn't a popular idea though and I withdrew the PR. |
Link to PR mentioned above: #7500 |
As far as I see it, the problem with #7500 is the ambiguity between units. Of course, it is somewhat paradoxical to complain about too many options and trying to fix the problem by adding another option. However, I personally find it more elegant to use |
|
Yeah, that's not so bad. |
This got me thinking, and I realised that the |
I think we should go with the const approach instead of another variant, because of the multiple representations problem. |
# Objective - Fixes #9533 ## Solution * Added `Val::ZERO` as a constant which is defined as `Val::Px(0.)`. * Added manual `PartialEq` implementation for `Val` which allows any zero value to equal any other zero value. E.g., `Val::Px(0.) == Val::Percent(0.)` etc. This is technically a breaking change, as `Val::Px(0.) == Val::Percent(0.)` now equals `true` instead of `false` (as an example) * Replaced instances of `Val::Px(0.)`, `Val::Percent(0.)`, etc. with `Val::ZERO` * Fixed `bevy_ui::layout::convert::tests::test_convert_from` test to account for Taffy not equating `Points(0.)` and `Percent(0.)`. These tests now use `assert_eq!(...)` instead of `assert!(matches!(...))` which gives easier to diagnose error messages.
What problem does this solve or what need does it fill?
When requesting a UI length of zero, there is no clear choice of unit.
In CSS e.g., the zero literal does not have to be followed by any unit:
What solution would you like?
Add the
Val::Zero
case to theui_node::Val
enum.What alternative(s) have you considered?
Just continue using
Val::Px(0.0)
/Val::Percent(0.0)
/ etc.Additional context
https://stackoverflow.com/questions/7923042/when-specifying-a-0-value-in-css-should-i-explicitly-mark-the-units-or-omit
The text was updated successfully, but these errors were encountered: