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 4
Last updated at 2:03 am UTC on 16 April 2010
Craig Latta asked Mon, 04 Feb 2002 on the mailing list:
> I'd like to nest a proportional layout in a table layout.

Bob Arning gave an example:
Morph new
	color: Color green;
	extent: 300 @ 300;
	layoutPolicy: ProportionalLayout new;
	addMorph: (
		Morph new color: (Color blue alpha: 0.5)
	)
	fullFrame: (
		LayoutFrame
                    fractions: (0@1 corner: 1 @ 1) offsets: (0@100 negated corner: 0@0)
	);

	addMorph: (
		Morph new
			color: (Color red alpha: 0.5);
			layoutPolicy: ProportionalLayout new;
			addMorph: (
				Morph new
					color: (Color yellow alpha: 0.5);
					layoutPolicy: TableLayout new;
					listDirection: #topToBottom;
					listCentering: #center;
					addMorph: (
						Morph new extent: 100@2; color: Color black; hResizing: #spaceFill
					)
			)
			fullFrame: (LayoutFrame fractions: (0@0 corner: 0.9 @ 0.9) offsets: nil)
	)
	fullFrame: (
		LayoutFrame fractions: (0@0 corner: 1 @ 1) offsets: (0@0 corner: 0@100 negated)
	);
     openInWorld


And here is the same example, refactored so that you can execute one statement at a time in a workspace and see the results as the example develops:
m := Morph new.
m openInWorld.
m color: Color green.
m extent: 300 @ 300.
m layoutPolicy: ProportionalLayout new.
	
bm := Morph new.
bm openInWorld.
m
	addMorph: bm
	fullFrame: (
		LayoutFrame
              fractions: (0@1 corner: 1 @ 1) offsets: (0@100 negated corner: 0@0)
	).
bm color: (Color blue alpha: 0.5).

sm := Morph new.
sm openInWorld.
m addMorph: sm fullFrame: (
		LayoutFrame fractions: (0@0 corner: 1 @ 1) offsets: (0@0 corner: 0@100 negated)).
sm color: (Color red alpha: 0.5).
sm layoutPolicy: ProportionalLayout new.
			
tm := Morph new.
tm openInWorld.
sm 
	addMorph: tm 
	fullFrame: (LayoutFrame fractions: (0@0 corner: 0.9 @ 0.9) offsets: nil).
tm color: (Color yellow alpha: 0.5).
tm layoutPolicy: TableLayout new.
tm listDirection: #topToBottom.
tm listCentering: #center.
	
fm := Morph new.
fm openInWorld.
tm addMorph: fm.
fm extent: 100@2.
fm color: Color black.
fm hResizing: #spaceFill.


Sean DeNigris