changeset 324:4374cb741eb5

core (common widgets): added a DelayedBoxLayout class: DelayedBoxLayout delay the sizing, this is useful when sizing is complex and resource consuming. Thanks to https://blog.kivy.org/2019/07/a-delayed-resize-layout-in-kivy/
author Goffi <goffi@goffi.org>
date Fri, 06 Dec 2019 13:23:03 +0100
parents 5bd583d00594
children 5868a5575e01
files cagou/core/common_widgets.py
diffstat 1 files changed, 18 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/cagou/core/common_widgets.py	Fri Dec 06 13:23:03 2019 +0100
+++ b/cagou/core/common_widgets.py	Fri Dec 06 13:23:03 2019 +0100
@@ -25,12 +25,30 @@
 from cagou.core.menu import TouchMenuItemBehaviour
 from kivy import properties
 from kivy.metrics import dp
+from kivy.clock import Clock
 from cagou import G
 from sat.core import log as logging
 
 log = logging.getLogger(__name__)
 
 
+class DelayedBoxLayout(BoxLayout):
+    """A BoxLayout with delayed layout, to avoid slowing down during resize"""
+    # XXX: thanks to Alexander Taylor for his blog post at
+    #      https://blog.kivy.org/2019/07/a-delayed-resize-layout-in-kivy/
+
+    do_layout_event = properties.ObjectProperty(None, allownone=True)
+    layout_delay_s = properties.NumericProperty(0.2)
+
+    def do_layout(self, *args, **kwargs):
+        if self.do_layout_event is not None:
+            self.do_layout_event.cancel()
+        real_do_layout = super().do_layout
+        self.do_layout_event = Clock.schedule_once(
+            lambda dt: real_do_layout(*args, **kwargs),
+            self.layout_delay_s)
+
+
 class Identities(object):
 
     def __init__(self, entity_ids):