1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use serde::{Serialize, Deserialize};

use super::{Color, Material};

/// A color or pattern for filling or stroking.
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase", rename_all_fields = "camelCase")]
pub enum Style {
    Color { color: Color },
    Hierarchical { level: usize },
    Material { material: Material },
}

impl Style {
    pub const PRIMARY: Self = Self::hierarchical(0);
    pub const SECONDARY: Self = Self::hierarchical(1);
    pub const TERTIARY: Self = Self::hierarchical(2);
    pub const QUATERNARY: Self = Self::hierarchical(3);
    pub const QUINARY: Self = Self::hierarchical(4);

    pub const fn color(color: Color) -> Self {
        Self::Color { color }
    }

    pub const fn hierarchical(level: usize) -> Self {
        Self::Hierarchical { level }
    }

    pub const fn material(material: Material) -> Self {
        Self::Material { material }
    }
}

impl From<Color> for Style {
    fn from(color: Color) -> Self {
        Self::Color { color }
    }
}

impl From<Material> for Style {
    fn from(material: Material) -> Self {
        Self::Material { material }
    }
}