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
|
use adw::prelude::*;
use relm4::prelude::*;
#[derive(Debug)]
pub(crate) struct TagPill(pub(crate) Box<str>);
#[derive(Debug)]
pub(crate) struct TagPillDelete(pub(crate) DynamicIndex);
pub(crate) struct TagPillWidgets {
label: gtk::Label,
button: gtk::Button,
}
impl FactoryComponent for TagPill {
type CommandOutput = ();
type Init = Box<str>;
type Output = TagPillDelete;
type Input = ();
type ParentWidget = gtk::Box;
type Root = gtk::Box;
type Widgets = TagPillWidgets;
type Index = DynamicIndex;
fn init_model(init: Self::Init, _idx: &DynamicIndex, _sender: FactorySender<Self>) -> Self {
Self(init)
}
fn init_root(&self) -> Self::Root {
relm4::view! {
root = gtk::Box {
#[iterate]
add_css_class: &["pill", "frame"],
inline_css: "border-radius: 48px",
set_spacing: 6,
set_height_request: 32,
}
}
root
}
fn init_widgets(
&mut self,
index: &Self::Index,
root: Self::Root,
flow_box_child: &<Self::ParentWidget as relm4::factory::FactoryView>::ReturnedWidget,
sender: FactorySender<Self>,
) -> Self::Widgets {
relm4::view! {
label = gtk::Label {
set_text: &self.0,
set_margin_horizontal: 6,
set_margin_start: 12,
},
button = gtk::Button {
#[iterate]
add_css_class: &["destructive-action", "flat", "circular"],
set_icon_name: "close-symbolic",
connect_clicked[sender, index] => move |_| {
let _ = sender.output(TagPillDelete(index.clone()));
}
}
};
flow_box_child.set_halign(gtk::Align::Start);
root.append(&label);
root.append(&button);
Self::Widgets {
label, button
}
}
}
|