Reputation: 51
I have a morph. This morph is designed to hold a row of submorphs, which I use a TableLayout layout policy for and it works well.
However, I want this morph to have a specific submorph that is always positioned directly below the morph. This specific submorph is determined by an instance variable of the morph.
In this example, the main morph is cyan, and the submorphs are red, green and blue. The purple morph is currently not a submorph of the main morph, but it demonstrates where I want it to be as a submorph.
Let's say that the main morph has the purple morph in one of its instance variables, and the purple morph is also a submorph of the main morph. How would I treat that submorph differently when organizing the morph's contents using TableLayout?
I haven't tried much of anything yet. This is partially because I wouldn't know how to try, and partially because this seems like a common enough use case that there might be a solution better than anything I could come up with.
Upvotes: 4
Views: 117
Reputation: 1080
To me, the first obvious question would be: Why do you want purple
to be a submorph of main
? Grouping morphs based on common properties usually helps organizing and layouting them. In general, it's a widespread practice in Morphic to use composition extensively.
Preliminary note: As you did not provide a code sample, I will work with the following baseline script:
main := Morph new
color: Color cyan;
borderWidth: 2;
borderColor: Color black.
main
changeTableLayout;
listDirection: #leftToRight;
hResizing: #shrinkWrap;
vResizing: #shrinkWrap;
cellGap: 5.
main addAllMorphs:
{Morph new color: Color red; borderWidth: 2; borderColor: Color black.
Morph new color: Color green; borderWidth: 2; borderColor: Color black.
Morph new color: Color blue; borderWidth: 2; borderColor: Color black}.
purple := Morph new color: Color magenta.
main openInWorld.
purple openInWorld.
purple topLeft: main bottomLeft.
If you use composition, you can arrange both main
and purple
in another table-layouted transparent container:
outer := Morph new
changeTableLayout;
beTransparent;
hResizing: #shrinkWrap;
vResizing: #shrinkWrap;
cellPositioning: #topLeft;
yourself.
outer addAllMorphs: {main. purple}.
outer openInWorld.
Just for sake of completion, it is also possible to exclude a single morph from its owner layout policy as you requested. This can be done by enabling the #disableLayout
property on the relevant submorph:
purple disableLayout: true.
main vResizing: #rigid; height: 44.
main addMorph: purple.
purple topLeft: main bottomLeft.
However, I would not consider this solution idiomatic in most situations:
#fullBounds
), this is often unexpected and may make certain inspection and debugging tasks harder. For instance, to invoke a halo on the purple morph in this example, you need to either press Shift + Blue, or turn on the preference "Halo encloses full bounds". Note that since Squeak 6.0, you can also press Ctrl + Blue to override this preference once.Upvotes: 0