pandora_kit/
popup_config.rs1use hefesto_widgets::{BorderType, PopupSize};
2
3#[derive(Clone, Default)]
4pub struct PopupConfig {
5 pub width: Option<u16>,
6 pub height: Option<u16>,
7 pub border_type: Option<BorderType>,
8 pub header: bool,
9}
10
11impl PopupConfig {
12 pub fn new() -> Self {
13 Self::default()
14 }
15
16 pub fn width(mut self, w: u16) -> Self {
17 self.width = Some(w);
18 self
19 }
20
21 pub fn height(mut self, h: u16) -> Self {
22 self.height = Some(h);
23 self
24 }
25
26 pub fn border_type(mut self, bt: BorderType) -> Self {
27 self.border_type = Some(bt);
28 self
29 }
30
31 pub fn header(mut self) -> Self {
32 self.header = true;
33 self
34 }
35}
36
37pub trait PopupConfigurable<'a>: Sized {
38 fn with_config(self, config: &PopupConfig) -> Self;
39}
40
41macro_rules! impl_configurable {
42 ($ty:ty) => {
43 impl<'a> PopupConfigurable<'a> for $ty {
44 fn with_config(self, config: &PopupConfig) -> Self {
45 let mut s = self;
46 if let Some(w) = config.width {
47 s = s.width(PopupSize::Fixed(w));
48 }
49 if let Some(h) = config.height {
50 s = s.height(PopupSize::Fixed(h));
51 }
52 if let Some(bt) = config.border_type {
53 s = s.border_type(bt);
54 }
55 if config.header {
56 s = s.header();
57 }
58 s
59 }
60 }
61 };
62}
63
64impl_configurable!(hefesto_widgets::ChoosePopup<'_>);
65impl_configurable!(hefesto_widgets::ThemedConfirmationPopup<'_>);
66impl_configurable!(hefesto_widgets::TextInputPopup<'_>);
67impl_configurable!(hefesto_widgets::TreePopup<'_>);
68
69impl<'a> PopupConfigurable<'a> for hefesto_widgets::SpinPopup<'_> {
70 fn with_config(self, config: &PopupConfig) -> Self {
71 let mut s = self;
72 if let Some(w) = config.width { s = s.width(PopupSize::Fixed(w)); }
73 if let Some(h) = config.height { s = s.height(PopupSize::Fixed(h)); }
74 if let Some(bt) = config.border_type { s = s.border_type(bt); }
75 s
76 }
77}
78
79impl<'a> PopupConfigurable<'a> for hefesto_widgets::FileBrowserPopup {
80 fn with_config(self, config: &PopupConfig) -> Self {
81 let mut s = self;
82 if let Some(w) = config.width { s = s.width(PopupSize::Fixed(w)); }
83 if let Some(h) = config.height { s = s.height(PopupSize::Fixed(h)); }
84 if let Some(bt) = config.border_type { s = s.border_type(bt); }
85 if config.header { s = s.header(); }
86 s
87 }
88}