# HG changeset patch # User Goffi # Date 1470773160 -7200 # Node ID bc15b55a4114ffbdc39cab0e8d8905785b1b3c99 # Parent f9869f34f629ab94c3d5bcadfb91eed736a52ff0 chat: better bubble and time resizing diff -r f9869f34f629 -r bc15b55a4114 src/cagou/plugins/plugin_wid_chat.kv --- a/src/cagou/plugins/plugin_wid_chat.kv Mon Aug 08 21:05:29 2016 +0200 +++ b/src/cagou/plugins/plugin_wid_chat.kv Tue Aug 09 22:06:00 2016 +0200 @@ -24,28 +24,22 @@ hint_text: "Enter your message here" : - mess_label: mess_label - size_hint: None,None - pos_hint: {'x': 0} if root.mess_data.own_mess else {'right': 1} - height: mess_label.height + time_label.height - width: mess_label.width + size_hint: 1, None + height: time_label.height + mess_label.height on_height: if root.parent: root.parent.sizeAdjust() + on_width: self.sizeAdjust() Label: id: time_label - size_hint: None, None + text_size: None, None + size_hint: 1, None height: self.texture_size[1] - width: root.parent.width if root.parent else 100 text: root.mess_data.time_text halign: "center" BoxLayout: - canvas.before: - Color: - rgba: 1, 1, 1, 1 - BorderImage: - source: "cagou/images/border_{}.jpg".format("blue" if root.mess_data.own_mess else "gray") - pos: self.pos - size: self.size + size_hint: None,None + size: mess_label.size + pos_hint: {'x': 0} if root.mess_data.own_mess else {'right': 1} # Label: # id: nick_label @@ -63,13 +57,18 @@ # # size_hint: None, 1 # # valign: "top" Label: + canvas.before: + Color: + rgba: 1, 1, 1, 1 + BorderImage: + source: "cagou/images/border_{}.jpg".format("blue" if root.mess_data.own_mess else "gray") + pos: self.pos + size: self.size id: mess_label color: 0, 0, 0, 1 padding: 5, 5 text_size: None, None size_hint: None, None size: self.texture_size - # text: 'root:{} nick:{} self:{}'.format(root.height, nick_label.height, self.height) text: root.message or u' ' - # haligh: "left" - on_texture_size: root.adjustMax(self.texture_size) + on_texture_size: root.sizeAdjust() diff -r f9869f34f629 -r bc15b55a4114 src/cagou/plugins/plugin_wid_chat.py --- a/src/cagou/plugins/plugin_wid_chat.py Mon Aug 08 21:05:29 2016 +0200 +++ b/src/cagou/plugins/plugin_wid_chat.py Tue Aug 09 22:06:00 2016 +0200 @@ -52,11 +52,17 @@ """Return currently displayed message""" return self.mess_data.main_message - def adjustMax(self, texture_size): + def sizeAdjust(self): """this widget grows up with its children""" - width, height = texture_size - if width > self.parent.width: + text_width, text_height = self.mess_label.texture_size + if text_width > self.parent.width: self.mess_label.text_size = (self.parent.width - 10, None) + self.text_max = text_width + elif self.mess_label.text_size[0] is not None and text_width < self.parent.width - 10: + if text_width > self.text_max: + self.mess_label.text_size = (None, None) + else: + self.mess_label.text_size = (self.parent.width - 10, None) class MessageInputWidget(TextInput):