charming_fork_zephyr/element/
background.rs

1use serde::Serialize;
2
3use super::{area_style::AreaStyle, border_type::BorderType, color::Color, line_style::LineStyle};
4
5#[derive(Serialize)]
6#[serde(rename_all = "camelCase")]
7pub struct BackgroundStyle {
8    #[serde(skip_serializing_if = "Option::is_none")]
9    color: Option<Color>,
10
11    #[serde(skip_serializing_if = "Option::is_none")]
12    border_color: Option<Color>,
13
14    #[serde(skip_serializing_if = "Option::is_none")]
15    border_width: Option<i64>,
16
17    #[serde(skip_serializing_if = "Option::is_none")]
18    border_type: Option<BorderType>,
19
20    #[serde(skip_serializing_if = "Option::is_none")]
21    border_radius: Option<i64>,
22
23    #[serde(skip_serializing_if = "Option::is_none")]
24    opacity: Option<i64>,
25}
26
27impl BackgroundStyle {
28    pub fn new() -> Self {
29        Self {
30            color: None,
31            border_color: None,
32            border_width: None,
33            border_type: None,
34            border_radius: None,
35            opacity: None,
36        }
37    }
38
39    pub fn color<C: Into<Color>>(mut self, color: C) -> Self {
40        self.color = Some(color.into());
41        self
42    }
43
44    pub fn border_color<C: Into<Color>>(mut self, border_color: C) -> Self {
45        self.border_color = Some(border_color.into());
46        self
47    }
48
49    pub fn border_width<F: Into<i64>>(mut self, border_width: F) -> Self {
50        self.border_width = Some(border_width.into());
51        self
52    }
53
54    pub fn border_type<B: Into<BorderType>>(mut self, border_type: B) -> Self {
55        self.border_type = Some(border_type.into());
56        self
57    }
58
59    pub fn border_radius<F: Into<i64>>(mut self, border_radius: F) -> Self {
60        self.border_radius = Some(border_radius.into());
61        self
62    }
63
64    pub fn opacity<F: Into<i64>>(mut self, opacity: F) -> Self {
65        self.opacity = Some(opacity.into());
66        self
67    }
68}
69
70#[derive(Serialize)]
71#[serde(rename_all = "camelCase")]
72pub struct DataBackground {
73    #[serde(skip_serializing_if = "Option::is_none")]
74    line_style: Option<LineStyle>,
75
76    #[serde(skip_serializing_if = "Option::is_none")]
77    area_style: Option<AreaStyle>,
78}
79
80impl DataBackground {
81    pub fn new() -> Self {
82        Self {
83            line_style: None,
84            area_style: None,
85        }
86    }
87
88    pub fn line_style<L: Into<LineStyle>>(mut self, line_style: L) -> Self {
89        self.line_style = Some(line_style.into());
90        self
91    }
92
93    pub fn area_style<A: Into<AreaStyle>>(mut self, area_style: A) -> Self {
94        self.area_style = Some(area_style.into());
95        self
96    }
97}