charming_fork_zephyr/component/
title.rs

1use serde::Serialize;
2
3use crate::{
4    datatype::CompositeValue,
5    element::{Color, LinkTarget, Padding, TextAlign, TextStyle, TextVerticalAlign},
6};
7
8/// Title component, including main title and subtitle.
9#[derive(Serialize)]
10#[serde(rename_all = "camelCase")]
11pub struct Title {
12    /// Component ID.
13    #[serde(skip_serializing_if = "Option::is_none")]
14    id: Option<String>,
15
16    /// Whether to show the title component.
17    #[serde(skip_serializing_if = "Option::is_none")]
18    show: Option<bool>,
19
20    /// The main title text, supporting for `\n` for newlines.
21    #[serde(skip_serializing_if = "Option::is_none")]
22    text: Option<String>,
23
24    /// The hyper link of main title text.
25    #[serde(skip_serializing_if = "Option::is_none")]
26    link: Option<String>,
27
28    /// Open the hyper link of main title in specified target.
29    #[serde(skip_serializing_if = "Option::is_none")]
30    target: Option<LinkTarget>,
31
32    /// The text style of main title.
33    #[serde(skip_serializing_if = "Option::is_none")]
34    text_style: Option<TextStyle>,
35
36    /// The sub title text, supporting for `\n` for newlines.
37    #[serde(skip_serializing_if = "Option::is_none")]
38    subtext: Option<String>,
39
40    /// The hyper link of sub title text.
41    #[serde(skip_serializing_if = "Option::is_none")]
42    sublink: Option<String>,
43
44    /// Open the hyper link of sub title in specified target.
45    #[serde(skip_serializing_if = "Option::is_none")]
46    subtarget: Option<LinkTarget>,
47
48    /// The text style of sub title.
49    #[serde(skip_serializing_if = "Option::is_none")]
50    subtext_style: Option<TextStyle>,
51
52    /// The horizontal align of the component.
53    #[serde(skip_serializing_if = "Option::is_none")]
54    text_align: Option<TextAlign>,
55
56    /// The vertical align of the component.
57    #[serde(skip_serializing_if = "Option::is_none")]
58    text_vertical_align: Option<TextVerticalAlign>,
59
60    /// Title padding, the unit is px.
61    #[serde(skip_serializing_if = "Option::is_none")]
62    padding: Option<Padding>,
63
64    /// The gap between the main title and the sub title, the unit is px.
65    #[serde(skip_serializing_if = "Option::is_none")]
66    item_gap: Option<i64>,
67
68    /// The `zlevel` value of all graphical elements in the title.
69    #[serde(skip_serializing_if = "Option::is_none")]
70    zlevel: Option<i64>,
71
72    /// The `z` value of all graphical elements in the title.
73    #[serde(skip_serializing_if = "Option::is_none")]
74    z: Option<i64>,
75
76    /// Distance between title component and the left side of the container.
77    #[serde(skip_serializing_if = "Option::is_none")]
78    left: Option<CompositeValue>,
79
80    /// Distance between title component and the top side of the container.
81    #[serde(skip_serializing_if = "Option::is_none")]
82    top: Option<CompositeValue>,
83
84    /// Distance between title component and the right side of the container.
85    #[serde(skip_serializing_if = "Option::is_none")]
86    right: Option<CompositeValue>,
87
88    /// Distance between title component and the bottom side of the container.
89    #[serde(skip_serializing_if = "Option::is_none")]
90    bottom: Option<CompositeValue>,
91
92    /// Background color of title, default to be transparent.
93    #[serde(skip_serializing_if = "Option::is_none")]
94    background_color: Option<Color>,
95
96    /// Border color of title.
97    #[serde(skip_serializing_if = "Option::is_none")]
98    border_color: Option<Color>,
99
100    /// Border width of title.
101    #[serde(skip_serializing_if = "Option::is_none")]
102    border_width: Option<i64>,
103
104    /// Border radius of title.
105    #[serde(skip_serializing_if = "Option::is_none")]
106    border_radius: Option<i64>,
107
108    /// Shadow color of title.
109    #[serde(skip_serializing_if = "Option::is_none")]
110    shadow_color: Option<Color>,
111
112    /// Size of shadow blur.
113    #[serde(skip_serializing_if = "Option::is_none")]
114    shadow_blur: Option<i64>,
115
116    /// Offset distance on the horizontal direction of shadow.
117    #[serde(skip_serializing_if = "Option::is_none")]
118    shadow_offset_x: Option<i64>,
119
120    /// Offset distance on the vertical direction of shadow.
121    #[serde(skip_serializing_if = "Option::is_none")]
122    shadow_offset_y: Option<i64>,
123}
124
125impl Title {
126    pub fn new() -> Self {
127        Self {
128            id: None,
129            show: None,
130            text: None,
131            link: None,
132            target: None,
133            text_style: None,
134            subtext: None,
135            sublink: None,
136            subtarget: None,
137            subtext_style: None,
138            text_align: None,
139            text_vertical_align: None,
140            padding: None,
141            item_gap: None,
142            zlevel: None,
143            z: None,
144            left: None,
145            top: None,
146            right: None,
147            bottom: None,
148            background_color: None,
149            border_color: None,
150            border_width: None,
151            border_radius: None,
152            shadow_color: None,
153            shadow_blur: None,
154            shadow_offset_x: None,
155            shadow_offset_y: None,
156        }
157    }
158
159    pub fn show(mut self, show: bool) -> Self {
160        self.show = Some(show);
161        self
162    }
163
164    pub fn text<S: Into<String>>(mut self, text: S) -> Self {
165        self.text = Some(text.into());
166        self
167    }
168
169    pub fn link<S: Into<String>>(mut self, link: S) -> Self {
170        self.link = Some(link.into());
171        self
172    }
173
174    pub fn target<T: Into<LinkTarget>>(mut self, target: T) -> Self {
175        self.target = Some(target.into());
176        self
177    }
178
179    pub fn text_style<S: Into<TextStyle>>(mut self, text_style: S) -> Self {
180        self.text_style = Some(text_style.into());
181        self
182    }
183
184    pub fn subtext<S: Into<String>>(mut self, subtext: S) -> Self {
185        self.subtext = Some(subtext.into());
186        self
187    }
188
189    pub fn sublink<S: Into<String>>(mut self, sublink: S) -> Self {
190        self.sublink = Some(sublink.into());
191        self
192    }
193
194    pub fn subtarget<T: Into<LinkTarget>>(mut self, subtarget: T) -> Self {
195        self.subtarget = Some(subtarget.into());
196        self
197    }
198
199    pub fn subtext_style<S: Into<TextStyle>>(mut self, subtext_style: S) -> Self {
200        self.subtext_style = Some(subtext_style.into());
201        self
202    }
203
204    pub fn text_align<A: Into<TextAlign>>(mut self, text_align: A) -> Self {
205        self.text_align = Some(text_align.into());
206        self
207    }
208
209    pub fn text_vertical_align<A: Into<TextVerticalAlign>>(
210        mut self,
211        text_vertical_align: A,
212    ) -> Self {
213        self.text_vertical_align = Some(text_vertical_align.into());
214        self
215    }
216
217    pub fn padding<P: Into<Padding>>(mut self, padding: P) -> Self {
218        self.padding = Some(padding.into());
219        self
220    }
221
222    pub fn item_gap<F: Into<i64>>(mut self, item_gap: F) -> Self {
223        self.item_gap = Some(item_gap.into());
224        self
225    }
226
227    pub fn zlevel<F: Into<i64>>(mut self, zlevel: F) -> Self {
228        self.zlevel = Some(zlevel.into());
229        self
230    }
231
232    pub fn z<F: Into<i64>>(mut self, z: F) -> Self {
233        self.z = Some(z.into());
234        self
235    }
236
237    pub fn left<C: Into<CompositeValue>>(mut self, left: C) -> Self {
238        self.left = Some(left.into());
239        self
240    }
241
242    pub fn top<C: Into<CompositeValue>>(mut self, top: C) -> Self {
243        self.top = Some(top.into());
244        self
245    }
246
247    pub fn right<C: Into<CompositeValue>>(mut self, right: C) -> Self {
248        self.right = Some(right.into());
249        self
250    }
251
252    pub fn bottom<C: Into<CompositeValue>>(mut self, bottom: C) -> Self {
253        self.bottom = Some(bottom.into());
254        self
255    }
256
257    pub fn background_color<C: Into<Color>>(mut self, background_color: C) -> Self {
258        self.background_color = Some(background_color.into());
259        self
260    }
261
262    pub fn border_color<C: Into<Color>>(mut self, border_color: C) -> Self {
263        self.border_color = Some(border_color.into());
264        self
265    }
266
267    pub fn border_width<F: Into<i64>>(mut self, border_width: F) -> Self {
268        self.border_width = Some(border_width.into());
269        self
270    }
271
272    pub fn border_radius<F: Into<i64>>(mut self, border_radius: F) -> Self {
273        self.border_radius = Some(border_radius.into());
274        self
275    }
276
277    pub fn shadow_color<C: Into<Color>>(mut self, shadow_color: C) -> Self {
278        self.shadow_color = Some(shadow_color.into());
279        self
280    }
281
282    pub fn shadow_blur<F: Into<i64>>(mut self, shadow_blur: F) -> Self {
283        self.shadow_blur = Some(shadow_blur.into());
284        self
285    }
286
287    pub fn shadow_offset_x<F: Into<i64>>(mut self, shadow_offset_x: F) -> Self {
288        self.shadow_offset_x = Some(shadow_offset_x.into());
289        self
290    }
291
292    pub fn shadow_offset_y<F: Into<i64>>(mut self, shadow_offset_y: F) -> Self {
293        self.shadow_offset_y = Some(shadow_offset_y.into());
294        self
295    }
296}