From 08a1b04fdf7c8dc4ff3c70f63ad847802f09348e Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Wed, 12 May 2021 12:57:12 +0200 Subject: [PATCH] feat(style) add user_data paramter to lv_style_transition_dsc_init --- examples/widgets/btn/lv_example_btn_2.c | 2 +- examples/widgets/btn/lv_example_btn_3.c | 4 ++-- examples/widgets/imgbtn/lv_example_imgbtn_1.c | 2 +- examples/widgets/slider/lv_example_slider_2.c | 2 +- src/extra/themes/default/lv_theme_default.c | 4 ++-- src/misc/lv_style.c | 5 ++++- src/misc/lv_style.h | 7 ++++--- 7 files changed, 15 insertions(+), 11 deletions(-) diff --git a/examples/widgets/btn/lv_example_btn_2.c b/examples/widgets/btn/lv_example_btn_2.c index 21e27ac82..addde71ab 100644 --- a/examples/widgets/btn/lv_example_btn_2.c +++ b/examples/widgets/btn/lv_example_btn_2.c @@ -47,7 +47,7 @@ void lv_example_btn_2(void) /*Add a transition to the the outline*/ static lv_style_transition_dsc_t trans; static lv_style_prop_t props[] = {LV_STYLE_OUTLINE_WIDTH, LV_STYLE_OUTLINE_OPA, 0}; - lv_style_transition_dsc_init(&trans, props, lv_anim_path_linear, 300, 0); + lv_style_transition_dsc_init(&trans, props, lv_anim_path_linear, 300, 0, NULL); lv_style_set_transition(&style_pr, &trans); diff --git a/examples/widgets/btn/lv_example_btn_3.c b/examples/widgets/btn/lv_example_btn_3.c index 49ee2b1e3..1b8ef662a 100644 --- a/examples/widgets/btn/lv_example_btn_3.c +++ b/examples/widgets/btn/lv_example_btn_3.c @@ -14,12 +14,12 @@ void lv_example_btn_3(void) /*Transition descriptor when going back to the default state. *Add some delay to be sure the press transition is visible even if the press was very short*/ static lv_style_transition_dsc_t transition_dsc_def; - lv_style_transition_dsc_init(&transition_dsc_def, props, lv_anim_path_overshoot, 250, 100); + lv_style_transition_dsc_init(&transition_dsc_def, props, lv_anim_path_overshoot, 250, 100, NULL); /*Transition descriptor when going to pressed state. *No delay, go to presses state immediately*/ static lv_style_transition_dsc_t transition_dsc_pr; - lv_style_transition_dsc_init(&transition_dsc_pr, props, lv_anim_path_ease_in_out, 250, 0); + lv_style_transition_dsc_init(&transition_dsc_pr, props, lv_anim_path_ease_in_out, 250, 0, NULL); /*Add only the new transition to he default state*/ static lv_style_t style_def; diff --git a/examples/widgets/imgbtn/lv_example_imgbtn_1.c b/examples/widgets/imgbtn/lv_example_imgbtn_1.c index ef51b3f5c..4fcb62e42 100644 --- a/examples/widgets/imgbtn/lv_example_imgbtn_1.c +++ b/examples/widgets/imgbtn/lv_example_imgbtn_1.c @@ -10,7 +10,7 @@ void lv_example_imgbtn_1(void) /*Create a transition animation on width transformation and recolor.*/ static lv_style_prop_t tr_prop[] = {LV_STYLE_TRANSFORM_WIDTH, LV_STYLE_IMG_RECOLOR_OPA, 0}; static lv_style_transition_dsc_t tr; - lv_style_transition_dsc_init(&tr, tr_prop, lv_anim_path_linear, 200, 0); + lv_style_transition_dsc_init(&tr, tr_prop, lv_anim_path_linear, 200, 0, NULL); static lv_style_t style_def; lv_style_init(&style_def); diff --git a/examples/widgets/slider/lv_example_slider_2.c b/examples/widgets/slider/lv_example_slider_2.c index 183ca3b56..883d61f34 100644 --- a/examples/widgets/slider/lv_example_slider_2.c +++ b/examples/widgets/slider/lv_example_slider_2.c @@ -11,7 +11,7 @@ void lv_example_slider_2(void) /*Create a transition*/ static const lv_style_prop_t props[] = {LV_STYLE_BG_COLOR, 0}; static lv_style_transition_dsc_t transition_dsc; - lv_style_transition_dsc_init(&transition_dsc, props, lv_anim_path_linear, 300, 0); + lv_style_transition_dsc_init(&transition_dsc, props, lv_anim_path_linear, 300, 0, NULL); static lv_style_t style_main; static lv_style_t style_indicator; diff --git a/src/extra/themes/default/lv_theme_default.c b/src/extra/themes/default/lv_theme_default.c index 10be2b22c..99d809deb 100644 --- a/src/extra/themes/default/lv_theme_default.c +++ b/src/extra/themes/default/lv_theme_default.c @@ -213,10 +213,10 @@ static void style_init(void) color_grey = theme.flags & MODE_DARK ? DARK_COLOR_GREY : LIGHT_COLOR_GREY; static lv_style_transition_dsc_t trans_delayed; - lv_style_transition_dsc_init(&trans_delayed, trans_props, lv_anim_path_linear, TRANSITION_TIME, 70); + lv_style_transition_dsc_init(&trans_delayed, trans_props, lv_anim_path_linear, TRANSITION_TIME, 70, NULL); static lv_style_transition_dsc_t trans_normal; - lv_style_transition_dsc_init(&trans_normal, trans_props, lv_anim_path_linear, TRANSITION_TIME, 0); + lv_style_transition_dsc_init(&trans_normal, trans_props, lv_anim_path_linear, TRANSITION_TIME, 0, NULL); style_init_reset(&styles->transition_delayed); lv_style_set_transition(&styles->transition_delayed, &trans_delayed); /*Go back to default state with delay*/ diff --git a/src/misc/lv_style.c b/src/misc/lv_style.c index e77f5881d..2028e0f1a 100644 --- a/src/misc/lv_style.c +++ b/src/misc/lv_style.c @@ -210,13 +210,16 @@ lv_res_t lv_style_get_prop(lv_style_t * style, lv_style_prop_t prop, lv_style_va return lv_style_get_prop_inlined(style, prop, value); } -void lv_style_transition_dsc_init(lv_style_transition_dsc_t * tr, const lv_style_prop_t props[], lv_anim_path_cb_t path_cb, uint32_t time, uint32_t delay) +void lv_style_transition_dsc_init(lv_style_transition_dsc_t * tr, const lv_style_prop_t props[], lv_anim_path_cb_t path_cb, uint32_t time, uint32_t delay, void * user_data) { lv_memset_00(tr, sizeof(lv_style_transition_dsc_t)); tr->props = props; tr->path_xcb = path_cb == NULL ? lv_anim_path_linear : path_cb; tr->time = time; tr->delay = delay; +#if LV_USE_USER_DATA + tr->user_data = user_data; +#endif } lv_style_value_t lv_style_prop_get_default(lv_style_prop_t prop) diff --git a/src/misc/lv_style.h b/src/misc/lv_style.h index 609676d63..ed0eb4c83 100644 --- a/src/misc/lv_style.h +++ b/src/misc/lv_style.h @@ -385,15 +385,16 @@ static inline lv_res_t lv_style_get_prop_inlined(lv_style_t * style, lv_style_pr * Initialize a transition descriptor. * @param tr pointer to a transition descriptor to initialize * @param props an array with the properties to transition. The last element must be zero. - * @param path_cb and animation path (ease) callback. If `NULL` liner path will be used. + * @param path_cb an animation path (ease) callback. If `NULL` liner path will be used. * @param time duration of the transition in [ms] * @param delay delay before the transition in [ms] + * @param user_data any custom data that will be saved in the transition animation and will be available when `path_cb` is called * @example * const static lv_style_prop_t trans_props[] = { LV_STYLE_BG_OPA, LV_STYLE_BG_COLOR, 0 }; * static lv_style_transition_dsc_t trans1; - * lv_style_transition_dsc_init(&trans1, trans_props, NULL, 300, 0); + * lv_style_transition_dsc_init(&trans1, trans_props, NULL, 300, 0, NULL); */ -void lv_style_transition_dsc_init(lv_style_transition_dsc_t * tr, const lv_style_prop_t props[], lv_anim_path_cb_t path_cb, uint32_t time, uint32_t delay); +void lv_style_transition_dsc_init(lv_style_transition_dsc_t * tr, const lv_style_prop_t props[], lv_anim_path_cb_t path_cb, uint32_t time, uint32_t delay, void * user_data); /** * Get the default value of a property