You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Chapters/bloc/layout.md
+99-24Lines changed: 99 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -367,49 +367,124 @@ Stef should continue down here.
367
367
368
368
### Linear layout - BlLinearLayout
369
369
370
-
Children can use dynamic size with constraints. The number of element will then fit
371
-
its parents available space. If you specify their size, and the total is
372
-
over its parents, they will be hidden. need to specify their size. If they use
373
-
constraint, the last one will hide previous one. They will fit available space +
374
-
move to next line if necessary
370
+
A linear layout is used when you need to display a multiple children elements next to each others.
371
+
A linear layout can diplay the children elements horizontaly or verticaly.
372
+
The size of a child element depends of the child's constraints.
373
+
The constraints are:
375
374
376
-
#### Parent definition
375
+
-`BlLayoutCommonConstraintsAxis exact:` to define an exact size for the child.
376
+
-`BlLayoutCommonConstraintsAxis fitContent` to define a size that will match the content of the child.
377
+
-`BlLinearLayoutConstraints weight:` to define a proportional size of the child compare to its siblings' weigths (only available if matchParent is set as the BlLayoutCommonConstraintsAxis). By default the weight equals 1.
377
378
378
-
- horizontal
379
-
- vertical
379
+
#### Example
380
+
381
+
In this example the childA has a weight of 3, the childB has a default weight of 1 and the childC has a weight of 200.
382
+
But the weight of the childC will not be considered because its horizontal size is defined has an exact value.
383
+
384
+
- The childA will take `3 / (3 + 1) = 3 / 4` of the available space.
385
+
- The childB will take `1 / (3 + 1) = 1 / 4` of the available space.
386
+
387
+
```smalltalk
388
+
root := BlElement new
389
+
border: (BlBorder paint: Color red width: 1);
390
+
background: (Color red alpha: 0.2);
391
+
layout: BlLinearLayout horizontal;
392
+
constraintsDo: [ :c |
393
+
c horizontal matchParent.
394
+
c vertical fitContent ];
395
+
yourself.
396
+
397
+
childA := BlElement new
398
+
border: (BlBorder paint: Color blue width: 1);
399
+
background: (Color blue alpha: 0.2);
400
+
margin: (BlInsets all: 10);
401
+
constraintsDo: [ :c |
402
+
c horizontal matchParent.
403
+
c vertical exact: 50.
404
+
c linear weight: 3 ];
405
+
yourself.
406
+
407
+
childB := BlElement new
408
+
border: (BlBorder paint: Color blue width: 1);
409
+
background: (Color blue alpha: 0.2);
410
+
margin: (BlInsets all: 10);
411
+
constraintsDo: [ :c |
412
+
c horizontal matchParent.
413
+
c vertical exact: 50 ];
414
+
yourself.
415
+
416
+
childC := BlElement new
417
+
border: (BlBorder paint: Color blue width: 1);
418
+
background: (Color blue alpha: 0.2);
419
+
margin: (BlInsets all: 10);
420
+
constraintsDo: [ :c |
421
+
c horizontal exact: 50.
422
+
c vertical exact: 50.
423
+
c linear weight: 20 ];
424
+
yourself.
425
+
426
+
root addChildren: { childA . childB . childC }.
427
+
root openInNewSpace.
428
+
```
380
429
381
430
#### Child constraints
382
431
383
-
- horizontal
432
+
Constraints can be added on the children relative position.
433
+
434
+
If the layout is vertical:
384
435
- alignCenter
385
436
- alignLeft
386
437
- alignRight
387
-
- vertical
438
+
439
+
If the layout is horizontal:
388
440
- alignBottom
389
441
- alignCenter
390
442
- alignTop
391
443
392
-
#### Example
393
-
394
-
```smalltalk
444
+
```st
395
445
root := BlElement new
396
446
border: (BlBorder paint: Color red width: 1);
397
447
background: (Color red alpha: 0.2);
398
-
layout: BlLinearLayout horizontal;
448
+
layout: BlLinearLayout horizontal;
399
449
constraintsDo: [ :c |
400
-
c horizontal fitContent.
401
-
c vertical fitContent ].
402
-
403
-
50 timesRepeat: [ |elt| elt := BlElement new border: (BlBorder paint: Color blue width: 1);
0 commit comments