Add mechanism to show playlist page

This commit is contained in:
Elias Projahn 2023-09-24 11:57:16 +02:00
parent 5fd958644e
commit d0cf77888c
8 changed files with 135 additions and 8 deletions

View file

@ -4,6 +4,7 @@ gnome = import('gnome')
blueprints = custom_target('blueprints', blueprints = custom_target('blueprints',
input: files( input: files(
'home_page.blp', 'home_page.blp',
'playlist_page.blp',
'tile.blp', 'tile.blp',
'welcome_page.blp', 'welcome_page.blp',
'window.blp' 'window.blp'

View file

@ -3,6 +3,7 @@
<gresource prefix="/de/johrpan/musicus"> <gresource prefix="/de/johrpan/musicus">
<file preprocess="xml-stripblanks">icons/scalable/actions/playlist-symbolic.svg</file> <file preprocess="xml-stripblanks">icons/scalable/actions/playlist-symbolic.svg</file>
<file preprocess="xml-stripblanks">home_page.ui</file> <file preprocess="xml-stripblanks">home_page.ui</file>
<file preprocess="xml-stripblanks">playlist_page.ui</file>
<file preprocess="xml-stripblanks">tile.ui</file> <file preprocess="xml-stripblanks">tile.ui</file>
<file preprocess="xml-stripblanks">welcome_page.ui</file> <file preprocess="xml-stripblanks">welcome_page.ui</file>
<file preprocess="xml-stripblanks">window.ui</file> <file preprocess="xml-stripblanks">window.ui</file>

View file

@ -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;
}
}
}
}

View file

@ -5,17 +5,31 @@ template $MusicusWindow : Adw.ApplicationWindow {
title: _("Musicus"); title: _("Musicus");
Adw.ToolbarView { Adw.ToolbarView {
Adw.NavigationView navigation_view { Gtk.Stack stack {
transition-type: over_up_down;
Gtk.StackPage {
name: "navigation";
child: Adw.NavigationView navigation_view {
$MusicusWelcomePage { $MusicusWelcomePage {
folder-selected => $set_library_folder() swapped; folder-selected => $set_library_folder() swapped;
} }
$MusicusHomePage {} $MusicusHomePage {}
};
}
Gtk.StackPage {
name: "playlist";
child: $MusicusPlaylistPage {
close => $hide_playlist() swapped;
};
}
} }
[bottom] [bottom]
Gtk.Revealer player_bar_revealer { Gtk.Revealer player_bar_revealer {
reveal-child: false; reveal-child: true;
transition-type: slide_up; transition-type: slide_up;
Gtk.Box { Gtk.Box {
@ -55,10 +69,11 @@ template $MusicusWindow : Adw.ApplicationWindow {
label: "00:00 / 01:00"; label: "00:00 / 01:00";
} }
Gtk.Button { Gtk.ToggleButton playlist_button {
styles ["flat"] styles ["flat"]
valign: center; valign: center;
icon-name: "playlist-symbolic"; icon-name: "playlist-symbolic";
toggled => $show_playlist() swapped;
} }
} }
} }

View file

@ -1,4 +1,5 @@
data/res/home_page.blp data/res/home_page.blp
data/res/playlist_page.blp
data/res/tile.blp data/res/tile.blp
data/res/welcome_page.blp data/res/welcome_page.blp
data/res/window.blp data/res/window.blp

View file

@ -1,6 +1,7 @@
mod application; mod application;
mod config; mod config;
mod home_page; mod home_page;
mod playlist_page;
mod tile; mod tile;
mod welcome_page; mod welcome_page;
mod window; mod window;

56
src/playlist_page.rs Normal file
View file

@ -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<Self>) {
obj.init_template();
}
}
impl ObjectImpl for MusicusPlaylistPage {
fn signals() -> &'static [Signal] {
static SIGNALS: Lazy<Vec<Signal>> =
Lazy::new(|| vec![Signal::builder("close").build()]);
SIGNALS.as_ref()
}
}
impl WidgetImpl for MusicusPlaylistPage {}
impl BinImpl for MusicusPlaylistPage {}
}
glib::wrapper! {
pub struct MusicusPlaylistPage(ObjectSubclass<imp::MusicusPlaylistPage>)
@extends gtk::Widget, adw::Bin;
}
#[gtk::template_callbacks]
impl MusicusPlaylistPage {
pub fn new() -> Self {
glib::Object::new()
}
#[template_callback]
fn close(&self, _: &gtk::Button) {
self.emit_by_name::<()>("close", &[]);
}
}

View file

@ -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 adw::subclass::prelude::*;
use gtk::{gio, glib, prelude::*}; use gtk::{gio, glib, prelude::*};
@ -9,10 +12,14 @@ mod imp {
#[derive(Debug, Default, gtk::CompositeTemplate)] #[derive(Debug, Default, gtk::CompositeTemplate)]
#[template(resource = "/de/johrpan/musicus/window.ui")] #[template(resource = "/de/johrpan/musicus/window.ui")]
pub struct MusicusWindow { pub struct MusicusWindow {
#[template_child]
pub stack: TemplateChild<gtk::Stack>,
#[template_child] #[template_child]
pub navigation_view: TemplateChild<adw::NavigationView>, pub navigation_view: TemplateChild<adw::NavigationView>,
#[template_child] #[template_child]
pub player_bar_revealer: TemplateChild<gtk::Revealer>, pub player_bar_revealer: TemplateChild<gtk::Revealer>,
#[template_child]
pub playlist_button: TemplateChild<gtk::ToggleButton>,
} }
#[glib::object_subclass] #[glib::object_subclass]
@ -23,6 +30,7 @@ mod imp {
fn class_init(klass: &mut Self::Class) { fn class_init(klass: &mut Self::Class) {
MusicusHomePage::static_type(); MusicusHomePage::static_type();
MusicusPlaylistPage::static_type();
MusicusWelcomePage::static_type(); MusicusWelcomePage::static_type();
klass.bind_template(); klass.bind_template();
klass.bind_template_instance_callbacks(); klass.bind_template_instance_callbacks();
@ -93,4 +101,20 @@ impl MusicusWindow {
log::info!("{path:?}"); log::info!("{path:?}");
self.imp().navigation_view.replace_with_tags(&["home"]); self.imp().navigation_view.replace_with_tags(&["home"]);
} }
#[template_callback]
fn show_playlist(&self, button: &gtk::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);
}
} }