#[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 RED: Color = Color([255, 0, 0, 255]);
pub const GREEN: Color = Color([0, 255, 0, 255]);
pub const BLUE: Color = Color([0, 0, 255, 255]);
pub fn new(rgba: [u8; 4]) -> Self {
Color(rgba)
}
}
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,
}
}
}