Forum Archive

content_inset for TextView

mikael

TextView seems to inherit or proxy content_inset from ScrollView, but it does not work for me. Something like the correct inset is briefly flashed, then the view moves to default insets.

I am running 1.6 beta on 6s Plus with 9.2. Here's my test case:

#coding: utf-8
import ui

init_text = '''
Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum

Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum
'''

tv = ui.TextView()
tv.text = init_text
tv.content_inset = (30, 50, 30, 15)
tv.present()
#tv.content_inset = (30, 50, 30, 15)

Could someone confirm/deny this behavior?

Thanks,
Mikael

Phuket2

@mikael , I see it jumping on my ipad. But look I haven't done much work with TextView...
But if you do the following, does it help?

tv = ui.TextView(frame = (0,0,500,500))
tv.auto_content_inset = False
# then the code you had 
mikael

Thanks, you are quite right.

Turning auto_content_inset off does stop the jumping. Counterintuitive that these two settings should be related, as I am not even editing the text.

Also painful that the content insets seem to be applied outside the original frame, rather than squeezing the content in.

Phuket2

@mikael , but I am sure you saved a future issue for me 😁

JonB

Try setting the content after you set the frame. or, have your tv as a subview to another view, and turn off flex. Your frame size changes when you call present, which likely is why the inset changes, and why you are notnhappy with the current approach.