Calendar - Best way to close/delete object


I have created a calendar on a window popup. Is there a cancel option to close it? If not what would be the bext way of closing/deleting the window?

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


What LVGL version are you using?


What do you want to achieve?

As described

What have you tried so far?

Selecting the date and using the callback but I’d like an X button somewhere…

Code to reproduce

void cb_setLeavingDate(lv_event_t * event)
    lv_obj_t * cont = lv_win_get_content(holidy_mode_window);  /*Content can be added here*/
    lv_obj_t  * calendar = lv_calendar_create(cont);
    lv_obj_set_size(calendar, 385, 385);
    lv_obj_align(calendar, LV_ALIGN_CENTER, 0, 0);
    lv_obj_add_event_cb(calendar, cb_calendar_leavingDate, LV_EVENT_ALL, NULL);

    lv_calendar_set_today_date(calendar, 2022, 03, 8);
    lv_calendar_set_showed_date(calendar, 2022, 03);

    /*Highlight a few days*/
    static lv_calendar_date_t highlighted_days[1];       /*Only its pointer will be saved so should be static*/
    highlighted_days[0].year = 2021;
    highlighted_days[0].month = 03;
    highlighted_days[0].day = 8;

    lv_calendar_set_highlighted_dates(calendar, highlighted_days, 3);


    lv_calendar_set_showed_date(calendar, 2022, 3);

Screenshot and/or video

I’m not sure if its the best approach but I ended up wrapping the calendar in a window lv_win…

So, one way is that you can lv_obj_del(calender); when a callback is called or a confirm button is selected.

Yeh, I started down that route but I didnt want to close (delete it) when a date was selected and there wasnt anywhere to put a confirm button. Hence the window wrapper:


Thanks :slight_smile: