fix: protect scroll operations when non-scrollable

Fixes #109
This commit is contained in:
Alexandre Bury 2017-02-26 14:53:50 -08:00
parent e91021a633
commit 34c7462877

View File

@ -119,23 +119,29 @@ impl ScrollBase {
/// Scroll to the bottom of the view. /// Scroll to the bottom of the view.
pub fn scroll_bottom(&mut self) { pub fn scroll_bottom(&mut self) {
if self.scrollable() {
self.start_line = self.content_height - self.view_height; self.start_line = self.content_height - self.view_height;
} }
}
/// Scroll down by the given number of line. /// Scroll down by the given number of line.
/// ///
/// Never further than the bottom of the view. /// Never further than the bottom of the view.
pub fn scroll_down(&mut self, n: usize) { pub fn scroll_down(&mut self, n: usize) {
if self.scrollable() {
self.start_line = min(self.start_line + n, self.start_line = min(self.start_line + n,
self.content_height - self.view_height); self.content_height - self.view_height);
} }
}
/// Scroll up by the given number of lines. /// Scroll up by the given number of lines.
/// ///
/// Never above the top of the view. /// Never above the top of the view.
pub fn scroll_up(&mut self, n: usize) { pub fn scroll_up(&mut self, n: usize) {
if self.scrollable() {
self.start_line -= min(self.start_line, n); self.start_line -= min(self.start_line, n);
} }
}
/// Draws the scroll bar and the content using the given drawer. /// Draws the scroll bar and the content using the given drawer.
/// ///