dynamic Popup size with multiline Label

30 views
Skip to first unread message

Mike

unread,
Oct 11, 2016, 9:19:10 AM10/11/16
to Kivy users support
Simple Question, but I do not find a simple solution.

Problem: A modal message box which has a multiline label and some buttons. The box shall have a height according to the number of text lines within the label.

My only solution up to now is to split the text into single lines and add a Label fo each programmatically. Then I am able to compute the size of all Popup content and setting Popup size.

All other attempts failed. I am not able to get the Label height in multiline case since Label height does not seem a simple multiplication with font_size or font_size + offset (tried with float computation, not pixels). Binding a function to label size / height and correcting Popup size ends in endless loop (expected). Popup Gridlayout minimum_height does not do it. A forward label ref to get the height in kv neither. Waiting for label height settled ... but what is the condition ... I can log up 2..5 iterations.

What is missing? Or I do not see the wood for the trees ...


ZenCODE

unread,
Oct 13, 2016, 11:23:07 AM10/13/16
to Kivy users support
Can you post what you have? Or a minimal example? You should be able to use the 'on_texture' event on the label and then set the size_hint_y property of the popup accordingly, something like

popup.size_hint = (0.7, (texture.height + 50 ) / Window.height)


Mike

unread,
Oct 20, 2016, 5:43:46 AM10/20/16
to Kivy users support
Thank you for your hint. Now it works:


kv Label:

# size_hint_y: None
# was: not commented

text_size: self.size[0],None
# was: text_size: self.size


Code:

<Label instance>.bind(texture_size=self.on_texture_size)

def on_texture_size(self,instance,texture_size):
  <Popup instance>.height = ... + texture_size[1] + ...
Reply all
Reply to author
Forward
0 new messages