diff --git a/examples/widgets/carousel_buttons.py b/examples/widgets/carousel_buttons.py index fbfb1c600..8006feffa 100644 --- a/examples/widgets/carousel_buttons.py +++ b/examples/widgets/carousel_buttons.py @@ -19,8 +19,14 @@ Builder.load_string(''' Button Button Button + text: 'prev' + on_release: + root.parent.parent.load_previous() Button Button + text: 'next' + on_release: + root.parent.parent.load_next() ''') class Page(GridLayout): diff --git a/kivy/uix/carousel.py b/kivy/uix/carousel.py index 37a562beb..005239651 100644 --- a/kivy/uix/carousel.py +++ b/kivy/uix/carousel.py @@ -235,6 +235,30 @@ class Carousel(StencilView): self._position_visible_slides, -1) 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 next 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): return slide.parent