1#[derive(Clone, Copy)]
3pub struct Color {
4 pub r: u8,
6 pub g: u8,
8 pub b: u8,
10 pub a: u8
12}
13
14pub enum ColorPre {
16 Red,
17 Green,
18 Blue,
19 Black,
20 White,
21 Grey,
22 Default,
23 None
24}
25
26impl Into<Color> for ColorPre {
28 fn into(self) -> Color {
29 match self {
30 ColorPre::Red => Color::from((255, 0, 0, 255)),
31 ColorPre::Green => Color::from((0, 255, 0, 255)),
32 ColorPre::Blue => Color::from((0, 0, 255, 255)),
33 ColorPre::Black => Color::from((0, 0, 0, 255)),
34 ColorPre::White => Color::from((255, 255, 255, 255)),
35 ColorPre::Grey => Color::from((127, 127, 127, 255)),
36 ColorPre::Default => Color::from((0, 0, 0, 255)),
37 ColorPre::None => Color::from((0, 0, 0, 0)),
38 }
39 }
40}
41
42pub type ColorSvg = String;
44
45impl Default for Color {
46 fn default() -> Self {
47 ColorPre::Default.into()
48 }
49}
50
51impl From<(u8, u8, u8, u8)> for Color {
52 fn from(color: (u8, u8, u8, u8)) -> Self {
53 let (r, g, b, a) = color;
54
55 Self { r, g, b, a }
56 }
57}
58
59impl Into<ColorSvg> for Color {
60 fn into(self) -> ColorSvg {
61 let alpha = (self.a / 255) as f64;
62
63 format!("rgba({}, {}, {}, {})", self.r, self.g, self.b, alpha)
64 }
65}