diff --git a/demos/benchmark/lv_demo_benchmark.c b/demos/benchmark/lv_demo_benchmark.c index f9f67070c..b2a67a45c 100644 --- a/demos/benchmark/lv_demo_benchmark.c +++ b/demos/benchmark/lv_demo_benchmark.c @@ -766,7 +766,7 @@ static void arc_anim(lv_obj_t * obj) lv_anim_set_exec_cb(&a, arc_anim_cb); lv_anim_set_values(&a, 0, 100); lv_anim_set_duration(&a, t1); - lv_anim_set_playback_duration(&a, t2); + lv_anim_set_reverse_duration(&a, t2); lv_anim_set_var(&a, obj); lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE); lv_anim_start(&a); @@ -787,7 +787,7 @@ static void scroll_anim(lv_obj_t * obj, int32_t y_max) lv_anim_set_exec_cb(&a, scroll_anim_y_cb); lv_anim_set_values(&a, 0, y_max); lv_anim_set_duration(&a, t); - lv_anim_set_playback_duration(&a, t); + lv_anim_set_reverse_duration(&a, t); lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE); lv_anim_start(&a); @@ -808,7 +808,7 @@ static void fall_anim(lv_obj_t * obj, int32_t y_max) lv_anim_set_exec_cb(&a, shake_anim_y_cb); lv_anim_set_values(&a, 0, y_max); lv_anim_set_duration(&a, t1); - lv_anim_set_playback_duration(&a, t2); + lv_anim_set_reverse_duration(&a, t2); lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE); lv_anim_start(&a); } diff --git a/demos/music/lv_demo_music_main.c b/demos/music/lv_demo_music_main.c index 87ad0226f..2d036e950 100644 --- a/demos/music/lv_demo_music_main.c +++ b/demos/music/lv_demo_music_main.c @@ -360,7 +360,7 @@ void lv_demo_music_resume(void) lv_anim_set_exec_cb(&a, spectrum_anim_cb); lv_anim_set_var(&a, spectrum_obj); lv_anim_set_duration(&a, ((spectrum_len - spectrum_i) * 1000) / 30); - lv_anim_set_playback_duration(&a, 0); + lv_anim_set_reverse_duration(&a, 0); lv_anim_set_completed_cb(&a, spectrum_end_cb); lv_anim_start(&a); diff --git a/demos/stress/lv_demo_stress.c b/demos/stress/lv_demo_stress.c index 0b01fec79..c4b3437de 100644 --- a/demos/stress/lv_demo_stress.c +++ b/demos/stress/lv_demo_stress.c @@ -124,7 +124,7 @@ static void obj_test_task_cb(lv_timer_t * tmr) lv_anim_set_duration(&a, LV_DEMO_STRESS_TIME_STEP * 2); lv_anim_set_exec_cb(&a, set_width_anim); lv_anim_set_values(&a, 100, 200); - lv_anim_set_playback_duration(&a, LV_DEMO_STRESS_TIME_STEP * 2); + lv_anim_set_reverse_duration(&a, LV_DEMO_STRESS_TIME_STEP * 2); lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE); lv_anim_start(&a); @@ -227,7 +227,7 @@ static void obj_test_task_cb(lv_timer_t * tmr) lv_anim_set_values(&a, 180, 400); lv_anim_set_duration(&a, LV_DEMO_STRESS_TIME_STEP * 2); lv_anim_set_delay(&a, LV_DEMO_STRESS_TIME_STEP + 25); - lv_anim_set_playback_duration(&a, LV_DEMO_STRESS_TIME_STEP * 5); + lv_anim_set_reverse_duration(&a, LV_DEMO_STRESS_TIME_STEP * 5); lv_anim_set_repeat_count(&a, 3); lv_anim_set_exec_cb(&a, arc_set_end_angle_anim); lv_anim_start(&a); diff --git a/demos/widgets/lv_demo_widgets.c b/demos/widgets/lv_demo_widgets.c index 048807a0c..5062acc99 100644 --- a/demos/widgets/lv_demo_widgets.c +++ b/demos/widgets/lv_demo_widgets.c @@ -235,7 +235,7 @@ void lv_demo_widgets_start_slideshow(void) lv_anim_init(&a); lv_anim_set_exec_cb(&a, scroll_anim_y_cb); lv_anim_set_duration(&a, t); - lv_anim_set_playback_duration(&a, t); + lv_anim_set_reverse_duration(&a, t); lv_anim_set_values(&a, 0, v); lv_anim_set_var(&a, tab); lv_anim_set_completed_cb(&a, slideshow_anim_completed_cb); @@ -701,7 +701,7 @@ static void analytics_create(lv_obj_t * parent) lv_anim_set_exec_cb(&a, scale1_indic1_anim_cb); lv_anim_set_var(&a, arc); lv_anim_set_duration(&a, 4100); - lv_anim_set_playback_duration(&a, 2700); + lv_anim_set_reverse_duration(&a, 2700); lv_anim_start(&a); arc = lv_arc_create(scale1); @@ -717,7 +717,7 @@ static void analytics_create(lv_obj_t * parent) lv_anim_set_exec_cb(&a, scale1_indic1_anim_cb); lv_anim_set_var(&a, arc); lv_anim_set_duration(&a, 2600); - lv_anim_set_playback_duration(&a, 3200); + lv_anim_set_reverse_duration(&a, 3200); lv_anim_start(&a); arc = lv_arc_create(scale1); @@ -733,7 +733,7 @@ static void analytics_create(lv_obj_t * parent) lv_anim_set_exec_cb(&a, scale1_indic1_anim_cb); lv_anim_set_var(&a, arc); lv_anim_set_duration(&a, 2800); - lv_anim_set_playback_duration(&a, 1800); + lv_anim_set_reverse_duration(&a, 1800); lv_anim_start(&a); /*Scale 2*/ @@ -864,7 +864,7 @@ static void analytics_create(lv_obj_t * parent) lv_anim_set_exec_cb(&a, scale3_anim_cb); lv_anim_set_var(&a, scale3); lv_anim_set_duration(&a, 4100); - lv_anim_set_playback_duration(&a, 800); + lv_anim_set_reverse_duration(&a, 800); lv_anim_start(&a); lv_obj_align(scale3_mbps_label, LV_ALIGN_TOP_MID, 10, lv_pct(55)); @@ -1673,7 +1673,7 @@ static void slideshow_anim_completed_cb(lv_anim_t * a_old) lv_anim_init(&a); lv_anim_set_exec_cb(&a, scroll_anim_y_cb); lv_anim_set_duration(&a, t); - lv_anim_set_playback_duration(&a, t); + lv_anim_set_reverse_duration(&a, t); lv_anim_set_values(&a, 0, v); lv_anim_set_var(&a, tab); lv_anim_set_completed_cb(&a, slideshow_anim_completed_cb); diff --git a/docs/details/main-components/animation.rst b/docs/details/main-components/animation.rst index 8396686f7..c2b554867 100644 --- a/docs/details/main-components/animation.rst +++ b/docs/details/main-components/animation.rst @@ -115,10 +115,10 @@ To create an Animation, start by creating an Animation *template* in an lv_anim_set_start_cb(&anim_template, start_cb); /* When ready, play the Animation backward with this duration. Default is 0 (disabled) [ms] */ - lv_anim_set_playback_duration(&anim_template, time); + lv_anim_set_reverse_duration(&anim_template, time); - /* Delay before playback. Default is 0 (disabled) [ms] */ - lv_anim_set_playback_delay(&anim_template, delay); + /* Delay before reverse play. Default is 0 (disabled) [ms] */ + lv_anim_set_reverse_delay(&anim_template, delay); /* Number of repetitions. Default is 1. LV_ANIM_REPEAT_INFINITE for infinite repetition */ lv_anim_set_repeat_count(&anim_template, cnt); @@ -201,10 +201,10 @@ Sometimes an Animation needs to play forward, and then play backwards, effective reversing course, animating from the ``end`` value back to the ``start`` value again. To do this, pass a non-zero value to this function to set the duration for the reverse portion of the Animation: -:cpp:expr:`lv_anim_set_playback_duration(&anim_template, duration_in_ms)`. +:cpp:expr:`lv_anim_set_reverse_duration(&anim_template, duration_in_ms)`. Optionally, you can also introduce a delay between the forward and backward -directions using :cpp:expr:`lv_anim_set_playback_delay(&anim_template, delay_in_ms)` +directions using :cpp:expr:`lv_anim_set_reverse_delay(&anim_template, delay_in_ms)` @@ -321,7 +321,7 @@ easy to create complex composite Animations. To create and use an Animation Tim own copy of the contents of the Animation template, so if you do not need it later, its contents do not need to be preserved after this call. -It supports forward and backward playback of the entire Animation group, using +It supports forward and reverse play of the entire Animation group, using :cpp:expr:`lv_anim_timeline_set_reverse(timeline, reverse)`. Note that if you want to play in reverse from the end of the Timeline, you need to call :cpp:expr:`lv_anim_timeline_set_progress(timeline, LV_ANIM_TIMELINE_PROGRESS_MAX)` @@ -337,7 +337,7 @@ Call :cpp:expr:`lv_anim_timeline_set_progress(timeline, progress)` function to s state of the Animation Timeline according to the ``progress`` value. ``progress`` is a value between ``0`` and ``32767`` (:c:macro:`LV_ANIM_TIMELINE_PROGRESS_MAX`) to indicate the proportion of the Timeline that has "played". Example: a ``progress`` value of -:cpp:expr:`LV_ANIM_TIMELINE_PROGRESS_MAX / 2` would set the Timeline playback to its +:cpp:expr:`LV_ANIM_TIMELINE_PROGRESS_MAX / 2` would set the Timeline play to its half-way point. Call :cpp:expr:`lv_anim_timeline_get_playtime(timeline)` function to get the total diff --git a/examples/anim/lv_example_anim_2.c b/examples/anim/lv_example_anim_2.c index 434e0d1f6..d6d89cfa5 100644 --- a/examples/anim/lv_example_anim_2.c +++ b/examples/anim/lv_example_anim_2.c @@ -28,8 +28,8 @@ void lv_example_anim_2(void) lv_anim_set_var(&a, obj); lv_anim_set_values(&a, 10, 50); lv_anim_set_duration(&a, 1000); - lv_anim_set_playback_delay(&a, 100); - lv_anim_set_playback_duration(&a, 300); + lv_anim_set_reverse_delay(&a, 100); + lv_anim_set_reverse_duration(&a, 300); lv_anim_set_repeat_delay(&a, 500); lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE); lv_anim_set_path_cb(&a, lv_anim_path_ease_in_out); diff --git a/examples/layouts/flex/lv_example_flex_5.c b/examples/layouts/flex/lv_example_flex_5.c index 11d494cb5..06bea9e6c 100644 --- a/examples/layouts/flex/lv_example_flex_5.c +++ b/examples/layouts/flex/lv_example_flex_5.c @@ -39,12 +39,12 @@ void lv_example_flex_5(void) lv_anim_set_exec_cb(&a, row_gap_anim); lv_anim_set_duration(&a, 500); - lv_anim_set_playback_duration(&a, 500); + lv_anim_set_reverse_duration(&a, 500); lv_anim_start(&a); lv_anim_set_exec_cb(&a, column_gap_anim); lv_anim_set_duration(&a, 3000); - lv_anim_set_playback_duration(&a, 3000); + lv_anim_set_reverse_duration(&a, 3000); lv_anim_start(&a); } diff --git a/examples/layouts/grid/lv_example_grid_5.c b/examples/layouts/grid/lv_example_grid_5.c index f5b1a5842..12f395097 100644 --- a/examples/layouts/grid/lv_example_grid_5.c +++ b/examples/layouts/grid/lv_example_grid_5.c @@ -50,12 +50,12 @@ void lv_example_grid_5(void) lv_anim_set_exec_cb(&a, row_gap_anim); lv_anim_set_duration(&a, 500); - lv_anim_set_playback_duration(&a, 500); + lv_anim_set_reverse_duration(&a, 500); lv_anim_start(&a); lv_anim_set_exec_cb(&a, column_gap_anim); lv_anim_set_duration(&a, 3000); - lv_anim_set_playback_duration(&a, 3000); + lv_anim_set_reverse_duration(&a, 3000); lv_anim_start(&a); } diff --git a/examples/widgets/bar/lv_example_bar_3.c b/examples/widgets/bar/lv_example_bar_3.c index af1fa4302..247d97253 100644 --- a/examples/widgets/bar/lv_example_bar_3.c +++ b/examples/widgets/bar/lv_example_bar_3.c @@ -29,7 +29,7 @@ void lv_example_bar_3(void) lv_anim_init(&a); lv_anim_set_exec_cb(&a, set_temp); lv_anim_set_duration(&a, 3000); - lv_anim_set_playback_duration(&a, 3000); + lv_anim_set_reverse_duration(&a, 3000); lv_anim_set_var(&a, bar); lv_anim_set_values(&a, -20, 40); lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE); diff --git a/examples/widgets/bar/lv_example_bar_6.c b/examples/widgets/bar/lv_example_bar_6.c index ad2e37105..5ddf4d2e1 100644 --- a/examples/widgets/bar/lv_example_bar_6.c +++ b/examples/widgets/bar/lv_example_bar_6.c @@ -67,7 +67,7 @@ void lv_example_bar_6(void) lv_anim_set_values(&a, 0, 100); lv_anim_set_exec_cb(&a, set_value); lv_anim_set_duration(&a, 4000); - lv_anim_set_playback_duration(&a, 4000); + lv_anim_set_reverse_duration(&a, 4000); lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE); lv_anim_start(&a); diff --git a/examples/widgets/image/lv_example_image_3.c b/examples/widgets/image/lv_example_image_3.c index 11467930f..844637495 100644 --- a/examples/widgets/image/lv_example_image_3.c +++ b/examples/widgets/image/lv_example_image_3.c @@ -35,7 +35,7 @@ void lv_example_image_3(void) lv_anim_set_exec_cb(&a, set_scale); lv_anim_set_values(&a, 128, 256); - lv_anim_set_playback_duration(&a, 3000); + lv_anim_set_reverse_duration(&a, 3000); lv_anim_start(&a); } diff --git a/examples/widgets/image/lv_example_image_4.c b/examples/widgets/image/lv_example_image_4.c index 40ce31345..e840ce62f 100644 --- a/examples/widgets/image/lv_example_image_4.c +++ b/examples/widgets/image/lv_example_image_4.c @@ -32,7 +32,7 @@ void lv_example_image_4(void) lv_anim_set_exec_cb(&a, ofs_y_anim); lv_anim_set_values(&a, 0, 100); lv_anim_set_duration(&a, 3000); - lv_anim_set_playback_duration(&a, 500); + lv_anim_set_reverse_duration(&a, 500); lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE); lv_anim_start(&a); diff --git a/examples/widgets/scale/lv_example_scale_3.c b/examples/widgets/scale/lv_example_scale_3.c index 25d038daa..f835296eb 100644 --- a/examples/widgets/scale/lv_example_scale_3.c +++ b/examples/widgets/scale/lv_example_scale_3.c @@ -54,7 +54,7 @@ void lv_example_scale_3(void) lv_anim_set_exec_cb(&anim_scale_line, set_needle_line_value); lv_anim_set_duration(&anim_scale_line, 1000); lv_anim_set_repeat_count(&anim_scale_line, LV_ANIM_REPEAT_INFINITE); - lv_anim_set_playback_duration(&anim_scale_line, 1000); + lv_anim_set_reverse_duration(&anim_scale_line, 1000); lv_anim_set_values(&anim_scale_line, 10, 40); lv_anim_start(&anim_scale_line); @@ -92,7 +92,7 @@ void lv_example_scale_3(void) lv_anim_set_exec_cb(&anim_scale_img, set_needle_img_value); lv_anim_set_duration(&anim_scale_img, 1000); lv_anim_set_repeat_count(&anim_scale_img, LV_ANIM_REPEAT_INFINITE); - lv_anim_set_playback_duration(&anim_scale_img, 1000); + lv_anim_set_reverse_duration(&anim_scale_img, 1000); lv_anim_set_values(&anim_scale_img, 10, 40); lv_anim_start(&anim_scale_img); } diff --git a/src/lv_api_map_v9_1.h b/src/lv_api_map_v9_1.h index 8c390453b..d2ec5cc47 100644 --- a/src/lv_api_map_v9_1.h +++ b/src/lv_api_map_v9_1.h @@ -87,10 +87,16 @@ extern "C" { #define LV_LABEL_LONG_SCROLL_CIRCULAR LV_LABEL_LONG_MODE_SCROLL_CIRCULAR #define LV_LABEL_LONG_CLIP LV_LABEL_LONG_MODE_CLIP +#define lv_anim_set_playback_delay lv_anim_set_reverse_delay +#define lv_anim_set_playback_duration lv_anim_set_reverse_duration + /********************** * DEPRECATED FUNCTIONS **********************/ +#define lv_anim_set_time lv_anim_set_duration +#define lv_anim_set_playback_time lv_anim_set_reverse_duration + #ifdef __cplusplus } /*extern "C"*/ #endif diff --git a/src/misc/lv_anim.c b/src/misc/lv_anim.c index 3b9283c2e..beca3a9de 100644 --- a/src/misc/lv_anim.c +++ b/src/misc/lv_anim.c @@ -137,7 +137,7 @@ uint32_t lv_anim_get_playtime(const lv_anim_t * a) uint32_t repeat_cnt = a->repeat_cnt; if(repeat_cnt < 1) repeat_cnt = 1; - uint32_t playtime = a->repeat_delay + a->duration + a->playback_delay + a->playback_duration; + uint32_t playtime = a->repeat_delay + a->duration + a->reverse_delay + a->reverse_duration; playtime = playtime * repeat_cnt; return playtime; } @@ -408,19 +408,19 @@ void lv_anim_set_deleted_cb(lv_anim_t * a, lv_anim_deleted_cb_t deleted_cb) a->deleted_cb = deleted_cb; } -void lv_anim_set_playback_duration(lv_anim_t * a, uint32_t duration) +void lv_anim_set_reverse_duration(lv_anim_t * a, uint32_t duration) { - a->playback_duration = duration; + a->reverse_duration = duration; } -void lv_anim_set_playback_time(lv_anim_t * a, uint32_t duration) +void lv_anim_set_reverse_time(lv_anim_t * a, uint32_t duration) { - lv_anim_set_playback_duration(a, duration); + lv_anim_set_reverse_duration(a, duration); } -void lv_anim_set_playback_delay(lv_anim_t * a, uint32_t delay) +void lv_anim_set_reverse_delay(lv_anim_t * a, uint32_t delay) { - a->playback_delay = delay; + a->reverse_delay = delay; } void lv_anim_set_repeat_count(lv_anim_t * a, uint32_t cnt) @@ -572,20 +572,20 @@ static void anim_timer(lv_timer_t * param) /** * Called when an animation is completed to do the necessary things - * e.g. repeat, play back, delete etc. + * e.g. repeat, play in reverse, delete etc. * @param a pointer to an animation descriptor */ static void anim_completed_handler(lv_anim_t * a) { /*In the end of a forward anim decrement repeat cnt.*/ - if(a->playback_now == 0 && a->repeat_cnt > 0 && a->repeat_cnt != LV_ANIM_REPEAT_INFINITE) { + if(a->reverse_play_in_progress == 0 && a->repeat_cnt > 0 && a->repeat_cnt != LV_ANIM_REPEAT_INFINITE) { a->repeat_cnt--; } - /*Delete the animation if - * - no repeat left and no play back (simple one shot animation) - * - no repeat, play back is enabled and play back is ready*/ - if(a->repeat_cnt == 0 && (a->playback_duration == 0 || a->playback_now == 1)) { + /*Delete animation if + * - no repeat left and no reverse play scheduled (simple one shot animation); or + * - no repeat, reverse play enabled (reverse_duration != 0) and reverse play is completed. */ + if(a->repeat_cnt == 0 && (a->reverse_duration == 0 || a->reverse_play_in_progress == 1)) { /*Delete the animation from the list. * This way the `completed_cb` will see the animations like it's animation is already deleted*/ @@ -604,21 +604,21 @@ static void anim_completed_handler(lv_anim_t * a) int32_t over_time = 0; if(a->act_time > a->duration) over_time = a->act_time - a->duration; a->act_time = over_time - (int32_t)(a->repeat_delay); - /*Swap the start and end values in play back mode*/ - if(a->playback_duration != 0) { - /*If now turning back use the 'playback_pause*/ - if(a->playback_now == 0) a->act_time = -(int32_t)(a->playback_delay); + /*Swap start and end values in reverse-play mode*/ + if(a->reverse_duration != 0) { + /*If now now playing in reverse, use the 'reverse_delay'.*/ + if(a->reverse_play_in_progress == 0) a->act_time = -(int32_t)(a->reverse_delay); - /*Toggle the play back state*/ - a->playback_now = a->playback_now == 0 ? 1 : 0; + /*Toggle reverse-play state*/ + a->reverse_play_in_progress = a->reverse_play_in_progress == 0 ? 1 : 0; /*Swap the start and end values*/ int32_t tmp = a->start_value; a->start_value = a->end_value; a->end_value = tmp; - /*Swap the time and playback_duration*/ + /*Swap the time and reverse_duration*/ tmp = a->duration; - a->duration = a->playback_duration; - a->playback_duration = tmp; + a->duration = a->reverse_duration; + a->reverse_duration = tmp; } } } @@ -663,8 +663,8 @@ static uint32_t convert_speed_to_time(uint32_t speed_or_time, int32_t start, int static void resolve_time(lv_anim_t * a) { a->duration = convert_speed_to_time(a->duration, a->start_value, a->end_value); - a->playback_duration = convert_speed_to_time(a->playback_duration, a->start_value, a->end_value); - a->playback_delay = convert_speed_to_time(a->playback_delay, a->start_value, a->end_value); + a->reverse_duration = convert_speed_to_time(a->reverse_duration, a->start_value, a->end_value); + a->reverse_delay = convert_speed_to_time(a->reverse_delay, a->start_value, a->end_value); a->repeat_delay = convert_speed_to_time(a->repeat_delay, a->start_value, a->end_value); } diff --git a/src/misc/lv_anim.h b/src/misc/lv_anim.h index 84602e416..0aaa84eb0 100644 --- a/src/misc/lv_anim.h +++ b/src/misc/lv_anim.h @@ -122,35 +122,36 @@ typedef struct { /** Describes an animation*/ struct _lv_anim_t { - void * var; /**< Variable to animate*/ - lv_anim_exec_xcb_t exec_cb; /**< Function to execute to animate*/ + void * var; /**< Variable (Widget or other user-provided object) to animate */ + lv_anim_exec_xcb_t exec_cb; /**< Function to execute to animate */ lv_anim_custom_exec_cb_t custom_exec_cb; /**< Function to execute to animate, - * same purpose as exec_cb but different parameters*/ - lv_anim_start_cb_t start_cb; /**< Call it when the animation is starts (considering `delay`)*/ - lv_anim_completed_cb_t completed_cb; /**< Call it when the animation is fully completed*/ - 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*/ - void * user_data; /**< Custom user data*/ - lv_anim_path_cb_t path_cb; /**< Describe the path (curve) of animations*/ - int32_t start_value; /**< Start value*/ - int32_t current_value; /**< Current value*/ - int32_t end_value; /**< End value*/ - int32_t duration; /**< Animation time in ms*/ - int32_t act_time; /**< Current time in animation. Set to negative to make delay.*/ - uint32_t playback_delay; /**< Wait before play back*/ - uint32_t playback_duration; /**< Duration of playback animation*/ - uint32_t repeat_delay; /**< Wait before repeat*/ - uint32_t repeat_cnt; /**< Repeat count for the animation*/ + * same purpose as exec_cb but different parameters */ + lv_anim_start_cb_t start_cb; /**< Call it when animation is starts (considering `delay`) */ + lv_anim_completed_cb_t completed_cb; /**< Call it when animation is fully completed */ + lv_anim_deleted_cb_t deleted_cb; /**< Call it when animation is deleted */ + lv_anim_get_value_cb_t get_value_cb; /**< Get current value in relative mode */ + void * user_data; /**< Custom user data */ + lv_anim_path_cb_t path_cb; /**< Provides path (curve) of animation */ + int32_t start_value; /**< Start value */ + int32_t current_value; /**< Current value */ + int32_t end_value; /**< End value */ + int32_t duration; /**< Animation duration in ms */ + int32_t act_time; /**< Ms elapsed since animation started. Set to negative to make delay. */ + uint32_t reverse_delay; /**< Wait (in ms) after forward play ends and before reverse play begins. */ + uint32_t reverse_duration; /**< Reverse animation duration in ms */ + uint32_t repeat_delay; /**< Wait before repeating */ + uint32_t repeat_cnt; /**< Repeat count for animation */ union _lv_anim_path_para_t { - lv_anim_bezier3_para_t bezier3; /**< Parameter used when path is custom_bezier*/ + lv_anim_bezier3_para_t bezier3; /**< Parameter used when path is custom_bezier */ } parameter; /* Animation system use these - user shouldn't set */ uint32_t last_timer_run; - uint8_t playback_now : 1; /**< Play back is in progress*/ - uint8_t run_round : 1; /**< Indicates the animation has run in this round*/ - uint8_t start_cb_called : 1; /**< Indicates that the `start_cb` was already called*/ - uint8_t early_apply : 1; /**< 1: Apply start value immediately even is there is `delay`*/ + uint8_t reverse_play_in_progress : 1; /**< Reverse play is in progress */ + uint8_t run_round : 1; /**< When not equal to global.anim_state.anim_run_round (which toggles each + * time animation timer executes), indicates this animation needs to be updated. */ + uint8_t start_cb_called : 1; /**< Indicates that `start_cb` was already called */ + uint8_t early_apply : 1; /**< 1: Apply start value immediately even is there is a `delay` */ }; /********************** @@ -262,19 +263,19 @@ void lv_anim_set_deleted_cb(lv_anim_t * a, lv_anim_deleted_cb_t deleted_cb); * @param a pointer to an initialized `lv_anim_t` variable * @param duration duration of playback animation in milliseconds. 0: disable playback */ -void lv_anim_set_playback_duration(lv_anim_t * a, uint32_t duration); +void lv_anim_set_reverse_duration(lv_anim_t * a, uint32_t duration); /** - * Legacy `lv_anim_set_playback_time` API will be removed soon, use `lv_anim_set_playback_duration` instead. + * Legacy `lv_anim_set_reverse_time` API will be removed soon, use `lv_anim_set_reverse_duration` instead. */ -void lv_anim_set_playback_time(lv_anim_t * a, uint32_t duration); +void lv_anim_set_reverse_time(lv_anim_t * a, uint32_t duration); /** * Make the animation to play back to when the forward direction is ready * @param a pointer to an initialized `lv_anim_t` variable * @param delay delay in milliseconds before starting the playback animation. */ -void lv_anim_set_playback_delay(lv_anim_t * a, uint32_t delay); +void lv_anim_set_reverse_delay(lv_anim_t * a, uint32_t delay); /** * Make the animation repeat itself. diff --git a/src/misc/lv_anim_timeline.c b/src/misc/lv_anim_timeline.c index ee39d268a..68abf5940 100644 --- a/src/misc/lv_anim_timeline.c +++ b/src/misc/lv_anim_timeline.c @@ -109,7 +109,7 @@ uint32_t lv_anim_timeline_start(lv_anim_timeline_t * at) lv_anim_set_var(&a, at); lv_anim_set_exec_cb(&a, anim_timeline_exec_cb); lv_anim_set_values(&a, start, end); - lv_anim_set_time(&a, duration); + lv_anim_set_duration(&a, duration); lv_anim_set_path_cb(&a, anim_timeline_path_cb); lv_anim_set_repeat_count(&a, repeat); lv_anim_set_repeat_delay(&a, delay); diff --git a/src/widgets/animimage/lv_animimage.c b/src/widgets/animimage/lv_animimage.c index 548c48c8c..831d3741d 100644 --- a/src/widgets/animimage/lv_animimage.c +++ b/src/widgets/animimage/lv_animimage.c @@ -92,7 +92,7 @@ void lv_animimg_set_duration(lv_obj_t * obj, uint32_t duration) LV_ASSERT_OBJ(obj, MY_CLASS); lv_animimg_t * animimg = (lv_animimg_t *)obj; lv_anim_set_duration(&animimg->anim, duration); - lv_anim_set_playback_delay(&animimg->anim, duration); + lv_anim_set_reverse_delay(&animimg->anim, duration); } void lv_animimg_set_repeat_count(lv_obj_t * obj, uint32_t count) diff --git a/src/widgets/label/lv_label.c b/src/widgets/label/lv_label.c index ed006fe8f..350ac797d 100644 --- a/src/widgets/label/lv_label.c +++ b/src/widgets/label/lv_label.c @@ -908,7 +908,7 @@ static void overwrite_anim_property(lv_anim_t * dest, const lv_anim_t * src, lv_ dest->repeat_cnt = src->repeat_cnt; dest->repeat_delay = src->repeat_delay; dest->completed_cb = src->completed_cb; - dest->playback_delay = src->playback_delay; + dest->reverse_delay = src->reverse_delay; break; case LV_LABEL_LONG_MODE_SCROLL_CIRCULAR: /** If the dest animation is already running, overwrite is not allowed */ @@ -961,8 +961,8 @@ static void lv_label_refr_text(lv_obj_t * obj) lv_anim_init(&a); lv_anim_set_var(&a, obj); lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE); - lv_anim_set_playback_delay(&a, LV_LABEL_SCROLL_DELAY); - lv_anim_set_repeat_delay(&a, a.playback_delay); + lv_anim_set_reverse_delay(&a, LV_LABEL_SCROLL_DELAY); + lv_anim_set_repeat_delay(&a, a.reverse_delay); bool hor_anim = false; if(size.x > lv_area_get_width(&txt_coords)) { @@ -992,16 +992,16 @@ static void lv_label_refr_text(lv_obj_t * obj) lv_anim_t * anim_cur = lv_anim_get(obj, set_ofs_x_anim); int32_t act_time = 0; - bool playback_now = false; + bool reverse_play_in_progress = false; if(anim_cur) { act_time = anim_cur->act_time; - playback_now = anim_cur->playback_now; + reverse_play_in_progress = anim_cur->reverse_play_in_progress; } if(act_time < a.duration) { a.act_time = act_time; /*To keep the old position*/ a.early_apply = 0; - if(playback_now) { - a.playback_now = 1; + if(reverse_play_in_progress) { + a.reverse_play_in_progress = 1; /*Swap the start and end values*/ int32_t tmp; tmp = a.start_value; @@ -1011,7 +1011,7 @@ static void lv_label_refr_text(lv_obj_t * obj) } lv_anim_set_duration(&a, anim_time); - lv_anim_set_playback_duration(&a, a.duration); + lv_anim_set_reverse_duration(&a, a.duration); /*If a template animation exists, overwrite some property*/ if(anim_template) @@ -1031,16 +1031,16 @@ static void lv_label_refr_text(lv_obj_t * obj) lv_anim_t * anim_cur = lv_anim_get(obj, set_ofs_y_anim); int32_t act_time = 0; - bool playback_now = false; + bool reverse_play_in_progress = false; if(anim_cur) { act_time = anim_cur->act_time; - playback_now = anim_cur->playback_now; + reverse_play_in_progress = anim_cur->reverse_play_in_progress; } if(act_time < a.duration) { a.act_time = act_time; /*To keep the old position*/ a.early_apply = 0; - if(playback_now) { - a.playback_now = 1; + if(reverse_play_in_progress) { + a.reverse_play_in_progress = 1; /*Swap the start and end values*/ int32_t tmp; tmp = a.start_value; @@ -1050,7 +1050,7 @@ static void lv_label_refr_text(lv_obj_t * obj) } lv_anim_set_duration(&a, anim_time); - lv_anim_set_playback_duration(&a, a.duration); + lv_anim_set_reverse_duration(&a, a.duration); /*If a template animation exists, overwrite some property*/ if(anim_template) diff --git a/src/widgets/lottie/lv_lottie.c b/src/widgets/lottie/lv_lottie.c index 455b1be6b..d9538934e 100644 --- a/src/widgets/lottie/lv_lottie.c +++ b/src/widgets/lottie/lv_lottie.c @@ -125,10 +125,10 @@ void lv_lottie_set_src_data(lv_obj_t * obj, const void * src, size_t src_size) float f_total; tvg_animation_get_total_frame(lottie->tvg_anim, &f_total); - lv_anim_set_time(lottie->anim, (int32_t)f_total * 1000 / 60); /*60 FPS*/ + lv_anim_set_duration(lottie->anim, (int32_t)f_total * 1000 / 60); /*60 FPS*/ lottie->anim->act_time = 0; lottie->anim->end_value = (int32_t)f_total; - lottie->anim->playback_now = false; + lottie->anim->reverse_play_in_progress = false; lottie_update(lottie, 0); /*Render immediately*/ } @@ -143,10 +143,10 @@ void lv_lottie_set_src_file(lv_obj_t * obj, const char * src) float f_total; tvg_animation_get_total_frame(lottie->tvg_anim, &f_total); - lv_anim_set_time(lottie->anim, (int32_t)f_total * 1000 / 60); /*60 FPS*/ + lv_anim_set_duration(lottie->anim, (int32_t)f_total * 1000 / 60); /*60 FPS*/ lottie->anim->act_time = 0; lottie->anim->end_value = (int32_t)f_total; - lottie->anim->playback_now = false; + lottie->anim->reverse_play_in_progress = false; lottie_update(lottie, 0); /*Render immediately*/ } diff --git a/src/widgets/textarea/lv_textarea.c b/src/widgets/textarea/lv_textarea.c index 1958371b3..ff68de17f 100644 --- a/src/widgets/textarea/lv_textarea.c +++ b/src/widgets/textarea/lv_textarea.c @@ -1160,7 +1160,7 @@ static void start_cursor_blink(lv_obj_t * obj) lv_anim_set_var(&a, ta); lv_anim_set_exec_cb(&a, cursor_blink_anim_cb); lv_anim_set_duration(&a, blink_time); - lv_anim_set_playback_duration(&a, blink_time); + lv_anim_set_reverse_duration(&a, blink_time); lv_anim_set_values(&a, 1, 0); lv_anim_set_path_cb(&a, lv_anim_path_step); lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE); diff --git a/tests/src/test_cases/test_style.c b/tests/src/test_cases/test_style.c index 4454df892..eaa65e565 100644 --- a/tests/src/test_cases/test_style.c +++ b/tests/src/test_cases/test_style.c @@ -29,7 +29,7 @@ void test_gradient_vertical_misalignment(void) lv_anim_set_var(&a, obj); lv_anim_set_exec_cb(&a, obj_set_height_helper); lv_anim_set_duration(&a, 1000); - lv_anim_set_playback_duration(&a, 1000); + lv_anim_set_reverse_duration(&a, 1000); lv_anim_set_repeat_count(&a, 100); lv_anim_set_values(&a, 0, 300); lv_anim_start(&a);