2023-10-08 16:40:59 +02:00
|
|
|
use crate::search_tag::Tag;
|
|
|
|
|
use gtk::{glib, prelude::*, subclass::prelude::*};
|
|
|
|
|
use std::cell::OnceCell;
|
|
|
|
|
|
|
|
|
|
mod imp {
|
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Default, gtk::CompositeTemplate)]
|
|
|
|
|
#[template(file = "data/ui/tag_tile.blp")]
|
|
|
|
|
pub struct MusicusTagTile {
|
|
|
|
|
#[template_child]
|
|
|
|
|
pub title_label: TemplateChild<gtk::Label>,
|
|
|
|
|
#[template_child]
|
|
|
|
|
pub subtitle_label: TemplateChild<gtk::Label>,
|
|
|
|
|
|
|
|
|
|
pub tag: OnceCell<Tag>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[glib::object_subclass]
|
|
|
|
|
impl ObjectSubclass for MusicusTagTile {
|
|
|
|
|
const NAME: &'static str = "MusicusTagTile";
|
|
|
|
|
type Type = super::MusicusTagTile;
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl ObjectImpl for MusicusTagTile {}
|
|
|
|
|
impl WidgetImpl for MusicusTagTile {}
|
|
|
|
|
impl FlowBoxChildImpl for MusicusTagTile {}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
glib::wrapper! {
|
|
|
|
|
pub struct MusicusTagTile(ObjectSubclass<imp::MusicusTagTile>)
|
|
|
|
|
@extends gtk::Widget, gtk::FlowBoxChild;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl MusicusTagTile {
|
|
|
|
|
pub fn new(tag: Tag) -> Self {
|
|
|
|
|
let obj: Self = glib::Object::new();
|
|
|
|
|
let imp = obj.imp();
|
|
|
|
|
|
|
|
|
|
match &tag {
|
|
|
|
|
Tag::Composer(person) | Tag::Performer(person) => {
|
2024-03-23 18:06:46 +01:00
|
|
|
imp.title_label.set_label(person.name.get());
|
2023-10-08 16:40:59 +02:00
|
|
|
}
|
|
|
|
|
Tag::Ensemble(ensemble) => {
|
2024-03-23 18:06:46 +01:00
|
|
|
imp.title_label.set_label(ensemble.name.get());
|
2023-10-08 16:40:59 +02:00
|
|
|
}
|
|
|
|
|
Tag::Work(work) => {
|
2024-03-23 18:06:46 +01:00
|
|
|
imp.title_label.set_label(work.name.get());
|
|
|
|
|
imp.subtitle_label.set_label(&work.composers_string());
|
2023-10-08 16:40:59 +02:00
|
|
|
imp.subtitle_label.set_visible(true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
imp.tag.set(tag).unwrap();
|
|
|
|
|
|
|
|
|
|
obj
|
|
|
|
|
}
|
2023-10-11 12:04:49 +02:00
|
|
|
|
|
|
|
|
pub fn tag(&self) -> &Tag {
|
|
|
|
|
self.imp().tag.get().unwrap()
|
|
|
|
|
}
|
2023-10-08 16:40:59 +02:00
|
|
|
}
|