Good morning,
I want to successively display the examples included in the LVGL library. The major difficulty is to correctly release the resources between each example.
I would like to know if it is possible to erase all the screens created previously without knowing their numbers and identifiers?
Is there a function that would remove all inactive screens?
Is there a function that would allow to have the number of screens created? Or the number of objects that have no parent? I think it would be the same, it would allow using lv_obj_del().
What have you tried so far?
I saw that the lv_obj_clean() function allows to delete all the children of a screen (with the lv_scr_act() parameter for the active screen).
The lv_obj_del() and lv_obj_del_async() functions are used to delete a screen, except the active screen.
I think the best way is to have a handler for each screen and a structure that contains the elements for each one.
In my application I created a function responsible for initializing and deallocating the resources based on a variable that has the current and the old screen.
It is important to note that in this model each screen has a function that initializes its elements.
Thank you for your answer.
Sorry to only answer now, I only just tried the code you posted.
This code looks interesting, but I can’t get it to work, it looks like there are several errors in this code.
After looking at the Create screens part of this page: Objects — LVGL documentation I replaced the line: static lv_obj_t * scrYourScreen1 = NULL;
by
Here is my best solution to manage screens and remove the previous screen automatically when I load a new one :
gui_loader.h
#ifndef GUI_PAGE_LOADER_H
#define GUI_PAGE_LOADER_H
#define CAT_NAME_FUN(name, fun) name##fun
#define LOAD_PAGE(page) CAT_NAME_FUN(page, _create()) // this will add _create to the name of the page in the enumeration
#define DEL_PAGE(page) CAT_NAME_FUN(page, _delete()) // this will add _delete
// so, LOAD_PAGE will call a function gui_page_whatever_create()
// and DEL_PAGE will call a function gui_page_whatever_delete()
// and both of this functions should be contained in each page screen.
/* INCLUDES */
#include "page_home.h"
#include "page_prepare.h"
#include "page_wifi.h"
/* PAGES */
typedef enum {
gui_page_home,
gui_page_prepare,
gui_page_wifi
} gui_pages_t;
gui_pages_t gui_loader_get_current_page();
void gui_loader_set_current_page(gui_pages_t page);
#define NAVIGATE_TO(parent, page) {LOAD_PAGE(page); DEL_PAGE(parent); gui_loader_set_current_page(page);}
#endif