Auto-expanding a MultilineTextEdit

23 views
Skip to first unread message

Joe Betz

unread,
Feb 22, 2022, 4:51:16 PMFeb 22
to
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

unread,
Feb 26, 2022, 2:13:15 AMFeb 26
to
<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
Forward
0 new messages