1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-28 07:03:00 +08:00

feat(anim) remove lv_anim_path_t and use a callback directly

lv_anim_path_t was required for the MicroPython binding becase the callback couldn't attached dircetly to the styles
However, in v8, path_cb is used in the style transitons which has user_data and that user data is passed to the transition animation. Hence the path_cb sees the the same user data during the animaton as when it was registered to the transiton.
This commit is contained in:
Gabor Kiss-Vamosi 2021-04-17 20:50:10 +02:00
parent 88979ccff9
commit da367337c9
17 changed files with 98 additions and 202 deletions

View File

@ -9,7 +9,7 @@ void lv_example_btn_2(void)
{
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_def, 300, 0);
lv_style_transition_dsc_init(&trans, props, lv_anim_path_linear, 300, 0);
static lv_style_t style;
lv_style_init(&style);

View File

@ -12,25 +12,15 @@ void lv_example_btn_3(void)
LV_STYLE_TRANSFORM_WIDTH, LV_STYLE_TRANSFORM_HEIGHT, LV_STYLE_TEXT_LETTER_SPACE, 0
};
/*Define animation paths*/
static lv_anim_path_t path_ease_in_out;
lv_anim_path_init(&path_ease_in_out);
lv_anim_path_set_cb(&path_ease_in_out, lv_anim_path_ease_in_out);
static lv_anim_path_t path_overshoot;
lv_anim_path_init(&path_overshoot);
lv_anim_path_set_cb(&path_overshoot, lv_anim_path_overshoot);
/*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, &path_overshoot, 250, 100);
lv_style_transition_dsc_init(&transition_dsc_def, props, lv_anim_path_overshoot, 250, 100);
/*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, &path_ease_in_out, 250, 0);
lv_style_transition_dsc_init(&transition_dsc_pr, props, lv_anim_path_ease_in_out, 250, 0);
/*Add only the new transition to he default state*/
static lv_style_t style_def;

View File

@ -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_def, 200, 0);
lv_style_transition_dsc_init(&tr, tr_prop, lv_anim_path_linear, 200, 0);
static lv_style_t style_def;
lv_style_init(&style_def);

View File

@ -48,14 +48,6 @@ typedef struct _lv_event_temp_data {
struct _lv_event_temp_data * prev;
} lv_event_temp_data_t;
typedef struct {
uint16_t time;
uint16_t delay;
lv_style_selector_t selector;
lv_style_prop_t prop;
const lv_anim_path_t * path;
}trans_set_t;
typedef struct _lv_event_dsc_t{
lv_event_cb_t cb;
void * user_data;
@ -953,8 +945,8 @@ static void lv_obj_set_state(lv_obj_t * obj, lv_state_t new_state)
/*If there is no difference in styles there is nothing else to do*/
if(cmp_res == _LV_STYLE_STATE_CMP_SAME) return;
trans_set_t * ts = lv_mem_buf_get(sizeof(trans_set_t) * STYLE_TRANSITION_MAX);
lv_memset_00(ts, sizeof(trans_set_t) * STYLE_TRANSITION_MAX);
_lv_obj_style_transition_dsc_t * ts = lv_mem_buf_get(sizeof(_lv_obj_style_transition_dsc_t) * STYLE_TRANSITION_MAX);
lv_memset_00(ts, sizeof(_lv_obj_style_transition_dsc_t) * STYLE_TRANSITION_MAX);
uint32_t tsi = 0;
uint32_t i;
for(i = 0; i < obj->style_cnt && tsi < STYLE_TRANSITION_MAX; i++) {
@ -980,8 +972,11 @@ static void lv_obj_set_state(lv_obj_t * obj, lv_state_t new_state)
if(t == tsi) {
ts[tsi].time = tr->time;
ts[tsi].delay = tr->delay;
ts[tsi].path = tr->path;
ts[tsi].path_cb = tr->path_cb;
ts[tsi].prop = tr->props[j];
#if LV_USE_USER_DATA
ts[tsi].user_data = tr->user_data;
#endif
ts[tsi].selector = obj_style->selector;
tsi++;
}
@ -990,7 +985,7 @@ static void lv_obj_set_state(lv_obj_t * obj, lv_state_t new_state)
for(i = 0;i < tsi; i++) {
lv_part_t part_act = lv_obj_style_get_selector_part(ts[i].selector);
_lv_obj_style_create_transition(obj, ts[i].prop, part_act, prev_state, new_state, ts[i].time, ts[i].delay, ts[i].path);
_lv_obj_style_create_transition(obj, part_act, prev_state, new_state, &ts[i]);
}
lv_mem_buf_release(ts);

View File

@ -248,10 +248,6 @@ void lv_obj_scroll_by(lv_obj_t * obj, lv_coord_t x, lv_coord_t y, lv_anim_enable
lv_anim_set_var(&a, obj);
lv_anim_set_ready_cb(&a, scroll_anim_ready_cb);
lv_anim_path_t path;
lv_anim_path_init(&path);
lv_anim_path_set_cb(&path, lv_anim_path_ease_out);
if(x) {
lv_res_t res;
res = lv_event_send(obj, LV_EVENT_SCROLL_BEGIN, NULL);
@ -264,7 +260,7 @@ void lv_obj_scroll_by(lv_obj_t * obj, lv_coord_t x, lv_coord_t y, lv_anim_enable
lv_coord_t sx = lv_obj_get_scroll_x(obj);
lv_anim_set_values(&a, -sx, -sx + x);
lv_anim_set_exec_cb(&a, scroll_x_anim);
lv_anim_set_path(&a, &path);
lv_anim_set_path_cb(&a, lv_anim_path_ease_out);
lv_anim_start(&a);
}
@ -280,7 +276,7 @@ void lv_obj_scroll_by(lv_obj_t * obj, lv_coord_t x, lv_coord_t y, lv_anim_enable
lv_coord_t sy = lv_obj_get_scroll_y(obj);
lv_anim_set_values(&a, -sy, -sy + y);
lv_anim_set_exec_cb(&a, scroll_y_anim);
lv_anim_set_path(&a, &path);
lv_anim_set_path_cb(&a, lv_anim_path_ease_out);
lv_anim_start(&a);
}
} else {
@ -517,7 +513,6 @@ void lv_obj_scrollbar_invalidate(lv_obj_t * obj)
if(lv_area_get_size(&hor_area) <= 0 && lv_area_get_size(&ver_area) <= 0) return;
printf("h: %d\n", hor_area.x2);
if(lv_area_get_size(&hor_area) > 0) lv_obj_invalidate_area(obj, &hor_area);
if(lv_area_get_size(&ver_area) > 0) lv_obj_invalidate_area(obj, &ver_area);
}

View File

@ -284,28 +284,27 @@ bool lv_obj_remove_local_style_prop(lv_obj_t * obj, lv_style_prop_t prop, lv_sty
return lv_style_remove_prop(obj->styles[i].style, prop);
}
void _lv_obj_style_create_transition(lv_obj_t * obj, lv_style_prop_t prop, lv_part_t part, lv_state_t prev_state,
lv_state_t new_state, uint32_t time, uint32_t delay, const lv_anim_path_t * path)
void _lv_obj_style_create_transition(lv_obj_t * obj, lv_part_t part, lv_state_t prev_state, lv_state_t new_state, const _lv_obj_style_transition_dsc_t * tr_dsc)
{
trans_t * tr;
/*Get the previous and current values*/
obj->skip_trans = 1;
obj->state = prev_state;
lv_style_value_t v1 = lv_obj_get_style_prop(obj, part, prop);
lv_style_value_t v1 = lv_obj_get_style_prop(obj, part, tr_dsc->prop);
obj->state = new_state;
lv_style_value_t v2 = lv_obj_get_style_prop(obj, part, prop);
lv_style_value_t v2 = lv_obj_get_style_prop(obj, part, tr_dsc->prop);
obj->skip_trans = 0;
if(v1.ptr == v2.ptr && v1.num == v2.num && v1.color.full == v2.color.full) return;
obj->state = prev_state;
v1 = lv_obj_get_style_prop(obj, part, prop);
v1 = lv_obj_get_style_prop(obj, part, tr_dsc->prop);
obj->state = new_state;
lv_obj_style_t * style_trans = get_trans_style(obj, part);
lv_style_set_prop(style_trans->style, prop, v1); /*Be sure `trans_style` has a valid value*/
lv_style_set_prop(style_trans->style, tr_dsc->prop, v1); /*Be sure `trans_style` has a valid value*/
if(prop == LV_STYLE_RADIUS) {
if(tr_dsc->prop == LV_STYLE_RADIUS) {
if(v1.num == LV_RADIUS_CIRCLE || v2.num == LV_RADIUS_CIRCLE) {
lv_coord_t whalf = lv_obj_get_width(obj) / 2;
lv_coord_t hhalf = lv_obj_get_width(obj) / 2;
@ -322,7 +321,7 @@ void _lv_obj_style_create_transition(lv_obj_t * obj, lv_style_prop_t prop, lv_pa
if(tr) {
tr->obj = obj;
tr->prop = prop;
tr->prop = tr_dsc->prop;
tr->selector = part;
lv_anim_t a;
@ -332,10 +331,11 @@ void _lv_obj_style_create_transition(lv_obj_t * obj, lv_style_prop_t prop, lv_pa
lv_anim_set_start_cb(&a, trans_anim_start_cb);
lv_anim_set_ready_cb(&a, trans_anim_ready_cb);
lv_anim_set_values(&a, 0x00, 0xFF);
lv_anim_set_time(&a, time);
lv_anim_set_delay(&a, delay);
lv_anim_set_path(&a, path);
a.early_apply = 0;
lv_anim_set_time(&a, tr_dsc->time);
lv_anim_set_delay(&a, tr_dsc->delay);
lv_anim_set_path_cb(&a, tr_dsc->path_cb);
lv_anim_set_early_apply(&a, false);
a.user_data = tr_dsc->user_data;
lv_anim_start(&a);
}
}

View File

@ -42,6 +42,17 @@ typedef struct {
uint32_t is_trans :1;
}lv_obj_style_t;
typedef struct {
uint16_t time;
uint16_t delay;
lv_style_selector_t selector;
lv_style_prop_t prop;
lv_anim_path_cb_t path_cb;
#if LV_USE_USER_DATA
void * user_data;
#endif
}_lv_obj_style_transition_dsc_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
@ -144,16 +155,12 @@ bool lv_obj_remove_local_style_prop(struct _lv_obj_t * obj, lv_style_prop_t prop
/**
* Used internally to create a style tarnsition
* @param obj
* @param prop
* @param part
* @param prev_state
* @param new_state
* @param time
* @param delay
* @param path
* @param tr
*/
void _lv_obj_style_create_transition(struct _lv_obj_t * obj, lv_style_prop_t prop, lv_part_t part, lv_state_t prev_state,
lv_state_t new_state, uint32_t time, uint32_t delay, const lv_anim_path_t * path);
void _lv_obj_style_create_transition(struct _lv_obj_t * obj, lv_part_t part, lv_state_t prev_state, lv_state_t new_state, const _lv_obj_style_transition_dsc_t * tr);
/**
* Used internally to compare the appearance of an object in 2 states

View File

@ -208,10 +208,10 @@ static void style_init(void)
theme.color_secondary = color_secondary_accent;
static lv_style_transition_dsc_t trans_delayed;
lv_style_transition_dsc_init(&trans_delayed, trans_props, &lv_anim_path_def, TRANSITION_TIME, 70);
lv_style_transition_dsc_init(&trans_delayed, trans_props, lv_anim_path_linear, TRANSITION_TIME, 70);
static lv_style_transition_dsc_t trans_normal;
lv_style_transition_dsc_init(&trans_normal, trans_props, &lv_anim_path_def, TRANSITION_TIME, 0);
lv_style_transition_dsc_init(&trans_normal, trans_props, lv_anim_path_linear, TRANSITION_TIME, 0);
style_init_reset(&styles->transition_delayed);
lv_style_set_transition(&styles->transition_delayed, &trans_delayed); /*Go back to default state with delay*/
@ -363,8 +363,7 @@ static void style_init(void)
#if LV_THEME_DEFAULT_GROW
style_init_reset(&styles->grow);
lv_style_set_transform_width(&styles->grow, 20);
lv_style_set_transform_height(&styles->grow, 20);
lv_style_set_transform_zoom(&styles->grow, 400);
#endif
style_init_reset(&styles->knob);
@ -424,7 +423,7 @@ static void style_init(void)
style_init_reset(&styles->chart_series);
lv_style_set_line_width(&styles->chart_series, LV_DPX(3));
lv_style_set_radius(&styles->chart_series, LV_DPX(3));
lv_style_set_size(&styles->chart_series, LV_DPX(4));
lv_style_set_size(&styles->chart_series, LV_DPX(8));
lv_style_set_pad_column(&styles->chart_series, LV_DPX(2));
style_init_reset(&styles->chart_ticks);

View File

@ -49,10 +49,6 @@ lv_obj_t * lv_spinner_create(lv_obj_t * parent, uint32_t time, uint32_t arc_leng
lv_obj_remove_style(spinner, NULL, LV_PART_KNOB | LV_STATE_ANY);
lv_anim_path_t path;
lv_anim_path_init(&path);
lv_anim_path_set_cb(&path, lv_anim_path_ease_in_out);
lv_anim_t a;
lv_anim_init(&a);
lv_anim_set_var(&a, spinner);
@ -62,7 +58,7 @@ lv_obj_t * lv_spinner_create(lv_obj_t * parent, uint32_t time, uint32_t arc_leng
lv_anim_set_values(&a, arc_length, 360 + arc_length);
lv_anim_start(&a);
lv_anim_set_path(&a, &path);
lv_anim_set_path_cb(&a, lv_anim_path_ease_in_out);
lv_anim_set_values(&a, 0, 360);
lv_anim_set_exec_cb(&a, arc_anim_start_angle);
lv_anim_start(&a);

View File

@ -41,7 +41,6 @@ static uint32_t last_timer_run;
static bool anim_list_changed;
static bool anim_run_round;
static lv_timer_t * _lv_anim_tmr;
const lv_anim_path_t lv_anim_path_def = {.cb = lv_anim_path_linear};
/**********************
* MACROS
@ -82,8 +81,8 @@ void lv_anim_init(lv_anim_t * a)
a->time = 500;
a->start_value = 0;
a->end_value = 100;
lv_memcpy_small(&a->path, &lv_anim_path_def, sizeof(lv_anim_path_cb_t));
a->repeat_cnt = 1;
a->path_cb = lv_anim_path_linear;
a->early_apply = 1;
}
/**
@ -130,27 +129,6 @@ void lv_anim_start(lv_anim_t * a)
TRACE_ANIM("finished");
}
/**
* Initialize an animation path
* @param path pointer to path
*/
void lv_anim_path_init(lv_anim_path_t * path)
{
lv_memset_00(path, sizeof(lv_anim_path_t));
}
/**
* Set the path (curve) of the animation.
* @param a pointer to an initialized `lv_anim_t` variable
* @param path_cb a function the get the current value of the animation.
* The built in functions starts with `lv_anim_path_...`
*/
void lv_anim_set_path(lv_anim_t * a, const lv_anim_path_t * path)
{
lv_memcpy_small(&a->path, path, sizeof(lv_anim_path_t));
}
/**
* Delete an animation of a variable with a given animator function
* @param var pointer to variable
@ -258,10 +236,8 @@ void lv_anim_refr_now(void)
* @param a pointer to an animation
* @return the current value to set
*/
int32_t lv_anim_path_linear(const lv_anim_path_t * path, const lv_anim_t * a)
int32_t lv_anim_path_linear(const lv_anim_t * a)
{
LV_UNUSED(path);
/*Calculate the current step*/
int32_t step = lv_map(a->act_time, 0, a->time, 0, LV_ANIM_RESOLUTION);
@ -280,12 +256,9 @@ int32_t lv_anim_path_linear(const lv_anim_path_t * path, const lv_anim_t * a)
* @param a pointer to an animation
* @return the current value to set
*/
int32_t lv_anim_path_ease_in(const lv_anim_path_t * path, const lv_anim_t * a)
int32_t lv_anim_path_ease_in(const lv_anim_t * a)
{
LV_UNUSED(path);
/*Calculate the current step*/
uint32_t t = lv_map(a->act_time, 0, a->time, 0, 1024);
int32_t step = lv_bezier3(t, 0, 50, 100, 1024);
@ -302,10 +275,8 @@ int32_t lv_anim_path_ease_in(const lv_anim_path_t * path, const lv_anim_t * a)
* @param a pointer to an animation
* @return the current value to set
*/
int32_t lv_anim_path_ease_out(const lv_anim_path_t * path, const lv_anim_t * a)
int32_t lv_anim_path_ease_out(const lv_anim_t * a)
{
LV_UNUSED(path);
/*Calculate the current step*/
uint32_t t = lv_map(a->act_time, 0, a->time, 0, 1024);
int32_t step = lv_bezier3(t, 0, 900, 950, 1024);
@ -323,10 +294,8 @@ int32_t lv_anim_path_ease_out(const lv_anim_path_t * path, const lv_anim_t * a)
* @param a pointer to an animation
* @return the current value to set
*/
int32_t lv_anim_path_ease_in_out(const lv_anim_path_t * path, const lv_anim_t * a)
int32_t lv_anim_path_ease_in_out(const lv_anim_t * a)
{
LV_UNUSED(path);
/*Calculate the current step*/
uint32_t t = lv_map(a->act_time, 0, a->time, 0, 1024);
int32_t step = lv_bezier3(t, 0, 50, 952, 1024);
@ -344,12 +313,9 @@ int32_t lv_anim_path_ease_in_out(const lv_anim_path_t * path, const lv_anim_t *
* @param a pointer to an animation
* @return the current value to set
*/
int32_t lv_anim_path_overshoot(const lv_anim_path_t * path, const lv_anim_t * a)
int32_t lv_anim_path_overshoot(const lv_anim_t * a)
{
LV_UNUSED(path);
/*Calculate the current step*/
uint32_t t = lv_map(a->act_time, 0, a->time, 0, 1024);
int32_t step = lv_bezier3(t, 0, 1000, 1300, 1024);
@ -366,12 +332,9 @@ int32_t lv_anim_path_overshoot(const lv_anim_path_t * path, const lv_anim_t * a)
* @param a pointer to an animation
* @return the current value to set
*/
int32_t lv_anim_path_bounce(const lv_anim_path_t * path, const lv_anim_t * a)
int32_t lv_anim_path_bounce(const lv_anim_t * a)
{
LV_UNUSED(path);
/*Calculate the current step*/
uint32_t t = lv_map(a->act_time, 0, a->time, 0, 1024);
int32_t diff = (a->end_value - a->start_value);
@ -425,10 +388,8 @@ int32_t lv_anim_path_bounce(const lv_anim_path_t * path, const lv_anim_t * a)
* @param a pointer to an animation
* @return the current value to set
*/
int32_t lv_anim_path_step(const lv_anim_path_t * path, const lv_anim_t * a)
int32_t lv_anim_path_step(const lv_anim_t * a)
{
LV_UNUSED(path);
if(a->act_time >= a->time)
return a->end_value;
else
@ -479,8 +440,7 @@ static void anim_timer(lv_timer_t * param)
if(a->act_time > a->time) a->act_time = a->time;
int32_t new_value;
if(a->path.cb) new_value = a->path.cb(&a->path, a);
else new_value = lv_anim_path_linear(&a->path, a);
new_value = a->path_cb(a);
if(new_value != a->current_value) {
a->current_value = new_value;

View File

@ -38,12 +38,7 @@ typedef enum {
struct _lv_anim_t;
struct _lv_anim_path_t;
/** Get the current value during an animation*/
typedef int32_t (*lv_anim_path_cb_t)(const struct _lv_anim_path_t *, const struct _lv_anim_t *);
typedef struct _lv_anim_path_t {
lv_anim_path_cb_t cb;
void * user_data;
} lv_anim_path_t;
typedef int32_t (*lv_anim_path_cb_t)(const struct _lv_anim_t *);
/** Generic prototype of "animator" functions.
* First parameter is the variable to animate.
@ -76,7 +71,7 @@ typedef struct _lv_anim_t {
#if LV_USE_USER_DATA
void * user_data; /**< Custom user data*/
#endif
lv_anim_path_t path; /**< Describe the path (curve) of animations*/
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*/
@ -186,10 +181,12 @@ static inline void lv_anim_set_custom_exec_cb(lv_anim_t * a, lv_anim_custom_exec
/**
* Set the path (curve) of the animation.
* @param a pointer to an initialized `lv_anim_t` variable
* @param path a function the get the current value of the animation.
* The built in functions starts with `lv_anim_path_...`
* @param path_cb a function the get the current value of the animation.
*/
void lv_anim_set_path(lv_anim_t * a, const lv_anim_path_t * path);
static inline void lv_anim_set_path_cb(lv_anim_t * a, lv_anim_path_cb_t path_cb)
{
a->path_cb = path_cb;
}
/**
* Set a function call when the animation really starts (considering `delay`)
@ -278,32 +275,6 @@ static inline void lv_anim_set_early_apply(lv_anim_t * a, bool en)
*/
void lv_anim_start(lv_anim_t * a);
/**
* Initialize an animation path
* @param path pointer to path
*/
void lv_anim_path_init(lv_anim_path_t * path);
/**
* Set a callback for a path
* @param path pointer to an initialized path
* @param cb the callback
*/
static inline void lv_anim_path_set_cb(lv_anim_path_t * path, lv_anim_path_cb_t cb)
{
path->cb = cb;
}
/**
* Set a user data for a path
* @param path pointer to an initialized path
* @param user_data pointer to the user data
*/
static inline void lv_anim_path_set_user_data(lv_anim_path_t * path, void * user_data)
{
path->user_data = user_data;
}
/**
* Get a delay before starting the animation
* @param a pointer to an initialized `lv_anim_t` variable
@ -381,42 +352,42 @@ void lv_anim_refr_now(void);
* @param a pointer to an animation
* @return the current value to set
*/
int32_t lv_anim_path_linear(const lv_anim_path_t * path, const lv_anim_t * a);
int32_t lv_anim_path_linear(const lv_anim_t * a);
/**
* Calculate the current value of an animation slowing down the start phase
* @param a pointer to an animation
* @return the current value to set
*/
int32_t lv_anim_path_ease_in(const lv_anim_path_t * path, const lv_anim_t * a);
int32_t lv_anim_path_ease_in(const lv_anim_t * a);
/**
* Calculate the current value of an animation slowing down the end phase
* @param a pointer to an animation
* @return the current value to set
*/
int32_t lv_anim_path_ease_out(const lv_anim_path_t * path, const lv_anim_t * a);
int32_t lv_anim_path_ease_out(const lv_anim_t * a);
/**
* Calculate the current value of an animation applying an "S" characteristic (cosine)
* @param a pointer to an animation
* @return the current value to set
*/
int32_t lv_anim_path_ease_in_out(const lv_anim_path_t * path, const lv_anim_t * a);
int32_t lv_anim_path_ease_in_out(const lv_anim_t * a);
/**
* Calculate the current value of an animation with overshoot at the end
* @param a pointer to an animation
* @return the current value to set
*/
int32_t lv_anim_path_overshoot(const lv_anim_path_t * path, const lv_anim_t * a);
int32_t lv_anim_path_overshoot(const lv_anim_t * a);
/**
* Calculate the current value of an animation with 3 bounces
* @param a pointer to an animation
* @return the current value to set
*/
int32_t lv_anim_path_bounce(const lv_anim_path_t * path, const lv_anim_t * a);
int32_t lv_anim_path_bounce(const lv_anim_t * a);
/**
* Calculate the current value of an animation applying step characteristic.
@ -424,12 +395,11 @@ int32_t lv_anim_path_bounce(const lv_anim_path_t * path, const lv_anim_t * a);
* @param a pointer to an animation
* @return the current value to set
*/
int32_t lv_anim_path_step(const lv_anim_path_t * path, const lv_anim_t * a);
int32_t lv_anim_path_step(const lv_anim_t * a);
/**********************
* GLOBAL VARIABLES
**********************/
extern const lv_anim_path_t lv_anim_path_def;
/**********************
* MACROS

View File

@ -198,11 +198,11 @@ 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, const lv_anim_path_t * path, 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)
{
lv_memset_00(tr, sizeof(lv_style_transition_dsc_t));
tr->props = props;
tr->path = path == NULL ? &lv_anim_path_def : path;
tr->path_cb = path_cb == NULL ? lv_anim_path_linear : path_cb;
tr->time = time;
tr->delay = delay;
}

View File

@ -227,17 +227,14 @@ typedef enum {
*/
typedef struct _lv_style_transiton_t {
const lv_style_prop_t * props; /**< An array with the properties to animate.*/
const lv_anim_path_t * path; /**< A path for the animation.*/
#if LV_USE_USER_DATA
void * user_data; /**< A custom user data that will be passed to the animation's user_data */
#endif
lv_anim_path_cb_t path_cb; /**< A path for the animation.*/
uint32_t time; /**< Duration of the transition in [ms]*/
uint32_t delay; /**< Delay before the transition in [ms]*/
}lv_style_transition_dsc_t;
#if LV_USE_ASSERT_STYLE
# define _LV_STYLE_SENTINEL uint32_t sentinel;
#else
# define _LV_STYLE_SENTINEL
#endif
/**
* Descriptor of a style (a collection of properties and values).
*/
@ -358,18 +355,18 @@ 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 and animation path. If `NULL` a default liner path will be used.
* @param time duration of the transition in [ms]
* @param delay delay before the transition in [ms]
* @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 time duration of the transition in [ms]
* @param delay delay before the transition in [ms]
* @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);
* @note For performance reasons there are no sanity check on `style`
*/
void lv_style_transition_dsc_init(lv_style_transition_dsc_t * tr, const lv_style_prop_t * props, const lv_anim_path_t * path, 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);
/**
* Get the default value of a property

View File

@ -238,8 +238,12 @@ static void draw_indic(lv_event_t * e)
const lv_area_t * clip_area = lv_event_get_param(e);
lv_coord_t barw = lv_obj_get_width(obj);
lv_coord_t barh = lv_obj_get_height(obj);
lv_area_t bar_coords;
lv_area_zoom(lv_obj_get_style_transform_zoom(obj, LV_PART_MAIN), &obj->coords, &bar_coords);
lv_obj_get_coords(obj, &bar_coords);
lv_coord_t barw = lv_area_get_width(&bar_coords);
lv_coord_t barh = lv_area_get_height(&bar_coords);
int32_t range = bar->max_value - bar->min_value;
bool hor = barw >= barh ? true : false;
bool sym = false;
@ -252,7 +256,7 @@ static void draw_indic(lv_event_t * e)
lv_coord_t bg_top = lv_obj_get_style_pad_top(obj, LV_PART_MAIN);
lv_coord_t bg_bottom = lv_obj_get_style_pad_bottom(obj, LV_PART_MAIN);
/*Respect padding and minimum width/height too*/
lv_area_copy(&bar->indic_area, &obj->coords);
lv_area_copy(&bar->indic_area, &bar_coords);
bar->indic_area.x1 += bg_left;
bar->indic_area.x2 -= bg_right;
bar->indic_area.y1 += bg_top;
@ -420,7 +424,7 @@ static void draw_indic(lv_event_t * e)
/*Get the max possible indicator area. The gradient should be applied on this*/
lv_area_t mask_indic_max_area;
lv_area_copy(&mask_indic_max_area, &obj->coords);
lv_area_copy(&mask_indic_max_area, &bar_coords);
mask_indic_max_area.x1 += bg_left;
mask_indic_max_area.y1 += bg_top;
mask_indic_max_area.x2 -= bg_right;

View File

@ -590,7 +590,6 @@ static void refr_position(lv_obj_t * obj, lv_anim_enable_t anim_en)
inf_normalize(obj);
}
int32_t id = roller->sel_opt_id;
lv_coord_t sel_y1 = id * (font_h + line_space);
lv_coord_t mid_y1 = h / 2 - font_h / 2;
@ -602,9 +601,6 @@ static void refr_position(lv_obj_t * obj, lv_anim_enable_t anim_en)
lv_obj_set_y(label, new_y);
}
else {
lv_anim_path_t path;
lv_anim_path_init(&path);
lv_anim_path_set_cb(&path, lv_anim_path_ease_out);
lv_anim_t a;
lv_anim_init(&a);
lv_anim_set_var(&a, label);
@ -612,7 +608,7 @@ static void refr_position(lv_obj_t * obj, lv_anim_enable_t anim_en)
lv_anim_set_values(&a, lv_obj_get_y(label), new_y);
lv_anim_set_time(&a, anim_time);
lv_anim_set_ready_cb(&a, scroll_anim_ready_cb);
lv_anim_set_path(&a, &path);
lv_anim_set_path_cb(&a, lv_anim_path_ease_out);
lv_anim_start(&a);
}
}

View File

@ -275,12 +275,13 @@ static void lv_slider_event(lv_event_t * e)
lv_coord_t knob_bottom = lv_obj_get_style_pad_bottom(obj, LV_PART_KNOB);
/*The smaller size is the knob diameter*/
lv_coord_t trans_w = lv_obj_get_style_transform_width(obj, LV_PART_MAIN);
lv_coord_t trans_h = lv_obj_get_style_transform_height(obj, LV_PART_MAIN);
lv_coord_t zoom = lv_obj_get_style_transform_zoom(obj, LV_PART_KNOB);
lv_coord_t trans_w = lv_obj_get_style_transform_width(obj, LV_PART_KNOB);
lv_coord_t trans_h = lv_obj_get_style_transform_height(obj, LV_PART_KNOB);
lv_coord_t knob_size = LV_MIN(lv_obj_get_width(obj) + 2 * trans_w, lv_obj_get_height(obj) + 2 * trans_h) >> 1;
knob_size = (knob_size * zoom) >> 8;
knob_size += LV_MAX(LV_MAX(knob_left, knob_right), LV_MAX(knob_bottom, knob_top));
knob_size += 2; /*For rounding error*/
knob_size += lv_obj_calculate_ext_draw_size(obj, LV_PART_KNOB);
/*Indic. size is handled by bar*/
@ -401,7 +402,6 @@ static void draw_knob(lv_event_t * e)
lv_draw_rect(&slider->left_knob_area, clip_area, &knob_rect_dsc);
lv_event_send(obj, LV_EVENT_DRAW_PART_END, &dsc);
}
}
static void position_knob(lv_obj_t * obj, lv_area_t * knob_area, lv_coord_t knob_size, bool hor)
@ -420,6 +420,9 @@ static void position_knob(lv_obj_t * obj, lv_area_t * knob_area, lv_coord_t knob
knob_area->x2 = obj->coords.x2;
}
lv_coord_t zoom = lv_obj_get_style_transform_zoom(obj, LV_PART_KNOB);
lv_area_zoom(zoom, knob_area, knob_area);
lv_coord_t knob_left = lv_obj_get_style_pad_left(obj, LV_PART_KNOB);
lv_coord_t knob_right = lv_obj_get_style_pad_right(obj, LV_PART_KNOB);
lv_coord_t knob_top = lv_obj_get_style_pad_top(obj, LV_PART_KNOB);

View File

@ -147,17 +147,13 @@ void lv_textarea_add_char(lv_obj_t * obj, uint32_t c)
pwd_char_hider(obj);
}
else {
lv_anim_path_t path;
lv_anim_path_init(&path);
lv_anim_path_set_cb(&path, lv_anim_path_step);
lv_anim_t a;
lv_anim_init(&a);
lv_anim_set_var(&a, ta);
lv_anim_set_exec_cb(&a, pwd_char_hider_anim);
lv_anim_set_time(&a, ta->pwd_show_time);
lv_anim_set_values(&a, 0, 1);
lv_anim_set_path(&a, &path);
lv_anim_set_path_cb(&a, lv_anim_path_step);
lv_anim_set_ready_cb(&a, pwd_char_hider_anim_ready);
lv_anim_start(&a);
}
@ -213,17 +209,13 @@ void lv_textarea_add_text(lv_obj_t * obj, const char * txt)
pwd_char_hider(obj);
}
else {
lv_anim_path_t path;
lv_anim_path_init(&path);
lv_anim_path_set_cb(&path, lv_anim_path_step);
lv_anim_t a;
lv_anim_init(&a);
lv_anim_set_var(&a, ta);
lv_anim_set_exec_cb(&a, pwd_char_hider_anim);
lv_anim_set_time(&a, ta->pwd_show_time);
lv_anim_set_values(&a, 0, 1);
lv_anim_set_path(&a, &path);
lv_anim_set_path_cb(&a, lv_anim_path_step);
lv_anim_set_ready_cb(&a, pwd_char_hider_anim_ready);
lv_anim_start(&a);
}
@ -337,17 +329,13 @@ void lv_textarea_set_text(lv_obj_t * obj, const char * txt)
pwd_char_hider(obj);
}
else {
lv_anim_path_t path;
lv_anim_path_init(&path);
lv_anim_path_set_cb(&path, lv_anim_path_step);
lv_anim_t a;
lv_anim_init(&a);
lv_anim_set_var(&a, ta);
lv_anim_set_exec_cb(&a, pwd_char_hider_anim);
lv_anim_set_time(&a, ta->pwd_show_time);
lv_anim_set_values(&a, 0, 1);
lv_anim_set_path(&a, &path);
lv_anim_set_path_cb(&a, lv_anim_path_step);
lv_anim_set_ready_cb(&a, pwd_char_hider_anim_ready);
lv_anim_start(&a);
}
@ -1031,10 +1019,6 @@ static void start_cursor_blink(lv_obj_t * obj)
lv_anim_del(obj, cursor_blink_anim_cb);
ta->cursor.show = 1;
} else {
lv_anim_path_t path;
lv_anim_path_init(&path);
lv_anim_path_set_cb(&path, lv_anim_path_step);
lv_anim_t a;
lv_anim_init(&a);
lv_anim_set_var(&a, ta);
@ -1042,7 +1026,7 @@ static void start_cursor_blink(lv_obj_t * obj)
lv_anim_set_time(&a, blink_time);
lv_anim_set_playback_time(&a, blink_time);
lv_anim_set_values(&a, 1, 0);
lv_anim_set_path(&a, &path);
lv_anim_set_path_cb(&a, lv_anim_path_step);
lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE);
lv_anim_start(&a);
}