2024-06-05 13:26:47 +02:00
|
|
|
use std::cell::OnceCell;
|
|
|
|
|
|
2025-03-01 09:57:01 +01:00
|
|
|
use gtk::{glib, subclass::prelude::*};
|
|
|
|
|
|
2024-06-05 13:26:47 +02:00
|
|
|
use crate::db::models::Album;
|
|
|
|
|
|
|
|
|
|
mod imp {
|
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Default, gtk::CompositeTemplate)]
|
|
|
|
|
#[template(file = "data/ui/album_tile.blp")]
|
2025-03-01 09:57:01 +01:00
|
|
|
pub struct AlbumTile {
|
2024-06-05 13:26:47 +02:00
|
|
|
pub album: OnceCell<Album>,
|
|
|
|
|
|
|
|
|
|
#[template_child]
|
|
|
|
|
pub title_label: TemplateChild<gtk::Label>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[glib::object_subclass]
|
2025-03-01 09:57:01 +01:00
|
|
|
impl ObjectSubclass for AlbumTile {
|
2024-06-05 13:26:47 +02:00
|
|
|
const NAME: &'static str = "MusicusAlbumTile";
|
2025-03-01 09:57:01 +01:00
|
|
|
type Type = super::AlbumTile;
|
2024-06-05 13:26:47 +02:00
|
|
|
type ParentType = gtk::FlowBoxChild;
|
|
|
|
|
|
|
|
|
|
fn class_init(klass: &mut Self::Class) {
|
|
|
|
|
klass.bind_template();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn instance_init(obj: &glib::subclass::InitializingObject<Self>) {
|
|
|
|
|
obj.init_template();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-01 09:57:01 +01:00
|
|
|
impl ObjectImpl for AlbumTile {}
|
|
|
|
|
impl WidgetImpl for AlbumTile {}
|
|
|
|
|
impl FlowBoxChildImpl for AlbumTile {}
|
2024-06-05 13:26:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
glib::wrapper! {
|
2025-03-01 09:57:01 +01:00
|
|
|
pub struct AlbumTile(ObjectSubclass<imp::AlbumTile>)
|
2024-06-05 13:26:47 +02:00
|
|
|
@extends gtk::Widget, gtk::FlowBoxChild;
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-01 09:57:01 +01:00
|
|
|
impl AlbumTile {
|
2024-06-05 13:26:47 +02:00
|
|
|
pub fn new(album: &Album) -> Self {
|
|
|
|
|
let obj: Self = glib::Object::new();
|
|
|
|
|
|
|
|
|
|
obj.imp().title_label.set_label(&album.name.get());
|
|
|
|
|
obj.imp().album.set(album.clone()).unwrap();
|
|
|
|
|
|
|
|
|
|
obj
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn album(&self) -> &Album {
|
|
|
|
|
self.imp().album.get().unwrap()
|
|
|
|
|
}
|
|
|
|
|
}
|