From 7d598bb1d08b05fd5ab532657acdad967c0afbc3 Mon Sep 17 00:00:00 2001 From: Jordan Petridis Date: Wed, 16 May 2018 19:40:36 +0300 Subject: [PATCH] h-gtk: Smooth out some stack transitions. --- hammond-gtk/src/stacks/home.rs | 19 ++++++++++++++----- hammond-gtk/src/stacks/populated.rs | 9 +++++---- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/hammond-gtk/src/stacks/home.rs b/hammond-gtk/src/stacks/home.rs index 7b959b6..1974168 100644 --- a/hammond-gtk/src/stacks/home.rs +++ b/hammond-gtk/src/stacks/home.rs @@ -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(()) diff --git a/hammond-gtk/src/stacks/populated.rs b/hammond-gtk/src/stacks/populated.rs index 90776ce..e791ca5 100644 --- a/hammond-gtk/src/stacks/populated.rs +++ b/hammond-gtk/src/stacks/populated.rs @@ -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 {