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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//! Vector object styles; Fill and Stroke data
use crate::RGB;

/// Shape fill
#[derive(Clone, Debug, Default, PartialEq)]
pub struct Fill {
    pub color: RGB,
    // todo: Opacity
}

impl Fill {
    pub fn new(color: RGB) -> Fill {
        Fill { color }
    }
}

/// Shape stroke
#[derive(Clone, Debug, Default, PartialEq)]
pub struct Stroke {
    pub width: u32,
    pub color: RGB,
}

impl Stroke {
    pub fn new(width: u32, color: RGB) -> Stroke {
        Stroke { width, color }
    }
}

/// Optional Fill and Stroke
#[derive(Default, Clone, Debug, PartialEq)]
pub struct Style {
    pub fill: Option<Fill>,
    pub stroke: Option<Stroke>,
}

impl Style {
    /// Default empty style with no fill or stroke
    pub fn default() -> Style {
        Style {
            fill: None,
            stroke: None,
        }
    }

    /// New style with both fill and stroke
    pub fn new(fill: Fill, stroke: Stroke) -> Style {
        Style {
            fill: Some(fill),
            stroke: Some(stroke),
        }
    }

    /// New style with only a solid fill color and no stroke
    pub fn filled(color: RGB) -> Style {
        Style {
            fill: Some(Fill::new(color)),
            stroke: None,
        }
    }

    /// New style with only a stroke and no fill
    pub fn stroked(width: u32, color: RGB) -> Style {
        Style {
            fill: None,
            stroke: Some(Stroke::new(width, color)),
        }
    }
}