From e59c83b453cc09fba87909189a8c4acd373be939 Mon Sep 17 00:00:00 2001 From: qinshijing <51692568+qinshijing@users.noreply.github.com> Date: Fri, 3 Jun 2022 17:01:07 +0800 Subject: [PATCH] feat(anim): add deleted callback (#3279) (#3295) Co-authored-by: qinshijing --- docs/overview/animation.md | 3 +++ src/misc/lv_anim.c | 2 ++ src/misc/lv_anim.h | 14 ++++++++++++++ 3 files changed, 19 insertions(+) diff --git a/docs/overview/animation.md b/docs/overview/animation.md index 52e271f87..d4800e650 100644 --- a/docs/overview/animation.md +++ b/docs/overview/animation.md @@ -48,6 +48,9 @@ lv_anim_set_path(&a, lv_anim_path_ease_in); /*Set a callback to indicate when the animation is ready (idle).*/ lv_anim_set_ready_cb(&a, ready_cb); +/*Set a callback to indicate when the animation is deleted (idle).*/ +lv_anim_set_deleted_cb(&a, deleted_cb); + /*Set a callback to indicate when the animation is started (after delay).*/ lv_anim_set_start_cb(&a, start_cb); diff --git a/src/misc/lv_anim.c b/src/misc/lv_anim.c index 133b59ff3..4e4253a6e 100644 --- a/src/misc/lv_anim.c +++ b/src/misc/lv_anim.c @@ -147,6 +147,7 @@ bool lv_anim_del(void * var, lv_anim_exec_xcb_t exec_cb) if((a->var == var || var == NULL) && (a->exec_cb == exec_cb || exec_cb == NULL)) { _lv_ll_remove(&LV_GC_ROOT(_lv_anim_ll), a); + if(a->deleted_cb != NULL) a->deleted_cb(a); lv_mem_free(a); anim_mark_list_change(); /*Read by `anim_timer`. It need to know if a delete occurred in the linked list*/ @@ -434,6 +435,7 @@ static void anim_ready_handler(lv_anim_t * a) /*Call the callback function at the end*/ if(a->ready_cb != NULL) a->ready_cb(a); + if(a->deleted_cb != NULL) a->deleted_cb(a); lv_mem_free(a); } /*If the animation is not deleted then restart it*/ diff --git a/src/misc/lv_anim.h b/src/misc/lv_anim.h index 3a8dc30f7..faef72787 100644 --- a/src/misc/lv_anim.h +++ b/src/misc/lv_anim.h @@ -66,12 +66,16 @@ typedef void (*lv_anim_start_cb_t)(struct _lv_anim_t *); /** Callback used when the animation values are relative to get the current value*/ typedef int32_t (*lv_anim_get_value_cb_t)(struct _lv_anim_t *); +/** Callback used when the animation is deleted*/ +typedef void (*lv_anim_deleted_cb_t)(struct _lv_anim_t *); + /** Describes an animation*/ typedef struct _lv_anim_t { void * var; /**ready_cb = ready_cb; } +/** + * Set a function call when the animation is deleted. + * @param a pointer to an initialized `lv_anim_t` variable + * @param deleted_cb a function call when the animation is deleted + */ +static inline void lv_anim_set_deleted_cb(lv_anim_t * a, lv_anim_deleted_cb_t deleted_cb) +{ + a->deleted_cb = deleted_cb; +} + /** * Make the animation to play back to when the forward direction is ready * @param a pointer to an initialized `lv_anim_t` variable