aMorph submorphsDo: aBlock
Last updated at 3:09 pm UTC on 7 May 2019
When using #addMorph: new instances of the class Morph are added in front of the submorphs list.
Thus the red morph though added first appears last when executing
aMorph submorphsDo: aBlock
This is illustrated by the following example.
A number is attached to each submorph when the block is executed.
| w p1 p2 p3 p4 msize number offset |
w := PasteUpMorph new extent: 600@480; position: 10@30.
msize := 240@180.
p1 := PasteUpMorph new extent: msize; position: 40@40; color: Color red.
w addMorph: p1.
p2 := PasteUpMorph new extent: msize; position: 320@60; color: Color blue.
w addMorph: p2.
p3 := PasteUpMorph new extent: msize; position: 50@260; color: Color orange.
w addMorph: p3.
p4 := PasteUpMorph new extent: msize; position: 340@280; color: Color green.
w addMorph: p4.
number := 0.
offset:= 6@6.
w submorphsDo: [:p | number:= number + 1.
p addMorph:
((StringMorph contents: number printString)
position: (p position + offset))
].
w openInWorld.
tagBeginner