commit dabcc36baab06598fa4baa76bb779f09d82814cc Author: Damian Johnson atagar@torproject.org Date: Wed Nov 16 09:52:35 2016 -0800
Fix slider math
Damn this scrollbar method has given me a lot of headaches. Correcting an off-by-one error that caused the tests to fail on my netbook but pass on my pc.
I really hope this is the last time I need to weed one of these out. For my personal reference here's the numbers when working through the test...
top = 15 top_index = 21 size = 30 self.height = 25
scrollbar_height = self.height - top - 1 = 25 - 15 - 1 = 9
bottom_index = top_index + scrollbar_height = 21 + 9 = 30
slider_top = (scrollbar_height * top_index) // size = (9 * 21) // 30 = 6 slider_size = (scrollbar_height * (bottom_index - top_index + 1)) // size = (9 * (30 - 21 + 1)) // 30 = 3 --- nyx/curses.py | 9 +++++++-- test/subwindow.py | 6 +++--- 2 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/nyx/curses.py b/nyx/curses.py index b733449..4396ab4 100644 --- a/nyx/curses.py +++ b/nyx/curses.py @@ -885,9 +885,14 @@ class _Subwindow(object): # determines scrollbar dimensions
scrollbar_height = self.height - top - 1 # -1 is for the bottom border - bottom_index = top_index + scrollbar_height + 1 + + # Bottom index of the scroll bar. We show (scrollbar_height + 1) items at a + # time but have -1 to make the bottom bound inclusive. + + bottom_index = top_index + scrollbar_height + slider_top = (scrollbar_height * top_index) // size - slider_size = (scrollbar_height * (bottom_index - top_index)) // size + slider_size = (scrollbar_height * (bottom_index - top_index + 1)) // size max_slider_top = scrollbar_height - slider_size - 1
# ensures slider isn't at top or bottom unless really at those extreme bounds diff --git a/test/subwindow.py b/test/subwindow.py index db97970..61246d2 100644 --- a/test/subwindow.py +++ b/test/subwindow.py @@ -34,7 +34,7 @@ EXPECTED_SCROLLBAR_TOP = """ *| *| *| - | +*| | | | @@ -48,7 +48,7 @@ EXPECTED_SCROLLBAR_MIDDLE = """ *| *| *| - | +*| | | | @@ -62,7 +62,7 @@ EXPECTED_SCROLLBAR_BOTTOM = """ | | | - | +*| *| *| *|
tor-commits@lists.torproject.org