split off album carousel album into its own class
This commit is contained in:
parent
8b748115e5
commit
afa27dbb6a
6 changed files with 138 additions and 52 deletions
|
@ -80,58 +80,10 @@ template $AudreyUiAlbumCarousel: Adw.Bin {
|
||||||
model: bind template.model;
|
model: bind template.model;
|
||||||
};
|
};
|
||||||
|
|
||||||
factory: BuilderListItemFactory {
|
factory: SignalListItemFactory {
|
||||||
template ListItem {
|
setup => $on_setup() swapped;
|
||||||
child: Box {
|
bind => $on_bind() swapped;
|
||||||
styles [
|
unbind => $on_unbind() swapped;
|
||||||
"album"
|
|
||||||
]
|
|
||||||
|
|
||||||
orientation: vertical;
|
|
||||||
margin-bottom: 6;
|
|
||||||
spacing: 6;
|
|
||||||
|
|
||||||
Image {
|
|
||||||
icon-name: "media-optical-cd";
|
|
||||||
pixel-size: 160;
|
|
||||||
halign: center;
|
|
||||||
hexpand: false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Box {
|
|
||||||
styles [
|
|
||||||
"labels"
|
|
||||||
]
|
|
||||||
|
|
||||||
orientation: vertical;
|
|
||||||
homogeneous: true;
|
|
||||||
|
|
||||||
Label {
|
|
||||||
single-line-mode: true;
|
|
||||||
label: bind template.item as <$AudreyModelAlbum>.name;
|
|
||||||
ellipsize: end;
|
|
||||||
xalign: 0;
|
|
||||||
margin-start: 6;
|
|
||||||
|
|
||||||
styles [
|
|
||||||
"heading"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
Label {
|
|
||||||
single-line-mode: true;
|
|
||||||
label: bind template.item as <$AudreyModelAlbum>.artist;
|
|
||||||
ellipsize: end;
|
|
||||||
xalign: 0;
|
|
||||||
margin-start: 6;
|
|
||||||
|
|
||||||
styles [
|
|
||||||
"caption"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
54
resources/album_carousel_album.blp
Normal file
54
resources/album_carousel_album.blp
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
using Gtk 4.0;
|
||||||
|
using Adw 1;
|
||||||
|
|
||||||
|
template $AudreyUiAlbumCarouselAlbum: Adw.Bin {
|
||||||
|
child: Box {
|
||||||
|
styles [
|
||||||
|
"album"
|
||||||
|
]
|
||||||
|
|
||||||
|
orientation: vertical;
|
||||||
|
margin-bottom: 6;
|
||||||
|
spacing: 6;
|
||||||
|
|
||||||
|
Image {
|
||||||
|
icon-name: "media-optical-cd";
|
||||||
|
pixel-size: 160;
|
||||||
|
halign: center;
|
||||||
|
hexpand: false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Box {
|
||||||
|
styles [
|
||||||
|
"labels"
|
||||||
|
]
|
||||||
|
|
||||||
|
orientation: vertical;
|
||||||
|
homogeneous: true;
|
||||||
|
|
||||||
|
Label {
|
||||||
|
single-line-mode: true;
|
||||||
|
label: bind template.item as <$AudreyModelAlbum>.name;
|
||||||
|
ellipsize: end;
|
||||||
|
xalign: 0;
|
||||||
|
margin-start: 6;
|
||||||
|
|
||||||
|
styles [
|
||||||
|
"heading"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
Label {
|
||||||
|
single-line-mode: true;
|
||||||
|
label: bind template.item as <$AudreyModelAlbum>.artist;
|
||||||
|
ellipsize: end;
|
||||||
|
xalign: 0;
|
||||||
|
margin-start: 6;
|
||||||
|
|
||||||
|
styles [
|
||||||
|
"caption"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
|
@ -8,6 +8,7 @@
|
||||||
<file>style.css</file>
|
<file>style.css</file>
|
||||||
<file preprocess="xml-stripblanks">gtk/help-overlay.ui</file>
|
<file preprocess="xml-stripblanks">gtk/help-overlay.ui</file>
|
||||||
<file preprocess="xml-stripblanks">album_carousel.ui</file>
|
<file preprocess="xml-stripblanks">album_carousel.ui</file>
|
||||||
|
<file preprocess="xml-stripblanks">album_carousel_album.ui</file>
|
||||||
<file preprocess="xml-stripblanks">play_queue.ui</file>
|
<file preprocess="xml-stripblanks">play_queue.ui</file>
|
||||||
<file preprocess="xml-stripblanks">play_queue_song.ui</file>
|
<file preprocess="xml-stripblanks">play_queue_song.ui</file>
|
||||||
<file preprocess="xml-stripblanks">playbar.ui</file>
|
<file preprocess="xml-stripblanks">playbar.ui</file>
|
||||||
|
|
|
@ -2,6 +2,7 @@ blueprints = custom_target(
|
||||||
'blueprints',
|
'blueprints',
|
||||||
input: files(
|
input: files(
|
||||||
'album_carousel.blp',
|
'album_carousel.blp',
|
||||||
|
'album_carousel_album.blp',
|
||||||
'play_queue.blp',
|
'play_queue.blp',
|
||||||
'play_queue_song.blp',
|
'play_queue_song.blp',
|
||||||
'playbar.blp',
|
'playbar.blp',
|
||||||
|
@ -10,6 +11,7 @@ blueprints = custom_target(
|
||||||
),
|
),
|
||||||
output: [
|
output: [
|
||||||
'album_carousel.ui',
|
'album_carousel.ui',
|
||||||
|
'album_carousel_album.ui',
|
||||||
'play_queue.ui',
|
'play_queue.ui',
|
||||||
'play_queue_song.ui',
|
'play_queue_song.ui',
|
||||||
'playbar.ui',
|
'playbar.ui',
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
|
mod album;
|
||||||
|
pub use album::Album;
|
||||||
|
|
||||||
|
use crate::model;
|
||||||
use crate::subsonic::AlbumListType;
|
use crate::subsonic::AlbumListType;
|
||||||
use adw::prelude::*;
|
use adw::prelude::*;
|
||||||
use adw::subclass::prelude::*;
|
use adw::subclass::prelude::*;
|
||||||
|
@ -142,6 +146,25 @@ mod imp {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[template_callback]
|
||||||
|
pub fn on_setup(&self, item: >k::ListItem, _factory: >k::SignalListItemFactory) {
|
||||||
|
let child: super::Album = glib::Object::new();
|
||||||
|
item.set_child(Some(&child));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[template_callback]
|
||||||
|
pub fn on_bind(&self, item: >k::ListItem, _factory: >k::SignalListItemFactory) {
|
||||||
|
let child: super::Album = item.child().and_downcast().unwrap();
|
||||||
|
let album: model::Album = item.item().and_downcast().unwrap();
|
||||||
|
child.bind(&album);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[template_callback]
|
||||||
|
pub fn on_unbind(&self, item: >k::ListItem, _factory: >k::SignalListItemFactory) {
|
||||||
|
let child: super::Album = item.child().and_downcast().unwrap();
|
||||||
|
child.unbind();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
54
src/ui/album_carousel/album.rs
Normal file
54
src/ui/album_carousel/album.rs
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
use crate::model;
|
||||||
|
use adw::{prelude::*, subclass::prelude::*};
|
||||||
|
use glib::subclass::InitializingObject;
|
||||||
|
use std::cell::RefCell;
|
||||||
|
|
||||||
|
mod imp {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[derive(gtk::CompositeTemplate, glib::Properties, Default)]
|
||||||
|
#[template(resource = "/eu/callcc/audrey/album_carousel_album.ui")]
|
||||||
|
#[properties(wrapper_type = super::Album)]
|
||||||
|
pub struct Album {
|
||||||
|
#[property(get, set, nullable)]
|
||||||
|
item: RefCell<Option<model::Album>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[glib::object_subclass]
|
||||||
|
impl ObjectSubclass for Album {
|
||||||
|
const NAME: &'static str = "AudreyUiAlbumCarouselAlbum";
|
||||||
|
type Type = super::Album;
|
||||||
|
type ParentType = adw::Bin;
|
||||||
|
|
||||||
|
fn class_init(klass: &mut Self::Class) {
|
||||||
|
klass.bind_template();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn instance_init(obj: &InitializingObject<Self>) {
|
||||||
|
obj.init_template();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[glib::derived_properties]
|
||||||
|
impl ObjectImpl for Album {}
|
||||||
|
|
||||||
|
impl WidgetImpl for Album {}
|
||||||
|
|
||||||
|
impl BinImpl for Album {}
|
||||||
|
}
|
||||||
|
|
||||||
|
glib::wrapper! {
|
||||||
|
pub struct Album(ObjectSubclass<imp::Album>)
|
||||||
|
@extends adw::Bin, gtk::Widget,
|
||||||
|
@implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Album {
|
||||||
|
pub fn bind(&self, album: &model::Album) {
|
||||||
|
self.set_item(Some(album));
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn unbind(&self) {
|
||||||
|
self.set_item(None::<model::Album>);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue