changeset 329:51520ce98154

common_widgets (DelayedBoxLayout), chat: don't delay layout on new message: DelayedBoxLayout has a new `dont_delay_next_layouts` property to skip delaying for the next X sizing. This is used in chat widget to avoid unpleasant flickering when a new message is sent or received.
author Goffi <goffi@goffi.org>
date Fri, 20 Dec 2019 12:29:37 +0100
parents dddea9684a8e
children bc977e3ff2aa
files cagou/core/common_widgets.py cagou/plugins/plugin_wid_chat.py
diffstat 2 files changed, 13 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/cagou/core/common_widgets.py	Fri Dec 20 12:29:37 2019 +0100
+++ b/cagou/core/common_widgets.py	Fri Dec 20 12:29:37 2019 +0100
@@ -39,14 +39,20 @@
 
     do_layout_event = properties.ObjectProperty(None, allownone=True)
     layout_delay_s = properties.NumericProperty(0.2)
+    #: set this to X to force next X layouts to be done without delay
+    dont_delay_next_layouts = properties.NumericProperty(0)
 
     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)
+        if self.dont_delay_next_layouts>0:
+            self.dont_delay_next_layouts-=1
+            super().do_layout()
+        else:
+            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):
--- a/cagou/plugins/plugin_wid_chat.py	Fri Dec 20 12:29:37 2019 +0100
+++ b/cagou/plugins/plugin_wid_chat.py	Fri Dec 20 12:29:37 2019 +0100
@@ -559,6 +559,9 @@
 
     def createMessage(self, message):
         self.appendMessage(message)
+        # we need to render immediatly next 2 layouts to avoid an unpleasant flickering
+        # when sending or receiving a message
+        self.messages_widget.dont_delay_next_layouts = 2
 
     def appendMessage(self, mess_data):
         """Append a message Widget to the history