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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
use gtk;
use gtk::{ContainerExt, IsA, Object, WidgetExt};
use component::Component;
use super::{DisplayVariant, RemoteRelm, create_widget, init_component};
use widget::Widget;
pub trait Container: Widget {
type Container;
fn container(&self) -> &Self::Container;
}
pub trait ContainerWidget
where Self: Sized,
{
fn add_widget<WIDGET, MSG>(&self, relm: &RemoteRelm<MSG>) -> Component<WIDGET>
where MSG: Clone + DisplayVariant + Send + 'static,
WIDGET: Widget + 'static,
WIDGET::Model: Clone + Send,
WIDGET::Msg: Clone + DisplayVariant + Send + 'static,
WIDGET::Root: IsA<gtk::Widget> + IsA<Object> + WidgetExt;
fn remove_widget<WIDGET>(&self, component: Component<WIDGET>)
where WIDGET: Widget,
WIDGET::Model: Clone,
WIDGET::Root: IsA<gtk::Widget>;
}
impl<W: Clone + ContainerExt + IsA<gtk::Widget> + IsA<Object>> ContainerWidget for W {
fn add_widget<CHILDWIDGET, MSG>(&self, relm: &RemoteRelm<MSG>) -> Component<CHILDWIDGET>
where MSG: Clone + DisplayVariant + Send + 'static,
CHILDWIDGET: Widget + 'static,
CHILDWIDGET::Model: Clone + Send,
CHILDWIDGET::Msg: Clone + DisplayVariant + Send + 'static,
CHILDWIDGET::Root: IsA<gtk::Widget> + IsA<Object> + WidgetExt,
{
let component = create_widget::<CHILDWIDGET>(&relm.remote);
self.add(component.widget.root());
component.widget.on_add(self.clone());
init_component::<CHILDWIDGET>(&component, &relm.remote);
Component::new(component)
}
fn remove_widget<WIDGET>(&self, component: Component<WIDGET>)
where WIDGET: Widget,
WIDGET::Model: Clone,
WIDGET::Root: IsA<gtk::Widget>,
{
self.remove(component.widget().root());
}
}
pub trait RelmContainer {
fn add<W: IsA<gtk::Widget>>(&self, widget: &W);
fn add_widget<CHILDWIDGET, MSG>(&self, relm: &RemoteRelm<MSG>) -> Component<CHILDWIDGET>
where MSG: Clone + DisplayVariant,
CHILDWIDGET: Widget + 'static,
CHILDWIDGET::Model: Clone + Send,
CHILDWIDGET::Msg: Send;
}
impl<WIDGET> RelmContainer for Component<WIDGET>
where WIDGET: Container + Widget,
WIDGET::Container: Clone + ContainerExt + IsA<gtk::Widget> + IsA<Object>,
WIDGET::Model: Clone,
{
fn add<W: IsA<gtk::Widget>>(&self, widget: &W) {
let container = self.widget().container();
container.add(widget);
}
fn add_widget<CHILDWIDGET, MSG>(&self, relm: &RemoteRelm<MSG>) -> Component<CHILDWIDGET>
where MSG: Clone + DisplayVariant,
CHILDWIDGET: Widget + 'static,
CHILDWIDGET::Model: Clone + Send,
CHILDWIDGET::Msg: Send,
{
let component = create_widget::<CHILDWIDGET>(&relm.remote);
let container = self.widget().container();
container.add(component.widget.root());
component.widget.on_add(container.clone());
init_component::<CHILDWIDGET>(&component, &relm.remote);
Component::new(component)
}
}