Auto-expanding a MultilineTextEdit

Skip to first unread message

Joe Betz

Feb 22, 2022, 4:51:16 PM2/22/22
How do you configure a MultilineTextEdit to increase in height whenever text wraps to a new line or a newline gets added (i.e., by pressing enter)?

Context: The MultilineTextEdit is inside a ContainerView using ProportionalLayout with arrangement set to 0. I tried enabling `usePreferredExtent`, recalculating the extent with every key typed, and then updating it using `preferredExtent:`, but the edit field remains the same size.

I have a strong feeling that it's an issue with the layouts but I can't figure out a better way to arrange things to get the behavior I want.

Joe Betz

Feb 26, 2022, 2:13:15 AM2/26/22
<sigh> There was an extra ContainerView that was screwing things up, inbetween the input field and the view where the layout was correctly defined. Got rid of that and `preferredExtent:` is now working as expected.

onKeyTyped: aKeyEvent on: aTextInput
| newExtent |
newExtent := aTextInput calculateExtent: (LayoutContext forContainer: self).
(newExtent y < 250) ifTrue: [ aTextInput preferredExtent: newExtent ]
Reply all
Reply to author
0 new messages