use bevy_reflect::Reflect; use glam::Vec2; use std::ops::{Add, AddAssign}; /// A two dimensional "size" as defined by a width and height #[derive(Copy, Clone, PartialEq, Debug, Reflect)] pub struct Size { pub width: T, pub height: T, } impl Size { pub fn new(width: T, height: T) -> Self { Size { width, height } } } impl Default for Size { fn default() -> Self { Self { width: Default::default(), height: Default::default(), } } } /// A rect, as defined by its "side" locations #[derive(Copy, Clone, PartialEq, Debug, Reflect)] pub struct Rect { pub left: T, pub right: T, pub top: T, pub bottom: T, } impl Rect { pub fn all(value: T) -> Self where T: Clone, { Rect { left: value.clone(), right: value.clone(), top: value.clone(), bottom: value, } } } impl Default for Rect { fn default() -> Self { Self { left: Default::default(), right: Default::default(), top: Default::default(), bottom: Default::default(), } } } impl Add for Size where T: Add, { type Output = Size; fn add(self, rhs: Vec2) -> Self::Output { Self { width: self.width + rhs.x, height: self.height + rhs.y, } } } impl AddAssign for Size where T: AddAssign, { fn add_assign(&mut self, rhs: Vec2) { self.width += rhs.x; self.height += rhs.y; } }