How to lay out submorphs - example 0 - centered submorph
Last updated at 11:25 am UTC on 17 September 2021
A RectangleMorph object is made a layout morph by assigning to it a LayoutPolicy, a TableLayout policy object.
myLayoutMorph := RectangleMorph new.
myLayoutMorph layoutPolicy: TableLayout new.
"center submorphs"
myLayoutMorph listCentering: #center.
myLayoutMorph wrapCentering: #center.
myLayoutMorph width: 320.
myLayoutMorph height: 240.
myLayoutMorph color: Color white darker.
m := RectangleMorph new color: (Color red).
m width: (myLayoutMorph width - 40).
m height: (myLayoutMorph height - 40).
myLayoutMorph addMorph: m.
myLayoutMorph openInWorld.

In the following example listCentering: #center
and wrapCentering: #center
is not used on the container morph "myLayoutMorph".
The #shrinkWrap
horizontal and vertical resizing behavior is used which results in the effect that the (only one) submorph is centered.
myLayoutMorph := RectangleMorph new.
myLayoutMorph layoutPolicy: TableLayout new.
myLayoutMorph color: Color gray.
myLayoutMorph listDirection: #leftToRight.
myLayoutMorph hResizing: #shrinkWrap; vResizing: #shrinkWrap.
myLayoutMorph layoutInset: 20.
m:= RectangleMorph new color: (Color green darker).
m width: 300.
m height: 200.
myLayoutMorph addMorph: m.
myLayoutMorph openInHand
