#[derive(Clone, Copy)]
pub struct Color {
pub r: u8,
pub g: u8,
pub b: u8,
pub a: u8
}
pub enum ColorPre {
Red,
Green,
Blue,
Black,
White,
Grey,
Default,
None
}
impl Into<Color> for ColorPre {
fn into(self) -> Color {
match self {
ColorPre::Red => Color::from((255, 0, 0, 255)),
ColorPre::Green => Color::from((0, 255, 0, 255)),
ColorPre::Blue => Color::from((0, 0, 255, 255)),
ColorPre::Black => Color::from((0, 0, 0, 255)),
ColorPre::White => Color::from((255, 255, 255, 255)),
ColorPre::Grey => Color::from((127, 127, 127, 255)),
ColorPre::Default => Color::from((0, 0, 0, 255)),
ColorPre::None => Color::from((0, 0, 0, 0)),
}
}
}
pub type ColorSvg = String;
impl Default for Color {
fn default() -> Self {
ColorPre::Default.into()
}
}
impl From<(u8, u8, u8, u8)> for Color {
fn from(color: (u8, u8, u8, u8)) -> Self {
let (r, g, b, a) = color;
Self { r, g, b, a }
}
}
impl Into<ColorSvg> for Color {
fn into(self) -> ColorSvg {
let alpha = (self.a / 255) as f64;
format!("rgba({}, {}, {}, {})", self.r, self.g, self.b, alpha)
}
}