def test_smooth_scroll_end(self): EventLoop.ensure_window() win = EventLoop.window grid = _TestGrid() scroll = ScrollView(smooth_scroll_end=10) assert scroll.smooth_scroll_end == 10 scroll.add_widget(grid) # XXX this shouldn't be needed, but previous tests apparently # don't cleanup while win.children: win.remove_widget(win.children[0]) win.add_widget(scroll) # get widgets ready EventLoop.idle() e = scroll.effect_y assert e.velocity == 0 touch = UTMotionEvent( "unittest", next(touch_id), { "x": scroll.center_x / float(win.width), "y": scroll.center_y / float(win.height), }) touch.profile.append('button') touch.button = 'scrollup' EventLoop.post_dispatch_input("begin", touch) # EventLoop.post_dispatch_input("update", touch) assert e.velocity == 10 * scroll.scroll_wheel_distance EventLoop.idle() assert 0 < e.velocity < 10 * scroll.scroll_wheel_distance EventLoop.post_dispatch_input("end", touch) EventLoop.idle() assert 0 < e.velocity < 10 * scroll.scroll_wheel_distance # wait for velocity to die off while e.velocity: EventLoop.idle() touch = UTMotionEvent( "unittest", next(touch_id), { "x": scroll.center_x / float(win.width), "y": scroll.center_y / float(win.height), }) touch.profile.append('button') touch.button = 'scrolldown' EventLoop.post_dispatch_input("begin", touch) # EventLoop.post_dispatch_input("update", touch) assert e.velocity == -10 * scroll.scroll_wheel_distance EventLoop.idle() assert 0 > e.velocity > -10 * scroll.scroll_wheel_distance EventLoop.post_dispatch_input("end", touch) EventLoop.idle() assert 0 > e.velocity > -10 * scroll.scroll_wheel_distance
def test_vertical_scroll_doesnt_depend_on_lines_rendering(self): # TextInput.on_touch_down was checking the possibility to scroll_up # using the positions of the rendered lines' rects. These positions # don't change when the lines are skipped (e.g. during fast scroll # or ctrl+cursor_home) which lead to scroll freeze ti = self.make_scrollable_text_input() # move viewport to the first line ti.do_cursor_movement('cursor_home', control=True) self.advance_frames(1) assert ti._visible_lines_range == (0, 10) from kivy.base import EventLoop win = EventLoop.window # slowly scroll to the last line to render all lines at least once for _ in range(30): # little overscroll is important for detection touch = UTMotionEvent( "unittest", next(touch_id), { "x": ti.center_x / float(win.width), "y": ti.center_y / float(win.height), }) touch.profile.append('button') touch.button = 'scrollup' EventLoop.post_dispatch_input("begin", touch) EventLoop.post_dispatch_input("end", touch) self.advance_frames(1) assert ti._visible_lines_range == (20, 30) # jump to the first line again ti.do_cursor_movement('cursor_home', control=True) # temp fix: only change of cursor position triggers update as for now ti._trigger_update_graphics() self.advance_frames(1) assert ti._visible_lines_range == (0, 10) # scrolling up should work now touch = UTMotionEvent( "unittest", next(touch_id), { "x": ti.center_x / float(win.width), "y": ti.center_y / float(win.height), }) touch.profile.append('button') touch.button = 'scrollup' EventLoop.post_dispatch_input("begin", touch) EventLoop.post_dispatch_input("end", touch) self.advance_frames(1) assert ti._visible_lines_range == (1, 11)
def test_vertical_scroll_doesnt_depend_on_lines_rendering(self): # TextInput.on_touch_down was checking the possibility to scroll_up # using the positions of the rendered lines' rects. These positions # don't change when the lines are skipped (e.g. during fast scroll # or ctrl+cursor_home) which lead to scroll freeze ti = self.make_scrollable_text_input() # move viewport to the first line ti.do_cursor_movement('cursor_home', control=True) self.advance_frames(1) assert ti._visible_lines_range == (0, 10) from kivy.base import EventLoop win = EventLoop.window # slowly scroll to the last line to render all lines at least once for _ in range(30): # little overscroll is important for detection touch = UTMotionEvent("unittest", next(touch_id), { "x": ti.center_x / float(win.width), "y": ti.center_y / float(win.height), }) touch.profile.append('button') touch.button = 'scrollup' EventLoop.post_dispatch_input("begin", touch) EventLoop.post_dispatch_input("end", touch) self.advance_frames(1) assert ti._visible_lines_range == (20, 30) # jump to the first line again ti.do_cursor_movement('cursor_home', control=True) # temp fix: only change of cursor position triggers update as for now ti._trigger_update_graphics() self.advance_frames(1) assert ti._visible_lines_range == (0, 10) # scrolling up should work now touch = UTMotionEvent("unittest", next(touch_id), { "x": ti.center_x / float(win.width), "y": ti.center_y / float(win.height), }) touch.profile.append('button') touch.button = 'scrollup' EventLoop.post_dispatch_input("begin", touch) EventLoop.post_dispatch_input("end", touch) self.advance_frames(1) assert ti._visible_lines_range == (1, 11)
def test_scroll_doesnt_move_cursor(self): ti = self.make_scrollable_text_input() from kivy.base import EventLoop win = EventLoop.window touch = UTMotionEvent("unittest", next(touch_id), { "x": ti.center_x / float(win.width), "y": ti.center_y / float(win.height), }) touch.profile.append('button') touch.button = 'scrolldown' prev_cursor = ti.cursor assert ti._visible_lines_range == (20, 30) EventLoop.post_dispatch_input("begin", touch) EventLoop.post_dispatch_input("end", touch) self.advance_frames(1) assert ti._visible_lines_range == (19, 29) assert ti.cursor == prev_cursor
def test_scroll_doesnt_move_cursor(self): ti = self.make_scrollable_text_input() from kivy.base import EventLoop win = EventLoop.window touch = UTMotionEvent("unittest", next(touch_id), { "x": ti.center_x / float(win.width), "y": ti.center_y / float(win.height), }) touch.profile.append('button') touch.button = 'scrolldown' prev_cursor = ti.cursor assert ti._visible_lines_range == (20, 30) EventLoop.post_dispatch_input("begin", touch) EventLoop.post_dispatch_input("end", touch) self.advance_frames(1) assert ti._visible_lines_range == (19, 29) assert ti.cursor == prev_cursor