LVGL(三) 对象中创建对象
万物源于对象
lv_obj_t *lv_example_time_page(lv_obj_t *scr) {
// 创建时间显示容器的对象
lv_obj_t *time_container = lv_obj_create(scr);
// 设置容器样式
static lv_style_t container_style;
lv_style_init(&container_style);
lv_style_set_width(&container_style,250);
lv_style_set_height(&container_style,90);
lv_style_set_align(&container_style,LV_ALIGN_CENTER);
lv_style_set_border_width(&container_style, 0);
lv_style_set_bg_opa(&container_style, LV_OPA_TRANSP);
lv_obj_add_style(time_container, &container_style, LV_PART_MAIN);
// 在容器中创建对象,该对象为文本
time_label = lv_label_create(time_container);
lv_label_set_text(time_label, "00:00:00");
// 设置文本对象样式
static lv_style_t time_style;
lv_style_init(&time_style);
lv_style_set_text_font(&time_style, &lv_font_montserrat_48);
lv_style_set_align(&container_style,LV_ALIGN_CENTER);
lv_obj_add_style(time_label, &time_style, LV_PART_MAIN);
}
License:
CC BY 4.0