Make tiles selectable by mouse

This commit is contained in:
Elias Projahn 2023-10-11 12:04:49 +02:00
parent 2143d6333b
commit 16d1408194
3 changed files with 33 additions and 1 deletions

View file

@ -57,6 +57,7 @@ template $MusicusHomePage : Adw.NavigationPage {
row-spacing: 12; row-spacing: 12;
homogeneous: true; homogeneous: true;
selection-mode: none; selection-mode: none;
child-activated => $tile_selected() swapped;
} }
Gtk.Label { Gtk.Label {
@ -73,6 +74,7 @@ template $MusicusHomePage : Adw.NavigationPage {
row-spacing: 12; row-spacing: 12;
homogeneous: true; homogeneous: true;
selection-mode: none; selection-mode: none;
child-activated => $tile_selected() swapped;
} }
Gtk.Label { Gtk.Label {
@ -89,6 +91,7 @@ template $MusicusHomePage : Adw.NavigationPage {
row-spacing: 12; row-spacing: 12;
homogeneous: true; homogeneous: true;
selection-mode: none; selection-mode: none;
child-activated => $tile_selected() swapped;
} }
Gtk.Label { Gtk.Label {
@ -105,6 +108,7 @@ template $MusicusHomePage : Adw.NavigationPage {
row-spacing: 12; row-spacing: 12;
homogeneous: true; homogeneous: true;
selection-mode: none; selection-mode: none;
child-activated => $tile_selected() swapped;
} }
Gtk.Label { Gtk.Label {
@ -121,6 +125,7 @@ template $MusicusHomePage : Adw.NavigationPage {
row-spacing: 12; row-spacing: 12;
homogeneous: true; homogeneous: true;
selection-mode: none; selection-mode: none;
child-activated => $recording_selected() swapped;
} }
} }
} }

View file

@ -118,12 +118,13 @@ impl MusicusHomePage {
fn select(&self, search_entry: &MusicusSearchEntry) { fn select(&self, search_entry: &MusicusSearchEntry) {
let imp = self.imp(); let imp = self.imp();
let (composer, performer, ensemble, work) = { let (composer, performer, ensemble, work, recording) = {
( (
imp.composers.borrow().first().cloned(), imp.composers.borrow().first().cloned(),
imp.performers.borrow().first().cloned(), imp.performers.borrow().first().cloned(),
imp.ensembles.borrow().first().cloned(), imp.ensembles.borrow().first().cloned(),
imp.works.borrow().first().cloned(), imp.works.borrow().first().cloned(),
imp.recordings.borrow().first().cloned(),
) )
}; };
@ -135,9 +136,31 @@ impl MusicusHomePage {
search_entry.add_tag(Tag::Ensemble(ensemble)); search_entry.add_tag(Tag::Ensemble(ensemble));
} else if let Some(work) = work { } else if let Some(work) = work {
search_entry.add_tag(Tag::Work(work)); search_entry.add_tag(Tag::Work(work));
} else if let Some(recording) = recording {
self.play_recording(&recording);
} }
} }
#[template_callback]
fn tile_selected(&self, tile: &gtk::FlowBoxChild, _: &gtk::FlowBox) {
self.imp()
.search_entry
.add_tag(tile.downcast_ref::<MusicusTagTile>().unwrap().tag().clone())
}
#[template_callback]
fn recording_selected(&self, tile: &gtk::FlowBoxChild, _: &gtk::FlowBox) {
self.play_recording(
tile.downcast_ref::<MusicusRecordingTile>()
.unwrap()
.recording(),
);
}
fn play_recording(&self, recording: &Recording) {
log::info!("Play recording: {:?}", recording)
}
fn query(&self, query: &LibraryQuery) { fn query(&self, query: &LibraryQuery) {
let imp = self.imp(); let imp = self.imp();
let results = self.library().query(query); let results = self.library().query(query);

View file

@ -64,4 +64,8 @@ impl MusicusTagTile {
obj obj
} }
pub fn tag(&self) -> &Tag {
self.imp().tag.get().unwrap()
}
} }