diff --git a/src/lv_core/lv_obj.c b/src/lv_core/lv_obj.c index f00ba1c65..aeb51c7f4 100644 --- a/src/lv_core/lv_obj.c +++ b/src/lv_core/lv_obj.c @@ -60,13 +60,13 @@ typedef struct { lv_color_t _color; lv_style_int_t _int; lv_opa_t _opa; - _lv_style_fptr_dptr_t _ptr; + const void * _ptr; } start_value; union { lv_color_t _color; lv_style_int_t _int; lv_opa_t _opa; - _lv_style_fptr_dptr_t _ptr; + const void * _ptr; } end_value; } lv_style_trans_t; @@ -1261,7 +1261,7 @@ void _lv_obj_set_style_local_opa(lv_obj_t * obj, uint8_t part, lv_style_property * For example: `lv_obj_style_get_border_opa()` * @note for performance reasons it's not checked if the property really has pointer type */ -void _lv_obj_set_style_local_ptr(lv_obj_t * obj, uint8_t part, lv_style_property_t prop, _lv_style_fptr_dptr_t value) +void _lv_obj_set_style_local_ptr(lv_obj_t * obj, uint8_t part, lv_style_property_t prop, const void * value) { lv_style_list_t * style_dsc = lv_obj_get_style_list(obj, part); lv_style_list_set_local_ptr(style_dsc, prop, value); @@ -1595,7 +1595,7 @@ void lv_obj_set_state(lv_obj_t * obj, lv_state_t new_state) lv_style_int_t time = lv_obj_get_style_transition_time(obj, part); lv_style_property_t props[LV_STYLE_TRANS_NUM_MAX]; lv_style_int_t delay = lv_obj_get_style_transition_delay(obj, part); - lv_anim_path_cb_t path = lv_obj_get_style_transition_path(obj, part); + lv_anim_path_t * path = lv_obj_get_style_transition_path(obj, part); props[0] = lv_obj_get_style_transition_prop_1(obj, part); props[1] = lv_obj_get_style_transition_prop_2(obj, part); props[2] = lv_obj_get_style_transition_prop_3(obj, part); @@ -1625,7 +1625,7 @@ void lv_obj_set_state(lv_obj_t * obj, lv_state_t new_state) lv_anim_set_values(&a, 0x00, 0xFF); lv_anim_set_time(&a, time); lv_anim_set_delay(&a, delay); - lv_anim_set_path_cb(&a, path); + lv_anim_set_path(&a, path); a.early_apply = 0; lv_anim_start(&a); } @@ -2538,14 +2538,14 @@ lv_opa_t _lv_obj_get_style_opa(const lv_obj_t * obj, uint8_t part, lv_style_prop * For example: `lv_obj_style_get_border_opa()` * @note for performance reasons it's not checked if the property really has pointer type */ -_lv_style_fptr_dptr_t _lv_obj_get_style_ptr(const lv_obj_t * obj, uint8_t part, lv_style_property_t prop) +const void * _lv_obj_get_style_ptr(const lv_obj_t * obj, uint8_t part, lv_style_property_t prop) { lv_style_property_t prop_ori = prop; lv_style_attr_t attr; attr.full = prop_ori >> 8; - _lv_style_fptr_dptr_t value_act; + const void * value_act; lv_res_t res = LV_RES_INV; const lv_obj_t * parent = obj; while(parent) { @@ -2571,22 +2571,17 @@ _lv_style_fptr_dptr_t _lv_obj_get_style_ptr(const lv_obj_t * obj, uint8_t part, /*Handle unset values*/ prop = prop & (~LV_STYLE_STATE_MASK); - _lv_style_fptr_dptr_t fd; - fd.dptr = NULL; - fd.fptr = NULL; switch(prop) { case LV_STYLE_TEXT_FONT: case LV_STYLE_VALUE_FONT: - fd.dptr = LV_THEME_DEFAULT_FONT_NORMAL; - return fd; + return LV_THEME_DEFAULT_FONT_NORMAL; #if LV_USE_ANIMATION case LV_STYLE_TRANSITION_PATH: - fd.fptr = (_lv_style_prop_xcb_t)lv_anim_path_linear; - return fd; + return &lv_anim_path_def; #endif } - return fd; + return NULL; } /** @@ -3795,22 +3790,22 @@ static lv_style_trans_t * trans_create(lv_obj_t * obj, lv_style_property_t prop, else { /*Ptr*/ obj->state = prev_state; style_list->skip_trans = 1; - _lv_style_fptr_dptr_t fd1 = _lv_obj_get_style_ptr(obj, part, prop); + const void * p1 = _lv_obj_get_style_ptr(obj, part, prop); obj->state = new_state; - _lv_style_fptr_dptr_t fd2 = _lv_obj_get_style_ptr(obj, part, prop); + const void * p2 = _lv_obj_get_style_ptr(obj, part, prop); style_list->skip_trans = 0; - if(memcmp(&fd1, &fd2, sizeof(_lv_style_fptr_dptr_t)) == 0) return NULL; + if(memcmp(&p1, &p2, sizeof(const void *)) == 0) return NULL; obj->state = prev_state; - fd1 = _lv_obj_get_style_ptr(obj, part, prop); + p1 = _lv_obj_get_style_ptr(obj, part, prop); obj->state = new_state; - _lv_style_set_ptr(style_trans, prop, fd1); /*Be sure `trans_style` has a valid value */ + _lv_style_set_ptr(style_trans, prop, p1); /*Be sure `trans_style` has a valid value */ tr = lv_ll_ins_head(&LV_GC_ROOT(_lv_obj_style_trans_ll)); LV_ASSERT_MEM(tr); if(tr == NULL) return NULL; - tr->start_value._ptr = fd1; - tr->end_value._ptr = fd2; + tr->start_value._ptr = p1; + tr->end_value._ptr = p2; } return tr; @@ -3878,7 +3873,7 @@ static void trans_anim_cb(lv_style_trans_t * tr, lv_anim_value_t v) _lv_style_set_opa(style, tr->prop, x); } else { - _lv_style_fptr_dptr_t x; + const void * x; if(v < 128) x = tr->start_value._ptr; else x = tr->end_value._ptr; _lv_style_set_ptr(style, tr->prop, x); diff --git a/src/lv_core/lv_obj.h b/src/lv_core/lv_obj.h index 654e4e96c..5dcb62b02 100644 --- a/src/lv_core/lv_obj.h +++ b/src/lv_core/lv_obj.h @@ -601,48 +601,7 @@ void _lv_obj_set_style_local_opa(lv_obj_t * obj, uint8_t type, lv_style_property * For example: `lv_obj_style_get_border_opa()` * @note for performance reasons it's not checked if the property really has pointer type */ -void _lv_obj_set_style_local_ptr(lv_obj_t * obj, uint8_t type, lv_style_property_t prop, _lv_style_fptr_dptr_t value); - -/** - * Set a local style property of a part of an object in a given state. - * @param obj pointer to an object - * @param part the part of the object which style property should be set. - * E.g. `LV_OBJ_PART_MAIN`, `LV_BTN_PART_MAIN`, `LV_SLIDER_PART_KNOB` - * @param prop a style property ORed with a state. - * E.g. `LV_STYLE_TEXT_FONT | (LV_STATE_PRESSED << LV_STYLE_STATE_POS)` - * @param the value to set - * @note shouldn't be used directly. Use the specific property get functions instead. - * For example: `lv_obj_style_get_trasition_path()` - * @note for performance reasons it's not checked if the property really has pointer type - */ -static inline void _lv_obj_set_style_local_func_ptr(lv_obj_t * obj, uint8_t type, lv_style_property_t prop, - _lv_style_prop_xcb_t value) -{ - _lv_style_fptr_dptr_t fd; - fd.fptr = value; - fd.dptr = NULL; - _lv_obj_set_style_local_ptr(obj, type, prop, fd); -} -/** - * Set a local style property of a part of an object in a given state. - * @param obj pointer to an object - * @param part the part of the object which style property should be set. - * E.g. `LV_OBJ_PART_MAIN`, `LV_BTN_PART_MAIN`, `LV_SLIDER_PART_KNOB` - * @param prop a style property ORed with a state. - * E.g. `LV_STYLE_TEXT_FONT | (LV_STATE_PRESSED << LV_STYLE_STATE_POS)` - * @param the value to set - * @note shouldn't be used directly. Use the specific property get functions instead. - * For example: `lv_obj_style_get_text_font()` - * @note for performance reasons it's not checked if the property really has pointer type - */ -static inline void _lv_obj_set_style_local_data_ptr(lv_obj_t * obj, uint8_t type, lv_style_property_t prop, - const void * value) -{ - _lv_style_fptr_dptr_t fd; - fd.fptr = NULL; - fd.dptr = value; - _lv_obj_set_style_local_ptr(obj, type, prop, fd); -} +void _lv_obj_set_style_local_ptr(lv_obj_t * obj, uint8_t type, lv_style_property_t prop, const void * value); /** * Remove a local style property from a part of an object with a given state. @@ -1148,52 +1107,7 @@ lv_opa_t _lv_obj_get_style_opa(const lv_obj_t * obj, uint8_t part, lv_style_prop * For example: `lv_obj_style_get_border_opa()` * @note for performance reasons it's not checked if the property really has pointer type */ -_lv_style_fptr_dptr_t _lv_obj_get_style_ptr(const lv_obj_t * obj, uint8_t part, lv_style_property_t prop); - -/** - * Get a style property of a part of an object in the object's current state. - * If there is a running transitions it is taken into account - * @param obj pointer to an object - * @param part the part of the object which style property should be get. - * E.g. `LV_OBJ_PART_MAIN`, `LV_BTN_PART_MAIN`, `LV_SLIDER_PART_KNOB` - * @param prop the property to get. E.g. `LV_STYLE_TEXT_FONT`. - * The state of the object will be added internally - * @return the value of the property of the given part in the current state. - * If the property is not found a default value will be returned. - * @note shouldn't be used directly. Use the specific property get functions instead. - * For example: `lv_obj_style_get_trasition_path()` - * @note for performance reasons it's not checked if the property really has pointer type - */ -static inline _lv_style_prop_xcb_t _lv_obj_get_style_func_ptr(const lv_obj_t * obj, uint8_t part, - lv_style_property_t prop) -{ - _lv_style_fptr_dptr_t fd; - fd = _lv_obj_get_style_ptr(obj, part, prop); - return fd.fptr; -} - -/** - * Get a style property of a part of an object in the object's current state. - * If there is a running transitions it is taken into account - * @param obj pointer to an object - * @param part the part of the object which style property should be get. - * E.g. `LV_OBJ_PART_MAIN`, `LV_BTN_PART_MAIN`, `LV_SLIDER_PART_KNOB` - * @param prop the property to get. E.g. `LV_STYLE_TEXT_FONT`. - * The state of the object will be added internally - * @return the value of the property of the given part in the current state. - * If the property is not found a default value will be returned. - * @note shouldn't be used directly. Use the specific property get functions instead. - * For example: `lv_obj_style_get_text_font()` - * @note for performance reasons it's not checked if the property really has pointer type - */ -static inline const void * _lv_obj_get_style_data_ptr(const lv_obj_t * obj, uint8_t part, lv_style_property_t prop) -{ - _lv_style_fptr_dptr_t fd; - fd = _lv_obj_get_style_ptr(obj, part, prop); - return fd.dptr; -} - - +const void * _lv_obj_get_style_ptr(const lv_obj_t * obj, uint8_t part, lv_style_property_t prop); /** * Get the local style of a part of an object. diff --git a/src/lv_core/lv_obj_style_dec.h b/src/lv_core/lv_obj_style_dec.h index a943f29d7..a97f16108 100644 --- a/src/lv_core/lv_obj_style_dec.h +++ b/src/lv_core/lv_obj_style_dec.h @@ -58,24 +58,12 @@ extern "C" { * `lv_style_set_border_width(&style1, LV_STATE_PRESSED, 2);` */ -#ifdef __cplusplus -#define FUNC_PTR_CAST(v) reinterpret_cast<_lv_style_prop_xcb_t>(v) -#else -#define FUNC_PTR_CAST(v) (_lv_style_prop_xcb_t)v -#endif - #define _OBJ_GET_STYLE_scalar(prop_name, func_name, value_type, style_type) \ static inline value_type lv_obj_get_style_##func_name (const lv_obj_t * obj, uint8_t part) \ { \ return (value_type) _lv_obj_get_style##style_type (obj, part, LV_STYLE_##prop_name); \ } -#define _OBJ_GET_STYLE_func_ptr(prop_name, func_name, value_type, style_type) \ - static inline value_type lv_obj_get_style_##func_name (const lv_obj_t * obj, uint8_t part) \ - { \ - return (value_type) _lv_obj_get_style##style_type (obj, part, LV_STYLE_##prop_name); \ - } - #define _OBJ_GET_STYLE_nonscalar(prop_name, func_name, value_type, style_type) \ static inline value_type lv_obj_get_style_##func_name (const lv_obj_t * obj, uint8_t part) \ { \ @@ -94,12 +82,6 @@ extern "C" { _lv_obj_set_style_local##style_type (obj, part, LV_STYLE_##prop_name | (state << LV_STYLE_STATE_POS), value); \ } -#define _OBJ_SET_STYLE_LOCAL_func_ptr(prop_name, func_name, value_type, style_type) \ - static inline void lv_obj_set_style_local_##func_name (lv_obj_t * obj, uint8_t part, lv_state_t state, value_type value) \ - { \ - _lv_obj_set_style_local##style_type (obj, part, LV_STYLE_##prop_name | (state << LV_STYLE_STATE_POS), FUNC_PTR_CAST(value)); \ - } - #define _OBJ_SET_STYLE_scalar(prop_name, func_name, value_type, style_type) \ static inline void lv_style_set_##func_name (lv_style_t * style, lv_state_t state, value_type value) \ { \ @@ -112,12 +94,6 @@ extern "C" { _lv_style_set##style_type (style, LV_STYLE_##prop_name | (state << LV_STYLE_STATE_POS), value); \ } -#define _OBJ_SET_STYLE_func_ptr(prop_name, func_name, value_type, style_type) \ - static inline void lv_style_set_##func_name (lv_style_t * style, lv_state_t state, value_type value) \ - { \ - _lv_style_set##style_type (style, LV_STYLE_##prop_name | (state << LV_STYLE_STATE_POS), FUNC_PTR_CAST(value)); \ - } \ - #define _LV_OBJ_STYLE_SET_GET_DECLARE(prop_name, func_name, value_type, style_type, scalar) \ _OBJ_GET_STYLE_##scalar(prop_name, func_name, value_type, style_type) \ _OBJ_SET_STYLE_LOCAL_##scalar(prop_name, func_name, value_type, style_type) \ @@ -180,7 +156,7 @@ _LV_OBJ_STYLE_SET_GET_DECLARE(PATTERN_BLEND_MODE, pattern_blend_mode, lv_blend_m _LV_OBJ_STYLE_SET_GET_DECLARE(PATTERN_RECOLOR, pattern_recolor, lv_color_t, _color, nonscalar) _LV_OBJ_STYLE_SET_GET_DECLARE(PATTERN_OPA, pattern_opa, lv_opa_t, _opa, scalar) _LV_OBJ_STYLE_SET_GET_DECLARE(PATTERN_RECOLOR_OPA, pattern_recolor_opa, lv_opa_t, _opa, scalar) -_LV_OBJ_STYLE_SET_GET_DECLARE(PATTERN_IMAGE, pattern_image, const void *, _data_ptr, scalar) +_LV_OBJ_STYLE_SET_GET_DECLARE(PATTERN_IMAGE, pattern_image, const void *, _ptr, scalar) _LV_OBJ_STYLE_SET_GET_DECLARE(VALUE_LETTER_SPACE, value_letter_space, lv_style_int_t, _int, scalar) _LV_OBJ_STYLE_SET_GET_DECLARE(VALUE_LINE_SPACE, value_line_space, lv_style_int_t, _int, scalar) _LV_OBJ_STYLE_SET_GET_DECLARE(VALUE_BLEND_MODE, value_blend_mode, lv_blend_mode_t, _int, scalar) @@ -189,8 +165,8 @@ _LV_OBJ_STYLE_SET_GET_DECLARE(VALUE_OFS_Y, value_ofs_y, lv_style_int_t, _int, sc _LV_OBJ_STYLE_SET_GET_DECLARE(VALUE_ALIGN, value_align, lv_align_t, _int, scalar) _LV_OBJ_STYLE_SET_GET_DECLARE(VALUE_COLOR, value_color, lv_color_t, _color, nonscalar) _LV_OBJ_STYLE_SET_GET_DECLARE(VALUE_OPA, value_opa, lv_opa_t, _opa, scalar) -_LV_OBJ_STYLE_SET_GET_DECLARE(VALUE_FONT, value_font, const lv_font_t *, _data_ptr, scalar) -_LV_OBJ_STYLE_SET_GET_DECLARE(VALUE_STR, value_str, const char *, _data_ptr, scalar) +_LV_OBJ_STYLE_SET_GET_DECLARE(VALUE_FONT, value_font, const lv_font_t *, _ptr, scalar) +_LV_OBJ_STYLE_SET_GET_DECLARE(VALUE_STR, value_str, const char *, _ptr, scalar) _LV_OBJ_STYLE_SET_GET_DECLARE(TEXT_LETTER_SPACE, text_letter_space, lv_style_int_t, _int, scalar) _LV_OBJ_STYLE_SET_GET_DECLARE(TEXT_LINE_SPACE, text_line_space, lv_style_int_t, _int, scalar) _LV_OBJ_STYLE_SET_GET_DECLARE(TEXT_DECOR, text_decor, lv_text_decor_t, _int, scalar) @@ -198,7 +174,7 @@ _LV_OBJ_STYLE_SET_GET_DECLARE(TEXT_BLEND_MODE, text_blend_mode, lv_blend_mode_t, _LV_OBJ_STYLE_SET_GET_DECLARE(TEXT_COLOR, text_color, lv_color_t, _color, nonscalar) _LV_OBJ_STYLE_SET_GET_DECLARE(TEXT_SEL_COLOR, text_sel_color, lv_color_t, _color, nonscalar) _LV_OBJ_STYLE_SET_GET_DECLARE(TEXT_OPA, text_opa, lv_opa_t, _opa, scalar) -_LV_OBJ_STYLE_SET_GET_DECLARE(TEXT_FONT, text_font, const lv_font_t *, _data_ptr, scalar) +_LV_OBJ_STYLE_SET_GET_DECLARE(TEXT_FONT, text_font, const lv_font_t *, _ptr, scalar) _LV_OBJ_STYLE_SET_GET_DECLARE(LINE_WIDTH, line_width, lv_style_int_t, _int, scalar) _LV_OBJ_STYLE_SET_GET_DECLARE(LINE_BLEND_MODE, line_blend_mode, lv_blend_mode_t, _int, scalar) _LV_OBJ_STYLE_SET_GET_DECLARE(LINE_DASH_WIDTH, line_dash_width, lv_style_int_t, _int, scalar) @@ -219,10 +195,10 @@ _LV_OBJ_STYLE_SET_GET_DECLARE(TRANSITION_PROP_4, transition_prop_4, lv_style_int _LV_OBJ_STYLE_SET_GET_DECLARE(TRANSITION_PROP_5, transition_prop_5, lv_style_int_t, _int, scalar) _LV_OBJ_STYLE_SET_GET_DECLARE(TRANSITION_PROP_6, transition_prop_6, lv_style_int_t, _int, scalar) #if LV_USE_ANIMATION -_LV_OBJ_STYLE_SET_GET_DECLARE(TRANSITION_PATH, transition_path, lv_anim_path_cb_t, _func_ptr, func_ptr) +_LV_OBJ_STYLE_SET_GET_DECLARE(TRANSITION_PATH, transition_path, lv_anim_path_t *, _ptr, scalar) #else -_LV_OBJ_STYLE_SET_GET_DECLARE(TRANSITION_PATH, transition_path, _lv_style_prop_xcb_t, _func_ptr, - func_ptr) /*For compatibility*/ +/*For compatibility*/ +_LV_OBJ_STYLE_SET_GET_DECLARE(TRANSITION_PATH, transition_path, const void *, _ptr, scalar) #endif _LV_OBJ_STYLE_SET_GET_DECLARE(SCALE_WIDTH, scale_width, lv_style_int_t, _int, scalar) _LV_OBJ_STYLE_SET_GET_DECLARE(SCALE_BORDER_WIDTH, scale_border_width, lv_style_int_t, _int, scalar) diff --git a/src/lv_core/lv_style.c b/src/lv_core/lv_style.c index f264495d1..1fee0ade6 100644 --- a/src/lv_core/lv_style.c +++ b/src/lv_core/lv_style.c @@ -112,7 +112,7 @@ bool lv_style_remove_prop(lv_style_t * style, lv_style_property_t prop) if((prop & 0xF) < LV_STYLE_ID_COLOR) prop_size += sizeof(lv_style_int_t); else if((prop & 0xF) < LV_STYLE_ID_OPA) prop_size += sizeof(lv_color_t); else if((prop & 0xF) < LV_STYLE_ID_PTR) prop_size += sizeof(lv_opa_t); - else prop_size += sizeof(_lv_style_fptr_dptr_t); + else prop_size += sizeof(const void *); /*Move the props to fill the space of the property to delete*/ uint32_t i; @@ -341,7 +341,7 @@ uint16_t lv_style_get_mem_size(const lv_style_t * style) if((style->map[i] & 0xF) < LV_STYLE_ID_COLOR) i += sizeof(lv_style_int_t); else if((style->map[i] & 0xF) < LV_STYLE_ID_OPA) i += sizeof(lv_color_t); else if((style->map[i] & 0xF) < LV_STYLE_ID_PTR) i += sizeof(lv_opa_t); - else i += sizeof(_lv_style_fptr_dptr_t); + else i += sizeof(const void *); i += sizeof(lv_style_property_t); } @@ -499,7 +499,7 @@ void _lv_style_set_opa(lv_style_t * style, lv_style_property_t prop, lv_opa_t op * For example: `lv_style_set_border_width()` * @note for performance reasons it's not checked if the property is really has pointer type */ -void _lv_style_set_ptr(lv_style_t * style, lv_style_property_t prop, _lv_style_fptr_dptr_t p) +void _lv_style_set_ptr(lv_style_t * style, lv_style_property_t prop, const void * p) { LV_ASSERT_STYLE(style); @@ -513,26 +513,26 @@ void _lv_style_set_ptr(lv_style_t * style, lv_style_property_t prop, _lv_style_f attr_goal.full = (prop >> 8) & 0xFFU; if(attr_found.bits.state == attr_goal.bits.state) { - lv_memcpy_small(style->map + id + sizeof(lv_style_property_t), &p, sizeof(_lv_style_fptr_dptr_t)); + lv_memcpy_small(style->map + id + sizeof(lv_style_property_t), &p, sizeof(const void * )); return; } } /*Add new property if not exists yet*/ - uint8_t new_prop_size = (sizeof(lv_style_property_t) + sizeof(_lv_style_fptr_dptr_t)); + uint8_t new_prop_size = (sizeof(lv_style_property_t) + sizeof(const void * )); lv_style_property_t end_mark = _LV_STYLE_CLOSEING_PROP; uint8_t end_mark_size = sizeof(end_mark); uint16_t size = lv_style_get_mem_size(style); if(size == 0) size += end_mark_size; - size += sizeof(lv_style_property_t) + sizeof(_lv_style_fptr_dptr_t); + size += sizeof(lv_style_property_t) + sizeof(const void * ); style->map = lv_mem_realloc(style->map, size); LV_ASSERT_MEM(style->map); if(style == NULL) return; lv_memcpy_small(style->map + size - new_prop_size - end_mark_size, &prop, sizeof(lv_style_property_t)); - lv_memcpy_small(style->map + size - sizeof(_lv_style_fptr_dptr_t) - end_mark_size, &p, sizeof(_lv_style_fptr_dptr_t)); + lv_memcpy_small(style->map + size - sizeof(const void * ) - end_mark_size, &p, sizeof(const void * )); lv_memcpy_small(style->map + size - end_mark_size, &end_mark, sizeof(end_mark)); } @@ -656,7 +656,7 @@ int16_t _lv_style_get_color(const lv_style_t * style, lv_style_property_t prop, */ int16_t _lv_style_get_ptr(const lv_style_t * style, lv_style_property_t prop, void * v_res) { - _lv_style_fptr_dptr_t * res = (_lv_style_fptr_dptr_t *)v_res; + const void ** res = (const void **)v_res; if(style == NULL) return -1; if(style->map == NULL) return -1; @@ -665,7 +665,7 @@ int16_t _lv_style_get_ptr(const lv_style_t * style, lv_style_property_t prop, vo return -1; } else { - lv_memcpy_small(res, &style->map[id + sizeof(lv_style_property_t)], sizeof(_lv_style_fptr_dptr_t)); + lv_memcpy_small(res, &style->map[id + sizeof(lv_style_property_t)], sizeof(const void *)); lv_style_attr_t attr_act; attr_act.full = style->map[id + 1]; @@ -791,7 +791,7 @@ void lv_style_list_set_local_color(lv_style_list_t * list, lv_style_property_t p * @param value the value to set * @note for performance reasons it's not checked if the property really has pointer type */ -void lv_style_list_set_local_ptr(lv_style_list_t * list, lv_style_property_t prop, _lv_style_fptr_dptr_t value) +void lv_style_list_set_local_ptr(lv_style_list_t * list, lv_style_property_t prop, const void * value) { LV_ASSERT_STYLE_LIST(list); @@ -964,7 +964,7 @@ lv_res_t lv_style_list_get_opa(lv_style_list_t * list, lv_style_property_t prop, * LV_RES_INV: there was NO matching property in the list * @note for performance reasons it's not checked if the property really has pointer type */ -lv_res_t lv_style_list_get_ptr(lv_style_list_t * list, lv_style_property_t prop, _lv_style_fptr_dptr_t * res) +lv_res_t lv_style_list_get_ptr(lv_style_list_t * list, lv_style_property_t prop, const void ** res) { LV_ASSERT_STYLE_LIST(list); @@ -977,9 +977,7 @@ lv_res_t lv_style_list_get_ptr(lv_style_list_t * list, lv_style_property_t prop, int16_t weight = -1; - _lv_style_fptr_dptr_t value_act; - value_act.dptr = NULL; - value_act.fptr = NULL; + const void * value_act; int16_t ci; for(ci = 0; ci < list->style_cnt; ci++) { @@ -987,20 +985,17 @@ lv_res_t lv_style_list_get_ptr(lv_style_list_t * list, lv_style_property_t prop, int16_t weight_act = _lv_style_get_ptr(class, prop, &value_act); /*On perfect match return the value immediately*/ if(weight_act == weight_goal) { - res->dptr = value_act.dptr; - res->fptr = value_act.fptr; + *res = value_act; return LV_RES_OK; } else if(list->has_trans && weight_act >= 0 && ci == 0 && !list->skip_trans) { - res->dptr = value_act.dptr; - res->fptr = value_act.fptr; + *res = value_act; return LV_RES_OK; } /*If the found ID is better the current candidate then use it*/ else if(weight_act > weight) { weight = weight_act; - res->dptr = value_act.dptr; - res->fptr = value_act.fptr; + *res = value_act; } } @@ -1059,7 +1054,7 @@ static inline int32_t get_property_index(const lv_style_t * style, lv_style_prop if((style->map[i] & 0xF) < LV_STYLE_ID_COLOR) i += sizeof(lv_style_int_t); else if((style->map[i] & 0xF) < LV_STYLE_ID_OPA) i += sizeof(lv_color_t); else if((style->map[i] & 0xF) < LV_STYLE_ID_PTR) i += sizeof(lv_opa_t); - else i += sizeof(_lv_style_fptr_dptr_t); + else i += sizeof(const void *); i += sizeof(lv_style_property_t); } diff --git a/src/lv_core/lv_style.h b/src/lv_core/lv_style.h index 3cfccbfec..52b611901 100644 --- a/src/lv_core/lv_style.h +++ b/src/lv_core/lv_style.h @@ -216,16 +216,6 @@ typedef struct { typedef int16_t lv_style_int_t; -/*A helper general function pointer*/ -typedef void(*_lv_style_prop_xcb_t)(void); - -/*A helper type to handle data pointers and function pointer is the same way.*/ -typedef union { - _lv_style_prop_xcb_t fptr; - const void * dptr; -} _lv_style_fptr_dptr_t; - - typedef struct { lv_style_t ** style_list; #if LV_USE_ASSERT_STYLE @@ -373,43 +363,8 @@ void _lv_style_set_opa(lv_style_t * style, lv_style_property_t prop, lv_opa_t op * For example: `lv_style_set_border_width()` * @note for performance reasons it's not checked if the property really has pointer type */ -void _lv_style_set_ptr(lv_style_t * style, lv_style_property_t prop, _lv_style_fptr_dptr_t p); +void _lv_style_set_ptr(lv_style_t * style, lv_style_property_t prop, const void * p); -/** - * Set a function pointer typed property in a style. - * @param style pointer to a style where the property should be set - * @param prop a style property ORed with a state. - * E.g. `LV_STYLE_TRANSITION_PATH | (LV_STATE_PRESSED << LV_STYLE_STATE_POS)` - * @param value the value to set - * @note shouldn't be used directly. Use the specific property set functions instead. - * For example: `lv_style_set_border_width()` - * @note for performance reasons it's not checked if the property really has pointer type - */ -static inline void _lv_style_set_func_ptr(lv_style_t * style, lv_style_property_t prop, _lv_style_prop_xcb_t p) -{ - _lv_style_fptr_dptr_t fd; - fd.dptr = NULL; - fd.fptr = p; - _lv_style_set_ptr(style, prop, fd); -} - -/** - * Set a data pointer typed property in a style. - * @param style pointer to a style where the property should be set - * @param prop a style property ORed with a state. - * E.g. `LV_STYLE_TRANSITION_PATH | (LV_STATE_PRESSED << LV_STYLE_STATE_POS)` - * @param value the value to set - * @note shouldn't be used directly. Use the specific property set functions instead. - * For example: `lv_style_set_border_width()` - * @note for performance reasons it's not checked if the property really has pointer type - */ -static inline void _lv_style_set_data_ptr(lv_style_t * style, lv_style_property_t prop, const void * p) -{ - _lv_style_fptr_dptr_t fd; - fd.fptr = NULL; - fd.dptr = p; - _lv_style_set_ptr(style, prop, fd); -} /** @@ -472,57 +427,6 @@ int16_t _lv_style_get_opa(const lv_style_t * style, lv_style_property_t prop, vo */ int16_t _lv_style_get_ptr(const lv_style_t * style, lv_style_property_t prop, void * res); -/** - * Get a pointer typed property from a style. - * @param style pointer to a style from where the property should be get - * @param prop a style property ORed with a state. - * E.g. `LV_STYLE_TEXT_FONT | (LV_STATE_PRESSED << LV_STYLE_STATE_POS)` - * @param res pointer to a buffer to store the result value - * @return -1: the property wasn't found in the style. - * The matching state bits of the desired state (in `prop`) and the best matching property's state - * Higher value means match in higher precedence state. - * @note shouldn't be used directly. Use the specific property get functions instead. - * For example: `lv_style_get_transition_path()` - * @note for performance reasons it's not checked if the property really has pointer type - */ -static inline int16_t _lv_style_get_func_ptr(const lv_style_t * style, lv_style_property_t prop, void * res) -{ - _lv_style_fptr_dptr_t fd_res; - fd_res.dptr = NULL; - fd_res.fptr = NULL; - lv_res_t r = _lv_style_get_ptr(style, prop, &fd_res); - - _lv_style_prop_xcb_t * res2 = (_lv_style_prop_xcb_t *)res; - *res2 = fd_res.fptr; - return r; -} - -/** - * Get a pointer typed property from a style. - * @param style pointer to a style from where the property should be get - * @param prop a style property ORed with a state. - * E.g. `LV_STYLE_TEXT_FONT | (LV_STATE_PRESSED << LV_STYLE_STATE_POS)` - * @param res pointer to a buffer to store the result value - * @return -1: the property wasn't found in the style. - * The matching state bits of the desired state (in `prop`) and the best matching property's state - * Higher value means match in higher precedence state. - * @note shouldn't be used directly. Use the specific property get functions instead. - * For example: `lv_style_get_text_font()` - * @note for performance reasons it's not checked if the property really has pointer type - */ -static inline int16_t _lv_style_get_data_ptr(const lv_style_t * style, lv_style_property_t prop, void * res) -{ - _lv_style_fptr_dptr_t fd_res; - fd_res.dptr = NULL; - fd_res.fptr = NULL; - lv_res_t r = _lv_style_get_ptr(style, prop, &fd_res); - - void ** res2 = (void **)res; - *res2 = (void *)fd_res.dptr; - return r; -} - - /** * Get the local style of a style list * @param list pointer to a style list where the local property should be set @@ -582,41 +486,8 @@ void lv_style_list_set_local_opa(lv_style_list_t * list, lv_style_property_t pro * @param value the value to set * @note for performance reasons it's not checked if the property really has pointer type */ -void lv_style_list_set_local_ptr(lv_style_list_t * list, lv_style_property_t prop, _lv_style_fptr_dptr_t value); +void lv_style_list_set_local_ptr(lv_style_list_t * list, lv_style_property_t prop, const void * value); -/** - * Set a local pointer typed property in a style list. - * @param list pointer to a style list where the local property should be set - * @param prop a style property ORed with a state. - * E.g. `LV_STYLE_TRANSITION_PATH | (LV_STATE_PRESSED << LV_STYLE_STATE_POS)` - * @param value the value to set - * @note for performance reasons it's not checked if the property really has pointer type - */ -static inline void lv_style_list_set_local_func_ptr(lv_style_list_t * list, lv_style_property_t prop, - _lv_style_prop_xcb_t value) -{ - _lv_style_fptr_dptr_t fd; - fd.dptr = NULL; - fd.fptr = value; - lv_style_list_set_local_ptr(list, prop, fd); -} - -/** - * Set a local pointer typed property in a style list. - * @param list pointer to a style list where the local property should be set - * @param prop a style property ORed with a state. - * E.g. `LV_STYLE_TEXT_FONT | (LV_STATE_PRESSED << LV_STYLE_STATE_POS)` - * @param value the value to set - * @note for performance reasons it's not checked if the property really has pointer type - */ -static inline void lv_style_list_set_local_data_ptr(lv_style_list_t * list, lv_style_property_t prop, - const void * value) -{ - _lv_style_fptr_dptr_t fd; - fd.fptr = NULL; - fd.dptr = value; - lv_style_list_set_local_ptr(list, prop, fd); -} /** * Get an integer typed property from a style list. * It will return the property which match best with given state. @@ -667,55 +538,10 @@ lv_res_t lv_style_list_get_opa(lv_style_list_t * list, lv_style_property_t prop, * @return LV_RES_OK: there was a matching property in the list * LV_RES_INV: there was NO matching property in the list * @note for performance reasons it's not checked if the property really has pointer type - * @note Do not use this function directly. Use `lv_style_list_get_func_ptr` or `lv_style_list_get_data_ptr` */ -lv_res_t lv_style_list_get_ptr(lv_style_list_t * list, lv_style_property_t prop, _lv_style_fptr_dptr_t * res); +lv_res_t lv_style_list_get_ptr(lv_style_list_t * list, lv_style_property_t prop, const void ** res); -/** - * Get a function pointer typed property from a style list. - * It will return the property which match best with given state. - * @param list pointer to a style list from where the property should be get - * @param prop a style property ORed with a state. - * E.g. `LV_STYLE_TRANSITION_PATH | (LV_STATE_PRESSED << LV_STYLE_STATE_POS)` - * @param res pointer to a buffer to store the result - * @return LV_RES_OK: there was a matching property in the list - * LV_RES_INV: there was NO matching property in the list - * @note for performance reasons it's not checked if the property really has pointer type - */ -static inline lv_res_t lv_style_list_get_func_ptr(lv_style_list_t * list, lv_style_property_t prop, void (**res)(void)) -{ - _lv_style_fptr_dptr_t fd_res; - fd_res.dptr = NULL; - fd_res.fptr = NULL; - lv_res_t r = lv_style_list_get_ptr(list, prop, &fd_res); - - *res = fd_res.fptr; - return r; -} - -/** - * Get a data pointer typed property from a style list. - * It will return the property which match best with given state. - * @param list pointer to a style list from where the property should be get - * @param prop a style property ORed with a state. - * E.g. `LV_STYLE_TEXT_FONT | (LV_STATE_PRESSED << LV_STYLE_STATE_POS)` - * @param res pointer to a buffer to store the result - * @return LV_RES_OK: there was a matching property in the list - * LV_RES_INV: there was NO matching property in the list - * @note for performance reasons it's not checked if the property really has pointer type - */ -static inline lv_res_t lv_style_list_get_data_ptr(lv_style_list_t * list, lv_style_property_t prop, const void ** res) -{ - _lv_style_fptr_dptr_t fd_res; - fd_res.dptr = NULL; - fd_res.fptr = NULL; - lv_res_t r = lv_style_list_get_ptr(list, prop, &fd_res); - - *res = fd_res.dptr; - return r; -} - /************************* * GLOBAL VARIABLES *************************/ diff --git a/src/lv_misc/lv_anim.c b/src/lv_misc/lv_anim.c index 5eb33197d..e82653746 100644 --- a/src/lv_misc/lv_anim.c +++ b/src/lv_misc/lv_anim.c @@ -45,6 +45,7 @@ static bool anim_ready_handler(lv_anim_t * a); static uint32_t last_task_run; static bool anim_list_changed; static lv_task_t * _lv_anim_task; +const lv_anim_path_t lv_anim_path_def = {.cb = lv_anim_path_linear}; /********************** * MACROS @@ -81,7 +82,7 @@ void lv_anim_init(lv_anim_t * a) a->time = 500; a->start = 0; a->end = 100; - a->path_cb = lv_anim_path_linear; + lv_memcpy_small(&a->path, &lv_anim_path_def, sizeof(lv_anim_path_cb_t)); a->repeat_cnt = 1; a->early_apply = 1; } @@ -221,7 +222,7 @@ void lv_anim_refr_now(void) * @param a pointer to an animation * @return the current value to set */ -lv_anim_value_t lv_anim_path_linear(const lv_anim_t * a) +lv_anim_value_t lv_anim_path_linear(const lv_anim_path_t * path, const lv_anim_t * a) { /*Calculate the current step*/ uint32_t step; @@ -247,7 +248,7 @@ lv_anim_value_t lv_anim_path_linear(const lv_anim_t * a) * @param a pointer to an animation * @return the current value to set */ -lv_anim_value_t lv_anim_path_ease_in(const lv_anim_t * a) +lv_anim_value_t lv_anim_path_ease_in(const lv_anim_path_t * path, const lv_anim_t * a) { /*Calculate the current step*/ uint32_t t; @@ -271,7 +272,7 @@ lv_anim_value_t lv_anim_path_ease_in(const lv_anim_t * a) * @param a pointer to an animation * @return the current value to set */ -lv_anim_value_t lv_anim_path_ease_out(const lv_anim_t * a) +lv_anim_value_t lv_anim_path_ease_out(const lv_anim_path_t * path, const lv_anim_t * a) { /*Calculate the current step*/ @@ -296,7 +297,7 @@ lv_anim_value_t lv_anim_path_ease_out(const lv_anim_t * a) * @param a pointer to an animation * @return the current value to set */ -lv_anim_value_t lv_anim_path_ease_in_out(const lv_anim_t * a) +lv_anim_value_t lv_anim_path_ease_in_out(const lv_anim_path_t * path, const lv_anim_t * a) { /*Calculate the current step*/ @@ -321,7 +322,7 @@ lv_anim_value_t lv_anim_path_ease_in_out(const lv_anim_t * a) * @param a pointer to an animation * @return the current value to set */ -lv_anim_value_t lv_anim_path_overshoot(const lv_anim_t * a) +lv_anim_value_t lv_anim_path_overshoot(const lv_anim_path_t * path, const lv_anim_t * a) { /*Calculate the current step*/ @@ -347,7 +348,7 @@ lv_anim_value_t lv_anim_path_overshoot(const lv_anim_t * a) * @param a pointer to an animation * @return the current value to set */ -lv_anim_value_t lv_anim_path_bounce(const lv_anim_t * a) +lv_anim_value_t lv_anim_path_bounce(const lv_anim_path_t * path, const lv_anim_t * a) { /*Calculate the current step*/ uint32_t t; @@ -409,7 +410,7 @@ lv_anim_value_t lv_anim_path_bounce(const lv_anim_t * a) * @param a pointer to an animation * @return the current value to set */ -lv_anim_value_t lv_anim_path_step(const lv_anim_t * a) +lv_anim_value_t lv_anim_path_step(const lv_anim_path_t * path, const lv_anim_t * a) { if(a->act_time >= a->time) return a->end; @@ -458,7 +459,8 @@ static void anim_task(lv_task_t * param) if(a->act_time > a->time) a->act_time = a->time; int32_t new_value; - new_value = a->path_cb(a); + if(a->path.cb) new_value = a->path.cb(&a->path, a); + else new_value = lv_anim_path_linear(&a->path, a); /*Apply the calculated value*/ if(a->exec_cb) a->exec_cb(a->var, new_value); @@ -490,7 +492,7 @@ static void anim_task(lv_task_t * param) static bool anim_ready_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_INFINIT) { + if(a->playback_now == 0 && a->repeat_cnt > 0 && a->repeat_cnt != LV_ANIM_REPEAT_INFINITE) { a->repeat_cnt--; } diff --git a/src/lv_misc/lv_anim.h b/src/lv_misc/lv_anim.h index c9583810e..e5f99aeea 100644 --- a/src/lv_misc/lv_anim.h +++ b/src/lv_misc/lv_anim.h @@ -18,6 +18,7 @@ extern "C" { #include #include #include +#include "lv_mem.h" /********************* * DEFINES @@ -40,9 +41,20 @@ typedef lv_coord_t lv_anim_value_t; #if LV_USE_ANIMATION -#define LV_ANIM_REPEAT_INFINIT 0xFFFF +#define LV_ANIM_REPEAT_INFINITE 0xFFFF + struct _lv_anim_t; +struct _lv_anim_path_t; +/** Get the current value during an animation*/ +typedef lv_anim_value_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; + + /** Generic prototype of "animator" functions. * First parameter is the variable to animate. @@ -56,9 +68,6 @@ typedef void (*lv_anim_exec_xcb_t)(void *, lv_anim_value_t); * It's more consistent but less convenient. Might be used by binding generator functions.*/ typedef void (*lv_anim_custom_exec_cb_t)(struct _lv_anim_t *, lv_anim_value_t); -/** Get the current value during an animation*/ -typedef lv_anim_value_t (*lv_anim_path_cb_t)(const struct _lv_anim_t *); - /** Callback to call when the animation is ready*/ typedef void (*lv_anim_ready_cb_t)(struct _lv_anim_t *); @@ -69,9 +78,9 @@ typedef void (*lv_anim_start_cb_t)(struct _lv_anim_t *); typedef struct _lv_anim_t { void * var; /**path_cb = path_cb; + lv_memcpy_small(&a->path, path, sizeof(lv_anim_path_t)); } @@ -259,6 +268,34 @@ static inline void lv_anim_set_repeat_delay(lv_anim_t * a, uint16_t delay) */ void lv_anim_start(lv_anim_t * a); +/** + * Initialize an animation path + * @param path pointer to path + */ +static inline void lv_anim_path_init(lv_anim_path_t * path) +{ + lv_memset_00(path, sizeof(lv_anim_path_t)); +} + +/** + * 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 @@ -333,42 +370,42 @@ void lv_anim_refr_now(void); * @param a pointer to an animation * @return the current value to set */ -lv_anim_value_t lv_anim_path_linear(const lv_anim_t * a); +lv_anim_value_t lv_anim_path_linear(const lv_anim_path_t * path, 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 */ -lv_anim_value_t lv_anim_path_ease_in(const lv_anim_t * a); +lv_anim_value_t lv_anim_path_ease_in(const lv_anim_path_t * path, 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 */ -lv_anim_value_t lv_anim_path_ease_out(const lv_anim_t * a); +lv_anim_value_t lv_anim_path_ease_out(const lv_anim_path_t * path, 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 */ -lv_anim_value_t lv_anim_path_ease_in_out(const lv_anim_t * a); +lv_anim_value_t lv_anim_path_ease_in_out(const lv_anim_path_t * path, 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 */ -lv_anim_value_t lv_anim_path_overshoot(const lv_anim_t * a); +lv_anim_value_t lv_anim_path_overshoot(const lv_anim_path_t * path, 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 */ -lv_anim_value_t lv_anim_path_bounce(const lv_anim_t * a); +lv_anim_value_t lv_anim_path_bounce(const lv_anim_path_t * path, const lv_anim_t * a); /** * Calculate the current value of an animation applying step characteristic. @@ -376,7 +413,12 @@ lv_anim_value_t lv_anim_path_bounce(const lv_anim_t * a); * @param a pointer to an animation * @return the current value to set */ -lv_anim_value_t lv_anim_path_step(const lv_anim_t * a); +lv_anim_value_t lv_anim_path_step(const lv_anim_path_t * path, const lv_anim_t * a); + +/********************** + * GLOBAL VARIABLES + **********************/ +extern const lv_anim_path_t lv_anim_path_def; /********************** * MACROS diff --git a/src/lv_widgets/lv_label.c b/src/lv_widgets/lv_label.c index 3061f8f80..656b0a197 100644 --- a/src/lv_widgets/lv_label.c +++ b/src/lv_widgets/lv_label.c @@ -1208,7 +1208,7 @@ static void lv_label_refr_text(lv_obj_t * label) lv_anim_t a; lv_anim_init(&a); lv_anim_set_var(&a, label); - lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINIT); + lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE); lv_anim_set_playback_delay(&a, (((lv_font_get_glyph_width(font, ' ', ' ') + letter_space) * 1000) / ext->anim_speed) * LV_LABEL_WAIT_CHAR_COUNT); @@ -1291,7 +1291,7 @@ static void lv_label_refr_text(lv_obj_t * label) lv_anim_t a; lv_anim_init(&a); lv_anim_set_var(&a, label); - lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINIT); + lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE); bool hor_anim = false; if(size.x > lv_area_get_width(&txt_coords)) { diff --git a/src/lv_widgets/lv_spinner.c b/src/lv_widgets/lv_spinner.c index 2f7186a24..06a68557e 100644 --- a/src/lv_widgets/lv_spinner.c +++ b/src/lv_widgets/lv_spinner.c @@ -168,12 +168,16 @@ void lv_spinner_set_type(lv_obj_t * spinner, lv_spinner_type_t type) switch(type) { case LV_SPINNER_TYPE_FILLSPIN_ARC: { ext->anim_type = LV_SPINNER_TYPE_FILLSPIN_ARC; + 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); lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)lv_spinner_anim_cb); - lv_anim_set_path_cb(&a, lv_anim_path_ease_in_out); - lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINIT); + lv_anim_set_path(&a, &path); + lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE); lv_anim_set_time(&a, ext->time); if(ext->anim_dir == LV_SPINNER_DIR_FORWARD) lv_anim_set_values(&a, 0, 360); else lv_anim_set_values(&a, 360, 0); @@ -191,13 +195,18 @@ void lv_spinner_set_type(lv_obj_t * spinner, lv_spinner_type_t type) case LV_SPINNER_TYPE_SPINNING_ARC: default: { ext->anim_type = type; + + lv_anim_path_t path; + lv_anim_path_init(&path); + lv_anim_path_set_cb(&path, (LV_SPINNER_TYPE_CONSTANT_ARC == type ? lv_anim_path_linear : lv_anim_path_ease_in_out)); + lv_anim_t a; lv_anim_init(&a); lv_anim_set_var(&a, spinner); lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)lv_spinner_anim_cb); lv_anim_set_time(&a, ext->time); - lv_anim_set_path_cb(&a, (LV_SPINNER_TYPE_CONSTANT_ARC == type ? lv_anim_path_linear : lv_anim_path_ease_in_out)); - lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINIT); + lv_anim_set_path(&a, &path); + lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE); if(ext->anim_dir == LV_SPINNER_DIR_FORWARD) lv_anim_set_values(&a, 0, 360); else lv_anim_set_values(&a, 360, 0); lv_anim_start(&a); diff --git a/src/lv_widgets/lv_textarea.c b/src/lv_widgets/lv_textarea.c index 4193c97a7..002113d3c 100644 --- a/src/lv_widgets/lv_textarea.c +++ b/src/lv_widgets/lv_textarea.c @@ -193,6 +193,10 @@ lv_obj_t * lv_textarea_create(lv_obj_t * par, const lv_obj_t * copy) #if LV_USE_ANIMATION if(ext->cursor.blink_time) { /*Create a cursor blinker animation*/ + 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); @@ -200,8 +204,8 @@ lv_obj_t * lv_textarea_create(lv_obj_t * par, const lv_obj_t * copy) lv_anim_set_time(&a, ext->cursor.blink_time); lv_anim_set_playback_time(&a, ext->cursor.blink_time); lv_anim_set_values(&a, 0, 1); - lv_anim_set_path_cb(&a, lv_anim_path_step); - lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINIT); + lv_anim_set_path(&a, &path); + lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE); lv_anim_start(&a); } #endif @@ -281,13 +285,17 @@ void lv_textarea_add_char(lv_obj_t * ta, uint32_t c) #if LV_USE_ANIMATION /*Auto hide characters*/ + 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, (lv_anim_exec_xcb_t)pwd_char_hider_anim); lv_anim_set_time(&a, ext->pwd_show_time); lv_anim_set_values(&a, 0, 1); - lv_anim_set_path_cb(&a, lv_anim_path_step); + lv_anim_set_path(&a, &path); lv_anim_set_ready_cb(&a, pwd_char_hider_anim_ready); lv_anim_start(&a); @@ -364,13 +372,16 @@ void lv_textarea_add_text(lv_obj_t * ta, const char * txt) #if LV_USE_ANIMATION /*Auto hide characters*/ + 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, (lv_anim_exec_xcb_t)pwd_char_hider_anim); lv_anim_set_time(&a, ext->pwd_show_time); lv_anim_set_values(&a, 0, 1); - lv_anim_set_path_cb(&a, lv_anim_path_step); + lv_anim_set_path(&a, &path); lv_anim_set_ready_cb(&a, pwd_char_hider_anim_ready); lv_anim_start(&a); #else @@ -521,13 +532,17 @@ void lv_textarea_set_text(lv_obj_t * ta, const char * txt) #if LV_USE_ANIMATION /*Auto hide characters*/ + 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, (lv_anim_exec_xcb_t)pwd_char_hider_anim); lv_anim_set_time(&a, ext->pwd_show_time); lv_anim_set_values(&a, 0, 1); - lv_anim_set_path_cb(&a, lv_anim_path_step); + lv_anim_set_path(&a, &path); lv_anim_set_ready_cb(&a, pwd_char_hider_anim_ready); lv_anim_start(&a); #else @@ -640,6 +655,10 @@ void lv_textarea_set_cursor_pos(lv_obj_t * ta, int16_t pos) #if LV_USE_ANIMATION if(ext->cursor.blink_time) { /*Reset cursor blink animation*/ + 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); @@ -647,8 +666,8 @@ void lv_textarea_set_cursor_pos(lv_obj_t * ta, int16_t pos) lv_anim_set_time(&a, ext->cursor.blink_time); lv_anim_set_playback_time(&a, ext->cursor.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_INFINIT); + lv_anim_set_path(&a, &path); + lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE); lv_anim_start(&a); } #endif @@ -901,6 +920,10 @@ void lv_textarea_set_cursor_blink_time(lv_obj_t * ta, uint16_t time) #if LV_USE_ANIMATION if(ext->cursor.blink_time) { /*Reset cursor blink animation*/ + 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); @@ -908,7 +931,7 @@ void lv_textarea_set_cursor_blink_time(lv_obj_t * ta, uint16_t time) lv_anim_set_time(&a, ext->cursor.blink_time); lv_anim_set_playback_time(&a, ext->cursor.blink_time); lv_anim_set_values(&a, 1, 0); - lv_anim_set_path_cb(&a, lv_anim_path_step); + lv_anim_set_path(&a, &path); lv_anim_start(&a); } else { diff --git a/src/lv_widgets/lv_tileview.c b/src/lv_widgets/lv_tileview.c index 56792049f..d6f2eae1d 100644 --- a/src/lv_widgets/lv_tileview.c +++ b/src/lv_widgets/lv_tileview.c @@ -233,13 +233,11 @@ void lv_tileview_set_tile_act(lv_obj_t * tileview, lv_coord_t x, lv_coord_t y, l lv_coord_t x_act = lv_obj_get_x(scrl); lv_coord_t y_act = lv_obj_get_y(scrl); - lv_anim_t a; lv_anim_init(&a); lv_anim_set_var(&a, scrl); lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)lv_obj_set_x); lv_anim_set_time(&a, ext->anim_time); - lv_anim_set_path_cb(&a, lv_anim_path_linear); if(x_coord != x_act) { diff --git a/tests/lv_test_core/lv_test_style.c b/tests/lv_test_core/lv_test_style.c index 61c9346f0..ec886fc18 100644 --- a/tests/lv_test_core/lv_test_style.c +++ b/tests/lv_test_core/lv_test_style.c @@ -85,7 +85,7 @@ static void empty_style(void) found = lv_style_list_get_opa(&style_list, LV_STYLE_BG_OPA, &opa); lv_test_assert_int_eq(LV_RES_INV, found, "Get an 'opa' property"); - found = lv_style_list_get_data_ptr(&style_list, LV_STYLE_TEXT_FONT, &ptr); + found = lv_style_list_get_ptr(&style_list, LV_STYLE_TEXT_FONT, &ptr); lv_test_assert_int_eq(LV_RES_INV, found, "Get a 'ptr' property"); found = lv_style_list_get_color(&style_list, LV_STYLE_BG_COLOR, &color); @@ -120,7 +120,7 @@ static void add_remove_read_prop(void) found = lv_style_list_get_opa(&style_list, LV_STYLE_BG_OPA, &opa); lv_test_assert_int_eq(LV_RES_INV, found, "Get a non existing 'opa' property"); - found = lv_style_list_get_data_ptr(&style_list, LV_STYLE_TEXT_FONT, &ptr); + found = lv_style_list_get_ptr(&style_list, LV_STYLE_TEXT_FONT, &ptr); lv_test_assert_int_eq(LV_RES_INV, found, "Get a non existing 'ptr' property"); found = lv_style_list_get_color(&style_list, LV_STYLE_BG_COLOR, &color); @@ -129,7 +129,7 @@ static void add_remove_read_prop(void) lv_test_print("Set properties and read back the values"); _lv_style_set_int(&style, LV_STYLE_TEXT_LINE_SPACE, 5); _lv_style_set_opa(&style, LV_STYLE_BG_OPA, LV_OPA_50); - _lv_style_set_data_ptr(&style, LV_STYLE_TEXT_FONT, LV_THEME_DEFAULT_FONT_NORMAL); + _lv_style_set_ptr(&style, LV_STYLE_TEXT_FONT, LV_THEME_DEFAULT_FONT_NORMAL); _lv_style_set_color(&style, LV_STYLE_BG_COLOR, LV_COLOR_RED); found = lv_style_list_get_int(&style_list, LV_STYLE_TEXT_LINE_SPACE, &value); @@ -140,7 +140,7 @@ static void add_remove_read_prop(void) lv_test_assert_int_eq(LV_RES_OK, found, "Get an existing 'opa' property"); lv_test_assert_int_eq(LV_OPA_50, opa, "Get the value of an 'opa' property"); - found = lv_style_list_get_data_ptr(&style_list, LV_STYLE_TEXT_FONT, &ptr); + found = lv_style_list_get_ptr(&style_list, LV_STYLE_TEXT_FONT, &ptr); lv_test_assert_int_eq(LV_RES_OK, found, "Get an existing 'ptr' property"); lv_test_assert_ptr_eq(LV_THEME_DEFAULT_FONT_NORMAL, ptr, "Get the value of a 'ptr' property"); @@ -156,7 +156,7 @@ static void add_remove_read_prop(void) found = lv_style_list_get_opa(&style_list, LV_STYLE_BG_OPA, &opa); lv_test_assert_int_eq(LV_RES_INV, found, "Get an 'opa' property from a reseted style"); - found = lv_style_list_get_data_ptr(&style_list, LV_STYLE_TEXT_FONT, &ptr); + found = lv_style_list_get_ptr(&style_list, LV_STYLE_TEXT_FONT, &ptr); lv_test_assert_int_eq(LV_RES_INV, found, "Get an 'ptr' property from a reseted style"); found = lv_style_list_get_color(&style_list, LV_STYLE_BG_COLOR, &color); @@ -194,7 +194,7 @@ static void cascade(void) _lv_style_set_int(&style_first, LV_STYLE_TEXT_LINE_SPACE, 5); _lv_style_set_opa(&style_first, LV_STYLE_BG_OPA, LV_OPA_50); - _lv_style_set_data_ptr(&style_first, LV_STYLE_TEXT_FONT, LV_THEME_DEFAULT_FONT_NORMAL); + _lv_style_set_ptr(&style_first, LV_STYLE_TEXT_FONT, LV_THEME_DEFAULT_FONT_NORMAL); _lv_style_set_color(&style_first, LV_STYLE_BG_COLOR, LV_COLOR_RED); found = lv_style_list_get_int(&style_list, LV_STYLE_TEXT_LINE_SPACE, &value); @@ -205,7 +205,7 @@ static void cascade(void) lv_test_assert_int_eq(LV_RES_OK, found, "Get an 'opa' property"); lv_test_assert_int_eq(LV_OPA_50, opa, "Get the value of an 'opa' property"); - found = lv_style_list_get_data_ptr(&style_list, LV_STYLE_TEXT_FONT, &ptr); + found = lv_style_list_get_ptr(&style_list, LV_STYLE_TEXT_FONT, &ptr); lv_test_assert_int_eq(LV_RES_OK, found, "Get an 'ptr' property"); lv_test_assert_ptr_eq(LV_THEME_DEFAULT_FONT_NORMAL, ptr, "Get the value of a 'ptr' property"); @@ -217,7 +217,7 @@ static void cascade(void) _lv_style_set_int(&style_second, LV_STYLE_TEXT_LINE_SPACE, 10); _lv_style_set_opa(&style_second, LV_STYLE_BG_OPA, LV_OPA_60); - _lv_style_set_data_ptr(&style_second, LV_STYLE_TEXT_FONT, LV_THEME_DEFAULT_FONT_NORMAL + 1); + _lv_style_set_ptr(&style_second, LV_STYLE_TEXT_FONT, LV_THEME_DEFAULT_FONT_NORMAL + 1); _lv_style_set_color(&style_second, LV_STYLE_BG_COLOR, LV_COLOR_BLUE); found = lv_style_list_get_int(&style_list, LV_STYLE_TEXT_LINE_SPACE, &value); @@ -228,7 +228,7 @@ static void cascade(void) lv_test_assert_int_eq(LV_RES_OK, found, "Get an overwritten 'opa' property"); lv_test_assert_int_eq(LV_OPA_60, opa, "Get the value of an overwritten 'opa' property"); - found = lv_style_list_get_data_ptr(&style_list, LV_STYLE_TEXT_FONT, &ptr); + found = lv_style_list_get_ptr(&style_list, LV_STYLE_TEXT_FONT, &ptr); lv_test_assert_int_eq(LV_RES_OK, found, "Get an overwritten 'ptr' property"); lv_test_assert_ptr_eq(LV_THEME_DEFAULT_FONT_NORMAL + 1, ptr, "Get the value of an overwritten 'ptr' property"); @@ -240,7 +240,7 @@ static void cascade(void) lv_test_print("Overwrite the properties with the local style"); lv_style_list_set_local_int(&style_list, LV_STYLE_TEXT_LINE_SPACE, 20); lv_style_list_set_local_opa(&style_list, LV_STYLE_BG_OPA, LV_OPA_70); - lv_style_list_set_local_data_ptr(&style_list, LV_STYLE_TEXT_FONT, LV_THEME_DEFAULT_FONT_NORMAL + 2); + lv_style_list_set_local_ptr(&style_list, LV_STYLE_TEXT_FONT, LV_THEME_DEFAULT_FONT_NORMAL + 2); lv_style_list_set_local_color(&style_list, LV_STYLE_BG_COLOR, LV_COLOR_LIME); found = lv_style_list_get_int(&style_list, LV_STYLE_TEXT_LINE_SPACE, &value); @@ -251,7 +251,7 @@ static void cascade(void) lv_test_assert_int_eq(LV_RES_OK, found, "Get a local 'opa' property"); lv_test_assert_int_eq(LV_OPA_70, opa, "Get the value of a local 'opa' property"); - found = lv_style_list_get_data_ptr(&style_list, LV_STYLE_TEXT_FONT, &ptr); + found = lv_style_list_get_ptr(&style_list, LV_STYLE_TEXT_FONT, &ptr); lv_test_assert_int_eq(LV_RES_OK, found, "Get a local 'ptr' property"); lv_test_assert_ptr_eq(LV_THEME_DEFAULT_FONT_NORMAL + 2, ptr, "Get the value of a local'ptr' property"); @@ -470,17 +470,17 @@ static void mem_leak(void) lv_test_print("Use local style"); lv_mem_monitor(&mon_start); for(i = 0; i < 100; i++) { - lv_style_list_set_local_data_ptr(&style_list, LV_STYLE_TEXT_FONT | (LV_STATE_PRESSED) << LV_STYLE_STATE_POS, LV_THEME_DEFAULT_FONT_NORMAL); + lv_style_list_set_local_ptr(&style_list, LV_STYLE_TEXT_FONT | (LV_STATE_PRESSED) << LV_STYLE_STATE_POS, LV_THEME_DEFAULT_FONT_NORMAL); lv_style_list_reset(&style_list); - lv_style_list_set_local_data_ptr(&style_list, LV_STYLE_TEXT_FONT | (LV_STATE_PRESSED) << LV_STYLE_STATE_POS, NULL); - lv_style_list_set_local_data_ptr(&style_list, LV_STYLE_PATTERN_IMAGE, LV_SYMBOL_OK); - lv_style_list_set_local_data_ptr(&style_list, LV_STYLE_PATTERN_IMAGE, LV_SYMBOL_OK); - lv_style_list_set_local_data_ptr(&style_list, LV_STYLE_PATTERN_IMAGE, LV_SYMBOL_OK); - lv_style_list_set_local_data_ptr(&style_list, LV_STYLE_PATTERN_IMAGE, LV_SYMBOL_OK); - lv_style_list_set_local_data_ptr(&style_list, LV_STYLE_PATTERN_IMAGE, LV_SYMBOL_OK); - lv_style_list_set_local_data_ptr(&style_list, LV_STYLE_PATTERN_IMAGE, LV_SYMBOL_OK); + lv_style_list_set_local_ptr(&style_list, LV_STYLE_TEXT_FONT | (LV_STATE_PRESSED) << LV_STYLE_STATE_POS, NULL); + lv_style_list_set_local_ptr(&style_list, LV_STYLE_PATTERN_IMAGE, LV_SYMBOL_OK); + lv_style_list_set_local_ptr(&style_list, LV_STYLE_PATTERN_IMAGE, LV_SYMBOL_OK); + lv_style_list_set_local_ptr(&style_list, LV_STYLE_PATTERN_IMAGE, LV_SYMBOL_OK); + lv_style_list_set_local_ptr(&style_list, LV_STYLE_PATTERN_IMAGE, LV_SYMBOL_OK); + lv_style_list_set_local_ptr(&style_list, LV_STYLE_PATTERN_IMAGE, LV_SYMBOL_OK); + lv_style_list_set_local_ptr(&style_list, LV_STYLE_PATTERN_IMAGE, LV_SYMBOL_OK); lv_style_list_reset(&style_list); } @@ -559,7 +559,7 @@ static void mem_leak(void) for(i = 0; i < 100; i++) { if(i % 2 == 0) { - lv_style_list_set_local_data_ptr(&style_list, LV_STYLE_PATTERN_IMAGE, LV_SYMBOL_CLOSE); + lv_style_list_set_local_ptr(&style_list, LV_STYLE_PATTERN_IMAGE, LV_SYMBOL_CLOSE); } _lv_style_set_color(&style1, LV_STYLE_LINE_COLOR, LV_COLOR_RED); @@ -571,7 +571,7 @@ static void mem_leak(void) if(i % 4 == 0) { - lv_style_list_set_local_data_ptr(&style_list, LV_STYLE_PATTERN_IMAGE, LV_SYMBOL_CLOSE); + lv_style_list_set_local_ptr(&style_list, LV_STYLE_PATTERN_IMAGE, LV_SYMBOL_CLOSE); } lv_style_list_remove_style(&style_list, &style1); @@ -586,7 +586,7 @@ static void mem_leak(void) lv_style_list_add_style(&style_list, &style2); if(i % 8 == 0) { - lv_style_list_set_local_data_ptr(&style_list, LV_STYLE_PATTERN_IMAGE, LV_SYMBOL_CLOSE); + lv_style_list_set_local_ptr(&style_list, LV_STYLE_PATTERN_IMAGE, LV_SYMBOL_CLOSE); } lv_style_list_add_style(&style_list, &style2); @@ -604,14 +604,14 @@ static void mem_leak(void) _lv_style_set_int(&style3, LV_STYLE_PAD_LEFT, 12); _lv_style_set_int(&style3, LV_STYLE_PAD_RIGHT, 23); - lv_style_list_set_local_data_ptr(&style_list, LV_STYLE_TEXT_FONT | (LV_STATE_PRESSED) << LV_STYLE_STATE_POS, LV_THEME_DEFAULT_FONT_NORMAL); - lv_style_list_set_local_data_ptr(&style_list, LV_STYLE_TEXT_FONT | (LV_STATE_PRESSED) << LV_STYLE_STATE_POS, NULL); - lv_style_list_set_local_data_ptr(&style_list, LV_STYLE_PATTERN_IMAGE, LV_SYMBOL_OK); - lv_style_list_set_local_data_ptr(&style_list, LV_STYLE_PATTERN_IMAGE, LV_SYMBOL_OK); - lv_style_list_set_local_data_ptr(&style_list, LV_STYLE_PATTERN_IMAGE, LV_SYMBOL_OK); - lv_style_list_set_local_data_ptr(&style_list, LV_STYLE_PATTERN_IMAGE, LV_SYMBOL_OK); - lv_style_list_set_local_data_ptr(&style_list, LV_STYLE_PATTERN_IMAGE, LV_SYMBOL_OK); - lv_style_list_set_local_data_ptr(&style_list, LV_STYLE_PATTERN_IMAGE, LV_SYMBOL_OK); + lv_style_list_set_local_ptr(&style_list, LV_STYLE_TEXT_FONT | (LV_STATE_PRESSED) << LV_STYLE_STATE_POS, LV_THEME_DEFAULT_FONT_NORMAL); + lv_style_list_set_local_ptr(&style_list, LV_STYLE_TEXT_FONT | (LV_STATE_PRESSED) << LV_STYLE_STATE_POS, NULL); + lv_style_list_set_local_ptr(&style_list, LV_STYLE_PATTERN_IMAGE, LV_SYMBOL_OK); + lv_style_list_set_local_ptr(&style_list, LV_STYLE_PATTERN_IMAGE, LV_SYMBOL_OK); + lv_style_list_set_local_ptr(&style_list, LV_STYLE_PATTERN_IMAGE, LV_SYMBOL_OK); + lv_style_list_set_local_ptr(&style_list, LV_STYLE_PATTERN_IMAGE, LV_SYMBOL_OK); + lv_style_list_set_local_ptr(&style_list, LV_STYLE_PATTERN_IMAGE, LV_SYMBOL_OK); + lv_style_list_set_local_ptr(&style_list, LV_STYLE_PATTERN_IMAGE, LV_SYMBOL_OK); lv_style_list_add_style(&style_list, &style3); lv_style_list_add_style(&style_list, &style2);