The AlignmentMorph may be replaced by any Morph class
Last updated at 3:05 pm UTC on 9 January 2022
The AlignmentMorph class has been reduced to only 13 instance methods in 2000. It it kept in the image for compatibility reasons.
However in a recent Squeak image many morph classes are still based on the AlignmentMorph
The functionality is now available directly inside each Morph and thus it is no longer necessary to subclass AlignmentMorph for your own Morph class in order to have the layout capability on that morph.
Any morph type can do alignment (or more generally 'Layout') if it has been given a LayoutPolicy.
AlingmentMorph the two construction methods: construction of a newColumn and of a newRow.
Configuration of a Morph object to do layout for a row
You may copy the content the newRow method of AlignmentMorph
newRow
^ self new
listDirection: #leftToRight;
hResizing: #spaceFill;
vResizing: #spaceFill;
extent: 1@1;
borderWidth: 0
to your own subclass of Morph 'MyLayoutMorph' and combine it with some code from AlignmentMorph>>basicInitialize
newRow
^ self new layoutPolicy: TableLayout new;
listDirection: #leftToRight;
wrapCentering: #topLeft;
hResizing: #spaceFill;
vResizing: #spaceFill;
layoutInset: 2;
extent: 1@1;
borderWidth: 0
So
MyLayoutMorph newRow
gives you a morph configured to do a row layout.
Configuration of a Morph object to do layout for a column
From AlignmentMorph
self new
listDirection: #topToBottom;
hResizing: #spaceFill;
extent: 1@1;
vResizing: #spaceFill
Variants to add to any subclass of Morph needs to set a few parameters more
newColumn
^ self new layoutPolicy: TableLayout new;
listDirection: #topToBottom;
hResizing: #spaceFill; "or #rigid"
vResizing: #spaceFill; "or #shrinkWrap"
extent: 1@1;
layoutInset: 2;
borderWidth: 0
createColumnMorphWithExtent: anExtent color: aColor borderWidth: anInteger
^RectangleMorph new
extent: anExtent;
color: aColor;
borderWidth: anInteger;
layoutPolicy: TableLayout new;
listDirection: #topToBottom;
"listCentering: #center;"
wrapCentering: #center; "as listDirection goes topToBottom this needs to be #center"
hResizing: #rigid;
vResizing: #shrinkWrap.
Use one of the method variants as a starter
(self new createColumnMorphWithExtent: 300@60 color: Color white borderWidth: 2) addMorph: (Morph new); addMorph: (Morph new color: Color tangerine); inspect; openInHand
and then bring up the Halo on the morph object and use the red halo to fine tune the parameters and adapt the code accordingly.
(CreateHeaderMorphAction5)
More
see: How to lay out submorphs.