Hide all objects - What is the easiest way?

I have many objects created like this…

lv_obj_t * slider = lv_slider_create(lv_scr_act(), NULL);

and i wish to hide ALL of the objects created with something like…

lv_obj_set_hidden(slider, true);

Is there a simple way i can do this for all of my objects rather than just one at a time?


Hi @flossandmeditate,

I would create your sliders as an array of pointers…

lv_obj_t * slider[NO_SLIDERS];

for( i=0; i<NO_SLIDERS; i++ ) {
    slider[i] = lv_slider_create(lv_scr_act(), NULL);
    lv_obj_set_hidden(slider[i], true);

Also you could create an enum for the index to make it easier to track the individual sliders.

For Example:

enum slider_names {

Then reference the array using the enum as follows:

lv_obj_set_event_cb(slider[Sldr_Volume], volume_handler);

Hope that helps.

Kind Regards,



what is [NO_SLIDERS]
can you please tell me?
Array or it is simple total no of all enums .

lv_obj_add_flag(lv_obj_t * obj, lv_obj_flag_t f);
lv_obj_t * obj ______________ here i have for example ui_Panel11 and i have 20 Panels so i want a loop that will do something like.

for (i=0;i<21;i++)
lv_obj_add_flag(ui_Panel, LV_OBJ_FLAG_HIDDEN));
hide one and unhide all others.

i see it is pointer (lv_obj_t *) strcut but i dont know how i can do this alternative instead of writing 20 lines with lot of ifs.

lv_obj_add_flag(“”“”“”““her i want something to loop for 20 Panels)””“”“”“”", LV_OBJ_FLAG_HIDDEN));

Hey you reply to 2020 message…

If you have answer!

all you have to do is hide the parent object. In this case the parent object is the screen.

lv_obj_t *screen = lv_screen_active();

lv_obj_add_flag(screen, LV_OBJ_FLAG_HIDDEN));

lv_obj_t *new_screen = lv_obj_create(NULL);

the new screen you can add UI elements to if you want.

another way is to iterate over the children in a screen and hide them

lv_obj_t *screen = lv_screen_active();
uint32_t child_count = lv_obj_get_child_count(screen);

for(uint32_t i=0;i<child_count;i++) {
    lv_obj_add_flag(lv_obj_get_child(screen, i), LV_OBJ_FLAG_HIDDEN);

either one of those would work.

and if you want to explicitly set the hidden flag on all UI elements you would use the following.

void recursive_hide(lv_obj_t *parent);

void recursive_hide(lv_obj_t *parent)

    uint32_t child_count = lv_obj_get_child_count(parent);
    lv_obj_t *child;

    for(uint32_t i=0;i<child_count;i++) {
        child = lv_obj_get_child(parent, i);
        lv_obj_add_flag(child, LV_OBJ_FLAG_HIDDEN);

lv_obj_t *screen = lv_screen_active();

I have input like int 20 ,
so i have already created Panels1 to Panels 20.
It means if i enter 10 it will hide 10 Panels if i enter 20 it will hide 20 elements.

I want to hide in loop
lv_obj_add_flag(Panels1 to Panels20, LV_OBJ_FLAG_HIDDEN));

uint32_t i;
for(i = 0; i < lv_obj_get_child_count(parent); i++) {
lv_obj_t * child = lv_obj_get_child(parent, i);
/Do something with child/

Here is the same idea, thank you for hinting me. Thanks

The store the panels in an array and iterate over that array…

lv_obj_t *panels[20];

// create your panels and store them in the array
lv_obj_t *panel = lv_obj_create(lv_screen_active());
panels[0] = panel;

// rest of code to add to the panel and to create other panels goes here. 

for(uint8_t i=0;i<20;i++) {
    lv_obj_add_flag(panels[i], LV_OBJ_FLAG_HIDDEN);

Thanks man for your answer .

no worries m8, Hopefully it helped you out.

If one of the responses I gave was the solution please mark that response as the solution so others will know there is a solution that was found.

Based on thread subject valid response is dont waste MCU cycles and simply switch to empty screen.
And only autor can mark valod response.

1 Like