Morphic question
Hannes Hirzel
hannes.hirzel.squeaklist at bluewin.ch
Mon Feb 10 08:30:24 UTC 2003
Dustin Sallings <dustin+squeak at spy.net> wrote:
>
> I went through some of the morphic tutorials and I think I
> understand the basic concepts. What I didn't get was the part where you
> create a morph class that will contain one or more embeded morph classes.
>
> I can instantiate them in a project and get them all embeded and
> all that, but I'd like to create a standalone morph of which I can easily
> create multiple instances.
>
> Any pointers?
A simple example is the LedMorph
If you evaluate (ALT-D in Windows) in a workspace
LedMorph new openInWorld
you get a LedMorph with two digits.
------------------------------------------------------------------------
-------
It was constructed by executing the code of the method initialize
initialize
super initialize.
flashing _ false.
flash _ false.
self scrollInit.
self digits: 2.
self value: 0.
self color: Color green.
which contains the expression:
self digits: 2.
If you look into #digits:
digits: aNumber
digits _ aNumber.
self removeAllMorphs.
1 to: digits do: [:i | self addMorph: (LedDigitMorph new color:
color)].
self layoutChanged.
self changed.
You see that #addMorph: is used.
------------------------------------------------------------------------
------------
To summarize
To come up with your own Morph you subclass an existing Morph
(class Morph is a good candidate as it already is very capable - it
has 1000 methods!)
and you write your own initialize method which uses #addMorph
to add submorphs.
There is a tutorial http://minnow.cc.gatech.edu/squeak/795
which explains in a more detailed way how to do your own morph
(not by direct manipulation / construction but with Smalltalk code;
section second and third approach)
Hannes Hirzel
More information about the Squeak-dev
mailing list
|