mirror of
https://github.com/johrpan/musicus.git
synced 2025-10-26 11:47:25 +01:00
Improve tile widget
This commit is contained in:
parent
54f0088e61
commit
bcb4b84b19
3 changed files with 66 additions and 14 deletions
|
|
@ -8,3 +8,16 @@
|
|||
min-height: 24px;
|
||||
margin: 0px;
|
||||
}
|
||||
|
||||
.tile {
|
||||
min-height: 50px;
|
||||
min-width: 200px;
|
||||
}
|
||||
|
||||
.tile > box {
|
||||
margin: 6px 12px;
|
||||
}
|
||||
|
||||
.tile .subtitle {
|
||||
font-size: smaller;
|
||||
}
|
||||
|
|
@ -2,24 +2,21 @@ using Gtk 4.0;
|
|||
using Adw 1;
|
||||
|
||||
template $MusicusTile : Gtk.FlowBoxChild {
|
||||
styles ["card", "activatable"]
|
||||
width-request: 200;
|
||||
styles ["card", "activatable", "tile"]
|
||||
|
||||
Gtk.Box {
|
||||
orientation: vertical;
|
||||
margin-start: 6;
|
||||
margin-end: 6;
|
||||
margin-top: 6;
|
||||
margin-bottom: 6;
|
||||
valign: center;
|
||||
|
||||
Gtk.Label title_label {
|
||||
styles ["caption-heading"]
|
||||
styles ["title"]
|
||||
halign: start;
|
||||
label: _("Title");
|
||||
}
|
||||
|
||||
Gtk.Label subtitle_label {
|
||||
styles ["caption"]
|
||||
visible: false;
|
||||
styles ["subtitle", "dim-label"]
|
||||
halign: start;
|
||||
label: _("Subtitle");
|
||||
}
|
||||
|
|
|
|||
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