From b5dbfb1a86aad7af4d0ae5741e8ed5b83c3001a1 Mon Sep 17 00:00:00 2001 From: Jordan Petridis Date: Fri, 4 May 2018 11:32:50 +0300 Subject: [PATCH] PopulatedStack: Allow for more control over the stack transitions. When you just update/replace the widget there is no need for an animation to occur. Thus why animations where broken before. This commit is not ideal as it makes it the responsibility of the caller to declare valid(UX wise) transitions. --- hammond-gtk/src/app.rs | 8 ++++++-- hammond-gtk/src/stacks/populated.rs | 14 ++++++-------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/hammond-gtk/src/app.rs b/hammond-gtk/src/app.rs index 130e2e9..6be9c40 100644 --- a/hammond-gtk/src/app.rs +++ b/hammond-gtk/src/app.rs @@ -182,12 +182,16 @@ impl App { Ok(Action::ShowWidgetAnimated) => { let shows = content.get_shows(); let mut pop = shows.borrow().populated(); - pop.borrow_mut().switch_visible(PopulatedState::Widget); + pop.borrow_mut().switch_visible( + PopulatedState::Widget, + gtk::StackTransitionType::SlideLeft, + ); } Ok(Action::ShowShowsAnimated) => { let shows = content.get_shows(); let mut pop = shows.borrow().populated(); - pop.borrow_mut().switch_visible(PopulatedState::View); + pop.borrow_mut() + .switch_visible(PopulatedState::View, gtk::StackTransitionType::SlideRight); } Ok(Action::HeaderBarShowTile(title)) => headerbar.switch_to_back(&title), Ok(Action::HeaderBarNormal) => headerbar.switch_to_normal(), diff --git a/hammond-gtk/src/stacks/populated.rs b/hammond-gtk/src/stacks/populated.rs index f03c585..f9f92fb 100644 --- a/hammond-gtk/src/stacks/populated.rs +++ b/hammond-gtk/src/stacks/populated.rs @@ -72,7 +72,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); + self.switch_visible(s, gtk::StackTransitionType::None); old.destroy(); Ok(()) @@ -95,7 +95,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); + self.switch_visible(s, gtk::StackTransitionType::None); Ok(()) } @@ -114,7 +114,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); + self.switch_visible(s, gtk::StackTransitionType::None); old.destroy(); Ok(()) @@ -135,18 +135,16 @@ impl PopulatedStack { } #[inline] - pub fn switch_visible(&mut self, state: PopulatedState) { + pub fn switch_visible(&mut self, state: PopulatedState, animation: gtk::StackTransitionType) { use self::PopulatedState::*; match state { View => { - self.stack - .set_visible_child_full("shows", gtk::StackTransitionType::SlideRight); + self.stack.set_visible_child_full("shows", animation); self.state = View; } Widget => { - self.stack - .set_visible_child_full("widget", gtk::StackTransitionType::SlideLeft); + self.stack.set_visible_child_full("widget", animation); self.state = Widget; } }