[Newbies] Expand TextMorph to encompass entire string?

Ron Teitelbaum ron at usmedrec.com
Tue Sep 6 00:06:50 UTC 2016

From: John-Reed Maffeo
Sent: Monday, September 5, 2016 3:49 PM


Total Morphic newbie here - I am trying to build a simple app with two panes (BorderedRectangles), each pane contains a column of rows. Each row contains a String for a label and a TextMorph to contain data that I want to display and possibly edit.


Some of the TextMorphs contain long strings which cause the parent pane to expand out past the boundaries of the SystemWindow which contains it. I can't figure out how to limit the width of the row and let the height of the TextMorph vary based on the size of its contents.


Any suggestions?

[Ron Teitelbaum] Hi John-Reed, 


There are a number of method available to you on TextMorph.  Browse TextMorph and press the instVars button.  Select wrapFlag to see Accesses to that.  In general the TextMorph has methods that should update the text to wrap the contents when you update or add text.  You can also probably wrap the text manually (calling the wrap method yourself) as you add it depending on the width of the string you are adding.  Also look for how to set the height of the row, and set that based on the results of the number of lines returned from the wrapping times the font height + some bounds between lines.  It may do that already in some cases (not reading the code so not sure).  In general you need some sort of compose method that looks for all the variables.  The length of the string, the width of the column, the font size, and it should trim the strings based on width to rows (possibly in something like a paragraph), and set the height of the row to accommodate the string, and possibly add a scroll bar if it doesn’t fit.  (remember to add the width of the scroll bar in your compose method).  That method needs to be called whenever something changes, like when the component is resized or new text is added or removed.


I would think that there is already a method that does all this so start with the wrap flag method and see how others are doing the same thing.


Not sure if that is much help but you never know!


All the best,


Ron Teitelbaum  



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/beginners/attachments/20160905/d67231cd/attachment.htm

More information about the Beginners mailing list