diff --git a/podcasts-gtk/src/widgets/base_view.rs b/podcasts-gtk/src/widgets/base_view.rs index 3ce5c2e..faf6db9 100644 --- a/podcasts-gtk/src/widgets/base_view.rs +++ b/podcasts-gtk/src/widgets/base_view.rs @@ -1,4 +1,5 @@ -use gtk::{self, prelude::*, Orientation, PolicyType}; +use gtk::{self, prelude::*, Adjustment, Orientation, PolicyType}; +use utils::smooth_scroll_to; #[derive(Debug, Clone)] pub(crate) struct BaseView { @@ -34,4 +35,18 @@ impl BaseView { pub(crate) fn add>(&self, widget: &T) { self.scrolled_window.add(widget); } + + pub(crate) fn set_adjutment<'a, 'b>( + &self, + hadjustment: Option<&'a Adjustment>, + vadjustment: Option<&'b Adjustment>, + ) { + if let Some(h) = hadjustment { + smooth_scroll_to(&self.scrolled_window, h); + } + + if let Some(v) = vadjustment { + smooth_scroll_to(&self.scrolled_window, v); + } + } } diff --git a/podcasts-gtk/src/widgets/show.rs b/podcasts-gtk/src/widgets/show.rs index daacf96..21b2758 100644 --- a/podcasts-gtk/src/widgets/show.rs +++ b/podcasts-gtk/src/widgets/show.rs @@ -94,10 +94,6 @@ impl ShowWidget { self.view.container() } - pub(crate) fn scrolled_window(&self) -> >k::ScrolledWindow { - self.view.scrolled_window() - } - /// Set the show cover. fn set_cover(&self, pd: &Arc) -> Result<(), Error> { utils::set_image_from_path(&self.cover, pd.id(), 256) @@ -113,6 +109,7 @@ impl ShowWidget { pub(crate) fn save_vadjustment(&self, oldid: i32) -> Result<(), Error> { if let Ok(mut guard) = SHOW_WIDGET_VALIGNMENT.lock() { let adj = self + .view .scrolled_window() .get_vadjustment() .ok_or_else(|| format_err!("Could not get the adjustment"))?; @@ -139,13 +136,8 @@ impl ShowWidget { }; // Copy the vertical scrollbar adjustment from the old view into the new one. - let res = fragile - .try_get() - .map(|x| utils::smooth_scroll_to(self.scrolled_window(), &x)) - .map_err(From::from); - - debug_assert!(res.is_ok()); - return res; + let vadj = fragile.try_get()?; + self.view.set_adjutment(None, Some(&vadj)); } Ok(())