Created
July 6, 2015 18:48
Kivy: layout size from child
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kivy | |
kivy.require('1.9.0') | |
from kivy.app import App | |
from kivy.lang import Builder | |
root = Builder.load_string(''' | |
<Message@BoxLayout>: | |
name: '' | |
message: '' | |
size_hint_y: None | |
height: max(lbl_name.height, lbl_message.height) | |
Label: | |
id: lbl_name | |
pos_hint: {'top': 1} | |
size_hint_y: None | |
size_hint_x: 0.5 | |
text: root.name | |
height: self.texture_size[1] | |
Label: | |
id: lbl_message | |
pos_hint: {'top': 1} | |
size_hint_y: None | |
text_size: self.width, None | |
text: root.message | |
height: self.texture_size[1] | |
ScrollView: | |
GridLayout: | |
cols: 1 | |
size_hint_y: None | |
height: self.minimum_height | |
Message: | |
name: 'user 1' | |
message: 'hello there' | |
Message: | |
name: 'user 2' | |
message: 'why hello!' | |
Message: | |
name: 'user 1' | |
message: 'i want to test a long message, so that it will wrap to multiple lines and extend the size of the box' | |
Message: | |
name: 'user 2' | |
message: '' | |
Message: | |
name: 'user 2' | |
message: 'that was a blank message' | |
Message: | |
name: 'user 1' | |
message: 'ok!' | |
''') | |
class TestApp(App): | |
def build(self): | |
return root | |
if __name__ == '__main__': | |
TestApp().run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment