diff --git a/docs/overview/animation.md b/docs/overview/animation.md index 9b5d61a80..428942bce 100644 --- a/docs/overview/animation.md +++ b/docs/overview/animation.md @@ -117,6 +117,8 @@ Finally, call `lv_anim_timeline_start(at)` to start the animation timeline. It supports forward and backward playback of the entire animation group, using `lv_anim_timeline_set_reverse(at, reverse)`. +Call the `lv_anim_timeline_stop(at)` to stop the animation timeline. + Call the `lv_anim_timeline_set_progress(at, progress)` function to set the state of the object corresponding to the progress of the timeline. Call the `lv_anim_timeline_get_playtime(at)` function to get the total duration of the entire animation timeline. diff --git a/examples/anim/lv_example_anim_timeline_1.c b/examples/anim/lv_example_anim_timeline_1.c index 3d8dc33ca..c1575f7a1 100644 --- a/examples/anim/lv_example_anim_timeline_1.c +++ b/examples/anim/lv_example_anim_timeline_1.c @@ -89,7 +89,7 @@ static void anim_timeline_create(void) lv_anim_timeline_add(anim_timeline, 400, &a6); } -static void btn_run_event_handler(lv_event_t * e) +static void btn_start_event_handler(lv_event_t * e) { lv_obj_t * btn = lv_event_get_target(e); @@ -111,6 +111,14 @@ static void btn_del_event_handler(lv_event_t * e) } } +static void btn_stop_event_handler(lv_event_t * e) +{ + LV_UNUSED(e); + if (anim_timeline) { + lv_anim_timeline_stop(anim_timeline); + } +} + static void slider_prg_event_handler(lv_event_t * e) { lv_obj_t * slider = lv_event_get_target(e); @@ -132,31 +140,45 @@ void lv_example_anim_timeline_1(void) lv_obj_set_flex_flow(par, LV_FLEX_FLOW_ROW); lv_obj_set_flex_align(par, LV_FLEX_ALIGN_SPACE_AROUND, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER); - lv_obj_t * btn_run = lv_btn_create(par); - lv_obj_add_event_cb(btn_run, btn_run_event_handler, LV_EVENT_VALUE_CHANGED, NULL); - lv_obj_add_flag(btn_run, LV_OBJ_FLAG_IGNORE_LAYOUT); - lv_obj_add_flag(btn_run, LV_OBJ_FLAG_CHECKABLE); - lv_obj_align(btn_run, LV_ALIGN_TOP_MID, -50, 20); + /* create btn_start */ + lv_obj_t * btn_start = lv_btn_create(par); + lv_obj_add_event_cb(btn_start, btn_start_event_handler, LV_EVENT_VALUE_CHANGED, NULL); + lv_obj_add_flag(btn_start, LV_OBJ_FLAG_IGNORE_LAYOUT); + lv_obj_add_flag(btn_start, LV_OBJ_FLAG_CHECKABLE); + lv_obj_align(btn_start, LV_ALIGN_TOP_MID, -100, 20); - lv_obj_t * label_run = lv_label_create(btn_run); - lv_label_set_text(label_run, "Run"); - lv_obj_center(label_run); + lv_obj_t * label_start = lv_label_create(btn_start); + lv_label_set_text(label_start, "Start"); + lv_obj_center(label_start); + /* create btn_del */ lv_obj_t * btn_del = lv_btn_create(par); lv_obj_add_event_cb(btn_del, btn_del_event_handler, LV_EVENT_CLICKED, NULL); lv_obj_add_flag(btn_del, LV_OBJ_FLAG_IGNORE_LAYOUT); - lv_obj_align(btn_del, LV_ALIGN_TOP_MID, 50, 20); + lv_obj_align(btn_del, LV_ALIGN_TOP_MID, 0, 20); lv_obj_t * label_del = lv_label_create(btn_del); - lv_label_set_text(label_del, "Stop"); + lv_label_set_text(label_del, "Delete"); lv_obj_center(label_del); + /* create btn_stop */ + lv_obj_t * btn_stop = lv_btn_create(par); + lv_obj_add_event_cb(btn_stop, btn_stop_event_handler, LV_EVENT_CLICKED, NULL); + lv_obj_add_flag(btn_stop, LV_OBJ_FLAG_IGNORE_LAYOUT); + lv_obj_align(btn_stop, LV_ALIGN_TOP_MID, 100, 20); + + lv_obj_t * label_stop = lv_label_create(btn_stop); + lv_label_set_text(label_stop, "Stop"); + lv_obj_center(label_stop); + + /* create slider_prg */ lv_obj_t * slider_prg = lv_slider_create(par); lv_obj_add_event_cb(slider_prg, slider_prg_event_handler, LV_EVENT_VALUE_CHANGED, NULL); lv_obj_add_flag(slider_prg, LV_OBJ_FLAG_IGNORE_LAYOUT); lv_obj_align(slider_prg, LV_ALIGN_BOTTOM_MID, 0, -20); lv_slider_set_range(slider_prg, 0, 65535); + /* create 3 objects */ obj1 = lv_obj_create(par); lv_obj_set_size(obj1, obj_width, obj_height); diff --git a/src/misc/lv_anim_timeline.c b/src/misc/lv_anim_timeline.c index 77b86c8b4..e28223c8f 100644 --- a/src/misc/lv_anim_timeline.c +++ b/src/misc/lv_anim_timeline.c @@ -62,10 +62,7 @@ void lv_anim_timeline_del(lv_anim_timeline_t * at) { LV_ASSERT_NULL(at); - for(uint32_t i = 0; i < at->anim_dsc_cnt; i++) { - lv_anim_t * a = &(at->anim_dsc[i].anim); - lv_anim_custom_del(a, (lv_anim_custom_exec_cb_t)a->exec_cb); - } + lv_anim_timeline_stop(at); lv_mem_free(at->anim_dsc); lv_mem_free(at); @@ -111,6 +108,16 @@ uint32_t lv_anim_timeline_start(lv_anim_timeline_t * at) return playtime; } +void lv_anim_timeline_stop(lv_anim_timeline_t * at) +{ + LV_ASSERT_NULL(at); + + for(uint32_t i = 0; i < at->anim_dsc_cnt; i++) { + lv_anim_t * a = &(at->anim_dsc[i].anim); + lv_anim_custom_del(a, (lv_anim_custom_exec_cb_t)a->exec_cb); + } +} + void lv_anim_timeline_set_reverse(lv_anim_timeline_t * at, bool reverse) { LV_ASSERT_NULL(at); diff --git a/src/misc/lv_anim_timeline.h b/src/misc/lv_anim_timeline.h index ba3cdba52..ed8782e19 100644 --- a/src/misc/lv_anim_timeline.h +++ b/src/misc/lv_anim_timeline.h @@ -58,6 +58,12 @@ void lv_anim_timeline_add(lv_anim_timeline_t * at, uint32_t start_time, lv_anim_ */ uint32_t lv_anim_timeline_start(lv_anim_timeline_t * at); +/** + * Stop the animation timeline. + * @param at pointer to the animation timeline. + */ +void lv_anim_timeline_stop(lv_anim_timeline_t * at); + /** * Set the playback direction of the animation timeline. * @param at pointer to the animation timeline.