1use crate::{
5 BasicFrontResource, BasicFrontResourceConfig, BorderKind, DisplayInfo, PositionSizeConfig,
6 RustConstructorResource,
7};
8use egui::TextureHandle;
9use std::{
10 any::Any,
11 fmt::{Debug, Formatter},
12};
13
14#[derive(Debug, Default, Clone, PartialEq, PartialOrd)]
23pub struct CustomRectConfig {
24 pub position_size_config: Option<PositionSizeConfig>,
28
29 pub clip_rect: Option<Option<PositionSizeConfig>>,
33
34 pub hidden: Option<bool>,
38
39 pub ignore_render_layer: Option<bool>,
43
44 pub rounding: Option<f32>,
48
49 pub color: Option<[u8; 3]>,
53
54 pub alpha: Option<u8>,
58
59 pub border_width: Option<f32>,
63
64 pub border_color: Option<[u8; 3]>,
68
69 pub border_alpha: Option<u8>,
73
74 pub border_kind: Option<BorderKind>,
78
79 pub tags: Option<Vec<[String; 2]>>,
83}
84
85impl CustomRectConfig {
86 pub fn from_custom_rect(custom_rect: &CustomRect) -> Self {
87 Self {
88 position_size_config: Some(
89 custom_rect.basic_front_resource_config.position_size_config,
90 ),
91 clip_rect: Some(custom_rect.basic_front_resource_config.clip_rect),
92 hidden: Some(custom_rect.display_info.hidden),
93 ignore_render_layer: Some(custom_rect.display_info.ignore_render_layer),
94 rounding: Some(custom_rect.rounding),
95 color: Some(custom_rect.color),
96 alpha: Some(custom_rect.alpha),
97 border_width: Some(custom_rect.border_width),
98 border_color: Some(custom_rect.border_color),
99 border_alpha: Some(custom_rect.border_alpha),
100 border_kind: Some(custom_rect.border_kind),
101 tags: Some(custom_rect.tags.clone()),
102 }
103 }
104
105 #[inline]
106 pub fn position_size_config(
107 mut self,
108 position_size_config: Option<PositionSizeConfig>,
109 ) -> Self {
110 self.position_size_config = position_size_config;
111 self
112 }
113
114 #[inline]
115 pub fn clip_rect(mut self, clip_rect: Option<Option<PositionSizeConfig>>) -> Self {
116 self.clip_rect = clip_rect;
117 self
118 }
119
120 #[inline]
121 pub fn hidden(mut self, hidden: Option<bool>) -> Self {
122 self.hidden = hidden;
123 self
124 }
125
126 #[inline]
127 pub fn ignore_render_layer(mut self, ignore_render_layer: Option<bool>) -> Self {
128 self.ignore_render_layer = ignore_render_layer;
129 self
130 }
131
132 #[inline]
133 pub fn rounding(mut self, rounding: Option<f32>) -> Self {
134 self.rounding = rounding;
135 self
136 }
137
138 #[inline]
139 pub fn color(mut self, color: Option<[u8; 3]>) -> Self {
140 self.color = color;
141 self
142 }
143
144 #[inline]
145 pub fn alpha(mut self, alpha: Option<u8>) -> Self {
146 self.alpha = alpha;
147 self
148 }
149
150 #[inline]
151 pub fn border_width(mut self, border_width: Option<f32>) -> Self {
152 self.border_width = border_width;
153 self
154 }
155
156 #[inline]
157 pub fn border_color(mut self, border_color: Option<[u8; 3]>) -> Self {
158 self.border_color = border_color;
159 self
160 }
161
162 #[inline]
163 pub fn border_alpha(mut self, border_alpha: Option<u8>) -> Self {
164 self.border_alpha = border_alpha;
165 self
166 }
167
168 #[inline]
169 pub fn border_kind(mut self, border_kind: Option<BorderKind>) -> Self {
170 self.border_kind = border_kind;
171 self
172 }
173
174 #[inline]
175 pub fn tags(mut self, tags: Option<Vec<[String; 2]>>) -> Self {
176 self.tags = tags;
177 self
178 }
179}
180
181#[derive(Debug, Clone, PartialEq, PartialOrd)]
185pub struct CustomRect {
186 pub basic_front_resource_config: BasicFrontResourceConfig,
190
191 pub position: [f32; 2],
195
196 pub size: [f32; 2],
200
201 pub display_info: DisplayInfo,
205
206 pub rounding: f32,
210
211 pub color: [u8; 3],
215
216 pub alpha: u8,
220
221 pub border_width: f32,
225
226 pub border_color: [u8; 3],
230
231 pub border_alpha: u8,
235
236 pub border_kind: BorderKind,
240
241 pub tags: Vec<[String; 2]>,
245}
246
247impl RustConstructorResource for CustomRect {
248 fn as_any(&self) -> &dyn Any {
249 self
250 }
251
252 fn as_any_mut(&mut self) -> &mut dyn Any {
253 self
254 }
255
256 fn display_display_info(&self) -> Option<DisplayInfo> {
257 Some(self.display_info)
258 }
259
260 fn modify_display_info(&mut self, display_info: DisplayInfo) {
261 self.display_info = display_info;
262 }
263
264 fn display_tags(&self) -> Vec<[String; 2]> {
265 self.tags.clone()
266 }
267
268 fn modify_tags(&mut self, tags: &[[String; 2]], replace: bool) {
269 if replace {
270 self.tags = tags.to_owned();
271 } else {
272 for tag in tags {
273 if let Some(index) = self.tags.iter().position(|x| x[0] == tag[0]) {
274 self.tags.remove(index);
275 };
276 }
277 self.tags.extend(tags.iter().cloned());
278 };
279 }
280}
281
282impl BasicFrontResource for CustomRect {
283 fn display_basic_front_resource_config(&self) -> BasicFrontResourceConfig {
284 self.basic_front_resource_config.clone()
285 }
286
287 fn display_position_size_config(&self) -> PositionSizeConfig {
288 self.basic_front_resource_config.position_size_config
289 }
290
291 fn display_clip_rect(&self) -> Option<PositionSizeConfig> {
292 self.basic_front_resource_config.clip_rect
293 }
294
295 fn display_position(&self) -> [f32; 2] {
296 self.position
297 }
298
299 fn display_size(&self) -> [f32; 2] {
300 self.size
301 }
302
303 fn modify_basic_front_resource_config(
304 &mut self,
305 basic_front_resource_config: BasicFrontResourceConfig,
306 ) {
307 self.basic_front_resource_config = basic_front_resource_config;
308 }
309
310 fn modify_position_size_config(&mut self, position_size_config: PositionSizeConfig) {
311 self.basic_front_resource_config.position_size_config = position_size_config;
312 }
313
314 fn modify_clip_rect(&mut self, clip_rect: Option<PositionSizeConfig>) {
315 self.basic_front_resource_config.clip_rect = clip_rect;
316 }
317}
318
319impl Default for CustomRect {
320 fn default() -> Self {
321 Self {
322 basic_front_resource_config: BasicFrontResourceConfig::default(),
323 position: [0_f32, 0_f32],
324 size: [0_f32, 0_f32],
325 display_info: DisplayInfo::default(),
326 rounding: 2_f32,
327 color: [255, 255, 255],
328 alpha: 255,
329 border_width: 2_f32,
330 border_color: [0, 0, 0],
331 border_alpha: 255,
332 border_kind: BorderKind::default(),
333 tags: Vec::new(),
334 }
335 }
336}
337
338impl CustomRect {
339 pub fn from_config(mut self, config: &CustomRectConfig) -> Self {
340 if let Some(position_size_config) = config.position_size_config {
341 self.basic_front_resource_config.position_size_config = position_size_config;
342 };
343 if let Some(clip_rect) = config.clip_rect {
344 self.basic_front_resource_config.clip_rect = clip_rect;
345 };
346 if let Some(hidden) = config.hidden {
347 self.display_info.hidden = hidden;
348 };
349 if let Some(ignore_render_layer) = config.ignore_render_layer {
350 self.display_info.ignore_render_layer = ignore_render_layer;
351 };
352 if let Some(rounding) = config.rounding {
353 self.rounding = rounding;
354 };
355 if let Some(color) = config.color {
356 self.color = color;
357 };
358 if let Some(alpha) = config.alpha {
359 self.alpha = alpha;
360 };
361 if let Some(border_width) = config.border_width {
362 self.border_width = border_width;
363 };
364 if let Some(border_color) = config.border_color {
365 self.border_color = border_color;
366 };
367 if let Some(border_alpha) = config.border_alpha {
368 self.border_alpha = border_alpha;
369 };
370 if let Some(border_kind) = config.border_kind {
371 self.border_kind = border_kind;
372 };
373 if let Some(tags) = config.tags.clone() {
374 self.tags = tags;
375 };
376 self
377 }
378
379 #[inline]
380 pub fn basic_front_resource_config(
381 mut self,
382 basic_front_resource_config: &BasicFrontResourceConfig,
383 ) -> Self {
384 self.basic_front_resource_config = basic_front_resource_config.clone();
385 self
386 }
387
388 #[inline]
389 pub fn hidden(mut self, hidden: bool) -> Self {
390 self.display_info.hidden = hidden;
391 self
392 }
393
394 #[inline]
395 pub fn ignore_render_layer(mut self, ignore_render_layer: bool) -> Self {
396 self.display_info.ignore_render_layer = ignore_render_layer;
397 self
398 }
399
400 #[inline]
401 pub fn rounding(mut self, rounding: f32) -> Self {
402 self.rounding = rounding;
403 self
404 }
405
406 #[inline]
407 pub fn color(mut self, r: u8, g: u8, b: u8) -> Self {
408 self.color = [r, g, b];
409 self
410 }
411
412 #[inline]
413 pub fn alpha(mut self, alpha: u8) -> Self {
414 self.alpha = alpha;
415 self
416 }
417
418 #[inline]
419 pub fn border_width(mut self, border_width: f32) -> Self {
420 self.border_width = border_width;
421 self
422 }
423
424 #[inline]
425 pub fn border_color(mut self, r: u8, g: u8, b: u8) -> Self {
426 self.border_color = [r, g, b];
427 self
428 }
429
430 #[inline]
431 pub fn border_alpha(mut self, border_alpha: u8) -> Self {
432 self.border_alpha = border_alpha;
433 self
434 }
435
436 #[inline]
437 pub fn border_kind(mut self, border_kind: BorderKind) -> Self {
438 self.border_kind = border_kind;
439 self
440 }
441
442 #[inline]
443 pub fn tags(mut self, tags: &[[String; 2]], replace: bool) -> Self {
444 if replace {
445 self.tags = tags.to_owned();
446 } else {
447 for tag in tags {
448 if let Some(index) = self.tags.iter().position(|x| x[0] == tag[0]) {
449 self.tags.remove(index);
450 };
451 }
452 self.tags.extend(tags.iter().cloned());
453 };
454 self
455 }
456}
457
458#[derive(Clone, PartialEq, Eq, Hash)]
462pub struct DebugTextureHandle(pub TextureHandle);
463
464impl Debug for DebugTextureHandle {
465 fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
466 f.debug_struct("DebugTextureHandle").finish()
468 }
469}
470
471impl DebugTextureHandle {
472 pub fn new(texture_handle: &TextureHandle) -> Self {
473 Self(texture_handle.clone())
474 }
475}
476
477#[derive(Debug, Clone, PartialEq, Eq, Hash)]
481pub enum ImageLoadMethod {
482 ByPath((String, [bool; 2])),
486
487 ByTexture(DebugTextureHandle),
491}
492
493#[derive(Debug, Default, Clone, PartialEq)]
497pub struct ImageConfig {
498 pub position_size_config: Option<PositionSizeConfig>,
502
503 pub clip_rect: Option<Option<PositionSizeConfig>>,
507
508 pub hidden: Option<bool>,
512
513 pub ignore_render_layer: Option<bool>,
517
518 pub alpha: Option<u8>,
522
523 pub overlay_color: Option<[u8; 3]>,
527
528 pub overlay_alpha: Option<u8>,
532
533 pub background_color: Option<[u8; 3]>,
537
538 pub background_alpha: Option<u8>,
542
543 pub rotate_angle: Option<f32>,
547
548 pub rotate_center: Option<[f32; 2]>,
552
553 pub image_load_method: Option<ImageLoadMethod>,
557
558 pub tags: Option<Vec<[String; 2]>>,
562}
563
564impl ImageConfig {
565 pub fn from_image(image: &Image) -> Self {
566 Self {
567 position_size_config: Some(image.basic_front_resource_config.position_size_config),
568 clip_rect: Some(image.basic_front_resource_config.clip_rect),
569 hidden: Some(image.display_info.hidden),
570 ignore_render_layer: Some(image.display_info.ignore_render_layer),
571 alpha: Some(image.alpha),
572 overlay_color: Some(image.overlay_color),
573 overlay_alpha: Some(image.overlay_alpha),
574 background_color: Some(image.background_color),
575 background_alpha: Some(image.background_alpha),
576 rotate_angle: Some(image.rotate_angle),
577 rotate_center: Some(image.rotate_center),
578 image_load_method: Some(image.image_load_method.clone()),
579 tags: Some(image.tags.clone()),
580 }
581 }
582
583 #[inline]
584 pub fn position_size_config(
585 mut self,
586 position_size_config: Option<PositionSizeConfig>,
587 ) -> Self {
588 self.position_size_config = position_size_config;
589 self
590 }
591
592 #[inline]
593 pub fn clip_rect(mut self, clip_rect: Option<Option<PositionSizeConfig>>) -> Self {
594 self.clip_rect = clip_rect;
595 self
596 }
597
598 #[inline]
599 pub fn hidden(mut self, hidden: Option<bool>) -> Self {
600 self.hidden = hidden;
601 self
602 }
603
604 #[inline]
605 pub fn ignore_render_layer(mut self, ignore_render_layer: Option<bool>) -> Self {
606 self.ignore_render_layer = ignore_render_layer;
607 self
608 }
609
610 #[inline]
611 pub fn alpha(mut self, alpha: Option<u8>) -> Self {
612 self.alpha = alpha;
613 self
614 }
615
616 #[inline]
617 pub fn overlay_color(mut self, overlay_color: Option<[u8; 3]>) -> Self {
618 self.overlay_color = overlay_color;
619 self
620 }
621
622 #[inline]
623 pub fn overlay_alpha(mut self, overlay_alpha: Option<u8>) -> Self {
624 self.overlay_alpha = overlay_alpha;
625 self
626 }
627
628 #[inline]
629 pub fn background_color(mut self, background_color: Option<[u8; 3]>) -> Self {
630 self.background_color = background_color;
631 self
632 }
633
634 #[inline]
635 pub fn background_alpha(mut self, background_alpha: Option<u8>) -> Self {
636 self.background_alpha = background_alpha;
637 self
638 }
639
640 #[inline]
641 pub fn rotate_angle(mut self, rotate_angle: Option<f32>) -> Self {
642 self.rotate_angle = rotate_angle;
643 self
644 }
645
646 #[inline]
647 pub fn rotate_center(mut self, rotate_center: Option<[f32; 2]>) -> Self {
648 self.rotate_center = rotate_center;
649 self
650 }
651
652 #[inline]
653 pub fn image_load_method(mut self, image_load_method: Option<ImageLoadMethod>) -> Self {
654 self.image_load_method = image_load_method;
655 self
656 }
657
658 #[inline]
659 pub fn tags(mut self, tags: Option<Vec<[String; 2]>>) -> Self {
660 self.tags = tags;
661 self
662 }
663}
664
665#[derive(Debug, Clone, PartialEq)]
669pub struct Image {
670 pub basic_front_resource_config: BasicFrontResourceConfig,
674
675 pub position: [f32; 2],
679
680 pub size: [f32; 2],
684
685 pub display_info: DisplayInfo,
689
690 pub texture: Option<DebugTextureHandle>,
694
695 pub alpha: u8,
699
700 pub overlay_color: [u8; 3],
704
705 pub overlay_alpha: u8,
709
710 pub background_color: [u8; 3],
714
715 pub background_alpha: u8,
719
720 pub rotate_angle: f32,
724
725 pub rotate_center: [f32; 2],
729
730 pub image_load_method: ImageLoadMethod,
734
735 pub last_frame_path: String,
739
740 pub tags: Vec<[String; 2]>,
744}
745
746impl RustConstructorResource for Image {
747 fn as_any(&self) -> &dyn Any {
748 self
749 }
750
751 fn as_any_mut(&mut self) -> &mut dyn Any {
752 self
753 }
754
755 fn display_display_info(&self) -> Option<DisplayInfo> {
756 Some(self.display_info)
757 }
758
759 fn modify_display_info(&mut self, display_info: DisplayInfo) {
760 self.display_info = display_info;
761 }
762
763 fn display_tags(&self) -> Vec<[String; 2]> {
764 self.tags.clone()
765 }
766
767 fn modify_tags(&mut self, tags: &[[String; 2]], replace: bool) {
768 if replace {
769 self.tags = tags.to_owned();
770 } else {
771 for tag in tags {
772 if let Some(index) = self.tags.iter().position(|x| x[0] == tag[0]) {
773 self.tags.remove(index);
774 };
775 }
776 self.tags.extend(tags.iter().cloned());
777 };
778 }
779}
780
781impl BasicFrontResource for Image {
782 fn display_basic_front_resource_config(&self) -> BasicFrontResourceConfig {
783 self.basic_front_resource_config.clone()
784 }
785
786 fn display_position_size_config(&self) -> PositionSizeConfig {
787 self.basic_front_resource_config.position_size_config
788 }
789
790 fn display_clip_rect(&self) -> Option<PositionSizeConfig> {
791 self.basic_front_resource_config.clip_rect
792 }
793
794 fn display_position(&self) -> [f32; 2] {
795 self.position
796 }
797
798 fn display_size(&self) -> [f32; 2] {
799 self.size
800 }
801
802 fn modify_basic_front_resource_config(
803 &mut self,
804 basic_front_resource_config: BasicFrontResourceConfig,
805 ) {
806 self.basic_front_resource_config = basic_front_resource_config;
807 }
808
809 fn modify_position_size_config(&mut self, position_size_config: PositionSizeConfig) {
810 self.basic_front_resource_config.position_size_config = position_size_config;
811 }
812
813 fn modify_clip_rect(&mut self, clip_rect: Option<PositionSizeConfig>) {
814 self.basic_front_resource_config.clip_rect = clip_rect;
815 }
816}
817
818impl Default for Image {
819 fn default() -> Self {
820 Self {
821 basic_front_resource_config: BasicFrontResourceConfig::default(),
822 position: [0_f32, 0_f32],
823 size: [0_f32, 0_f32],
824 display_info: DisplayInfo::default(),
825 texture: None,
826 alpha: 255,
827 overlay_color: [255, 255, 255],
828 overlay_alpha: 255,
829 background_color: [0, 0, 0],
830 background_alpha: 0,
831 rotate_angle: 0_f32,
832 rotate_center: [0_f32, 0_f32],
833 image_load_method: ImageLoadMethod::ByPath((String::new(), [false, false])),
834 last_frame_path: String::new(),
835 tags: Vec::new(),
836 }
837 }
838}
839
840impl Image {
841 pub fn from_config(mut self, config: &ImageConfig) -> Self {
842 if let Some(position_size_config) = config.position_size_config {
843 self.basic_front_resource_config.position_size_config = position_size_config;
844 };
845 if let Some(clip_rect) = config.clip_rect {
846 self.basic_front_resource_config.clip_rect = clip_rect;
847 };
848 if let Some(hidden) = config.hidden {
849 self.display_info.hidden = hidden;
850 };
851 if let Some(ignore_render_layer) = config.ignore_render_layer {
852 self.display_info.ignore_render_layer = ignore_render_layer;
853 };
854 if let Some(alpha) = config.alpha {
855 self.alpha = alpha;
856 };
857 if let Some(overlay_color) = config.overlay_color {
858 self.overlay_color = overlay_color;
859 };
860 if let Some(overlay_alpha) = config.overlay_alpha {
861 self.overlay_alpha = overlay_alpha;
862 };
863 if let Some(background_color) = config.background_color {
864 self.background_color = background_color;
865 };
866 if let Some(background_alpha) = config.background_alpha {
867 self.background_alpha = background_alpha;
868 };
869 if let Some(rotate_angle) = config.rotate_angle {
870 self.rotate_angle = rotate_angle;
871 };
872 if let Some(rotate_center) = config.rotate_center {
873 self.rotate_center = rotate_center;
874 };
875 if let Some(image_load_method) = config.image_load_method.clone() {
876 self.image_load_method = image_load_method;
877 };
878 if let Some(tags) = config.tags.clone() {
879 self.tags = tags;
880 };
881 self
882 }
883
884 #[inline]
885 pub fn basic_front_resource_config(
886 mut self,
887 basic_front_resource_config: &BasicFrontResourceConfig,
888 ) -> Self {
889 self.basic_front_resource_config = basic_front_resource_config.clone();
890 self
891 }
892
893 #[inline]
894 pub fn hidden(mut self, hidden: bool) -> Self {
895 self.display_info.hidden = hidden;
896 self
897 }
898
899 #[inline]
900 pub fn ignore_render_layer(mut self, ignore_render_layer: bool) -> Self {
901 self.display_info.ignore_render_layer = ignore_render_layer;
902 self
903 }
904
905 #[inline]
906 pub fn alpha(mut self, alpha: u8) -> Self {
907 self.alpha = alpha;
908 self
909 }
910
911 #[inline]
912 pub fn overlay_color(mut self, r: u8, g: u8, b: u8) -> Self {
913 self.overlay_color = [r, g, b];
914 self
915 }
916
917 #[inline]
918 pub fn overlay_alpha(mut self, overlay_alpha: u8) -> Self {
919 self.overlay_alpha = overlay_alpha;
920 self
921 }
922
923 #[inline]
924 pub fn background_color(mut self, r: u8, g: u8, b: u8) -> Self {
925 self.background_color = [r, g, b];
926 self
927 }
928
929 #[inline]
930 pub fn background_alpha(mut self, background_alpha: u8) -> Self {
931 self.background_alpha = background_alpha;
932 self
933 }
934
935 #[inline]
936 pub fn rotate_angle(mut self, rotate_angle: f32) -> Self {
937 self.rotate_angle = rotate_angle;
938 self
939 }
940
941 #[inline]
942 pub fn rotate_center(mut self, x: f32, y: f32) -> Self {
943 self.rotate_center = [x, y];
944 self
945 }
946
947 #[inline]
948 pub fn image_load_method(mut self, image_load_method: &ImageLoadMethod) -> Self {
949 self.image_load_method = image_load_method.clone();
950 self
951 }
952
953 #[inline]
954 pub fn tags(mut self, tags: &[[String; 2]], replace: bool) -> Self {
955 if replace {
956 self.tags = tags.to_owned();
957 } else {
958 for tag in tags {
959 if let Some(index) = self.tags.iter().position(|x| x[0] == tag[0]) {
960 self.tags.remove(index);
961 };
962 }
963 self.tags.extend(tags.iter().cloned());
964 };
965 self
966 }
967}
968
969#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
973pub enum HyperlinkSelectMethod {
974 All(String),
978 Segment(Vec<(usize, String)>),
982}
983
984#[derive(Debug, Default, Clone, PartialEq, PartialOrd)]
988pub struct TextConfig {
989 pub position_size_config: Option<PositionSizeConfig>,
993
994 pub clip_rect: Option<Option<PositionSizeConfig>>,
998
999 pub hidden: Option<bool>,
1003
1004 pub ignore_render_layer: Option<bool>,
1008
1009 pub content: Option<String>,
1013
1014 pub font_size: Option<f32>,
1018
1019 pub color: Option<[u8; 3]>,
1023
1024 pub alpha: Option<u8>,
1028
1029 pub background_color: Option<[u8; 3]>,
1033
1034 pub background_alpha: Option<u8>,
1038
1039 pub background_rounding: Option<f32>,
1043
1044 pub font: Option<String>,
1048
1049 pub selectable: Option<bool>,
1053
1054 pub hyperlink_text: Option<Vec<(String, HyperlinkSelectMethod)>>,
1058
1059 pub auto_fit: Option<[bool; 2]>,
1063
1064 pub tags: Option<Vec<[String; 2]>>,
1068}
1069
1070impl TextConfig {
1071 pub fn from_text(text: &Text) -> Self {
1072 Self {
1073 position_size_config: Some(text.basic_front_resource_config.position_size_config),
1074 clip_rect: Some(text.basic_front_resource_config.clip_rect),
1075 hidden: Some(text.display_info.hidden),
1076 ignore_render_layer: Some(text.display_info.ignore_render_layer),
1077 content: Some(text.content.clone()),
1078 font_size: Some(text.font_size),
1079 color: Some(text.color),
1080 alpha: Some(text.alpha),
1081 background_color: Some(text.background_color),
1082 background_alpha: Some(text.background_alpha),
1083 background_rounding: Some(text.background_rounding),
1084 font: Some(text.font.clone()),
1085 selectable: Some(text.selectable),
1086 hyperlink_text: Some(text.hyperlink_text.clone()),
1087 auto_fit: Some(text.auto_fit),
1088 tags: Some(text.tags.clone()),
1089 }
1090 }
1091
1092 #[inline]
1093 pub fn position_size_config(
1094 mut self,
1095 position_size_config: Option<PositionSizeConfig>,
1096 ) -> Self {
1097 self.position_size_config = position_size_config;
1098 self
1099 }
1100
1101 #[inline]
1102 pub fn clip_rect(mut self, clip_rect: Option<Option<PositionSizeConfig>>) -> Self {
1103 self.clip_rect = clip_rect;
1104 self
1105 }
1106
1107 #[inline]
1108 pub fn hidden(mut self, hidden: Option<bool>) -> Self {
1109 self.hidden = hidden;
1110 self
1111 }
1112
1113 #[inline]
1114 pub fn ignore_render_layer(mut self, ignore_render_layer: Option<bool>) -> Self {
1115 self.ignore_render_layer = ignore_render_layer;
1116 self
1117 }
1118
1119 #[inline]
1120 pub fn content(mut self, content: Option<String>) -> Self {
1121 self.content = content;
1122 self
1123 }
1124
1125 #[inline]
1126 pub fn font_size(mut self, font_size: Option<f32>) -> Self {
1127 self.font_size = font_size;
1128 self
1129 }
1130
1131 #[inline]
1132 pub fn color(mut self, color: Option<[u8; 3]>) -> Self {
1133 self.color = color;
1134 self
1135 }
1136
1137 #[inline]
1138 pub fn alpha(mut self, alpha: Option<u8>) -> Self {
1139 self.alpha = alpha;
1140 self
1141 }
1142
1143 #[inline]
1144 pub fn background_color(mut self, background_color: Option<[u8; 3]>) -> Self {
1145 self.background_color = background_color;
1146 self
1147 }
1148
1149 #[inline]
1150 pub fn background_alpha(mut self, background_alpha: Option<u8>) -> Self {
1151 self.background_alpha = background_alpha;
1152 self
1153 }
1154
1155 #[inline]
1156 pub fn background_rounding(mut self, background_rounding: Option<f32>) -> Self {
1157 self.background_rounding = background_rounding;
1158 self
1159 }
1160
1161 #[inline]
1162 pub fn font(mut self, font: Option<String>) -> Self {
1163 self.font = font;
1164 self
1165 }
1166
1167 #[inline]
1168 pub fn selectable(mut self, selectable: Option<bool>) -> Self {
1169 self.selectable = selectable;
1170 self
1171 }
1172
1173 #[inline]
1174 pub fn hyperlink_text(
1175 mut self,
1176 hyperlink_text: Option<Vec<(String, HyperlinkSelectMethod)>>,
1177 ) -> Self {
1178 self.hyperlink_text = hyperlink_text;
1179 self
1180 }
1181
1182 #[inline]
1183 pub fn auto_fit(mut self, auto_fit: Option<[bool; 2]>) -> Self {
1184 self.auto_fit = auto_fit;
1185 self
1186 }
1187
1188 #[inline]
1189 pub fn tags(mut self, tags: Option<Vec<[String; 2]>>) -> Self {
1190 self.tags = tags;
1191 self
1192 }
1193}
1194
1195#[derive(Debug, Clone, PartialEq, PartialOrd)]
1199pub struct Text {
1200 pub basic_front_resource_config: BasicFrontResourceConfig,
1204
1205 pub position: [f32; 2],
1209
1210 pub size: [f32; 2],
1214
1215 pub display_info: DisplayInfo,
1219
1220 pub content: String,
1224
1225 pub font_size: f32,
1229
1230 pub color: [u8; 3],
1234
1235 pub alpha: u8,
1239
1240 pub background_color: [u8; 3],
1244
1245 pub background_alpha: u8,
1249
1250 pub background_rounding: f32,
1254
1255 pub font: String,
1259
1260 pub selectable: bool,
1264
1265 pub hyperlink_text: Vec<(String, HyperlinkSelectMethod)>,
1269
1270 pub hyperlink_index: Vec<(usize, usize, String)>,
1274
1275 pub auto_fit: [bool; 2],
1279
1280 pub last_frame_content: String,
1284
1285 pub selection: Option<(usize, usize)>,
1289
1290 pub truncate_size: [f32; 2],
1294
1295 pub actual_size: [f32; 2],
1299
1300 pub tags: Vec<[String; 2]>,
1304}
1305
1306impl RustConstructorResource for Text {
1307 fn as_any(&self) -> &dyn Any {
1308 self
1309 }
1310
1311 fn as_any_mut(&mut self) -> &mut dyn Any {
1312 self
1313 }
1314
1315 fn display_display_info(&self) -> Option<DisplayInfo> {
1316 Some(self.display_info)
1317 }
1318
1319 fn modify_display_info(&mut self, display_info: DisplayInfo) {
1320 self.display_info = display_info;
1321 }
1322
1323 fn display_tags(&self) -> Vec<[String; 2]> {
1324 self.tags.clone()
1325 }
1326
1327 fn modify_tags(&mut self, tags: &[[String; 2]], replace: bool) {
1328 if replace {
1329 self.tags = tags.to_owned();
1330 } else {
1331 for tag in tags {
1332 if let Some(index) = self.tags.iter().position(|x| x[0] == tag[0]) {
1333 self.tags.remove(index);
1334 };
1335 }
1336 self.tags.extend(tags.iter().cloned());
1337 };
1338 }
1339}
1340
1341impl BasicFrontResource for Text {
1342 fn display_basic_front_resource_config(&self) -> BasicFrontResourceConfig {
1343 self.basic_front_resource_config.clone()
1344 }
1345
1346 fn display_position_size_config(&self) -> PositionSizeConfig {
1347 self.basic_front_resource_config.position_size_config
1348 }
1349
1350 fn display_clip_rect(&self) -> Option<PositionSizeConfig> {
1351 self.basic_front_resource_config.clip_rect
1352 }
1353
1354 fn display_position(&self) -> [f32; 2] {
1355 self.position
1356 }
1357
1358 fn display_size(&self) -> [f32; 2] {
1359 self.size
1360 }
1361
1362 fn modify_basic_front_resource_config(
1363 &mut self,
1364 basic_front_resource_config: BasicFrontResourceConfig,
1365 ) {
1366 self.basic_front_resource_config = basic_front_resource_config;
1367 }
1368
1369 fn modify_position_size_config(&mut self, position_size_config: PositionSizeConfig) {
1370 self.basic_front_resource_config.position_size_config = position_size_config;
1371 }
1372
1373 fn modify_clip_rect(&mut self, clip_rect: Option<PositionSizeConfig>) {
1374 self.basic_front_resource_config.clip_rect = clip_rect;
1375 }
1376}
1377
1378impl Default for Text {
1379 fn default() -> Self {
1380 Self {
1381 basic_front_resource_config: BasicFrontResourceConfig::default(),
1382 position: [0_f32, 0_f32],
1383 size: [0_f32, 0_f32],
1384 display_info: DisplayInfo::default(),
1385 content: String::from("Hello world"),
1386 font_size: 16_f32,
1387 color: [255, 255, 255],
1388 alpha: 255,
1389 background_color: [0, 0, 0],
1390 background_alpha: 0,
1391 background_rounding: 2_f32,
1392 font: String::new(),
1393 selectable: true,
1394 auto_fit: [true, true],
1395 hyperlink_text: Vec::new(),
1396 hyperlink_index: Vec::new(),
1397 last_frame_content: String::from(""),
1398 selection: None,
1399 truncate_size: [0_f32, 0_f32],
1400 actual_size: [0_f32, 0_f32],
1401 tags: Vec::new(),
1402 }
1403 }
1404}
1405
1406impl Text {
1407 pub fn from_config(mut self, config: &TextConfig) -> Self {
1408 if let Some(position_size_config) = config.position_size_config {
1409 self.basic_front_resource_config.position_size_config = position_size_config;
1410 };
1411 if let Some(clip_rect) = config.clip_rect {
1412 self.basic_front_resource_config.clip_rect = clip_rect;
1413 };
1414 if let Some(hidden) = config.hidden {
1415 self.display_info.hidden = hidden;
1416 };
1417 if let Some(ignore_render_layer) = config.ignore_render_layer {
1418 self.display_info.ignore_render_layer = ignore_render_layer;
1419 };
1420 if let Some(content) = config.content.clone() {
1421 self.content = content;
1422 };
1423 if let Some(font_size) = config.font_size {
1424 self.font_size = font_size;
1425 };
1426 if let Some(color) = config.color {
1427 self.color = color;
1428 };
1429 if let Some(alpha) = config.alpha {
1430 self.alpha = alpha;
1431 };
1432 if let Some(background_color) = config.background_color {
1433 self.background_color = background_color;
1434 };
1435 if let Some(background_alpha) = config.background_alpha {
1436 self.background_alpha = background_alpha;
1437 };
1438 if let Some(background_rounding) = config.background_rounding {
1439 self.background_rounding = background_rounding;
1440 };
1441 if let Some(font) = config.font.clone() {
1442 self.font = font;
1443 };
1444 if let Some(selectable) = config.selectable {
1445 self.selectable = selectable;
1446 };
1447 if let Some(hyperlink_text) = config.hyperlink_text.clone() {
1448 self.hyperlink_text = hyperlink_text;
1449 };
1450 if let Some(auto_fit) = config.auto_fit {
1451 self.auto_fit = auto_fit;
1452 };
1453 if let Some(tags) = config.tags.clone() {
1454 self.tags = tags;
1455 };
1456 self
1457 }
1458
1459 #[inline]
1460 pub fn basic_front_resource_config(
1461 mut self,
1462 basic_front_resource_config: &BasicFrontResourceConfig,
1463 ) -> Self {
1464 self.basic_front_resource_config = basic_front_resource_config.clone();
1465 self
1466 }
1467
1468 #[inline]
1469 pub fn hidden(mut self, hidden: bool) -> Self {
1470 self.display_info.hidden = hidden;
1471 self
1472 }
1473
1474 #[inline]
1475 pub fn ignore_render_layer(mut self, ignore_render_layer: bool) -> Self {
1476 self.display_info.ignore_render_layer = ignore_render_layer;
1477 self
1478 }
1479
1480 #[inline]
1481 pub fn content(mut self, content: &str) -> Self {
1482 self.content = content.to_string();
1483 self
1484 }
1485
1486 #[inline]
1487 pub fn font_size(mut self, font_size: f32) -> Self {
1488 self.font_size = font_size;
1489 self
1490 }
1491
1492 #[inline]
1493 pub fn color(mut self, r: u8, g: u8, b: u8) -> Self {
1494 self.color = [r, g, b];
1495 self
1496 }
1497
1498 #[inline]
1499 pub fn alpha(mut self, alpha: u8) -> Self {
1500 self.alpha = alpha;
1501 self
1502 }
1503
1504 #[inline]
1505 pub fn background_color(mut self, r: u8, g: u8, b: u8) -> Self {
1506 self.background_color = [r, g, b];
1507 self
1508 }
1509
1510 #[inline]
1511 pub fn background_alpha(mut self, alpha: u8) -> Self {
1512 self.background_alpha = alpha;
1513 self
1514 }
1515
1516 #[inline]
1517 pub fn background_rounding(mut self, background_rounding: f32) -> Self {
1518 self.background_rounding = background_rounding;
1519 self
1520 }
1521
1522 #[inline]
1523 pub fn font(mut self, font: &str) -> Self {
1524 self.font = font.to_string();
1525 self
1526 }
1527
1528 #[inline]
1529 pub fn selectable(mut self, selectable: bool) -> Self {
1530 self.selectable = selectable;
1531 self
1532 }
1533
1534 #[inline]
1535 pub fn push_hyperlink_text(
1536 mut self,
1537 target_text: &str,
1538 select_method: HyperlinkSelectMethod,
1539 ) -> Self {
1540 self.hyperlink_text
1541 .push((target_text.to_string(), select_method));
1542 self
1543 }
1544
1545 #[inline]
1546 pub fn hyperlink_text(mut self, hyperlink_text: Vec<(String, HyperlinkSelectMethod)>) -> Self {
1547 self.hyperlink_text = hyperlink_text;
1548 self
1549 }
1550
1551 #[inline]
1552 pub fn auto_fit(mut self, x: bool, y: bool) -> Self {
1553 self.auto_fit = [x, y];
1554 self
1555 }
1556
1557 #[inline]
1558 pub fn tags(mut self, tags: &[[String; 2]], replace: bool) -> Self {
1559 if replace {
1560 self.tags = tags.to_owned();
1561 } else {
1562 for tag in tags {
1563 if let Some(index) = self.tags.iter().position(|x| x[0] == tag[0]) {
1564 self.tags.remove(index);
1565 };
1566 }
1567 self.tags.extend(tags.iter().cloned());
1568 };
1569 self
1570 }
1571}