charming_fork_zephyr/component/
grid.rs1use serde::Serialize;
2
3use crate::{
4 datatype::CompositeValue,
5 element::{Color, Padding, TextStyle, Trigger},
6};
7
8#[derive(Serialize)]
9#[serde(rename_all = "camelCase")]
10pub struct GridTooltip {
11 #[serde(skip_serializing_if = "Option::is_none")]
13 show: Option<bool>,
14
15 #[serde(skip_serializing_if = "Option::is_none")]
17 trigger: Option<Trigger>,
18
19 #[serde(skip_serializing_if = "Option::is_none")]
22 position: Option<(String, String)>,
23
24 #[serde(skip_serializing_if = "Option::is_none")]
26 formatter: Option<String>,
27
28 #[serde(skip_serializing_if = "Option::is_none")]
30 value_formatter: Option<String>,
31
32 #[serde(skip_serializing_if = "Option::is_none")]
34 background_color: Option<Color>,
35
36 #[serde(skip_serializing_if = "Option::is_none")]
38 border_color: Option<Color>,
39
40 #[serde(skip_serializing_if = "Option::is_none")]
42 border_width: Option<i64>,
43
44 #[serde(skip_serializing_if = "Option::is_none")]
46 padding: Option<Padding>,
47
48 #[serde(skip_serializing_if = "Option::is_none")]
50 text_style: Option<TextStyle>,
51
52 #[serde(skip_serializing_if = "Option::is_none")]
54 extra_css_text: Option<String>,
55}
56
57impl GridTooltip {
58 pub fn new() -> Self {
59 Self {
60 show: None,
61 trigger: None,
62 position: None,
63 formatter: None,
64 value_formatter: None,
65 background_color: None,
66 border_color: None,
67 border_width: None,
68 padding: None,
69 text_style: None,
70 extra_css_text: None,
71 }
72 }
73
74 pub fn show(mut self, show: bool) -> Self {
75 self.show = Some(show);
76 self
77 }
78
79 pub fn trigger<T: Into<Trigger>>(mut self, trigger: T) -> Self {
80 self.trigger = Some(trigger.into());
81 self
82 }
83
84 pub fn position<S: Into<String>>(mut self, position: (S, S)) -> Self {
85 self.position = Some((position.0.into(), position.1.into()));
86 self
87 }
88
89 pub fn formatter<S: Into<String>>(mut self, formatter: S) -> Self {
90 self.formatter = Some(formatter.into());
91 self
92 }
93
94 pub fn value_formatter<S: Into<String>>(mut self, value_formatter: S) -> Self {
95 self.value_formatter = Some(value_formatter.into());
96 self
97 }
98
99 pub fn background_color<C: Into<Color>>(mut self, background_color: C) -> Self {
100 self.background_color = Some(background_color.into());
101 self
102 }
103
104 pub fn border_color<C: Into<Color>>(mut self, border_color: C) -> Self {
105 self.border_color = Some(border_color.into());
106 self
107 }
108
109 pub fn border_width<F: Into<i64>>(mut self, border_width: F) -> Self {
110 self.border_width = Some(border_width.into());
111 self
112 }
113
114 pub fn padding<P: Into<Padding>>(mut self, padding: P) -> Self {
115 self.padding = Some(padding.into());
116 self
117 }
118
119 pub fn text_style<T: Into<TextStyle>>(mut self, text_style: T) -> Self {
120 self.text_style = Some(text_style.into());
121 self
122 }
123
124 pub fn extra_css_text<S: Into<String>>(mut self, extra_css_text: S) -> Self {
125 self.extra_css_text = Some(extra_css_text.into());
126 self
127 }
128}
129
130#[derive(Serialize)]
131#[serde(rename_all = "camelCase")]
132pub struct Grid {
133 #[serde(skip_serializing_if = "Option::is_none")]
135 id: Option<String>,
136
137 #[serde(skip_serializing_if = "Option::is_none")]
139 show: Option<bool>,
140
141 #[serde(skip_serializing_if = "Option::is_none")]
143 zlevel: Option<i64>,
144
145 #[serde(skip_serializing_if = "Option::is_none")]
147 z: Option<i64>,
148
149 #[serde(skip_serializing_if = "Option::is_none")]
151 left: Option<CompositeValue>,
152
153 #[serde(skip_serializing_if = "Option::is_none")]
155 top: Option<CompositeValue>,
156
157 #[serde(skip_serializing_if = "Option::is_none")]
159 right: Option<CompositeValue>,
160
161 #[serde(skip_serializing_if = "Option::is_none")]
163 bottom: Option<CompositeValue>,
164
165 #[serde(skip_serializing_if = "Option::is_none")]
167 width: Option<CompositeValue>,
168
169 #[serde(skip_serializing_if = "Option::is_none")]
171 height: Option<CompositeValue>,
172
173 #[serde(skip_serializing_if = "Option::is_none")]
175 contain_label: Option<bool>,
176
177 #[serde(skip_serializing_if = "Option::is_none")]
179 background_color: Option<Color>,
180
181 #[serde(skip_serializing_if = "Option::is_none")]
183 border_color: Option<Color>,
184
185 #[serde(skip_serializing_if = "Option::is_none")]
187 border_width: Option<i64>,
188
189 #[serde(skip_serializing_if = "Option::is_none")]
191 shadow_blur: Option<i64>,
192
193 #[serde(skip_serializing_if = "Option::is_none")]
195 shadow_color: Option<Color>,
196
197 #[serde(skip_serializing_if = "Option::is_none")]
199 shadow_offset_x: Option<i64>,
200
201 #[serde(skip_serializing_if = "Option::is_none")]
203 shadow_offset_y: Option<i64>,
204
205 #[serde(skip_serializing_if = "Option::is_none")]
207 tooltip: Option<GridTooltip>,
208}
209
210impl Grid {
211 pub fn new() -> Self {
212 Self {
213 id: None,
214 show: None,
215 zlevel: None,
216 z: None,
217 left: None,
218 top: None,
219 right: None,
220 bottom: None,
221 width: None,
222 height: None,
223 contain_label: None,
224 background_color: None,
225 border_color: None,
226 border_width: None,
227 shadow_blur: None,
228 shadow_color: None,
229 shadow_offset_x: None,
230 shadow_offset_y: None,
231 tooltip: None,
232 }
233 }
234
235 pub fn show(mut self, show: bool) -> Self {
236 self.show = Some(show);
237 self
238 }
239
240 pub fn zlevel<F: Into<i64>>(mut self, zlevel: F) -> Self {
241 self.zlevel = Some(zlevel.into());
242 self
243 }
244
245 pub fn z<F: Into<i64>>(mut self, z: F) -> Self {
246 self.z = Some(z.into());
247 self
248 }
249
250 pub fn left<C: Into<CompositeValue>>(mut self, left: C) -> Self {
251 self.left = Some(left.into());
252 self
253 }
254
255 pub fn right<C: Into<CompositeValue>>(mut self, right: C) -> Self {
256 self.right = Some(right.into());
257 self
258 }
259
260 pub fn top<C: Into<CompositeValue>>(mut self, top: C) -> Self {
261 self.top = Some(top.into());
262 self
263 }
264
265 pub fn bottom<C: Into<CompositeValue>>(mut self, bottom: C) -> Self {
266 self.bottom = Some(bottom.into());
267 self
268 }
269
270 pub fn width<C: Into<CompositeValue>>(mut self, width: C) -> Self {
271 self.width = Some(width.into());
272 self
273 }
274
275 pub fn height<C: Into<CompositeValue>>(mut self, height: C) -> Self {
276 self.height = Some(height.into());
277 self
278 }
279
280 pub fn contain_label(mut self, contain_label: bool) -> Self {
281 self.contain_label = Some(contain_label);
282 self
283 }
284
285 pub fn background_color<C: Into<Color>>(mut self, background_color: C) -> Self {
286 self.background_color = Some(background_color.into());
287 self
288 }
289
290 pub fn border_color<C: Into<Color>>(mut self, border_color: C) -> Self {
291 self.border_color = Some(border_color.into());
292 self
293 }
294
295 pub fn border_width<F: Into<i64>>(mut self, border_width: F) -> Self {
296 self.border_width = Some(border_width.into());
297 self
298 }
299
300 pub fn shadow_blur<F: Into<i64>>(mut self, shadow_blur: F) -> Self {
301 self.shadow_blur = Some(shadow_blur.into());
302 self
303 }
304
305 pub fn shadow_color<C: Into<Color>>(mut self, shadow_color: C) -> Self {
306 self.shadow_color = Some(shadow_color.into());
307 self
308 }
309
310 pub fn shadow_offset_x<F: Into<i64>>(mut self, shadow_offset_x: F) -> Self {
311 self.shadow_offset_x = Some(shadow_offset_x.into());
312 self
313 }
314
315 pub fn shadow_offset_y<F: Into<i64>>(mut self, shadow_offset_y: F) -> Self {
316 self.shadow_offset_y = Some(shadow_offset_y.into());
317 self
318 }
319
320 pub fn tooltip<T: Into<GridTooltip>>(mut self, tooltip: T) -> Self {
321 self.tooltip = Some(tooltip.into());
322 self
323 }
324}