Skip to main content

ggplot_rs/theme/
elements.rs

1/// Text element styling.
2#[derive(Clone, Debug)]
3pub struct ElementText {
4    pub family: String,
5    /// Font face (R's `element_text(face = ...)`).
6    pub face: crate::render::backend::FontFace,
7    pub size: f64,
8    pub color: (u8, u8, u8),
9    pub angle: f64,
10    pub hjust: f64,
11    pub vjust: f64,
12    pub visible: bool,
13}
14
15impl ElementText {
16    /// Create an invisible (blank) text element.
17    pub fn blank() -> Self {
18        ElementText {
19            visible: false,
20            ..Default::default()
21        }
22    }
23}
24
25impl Default for ElementText {
26    fn default() -> Self {
27        ElementText {
28            family: "sans-serif".to_string(),
29            face: crate::render::backend::FontFace::Plain,
30            size: 12.0,
31            color: (0, 0, 0),
32            angle: 0.0,
33            hjust: 0.5,
34            vjust: 0.5,
35            visible: true,
36        }
37    }
38}
39
40/// Line element styling.
41#[derive(Clone, Debug)]
42pub struct ElementLine {
43    pub color: (u8, u8, u8),
44    pub width: f64,
45    pub visible: bool,
46    /// Line style (R's `element_line(linetype = ...)`).
47    pub linetype: crate::render::backend::Linetype,
48}
49
50impl ElementLine {
51    /// Create an invisible (blank) line element.
52    pub fn blank() -> Self {
53        ElementLine {
54            visible: false,
55            ..Default::default()
56        }
57    }
58}
59
60impl Default for ElementLine {
61    fn default() -> Self {
62        ElementLine {
63            color: (0, 0, 0),
64            width: 1.0,
65            visible: true,
66            linetype: crate::render::backend::Linetype::Solid,
67        }
68    }
69}
70
71/// Rectangle element styling.
72#[derive(Clone, Debug)]
73pub struct ElementRect {
74    pub fill: Option<(u8, u8, u8)>,
75    pub color: Option<(u8, u8, u8)>,
76    pub width: f64,
77    pub visible: bool,
78}
79
80impl ElementRect {
81    /// Create an invisible (blank) rect element.
82    pub fn blank() -> Self {
83        ElementRect {
84            visible: false,
85            ..Default::default()
86        }
87    }
88}
89
90impl Default for ElementRect {
91    fn default() -> Self {
92        ElementRect {
93            fill: Some((255, 255, 255)),
94            color: None,
95            width: 0.0,
96            visible: true,
97        }
98    }
99}