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
86
87
88
89
90
91
92
93
94
use proc_macro2::TokenStream as TokenStream2;
use syn::{Path, Type, Visibility};
use crate::widgets::{PropertyType, ReturnedWidget, Widget};
#[derive(Debug, Default)]
pub(super) struct TokenStreams {
pub struct_fields: TokenStream2,
pub init_widgets: TokenStream2,
pub assign_properties: TokenStream2,
pub connect_widgets: TokenStream2,
pub return_fields: TokenStream2,
pub view: TokenStream2,
pub track: TokenStream2,
pub connect: TokenStream2,
pub connect_components: TokenStream2,
}
impl Widget {
pub(super) fn generate_micro_widget_tokens_recursively(
&self,
streams: &mut TokenStreams,
vis: &Option<Visibility>,
model_type: &Type,
relm4_path: &Path,
) {
self.struct_fields_stream(&mut streams.struct_fields, vis);
self.init_widgets_stream(&mut streams.init_widgets);
self.return_stream(&mut streams.return_fields);
for prop in &self.properties.properties {
prop.connect_widgets_stream(&mut streams.connect_widgets, &self.name);
if let PropertyType::Widget(widget) = &prop.ty {
widget
.generate_micro_widget_tokens_recursively(streams, vis, model_type, relm4_path);
if let Some(returned_widget) = &widget.returned_widget {
returned_widget.generate_micro_widget_tokens_recursively(
streams, vis, model_type, relm4_path,
);
}
} else {
prop.property_init_stream(&mut streams.assign_properties, &self.name, relm4_path);
prop.view_stream(&mut streams.view, &self.name, relm4_path, false);
prop.track_stream(&mut streams.track, &self.name, model_type, false);
prop.connect_stream(&mut streams.connect, &self.name);
prop.connect_component_stream(&mut streams.connect_components, &self.name);
}
}
}
}
impl ReturnedWidget {
pub(super) fn generate_micro_widget_tokens_recursively(
&self,
streams: &mut TokenStreams,
vis: &Option<Visibility>,
model_type: &Type,
relm4_path: &Path,
) {
self.struct_fields_stream(&mut streams.struct_fields, vis);
self.return_stream(&mut streams.return_fields);
for prop in &self.properties.properties {
prop.connect_widgets_stream(&mut streams.connect_widgets, &self.name);
if let PropertyType::Widget(widget) = &prop.ty {
widget
.generate_micro_widget_tokens_recursively(streams, vis, model_type, relm4_path);
} else {
prop.property_init_stream(&mut streams.assign_properties, &self.name, relm4_path);
prop.connect_stream(&mut streams.connect, &self.name);
prop.view_stream(&mut streams.view, &self.name, relm4_path, false);
prop.track_stream(&mut streams.track, &self.name, model_type, false);
prop.connect_component_stream(&mut streams.connect_components, &self.name);
}
}
}
}