Skip to content
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] - Utility methods for Val #6134

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
71056a3
made resource_scope work for non-send resources
Pietrek14 Sep 27, 2022
d607e6b
Merge branch 'bevyengine:main' into main
Pietrek14 Sep 27, 2022
83f2417
fixed the non-send resource scope tests
Pietrek14 Sep 27, 2022
6da0e41
formatting
Pietrek14 Sep 27, 2022
3500039
simplified panic in a non-send resource scope test
Pietrek14 Sep 28, 2022
d823b1b
Merge branch 'bevyengine:main' into main
Pietrek14 Sep 28, 2022
f68eb33
changed the name of non-send struct used for testing
Pietrek14 Sep 28, 2022
56a5dd7
added arithmetic functions for Val
Pietrek14 Sep 29, 2022
ad9da5f
removed adding and subtracting of val with f32
Pietrek14 Sep 29, 2022
fef5ead
Merge branch 'bevyengine:main' into val-arithmetic
Pietrek14 Sep 30, 2022
c9dfd36
changed the names of val methods to be more in line with the standard…
Pietrek14 Oct 1, 2022
cb577bc
formatting
Pietrek14 Oct 1, 2022
1fb6049
deleted warnings from Val::try_add and Val::try_sub
Pietrek14 Oct 4, 2022
7b33282
deleted unnecessary use
Pietrek14 Oct 4, 2022
bd2240f
Val::evaluate returns f32
Pietrek14 Oct 4, 2022
3c57795
clippy
Pietrek14 Oct 4, 2022
e039468
added docs for Add and Subs impls for Size struct
Pietrek14 Oct 4, 2022
69fa054
formatting
Pietrek14 Oct 5, 2022
2fdb45c
replace add and sub impls for Size struct with from<(Val, Val)>
Pietrek14 Oct 5, 2022
da41750
ValArithmeticError derives Clone and Copy
Pietrek14 Oct 5, 2022
769362c
added error messages to ValArithmeticError
Pietrek14 Oct 5, 2022
495fef9
made the docs for Val::try_add_assign_with_size not reference self wh…
Pietrek14 Oct 5, 2022
54ef797
formatting
Pietrek14 Oct 5, 2022
a8e9ca9
doc comments for Val::try_add_assign and Val::try_sub_assign
Pietrek14 Oct 17, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/bevy_ui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ taffy = "0.1.0"
serde = { version = "1", features = ["derive"] }
smallvec = { version = "1.6", features = ["union", "const_generics"] }
bytemuck = { version = "1.5", features = ["derive"] }
thiserror = "1.0.37"
63 changes: 12 additions & 51 deletions crates/bevy_ui/src/geometry.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::Val;
use bevy_math::Vec2;
use bevy_reflect::Reflect;
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign};
use std::ops::{Div, DivAssign, Mul, MulAssign};

/// A type which is commonly used to define positions, margins, paddings and borders.
///
Expand Down Expand Up @@ -356,42 +355,15 @@ impl Size {
};
}

impl Add<Vec2> for Size {
type Output = Size;

fn add(self, rhs: Vec2) -> Self::Output {
Self {
width: self.width + rhs.x,
height: self.height + rhs.y,
}
}
}

impl AddAssign<Vec2> for Size {
fn add_assign(&mut self, rhs: Vec2) {
self.width += rhs.x;
self.height += rhs.y;
}
}

impl Sub<Vec2> for Size {
type Output = Size;

fn sub(self, rhs: Vec2) -> Self::Output {
impl From<(Val, Val)> for Size {
fn from(vals: (Val, Val)) -> Self {
Self {
width: self.width - rhs.x,
height: self.height - rhs.y,
width: vals.0,
height: vals.1,
}
}
}

impl SubAssign<Vec2> for Size {
fn sub_assign(&mut self, rhs: Vec2) {
self.width -= rhs.x;
self.height -= rhs.y;
}
}

impl Mul<f32> for Size {
type Output = Size;

Expand Down Expand Up @@ -433,27 +405,16 @@ mod tests {
use super::*;

#[test]
fn test_size_add() {
assert_eq!(
Size::new(Val::Px(10.), Val::Px(10.)) + Vec2::new(10., 10.),
Size::new(Val::Px(20.), Val::Px(20.))
);
fn test_size_from() {
let size: Size = (Val::Px(20.), Val::Px(30.)).into();

let mut size = Size::new(Val::Px(10.), Val::Px(10.));
size += Vec2::new(10., 10.);
assert_eq!(size, Size::new(Val::Px(20.), Val::Px(20.)));
}

#[test]
fn test_size_sub() {
assert_eq!(
Size::new(Val::Px(20.), Val::Px(20.)) - Vec2::new(10., 10.),
Size::new(Val::Px(10.), Val::Px(10.))
size,
Size {
width: Val::Px(20.),
height: Val::Px(30.),
}
);

let mut size = Size::new(Val::Px(20.), Val::Px(20.));
size -= Vec2::new(10., 10.);
assert_eq!(size, Size::new(Val::Px(10.), Val::Px(10.)));
}

#[test]
Expand Down
Loading