diff cagou/plugins/plugin_wid_chat.kv @ 325:5868a5575e01

chat: cleaning + some improvments: - code cleaning, removed some dead code - some improvments on the way size is calculated, removed unnecessary sizing methods which were linked to properties - image have now a max size, this avoid gigantic image in the whole screen - in SimpleXHTMLWidget, Label are now splitted when xhtml is set - use a DelayedBoxLayout for messages, as they are really slow to be resized - use of RecycleView has been investigated, but it is not currently usable as dynamic contents are not propertly handled (see https://github.com/kivy/kivy/issues/6580 and https://github.com/kivy/kivy/issues/6582). Furthermore, some tests with RecycleView on Android don't give the expected speed boost, so BoxLayout still seems like the way to go for the moment. To be re-investigated at a later point if necessary.
author Goffi <goffi@goffi.org>
date Fri, 06 Dec 2019 13:25:31 +0100
parents e2b51663d8b8
children d9d2b56f46db
line wrap: on
line diff
--- a/cagou/plugins/plugin_wid_chat.kv	Fri Dec 06 13:23:03 2019 +0100
+++ b/cagou/plugins/plugin_wid_chat.kv	Fri Dec 06 13:25:31 2019 +0100
@@ -14,10 +14,11 @@
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-#:import SimpleXHTMLWidget cagou.core.simple_xhtml.SimpleXHTMLWidget
 #:import _ sat.core.i18n._
 #:import C cagou.core.constants.Const
 #:import escape kivy.utils.escape_markup
+#:import SimpleXHTMLWidget cagou.core.simple_xhtml.SimpleXHTMLWidget
+#:import DelayedBoxLayout cagou.core.common_widgets.DelayedBoxLayout
 
 
 <MessAvatar>:
@@ -31,46 +32,38 @@
             pos: self.pos
             size: self.size
 
-<MessagesWidget>:
-    cols: 1
-    padding: dp(10)
-    spacing: dp(5)
-    size_hint: 1, None
-    height: self.minimum_height
-    canvas.before:
-        Color:
-            rgba: 1, 1, 1, 1
-        Rectangle:
-            pos: self.pos
-            size: self.size
 
 <MessageWidget>:
     size_hint: 1, None
-    height: right_part.minimum_height
-    on_width: self.widthAdjust()
     avatar: avatar
     delivery: delivery
     mess_xhtml: mess_xhtml
+    right_part: right_part
+    header_box: header_box
+    height: self.minimum_height
     BoxLayout:
         orientation: 'vertical'
         width: avatar.width
         size_hint: None, 1
         MessAvatar:
             id: avatar
+            source: (root.mess_data.avatar or '') if root.mess_data else ''
         Widget:
             # use to push the avatar on the top
             size_hint: 1, 1
     BoxLayout:
+        size_hint: 1, None
         orientation: 'vertical'
         id: right_part
+        height: header_box.height + mess_xhtml.height
         BoxLayout:
             id: header_box
             size_hint: 1, None
-            height: time_label.height if root.mess_data.type != C.MESS_TYPE_INFO else 0
-            opacity: 1 if root.mess_data.type != C.MESS_TYPE_INFO else 0
+            height: time_label.height if root.mess_type != C.MESS_TYPE_INFO else 0
+            opacity: 1 if root.mess_type != C.MESS_TYPE_INFO else 0
             Label:
                 id: time_label
-                color: (0, 0, 0, 1) if root.mess_data.own_mess else (0.55,0.55,0.55,1)
+                color: (0, 0, 0, 1) if root.own_mess else (0.55,0.55,0.55,1)
                 font_size: root.font_size
                 text_size: None, None
                 size_hint: None, None
@@ -78,7 +71,7 @@
                 padding: dp(5), 0
                 markup: True
                 valign: 'middle'
-                text: u"[b]{}[/b], {}".format(escape(root.mess_data.nick), root.mess_data.time_text)
+                text: u"[b]{}[/b], {}".format(escape(root.nick), root.time_text)
             Label:
                 id: delivery
                 color: C.COLOR_BTN_LIGHT
@@ -97,20 +90,26 @@
             size_hint: 1, None
             height: self.minimum_height
             xhtml: root.message_xhtml or self.escape(root.message or u' ')
-            color: (0.74,0.74,0.24,1) if root.mess_data.type == "info" else (0, 0, 0, 1)
+            color: (0.74,0.74,0.24,1) if root.mess_type == "info" else (0, 0, 0, 1)
             padding: root.mess_padding
-            bold: True if root.mess_data.type == "info" else False
+            bold: True if root.mess_type == "info" else False
+
 
 <Chat>:
+    message_input: message_input
     messages_widget: messages_widget
-    message_input: message_input
     ScrollView:
         scroll_y: 0
         do_scroll_x: False
         scroll_type: ['bars', 'content']
         bar_width: dp(6)
-        MessagesWidget:
+        DelayedBoxLayout:
             id: messages_widget
+            size_hint_y: None
+            padding: [app.MARGIN_LEFT, 0, app.MARGIN_RIGHT, dp(10)]
+            spacing: dp(10)
+            height: self.minimum_height
+            orientation: 'vertical'
     MessageInputBox:
         size_hint: 1, None
         height: self.minimum_height