1use crate::{
5 DisplayInfo, RustConstructorId, RustConstructorResource,
6 basic_front::{CustomRectConfig, ImageConfig, TextConfig},
7};
8use egui::PointerButton;
9use std::any::Any;
10
11#[derive(Clone, Debug, PartialEq)]
15pub enum BackgroundType {
16 Image(ImageConfig),
20
21 CustomRect(CustomRectConfig),
25}
26
27impl Default for BackgroundType {
28 fn default() -> Self {
29 BackgroundType::CustomRect(CustomRectConfig::default())
30 }
31}
32
33#[derive(Clone, Debug, Default, PartialEq)]
37pub struct Background {
38 pub background_type: BackgroundType,
42
43 pub auto_update: bool,
47
48 pub use_background_tags: bool,
52
53 pub tags: Vec<[String; 2]>,
57}
58
59impl RustConstructorResource for Background {
60 fn as_any(&self) -> &dyn Any {
61 self
62 }
63
64 fn as_any_mut(&mut self) -> &mut dyn Any {
65 self
66 }
67
68 fn display_display_info(&self) -> Option<DisplayInfo> {
69 None
70 }
71
72 fn modify_display_info(&mut self, _display_info: DisplayInfo) {}
73
74 fn display_tags(&self) -> Vec<[String; 2]> {
75 self.tags.clone()
76 }
77
78 fn modify_tags(&mut self, tags: &[[String; 2]], replace: bool) {
79 if replace {
80 self.tags = tags.to_owned();
81 } else {
82 for tag in tags {
83 if let Some(index) = self.tags.iter().position(|x| x[0] == tag[0]) {
84 self.tags.remove(index);
85 };
86 }
87 self.tags.extend(tags.iter().cloned());
88 };
89 }
90}
91
92impl Background {
93 #[inline]
94 pub fn background_type(mut self, background_type: &BackgroundType) -> Self {
95 self.background_type = background_type.clone();
96 self
97 }
98
99 #[inline]
100 pub fn auto_update(mut self, auto_update: bool) -> Self {
101 self.auto_update = auto_update;
102 self
103 }
104
105 #[inline]
106 pub fn use_background_tags(mut self, use_background_tags: bool) -> Self {
107 self.use_background_tags = use_background_tags;
108 self
109 }
110
111 #[inline]
112 pub fn tags(mut self, tags: &[[String; 2]], replace: bool) -> Self {
113 if replace {
114 self.tags = tags.to_owned();
115 } else {
116 for tag in tags {
117 if let Some(index) = self.tags.iter().position(|x| x[0] == tag[0]) {
118 self.tags.remove(index);
119 };
120 }
121 self.tags.extend(tags.iter().cloned());
122 };
123 self
124 }
125}
126
127#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
131pub enum ScrollLengthMethod {
132 Fixed(f32),
136 AutoFit(f32),
140}
141
142#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
150pub enum ClickAim {
151 Move,
155 TopResize,
159 BottomResize,
163 LeftResize,
167 RightResize,
171 LeftTopResize,
175 RightTopResize,
179 LeftBottomResize,
183 RightBottomResize,
187}
188
189#[derive(Debug, Clone, PartialEq)]
197pub enum ScrollBarDisplayMethod {
198 Always(BackgroundType, [f32; 2], f32),
202 OnlyScroll(BackgroundType, [f32; 2], f32),
206 Hidden,
210}
211
212#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
220pub enum PanelMargin {
221 Vertical([f32; 4], bool),
225 Horizontal([f32; 4], bool),
229 None([f32; 4], bool),
233}
234
235#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
239pub struct PanelLayout {
240 pub panel_margin: PanelMargin,
244 pub panel_location: PanelLocation,
248}
249
250#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
258pub enum PanelLocation {
259 Absolute([f32; 2]),
263 Relative([[u32; 2]; 2]),
267}
268
269#[derive(Debug, Default, Clone, PartialEq, PartialOrd)]
278pub struct PanelStorage {
279 pub id: RustConstructorId,
283
284 pub ignore_render_layer: bool,
288
289 pub hidden: bool,
293
294 pub origin_size: [f32; 2],
298}
299
300#[derive(Debug, Clone, PartialEq)]
304pub struct ResourcePanel {
305 pub resizable: [bool; 4],
309
310 pub background: BackgroundType,
314
315 pub min_size: [f32; 2],
319
320 pub max_size: Option<[f32; 2]>,
324
325 pub movable: [bool; 2],
329
330 pub scroll_length_method: [Option<ScrollLengthMethod>; 2],
334
335 pub scroll_sensitivity: f32,
339
340 pub use_smooth_scroll_delta: bool,
344
345 pub scroll_bar_display_method: ScrollBarDisplayMethod,
349
350 pub layout: PanelLayout,
354
355 pub hidden: bool,
359
360 pub reverse_scroll_direction: [bool; 2],
364
365 pub auto_shrink: [bool; 2],
369
370 pub scroll_length: [f32; 2],
374
375 pub scroll_progress: [f32; 2],
379
380 pub last_frame_mouse_status: Option<([f32; 2], ClickAim, [f32; 2])>,
384
385 pub scrolled: [bool; 2],
389
390 pub scroll_bar_alpha: [u8; 2],
394
395 pub resource_storage: Vec<PanelStorage>,
399
400 pub tags: Vec<[String; 2]>,
404}
405
406impl RustConstructorResource for ResourcePanel {
407 fn as_any(&self) -> &dyn Any {
408 self
409 }
410
411 fn as_any_mut(&mut self) -> &mut dyn Any {
412 self
413 }
414
415 fn display_display_info(&self) -> Option<DisplayInfo> {
416 None
417 }
418
419 fn modify_display_info(&mut self, _display_info: DisplayInfo) {}
420
421 fn display_tags(&self) -> Vec<[String; 2]> {
422 self.tags.clone()
423 }
424
425 fn modify_tags(&mut self, tags: &[[String; 2]], replace: bool) {
426 if replace {
427 self.tags = tags.to_owned();
428 } else {
429 for tag in tags {
430 if let Some(index) = self.tags.iter().position(|x| x[0] == tag[0]) {
431 self.tags.remove(index);
432 };
433 }
434 self.tags.extend(tags.iter().cloned());
435 };
436 }
437}
438
439impl Default for ResourcePanel {
440 fn default() -> Self {
441 Self {
442 resizable: [true, true, true, true],
443 background: BackgroundType::default(),
444 min_size: [10_f32, 10_f32],
445 max_size: None,
446 movable: [true, true],
447 scroll_length_method: [None, None],
448 scroll_sensitivity: 0_f32,
449 use_smooth_scroll_delta: true,
450 scroll_bar_display_method: ScrollBarDisplayMethod::OnlyScroll(
451 BackgroundType::default(),
452 [4_f32, 2_f32],
453 4_f32,
454 ),
455 layout: (PanelLayout {
456 panel_margin: PanelMargin::Vertical([0_f32, 0_f32, 0_f32, 0_f32], false),
457 panel_location: PanelLocation::Absolute([0_f32, 0_f32]),
458 }),
459 hidden: false,
460 reverse_scroll_direction: [false, false],
461 auto_shrink: [true, false],
462 scroll_length: [0_f32, 0_f32],
463 scroll_progress: [0_f32, 0_f32],
464 last_frame_mouse_status: None,
465 scrolled: [false, false],
466 scroll_bar_alpha: [0, 0],
467 resource_storage: Vec::new(),
468 tags: Vec::new(),
469 }
470 }
471}
472
473impl ResourcePanel {
474 #[inline]
475 pub fn resizable(mut self, top: bool, bottom: bool, left: bool, right: bool) -> Self {
476 self.resizable = [top, bottom, left, right];
477 self
478 }
479
480 #[inline]
481 pub fn background(mut self, background: &BackgroundType) -> Self {
482 self.background = background.clone();
483 self
484 }
485
486 #[inline]
487 pub fn min_size(mut self, width: f32, height: f32) -> Self {
488 self.min_size = [width, height];
489 self
490 }
491
492 #[inline]
493 pub fn max_size(mut self, max_size: Option<[f32; 2]>) -> Self {
494 self.max_size = max_size;
495 self
496 }
497
498 #[inline]
499 pub fn movable(mut self, horizontal: bool, vertical: bool) -> Self {
500 self.movable = [horizontal, vertical];
501 self
502 }
503
504 #[inline]
505 pub fn scroll_length_method(
506 mut self,
507 horizontal: Option<ScrollLengthMethod>,
508 vertical: Option<ScrollLengthMethod>,
509 ) -> Self {
510 self.scroll_length_method = [horizontal, vertical];
511 self
512 }
513
514 #[inline]
515 pub fn scroll_sensitivity(mut self, scroll_sensitivity: f32) -> Self {
516 self.scroll_sensitivity = scroll_sensitivity;
517 self
518 }
519
520 #[inline]
521 pub fn use_smooth_scroll_delta(mut self, use_smooth_scroll_delta: bool) -> Self {
522 self.use_smooth_scroll_delta = use_smooth_scroll_delta;
523 self
524 }
525
526 #[inline]
527 pub fn scroll_bar_display_method(
528 mut self,
529 scroll_bar_display_method: ScrollBarDisplayMethod,
530 ) -> Self {
531 self.scroll_bar_display_method = scroll_bar_display_method;
532 self
533 }
534
535 #[inline]
536 pub fn layout(mut self, layout: PanelLayout) -> Self {
537 self.layout = layout;
538 self
539 }
540
541 #[inline]
542 pub fn hidden(mut self, hidden: bool) -> Self {
543 self.hidden = hidden;
544 self
545 }
546
547 #[inline]
548 pub fn reverse_scroll_direction(mut self, horizontal: bool, vertical: bool) -> Self {
549 self.reverse_scroll_direction = [horizontal, vertical];
550 self
551 }
552
553 #[inline]
554 pub fn auto_shrink(mut self, horizontal: bool, vertical: bool) -> Self {
555 self.auto_shrink = [horizontal, vertical];
556 self
557 }
558
559 #[inline]
560 pub fn tags(mut self, tags: &[[String; 2]], replace: bool) -> Self {
561 if replace {
562 self.tags = tags.to_owned();
563 } else {
564 for tag in tags {
565 if let Some(index) = self.tags.iter().position(|x| x[0] == tag[0]) {
566 self.tags.remove(index);
567 };
568 }
569 self.tags.extend(tags.iter().cloned());
570 };
571 self
572 }
573}
574
575#[derive(Clone, Debug, Default, PartialEq)]
579pub struct SwitchAppearanceConfig {
580 pub background_config: BackgroundType,
584
585 pub text_config: TextConfig,
589
590 pub hint_text_config: TextConfig,
594}
595
596#[derive(Debug, Clone, Copy, PartialEq, Eq)]
600pub struct SwitchClickConfig {
601 pub click_method: PointerButton,
605
606 pub action: bool,
610}
611
612#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
616pub struct SwitchData {
617 pub switched: bool,
621
622 pub last_frame_clicked: Option<usize>,
626
627 pub state: u32,
631}
632
633#[derive(Debug, Clone, PartialEq)]
637pub struct Switch {
638 pub appearance: Vec<SwitchAppearanceConfig>,
642
643 pub background_type: BackgroundType,
647
648 pub text_config: TextConfig,
652
653 pub hint_text_config: TextConfig,
657
658 pub enable_animation: [bool; 2],
662
663 pub state_amount: u32,
667
668 pub click_method: Vec<SwitchClickConfig>,
672
673 pub enable: bool,
677
678 pub state: u32,
682
683 pub last_frame_hovered: bool,
687
688 pub last_frame_clicked: Option<usize>,
692
693 pub switched: bool,
697
698 pub use_switch_tags: bool,
702
703 pub tags: Vec<[String; 2]>,
707}
708
709impl RustConstructorResource for Switch {
710 fn as_any(&self) -> &dyn Any {
711 self
712 }
713
714 fn as_any_mut(&mut self) -> &mut dyn Any {
715 self
716 }
717
718 fn display_display_info(&self) -> Option<DisplayInfo> {
719 None
720 }
721
722 fn modify_display_info(&mut self, _display_info: DisplayInfo) {}
723
724 fn display_tags(&self) -> Vec<[String; 2]> {
725 self.tags.clone()
726 }
727
728 fn modify_tags(&mut self, tags: &[[String; 2]], replace: bool) {
729 if replace {
730 self.tags = tags.to_owned();
731 } else {
732 for tag in tags {
733 if let Some(index) = self.tags.iter().position(|x| x[0] == tag[0]) {
734 self.tags.remove(index);
735 };
736 }
737 self.tags.extend(tags.iter().cloned());
738 };
739 }
740}
741
742impl Default for Switch {
743 fn default() -> Self {
744 Self {
745 appearance: vec![],
746 background_type: BackgroundType::default(),
747 text_config: TextConfig::default(),
748 hint_text_config: TextConfig::default(),
749 enable_animation: [false, false],
750 state_amount: 0,
751 click_method: vec![],
752 enable: true,
753 state: 0,
754 last_frame_hovered: false,
755 last_frame_clicked: None,
756 switched: false,
757 use_switch_tags: false,
758 tags: Vec::new(),
759 }
760 }
761}
762
763impl Switch {
764 #[inline]
765 pub fn appearance(mut self, appearance: &[SwitchAppearanceConfig]) -> Self {
766 self.appearance = appearance.to_owned();
767 self
768 }
769
770 #[inline]
771 pub fn background_type(mut self, background_type: &BackgroundType) -> Self {
772 self.background_type = background_type.clone();
773 self
774 }
775
776 #[inline]
777 pub fn text_config(mut self, text_config: &TextConfig) -> Self {
778 self.text_config = text_config.clone();
779 self
780 }
781
782 #[inline]
783 pub fn hint_text_config(mut self, hint_text_config: &TextConfig) -> Self {
784 self.hint_text_config = hint_text_config.clone();
785 self
786 }
787
788 #[inline]
789 pub fn enable_animation(mut self, enable_hover: bool, enable_click: bool) -> Self {
790 self.enable_animation = [enable_hover, enable_click];
791 self
792 }
793
794 #[inline]
795 pub fn state_amount(mut self, state_amount: u32) -> Self {
796 self.state_amount = state_amount;
797 self
798 }
799
800 #[inline]
801 pub fn click_method(mut self, click_method: Vec<SwitchClickConfig>) -> Self {
802 self.click_method = click_method;
803 self
804 }
805
806 #[inline]
807 pub fn enable(mut self, enable: bool) -> Self {
808 self.enable = enable;
809 self
810 }
811
812 #[inline]
813 pub fn use_switch_tags(mut self, use_switch_tags: bool) -> Self {
814 self.use_switch_tags = use_switch_tags;
815 self
816 }
817
818 #[inline]
819 pub fn tags(mut self, tags: &[[String; 2]], replace: bool) -> Self {
820 if replace {
821 self.tags = tags.to_owned();
822 } else {
823 for tag in tags {
824 if let Some(index) = self.tags.iter().position(|x| x[0] == tag[0]) {
825 self.tags.remove(index);
826 };
827 }
828 self.tags.extend(tags.iter().cloned());
829 };
830 self
831 }
832}