LayoutPolicy
Last updated at 11:14 am UTC on 24 April 2022
Objects of class LayoutPolicy are used to control how the submorphs of a Morph are laid out.
The default for a morph is not to have a LayoutPolicy object.
m := Morph new.
m layoutPolicy
nil
Thus there is also no LayoutProperties object:
m layoutProperties
nil
That means the Morph does not do any layout of its submorphs at all. The following illustrates this effect.
"The container morph created below has a top left corner (= position) at the coordinate 50@20."
slide := Morph new color: Color white darker; width: 300; height: 200; position: 50@20.
"The child morph (= the red morph) has a default position of 0@0 which is maintained after it has been added."
redMorph := Morph new color: Color red.
slide addMorph: redMorph.
slide openInWorld.

The relationship between container morph and child morph is maintained if the container morph is moved:

Use of a TableLayout policy with default properties
With
TableLayout new
a LayoutPolicy object is created.
It has the default properties of for a TableLayout.
If it is assigned as layoutPolicy to a morph the morph starts enforcing layout on its submorphs.
redMorph := Morph new color: Color red.
slide := Morph new color: Color white darker;
width: 300; height: 200; position: 50@20.
"set a TableLayout object with default properties"
slide layoutPolicy: TableLayout new.
slide addMorph: redMorph.
slide openInWorld.

To see what the default object given by
TableLayout new
does see point 2 of: Example - aMorph addMorph: anotherMorph (no layout and TableLayout)
The TableLayout object may be configured in various ways.
There are two subclasses of LayoutPolicy.
For examples how these subclasses are used see: How to lay out submorphs
If you would like to write your own subclass of LayoutPolicy, you may be interested in LayoutPolicy.
Also useful is to subclass TableLayout and TableLayoutProperties, e.g. TableLayout1 and TableLayoutProperties1 and configure them for a specialized case.