use std::path::PathBuf; use gtk::prelude::*; use relm4::prelude::*; use crate::sheet::Sheet; use super::sheet_listing::SheetListingInput; pub enum SheetModelType { Sheet { sheet: Sheet }, Pdf { path: PathBuf }, } pub struct SheetModel { label: String, } #[relm4::factory(pub)] impl FactoryComponent for SheetModel { type Init = SheetModelType; type ParentWidget = gtk::Box; type CommandOutput = (); type ParentInput = SheetListingInput; type Input = (); type Output = (); view! { #[root] gtk::Box { set_orientation: gtk::Orientation::Vertical, append = >k::Label { set_label: &self.label, set_halign: gtk::Align::Start, set_margin_all: 10, } } } fn init_model(value: Self::Init, _index: &DynamicIndex, _sender: FactorySender) -> Self { let label = match value { SheetModelType::Sheet { sheet } => sheet.name, SheetModelType::Pdf { path } => path.file_name().unwrap().to_str().unwrap().to_string(), }; SheetModel { label } } }