1. 创建容器
/****************************************************************************************************
*@par : 该子类存在的父类,比如显示屏scr
*@copy : 传入的参数,一般为NULL
*******************************************************************************************************/
lv_obj_t * lv_cont_create(lv_obj_t * par, const lv_obj_t * copy)
举例
lv_obj_t* cont1;
cont1 = lv_cont_create(scr, NULL);
2. 设置容器坐标
/****************************************************************************************************
*@obj: 设置的类名称
*@x/y: 类的坐标
*******************************************************************************************************/
void lv_obj_set_pos(lv_obj_t * obj, lv_coord_t x, lv_coord_t y)
举例:lv_obj_set_pos(cont1,0,0);
3. 设置容器尺寸
设置了某些方向自适应,相对的尺寸设置就没有效果
比如设置了右边自适应,设置的宽度尺寸就没有效果,但是高度仍有效果
/****************************************************************************************************
*@obj: 容器名称
*@w/h: 宽度/高度
*******************************************************************************************************/
void lv_obj_set_size(lv_obj_t * obj, lv_coord_t w, lv_coord_t h)
举例:
lv_obj_set_size(cont1,150,250);
4. 设置容器自适应性
按照内部子类大小自动决定尺寸
enum
{
//无自适应,只能通过lv_obj_set_pos设置位置,若没有禁止则lv_obj_set_pos无效
LV_FIT_NONE,
//容器大小随着包括内部子对象大小,使用lv_cont_style.body.padding.left/top/right/bottom样式
LV_FIT_TIGHT,
//容器按照其父对象空间平铺,使用lv_cont_style.body.padding.left/top/right/bottom设置间距
LV_FIT_FLOOD,
LV_FIT_FILL, _LV_FIT_NUM //这个值是无意义的 ,只是用来记录一下有多少种自适应方式
};
/****************************************************************************************************
*@cont: 容器名称
*@left/right/top/bottom: 个方向自适应配置
*******************************************************************************************************/
void lv_cont_set_fit4(lv_obj_t * cont, lv_fit_t left, lv_fit_t right, lv_fit_t top, lv_fit_t bottom)
举例:设置右边与底部自适应,左侧与顶部由容器位置决定固定不改
lv_cont_set_fit4(cont,LV_FIT_NONE,LV_FIT_TIGHT,LV_FIT_NONE,LV_FIT_TIGHT);
5.容器内部布局
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
};
/****************************************************************************************************
*@cont: 容器名称
*@layout: 布局方式
*******************************************************************************************************/
void lv_cont_set_layout(lv_obj_t * cont, lv_layout_t layout)
lv_cont_set_layout(cont1,LV_LAYOUT_GRID);
6. 容器风格
/****************************************************************************************************
*@cont: 容器名称
*@type: 容器类型,目前只有LV_CONT_STYLE_MAIN选择
*@style: 容器风格
*******************************************************************************************************/
static inline void lv_cont_set_style(lv_obj_t * cont, lv_cont_style_t type, const lv_style_t * style)
举例:
static lv_style_t cont_style;//一定要设置static或者全局
lv_style_copy(&cont_style,&lv_style_plain_color);//样式拷贝,可以减少重复设置,可以不复制
//设置纯红色的背景
cont_style.body.main_color = LV_COLOR_RED;
cont_style.body.grad_color = LV_COLOR_RED;
//设置容器的4个内边距
cont_style.body.padding.top = 10;
cont_style.body.padding.left = 10;
cont_style.body.padding.right = 10;
cont_style.body.padding.bottom = 10;
cont_style.body.padding.inner = 10;//设置容器中子对象之间的间隙
lv_cont_set_style(cont,LV_CONT_STYLE_MAIN,&cont_style);//给容器设置样式