auto sizing of a textInput.

1,830 views
Skip to first unread message

ta...@swopusa.org

unread,
Feb 11, 2013, 8:34:27 PM2/11/13
to kivy-...@googlegroups.com
Hello, First, I am very new to Kivy, so perhaps I'm missing stuff, but so far I like Kivy!

I'm trying to figure out how to have a TextInput widget always show the largest possible text, for a given textInput Widget.

I found font_size, but it's a setting value only, I can't figure out how to get the current font_size.  Sorry, I'm sort of confused on how this all works with Kivy.

This is basically my algorithm:

textWidth = self._get_text_width(self.text, self.tab_width, self._label_cached)
multiplier = self.width / float(textWidth)
fontSize = fontSize * (multiplier - 0.1)

This mostly works but I have a few problems:
  * Newlines have a horrible line spacing problem, I found _line_spacing, which defaults to 0, but I notice in: _refresh_text_from_property, it is being forced to 2, for some reason. I haven't tried changing that, as I am using the compiled binary form of Kivy.

  * textWidth as calculated seems to be off, perhaps I'm calling it incorrectly?  I am using: textWidth = self._get_text_width(self.text, self.tab_width, self._label_cached)  By off, it always seems to be a lot smaller than the actual text width.

  * I can't seem to disable scrolling.

Anyways, sorry to be a bother.  Thanks for reading this far!

With Love,
Tara

Akshay Arora

unread,
Feb 12, 2013, 12:03:57 PM2/12/13
to kivy-...@googlegroups.com
Hi Tara,

    Can you elaborate a bit on what you are trying to achieve here ? I'm a bit confused by what you mean by "to have a TextInput widget always show the largest possible text, for a given textInput Widget."

Are looking for ::
a) The text to be the height TextInput Widget? Then I'd try TextInput_instance.font_size = TextInput_Instance.height - (TextInput_Instance.spacing -+TextInput_Instance.padding)
b) The TextInput expand according to the no of lines in it, then You can do ::
   
    ScrollView:
        id: scrlv
        TextInput:
            text: disp_text
            size_hint: 1, None
            height: max( (len(self._lines)+1) * self.line_height, scrlv.height)


Best Regards



--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

ta...@swopusa.org

unread,
Feb 12, 2013, 1:53:41 PM2/12/13
to kivy-...@googlegroups.com
option A, sort of.  I want all the text to fill all of the available space the widget takes up on the screen, so both width and height.  So your math is a bit simplistic, since it only takes into consideration height, but yes, that is the general idea.

Using your math, I ran into some problems:
   * .spacing doesn't exist, and .padding is a list property.

so from your example, I came up with this:
     self.card.font_size = self.card.height - (self.card._line_spacing + self.card.padding_y)

Which seems to work about as well as what I was doing before.  same problems tho:
    * Scrolling causes problems, it only shows a few characters, once you get past what the screen can display.
    * this ONLY takes into consideration the height, and I need to handle the width as well (since scrolling is a bad idea for me).

But I'm not really worried about the algorithm part, I'm worried about using all these ._ variables, and not having access to things like:
    * How to turn off Scrolling.
    * How to get the current font_size.
    * line_spacing being forced to the value 2, even when I don't want it.
    * text_width seemingly calculating incorrectly.

With Love,
Tara

Akshay Arora

unread,
Feb 12, 2013, 5:29:44 PM2/12/13
to kivy-...@googlegroups.com
I still can't comprehend what you mean by all the text cover all the area, as it could mean a lot of things.

Is the text to be displayed constant/vairable?
Is The TextInput size constant/variable?
Are you using single-line TextInput or multiline?

It would help if you could elaborate on what exactly you are trying to achieve.

Just for reference which version of Kivy are you using?


   
Best Regards.
Reply all
Reply to author
Forward
0 new messages