feat(anim): add deleted callback (#3279) (#3295)

Co-authored-by: qinshijing <qinshijing@xiaomi.com>
This commit is contained in:
qinshijing 2022-06-03 17:01:07 +08:00 committed by GitHub
parent ce0605182c
commit e59c83b453
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 0 deletions

View File

@ -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);

View File

@ -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*/

View File

@ -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; /**<Variable to animate*/
lv_anim_exec_xcb_t exec_cb; /**< Function to execute to animate*/
lv_anim_start_cb_t start_cb; /**< Call it when the animation is starts (considering `delay`)*/
lv_anim_ready_cb_t ready_cb; /**< Call it when the animation is ready*/
lv_anim_deleted_cb_t deleted_cb; /**< Call it when the animation is deleted*/
lv_anim_get_value_cb_t get_value_cb; /**< Get the current value in relative mode*/
#if LV_USE_USER_DATA
void * user_data; /**< Custom user data*/
@ -225,6 +229,16 @@ static inline void lv_anim_set_ready_cb(lv_anim_t * a, lv_anim_ready_cb_t ready_
a->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