I'm looking for a way to give my BoxLayout ability to stretch when we resize the window with wrapped text inside, so when the wrapped text down the line, the BoxLayout containing it will stretch down with them avoiding text dissapear.
Before resizing
After resizing, the BoxLayout size still remain which cause some text lost.
Edit: My code (it's working now)
.py file
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.label import Label
from kivy.uix.button import Button
from kivy.metrics import dp
class Chat_history_update(BoxLayout):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.app = App.get_running_app()
def Chat_history_generate(self):
self.ids['label'] = Wrapped_Label(text="hello"*200,halign="right",valign="top",size_hint=(1,None))
self.ids['box'] = Wrapped_Box_Layout(pos_hint={"right":1},size_hint=(.7,None))
self.ids['box'].add_widget(self.ids['label'])
self.add_widget(self.ids['box'])
class Wrapped_Label(Button):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.app = App.get_running_app()
self.bind(
width=lambda *x: self.setter('text_size')(self, (self.app.root.ids.box.width,None)),
texture_size=lambda *x: self.setter('size')(self, (self.texture_size[0],self.texture_size[1])))
class Wrapped_Box_Layout(BoxLayout):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.app = App.get_running_app()
self.bind(
size=lambda *x: self.setter('height')(None,self.app.root.ids.label.height))
class Test(App):
pass
Test().run()
.kv file
Chat_history_update:
<Chat_history_update>:
orientation: "vertical"
Button:
text: "generate"
size_hint: None,None
size: "100dp","100dp"
pos_hint: {"top":1}
on_press: root.Chat_history_generate()