diff --git a/src/app_msg.rs b/src/app_msg.rs new file mode 100644 index 0000000..84edd5b --- /dev/null +++ b/src/app_msg.rs @@ -0,0 +1,5 @@ + +#[derive(Debug)] +pub enum AppMsg { + Close, +} diff --git a/src/collection_list.rs b/src/collection_list.rs new file mode 100644 index 0000000..f4047e8 --- /dev/null +++ b/src/collection_list.rs @@ -0,0 +1,42 @@ +use gtk::traits::OrientableExt; +use relm4::prelude::*; + +use crate::app_msg::*; + +#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)] +pub struct CollectionListItem { + name: String, +} + +impl CollectionListItem { + pub fn new(name: String) -> Self { + Self { + name, + } + } +} + +#[relm4::factory(pub)] +impl FactoryComponent for CollectionListItem { + type Init = String; + type Input = (); + type Output = (); + type CommandOutput = (); + type ParentInput = AppMsg; + type ParentWidget = gtk::ListBox; + + view! { + gtk::Box { + set_orientation: gtk::Orientation::Horizontal, + gtk::Label { + set_label: &self.name, + } + } + } + + fn init_model(name: Self::Init, _index: &DynamicIndex, _sender: FactorySender) -> Self { + Self { + name, + } + } +} diff --git a/src/main.rs b/src/main.rs index 573d5e7..e8f114f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,16 +1,20 @@ use gtk::prelude::*; use gtk::glib::BoxedAnyObject; -use relm4::prelude::*; +use relm4::{ + prelude::*, + factory::FactoryVecDeque, +}; use std::cell::Ref; +mod collection_list; +use collection_list::CollectionListItem; +mod app_msg; +use app_msg::AppMsg; -#[derive(Debug)] -enum AppMsg { - Close, -} struct AppModel { samples: gtk::MultiSelection, + collections: FactoryVecDeque, } struct Sample { @@ -38,8 +42,11 @@ impl SimpleComponent for AppModel { gtk::Box { gtk::ScrolledWindow { - gtk::ListView { - + set_css_classes: &["sidebar"], + set_hscrollbar_policy: gtk::PolicyType::Never, + #[local_ref] + collection_view -> gtk::ListBox{ + set_css_classes: &["navigation-sidebar"] } }, gtk::Box { @@ -88,6 +95,7 @@ impl SimpleComponent for AppModel { window: &Self::Root, sender: ComponentSender, ) -> relm4::ComponentParts { + let factory1 = gtk::SignalListItemFactory::new(); factory1.connect_bind(move |_factory, item| { let item = item.downcast_ref::().unwrap(); @@ -116,9 +124,15 @@ impl SimpleComponent for AppModel { let samples = gtk::MultiSelection::new(Some(samples)); - let model = AppModel { - samples + let mut model = AppModel { + samples, + collections: FactoryVecDeque::new(gtk::ListBox::default(), sender.input_sender()), }; + + model.collections.guard().push_back("Tape808 & Tape909".to_string()); + model.collections.guard().push_back("Zero-G Planet of The Breaks".to_string()); + + let collection_view = model.collections.widget(); let widgets = view_output!(); ComponentParts { model, widgets }