Hi,大家好,欢迎来到树莓派之littlevGL课堂,我们在上节课中学习了消息弹窗控件(lv_mbox),本节课带大家学习页面控件,所谓的页面大家可以理解成一个长的文本显示区域,然后我们可以滚动显示查看文本,那么废话不多说! 一 有图有真相 二 代码分析 用户可下载"圆弧对象(lv_arc)的使用"文章末尾的Demo工程(点击我直接下载),参考圆弧对象(lv_arc)的使用文章,将以下Demo代码复制到Demo工程test.c文件空白处.然后在test.c文件的create_test()函数中增加page_test()函数测试。 void page_test(void) { /*Create a scroll bar style*/ static lv_style_t style_sb; lv_style_copy(&style_sb, &lv_style_plain); style_sb.body.main_color = LV_COLOR_BLACK; style_sb.body.grad_color = LV_COLOR_BLACK; style_sb.body.border.color = LV_COLOR_WHITE; style_sb.body.border.width = 1; style_sb.body.border.opa = LV_OPA_70; style_sb.body.radius = LV_RADIUS_CIRCLE; style_sb.body.opa = LV_OPA_60; style_sb.body.padding.right = 3; style_sb.body.padding.bottom = 3; style_sb.body.padding.inner = 8; /*Scrollbar width*/ /*Create a page*/ lv_obj_t * page = lv_page_create(lv_scr_act(), NULL); lv_obj_set_size(page, 150, 200); lv_obj_align(page, NULL, LV_ALIGN_CENTER, 0, 0); lv_page_set_style(page, LV_PAGE_STYLE_SB, &style_sb); /*Set the scrollbar style*/ /*Create a label on the page*/ lv_obj_t * label = lv_label_create(page, NULL); lv_label_set_long_mode(label, LV_LABEL_LONG_BREAK); /*Automatically break long lines*/ lv_obj_set_width(label, lv_page_get_fit_width(page)); /*Set the label width to max value to not show hor. scroll bars*/ lv_label_set_text(label, "Lorem ipsum dolor sit amet, consectetur adipiscing elit,\n" "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\n" "Ut enim ad minim veniam, quis nostrud exercitation ullamco\n" "laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure\n" "dolor in reprehenderit in voluptate velit esse cillum dolore\n" "eu fugiat nulla pariatur.\n" "Excepteur sint occaecat cupidatat non proident, sunt in culpa\n" "qui officia deserunt mollit anim id est laborum."); } style_sb.body.main_color = LV_COLOR_BLACK; style_sb.body.grad_color = LV_COLOR_BLACK; style_sb.body.border.color = LV_COLOR_WHITE; style_sb.body.border.width = 1; style_sb.body.border.opa = LV_OPA_70; style_sb.body.radius = LV_RADIUS_CIRCLE; style_sb.body.opa = LV_OPA_60; style_sb.body.padding.right = 3; style_sb.body.padding.bottom = 3; style_sb.body.padding.inner = 8; 然后我们创建了一个页面对象,就跟创建别的对象一样,设置大小为150*200,然后将我们设置好的滑块样式设置好,但是我们只创建个页面是什么都没有的,所以这里我们还在页面内部创建了一个标签对象,用来展示文本,所以我们创建标签对象是指定页面对象为父对象: lv_obj_t * label = lv_label_create(page, NULL); lv_label_set_long_mode(label, LV_LABEL_LONG_BREAK); 大家有没有学会呢?OK,本节课就到这里,我们下节课学习预加载控件(lv_perload),我们下节课再见! |