{ import: Objects } Layout : Object () Layout emptyLineHeight [ ^20 ] "The only public method. Compute a new layout based on the given extent. After calculate child boxes, it set own extent with Box >> layoutExtent:." Layout layout: aBox in: aPoint [ aBox layoutExtent: aPoint ] "----------------------------------------------------------------" SimpleLayout : Layout () SimpleLayout layout: aBox in: aPoint [ | x y w h | aPoint println. x := y := 0. w := aPoint x. h := 0. aBox do: [:box || xx | xx := box extent x. (x > 0 and: [x + xx >= w]) ifTrue: [y := y + h. x := h := 0]. box position: x,y. x := x + xx. h := h max: box extent y]. super layout: aBox in: aPoint " self layoutExtent: self contents last position + self contents last extent." ] "----------------------------------------------------------------" KerningLayout : Layout () KerningLayout layout: aBox in: aPoint [ | x y w h prev | x := y := 2. w := aPoint x - 4. h := 2. aBox do: [:box || xx | xx := box extent x. (x > 0 and: [x + xx >= w]) ifTrue: [y := y + h + 2. x := h := 2. prev := nil]. prev ifTrue: [x := x + (prev kerningFor: box) x]. prev := box. box position: x,y. x := x + xx. h := h max: box extent y]. "It takes care about empty line at end of the text." aBox layoutExtent: aPoint x, (aBox isEmpty ifTrue: [ self emptyLineHeight ] ifFalse: [y + h]). ] "----------------------------------------------------------------" ParagraphLayout : Layout () ParagraphLayout layout: aBox in: aPoint [ | y | y := 0. aBox do: [:box | box position: 0, y. box extent: aPoint x, box extent y. y := y + box extent y]. aBox layoutExtent: aPoint x, y. ] CenterLayout : Layout () CenterLayout layout: aBox in: aPoint [ | y | y := 0. aBox do: [:box | box position: 0, y. box extent: aPoint x, box extent y. box fitContents. box position: aPoint x - box extent x / 2, y. y := y + box extent y]. aBox layoutExtent: aPoint x, y. ]