From ff3ffb8eeb0e893e13d6b947d920997decc3d806 Mon Sep 17 00:00:00 2001 From: Lorenzo Arena Date: Fri, 20 Sep 2024 10:50:17 +0200 Subject: [PATCH] feat(animimg): add getter function for underlying animation (#6838) --- docs/widgets/animimg.rst | 10 ++++++++++ src/widgets/animimage/lv_animimage.c | 7 +++++++ src/widgets/animimage/lv_animimage.h | 8 ++++++++ 3 files changed, 25 insertions(+) diff --git a/docs/widgets/animimg.rst b/docs/widgets/animimg.rst index 906eeaa59..2fdf13fe9 100644 --- a/docs/widgets/animimg.rst +++ b/docs/widgets/animimg.rst @@ -33,6 +33,16 @@ Image sources To set the image in a state, use the :cpp:expr:`lv_animimg_set_src(imagebutton, dsc[], num)`. +Using the inner animation +------------------------- + +For more advanced use cases, the animation internally used by the image can be +retrieved using the :cpp:expr:`lv_animimg_get_anim(image)`. This way, the +:ref:`Animation ` functions can be used, for example to +override the animation values using the +:cpp:expr:`lv_anim_set_values(anim, start, end)` or to set a callback +on the animation completed event. + .. _lv_animimg_events: Events diff --git a/src/widgets/animimage/lv_animimage.c b/src/widgets/animimage/lv_animimage.c index 11ec7ca1c..548c48c8c 100644 --- a/src/widgets/animimage/lv_animimage.c +++ b/src/widgets/animimage/lv_animimage.c @@ -134,6 +134,13 @@ uint32_t lv_animimg_get_repeat_count(lv_obj_t * obj) return lv_anim_get_repeat_count(&animimg->anim); } +lv_anim_t * lv_animimg_get_anim(lv_obj_t * obj) +{ + LV_ASSERT_OBJ(obj, MY_CLASS); + lv_animimg_t * animimg = (lv_animimg_t *)obj; + return &animimg->anim; +} + /********************** * STATIC FUNCTIONS **********************/ diff --git a/src/widgets/animimage/lv_animimage.h b/src/widgets/animimage/lv_animimage.h index c7b3b0a8b..a2f1926c1 100644 --- a/src/widgets/animimage/lv_animimage.h +++ b/src/widgets/animimage/lv_animimage.h @@ -14,6 +14,7 @@ extern "C" { * INCLUDES *********************/ #include "../image/lv_image.h" +#include "../../misc/lv_types.h" #if LV_USE_ANIMIMG != 0 @@ -112,6 +113,13 @@ uint32_t lv_animimg_get_duration(lv_obj_t * img); */ uint32_t lv_animimg_get_repeat_count(lv_obj_t * img); +/** + * Get the image animation underlying animation. + * @param img pointer to an animation image object + * @return the animation reference + */ +lv_anim_t * lv_animimg_get_anim(lv_obj_t * img); + #endif /*LV_USE_ANIMIMG*/ #ifdef __cplusplus