lv_grid.h
API reference for lv_grid.h
Functions
lv_obj_set_grid_dsc_array
Set a grid layout on a Widget by describing its column and row track sizes.
Each element of the descriptor arrays is either a size in pixels, LV_GRID_FR(x) to take a proportional share of the free space, or LV_GRID_CONTENT to fit the largest child on that track. Both arrays must be closed with LV_GRID_TEMPLATE_LAST.
Only the pointers are saved, so the arrays must be static, global or dynamically allocated. They must outlive the Widget.
Calling this function also sets the Widget's layout to LV_LAYOUT_GRID, so its children will be positioned by the cells assigned with lv_obj_set_grid_cell().
Passing NULL for either array turns that axis into a sub-grid: the tracks are taken from the parent Grid container, sliced to the cell this Widget occupies (its own position and span on that axis). This makes a wrapper Widget "transparent" so that its children align to the outer grid's tracks.
void lv_obj_set_grid_dsc_array(lv_obj_t *obj, const int32_t col_dsc[], const int32_t row_dsc[])| Name | Type | Description |
|---|---|---|
obj | lv_obj_t * | pointer to a Widget which will be the grid container |
col_dsc | const int32_t | array of column track sizes closed by LV_GRID_TEMPLATE_LAST. May be NULL. Pass NULL to inherit the parent's columns (sub-grid) |
row_dsc | const int32_t | array of row track sizes closed by LV_GRID_TEMPLATE_LAST. May be NULL. Pass NULL to inherit the parent's rows (sub-grid) |
Sub-grids are resolved only one level deep: a sub-grid cannot itself have a sub-grid child.
An inherited LV_GRID_CONTENT track is measured from the sub-grid's own children, so it can end up a different size than in the parent. Use fixed or LV_GRID_FR(x) tracks on the inherited axis to keep the sub-grid aligned.
If both this Widget and its parent have a NULL descriptor on the same axis, no layout is performed and a warning is logged.
lv_obj_set_grid_align
Set how the Grid's tracks are distributed inside the container's content area.
This aligns the grid as a whole, similar to CSS's justify-content/align-content, not of justify-self/align-self. To align an individual item inside its cell, use the align parameters of lv_obj_set_grid_cell().
It only has a visible effect if there is free space left over after the tracks are sized. A grid built purely from LV_GRID_FR(x) tracks consumes all available space, so alignment will appear to do nothing.
Accepted values on both axes:
LV_GRID_ALIGN_START: tracks are packed to the left/top (default)LV_GRID_ALIGN_CENTER: tracks are centeredLV_GRID_ALIGN_END: tracks are packed to the right/bottomLV_GRID_ALIGN_SPACE_BETWEEN: free space is split between the tracks, none at the edgesLV_GRID_ALIGN_SPACE_AROUND: equal space around each track, so edge space is half of the space between tracksLV_GRID_ALIGN_SPACE_EVENLY: gaps between tracks and at the edges are all equal
void lv_obj_set_grid_align(lv_obj_t *obj, lv_grid_align_t column_align, lv_grid_align_t row_align)| Name | Type | Description |
|---|---|---|
obj | lv_obj_t * | pointer to a Grid container |
column_align | lv_grid_align_t | how to distribute the columns horizontally |
row_align | lv_grid_align_t | how to distribute the rows vertically |
This function does not set the Widget's layout to LV_LAYOUT_GRID
LV_GRID_ALIGN_STRETCH is meaningful only for items in a cell and is not a valid track alignment here.
The SPACE_* modes compute the spacing from the remaining free space and therefore override pad_column/pad_row. With a single track they behave like LV_GRID_ALIGN_CENTER.
If the container's size is LV_SIZE_CONTENT on an axis, there is no free space by definition and the alignment on that axis is ignored.
With LV_BASE_DIR_RTL on the container the column tracks are laid out right-to-left, so START means right-most.
lv_obj_set_grid_cell
Set the cell of an object. The object's parent needs to have grid layout, else nothing will happen
void lv_obj_set_grid_cell(lv_obj_t *obj, lv_grid_align_t column_align, int32_t col_pos, int32_t col_span, lv_grid_align_t row_align, int32_t row_pos, int32_t row_span)| Name | Type | Description |
|---|---|---|
obj | lv_obj_t * | pointer to an object |
column_align | lv_grid_align_t | the vertical alignment in the cell. LV_GRID_START/END/CENTER/STRETCH |
col_pos | int32_t | column ID |
col_span | int32_t | number of columns to take (>= 1) |
row_align | lv_grid_align_t | the horizontal alignment in the cell. LV_GRID_START/END/CENTER/STRETCH |
row_pos | int32_t | row ID |
row_span | int32_t | number of rows to take (>= 1) |
lv_grid_init
void lv_grid_init(void)lv_grid_fr
Just a wrapper to LV_GRID_FR for bindings.
int32_t lv_grid_fr(uint8_t x)| Name | Type |
|---|---|
x | uint8_t |
Enums
lv_grid_align_t
| Name |
|---|
LV_GRID_ALIGN_START |
LV_GRID_ALIGN_CENTER |
LV_GRID_ALIGN_END |
LV_GRID_ALIGN_STRETCH |
LV_GRID_ALIGN_SPACE_EVENLY |
LV_GRID_ALIGN_SPACE_AROUND |
LV_GRID_ALIGN_SPACE_BETWEEN |
Used by 12 functions
lv_obj_set_style_grid_column_align— paramvaluelv_obj_set_style_grid_row_align— paramvaluelv_obj_set_style_grid_cell_x_align— paramvaluelv_obj_set_style_grid_cell_y_align— paramvaluelv_style_set_grid_column_align— paramvaluelv_style_set_grid_row_align— paramvaluelv_style_set_grid_cell_x_align— paramvaluelv_style_set_grid_cell_y_align— paramvaluelv_obj_set_grid_align— paramcolumn_alignlv_obj_set_grid_align— paramrow_alignlv_obj_set_grid_cell— paramcolumn_alignlv_obj_set_grid_cell— paramrow_align
Macros
LV_GRID_FR
#define LV_GRID_FR(x) \
(LV_COORD_MAX - 100 + x)Can be used track size to make the track fill the free space.
Parameters| Name | Description |
|---|---|
x | how much space to take proportionally to other FR tracks |
Returns: a special track size
LV_GRID_CONTENT
#define LV_GRID_CONTENT (LV_COORD_MAX - 101)LV_GRID_TEMPLATE_LAST
#define LV_GRID_TEMPLATE_LAST (LV_COORD_MAX)Dependencies
Last updated on