Littlevgl multiple screens


I’m using the littlevgl library on a PIC32MK1024GPD micro-controller with a 320x240 TFT display. The application I’m designing contains multiple screens where the user needs to navigate. I saw from the documentation that I can create multiple screens using littlevgl and than hide/show the ones I need during run time. The issue with this is that I would be consuming RAM also for the hidden screens. Thus, I’m using only one screen and delete all the children and re-create them according to the screen to display.

As for menu structure, I made a very basic thing myself but I was asking if there is a ‘proper’ way to do this when using the littlevgl library. So my question is, is there a proper way when using littlevgl to perform menu/screens navigation without having a screen object for every screen?


1 Like


You can create a stack of objects and make each one be the parent of a different screen and point lvgl to the top of the stack.

To save ram you could stack function pointers that build the screen on demand.


I get your e-mail,i understand you question.

You can create multiple screens, in order to save memory, every screen, you write code. When you switch the screen, remove the original screen, screen to load the new code.

To load a screen, use lv_scr_load(scr). To get the active screen, use lv_scr_act().

Screens can be deleted with lv_obj_del(scr), but ensure that you do not delete the currently loaded screen.

This is a example for you.
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!");


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); 



Thanks for the example. If I’m understanding correctly, i make every page of my menu as a screen which is drawn/deleted as required. So every time I need to change the page, I would delete the current screen using lv_obj_del(scr) and re-draw the screen and load it using lv_scr_load(scr).

What I’m trying to work around now is the menu navigation. So to have buttons to change different screens. After some search, I came across the lv_ex_settings example which could give me an idea of how to structure the menu navigation. From what I can tell, is still a work in progress but I haven’t tried it yet.

Do you have an idea of how can I structure a menu tree, for example, having the home page with 4 buttons, thus 4 possible pages, with each page having its own nested pages etc…