I'm trying to put "layout3" inside "layout2" and put "layout2" inside "layout1", so a group of 3 layouts in total. And I'm trying to set their size relative to the "texture_size" inside "layout3" but got a bug. I solved the relative size in my previous question but it's "layout2" inside "layout1" only.
Here is the issue:
When it's supposed to be like this:
It's kind of hard to express my idea, but the idea is to create a history chatbox like Messenger and here is how I do it.
(More details: I created "BoxLayout2" with 70% screen to set text's width limit, so when the text expanse longer than that line, it will down the line.
More details for "BoxLayout3": Basically if I use halign="right", the wrapped text will start from the right when down the line. So I need it to halign="left, that why I need "BoxLayout3" to keep the text-align right while it still can start from the left when down the line.)
.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
class Chat_history_update(BoxLayout): #<< LAYOUT1
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"*50,halign="left",valign="top",size_hint=(1,None))
self.ids['box'] = Wrapped_BoxLayout(pos_hint={"right":1},size_hint=(None,None))
self.ids['box_limit'] = Wrapped_BoxLayout_limit(pos_hint={"right":1},size_hint=(.7,None))
self.ids['box_limit'].add_widget(self.ids['box'])
self.ids['box'].add_widget(self.ids['label'])
self.add_widget(self.ids['box_limit'])
class Wrapped_Label(Button): #<< WRAPPED TEXT WILL BE ADD WIDGET IN LAYOUT3
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_limit.width,None)),
texture_size=lambda *x: self.setter('size')(self, (self.texture_size[0],self.texture_size[1])))
class Wrapped_BoxLayout(BoxLayout): #<< LAYOUT3
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.app = App.get_running_app()
self.bind(
size=lambda *x: self.setter('size')(self, (self.app.root.ids.label.size)))
class Wrapped_BoxLayout_limit(BoxLayout): #<< LAYOUT2
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.app = App.get_running_app()
self.bind(
height=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>:
id: update
orientation: "vertical"
spacing: "10dp"
size_hint:1,1
Button:
text: "generate"
size_hint: None,None
size: "100dp","100dp"
pos_hint: {"top":1}
on_press: root.Chat_history_generate()
Edit: Well... since nothing works, I will have to consider my idea again. Also, if you are looking for more examples you can refer to this. If you have any answer to this question, it would be appreciated.