How to hide window and delete childs

How to delete child of window e.g list

What MCU/Processor/Board and compiler are you using?


What do you want to achieve?

I want to achieve that the window close button, deletes the childs of win + hides.

What have you tried so far?

static void event_handler_hide(lv_obj_t * obj, lv_event_t event)
  lv_obj_set_hidden(win, true);

I have added a list to the window and on click on window close btn the esp32 reboots. I guess it’s related to the list object?!

Code to reproduce

lv_obj_t * win;
static void create_tab3(lv_obj_t * parent)

  win = lv_win_create(parent, NULL);
  lv_win_set_title(win, "Title");                        /*Set the title*/
  lv_obj_align(win, parent, LV_ALIGN_CENTER, 50, 0);
  lv_win_set_layout(win, LV_LAYOUT_PRETTY);
  lv_obj_set_size(win, 230, 200);
  lv_obj_set_hidden(win, true);
  /*Add control button to the header*/
  lv_obj_t * close_btn = lv_win_add_btn(win, LV_SYMBOL_CLOSE);           /*Add close button and use  hide action*/
  lv_obj_set_event_cb(close_btn, event_handler_hide);
  lv_win_add_btn(win, LV_SYMBOL_OK);        /*Add a setup button*/

Is there something i’ve missed?

Many events can be fired by a button (not just the click event).

I recommend that you add an if statement checking for LV_EVENT_RELEASED (or a similar event) and delete the objects in there.

I’ve added the if statement as suggested and it works. Thank you :slight_smile: