h-gtk: Smooth out some stack transitions.
This commit is contained in:
parent
ccd3e3ab2c
commit
7d598bb1d0
@ -1,5 +1,6 @@
|
||||
use gtk;
|
||||
use gtk::prelude::*;
|
||||
use gtk::StackTransitionType;
|
||||
|
||||
use failure::Error;
|
||||
use hammond_data::dbqueries::is_episodes_populated;
|
||||
@ -60,6 +61,7 @@ impl HomeStack {
|
||||
.ok();
|
||||
|
||||
self.replace_view()?;
|
||||
// Determine the actuall state.
|
||||
self.determine_state().map_err(From::from)
|
||||
}
|
||||
|
||||
@ -69,8 +71,15 @@ impl HomeStack {
|
||||
let eps = HomeView::new(self.sender.clone())?;
|
||||
|
||||
// Remove the old widget and add the new one
|
||||
// during this the previous view is removed,
|
||||
// and the visibile child fallsback to empty view.
|
||||
self.stack.remove(old);
|
||||
self.stack.add_named(&eps.container, "home");
|
||||
// Keep the previous state.
|
||||
let s = self.state;
|
||||
// Set the visible child back to the previous one to avoid
|
||||
// the stack transition animation to show the empty view
|
||||
self.switch_visible(s, StackTransitionType::None);
|
||||
|
||||
// replace view in the struct too
|
||||
self.episodes = eps;
|
||||
@ -81,16 +90,16 @@ impl HomeStack {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn switch_visible(&mut self, s: State) {
|
||||
fn switch_visible(&mut self, s: State, animation: StackTransitionType) {
|
||||
use self::State::*;
|
||||
|
||||
match s {
|
||||
Home => {
|
||||
self.stack.set_visible_child_name("home");
|
||||
self.stack.set_visible_child_full("home", animation);
|
||||
self.state = Home;
|
||||
}
|
||||
Empty => {
|
||||
self.stack.set_visible_child_name("empty");
|
||||
self.stack.set_visible_child_full("empty", animation);
|
||||
self.state = Empty;
|
||||
}
|
||||
}
|
||||
@ -98,9 +107,9 @@ impl HomeStack {
|
||||
|
||||
fn determine_state(&mut self) -> Result<(), DataError> {
|
||||
if is_episodes_populated()? {
|
||||
self.switch_visible(State::Home);
|
||||
self.switch_visible(State::Home, StackTransitionType::Crossfade);
|
||||
} else {
|
||||
self.switch_visible(State::Empty);
|
||||
self.switch_visible(State::Empty, StackTransitionType::Crossfade);
|
||||
};
|
||||
|
||||
Ok(())
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
use gtk;
|
||||
use gtk::prelude::*;
|
||||
use gtk::StackTransitionType;
|
||||
|
||||
use failure::Error;
|
||||
|
||||
@ -65,7 +66,7 @@ impl PopulatedStack {
|
||||
// to make sure it will stay the same.
|
||||
let s = self.state;
|
||||
self.replace_shows()?;
|
||||
self.switch_visible(s, gtk::StackTransitionType::None);
|
||||
self.switch_visible(s, StackTransitionType::Crossfade);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@ -105,7 +106,7 @@ impl PopulatedStack {
|
||||
// removal and insertion in the gtk::Stack, so we have
|
||||
// to make sure it will stay the same.
|
||||
let s = self.state;
|
||||
self.switch_visible(s, gtk::StackTransitionType::None);
|
||||
self.switch_visible(s, StackTransitionType::None);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@ -124,7 +125,7 @@ impl PopulatedStack {
|
||||
// removal and insertion in the gtk::Stack, so we have
|
||||
// to make sure it will stay the same.
|
||||
let s = self.state;
|
||||
self.switch_visible(s, gtk::StackTransitionType::None);
|
||||
self.switch_visible(s, StackTransitionType::Crossfade);
|
||||
|
||||
old.destroy();
|
||||
Ok(())
|
||||
@ -144,7 +145,7 @@ impl PopulatedStack {
|
||||
self.container.clone()
|
||||
}
|
||||
|
||||
pub fn switch_visible(&mut self, state: PopulatedState, animation: gtk::StackTransitionType) {
|
||||
pub fn switch_visible(&mut self, state: PopulatedState, animation: StackTransitionType) {
|
||||
use self::PopulatedState::*;
|
||||
|
||||
match state {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user