mirror of https://github.com/kivy/kivy.git
uix:Carousel add `load_next` and `load_prev` methods for animating to
next slide and previous slides closes #896
This commit is contained in:
parent
f6ba55b1a8
commit
3d284099a5
|
@ -19,8 +19,14 @@ Builder.load_string('''
|
||||||
Button
|
Button
|
||||||
Button
|
Button
|
||||||
Button
|
Button
|
||||||
|
text: 'prev'
|
||||||
|
on_release:
|
||||||
|
root.parent.parent.load_previous()
|
||||||
Button
|
Button
|
||||||
Button
|
Button
|
||||||
|
text: 'next'
|
||||||
|
on_release:
|
||||||
|
root.parent.parent.load_next()
|
||||||
''')
|
''')
|
||||||
|
|
||||||
class Page(GridLayout):
|
class Page(GridLayout):
|
||||||
|
|
|
@ -235,6 +235,30 @@ class Carousel(StencilView):
|
||||||
self._position_visible_slides, -1)
|
self._position_visible_slides, -1)
|
||||||
super(Carousel, self).__init__(**kwargs)
|
super(Carousel, self).__init__(**kwargs)
|
||||||
|
|
||||||
|
def load_previous(self):
|
||||||
|
'''Animate previous slide in.
|
||||||
|
|
||||||
|
.. versionadded:: 1.7.0
|
||||||
|
'''
|
||||||
|
self.load_next(mode='prev')
|
||||||
|
|
||||||
|
def load_next(self, mode='next'):
|
||||||
|
'''Animate previous slide in.
|
||||||
|
|
||||||
|
.. versionadded:: 1.7.0
|
||||||
|
'''
|
||||||
|
h, w = self.size
|
||||||
|
_direction = {
|
||||||
|
'top': -h / 2,
|
||||||
|
'bottom': h / 2,
|
||||||
|
'left': w / 2,
|
||||||
|
'right': -w / 2}
|
||||||
|
_offset = _direction[self.direction]
|
||||||
|
if mode == 'prev':
|
||||||
|
_offset = -_offset
|
||||||
|
self._offset = _offset
|
||||||
|
self._start_animation()
|
||||||
|
|
||||||
def get_slide_container(self, slide):
|
def get_slide_container(self, slide):
|
||||||
return slide.parent
|
return slide.parent
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue