Squeak
  links to this page:    
View this PageEdit this PageUploads to this PageHistory of this PageTop of the SwikiRecent ChangesSearch the SwikiHelp Guide
TextMorph examples
Last updated at 10:25 pm UTC on 25 August 2017
 tMorph := TextMorph new.
 font  :=  (TextFontReference toFont:  (StrikeFont familyName: 'Atlanta' size: 22)).
 aString := 'Aa Bc Cd Dd Ee Ff'.
 aText := aString asText addAttribute: font; addAttribute: (TextColor color: Color red).
 tMorph contents: aText.
 tMorph openInHand.

The same example with a TTCFont
 tMorph := TextMorph new.
 font  :=  (TextFontReference toFont:  (TTCFont familyName: 'BitstreamVeraSans' pointSize: 24 emphasis: 0)).
 aString := 'Aa Bc Cd Dd Ee Ff'.
 aText := aString asText addAttribute: font; addAttribute: (TextColor color: Color red).
 tMorph contents: aText.
 tMorph openInHand.

The text of the TextMorph instance is editable. If you do not want it to be editable you need to lock the morph.
 tMorph lock

A example with fixed width and wrapFlag set to true.

 | t |
 t := TextMorph new contents: 'Very first line'; wrapFlag: true.
 t openInWorld.
 2 to: 20 do: [ :i | t contents: (t contents, String cr, ' line ',
  i asString) ]

aTextMorph beAllFont: aFont example
(TextMorph new 
   beAllFont: ((TextStyle default fontOfSize: 36) emphasized: 1);
   color: Color magenta;
   contents: 'Some text') openInWorld

 aTextMorph text runs  withStartStopAndValueDo:
		[:start :stop :attributes | 
		Transcript show: 'start= ', start printString, ' stop = ', stop printString, ' attributes = ', attributes printString; cr]


 (TextMorph new string: 'Text me!' fontName: 'BitstreamVeraSans' size: 26) openInWorld.

 (TextMorph new string: 'Text me!' fontName: 'LiberationSans' size: 24) extent: 100@24; openInHand.

More see Font size and TextMorph

Question:I just wondered if you'd worked out a way to pop up a TextMorph in italic?
Answer: Ned Konz 21 December 2001

 TextMorph new
 contents: (Text string: 'this is something longer than normal' attribute: TextEmphasis italic);
 fontName: #BitstreamVeraSans size: 24;
 releaseCachedState; "—-added"
 openInWorld


  tm := TextMorph new.
  tm contentsWrapped: ''; extent: 100@20. "this is the important stuff"
Set a font with:
  tm beAllFont: ((TextStyle default fontOfSize: 36) emphasized: 1)

More about this see FAQ: Entry Field in Morphic

See also