#![allow(clippy::multiple_bound_locations)] #[repr(C)] #[derive(Clone, Copy, bytemuck::Zeroable)] pub struct Color { pub r: T, pub g: T, pub b: T, pub a: T, } impl Color { pub const BLACK: Self = Self::rgb(T::MIN, T::MIN, T::MIN); pub const WHITE: Self = Self::rgb(T::MAX, T::MAX, T::MAX); pub const RED: Self = Self::rgb(T::MAX, T::MIN, T::MIN); pub const ORANGE: Self = Self::rgb(T::MAX, T::MID, T::MIN); pub const YELLOW: Self = Self::rgb(T::MAX, T::MAX, T::MIN); pub const LIME: Self = Self::rgb(T::MID, T::MAX, T::MIN); pub const GREEN: Self = Self::rgb(T::MIN, T::MAX, T::MIN); pub const CYAN: Self = Self::rgb(T::MIN, T::MAX, T::MAX); pub const BLUE: Self = Self::rgb(T::MIN, T::MIN, T::MAX); pub const MAGENTA: Self = Self::rgb(T::MAX, T::MIN, T::MAX); } impl Color { pub const fn new(r: T, g: T, b: T, a: T) -> Self { Self { r, g, b, a } } pub const fn rgb(r: T, g: T, b: T) -> Self { Self { r, g, b, a: T::MAX } } pub fn alpha(mut self, a: T) -> Self { self.a = a; self } } pub trait ColorNum { const MIN: Self; const MID: Self; const MAX: Self; } impl ColorNum for u8 { const MIN: Self = u8::MIN; const MID: Self = u8::MAX / 2; const MAX: Self = u8::MAX; } unsafe impl bytemuck::Pod for Color {}