Writing a LayoutStrategy in Bloc can be easy.
Generic layout strategies get complex because
they can be parametrized a lot. That tends to
distract from the essentials.

In this case, all I need is a strategy that
adds submorphs from left to right in the panel,
breaking to a new line when it is full, and
recalculate the height when finished.

A LayoutStrategy needs to provide only one
method #layout:in:. In that, the morph and its
submorphs need to be layouted in the proposed
bounds. These bounds can be changed. Resizing
needs to happen with #innerExtent:, not with
#extent: as that results in a non-interruptible
loop.

Instead of using #submorphsDo, Bloc uses
#layoutComponentsDo:.

BlCardLayout>>layout: aMorph in: newBounds
        |offset maxHeight|
        offset := 0@0.
        maxHeight := 0.
        aMorph layoutComponentsDo: [ :component |
                offset x + component width > newBounds width ifTrue: [
                        "start a new line"
                        offset := 0@ (offset y + maxHeight).
                        maxHeight := 0].
                component position: offset.
                maxHeight := maxHeight max: component height.
                offset := (offset x + component width) @ offset y].
        maxHeight + offset y > aMorph height ifTrue: [
                aMorph innerExtent: aMorph innerExtent x @ (maxHeight+ offset 
y)]

For the card wall I'll need to add margin and inset.

Stephan



Reply via email to