Skip to content

Commit

Permalink
Enhanced scrollbars movement.
Browse files Browse the repository at this point in the history
The scrollbars now follow high speed mouse movement.
  • Loading branch information
LaChal committed Apr 10, 2016
1 parent 7318425 commit 0aae399
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
12 changes: 6 additions & 6 deletions albow/palette_view.py
Expand Up @@ -155,9 +155,9 @@ def mouse_drag(self, event):
s = float(d) / n
if abs(self.scroll_rel) >= s:
if self.scroll_rel > 0:
self.scroll_down()
self.scroll_down(delta=int(abs(self.scroll_rel) / s))
else:
self.scroll_up()
self.scroll_up(delta=int(abs(self.scroll_rel) / s))
self.scroll_rel = 0

def mouse_up(self, event):
Expand All @@ -166,13 +166,13 @@ def mouse_up(self, event):
self.dragging_hover = False
self.scroll_rel = 0

def scroll_up(self):
def scroll_up(self, delta=1):
if self.can_scroll_up():
self.scroll -= 1
self.scroll -= delta

def scroll_down(self):
def scroll_down(self, delta=1):
if self.can_scroll_down():
self.scroll += 1
self.scroll += delta

def scroll_to_item(self, n):
i = max(0, min(n, self.num_items() - 1))
Expand Down
14 changes: 8 additions & 6 deletions albow/scrollpanel.py
Expand Up @@ -151,6 +151,8 @@ def hscrollbar_rect(self):
r = Rect(left, slt, w, self.scroll_button_size)
r.right = min(r.right, d + slr)
r.inflate_ip(-4, -4)
if r.w < 1:
r.w = int(w)
return r

def can_scroll_left(self):
Expand Down Expand Up @@ -202,13 +204,13 @@ def draw(self, surface):
if l or r:
self.draw_hscrollbar(surface)

def scroll_left(self):
def scroll_left(self, delta=1):
if self.can_scroll_left():
self.hscroll -= self.cell_size[1]
self.hscroll -= self.cell_size[1] * delta

def scroll_right(self):
def scroll_right(self, delta=1):
if self.can_scroll_right():
self.hscroll += self.cell_size[1]
self.hscroll += self.cell_size[1] * delta

def mouse_down(self, event):
if event.button == 1:
Expand Down Expand Up @@ -241,9 +243,9 @@ def mouse_drag(self, event):
s = float(d) / n
if abs(self.hscroll_rel) > s:
if self.hscroll_rel > 0:
self.scroll_right()
self.scroll_right(delta=int(abs(self.hscroll_rel) / s))
else:
self.scroll_left()
self.scroll_left(delta=int(abs(self.hscroll_rel) / s))
self.hscroll_rel = 0
PaletteView.mouse_drag(self, event)

Expand Down

0 comments on commit 0aae399

Please sign in to comment.