mirror of
https://github.com/johrpan/musicus.git
synced 2025-10-26 19:57:25 +01:00
Improve tile widget
This commit is contained in:
parent
54f0088e61
commit
bcb4b84b19
3 changed files with 66 additions and 14 deletions
54
src/tile.rs
54
src/tile.rs
|
|
@ -1,11 +1,24 @@
|
|||
use gtk::{glib, subclass::prelude::*};
|
||||
use gtk::{glib, glib::Properties, prelude::*, subclass::prelude::*};
|
||||
use std::cell::RefCell;
|
||||
|
||||
mod imp {
|
||||
use super::*;
|
||||
|
||||
#[derive(Debug, Default, gtk::CompositeTemplate)]
|
||||
#[derive(Properties, Debug, Default, gtk::CompositeTemplate)]
|
||||
#[properties(wrapper_type = super::MusicusTile)]
|
||||
#[template(file = "data/ui/tile.blp")]
|
||||
pub struct MusicusTile {}
|
||||
pub struct MusicusTile {
|
||||
#[property(get, set)]
|
||||
pub title: RefCell<String>,
|
||||
|
||||
#[property(get, set)]
|
||||
pub subtitle: RefCell<Option<String>>,
|
||||
|
||||
#[template_child]
|
||||
pub title_label: TemplateChild<gtk::Label>,
|
||||
#[template_child]
|
||||
pub subtitle_label: TemplateChild<gtk::Label>,
|
||||
}
|
||||
|
||||
#[glib::object_subclass]
|
||||
impl ObjectSubclass for MusicusTile {
|
||||
|
|
@ -22,7 +35,29 @@ mod imp {
|
|||
}
|
||||
}
|
||||
|
||||
impl ObjectImpl for MusicusTile {}
|
||||
#[glib::derived_properties]
|
||||
impl ObjectImpl for MusicusTile {
|
||||
fn constructed(&self) {
|
||||
self.parent_constructed();
|
||||
|
||||
self.obj()
|
||||
.bind_property("title", &self.title_label.get(), "label")
|
||||
.sync_create()
|
||||
.build();
|
||||
|
||||
self.obj()
|
||||
.bind_property("subtitle", &self.subtitle_label.get(), "visible")
|
||||
.sync_create()
|
||||
.transform_to(|_, s: Option<String>| Some(s.is_some()))
|
||||
.build();
|
||||
|
||||
self.obj()
|
||||
.bind_property("subtitle", &self.subtitle_label.get(), "label")
|
||||
.sync_create()
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
impl WidgetImpl for MusicusTile {}
|
||||
impl FlowBoxChildImpl for MusicusTile {}
|
||||
}
|
||||
|
|
@ -33,7 +68,14 @@ glib::wrapper! {
|
|||
}
|
||||
|
||||
impl MusicusTile {
|
||||
pub fn new() -> Self {
|
||||
glib::Object::new()
|
||||
pub fn with_title(title: &str) -> Self {
|
||||
glib::Object::builder().property("title", title).build()
|
||||
}
|
||||
|
||||
pub fn with_subtitle(title: &str, subtitle: &str) -> Self {
|
||||
glib::Object::builder()
|
||||
.property("title", title)
|
||||
.property("subtitle", subtitle)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue