BaseView: implement a set_adjustments method

Ment to replace the individual set_vadjustment of widgets.
Also remove unused method from ShowWiget.
This commit is contained in:
Jordan Petridis 2018-08-09 07:20:22 +03:00
parent c3121bef84
commit 70a24fba69
No known key found for this signature in database
GPG Key ID: CEABAD9F5683B9A6
2 changed files with 19 additions and 12 deletions

View File

@ -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<T: IsA<gtk::Widget>>(&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);
}
}
}

View File

@ -94,10 +94,6 @@ impl ShowWidget {
self.view.container()
}
pub(crate) fn scrolled_window(&self) -> &gtk::ScrolledWindow {
self.view.scrolled_window()
}
/// Set the show cover.
fn set_cover(&self, pd: &Arc<Show>) -> 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(())