Navigation Menu

Skip to content

Commit

Permalink
Fix list bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
jackpot51 committed Aug 30, 2017
1 parent 07de5a0 commit 4f59f7e
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/widgets/list.rs
Expand Up @@ -13,7 +13,7 @@ use widgets::Widget;
use std::ops::Index; use std::ops::Index;


/// An entry in a list /// An entry in a list
/// Each entry stores widgets within. /// Each entry stores widgets within.
pub struct Entry { pub struct Entry {
pub height: Cell<u32>, pub height: Cell<u32>,
click_callback: RefCell<Option<Arc<Fn(&Entry, Point)>>>, click_callback: RefCell<Option<Arc<Fn(&Entry, Point)>>>,
Expand Down Expand Up @@ -107,11 +107,14 @@ impl List {


pub fn scroll(&self, y: i32) { pub fn scroll(&self, y: i32) {
let mut set_to = self.v_scroll.get() + y; let mut set_to = self.v_scroll.get() + y;

let max = self.current_height.get() as i32 - self.rect.get().height as i32;
if set_to < 0 { if set_to < 0 {
set_to = 0; set_to = 0;
} else if self.rect.get().height as i32 + set_to > self.current_height.get() as i32 { } else if set_to > max {
set_to = self.v_scroll.get() as i32; set_to = max;
} }

self.v_scroll.set(set_to); self.v_scroll.set(set_to);
} }


Expand Down Expand Up @@ -178,7 +181,7 @@ impl Widget for List {
} }


let image = image.data(); let image = image.data();
target.image(x, current_y-self.v_scroll.get(), width, entry.height.get(), &image); target.image(0, current_y-self.v_scroll.get(), width, entry.height.get(), &image);


current_y += entry.height.get() as i32 current_y += entry.height.get() as i32
} }
Expand Down Expand Up @@ -292,4 +295,3 @@ impl Widget for List {
} }


impl Place for List {} impl Place for List {}

0 comments on commit 4f59f7e

Please sign in to comment.