-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Remove the Val::try_*
arithmetic functions
#9571
Comments
I use fn move_background_cloud_images(
mut background_images: Query<&mut Style, With<IsBackgroundImage1>>,
time: Res<Time>,
) {
let speed = 10.0;
for mut image in background_images.iter_mut() {
image
.left
.try_sub_assign(Val::Px(speed * time.delta_seconds()))
.unwrap();
let Val::Px(bar) = image.left else { unreachable!() };
if bar < -1000.0 {
image.left.try_add_assign(Val::Px(1000.0)).unwrap();
}
}
} I agree that useless functions should be removed from the engine. And there are likely other ways to to what I did, but this is what I came up with using bevy docs. |
I'm fine to defer to you and remove these. |
That's a really helpful example. Rewritten using pattern matching it feels much more natural to me (hopefully I understood the intent of your code correctly): fn move_background_cloud_images_3(
mut background_images: Query<&mut Style, With<IsBackgroundImage1>>,
time: Res<Time>,
) {
let speed = 10.0;
for mut style in background_images.iter_mut() {
let Val::Px(ref mut bar) = style.left else { unreachable!(); };
*bar -= speed * time.delta_seconds();
if *bar < -1000. {
*bar += 1000.;
}
}
} |
Yes, that does the same job. Sorry for the poor variable name. |
Definitely think this is the way to go. They seem actively unhelpful and confusing. |
# Objective Remove `Val`'s `try_*` arithmetic methods. fixes #9571 ## Changelog Removed these methods from `bevy_ui::ui_node::Val`: - `try_add` - `try_sub` - `try_add_assign_with_size` - `try_sub_assign_with_size` - `try_add_assign` - `try_sub_assign` - `try_add_assign_with_size` - `try_sub_assign_with_size` ## Migration Guide `Val`'s `try_*` arithmetic methods have been removed. To perform arithmetic on `Val`s deconstruct them using pattern matching.
# Objective Remove `Val`'s `try_*` arithmetic methods. fixes bevyengine#9571 ## Changelog Removed these methods from `bevy_ui::ui_node::Val`: - `try_add` - `try_sub` - `try_add_assign_with_size` - `try_sub_assign_with_size` - `try_add_assign` - `try_sub_assign` - `try_add_assign_with_size` - `try_sub_assign_with_size` ## Migration Guide `Val`'s `try_*` arithmetic methods have been removed. To perform arithmetic on `Val`s deconstruct them using pattern matching.
What problem does this solve or what need does it fill?
Wondering if these are useful at all, or even make sense.
They aren't used internally or in any of the examples.
The
try_*_assign_with_size
functions seem problematic too:r.bottom
equalsVal::VMin(50.)
and is resolved to600. * 50. / 100. = 300.
.So
r.bottom
is assigned the value:Val::Px(350.)
.This might seem like it's okay. But now
r.bottom
is no longer responsive to changes in the viewport size.The text was updated successfully, but these errors were encountered: