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: content/components/lvgl/_index.md
-156Lines changed: 0 additions & 156 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -501,162 +501,6 @@ on_...:
501
501
border_color: 0x00FF00
502
502
```
503
503
504
-
{{< anchor "lvgl-layouts" >}}
505
-
506
-
### Layouts
507
-
508
-
Layouts aim to position widgets automatically, eliminating the need to specify `x` and `y` coordinates to position each widget. This is a great way to simplify your configuration as it allows you to omit alignment options.
509
-
510
-
The layout configuration options are applied to any parent widget or page, influencing the appearance of the children. The position and size calculated by the layout overwrites the *normal* `x`, `y`, `width`, and `height` settings of the children.
511
-
512
-
Check out [Flex layout positioning](#lvgl-cookbook-flex), [Grid layout positioning](#lvgl-cookbook-grid) and [Weather forecast panel](#lvgl-cookbook-weather) in the Cookbook for examples which demonstrate how to automate widget positioning, potentially reducing the size of your device's YAML configuration, and saving you from lots of manual calculations.
513
-
514
-
The `hidden`, `ignore_layout` and `floating` [flags](#lvgl-widget-flags) can be used on widgets to ignore them in layout calculations.
515
-
516
-
#### Configuration variables
517
-
518
-
- **layout** (*Optional*, dict): A dictionary describing the layout configuration:
519
-
- **type** (*Optional*, string): `FLEX`, `GRID` or `NONE`. Defaults to `NONE`.
520
-
- Further options from below depending on the chosen type.
521
-
522
-
#### Flex
523
-
524
-
The Flex layout in LVGL is a subset implementation of [CSS Flexbox](https://css-tricks.com/snippets/css/a-guide-to-flexbox/).
525
-
526
-
It can arrange items into rows or columns (tracks), handle wrapping, adjust spacing between items and tracks and even handle growing the layout to make the item(s) fill the remaining space with respect to minimum/maximum width and height.
527
-
528
-
**Terms used:**
529
-
530
-
- *track*: the rows or columns *main* direction flow: row or column in the direction in which the items are placed one after the other.
531
-
- *cross direction*: perpendicular to the main direction.
532
-
- *wrap*: if there is no more space in the track a new track is started.
533
-
- *gap*: the space between the rows and columns or the items on a track.
534
-
- *grow*: if set on an item it will grow to fill the remaining space on the track. The available space will be distributed among items respective to their grow value (larger value means more space). It dictates what amount of the available space the widget should take up. For example if all items on the track have a `grow` set to `1`, the space in the track will be distributed equally to all of them. If one of the items has a value of 2, that one would take up twice as much of the space as either one of the others.
535
-
536
-
**Configuration variables:**
537
-
538
-
- **flex_flow** (*Optional*, string): Select the arrangement of the children widgets:
539
-
- `ROW` : place the children in a row without wrapping.
540
-
- `COLUMN` : place the children in a column without wrapping.
541
-
- `ROW_WRAP` : place the children in a row with wrapping (default).
542
-
- `COLUMN_WRAP` : place the children in a column with wrapping.
543
-
- `ROW_REVERSE` : place the children in a row without wrapping but in reversed order.
544
-
- `COLUMN_REVERSE` : place the children in a column without wrapping but in reversed order.
545
-
- `ROW_WRAP_REVERSE` : place the children in a row with wrapping but in reversed order.
546
-
- `COLUMN_WRAP_REVERSE` : place the children in a column with wrapping but in reversed order.
547
-
548
-
- **flex_align_main** (*Optional*, string): Determines how to distribute the items in their track on the *main* axis. For example, flush the items to the right on with `flex_flow: ROW_WRAP` (known as *justify-content* in CSS). Possible options below.
549
-
- **flex_align_cross** (*Optional*, string): Determines how to distribute the items in their track on the *cross* axis. For example, if the items have different height place them to the bottom of the track (known as *align-items* in CSS). Possible options below.
550
-
- **flex_align_track** (*Optional*, string): Determines how to distribute the tracks (known as *align-content* in CSS). Possible options below.
551
-
552
-
Values for use with `flex_align_main`, `flex_align_cross`, `flex_align_track` :
553
-
554
-
- `START` : means left horizontally and top vertically (default).
555
-
- `END` : means right horizontally and bottom vertically.
556
-
- `CENTER` : simply center.
557
-
- `SPACE_EVENLY` : items are distributed so that the spacing between any two items (and the space to the edges) is equal. Does not apply to `flex_align_track`.
558
-
- `SPACE_AROUND` : items are evenly distributed in the track with equal space around them. Note that visually the spaces aren't equal, since all the items have equal space on both sides. The first item will have one unit of space against the container edge, but two units of space between the next item because that next item has its own spacing that applies. Does not apply to `flex_align_track`.
559
-
- `SPACE_BETWEEN` : items are evenly distributed in the track: first item is on the start line, last item on the end line. Does not apply to `flex_align_track`.
560
-
561
-
- **pad_row** (*Optional*, int16): Set the padding between the rows, in pixels.
562
-
- **pad_column** (*Optional*, int16): Set the padding between the columns, in pixels.
563
-
- **flex_grow** (*Optional*, int16): Can be used to make one or more children fill the available space on the track. When one or more children have `flex_grow` set, the available space will be distributed proportionally to the grow values. Defaults to `0`, which disables growing.
564
-
565
-
```yaml
566
-
# Example flex layout
567
-
568
-
- obj:
569
-
layout:
570
-
type: flex
571
-
pad_row: 4
572
-
pad_column: 4px
573
-
flex_align_main: center
574
-
flex_align_cross: start
575
-
flex_align_track: end
576
-
widgets:
577
-
- animimg:
578
-
flex_grow: 1
579
-
```
580
-
581
-
#### Grid
582
-
583
-
The Grid layout in LVGL is a subset implementation of [CSS Grid](https://css-tricks.com/snippets/css/complete-guide-grid//).
584
-
585
-
It can arrange items into a 2D "table" that has rows or columns (tracks). The item(s) can span through multiple columns or rows. The track's size can be set in pixels, to the largest item of the track (`CONTENT` ) or in "free units" to distribute the free space proportionally.
586
-
587
-
**Terms used:**
588
-
589
-
- *tracks*: the rows or the columns.
590
-
- *gap*: the space between the rows and columns or the items on a track.
591
-
- *free unit (FR)*: a proportional distribution unit for the space available on the track. It accepts a unitless integer value that serves as a proportion. It dictates what amount of the available space the widget should take up. For example if all items on the track have a `FR` set to `1`, the space in the track will be distributed equally to all of them. If one of the items has a value of 2, that one would take up twice as much of the space as either one of the others.
592
-
593
-
Child widgets can be placed on the grid using the `grid_cell_row_pos` and `grid_cell_column_pos` configuration variables.
594
-
If either is specified both must be specified. If neither is specified the widget will be placed in the first available position, in a row-major order.
595
-
Row and column spans will be taken into account when reserving space.
596
-
597
-
**Configuration variables (must be placed under the layout key):**
598
-
599
-
- **grid_rows** (**Required**): The number of rows in the grid, expressed a list of values in pixels, `CONTENT` or `FR(n)` (free units, where `n` is a proportional integer value).
600
-
- **grid_columns** (**Required**): The number of columns in the grid, expressed a list of values in pixels, `CONTENT` or `FR(n)` (free units, where `n` is a proportional integer value).
601
-
- **grid_row_align** (*Optional*, string): How to align the row. Works only when `grid_rows` is given in pixels. Possible options below.
602
-
- **grid_column_align** (*Optional*, string): How to align the column. Works only when `grid_columns` is given in pixels. Possible options below.
603
-
- **pad_row** (*Optional*, int16): Set the padding between the rows, in pixels.
604
-
- **pad_column** (*Optional*, int16): Set the padding between the columns, in pixels.
605
-
606
-
In a grid layout, *all the widgets placed on the grid* can have some additional configuration variables to help with placement:
607
-
608
-
- **grid_cell_row_pos** (*Optional*, int16): Position of the widget, in which row to appear (0 based count).
609
-
- **grid_cell_column_pos** (*Optional*, int16): Position of the widget, in which column to appear (0 based count).
610
-
- **grid_cell_x_align** (*Optional*, string): How to align the widget horizontally within the cell. Can also be applied through [Style properties](#lvgl-styling). Possible options below.
611
-
- **grid_cell_y_align** (*Optional*, string): How to align the widget vertically within the cell. Can also be applied through [Style properties](#lvgl-styling). Possible options below.
612
-
- **grid_cell_row_span** (*Optional*, int16): How many rows to span across the widget. Defaults to `1`.
613
-
- **grid_cell_column_span** (*Optional*, int16): How many columns to span across the widget.. Defaults to `1`.
614
-
615
-
> [!NOTE]
616
-
> These `grid_cell_` variables are applied to individual widgets (cells) within the grid layout!
617
-
618
-
Values for use with `grid_column_align`, `grid_row_align`, `grid_cell_x_align`, `grid_cell_y_align` :
619
-
620
-
- `START` : means left horizontally and top vertically (default).
621
-
- `END` : means right horizontally and bottom vertically.
622
-
- `CENTER` : simply center.
623
-
- `STRETCH` : stretch the widget to the cell in the respective direction. Does not apply to `grid_column_align`, `grid_row_align`.
624
-
- `SPACE_EVENLY` : items are distributed so that the spacing between any two items (and the space to the edges) is equal.
625
-
- `SPACE_AROUND` : items are evenly distributed in the track with equal space around them. Note that visually the spaces aren't equal, since all the items have equal space on both sides. The first item will have one unit of space against the container edge, but two units of space between the next item because that next item has its own spacing that applies.
626
-
- `SPACE_BETWEEN` : items are evenly distributed in the track: first item is on the start line, last item on the end line.
627
-
628
-
```yaml
629
-
# Example grid layout
630
-
631
-
- obj:
632
-
layout:
633
-
type: grid
634
-
grid_row_align: end
635
-
grid_rows: [25px, fr(1), content]
636
-
grid_columns: [fr(1), fr(1)]
637
-
pad_row: 6px
638
-
pad_column: 0
639
-
widgets:
640
-
- image:
641
-
grid_cell_row_pos: 0
642
-
grid_cell_column_pos: 0
643
-
- obj:
644
-
grid_cell_row_pos: 0
645
-
grid_cell_column_pos: 1
646
-
- obj:
647
-
grid_cell_row_pos: 2
648
-
grid_cell_column_pos: 0
649
-
- label:
650
-
text: "This will be placed in row 1, column 0"
651
-
- label:
652
-
text: "This will be placed in row 1, column 1"
653
-
- label:
654
-
text: "This will be placed in row 2, column 1, since 2/0 is occupied"
655
-
```
656
-
657
-
> [!TIP]
658
-
> To visualize real, calculated sizes of transparent widgets you can temporarily set `outline_width: 1` on them.
0 commit comments