I’m encountering two issues while trying to animate and delete a popup in my project:
- Animation not moving the popup: I am attempting to animate a popup so that it moves vertically (in the Y direction) using
lv_anim_set_exec_cbwithlv_obj_set_y. However, the popup remains stationary, and the animation does not seem to have any effect. - Deleting the popup after the animation: I would like the popup to be deleted automatically once the animation finishes. I tried using
lv_anim_set_ready_cbwith a custom callback to delete the object, but it doesn’t seem to work as expected.
follow the code to reproduce:
lv_obj_t *popup;
static void delete_label_callback(lv_anim_t *a) {
lv_obj_del(popup);
}
void create_popup_label(char *text) {
popup = lv_obj_create(lv_scr_act());
lv_obj_set_size(popup, 100, 75);
lv_obj_align(popup, LV_ALIGN_CENTER, 0, 0);
lv_obj_set_style_bg_color(popup, lv_color_hex(0xFFFFFF), 0);
lv_obj_set_style_border_color(popup, lv_color_hex(0x000000), 0);
lv_obj_set_style_border_width(popup, 2, 0);
lv_obj_t *label = lv_label_create(popup);
lv_label_set_text(label, text);
lv_obj_center(label);
lv_anim_t a;
lv_anim_init(&a);
lv_anim_set_var(&a, popup);
lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t) lv_obj_set_y);
int start_y = lv_obj_get_y(popup);
lv_anim_set_values(&a, start_y, start_y - 50);
lv_anim_set_time(&a, 500);
lv_anim_set_delay(&a, 2000);
lv_anim_start(&a);
lv_anim_set_ready_cb(&a, delete_label_callback);
lv_anim_start(&a);
}