mirror of
https://github.com/johrpan/musicus.git
synced 2025-10-26 19:57:25 +01:00
Add custom search bar with tags
This commit is contained in:
parent
00bd7027a6
commit
08be3cb613
9 changed files with 283 additions and 16 deletions
60
src/search_tag.rs
Normal file
60
src/search_tag.rs
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
use adw::{glib, glib::subclass::Signal, prelude::*, subclass::prelude::*};
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
mod imp {
|
||||
use super::*;
|
||||
|
||||
#[derive(Debug, Default, gtk::CompositeTemplate)]
|
||||
#[template(file = "data/ui/search_tag.blp")]
|
||||
pub struct MusicusSearchTag {
|
||||
#[template_child]
|
||||
pub label: TemplateChild<gtk::Label>,
|
||||
}
|
||||
|
||||
#[glib::object_subclass]
|
||||
impl ObjectSubclass for MusicusSearchTag {
|
||||
const NAME: &'static str = "MusicusSearchTag";
|
||||
type Type = super::MusicusSearchTag;
|
||||
type ParentType = gtk::Box;
|
||||
|
||||
fn class_init(klass: &mut Self::Class) {
|
||||
klass.bind_template();
|
||||
klass.bind_template_instance_callbacks();
|
||||
}
|
||||
|
||||
fn instance_init(obj: &glib::subclass::InitializingObject<Self>) {
|
||||
obj.init_template();
|
||||
}
|
||||
}
|
||||
|
||||
impl ObjectImpl for MusicusSearchTag {
|
||||
fn signals() -> &'static [Signal] {
|
||||
static SIGNALS: Lazy<Vec<Signal>> =
|
||||
Lazy::new(|| vec![Signal::builder("remove").build()]);
|
||||
|
||||
SIGNALS.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
impl WidgetImpl for MusicusSearchTag {}
|
||||
impl BoxImpl for MusicusSearchTag {}
|
||||
}
|
||||
|
||||
glib::wrapper! {
|
||||
pub struct MusicusSearchTag(ObjectSubclass<imp::MusicusSearchTag>)
|
||||
@extends gtk::Widget;
|
||||
}
|
||||
|
||||
#[gtk::template_callbacks]
|
||||
impl MusicusSearchTag {
|
||||
pub fn new(label: &str) -> Self {
|
||||
let tag: MusicusSearchTag = glib::Object::new();
|
||||
tag.imp().label.set_label(label);
|
||||
tag
|
||||
}
|
||||
|
||||
#[template_callback]
|
||||
fn remove(&self, _: >k::Button) {
|
||||
self.emit_by_name::<()>("remove", &[]);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue