Kivy TextInput: long text overflows textinputs border

139 views
Skip to first unread message

Giù sé

unread,
Jun 17, 2020, 9:42:37 AM6/17/20
to Kivy users support
I noticed that with single line textinputs (multiline: False) long texts will overflow and the last letter typed in will not be visible. I see the issue has also been raised on stackoverflow (here) and it seems to be a Kivy bug. Has this been solved by any chance (or has a bug report been opened at all)?

To me, it seems to be an issue of the cursor. When the text overflows, if I press the right arrow (i.e. move the cursor right) I am then able to read the whole text. So the text does fit into the textinput, it is the cursor that seems to misbehave.

Here a minimal code to reproduce the issue:

from kivy.app import App
from kivy.core.window import Window
from kivy.lang import Builder
from kivy.uix.gridlayout import GridLayout
from kivy.uix.screenmanager import Screen, ScreenManager



class MainGrid(GridLayout):
    pass

kv = Builder.load_string(
'''
MainGrid:

<MainGrid>:
    size_hint: 1, 1
    StackLayout:
        size_hint: 1,1
        TextInput:
            size_hint: 1, 1
            multiline: False
''')

class TrialApp(App):
    def build(self):
        return kv

if __name__ == "__main__":
    TrialApp().run()




Elliot Garbus

unread,
Jun 17, 2020, 5:29:03 PM6/17/20
to kivy-...@googlegroups.com

You can report this bug here: https://github.com/kivy/kivy/issues

 

Here are some possible work arounds:

  • Using horizontal padding keeps the cursor in the box, but the behavior of the last character is strange.
  • Avoid the problem by limiting the number of characters

 

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.textinput import TextInput
from kivy.properties import NumericProperty

kv =
"""
BoxLayout
    orientation: 'vertical'
    padding: 20
    Label:
        text: 'TextInput Test'
        font_size: 40
    BoxLayout:
        size_hint_y: None
        height: 48
        Label:
            text: 'No Padding'
        TextInput:
            size_hint: .8, None
            pos_hint: {'center_x': .5}
            height: '48'
            font_size: 20
            multiline: False
    BoxLayout:
        size_hint_y: None
        height: 48
        Label:
            text: 'Padding'
        TextInput:
            size_hint: .8, None
            pos_hint: {'center_x': .5}
            height: '48'
            font_size: 20
            multiline: False
            padding: 20, 10
    BoxLayout:
        size_hint_y: None
        height: 48
        Label:
            text: 'Use a filter to limit characters'
        CharLimitTextInput:
            size_hint: .8, None
            pos_hint: {'center_x': .5}
            height: '48'
            font_size: 20
            multiline: False
            max_characters: 10
            input_filter: self.char_limit
    Label:     
"""


class CharLimitTextInput(TextInput):
    max_characters = NumericProperty(
'20')

   
def char_limit(self, substring, undo):
       
if len(substring) + len(self.text) <= self.max_characters:
           
return substring
       
if len(substring) + len(self.text) > self.max_characters:
            c =
int(self.max_characters - len(self.text))
           
return substring[0:c]

class TrialApp(App):
   
def build(self):
       
return Builder.load_string(kv)

TrialApp().run()

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/50e25be9-3de6-44e3-bf48-12f6c0cb16a5o%40googlegroups.com.

 

Reply all
Reply to author
Forward
0 new messages