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 ameknite committed Nov 6, 2023
1 parent 0c2e256 commit b63326e
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 b63326e

Please sign in to comment.