Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
feat(obj) add lv_obj_del_delayed()
  • Loading branch information
kisvegabor committed Jun 12, 2021
1 parent 6f37c4f commit c6a2e15
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/overview/object.md
Expand Up @@ -121,6 +121,8 @@ This is useful e.g. if you want to delete the parent of an object in the child's
You can remove all the children of an object (but not the object itself) using `lv_obj_clean(obj)`.
You can use `lv_obj_del_delayed(obj, 1000)` to delete an object after some time. The delay is expressed in millliseconds.
## Screens
Expand Down
12 changes: 12 additions & 0 deletions src/core/lv_obj_tree.c
Expand Up @@ -106,6 +106,18 @@ void lv_obj_clean(lv_obj_t * obj)
LV_LOG_TRACE("finished (delete %p)", obj)
}

void lv_obj_del_delayed(lv_obj_t * obj, uint32_t delay_ms)
{
lv_anim_t a;
lv_anim_init(&a);
lv_anim_set_var(&a, obj);
lv_anim_set_exec_cb(&a, NULL);
lv_anim_set_time(&a, 1);
lv_anim_set_delay(&a, delay_ms);
lv_anim_set_ready_cb(&a, lv_obj_del_anim_ready_cb);
lv_anim_start(&a);
}

void lv_obj_del_anim_ready_cb(lv_anim_t * a)
{
lv_obj_del(a->var);
Expand Down
7 changes: 7 additions & 0 deletions src/core/lv_obj_tree.h
Expand Up @@ -56,6 +56,13 @@ void lv_obj_del(struct _lv_obj_t * obj);
*/
void lv_obj_clean(struct _lv_obj_t * obj);

/**
* Delete an object after some delay
* @param obj pointer to an object
* @param delay_ms time to wait before delete in milliseconds
*/
void lv_obj_del_delayed(struct _lv_obj_t * obj, uint32_t delay_ms);

/**
* A function to be easily used in animation ready callback to delete an object when the animation is ready
* @param a pointer to the animation
Expand Down

0 comments on commit c6a2e15

Please sign in to comment.