rust_constructor/
background.rs1use crate::{DisplayInfo, RustConstructorResource};
5use egui::FontDefinitions;
6use std::{any::Any, fmt::Debug};
7
8#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
16pub struct PageData {
17 pub forced_update: bool,
21
22 pub change_page_updated: bool,
26
27 pub enter_page_updated: bool,
31
32 pub tags: Vec<[String; 2]>,
36}
37
38impl RustConstructorResource for PageData {
39 fn as_any(&self) -> &dyn Any {
40 self
41 }
42
43 fn as_any_mut(&mut self) -> &mut dyn Any {
44 self
45 }
46
47 fn display_display_info(&self) -> Option<DisplayInfo> {
48 None
49 }
50
51 fn modify_display_info(&mut self, _display_info: DisplayInfo) {}
52
53 fn display_tags(&self) -> Vec<[String; 2]> {
54 self.tags.clone()
55 }
56
57 fn modify_tags(&mut self, tags: &[[String; 2]], replace: bool) {
58 if replace {
59 self.tags = tags.to_owned();
60 } else {
61 for tag in tags {
62 if let Some(index) = self.tags.iter().position(|x| x[0] == tag[0]) {
63 self.tags.remove(index);
64 };
65 }
66 self.tags.extend(tags.iter().cloned());
67 };
68 }
69}
70
71impl Default for PageData {
72 fn default() -> Self {
73 PageData {
74 forced_update: true,
75 change_page_updated: false,
76 enter_page_updated: false,
77 tags: Vec::new(),
78 }
79 }
80}
81
82impl PageData {
83 #[inline]
84 pub fn forced_update(mut self, forced_update: bool) -> Self {
85 self.forced_update = forced_update;
86 self
87 }
88
89 #[inline]
90 pub fn tags(mut self, tags: &[[String; 2]], replace: bool) -> Self {
91 if replace {
92 self.tags = tags.to_owned();
93 } else {
94 for tag in tags {
95 if let Some(index) = self.tags.iter().position(|x| x[0] == tag[0]) {
96 self.tags.remove(index);
97 };
98 }
99 self.tags.extend(tags.iter().cloned());
100 };
101 self
102 }
103}
104
105#[derive(Debug, Clone, PartialEq, PartialOrd)]
109pub struct Variable<T> {
110 pub value: Option<T>,
114
115 pub tags: Vec<[String; 2]>,
119}
120
121impl<T: Debug + 'static> RustConstructorResource for Variable<T> {
122 fn as_any(&self) -> &dyn Any {
123 self
124 }
125
126 fn as_any_mut(&mut self) -> &mut dyn Any {
127 self
128 }
129
130 fn display_display_info(&self) -> Option<DisplayInfo> {
131 None
132 }
133
134 fn modify_display_info(&mut self, _display_info: DisplayInfo) {}
135
136 fn display_tags(&self) -> Vec<[String; 2]> {
137 self.tags.clone()
138 }
139
140 fn modify_tags(&mut self, tags: &[[String; 2]], replace: bool) {
141 if replace {
142 self.tags = tags.to_owned();
143 } else {
144 for tag in tags {
145 if let Some(index) = self.tags.iter().position(|x| x[0] == tag[0]) {
146 self.tags.remove(index);
147 };
148 }
149 self.tags.extend(tags.iter().cloned());
150 };
151 }
152}
153
154impl<T> Default for Variable<T> {
155 fn default() -> Self {
156 Variable {
157 value: None,
158 tags: Vec::new(),
159 }
160 }
161}
162
163impl<T> Variable<T> {
164 #[inline]
165 pub fn value(mut self, value: Option<T>) -> Self {
166 self.value = value;
167 self
168 }
169
170 #[inline]
171 pub fn tags(mut self, tags: &[[String; 2]], replace: bool) -> Self {
172 if replace {
173 self.tags = tags.to_owned();
174 } else {
175 for tag in tags {
176 if let Some(index) = self.tags.iter().position(|x| x[0] == tag[0]) {
177 self.tags.remove(index);
178 };
179 }
180 self.tags.extend(tags.iter().cloned());
181 };
182 self
183 }
184}
185
186#[derive(Clone, Debug, Default, PartialEq)]
190pub struct Font {
191 pub font_definitions: FontDefinitions,
195
196 pub path: String,
200
201 pub tags: Vec<[String; 2]>,
205}
206
207impl RustConstructorResource for Font {
208 fn as_any(&self) -> &dyn Any {
209 self
210 }
211
212 fn as_any_mut(&mut self) -> &mut dyn Any {
213 self
214 }
215
216 fn display_display_info(&self) -> Option<DisplayInfo> {
217 None
218 }
219
220 fn modify_display_info(&mut self, _display_info: DisplayInfo) {}
221
222 fn display_tags(&self) -> Vec<[String; 2]> {
223 self.tags.clone()
224 }
225
226 fn modify_tags(&mut self, tags: &[[String; 2]], replace: bool) {
227 if replace {
228 self.tags = tags.to_owned();
229 } else {
230 for tag in tags {
231 if let Some(index) = self.tags.iter().position(|x| x[0] == tag[0]) {
232 self.tags.remove(index);
233 };
234 }
235 self.tags.extend(tags.iter().cloned());
236 };
237 }
238}
239
240impl Font {
241 #[inline]
242 pub fn path(mut self, path: &str) -> Self {
243 self.path = path.to_string();
244 self
245 }
246
247 #[inline]
248 pub fn tags(mut self, tags: &[[String; 2]], replace: bool) -> Self {
249 if replace {
250 self.tags = tags.to_owned();
251 } else {
252 for tag in tags {
253 if let Some(index) = self.tags.iter().position(|x| x[0] == tag[0]) {
254 self.tags.remove(index);
255 };
256 }
257 self.tags.extend(tags.iter().cloned());
258 };
259 self
260 }
261}
262
263#[derive(Debug, Clone, PartialEq, PartialOrd)]
272pub struct SplitTime {
273 pub time: [f32; 2],
277
278 pub tags: Vec<[String; 2]>,
282}
283
284impl RustConstructorResource for SplitTime {
285 fn as_any(&self) -> &dyn Any {
286 self
287 }
288
289 fn as_any_mut(&mut self) -> &mut dyn Any {
290 self
291 }
292
293 fn display_display_info(&self) -> Option<DisplayInfo> {
294 None
295 }
296
297 fn modify_display_info(&mut self, _display_info: DisplayInfo) {}
298
299 fn display_tags(&self) -> Vec<[String; 2]> {
300 self.tags.clone()
301 }
302
303 fn modify_tags(&mut self, tags: &[[String; 2]], replace: bool) {
304 if replace {
305 self.tags = tags.to_owned();
306 } else {
307 for tag in tags {
308 if let Some(index) = self.tags.iter().position(|x| x[0] == tag[0]) {
309 self.tags.remove(index);
310 };
311 }
312 self.tags.extend(tags.iter().cloned());
313 };
314 }
315}
316
317impl Default for SplitTime {
318 fn default() -> Self {
319 Self {
320 time: [0_f32, 0_f32],
321 tags: Vec::new(),
322 }
323 }
324}
325
326impl SplitTime {
327 #[inline]
328 pub fn tags(mut self, tags: &[[String; 2]], replace: bool) -> Self {
329 if replace {
330 self.tags = tags.to_owned();
331 } else {
332 for tag in tags {
333 if let Some(index) = self.tags.iter().position(|x| x[0] == tag[0]) {
334 self.tags.remove(index);
335 };
336 }
337 self.tags.extend(tags.iter().cloned());
338 };
339 self
340 }
341}