6.3 Submorph

Morphs can contain other morphs. These interior morphs are called submorphs of their containing morph. Again, you can do this by writing the software “code”, but let’s do it directly with a BoxedMorph.

First we obtain a BoxedMorph from the New morph... submenus. The BoxedMorph instance displays itself as a rect with a border.

ch06-05-AddRectangle

Figure 6.4: Obtain a BoxedMorph

Now drag the rect over the ellipse and Middle-Click on the rect and click on the blue construction handle to gets the rect’s Morph Menu. Use the menu selection embed into and select the ellipse as its new parent.

ch06-06-EmbedRectIntoEllipse

Figure 6.5: Make the rect a submorph of the ellipse

Now when you click-drag the ellipse, or use the Pick up or Move construction handles, the rect is just a decoration for the ellipse.

Indeed, the rect seems to have fused into the ellipse. Using the mouse where the rect shows itself is just using the mouse on the ellipse. This rect does not have many interesting behaviors.

Let’s add a behavior to just this one BoxedMorph.