LVGL容器
LVGL容器介绍
这是一个具有特殊功能的基础对象.
该对象中可以存放各种各样的子对象,但子对象过多的时候,排列就会很麻烦,所以有一个专门的Layout布局属性约束子对象们的摆放,具体体现在style.body.padding
.在上个笔记中也提到了.此外,容器还有一个Auto fit大小自动适应的特性.
LVGL容器的使用
普通API
lv_obj_t * lv_cont_create(lv_obj_t * par, const lv_obj_t *copy)
创建一个容器.
par
:父对象
copy
: 创建新对象时,可以把该对象上的属性值复制过来.void lv_cont_set_style(lv_obj_t * cont, lv_cont_style_t type, const lv_style_t *style)
设定容器样式
cont
: 容器对象
type
:设定容器上的部分样式,目前只有LV_CONT_STYLE_MAIN
可选
style
:样式
布局方式API
lv_cont_set_layout(lv_obj_t * cont, lv_layout_t layout)
设定容器布局方式.
layout
: 布局方式.参数如下./** Container layout options*/ enum { LV_LAYOUT_OFF = 0, /**< No layout */ LV_LAYOUT_CENTER, /**< Center objects */ LV_LAYOUT_COL_L, /**< Column left align*/ LV_LAYOUT_COL_M, /**< Column middle align*/ LV_LAYOUT_COL_R, /**< Column right align*/ LV_LAYOUT_ROW_T, /**< Row top align*/ LV_LAYOUT_ROW_M, /**< Row middle align*/ LV_LAYOUT_ROW_B, /**< Row bottom align*/ LV_LAYOUT_PRETTY, /**< Put as many object as possible in row and begin a >new row*/ LV_LAYOUT_GRID, /**< Align same-sized object into a grid*/ LV_LAYOUT_NUM }; typedef uint8_t lv_layout_t;
自适应API
-
lv_cont_set_fit4(lv_obj_t * cont, lv_fit_t left, lv_fit_t right, lv_fit_t top, lv_fit_t bottom)
-
static inline void lv_cont_set_fit2(lv_obj_t * cont, lv_fit_t hor, lv_fit_t ver)
-
static inline void lv_cont_set_fit(lv_obj_t * cont, lv_fit_t fit)
这三个函数作用是一样的,都是设定自适应方式.
第一个是设定四个方向的自适应方式.
第二个是设定水平和垂直方向上的自适应方式
第三个是将四个方向的自适应方式统一设定.
lv_fit_t
定义如下.enum { LV_FIT_NONE, /**< Do not change the size automatically*/ LV_FIT_TIGHT, /**< Shrink wrap around the children */ LV_FIT_FLOOD, /**< Align the size to the parent's edge*/ LV_FIT_FILL, /**< Align the size to the parent's edge first but if there is an object out of it then get larger */ _LV_FIT_NUM };
总体来说比较简单.