mirror of
https://github.com/johrpan/musicus.git
synced 2025-10-26 19:57:25 +01:00
Remove old navigator
This commit is contained in:
parent
ee71a905e1
commit
1b6f4ab51e
4 changed files with 0 additions and 207 deletions
|
|
@ -97,8 +97,6 @@ sources = files(
|
||||||
'widgets/indexed_list_model.rs',
|
'widgets/indexed_list_model.rs',
|
||||||
'widgets/list.rs',
|
'widgets/list.rs',
|
||||||
'widgets/mod.rs',
|
'widgets/mod.rs',
|
||||||
'widgets/navigator.rs',
|
|
||||||
'widgets/navigator_window.rs',
|
|
||||||
'widgets/player_bar.rs',
|
'widgets/player_bar.rs',
|
||||||
'widgets/poe_list.rs',
|
'widgets/poe_list.rs',
|
||||||
'widgets/screen.rs',
|
'widgets/screen.rs',
|
||||||
|
|
|
||||||
|
|
@ -12,12 +12,6 @@ pub use entry_row::*;
|
||||||
pub mod list;
|
pub mod list;
|
||||||
pub use list::*;
|
pub use list::*;
|
||||||
|
|
||||||
pub mod navigator;
|
|
||||||
pub use navigator::*;
|
|
||||||
|
|
||||||
pub mod navigator_window;
|
|
||||||
pub use navigator_window::*;
|
|
||||||
|
|
||||||
pub mod player_bar;
|
pub mod player_bar;
|
||||||
pub use player_bar::*;
|
pub use player_bar::*;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,151 +0,0 @@
|
||||||
use glib::clone;
|
|
||||||
use gtk::prelude::*;
|
|
||||||
use std::cell::RefCell;
|
|
||||||
use std::rc::Rc;
|
|
||||||
|
|
||||||
pub trait NavigatorScreen {
|
|
||||||
fn attach_navigator(&self, navigator: Rc<Navigator>);
|
|
||||||
fn get_widget(&self) -> gtk::Widget;
|
|
||||||
fn detach_navigator(&self);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct Navigator {
|
|
||||||
pub window: gtk::Window,
|
|
||||||
pub widget: gtk::Stack,
|
|
||||||
screens: RefCell<Vec<Rc<dyn NavigatorScreen>>>,
|
|
||||||
old_screens: RefCell<Vec<Rc<dyn NavigatorScreen>>>,
|
|
||||||
back_cb: RefCell<Option<Box<dyn Fn() -> ()>>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Navigator {
|
|
||||||
pub fn new<W, S>(window: &W, empty_screen: &S) -> Rc<Self>
|
|
||||||
where
|
|
||||||
W: IsA<gtk::Window>,
|
|
||||||
S: IsA<gtk::Widget>,
|
|
||||||
{
|
|
||||||
let widget = gtk::Stack::new();
|
|
||||||
widget.set_hhomogeneous(false);
|
|
||||||
widget.set_vhomogeneous(false);
|
|
||||||
widget.set_interpolate_size(true);
|
|
||||||
widget.set_transition_type(gtk::StackTransitionType::Crossfade);
|
|
||||||
widget.set_hexpand(true);
|
|
||||||
widget.add_named(empty_screen, Some("empty_screen"));
|
|
||||||
widget.show();
|
|
||||||
|
|
||||||
let result = Rc::new(Self {
|
|
||||||
window: window.clone().upcast(),
|
|
||||||
widget,
|
|
||||||
screens: RefCell::new(Vec::new()),
|
|
||||||
old_screens: RefCell::new(Vec::new()),
|
|
||||||
back_cb: RefCell::new(None),
|
|
||||||
});
|
|
||||||
|
|
||||||
unsafe {
|
|
||||||
result.widget.connect_notify_unsafe(
|
|
||||||
Some("transition-running"),
|
|
||||||
clone!(@strong result => move |_, _| {
|
|
||||||
if !result.widget.get_transition_running() {
|
|
||||||
result.clear_old_screens();
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
result
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_back_cb<F>(&self, cb: F)
|
|
||||||
where
|
|
||||||
F: Fn() -> () + 'static,
|
|
||||||
{
|
|
||||||
self.back_cb.replace(Some(Box::new(cb)));
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn push<S>(self: Rc<Self>, screen: Rc<S>)
|
|
||||||
where
|
|
||||||
S: NavigatorScreen + 'static,
|
|
||||||
{
|
|
||||||
if let Some(screen) = self.screens.borrow().last() {
|
|
||||||
screen.detach_navigator();
|
|
||||||
}
|
|
||||||
|
|
||||||
let widget = screen.get_widget();
|
|
||||||
self.widget.add_child(&widget);
|
|
||||||
self.widget.set_visible_child(&widget);
|
|
||||||
|
|
||||||
screen.attach_navigator(self.clone());
|
|
||||||
self.screens.borrow_mut().push(screen);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn pop(self: Rc<Self>) {
|
|
||||||
let popped = if let Some(screen) = self.screens.borrow_mut().pop() {
|
|
||||||
screen.detach_navigator();
|
|
||||||
self.old_screens.borrow_mut().push(screen);
|
|
||||||
|
|
||||||
true
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
};
|
|
||||||
|
|
||||||
if popped {
|
|
||||||
if let Some(screen) = self.screens.borrow().last() {
|
|
||||||
let widget = screen.get_widget();
|
|
||||||
self.widget.set_visible_child(&widget);
|
|
||||||
|
|
||||||
screen.attach_navigator(self.clone());
|
|
||||||
} else {
|
|
||||||
self.widget.set_visible_child_name("empty_screen");
|
|
||||||
if let Some(cb) = &*self.back_cb.borrow() {
|
|
||||||
cb()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if !self.widget.get_transition_running() {
|
|
||||||
self.clear_old_screens();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn replace<S>(self: Rc<Self>, screen: Rc<S>)
|
|
||||||
where
|
|
||||||
S: NavigatorScreen + 'static,
|
|
||||||
{
|
|
||||||
for screen in self.screens.replace(Vec::new()) {
|
|
||||||
screen.detach_navigator();
|
|
||||||
self.old_screens.borrow_mut().push(screen);
|
|
||||||
}
|
|
||||||
|
|
||||||
let widget = screen.get_widget();
|
|
||||||
self.widget.add_child(&widget);
|
|
||||||
self.widget.set_visible_child(&widget);
|
|
||||||
|
|
||||||
screen.attach_navigator(self.clone());
|
|
||||||
self.screens.borrow_mut().push(screen);
|
|
||||||
|
|
||||||
if !self.widget.get_transition_running() {
|
|
||||||
self.clear_old_screens();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn reset(&self) {
|
|
||||||
self.widget.set_visible_child_name("empty_screen");
|
|
||||||
|
|
||||||
for screen in self.screens.replace(Vec::new()) {
|
|
||||||
screen.detach_navigator();
|
|
||||||
self.old_screens.borrow_mut().push(screen);
|
|
||||||
}
|
|
||||||
|
|
||||||
if !self.widget.get_transition_running() {
|
|
||||||
self.clear_old_screens();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn clear_old_screens(&self) {
|
|
||||||
for screen in self.old_screens.borrow().iter() {
|
|
||||||
self.widget.remove(&screen.get_widget());
|
|
||||||
}
|
|
||||||
|
|
||||||
self.old_screens.borrow_mut().clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
@ -1,48 +0,0 @@
|
||||||
use crate::widgets::{Navigator, NavigatorScreen};
|
|
||||||
use glib::clone;
|
|
||||||
use gtk::prelude::*;
|
|
||||||
use std::rc::Rc;
|
|
||||||
|
|
||||||
/// A window hosting a navigator.
|
|
||||||
pub struct NavigatorWindow {
|
|
||||||
window: libadwaita::Window,
|
|
||||||
navigator: Rc<Navigator>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl NavigatorWindow {
|
|
||||||
/// Create a new navigator window showing an initial screen.
|
|
||||||
pub fn new<S: NavigatorScreen + 'static>(initial_screen: Rc<S>) -> Rc<Self> {
|
|
||||||
// Create UI
|
|
||||||
|
|
||||||
let window = libadwaita::Window::new();
|
|
||||||
window.set_default_size(600, 424);
|
|
||||||
let placeholder = gtk::Label::new(None);
|
|
||||||
let navigator = Navigator::new(&window, &placeholder);
|
|
||||||
libadwaita::WindowExt::set_child(&window, Some(&navigator.widget));
|
|
||||||
|
|
||||||
let this = Rc::new(Self { window, navigator });
|
|
||||||
|
|
||||||
// Connect signals and callbacks
|
|
||||||
|
|
||||||
this.navigator.set_back_cb(clone!(@strong this => move || {
|
|
||||||
this.window.close();
|
|
||||||
}));
|
|
||||||
|
|
||||||
// Initialize
|
|
||||||
|
|
||||||
this.navigator.clone().replace(initial_screen);
|
|
||||||
|
|
||||||
this
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Make the wrapped window transient. This will make the window modal.
|
|
||||||
pub fn set_transient_for<W: IsA<gtk::Window>>(&self, window: &W) {
|
|
||||||
self.window.set_modal(true);
|
|
||||||
self.window.set_transient_for(Some(window));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Show the navigator window.
|
|
||||||
pub fn show(&self) {
|
|
||||||
self.window.show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue