Hi,大家好,欢迎来到树莓派之littlevGL课堂,我们在上节课中学习了选项卡控件(lv_tabview),本节课带大家学习窗口控件,废话不多说! 一 有图有真相 二 代码分析 用户可下载"圆弧对象(lv_arc)的使用"文章末尾的Demo工程(点击我直接下载),参考圆弧对象(lv_arc)的使用文章,将以下Demo代码复制到Demo工程test.c文件空白处.然后在test.c文件的create_test()函数中增加win_test()函数测试。 void win_test(void) { /*Create a window*/ lv_obj_t * win = lv_win_create(lv_scr_act(), NULL); lv_win_set_title(win, "Window title"); /*Set the title*/ /*Add control button to the header*/ lv_obj_t * close_btn = lv_win_add_btn(win, LV_SYMBOL_CLOSE); /*Add close button and use built-in close action*/ lv_obj_set_event_cb(close_btn, lv_win_close_event_cb); lv_win_add_btn(win, LV_SYMBOL_SETTINGS); /*Add a setup button*/ /*Add some dummy content*/ lv_obj_t * txt = lv_label_create(win, NULL); lv_label_set_text(txt, "This is the content of the window\n\n" "You can add control buttons to\n" "the window header\n\n" "The content area becomes automatically\n" "scrollable is it's large enough.\n\n" " You can scroll the content\n" "See the scroll bar on the right!"); } 我们创建了一个窗口对象,然后通过以下API设置窗口标题为 Window title: lv_win_set_title(win, "Window title"); lv_obj_t * close_btn = lv_win_add_btn(win, LV_SYMBOL_CLOSE); /*Add close button and use built-in close action*/ lv_obj_set_event_cb(close_btn, lv_win_close_event_cb); lv_win_add_btn(win, LV_SYMBOL_SETTINGS); void lv_win_close_event_cb(lv_obj_t * btn, lv_event_t event) { if(event == LV_EVENT_RELEASED) { lv_obj_t * win = lv_win_get_from_btn(btn); lv_obj_del(win); } } 其实就是通过调用lv_obj_del这个API将我们的窗口对象删除了,所以大家点击关闭按钮的时候窗口就消失不见了,当然你也可以对设置按钮写一个回调函数,用来设置某些属性。 最后就是在串口对象内创建了一个标签,当然我们最后删除窗口对象时,这个窗口对象的子对象也是一起递归删除的。 OK,本节课就到这里,而且所有的自带控件我们都学完了,大家掌握了多少呢? |