charming_fork_zephyr/component/
single_axis.rs1use serde::Serialize;
2
3use crate::{datatype::CompositeValue, element::Orient};
4
5#[derive(Serialize)]
6#[serde(rename_all = "snake_case")]
7pub enum Type {
8 Value,
9 Category,
10 Time,
11 Log,
12}
13
14#[derive(Serialize)]
15#[serde(rename_all = "camelCase")]
16pub struct SingleAxis {
17 #[serde(skip_serializing_if = "Option::is_none")]
18 #[serde(rename = "type")]
19 type_: Option<Type>,
20
21 #[serde(skip_serializing_if = "Option::is_none")]
22 name: Option<String>,
23
24 #[serde(skip_serializing_if = "Option::is_none")]
25 left: Option<CompositeValue>,
26
27 #[serde(skip_serializing_if = "Option::is_none")]
28 top: Option<CompositeValue>,
29
30 #[serde(skip_serializing_if = "Option::is_none")]
31 right: Option<CompositeValue>,
32
33 #[serde(skip_serializing_if = "Option::is_none")]
34 bottom: Option<CompositeValue>,
35
36 #[serde(skip_serializing_if = "Option::is_none")]
37 width: Option<CompositeValue>,
38
39 #[serde(skip_serializing_if = "Option::is_none")]
40 height: Option<CompositeValue>,
41
42 #[serde(skip_serializing_if = "Option::is_none")]
43 orient: Option<Orient>,
44
45 #[serde(skip_serializing_if = "Option::is_none")]
46 inverse: Option<bool>,
47
48 #[serde(skip_serializing_if = "Option::is_none")]
49 min: Option<String>,
50
51 #[serde(skip_serializing_if = "Option::is_none")]
52 max: Option<String>,
53}
54
55impl SingleAxis {
56 pub fn new() -> Self {
57 Self {
58 type_: None,
59 name: None,
60 left: None,
61 top: None,
62 right: None,
63 bottom: None,
64 width: None,
65 height: None,
66 orient: None,
67 inverse: None,
68 min: None,
69 max: None,
70 }
71 }
72
73 pub fn type_(mut self, type_: Type) -> Self {
74 self.type_ = Some(type_);
75 self
76 }
77
78 pub fn name<S: Into<String>>(mut self, name: S) -> Self {
79 self.name = Some(name.into());
80 self
81 }
82
83 pub fn left<C: Into<CompositeValue>>(mut self, left: C) -> Self {
84 self.left = Some(left.into());
85 self
86 }
87
88 pub fn top<C: Into<CompositeValue>>(mut self, top: C) -> Self {
89 self.top = Some(top.into());
90 self
91 }
92
93 pub fn right<C: Into<CompositeValue>>(mut self, right: C) -> Self {
94 self.right = Some(right.into());
95 self
96 }
97
98 pub fn bottom<C: Into<CompositeValue>>(mut self, bottom: C) -> Self {
99 self.bottom = Some(bottom.into());
100 self
101 }
102
103 pub fn width<C: Into<CompositeValue>>(mut self, width: C) -> Self {
104 self.width = Some(width.into());
105 self
106 }
107
108 pub fn height<C: Into<CompositeValue>>(mut self, height: C) -> Self {
109 self.height = Some(height.into());
110 self
111 }
112
113 pub fn orient(mut self, orient: Orient) -> Self {
114 self.orient = Some(orient);
115 self
116 }
117
118 pub fn inverse(mut self, inverse: bool) -> Self {
119 self.inverse = Some(inverse);
120 self
121 }
122
123 pub fn min<S: Into<String>>(mut self, min: S) -> Self {
124 self.min = Some(min.into());
125 self
126 }
127
128 pub fn max<S: Into<String>>(mut self, max: S) -> Self {
129 self.max = Some(max.into());
130 self
131 }
132}