Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

kivy ScrollView implementation in TextInput

Tags:

kivy

I have a function (shown below) where I'm using a popup and TextInput to display some text and in most cases the text content is larger than the popup window and hence the need for scrolling. Without ScrollView I need to rely on keyboard arrow keys for scrolling and I tried implementing ScrollView so that I can scroll using the mouse wheel. But the problem is it doesn't seem to work, any ideas as to why that is?

def dispPopup(display_text):                                                                     
    root = ScrollView(size_hint=(0.8, 0.5))
    root.add_widget(TextInput(text= display_text, , size_hint=(0.8, 0.5)))
    popup = Popup(title='Search Result',
            content= root, size_hint=(0.8, 1), pos_hint={'right': 1}) 
    popup.open()

Thanks

like image 375
Crust3 Avatar asked Jan 02 '13 05:01

Crust3


1 Answers

ScrollView will only scroll if there is something to scroll.

You are adding a Textinput to the ScrollView but setting the size_hint of the Textinput to .8, .5(80% width and 50% height of it's parent i.e the ScrollView). So there is nothing to scroll.

To scroll vertically, You should set the width of the TextInput to the width of it's parent ScrollView and the height should be set to whichever is greater, the height of the ScrollView or the no of lines * line_height.

in kv ::

ScrollView:
    id: scrlv
    TextInput:
        text: disp_text
        size_hint: 1, None
        height: max( (len(self._lines)+1) * self.line_height, scrlv.height)

The TextInput will dynamically grow vertically depending on the number of lines in it or scrollview height or font size/style which changes the line_height.

Update ::

Starting 1.8.0 you can simply do ::

height: max(self.minimum_height, scrlv.height)
like image 184
qua-non Avatar answered Nov 19 '22 09:11

qua-non