Deleting object after animation


Hi, i am following the animations video tutorial in the LVGL academy however the ‘toast’ is still active after the opacity is set to 0, therefore any buttons which were placed in the same place as the pop up is now covered by the 0 opacity alert.

When i try to delete the alert after the opacity is set to 0, it does not reduce the opacity graduallly and rather just deletes it instantly.

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

VS Sim

What LVGL version are you using?


What do you want to achieve?

delete the alert after the fade out transition

What have you tried so far?

Code to reproduce

Add a code snippet which can run in the simulator. It should contain only the relevant code that compiles without errors when separated from your main code base.

The code block(s) should be formatted like:

void change_opa(lv_obj_t* obj, uint16_t val)
    lv_obj_set_style_local_opa_scale(obj, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, val);

void ready_cb(lv_anim_t* old_anim)
    lv_obj_t* alert = (lv_obj_t*)old_anim->var;
    lv_anim_t a;
    lv_anim_set_var(&a, alert);

    lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)change_opa);
    lv_anim_set_values(&a, 255, 50);
    lv_anim_set_time(&a, 1000);
    lv_anim_set_delay(&a, 1000);
    animready = TRUE;


 void message_alert(char* message)
     animready = FALSE;
    lv_obj_t* alert = lv_obj_create(lv_scr_act(), NULL);
    uint16_t height = 30;
    lv_obj_set_size(alert, lv_obj_get_width_fit(lv_scr_act()), height);
    lv_obj_set_y(alert, lv_obj_get_height_fit(lv_scr_act()) - height);
    lv_obj_set_style_local_bg_color(alert, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_RED);
    lv_obj_set_style_local_text_color(alert, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE);
    lv_obj_t* message_label = lv_label_create(alert, NULL);
    lv_label_set_text(message_label, message);
    lv_obj_align(message_label,NULL, LV_ALIGN_CENTER, 0, 0);

    lv_anim_t a;
    lv_anim_set_var(&a, alert);

    lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)lv_obj_set_y);
    lv_anim_set_values(&a, lv_obj_get_height_fit(lv_scr_act()), lv_obj_get_height_fit(lv_scr_act()) - height);
    lv_anim_set_time(&a, 1000);


    lv_anim_set_ready_cb(&a, ready_cb);

    //lv_anim_set_playback_time(&a, 1000);
    //lv_anim_set_playback_delay(&a, 1000);

 void btn_check(lv_obj_t* lightingbuttonA, lv_event_t event)
     lv_btn_state_t state = lv_btn_get_state(lightingbuttonA);
     if ((state == LV_BTN_STATE_RELEASED) && (animready == TRUE))
         message_alert("You Are Not Authorised To Use This Device");

Screenshot and/or video

If possible, add screenshots and/or videos about the current state.

I believe you need to call lv_obj_del_async at the end of the second animation, not the first one.

I was under the impression that the second animation is the one in the function ‘ready_cb’? Is that not correct?

No. There is a second animation created inside ready_cb. Animations run asynchronously over a period of time, so you need to apply a different ready_cb to the new animation in which you delete the object.