TextMorph examples
Last updated at 6:57 pm UTC on 22 November 2020
Creating a TextMorph object with a StrikeFont
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.
Creating a TextMorph object with a TrueType font-
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.
Make a TextMorph object read-only
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
Use of the wrapFlag
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) ]
The #beAllFont message
aTextMorph beAllFont: aFont example
(TextMorph new
beAllFont: ((TextStyle default fontOfSize: 36) emphasized: 1);
color: Color magenta;
contents: 'Some text') openInWorld
Listing the text attribute
aTextMorph text runs withStartStopAndValueDo:
[:start :stop :attributes |
Transcript show: 'start= ', start printString, ' stop = ', stop printString, ' attributes = ', attributes printString; cr]
Other TextMorph creation messages
(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
'foo' asText
addAttribute: (TextFontReference toFont: ((TextStyle named: 'Darkmap DejaVu Sans') fontOfSize: 20));
openAsMorph
'foo' asTextMorph
beAllFont: ((TextStyle named: 'Darkmap DejaVu Sans') fontOfSize: 20);
openInHand
See also