[Q] Morphic strategies

Ned Konz ned at bike-nomad.com
Tue May 20 23:30:47 UTC 2003


On Tuesday 20 May 2003 02:20 pm, Brian Brown wrote:

> > Can you show us what you've tried to do?
>
> Sure, here is some code....

[snip]

> This produces two colored boxes (topToBottom on the left) and one
> on the right. I would be putting various controls in the top and
> bottom boxes as well as in the right "frame". With this I have
> created a PasteUpMorph and 3 other RectangleMorphs just as
> containers... are there better ways to do it, or is this fine?

First, you probably don't want to use a PasteUpMorph as your master
container unless you're going to be dropping things into it and need that kind of behavior.

Second, you don't need to specify sizes of the submorphs if you're using a layout policy;
the layout policy will set the submorph sizes.

There are some utility constructors (in AlignmentMorph right now)
that can help when you need to make rows/columns of things:

AlignmentMorph inARow: someMorphs
AlignmentMorph inAColumn: someMorphs
AlignmentMorph newRow
AlignmentMorph newColumn
AlignmentMorph newVariableTransparentSpacer

etc.

But your example might be easier expressed as:

window := RectangleMorph newBounds: ((0 at 460) extent: (640 at 480)).
window layoutPolicy: ProportionalLayout new.
window addMorph: (RectangleMorph new color: Color green) fullFrame: (LayoutFrame fractions: (0 at 0 extent: 0.5 at 0.5)).
window addMorph: (RectangleMorph new color: Color red) fullFrame: (LayoutFrame fractions: (0 at 0.5 extent: 0.5 at 0.5)).
window addMorph: (RectangleMorph new color: Color yellow) fullFrame: (LayoutFrame fractions: (0.5 at 0 extent: 0.5 at 1)).
window openInWorld.

> (this will do no dynamic resizing though... I assume I need
> ProportionalLayout for that)

No, the table layout does dynamic resizing too.
But in something like a "window" where you have a clear idea of how big things are,
it often makes sense to use a proportional layout.

When using a LayoutFrame:
The fractions are relative to the owner.
So the fraction rectangle should have no corners outside (0 at 0 corner: 1 at 1).
The offsets are in pixels, and are relative to the fractional rectangle.

So if you wanted to have a row of buttons along the bottom of a Morph that always had to be 30 pixels tall,
you could use a LayoutFrame like this:

window addMorph: (AlignmentMorph inARow: buttons)
	fullFrame: (LayoutFrame fractions: (0 at 1 corner: 1 at 1) offsets: (0 at -30 corner: 0 at 0)).

So the button row would be laid out using a TableLayout, and its owner would use a ProportionalLayout.

-- 
Ned Konz
http://bike-nomad.com
GPG key ID: BEEA7EFE



More information about the Squeak-dev mailing list