comparison 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
comparison
equal deleted inserted replaced
324:4374cb741eb5 325:5868a5575e01
12 # GNU Affero General Public License for more details. 12 # GNU Affero General Public License for more details.
13 13
14 # You should have received a copy of the GNU Affero General Public License 14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>. 15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 16
17 #:import SimpleXHTMLWidget cagou.core.simple_xhtml.SimpleXHTMLWidget
18 #:import _ sat.core.i18n._ 17 #:import _ sat.core.i18n._
19 #:import C cagou.core.constants.Const 18 #:import C cagou.core.constants.Const
20 #:import escape kivy.utils.escape_markup 19 #:import escape kivy.utils.escape_markup
20 #:import SimpleXHTMLWidget cagou.core.simple_xhtml.SimpleXHTMLWidget
21 #:import DelayedBoxLayout cagou.core.common_widgets.DelayedBoxLayout
21 22
22 23
23 <MessAvatar>: 24 <MessAvatar>:
24 size_hint: None, None 25 size_hint: None, None
25 size: dp(30), dp(30) 26 size: dp(30), dp(30)
29 RoundedRectangle: 30 RoundedRectangle:
30 radius: [dp(5)] 31 radius: [dp(5)]
31 pos: self.pos 32 pos: self.pos
32 size: self.size 33 size: self.size
33 34
34 <MessagesWidget>:
35 cols: 1
36 padding: dp(10)
37 spacing: dp(5)
38 size_hint: 1, None
39 height: self.minimum_height
40 canvas.before:
41 Color:
42 rgba: 1, 1, 1, 1
43 Rectangle:
44 pos: self.pos
45 size: self.size
46 35
47 <MessageWidget>: 36 <MessageWidget>:
48 size_hint: 1, None 37 size_hint: 1, None
49 height: right_part.minimum_height
50 on_width: self.widthAdjust()
51 avatar: avatar 38 avatar: avatar
52 delivery: delivery 39 delivery: delivery
53 mess_xhtml: mess_xhtml 40 mess_xhtml: mess_xhtml
41 right_part: right_part
42 header_box: header_box
43 height: self.minimum_height
54 BoxLayout: 44 BoxLayout:
55 orientation: 'vertical' 45 orientation: 'vertical'
56 width: avatar.width 46 width: avatar.width
57 size_hint: None, 1 47 size_hint: None, 1
58 MessAvatar: 48 MessAvatar:
59 id: avatar 49 id: avatar
50 source: (root.mess_data.avatar or '') if root.mess_data else ''
60 Widget: 51 Widget:
61 # use to push the avatar on the top 52 # use to push the avatar on the top
62 size_hint: 1, 1 53 size_hint: 1, 1
63 BoxLayout: 54 BoxLayout:
55 size_hint: 1, None
64 orientation: 'vertical' 56 orientation: 'vertical'
65 id: right_part 57 id: right_part
58 height: header_box.height + mess_xhtml.height
66 BoxLayout: 59 BoxLayout:
67 id: header_box 60 id: header_box
68 size_hint: 1, None 61 size_hint: 1, None
69 height: time_label.height if root.mess_data.type != C.MESS_TYPE_INFO else 0 62 height: time_label.height if root.mess_type != C.MESS_TYPE_INFO else 0
70 opacity: 1 if root.mess_data.type != C.MESS_TYPE_INFO else 0 63 opacity: 1 if root.mess_type != C.MESS_TYPE_INFO else 0
71 Label: 64 Label:
72 id: time_label 65 id: time_label
73 color: (0, 0, 0, 1) if root.mess_data.own_mess else (0.55,0.55,0.55,1) 66 color: (0, 0, 0, 1) if root.own_mess else (0.55,0.55,0.55,1)
74 font_size: root.font_size 67 font_size: root.font_size
75 text_size: None, None 68 text_size: None, None
76 size_hint: None, None 69 size_hint: None, None
77 size: self.texture_size 70 size: self.texture_size
78 padding: dp(5), 0 71 padding: dp(5), 0
79 markup: True 72 markup: True
80 valign: 'middle' 73 valign: 'middle'
81 text: u"[b]{}[/b], {}".format(escape(root.mess_data.nick), root.mess_data.time_text) 74 text: u"[b]{}[/b], {}".format(escape(root.nick), root.time_text)
82 Label: 75 Label:
83 id: delivery 76 id: delivery
84 color: C.COLOR_BTN_LIGHT 77 color: C.COLOR_BTN_LIGHT
85 font_size: root.font_size 78 font_size: root.font_size
86 text_size: None, None 79 text_size: None, None
95 SimpleXHTMLWidget: 88 SimpleXHTMLWidget:
96 id: mess_xhtml 89 id: mess_xhtml
97 size_hint: 1, None 90 size_hint: 1, None
98 height: self.minimum_height 91 height: self.minimum_height
99 xhtml: root.message_xhtml or self.escape(root.message or u' ') 92 xhtml: root.message_xhtml or self.escape(root.message or u' ')
100 color: (0.74,0.74,0.24,1) if root.mess_data.type == "info" else (0, 0, 0, 1) 93 color: (0.74,0.74,0.24,1) if root.mess_type == "info" else (0, 0, 0, 1)
101 padding: root.mess_padding 94 padding: root.mess_padding
102 bold: True if root.mess_data.type == "info" else False 95 bold: True if root.mess_type == "info" else False
96
103 97
104 <Chat>: 98 <Chat>:
99 message_input: message_input
105 messages_widget: messages_widget 100 messages_widget: messages_widget
106 message_input: message_input
107 ScrollView: 101 ScrollView:
108 scroll_y: 0 102 scroll_y: 0
109 do_scroll_x: False 103 do_scroll_x: False
110 scroll_type: ['bars', 'content'] 104 scroll_type: ['bars', 'content']
111 bar_width: dp(6) 105 bar_width: dp(6)
112 MessagesWidget: 106 DelayedBoxLayout:
113 id: messages_widget 107 id: messages_widget
108 size_hint_y: None
109 padding: [app.MARGIN_LEFT, 0, app.MARGIN_RIGHT, dp(10)]
110 spacing: dp(10)
111 height: self.minimum_height
112 orientation: 'vertical'
114 MessageInputBox: 113 MessageInputBox:
115 size_hint: 1, None 114 size_hint: 1, None
116 height: self.minimum_height 115 height: self.minimum_height
117 spacing: dp(10) 116 spacing: dp(10)
118 padding: [app.MARGIN_LEFT, 0, app.MARGIN_RIGHT, dp(10)] 117 padding: [app.MARGIN_LEFT, 0, app.MARGIN_RIGHT, dp(10)]