From d0cf77888ce192a1a6f4a15c7bf539a7a45dfa57 Mon Sep 17 00:00:00 2001 From: Elias Projahn Date: Sun, 24 Sep 2023 11:57:16 +0200 Subject: [PATCH] Add mechanism to show playlist page --- data/res/meson.build | 1 + data/res/musicus.gresource.xml | 1 + data/res/playlist_page.blp | 28 +++++++++++++++++ data/res/window.blp | 29 +++++++++++++----- po/POTFILES | 1 + src/main.rs | 1 + src/playlist_page.rs | 56 ++++++++++++++++++++++++++++++++++ src/window.rs | 26 +++++++++++++++- 8 files changed, 135 insertions(+), 8 deletions(-) create mode 100644 data/res/playlist_page.blp create mode 100644 src/playlist_page.rs diff --git a/data/res/meson.build b/data/res/meson.build index 910b91b..188af4b 100644 --- a/data/res/meson.build +++ b/data/res/meson.build @@ -4,6 +4,7 @@ gnome = import('gnome') blueprints = custom_target('blueprints', input: files( 'home_page.blp', + 'playlist_page.blp', 'tile.blp', 'welcome_page.blp', 'window.blp' diff --git a/data/res/musicus.gresource.xml b/data/res/musicus.gresource.xml index 89899cd..4eff1e1 100644 --- a/data/res/musicus.gresource.xml +++ b/data/res/musicus.gresource.xml @@ -3,6 +3,7 @@ icons/scalable/actions/playlist-symbolic.svg home_page.ui + playlist_page.ui tile.ui welcome_page.ui window.ui diff --git a/data/res/playlist_page.blp b/data/res/playlist_page.blp new file mode 100644 index 0000000..60a0033 --- /dev/null +++ b/data/res/playlist_page.blp @@ -0,0 +1,28 @@ +using Gtk 4.0; +using Adw 1; + +template $MusicusPlaylistPage : Adw.Bin { + Adw.ToolbarView { + [top] + Adw.HeaderBar { + title-widget: Adw.WindowTitle { + title: _("Playlist"); + }; + + [start] + Gtk.Button close_button { + icon-name: "go-down-symbolic"; + clicked => $close() swapped; + } + } + + Gtk.ScrolledWindow { + hscrollbar-policy: never; + + Adw.Clamp { + maximum-size: 1000; + tightening-threshold: 600; + } + } + } +} diff --git a/data/res/window.blp b/data/res/window.blp index cb5ccd7..ae627b7 100644 --- a/data/res/window.blp +++ b/data/res/window.blp @@ -5,17 +5,31 @@ template $MusicusWindow : Adw.ApplicationWindow { title: _("Musicus"); Adw.ToolbarView { - Adw.NavigationView navigation_view { - $MusicusWelcomePage { - folder-selected => $set_library_folder() swapped; - } + Gtk.Stack stack { + transition-type: over_up_down; - $MusicusHomePage {} + Gtk.StackPage { + name: "navigation"; + child: Adw.NavigationView navigation_view { + $MusicusWelcomePage { + folder-selected => $set_library_folder() swapped; + } + + $MusicusHomePage {} + }; + } + + Gtk.StackPage { + name: "playlist"; + child: $MusicusPlaylistPage { + close => $hide_playlist() swapped; + }; + } } [bottom] Gtk.Revealer player_bar_revealer { - reveal-child: false; + reveal-child: true; transition-type: slide_up; Gtk.Box { @@ -55,10 +69,11 @@ template $MusicusWindow : Adw.ApplicationWindow { label: "00:00 / 01:00"; } - Gtk.Button { + Gtk.ToggleButton playlist_button { styles ["flat"] valign: center; icon-name: "playlist-symbolic"; + toggled => $show_playlist() swapped; } } } diff --git a/po/POTFILES b/po/POTFILES index e4d06c8..3c2699c 100644 --- a/po/POTFILES +++ b/po/POTFILES @@ -1,4 +1,5 @@ data/res/home_page.blp +data/res/playlist_page.blp data/res/tile.blp data/res/welcome_page.blp data/res/window.blp diff --git a/src/main.rs b/src/main.rs index 58cf09f..4be09ce 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,7 @@ mod application; mod config; mod home_page; +mod playlist_page; mod tile; mod welcome_page; mod window; diff --git a/src/playlist_page.rs b/src/playlist_page.rs new file mode 100644 index 0000000..dfc0e32 --- /dev/null +++ b/src/playlist_page.rs @@ -0,0 +1,56 @@ +use adw::subclass::prelude::*; +use gtk::{glib, glib::subclass::Signal, prelude::*}; +use once_cell::sync::Lazy; + +mod imp { + use super::*; + + #[derive(Debug, Default, gtk::CompositeTemplate)] + #[template(resource = "/de/johrpan/musicus/playlist_page.ui")] + pub struct MusicusPlaylistPage {} + + #[glib::object_subclass] + impl ObjectSubclass for MusicusPlaylistPage { + const NAME: &'static str = "MusicusPlaylistPage"; + type Type = super::MusicusPlaylistPage; + type ParentType = adw::Bin; + + fn class_init(klass: &mut Self::Class) { + klass.bind_template(); + klass.bind_template_instance_callbacks(); + } + + fn instance_init(obj: &glib::subclass::InitializingObject) { + obj.init_template(); + } + } + + impl ObjectImpl for MusicusPlaylistPage { + fn signals() -> &'static [Signal] { + static SIGNALS: Lazy> = + Lazy::new(|| vec![Signal::builder("close").build()]); + + SIGNALS.as_ref() + } + } + + impl WidgetImpl for MusicusPlaylistPage {} + impl BinImpl for MusicusPlaylistPage {} +} + +glib::wrapper! { + pub struct MusicusPlaylistPage(ObjectSubclass) + @extends gtk::Widget, adw::Bin; +} + +#[gtk::template_callbacks] +impl MusicusPlaylistPage { + pub fn new() -> Self { + glib::Object::new() + } + + #[template_callback] + fn close(&self, _: >k::Button) { + self.emit_by_name::<()>("close", &[]); + } +} diff --git a/src/window.rs b/src/window.rs index 7f968a6..c51ae66 100644 --- a/src/window.rs +++ b/src/window.rs @@ -1,4 +1,7 @@ -use crate::{home_page::MusicusHomePage, welcome_page::MusicusWelcomePage}; +use crate::{ + home_page::MusicusHomePage, playlist_page::MusicusPlaylistPage, + welcome_page::MusicusWelcomePage, +}; use adw::subclass::prelude::*; use gtk::{gio, glib, prelude::*}; @@ -9,10 +12,14 @@ mod imp { #[derive(Debug, Default, gtk::CompositeTemplate)] #[template(resource = "/de/johrpan/musicus/window.ui")] pub struct MusicusWindow { + #[template_child] + pub stack: TemplateChild, #[template_child] pub navigation_view: TemplateChild, #[template_child] pub player_bar_revealer: TemplateChild, + #[template_child] + pub playlist_button: TemplateChild, } #[glib::object_subclass] @@ -23,6 +30,7 @@ mod imp { fn class_init(klass: &mut Self::Class) { MusicusHomePage::static_type(); + MusicusPlaylistPage::static_type(); MusicusWelcomePage::static_type(); klass.bind_template(); klass.bind_template_instance_callbacks(); @@ -93,4 +101,20 @@ impl MusicusWindow { log::info!("{path:?}"); self.imp().navigation_view.replace_with_tags(&["home"]); } + + #[template_callback] + fn show_playlist(&self, button: >k::ToggleButton) { + self.imp() + .stack + .set_visible_child_name(if button.is_active() { + "playlist" + } else { + "navigation" + }); + } + + #[template_callback] + fn hide_playlist(&self, _: &MusicusPlaylistPage) { + self.imp().playlist_button.set_active(false); + } }