diff options
author | Vika <vika@fireburn.ru> | 2024-08-23 01:57:09 +0300 |
---|---|---|
committer | Vika <vika@fireburn.ru> | 2024-08-23 02:17:00 +0300 |
commit | c8f4b5240b8bcfb5b575bd12b09c68e96e15d37f (patch) | |
tree | 87d27ef34da970596077d8868c6cf51851b6ca04 /src/components/tag_pill.rs | |
parent | 1376d727e9017ce6b3cfd2ca3008d4d5cdd4ff2a (diff) |
Tags in posts
Diffstat (limited to 'src/components/tag_pill.rs')
-rw-r--r-- | src/components/tag_pill.rs | 77 |
1 files changed, 77 insertions, 0 deletions
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<str>); + +#[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<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 + } + } +} |