I've found a bug with the cursor not being set properly vs the display on start up - in my example below, after adding the lines to the TextInput
the cursor reads as (0, 100)
even though the top of the text is actually displayed. This causes the Bottom button to do nothing - until you click in the TextInput
(changing the cursor pos) or hit the Top button.
To see what I mean, just comment out Clock.schedule_once(lambda _: setattr(root.ids['ti'], 'cursor', (0, 0)))
.
I've tested this code as working with Kivy 1.8.1-dev (git: 1149da6bf26ff5f27536222b4ba6a874456cde6e) on Ubuntu 14.04:
import kivy
kivy.require('1.8.1')
from kivy.app import App
from kivy.lang import Builder
from kivy.clock import Clock
root = Builder.load_string('''
BoxLayout:
orientation: 'vertical'
BoxLayout:
TextInput:
id: ti
Label:
size_hint_x: None
width: sp(80)
text: str(ti.cursor)
BoxLayout:
size_hint_y: None
height: sp(128)
Widget
Button:
text: 'Top'
on_press: ti.cursor = (0, 0)
Button:
text: 'Bottom'
on_press: ti.cursor = (0, len(ti._lines) - 1)
Widget
''')
class TestApp(App):
def build(self):
text = ''
for i in xrange(100):
text += 'Line %d\n' % (i + 1,)
root.ids['ti'].text = text
# fix the cursor pos
Clock.schedule_once(lambda _: setattr(root.ids['ti'], 'cursor', (0, 0)))
return root
if __name__ == '__main__':
TestApp().run()