#[repr(C)]
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
pub struct Color(pub [u8; 4]);
impl Color {
pub const WHITE: Color = Color([255; 4]);
pub const BLACK: Color = Color([0, 0, 0, 255]);
pub const GRAY: Color = Color::from_rgb(128, 128, 128);
pub const RED: Color = Color::from_rgb(255, 0, 0);
pub const GREEN: Color = Color::from_rgb(0, 255, 0);
pub const BLUE: Color = Color::from_rgb(0, 0, 255);
pub const CYAN: Color = Color::from_rgb(0, 255, 255);
pub const MAGENTA: Color = Color::from_rgb(255, 0, 255);
pub const YELLOW: Color = Color::from_rgb(255, 255, 0);
pub const fn new(rgba: [u8; 4]) -> Self {
Color(rgba)
}
pub const fn from_rgb(r: u8, g: u8, b: u8) -> Self {
Color([r, g, b, 255])
}
pub const fn with_alpha(mut self, alpha: u8) -> Self {
self.0[3] = alpha;
self
}
}
impl From<Color> for [u8; 4] {
fn from(value: Color) -> Self {
value.0
}
}
impl From<Color> for wgpu::Color {
fn from(value: Color) -> Self {
let v = value.0;
let v = glam::DVec4::new(v[0] as f64, v[1] as f64, v[2] as f64, v[3] as f64) / 255.0;
wgpu::Color {
r: v.x,
g: v.y,
b: v.z,
a: v.w,
}
}
}