1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#[macro_export]
macro_rules! stack {
(
widget {
$($widget:tt)*
}
$(children_properties [
$( ($child_name:expr, $child_title:expr, $child_icon:expr) )*
])?
) => {{
let widget = gtk::StackBuilder::new().visible(true).build();
widget!(widget { $($widget)* });
$(
let mut children_props: Vec<(Option<&str>, Option<String>, Option<&str>)> = Vec::new();
$( children_props.push(($child_name, $child_title, $child_icon));
)*
if children_props.len() != widget.get_children().len() {
panic!("Stack has {} children but {} child property definitions.", children_props.len(), widget.get_children().len());
}
for (i, child) in widget.get_children().iter().enumerate() {
let props = children_props.get(i).unwrap();
widget.set_child_name(child, props.0.as_deref());
widget.set_child_title(child, props.1.as_deref());
widget.set_child_icon_name(child, props.2.as_deref());
}
)?
widget
}};
(
$($child:expr)*
) => {{
let widget = gtk::StackBuilder::new().visible(true).build();
widget! (widget {
children [
$($child)*
]
});
for (i, child) in widget.get_children().iter().enumerate() {
widget.set_child_name(child, format!("{}.{}", child.get_widget_name().as_str(), i).as_str().into());
widget.set_child_title(child, format!("{}.{}", child.get_widget_name().as_str(), i).as_str().into());
}
widget
}}
}