rust_constructor/
background.rs1use crate::{DisplayInfo, RustConstructorResource};
5use eframe::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, Default, PartialEq)]
190pub struct WrapDefinitions {
191 pub font_definitions: FontDefinitions,
195}
196
197impl Debug for WrapDefinitions {
198 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
199 f.pad("WrapDefinitions { .. }")
200 }
201}
202
203#[derive(Clone, Debug, Default, PartialEq)]
207pub struct Font {
208 pub font_definitions: WrapDefinitions,
212
213 pub path: String,
217
218 pub tags: Vec<[String; 2]>,
222}
223
224impl RustConstructorResource for Font {
225 fn as_any(&self) -> &dyn Any {
226 self
227 }
228
229 fn as_any_mut(&mut self) -> &mut dyn Any {
230 self
231 }
232
233 fn display_display_info(&self) -> Option<DisplayInfo> {
234 None
235 }
236
237 fn modify_display_info(&mut self, _display_info: DisplayInfo) {}
238
239 fn display_tags(&self) -> Vec<[String; 2]> {
240 self.tags.clone()
241 }
242
243 fn modify_tags(&mut self, tags: &[[String; 2]], replace: bool) {
244 if replace {
245 self.tags = tags.to_owned();
246 } else {
247 for tag in tags {
248 if let Some(index) = self.tags.iter().position(|x| x[0] == tag[0]) {
249 self.tags.remove(index);
250 };
251 }
252 self.tags.extend(tags.iter().cloned());
253 };
254 }
255}
256
257impl Font {
258 #[inline]
259 pub fn path(mut self, path: &str) -> Self {
260 self.path = path.to_string();
261 self
262 }
263
264 #[inline]
265 pub fn tags(mut self, tags: &[[String; 2]], replace: bool) -> Self {
266 if replace {
267 self.tags = tags.to_owned();
268 } else {
269 for tag in tags {
270 if let Some(index) = self.tags.iter().position(|x| x[0] == tag[0]) {
271 self.tags.remove(index);
272 };
273 }
274 self.tags.extend(tags.iter().cloned());
275 };
276 self
277 }
278}
279
280#[derive(Debug, Clone, PartialEq, PartialOrd)]
289pub struct SplitTime {
290 pub time: [f32; 2],
294
295 pub tags: Vec<[String; 2]>,
299}
300
301impl RustConstructorResource for SplitTime {
302 fn as_any(&self) -> &dyn Any {
303 self
304 }
305
306 fn as_any_mut(&mut self) -> &mut dyn Any {
307 self
308 }
309
310 fn display_display_info(&self) -> Option<DisplayInfo> {
311 None
312 }
313
314 fn modify_display_info(&mut self, _display_info: DisplayInfo) {}
315
316 fn display_tags(&self) -> Vec<[String; 2]> {
317 self.tags.clone()
318 }
319
320 fn modify_tags(&mut self, tags: &[[String; 2]], replace: bool) {
321 if replace {
322 self.tags = tags.to_owned();
323 } else {
324 for tag in tags {
325 if let Some(index) = self.tags.iter().position(|x| x[0] == tag[0]) {
326 self.tags.remove(index);
327 };
328 }
329 self.tags.extend(tags.iter().cloned());
330 };
331 }
332}
333
334impl Default for SplitTime {
335 fn default() -> Self {
336 Self {
337 time: [0_f32, 0_f32],
338 tags: Vec::new(),
339 }
340 }
341}
342
343impl SplitTime {
344 #[inline]
345 pub fn tags(mut self, tags: &[[String; 2]], replace: bool) -> Self {
346 if replace {
347 self.tags = tags.to_owned();
348 } else {
349 for tag in tags {
350 if let Some(index) = self.tags.iter().position(|x| x[0] == tag[0]) {
351 self.tags.remove(index);
352 };
353 }
354 self.tags.extend(tags.iter().cloned());
355 };
356 self
357 }
358}