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:
parent
198c0cc374
commit
2dc7559b92
@ -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)]
|
#[derive(Debug, Clone)]
|
||||||
pub(crate) struct BaseView {
|
pub(crate) struct BaseView {
|
||||||
@ -34,4 +35,18 @@ impl BaseView {
|
|||||||
pub(crate) fn add<T: IsA<gtk::Widget>>(&self, widget: &T) {
|
pub(crate) fn add<T: IsA<gtk::Widget>>(&self, widget: &T) {
|
||||||
self.scrolled_window.add(widget);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -94,10 +94,6 @@ impl ShowWidget {
|
|||||||
self.view.container()
|
self.view.container()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn scrolled_window(&self) -> >k::ScrolledWindow {
|
|
||||||
self.view.scrolled_window()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Set the show cover.
|
/// Set the show cover.
|
||||||
fn set_cover(&self, pd: &Arc<Show>) -> Result<(), Error> {
|
fn set_cover(&self, pd: &Arc<Show>) -> Result<(), Error> {
|
||||||
utils::set_image_from_path(&self.cover, pd.id(), 256)
|
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> {
|
pub(crate) fn save_vadjustment(&self, oldid: i32) -> Result<(), Error> {
|
||||||
if let Ok(mut guard) = SHOW_WIDGET_VALIGNMENT.lock() {
|
if let Ok(mut guard) = SHOW_WIDGET_VALIGNMENT.lock() {
|
||||||
let adj = self
|
let adj = self
|
||||||
|
.view
|
||||||
.scrolled_window()
|
.scrolled_window()
|
||||||
.get_vadjustment()
|
.get_vadjustment()
|
||||||
.ok_or_else(|| format_err!("Could not get the adjustment"))?;
|
.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.
|
// Copy the vertical scrollbar adjustment from the old view into the new one.
|
||||||
let res = fragile
|
let vadj = fragile.try_get()?;
|
||||||
.try_get()
|
self.view.set_adjutment(None, Some(&vadj));
|
||||||
.map(|x| utils::smooth_scroll_to(self.scrolled_window(), &x))
|
|
||||||
.map_err(From::from);
|
|
||||||
|
|
||||||
debug_assert!(res.is_ok());
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user