Squeak
  links to this page:    
View this PageEdit this PageUploads to this PageHistory of this PageTop of the SwikiRecent ChangesSearch the SwikiHelp Guide
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.
Rectangle_Morph_with_a_TableLayout_policy_and_centered_submorph.png

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
Rectangle_Morph_with_a_TableLayout_policy_and_centered_submorph_shrinkWrap.png