diff cagou/core/common_widgets.py @ 436:036ff0ed7474

common widgets (ImagesGallery): reset image transformation on slide change or double tap.
author Goffi <goffi@goffi.org>
date Sun, 01 Mar 2020 22:11:25 +0100
parents 027fad764864
children 3c9ba4a694ef
line wrap: on
line diff
--- a/cagou/core/common_widgets.py	Sun Mar 01 22:11:25 2020 +0100
+++ b/cagou/core/common_widgets.py	Sun Mar 01 22:11:25 2020 +0100
@@ -1,6 +1,5 @@
 #!/usr/bin/env python3
 
-
 # Cagou: desktop/mobile frontend for Salut à Toi XMPP client
 # Copyright (C) 2016-2020 Jérôme Poisson (goffi@goffi.org)
 
@@ -133,14 +132,29 @@
 class ImageViewer(ScatterLayout):
     source = properties.StringProperty()
 
+    def on_touch_down(self, touch):
+        if touch.is_double_tap:
+            self.reset()
+            return True
+        return super().on_touch_down(touch)
+
+    def reset(self):
+        self.rotation = 0
+        self.scale = 1
+        self.x = 0
+        self.y = 0
+
 
 class ImagesGallery(BoxLayout):
     """Show list of images in a Carousel, with some controls to downloads"""
     sources = properties.ListProperty()
     carousel = properties.ObjectProperty()
+    previous_slide = None
 
     def on_kv_post(self, __):
         self.on_sources(None, self.sources)
+        self.previous_slide = self.carousel.current_slide
+        self.carousel.bind(current_slide=self.on_slide_change)
 
     def on_parent(self, __, parent):
         # we hide the head widget to have full screen
@@ -156,6 +170,12 @@
             )
             self.carousel.add_widget(img)
 
+    def on_slide_change(self, __, slide):
+        if isinstance(self.previous_slide, ImageViewer):
+            self.previous_slide.reset()
+
+        self.previous_slide = slide
+
     def key_input(self, window, key, scancode, codepoint, modifier):
         if key == 27:
             G.host.closeUI()