Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to change submorph position

I have two morphs that one is in the other.

a:= Morph new.
b:= Morph new. 
a addMorph: b. 
a openInWorld.

but when I want to change b's position by doing b position: 100@100, it never shows the change, so what am I missing here? or is it somehow a's responsibility to keep track of b's position?

like image 458
yi cheng Avatar asked Apr 02 '13 19:04

yi cheng


1 Answers

This should work:

| morph1 morph2 |

morph1 := Morph new.
morph1 color: Color red.
morph1 extent: 200@200.

morph2 := Morph new.
morph2 color: Color green.
morph2 extent: 50@50.

morph1 addMorph: morph2.
morph2 position: 100@100.
morph1 openInWorld.

The result:

enter image description here

Note that the positions are absolute, if you want relative positions you have to do something like:

morph2 position: (morph1 position + (100@100))

If you add Morphs to a window, you could have a look at SystemWindow #addMorph:fullFrame: which offers better possibilities to position submorphs. Morph also implements #addMorph:fullFrame: but somehow this does not seem to work for me in Pharo 2.0.

Have a look at: Pharo collaborActive book and at the Basic Widgets chapter of Pharo by Example 2.

like image 116
MartinW Avatar answered Sep 28 '22 03:09

MartinW