lv_grid.h

API reference for lv_grid.h

Report on GitHub

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[])
Parameters
NameTypeDescription
objlv_obj_t *pointer to a Widget which will be the grid container
col_dscconst int32_tarray of column track sizes closed by LV_GRID_TEMPLATE_LAST. May be NULL. Pass NULL to inherit the parent's columns (sub-grid)
row_dscconst int32_tarray 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 centered
  • LV_GRID_ALIGN_END: tracks are packed to the right/bottom
  • LV_GRID_ALIGN_SPACE_BETWEEN: free space is split between the tracks, none at the edges
  • LV_GRID_ALIGN_SPACE_AROUND: equal space around each track, so edge space is half of the space between tracks
  • LV_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)
Parameters
NameTypeDescription
objlv_obj_t *pointer to a Grid container
column_alignlv_grid_align_thow to distribute the columns horizontally
row_alignlv_grid_align_thow 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)
Parameters
NameTypeDescription
objlv_obj_t *pointer to an object
column_alignlv_grid_align_tthe vertical alignment in the cell. LV_GRID_START/END/CENTER/STRETCH
col_posint32_tcolumn ID
col_spanint32_tnumber of columns to take (>= 1)
row_alignlv_grid_align_tthe horizontal alignment in the cell. LV_GRID_START/END/CENTER/STRETCH
row_posint32_trow ID
row_spanint32_tnumber of rows to take (>= 1)

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 — param value
  • lv_obj_set_style_grid_row_align — param value
  • lv_obj_set_style_grid_cell_x_align — param value
  • lv_obj_set_style_grid_cell_y_align — param value
  • lv_style_set_grid_column_align — param value
  • lv_style_set_grid_row_align — param value
  • lv_style_set_grid_cell_x_align — param value
  • lv_style_set_grid_cell_y_align — param value
  • lv_obj_set_grid_align — param column_align
  • lv_obj_set_grid_align — param row_align
  • lv_obj_set_grid_cell — param column_align
  • lv_obj_set_grid_cell — param row_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
NameDescription
xhow 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

Indirect dependencies

Last updated on

On this page