Skip to content

Commit

Permalink
Implement Neg for Val (bevyengine#10295)
Browse files Browse the repository at this point in the history
# Objective

Implement `Neg` for `Val`
  • Loading branch information
ickshonpe authored and Ray Redondo committed Jan 9, 2024
1 parent fb29f05 commit 6db0f81
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions crates/bevy_ui/src/geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use bevy_reflect::ReflectDeserialize;
use bevy_reflect::ReflectSerialize;
use serde::Deserialize;
use serde::Serialize;
use std::ops::Neg;
use std::ops::{Div, DivAssign, Mul, MulAssign};
use thiserror::Error;

Expand Down Expand Up @@ -154,6 +155,22 @@ impl DivAssign<f32> for Val {
}
}

impl Neg for Val {
type Output = Val;

fn neg(self) -> Self::Output {
match self {
Val::Px(value) => Val::Px(-value),
Val::Percent(value) => Val::Percent(-value),
Val::Vw(value) => Val::Vw(-value),
Val::Vh(value) => Val::Vh(-value),
Val::VMin(value) => Val::VMin(-value),
Val::VMax(value) => Val::VMax(-value),
_ => self,
}
}
}

#[derive(Debug, Eq, PartialEq, Clone, Copy, Error)]
pub enum ValArithmeticError {
#[error("the variants of the Vals don't match")]
Expand Down

0 comments on commit 6db0f81

Please sign in to comment.