Hi,大家好,欢迎来到STM32之littlevGL课堂,我们在上节课中学习了选项卡控件(lv_tabview),本节课带大家学习窗口控件,废话不多说! 一 有图有真相 二 代码分析 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); } } 最后就是在串口对象内创建了一个标签,当然我们最后删除窗口对象时,这个窗口对象的子对象也是一起递归删除的。 OK,本节课就到这里,而且所有的自带控件我们都学完了,大家掌握了多少呢? |