Merge pull request #261 from sajattack/master

implement scroll_to_top and scroll_to_bottom
This commit is contained in:
Alexandre Bury 2018-06-16 10:52:45 -07:00 committed by GitHub
commit 4f8613293c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -108,6 +108,32 @@ impl<V> ScrollView<V> {
self.with(|s| s.set_scroll_x(enabled))
}
/// Programmatically scroll to the top of the view.
pub fn scroll_to_top(&mut self) {
let curr_x = self.offset.x;
self.set_offset((curr_x,0));
}
/// Programmatically scroll to the bottom of the view.
pub fn scroll_to_bottom(&mut self) {
let max_y = self.inner_size.saturating_sub(self.available_size()).y;
let curr_x = self.offset.x;
self.set_offset((curr_x, max_y));
}
/// Programmatically scroll to the leftmost side of the view.
pub fn scroll_to_left(&mut self) {
let curr_y = self.offset.y;
self.set_offset((0, curr_y));
}
/// Programmatically scroll to the rightmost side of the view.
pub fn scroll_to_right(&mut self) {
let max_x = self.inner_size.saturating_sub(self.available_size()).x;
let curr_y = self.offset.y;
self.set_offset((max_x, curr_y));
}
/// Returns for each axis if we are scrolling.
fn is_scrolling(&self) -> XY<bool> {
self.inner_size.zip_map(self.last_size, |i, s| i > s)