summaryrefslogtreecommitdiffstats
path: root/svgbob/src/settings.rs
blob: addba2630450ed694177bd20e52028a75b505d95 (plain)
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
#[derive(Debug, Clone)]
pub struct Settings {
    pub text_width: f32,
    pub text_height: f32,
    /// the svg class of the generated svg
    pub class: Option<String>,
    /// the id of the generated svg
    pub id: Option<String>,
    /// the font family used for text (default: arial)
    pub font_family: String,
    /// the font size used for text (default: 14)
    pub font_size: f32,
    /// stroke width for all lines (default: 2.0)
    pub stroke_width: f32,
    /// stroke color, default black
    pub stroke_color: String,
    /// background color: default white
    pub background_color: String
}

impl Settings {
    pub fn set_size(&mut self, text_width: f32, text_height: f32) {
        self.text_width = text_width;
        self.text_height = text_height;
    }

    pub fn scale(&mut self, scale: f32) {
        self.text_width = self.text_width * scale;
        self.text_height = self.text_height * scale;
        self.font_size = self.font_size * scale;
        self.stroke_width = self.stroke_width * scale;
    }

}

impl Default for Settings {
    fn default() -> Settings {
        Settings {
            text_width: 8.0,
            text_height: 16.0,
            class: Some("bob".to_string()),
            id: None,
            font_family: "arial".to_string(),
            font_size: 14.0,
            stroke_width: 2.0,
            stroke_color: "currentColor".into(),
            background_color: "white".into(),
        }
    }
}