Skip to content

Commit 9afbea7

Browse files
authored
Merge pull request #34 from Nyan11/patch-6
Update layout.md - Flow layout display constraint
2 parents 62af7bd + 203edf2 commit 9afbea7

File tree

1 file changed

+33
-31
lines changed

1 file changed

+33
-31
lines changed

Chapters/bloc/layout.md

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -488,26 +488,16 @@ root openInNewSpace.
488488

489489
### Flow layout - BlFlowLayout
490490

491-
Children need to specify their size. If they use constraint, the last one will hide
492-
previous one. They will fit available space + move to next line if necessary.
493-
Flow will fill all available space in its parent, and parent can be resized to
494-
match the space needed to display all its children.
491+
A flow layout is used when you need to display a multiple children elements next to each others.
492+
A flow layout can diplay the children elements horizontaly or verticaly.
493+
If a flow layout does not have enought place to display the next child element, it will create a new row or column to display the next children.
494+
It works like a text editor, a word is added to the next line when the space is not enought to fit it.
495495

496-
#### Parent definition
497-
498-
- horizontal
499-
- vertical
496+
There is special display constraint for the children elements: the value is either `inline` or `float`.
497+
By default, all children are `inline`.
498+
In the case of a horizontal flow layout, the height of a line is equal to the maximum height of all inline elements of this line.
499+
If a child element has a display equals to `flow`, the other elements will be placed around it.
500500

501-
#### Child constraints
502-
503-
- horizontal
504-
- alignCenter
505-
- alignLeft
506-
- alignRight
507-
- vertical
508-
- alignBottom
509-
- alignCenter
510-
- alignTop
511501

512502
#### Example
513503

@@ -516,22 +506,34 @@ root := BlElement new
516506
border: (BlBorder paint: Color red width: 1);
517507
background: (Color red alpha: 0.2);
518508
layout: BlFlowLayout horizontal;
519-
constraintsDo: [ :c |
520-
c horizontal matchParent .
521-
c vertical fitContent ].
509+
constraintsDo: [ :c |
510+
c horizontal matchParent.
511+
c vertical matchParent ];
512+
yourself.
513+
514+
1 to: 100 do: [ :index | | child |
515+
child := BlElement new
516+
border: (BlBorder paint: Color blue width: 1);
517+
background: (Color blue alpha: 0.2);
518+
margin: (BlInsets all: 5);
519+
addChild: (BlTextElement text: index printString asRopedText);
520+
constraintsDo: [ :c |
521+
c horizontal exact: 20.
522+
c vertical exact: 20. ];
523+
yourself.
524+
index = 22 ifTrue: [
525+
child background: Color blue;
526+
size: 50 @ 60;
527+
constraintsDo: [ :c | c flow float ] ].
528+
index = 60 ifTrue: [
529+
child background: Color green;
530+
size: 50 @ 60 ].
531+
root addChild: child
532+
].
522533
523-
50 timesRepeat: [
524-
| elt |
525-
elt := BlElement new
526-
size: 40 @ 80;
527-
border: (BlBorder paint: Color blue width: 1);
528-
background: (Color blue alpha: 0.2);
529-
margin: (BlInsets all: 5).
530-
root addChild: elt ].
534+
root openInNewSpace.
531535
```
532536

533-
![Flow layout.](figures/flowlayout.png width=70)
534-
535537
### Grid layout - BlGridLayout
536538

537539
Elements are disposed in a grid. An element can span over multiple rows or columns.

0 commit comments

Comments
 (0)