Added a sidebar collection, nice.

This commit is contained in:
Vivianne 2023-06-11 17:56:16 -07:00
parent 6562725f8a
commit e59f85ae59
3 changed files with 70 additions and 9 deletions

5
src/app_msg.rs Normal file
View File

@ -0,0 +1,5 @@
#[derive(Debug)]
pub enum AppMsg {
Close,
}

42
src/collection_list.rs Normal file
View File

@ -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 {
Self {
name,
}
}
}

View File

@ -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<CollectionListItem>,
}
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<Self>,
) -> relm4::ComponentParts<Self> {
let factory1 = gtk::SignalListItemFactory::new();
factory1.connect_bind(move |_factory, item| {
let item = item.downcast_ref::<gtk::ListItem>().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 }