[Newbies] Centering text in morphic

Johann Hibschman johannh at gmail.com
Thu Feb 9 13:40:06 UTC 2012

On Wed, Feb 8, 2012 at 12:44 PM, Lawson English <lenglish5 at cox.net> wrote:
> Hi Johann, just after you left IRC, I figured out an easy (though perhaps
> not the best) way to do what you want:
> a := SimpleButtonMorph new openInWorld.
> a actWhen: #buttonDown.   "turns off visible button behavior"
> a label: 'new label'.              "lets you change the label to a different
> string of text"
> a clipSubmorphs: true.        "true means that your text doesn't extend
> beyond the border of the button"

Thanks, that's helpful. I don't think I'm going to use
SimpleButtonMorph, since it builds in a fixed margin, but reading its
implementation was useful. It makes a StringMorph and uses its #extent
to do the centering, and I can just do the same thing. (And I can just
look at StringMorph's #extent if I need to.)

If SimpleButtonMorph works by embedding a StringMorph, I think that's
a sign that I should do that rather than override #drawOn.


More information about the Beginners mailing list