From c8f4b5240b8bcfb5b575bd12b09c68e96e15d37f Mon Sep 17 00:00:00 2001 From: Vika Date: Fri, 23 Aug 2024 01:57:09 +0300 Subject: Tags in posts --- src/components/tag_pill.rs | 77 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 src/components/tag_pill.rs (limited to 'src/components/tag_pill.rs') diff --git a/src/components/tag_pill.rs b/src/components/tag_pill.rs new file mode 100644 index 0000000..bbb1185 --- /dev/null +++ b/src/components/tag_pill.rs @@ -0,0 +1,77 @@ +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 + } + } +} -- cgit 1.4.1