use adw::prelude::*; use relm4::prelude::*; #[derive(Debug)] pub(crate) struct TagPill(pub(crate) Box); #[derive(Debug)] pub(crate) struct TagPillDelete(pub(crate) DynamicIndex); pub(crate) struct TagPillWidgets { label: gtk::Label, button: gtk::Button, } //#[relm4::factory(pub(crate))] impl FactoryComponent for TagPill { type CommandOutput = (); type Init = Box; 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(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: &::ReturnedWidget, sender: FactorySender, ) -> 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 } } }