charming_fork_zephyr/element/
label.rs

1use serde::Serialize;
2
3use super::{color::Color, line_style::LineStyle, Formatter};
4
5#[derive(Serialize)]
6#[serde(rename_all = "camelCase")]
7pub enum LabelPosition {
8    Top,
9    Left,
10    Right,
11    Bottom,
12    Inside,
13    InsideLeft,
14    InsideRight,
15    InsideTop,
16    InsideBottom,
17    InsideTopLeft,
18    InsideBottomLeft,
19    InsideTopRight,
20    InsideBottomRight,
21    Start,
22    Outside,
23    Middle,
24    Center,
25}
26
27#[derive(Serialize)]
28#[serde(rename_all = "snake_case")]
29pub enum LabelAlign {
30    Left,
31    Center,
32    Right,
33}
34
35#[derive(Serialize)]
36#[serde(rename_all = "snake_case")]
37pub enum LabelVerticalAlign {
38    Top,
39    Middle,
40    Bottom,
41}
42
43#[derive(Serialize)]
44#[serde(rename_all = "camelCase")]
45pub struct Label {
46    #[serde(skip_serializing_if = "Option::is_none")]
47    show: Option<bool>,
48
49    #[serde(skip_serializing_if = "Option::is_none")]
50    position: Option<LabelPosition>,
51
52    #[serde(skip_serializing_if = "Option::is_none")]
53    distance: Option<i64>,
54
55    #[serde(skip_serializing_if = "Option::is_none")]
56    rotate: Option<String>,
57
58    #[serde(skip_serializing_if = "Option::is_none")]
59    offset: Option<(i64, i64)>,
60
61    #[serde(skip_serializing_if = "Option::is_none")]
62    formatter: Option<Formatter>,
63
64    #[serde(skip_serializing_if = "Option::is_none")]
65    color: Option<Color>,
66
67    #[serde(skip_serializing_if = "Option::is_none")]
68    font_size: Option<i64>,
69
70    #[serde(skip_serializing_if = "Option::is_none")]
71    font_weight: Option<String>,
72
73    #[serde(skip_serializing_if = "Option::is_none")]
74    padding: Option<(i64, i64, i64, i64)>,
75
76    #[serde(skip_serializing_if = "Option::is_none")]
77    align: Option<LabelAlign>,
78
79    #[serde(skip_serializing_if = "Option::is_none")]
80    vertical_align: Option<LabelVerticalAlign>,
81
82    #[serde(skip_serializing_if = "Option::is_none")]
83    silent: Option<bool>,
84
85    #[serde(skip_serializing_if = "Option::is_none")]
86    background_color: Option<Color>,
87
88    #[serde(skip_serializing_if = "Option::is_none")]
89    border_color: Option<Color>,
90
91    #[serde(skip_serializing_if = "Option::is_none")]
92    border_width: Option<i64>,
93
94    #[serde(skip_serializing_if = "Option::is_none")]
95    shadow_blur: Option<i64>,
96
97    #[serde(skip_serializing_if = "Option::is_none")]
98    shadow_offset_x: Option<i64>,
99
100    #[serde(skip_serializing_if = "Option::is_none")]
101    shadow_offset_y: Option<i64>,
102}
103
104impl Label {
105    pub fn new() -> Self {
106        Self {
107            show: None,
108            position: None,
109            distance: None,
110            rotate: None,
111            offset: None,
112            formatter: None,
113            color: None,
114            font_size: None,
115            font_weight: None,
116            padding: None,
117            align: None,
118            vertical_align: None,
119            silent: None,
120            background_color: None,
121            border_color: None,
122            border_width: None,
123            shadow_blur: None,
124            shadow_offset_x: None,
125            shadow_offset_y: None,
126        }
127    }
128
129    pub fn show(mut self, show: bool) -> Self {
130        self.show = Some(show);
131        self
132    }
133
134    pub fn position<P: Into<LabelPosition>>(mut self, position: P) -> Self {
135        self.position = Some(position.into());
136        self
137    }
138
139    pub fn distance<F: Into<i64>>(mut self, distance: F) -> Self {
140        self.distance = Some(distance.into());
141        self
142    }
143
144    pub fn rotate<S: Into<String>>(mut self, rotate: S) -> Self {
145        self.rotate = Some(rotate.into());
146        self
147    }
148
149    pub fn offset<F: Into<i64>>(mut self, offset: (F, F)) -> Self {
150        self.offset = Some((offset.0.into(), offset.1.into()));
151        self
152    }
153
154    pub fn formatter<F: Into<Formatter>>(mut self, formatter: F) -> Self {
155        self.formatter = Some(formatter.into());
156        self
157    }
158
159    pub fn color<C: Into<Color>>(mut self, color: C) -> Self {
160        self.color = Some(color.into());
161        self
162    }
163
164    pub fn font_size<F: Into<i64>>(mut self, font_size: F) -> Self {
165        self.font_size = Some(font_size.into());
166        self
167    }
168
169    pub fn font_weight<S: Into<String>>(mut self, font_weight: S) -> Self {
170        self.font_weight = Some(font_weight.into());
171        self
172    }
173
174    pub fn padding<F: Into<i64>>(mut self, padding: (F, F, F, F)) -> Self {
175        self.padding = Some((
176            padding.0.into(),
177            padding.1.into(),
178            padding.2.into(),
179            padding.3.into(),
180        ));
181        self
182    }
183
184    pub fn align<A: Into<LabelAlign>>(mut self, align: A) -> Self {
185        self.align = Some(align.into());
186        self
187    }
188
189    pub fn vertical_align<V: Into<LabelVerticalAlign>>(mut self, vertical_align: V) -> Self {
190        self.vertical_align = Some(vertical_align.into());
191        self
192    }
193
194    pub fn silent(mut self, silent: bool) -> Self {
195        self.silent = Some(silent);
196        self
197    }
198
199    pub fn background_color<C: Into<Color>>(mut self, background_color: C) -> Self {
200        self.background_color = Some(background_color.into());
201        self
202    }
203
204    pub fn border_color<C: Into<Color>>(mut self, border_color: C) -> Self {
205        self.border_color = Some(border_color.into());
206        self
207    }
208
209    pub fn border_width<F: Into<i64>>(mut self, border_width: F) -> Self {
210        self.border_width = Some(border_width.into());
211        self
212    }
213
214    pub fn shadow_blur<F: Into<i64>>(mut self, shadow_blur: F) -> Self {
215        self.shadow_blur = Some(shadow_blur.into());
216        self
217    }
218
219    pub fn shadow_offset_x<F: Into<i64>>(mut self, shadow_offset_x: F) -> Self {
220        self.shadow_offset_x = Some(shadow_offset_x.into());
221        self
222    }
223
224    pub fn shadow_offset_y<F: Into<i64>>(mut self, shadow_offset_y: F) -> Self {
225        self.shadow_offset_y = Some(shadow_offset_y.into());
226        self
227    }
228}
229
230#[derive(Serialize)]
231#[serde(rename_all = "camelCase")]
232pub struct LabelLine {
233    #[serde(skip_serializing_if = "Option::is_none")]
234    show: Option<bool>,
235
236    #[serde(skip_serializing_if = "Option::is_none")]
237    show_above: Option<bool>,
238
239    #[serde(skip_serializing_if = "Option::is_none")]
240    length: Option<i64>,
241
242    #[serde(skip_serializing_if = "Option::is_none")]
243    smooth: Option<bool>,
244
245    #[serde(skip_serializing_if = "Option::is_none")]
246    min_turn_angle: Option<i64>,
247
248    #[serde(skip_serializing_if = "Option::is_none")]
249    line_style: Option<LineStyle>,
250}
251
252impl LabelLine {
253    pub fn new() -> Self {
254        Self {
255            show: None,
256            show_above: None,
257            length: None,
258            smooth: None,
259            min_turn_angle: None,
260            line_style: None,
261        }
262    }
263
264    pub fn show(mut self, show: bool) -> Self {
265        self.show = Some(show);
266        self
267    }
268
269    pub fn show_above(mut self, show_above: bool) -> Self {
270        self.show_above = Some(show_above);
271        self
272    }
273
274    pub fn length<F: Into<i64>>(mut self, length: F) -> Self {
275        self.length = Some(length.into());
276        self
277    }
278
279    pub fn smooth(mut self, smooth: bool) -> Self {
280        self.smooth = Some(smooth);
281        self
282    }
283
284    pub fn min_turn_angle<F: Into<i64>>(mut self, min_turn_angle: F) -> Self {
285        self.min_turn_angle = Some(min_turn_angle.into());
286        self
287    }
288
289    pub fn line_style<S: Into<LineStyle>>(mut self, line_style: S) -> Self {
290        self.line_style = Some(line_style.into());
291        self
292    }
293}
294
295#[derive(Serialize)]
296#[serde(rename_all = "camelCase")]
297pub struct LabelLayout {
298    #[serde(skip_serializing_if = "Option::is_none")]
299    hide_overlap: Option<bool>,
300
301    #[serde(skip_serializing_if = "Option::is_none")]
302    overlap: Option<String>,
303
304    #[serde(skip_serializing_if = "Option::is_none")]
305    rotate: Option<i64>,
306}
307
308impl LabelLayout {
309    pub fn new() -> Self {
310        Self {
311            hide_overlap: None,
312            overlap: None,
313            rotate: None,
314        }
315    }
316
317    pub fn hide_overlap(mut self, hide_overlap: bool) -> Self {
318        self.hide_overlap = Some(hide_overlap);
319        self
320    }
321
322    pub fn overlap<S: Into<String>>(mut self, overlap: S) -> Self {
323        self.overlap = Some(overlap.into());
324        self
325    }
326
327    pub fn rotate<F: Into<i64>>(mut self, rotate: F) -> Self {
328        self.rotate = Some(rotate.into());
329        self
330    }
331}