diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml new file mode 100644 index 0000000000..e5c9e76dcf --- /dev/null +++ b/.github/workflows/ccpp.yml @@ -0,0 +1,17 @@ +name: C/C++ CI + +on: + push: + branches: [ dev-7.0 ] + pull_request: + branches: [ dev-7.0 ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Run tests + run: cd tests; python ./build.py diff --git a/README.md b/README.md index e9e47f3acc..c8fd621313 100644 --- a/README.md +++ b/README.md @@ -93,7 +93,7 @@ You can use the [Simulators](https://docs.littlevgl.com/en/html/get-started/pc-s 1. [Download](https://littlevgl.com/download) or [Clone](https://github.com/littlevgl/lvgl) the library 2. Copy the `lvgl` folder into your project -3. Copy `lvgl/lv_conf_template.h` as `lv_conf.h` next to the `lvgl` folder and set at least `LV_HOR_RES_MAX`, `LV_VER_RES_MAX` and `LV_COLOR_DEPTH`. +3. Copy `lvgl/lv_conf_template.h` as `lv_conf.h` next to the `lvgl` folder and set at least `LV_HOR_RES_MAX`, `LV_VER_RES_MAX` and `LV_COLOR_DEPTH`. Don't forget to **change the `#if 0` statement near the top of the file to `#if 1`**, otherwise you will get compilation errors. 4. Include `lvgl/lvgl.h` where you need to use LittlevGL related functions. 5. Call `lv_tick_inc(x)` every `x` milliseconds **in a Timer or Task** (`x` should be between 1 and 10). It is required for the internal timing of LittlevGL. 6. Call `lv_init()` diff --git a/azure-pipelines.yml b/azure-pipelines.yml deleted file mode 100644 index 2667c54116..0000000000 --- a/azure-pipelines.yml +++ /dev/null @@ -1,16 +0,0 @@ -# Starter pipeline -# Start with a minimal pipeline that you can customize to build and deploy your code. -# Add steps that build, run tests, deploy, and more: -# https://aka.ms/yaml - -trigger: -- dev-7.0 - -pool: - vmImage: 'ubuntu-latest' - -steps: - - script: | - cd tests - python build.py - displayName: 'Build' diff --git a/lv_conf_template.h b/lv_conf_template.h index d47e7ed4f8..06f88fe7eb 100644 --- a/lv_conf_template.h +++ b/lv_conf_template.h @@ -56,7 +56,7 @@ /* Dot Per Inch: used to initialize default sizes. * E.g. a button with width = LV_DPI / 2 -> half inch wide * (Not so important, you can adjust it to modify default sizes and spaces)*/ -#define LV_DPI 100 /*[px]*/ +#define LV_DPI 130 /*[px]*/ /* The the real width of the display changes some default values: * default object sizes, layout of examples, etc. @@ -65,9 +65,9 @@ * The 4th is extra large which has no upper limit so not listed here * The upper limit of the categories are set below in 0.1 inch unit. */ -#define LV_DISP_SMALL_LIMIT 20 -#define LV_DISP_MEDIUM_LIMIT 45 -#define LV_DISP_LARGE_LIMIT 65 +#define LV_DISP_SMALL_LIMIT 30 +#define LV_DISP_MEDIUM_LIMIT 50 +#define LV_DISP_LARGE_LIMIT 70 /* Type of coordinates. Should be `int16_t` (or `int32_t` for extreme cases) */ typedef int16_t lv_coord_t; diff --git a/src/lv_api_map.h b/src/lv_api_map.h index 12a77a9062..d5406b2402 100644 --- a/src/lv_api_map.h +++ b/src/lv_api_map.h @@ -31,6 +31,11 @@ extern "C" { * V6.0 COMPATIBILITY *--------------------*/ +static inline void lv_task_once(lv_task_t *task) +{ + lv_task_set_repeat_count(task, 1); +} + #if LV_USE_CHART #define lv_chart_get_point_cnt lv_chart_get_point_count diff --git a/src/lv_conf_internal.h b/src/lv_conf_internal.h index 971082adc1..ab74c41328 100644 --- a/src/lv_conf_internal.h +++ b/src/lv_conf_internal.h @@ -86,7 +86,7 @@ * E.g. a button with width = LV_DPI / 2 -> half inch wide * (Not so important, you can adjust it to modify default sizes and spaces)*/ #ifndef LV_DPI -#define LV_DPI 100 /*[px]*/ +#define LV_DPI 130 /*[px]*/ #endif /* The the real width of the display changes some default values: @@ -97,13 +97,13 @@ * The upper limit of the categories are set below in 0.1 inch unit. */ #ifndef LV_DISP_SMALL_LIMIT -#define LV_DISP_SMALL_LIMIT 20 +#define LV_DISP_SMALL_LIMIT 30 #endif #ifndef LV_DISP_MEDIUM_LIMIT -#define LV_DISP_MEDIUM_LIMIT 45 +#define LV_DISP_MEDIUM_LIMIT 50 #endif #ifndef LV_DISP_LARGE_LIMIT -#define LV_DISP_LARGE_LIMIT 65 +#define LV_DISP_LARGE_LIMIT 70 #endif /* Type of coordinates. Should be `int16_t` (or `int32_t` for extreme cases) */ diff --git a/src/lv_core/lv_debug.c b/src/lv_core/lv_debug.c index 5bfdeac008..5eb7e72019 100644 --- a/src/lv_core/lv_debug.c +++ b/src/lv_core/lv_debug.c @@ -63,6 +63,7 @@ bool lv_debug_check_obj_type(const lv_obj_t * obj, const char * obj_type) uint8_t i; for(i = 0; i < LV_MAX_ANCESTOR_NUM; i++) { + if(types.type[i] == NULL) break; if(strcmp(types.type[i], obj_type) == 0) return true; } @@ -159,7 +160,7 @@ void lv_debug_log_error(const char * msg, uint64_t value) char * bufp = buf; /*Add the function name*/ - memcpy(bufp, msg, msg_len); + lv_memcpy(bufp, msg, msg_len); bufp += msg_len; /*Add value in hey*/ diff --git a/src/lv_core/lv_disp.h b/src/lv_core/lv_disp.h index e095d8cafa..91c34d4bcd 100644 --- a/src/lv_core/lv_disp.h +++ b/src/lv_core/lv_disp.h @@ -152,7 +152,7 @@ static inline void lv_scr_load(lv_obj_t * scr) * 1 dip is 2 px on a 320 DPI screen * https://stackoverflow.com/questions/2025282/what-is-the-difference-between-px-dip-dp-and-sp */ -#define LV_DPX(n) LV_MATH_MAX(((LV_DPI * (n)) / 160), 1) +#define LV_DPX(n) LV_MATH_MAX(((LV_DPI * (n) + 80) / 160), 1) /*+80 for rounding*/ #ifdef __cplusplus } /* extern "C" */ diff --git a/src/lv_core/lv_group.c b/src/lv_core/lv_group.c index 4edbabf5d3..8f1a01f466 100644 --- a/src/lv_core/lv_group.c +++ b/src/lv_core/lv_group.c @@ -73,7 +73,7 @@ lv_group_t * lv_group_create(void) group->wrap = 1; #if LV_USE_USER_DATA - memset(&group->user_data, 0, sizeof(lv_group_user_data_t)); + lv_memset_00(&group->user_data, sizeof(lv_group_user_data_t)); #endif return group; @@ -303,28 +303,6 @@ lv_res_t lv_group_send_data(lv_group_t * group, uint32_t c) return res; } -/** - * Set a function for a group which will modify the object's style if it is in focus - * @param group pointer to a group - * @param style_mod_cb the style modifier function pointer - */ -void lv_group_set_style_mod_cb(lv_group_t * group, lv_group_style_mod_cb_t style_mod_cb) -{ - group->style_mod_cb = style_mod_cb; - if(group->obj_focus != NULL) lv_obj_invalidate(*group->obj_focus); -} - -/** - * Set a function for a group which will modify the object's style if it is in focus in edit mode - * @param group pointer to a group - * @param style_mod_func the style modifier function pointer - */ -void lv_group_set_style_mod_edit_cb(lv_group_t * group, lv_group_style_mod_cb_t style_mod_edit_cb) -{ - group->style_mod_edit_cb = style_mod_edit_cb; - if(group->obj_focus != NULL) lv_obj_invalidate(*group->obj_focus); -} - /** * Set a function for a group which will be called when a new object is focused * @param group pointer to a group @@ -342,6 +320,7 @@ void lv_group_set_focus_cb(lv_group_t * group, lv_group_focus_cb_t focus_cb) */ void lv_group_set_editing(lv_group_t * group, bool edit) { + if(group == NULL) return; uint8_t en_val = edit ? 1 : 0; if(en_val == group->editing) return; /*Do not set the same mode again*/ @@ -383,26 +362,6 @@ void lv_group_set_wrap(lv_group_t * group, bool en) group->wrap = en ? 1 : 0; } -/** - * Modify a style with the set 'style_mod' function. The input style remains unchanged. - * @param group pointer to group - * @param style pointer to a style to modify - * @return a copy of the input style but modified with the 'style_mod' function - */ -lv_style_t * lv_group_mod_style(lv_group_t * group, const lv_style_t * style) -{ - /*Load the current style. It will be modified by the callback*/ - lv_style_copy(&group->style_tmp, style); - - if(group->editing) { - if(group->style_mod_edit_cb) group->style_mod_edit_cb(group, &group->style_tmp); - } - else { - if(group->style_mod_cb) group->style_mod_cb(group, &group->style_tmp); - } - return &group->style_tmp; -} - /** * Get the focused object or NULL if there isn't one * @param group pointer to a group @@ -428,28 +387,6 @@ lv_group_user_data_t * lv_group_get_user_data(lv_group_t * group) } #endif -/** - * Get a the style modifier function of a group - * @param group pointer to a group - * @return pointer to the style modifier function - */ -lv_group_style_mod_cb_t lv_group_get_style_mod_cb(const lv_group_t * group) -{ - if(!group) return NULL; - return group->style_mod_cb; -} - -/** - * Get a the style modifier function of a group in edit mode - * @param group pointer to a group - * @return pointer to the style modifier function - */ -lv_group_style_mod_cb_t lv_group_get_style_mod_edit_cb(const lv_group_t * group) -{ - if(!group) return NULL; - return group->style_mod_edit_cb; -} - /** * Get the focus callback function of a group * @param group pointer to a group diff --git a/src/lv_core/lv_group.h b/src/lv_core/lv_group.h index 68dc237070..aa32b503a1 100644 --- a/src/lv_core/lv_group.h +++ b/src/lv_core/lv_group.h @@ -55,10 +55,7 @@ typedef struct _lv_group_t { lv_ll_t obj_ll; /**< Linked list to store the objects in the group */ lv_obj_t ** obj_focus; /**< The object in focus*/ - lv_group_style_mod_cb_t style_mod_cb; /**< A function to modifies the style of the focused object*/ - lv_group_style_mod_cb_t style_mod_edit_cb; /**< A function which modifies the style of the edited object*/ lv_group_focus_cb_t focus_cb; /**< A function to call when a new object is focused (optional)*/ - lv_style_t style_tmp; /**< Stores the modified style of the focused object */ #if LV_USE_USER_DATA lv_group_user_data_t user_data; #endif diff --git a/src/lv_core/lv_obj.c b/src/lv_core/lv_obj.c index 8e232f1894..f00ba1c656 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; + _lv_style_fptr_dptr_t _ptr; } start_value; union { lv_color_t _color; lv_style_int_t _int; lv_opa_t _opa; - lv_style_fptr_dptr_t _ptr; + _lv_style_fptr_dptr_t _ptr; } end_value; } lv_style_trans_t; @@ -209,7 +209,7 @@ lv_obj_t * lv_obj_create(lv_obj_t * parent, const lv_obj_t * copy) LV_ASSERT_MEM(new_obj); if(new_obj == NULL) return NULL; - memset(new_obj, 0x00, sizeof(lv_obj_t)); + lv_memset_00(new_obj, sizeof(lv_obj_t)); #if LV_USE_BIDI new_obj->base_dir = LV_BIDI_BASE_DIR_DEF; @@ -232,7 +232,7 @@ lv_obj_t * lv_obj_create(lv_obj_t * parent, const lv_obj_t * copy) LV_ASSERT_MEM(new_obj); if(new_obj == NULL) return NULL; - memset(new_obj, 0x00, sizeof(lv_obj_t)); + lv_memset_00(new_obj, sizeof(lv_obj_t)); new_obj->parent = parent; @@ -265,7 +265,7 @@ lv_obj_t * lv_obj_create(lv_obj_t * parent, const lv_obj_t * copy) new_obj->ext_draw_pad = 0; #if LV_USE_EXT_CLICK_AREA == LV_EXT_CLICK_AREA_FULL - memset(&new_obj->ext_click_pad, 0, sizeof(new_obj->ext_click_pad)); + lv_memset_00(&new_obj->ext_click_pad, sizeof(new_obj->ext_click_pad)); #elif LV_USE_EXT_CLICK_AREA == LV_EXT_CLICK_AREA_TINY new_obj->ext_click_pad_hor = 0; new_obj->ext_click_pad_ver = 0; @@ -282,7 +282,7 @@ lv_obj_t * lv_obj_create(lv_obj_t * parent, const lv_obj_t * copy) /*Init. user date*/ #if LV_USE_USER_DATA - memset(&new_obj->user_data, 0, sizeof(lv_obj_user_data_t)); + lv_memset_00(&new_obj->user_data, sizeof(lv_obj_user_data_t)); #endif @@ -328,7 +328,7 @@ lv_obj_t * lv_obj_create(lv_obj_t * parent, const lv_obj_t * copy) /*Set user data*/ #if LV_USE_USER_DATA - memcpy(&new_obj->user_data, ©->user_data, sizeof(lv_obj_user_data_t)); + lv_memcpy(&new_obj->user_data, ©->user_data, sizeof(lv_obj_user_data_t)); #endif /*Copy realign*/ @@ -800,9 +800,35 @@ void lv_obj_set_height(lv_obj_t * obj, lv_coord_t h) lv_obj_set_size(obj, lv_obj_get_width(obj), h); } +/** + * Set the width reduced by the left and right padding. + * @param obj pointer to an object + * @param w the width without paddings + */ +void lv_obj_set_width_fit(lv_obj_t * obj, lv_coord_t w) +{ + lv_style_int_t pleft = lv_obj_get_style_pad_left(obj, LV_OBJ_PART_MAIN); + lv_style_int_t pright = lv_obj_get_style_pad_right(obj, LV_OBJ_PART_MAIN); + + lv_obj_set_width(obj, w - pleft - pright); +} + +/** + * Set the height reduced by the top and bottom padding. + * @param obj pointer to an object + * @param h the height without paddings + */ +void lv_obj_set_height_fit(lv_obj_t * obj, lv_coord_t h) +{ + lv_style_int_t ptop = lv_obj_get_style_pad_top(obj, LV_OBJ_PART_MAIN); + lv_style_int_t pbottom = lv_obj_get_style_pad_bottom(obj, LV_OBJ_PART_MAIN); + + lv_obj_set_width(obj, h - ptop - pbottom); +} + /** * Set the width of an object by taking the left and right margin into account. - * The object heigwidthht will be `obj_w = w - margon_left - margin_right` + * The object width will be `obj_w = w - margon_left - margin_right` * @param obj pointer to an object * @param w new height including margins */ @@ -834,10 +860,10 @@ void lv_obj_set_height_margin(lv_obj_t * obj, lv_coord_t h) * @param obj pointer to an object to align * @param base pointer to an object (if NULL the parent is used). 'obj' will be aligned to it. * @param align type of alignment (see 'lv_align_t' enum) - * @param x_mod x coordinate shift after alignment - * @param y_mod y coordinate shift after alignment + * @param x_ofs x coordinate offset after alignment + * @param y_ofs y coordinate offset after alignment */ -void lv_obj_align(lv_obj_t * obj, const lv_obj_t * base, lv_align_t align, lv_coord_t x_mod, lv_coord_t y_mod) +void lv_obj_align(lv_obj_t * obj, const lv_obj_t * base, lv_align_t align, lv_coord_t x_ofs, lv_coord_t y_ofs) { LV_ASSERT_OBJ(obj, LV_OBJX_NAME); @@ -852,8 +878,8 @@ void lv_obj_align(lv_obj_t * obj, const lv_obj_t * base, lv_align_t align, lv_co lv_obj_t * par = lv_obj_get_parent(obj); lv_coord_t par_abs_x = par->coords.x1; lv_coord_t par_abs_y = par->coords.y1; - new_pos.x += x_mod; - new_pos.y += y_mod; + new_pos.x += x_ofs; + new_pos.y += y_ofs; new_pos.x -= par_abs_x; new_pos.y -= par_abs_y; @@ -862,8 +888,8 @@ void lv_obj_align(lv_obj_t * obj, const lv_obj_t * base, lv_align_t align, lv_co #if LV_USE_OBJ_REALIGN /*Save the last align parameters to use them in `lv_obj_realign`*/ obj->realign.align = align; - obj->realign.xofs = x_mod; - obj->realign.yofs = y_mod; + obj->realign.xofs = x_ofs; + obj->realign.yofs = y_ofs; obj->realign.base = base; obj->realign.origo_align = 0; #endif @@ -874,10 +900,10 @@ void lv_obj_align(lv_obj_t * obj, const lv_obj_t * base, lv_align_t align, lv_co * @param obj pointer to an object to align * @param base pointer to an object (if NULL the parent is used). 'obj' will be aligned to it. * @param align type of alignment (see 'lv_align_t' enum) - * @param x_mod x coordinate shift after alignment - * @param y_mod y coordinate shift after alignment + * @param x_ofs x coordinate offset after alignment + * @param y_ofs y coordinate offset after alignment */ -void lv_obj_align_origo(lv_obj_t * obj, const lv_obj_t * base, lv_align_t align, lv_coord_t x_mod, lv_coord_t y_mod) +void lv_obj_align_origo(lv_obj_t * obj, const lv_obj_t * base, lv_align_t align, lv_coord_t x_ofs, lv_coord_t y_ofs) { LV_ASSERT_OBJ(obj, LV_OBJX_NAME); @@ -1005,8 +1031,8 @@ void lv_obj_align_origo(lv_obj_t * obj, const lv_obj_t * base, lv_align_t align, lv_coord_t base_abs_y = base->coords.y1; lv_coord_t par_abs_x = par->coords.x1; lv_coord_t par_abs_y = par->coords.y1; - new_x += x_mod + base_abs_x; - new_y += y_mod + base_abs_y; + new_x += x_ofs + base_abs_x; + new_y += y_ofs + base_abs_y; new_x -= par_abs_x; new_y -= par_abs_y; @@ -1015,8 +1041,8 @@ void lv_obj_align_origo(lv_obj_t * obj, const lv_obj_t * base, lv_align_t align, #if LV_USE_OBJ_REALIGN /*Save the last align parameters to use them in `lv_obj_realign`*/ obj->realign.align = align; - obj->realign.xofs = x_mod; - obj->realign.yofs = y_mod; + obj->realign.xofs = x_ofs; + obj->realign.yofs = y_ofs; obj->realign.base = base; obj->realign.origo_align = 1; #endif @@ -1235,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, _lv_style_fptr_dptr_t value) { lv_style_list_t * style_dsc = lv_obj_get_style_list(obj, part); lv_style_list_set_local_ptr(style_dsc, prop, value); @@ -1267,7 +1293,7 @@ bool _lv_obj_remove_style_local_prop(lv_obj_t * obj, uint8_t part, lv_style_prop /** * Notify an object (and its children) about its style is modified * @param obj pointer to an object - * @param prop `LV_STYLE_PROP_ALL` or an `LV_STYLE_...` property. It is used the optimize what needs to be refreshed. + * @param prop `LV_STYLE_PROP_ALL` or an `LV_STYLE_...` property. It is used to optimize what needs to be refreshed. */ void lv_obj_refresh_style(lv_obj_t * obj, lv_style_property_t prop) { @@ -1332,9 +1358,8 @@ void lv_obj_refresh_style(lv_obj_t * obj, lv_style_property_t prop) lv_obj_invalidate(obj); - if(prop == LV_STYLE_PROP_ALL || (prop & LV_STYLE_INHERIT_MASK)) - /*Send style change signals*/ - refresh_children_style(obj); + /*Send style change signals*/ + if(prop == LV_STYLE_PROP_ALL || (prop & LV_STYLE_INHERIT_MASK)) refresh_children_style(obj); } else { lv_obj_invalidate(obj); @@ -2513,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) +_lv_style_fptr_dptr_t _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; + _lv_style_fptr_dptr_t value_act; lv_res_t res = LV_RES_INV; const lv_obj_t * parent = obj; while(parent) { @@ -2546,7 +2571,7 @@ lv_style_fptr_dptr_t _lv_obj_get_style_ptr(const lv_obj_t * obj, uint8_t part, l /*Handle unset values*/ prop = prop & (~LV_STYLE_STATE_MASK); - lv_style_fptr_dptr_t fd; + _lv_style_fptr_dptr_t fd; fd.dptr = NULL; fd.fptr = NULL; switch(prop) { @@ -2556,7 +2581,7 @@ lv_style_fptr_dptr_t _lv_obj_get_style_ptr(const lv_obj_t * obj, uint8_t part, l return fd; #if LV_USE_ANIMATION case LV_STYLE_TRANSITION_PATH: - fd.fptr = (lv_style_prop_cb_t)lv_anim_path_linear; + fd.fptr = (_lv_style_prop_xcb_t)lv_anim_path_linear; return fd; #endif } @@ -2826,8 +2851,8 @@ void lv_obj_get_type(const lv_obj_t * obj, lv_obj_type_t * buf) lv_obj_type_t tmp; - memset(buf, 0, sizeof(lv_obj_type_t)); - memset(&tmp, 0, sizeof(lv_obj_type_t)); + lv_memset_00(buf, sizeof(lv_obj_type_t)); + lv_memset_00(&tmp, sizeof(lv_obj_type_t)); obj->signal_cb((lv_obj_t *)obj, LV_SIGNAL_GET_TYPE, &tmp); @@ -2878,7 +2903,7 @@ void lv_obj_set_user_data(lv_obj_t * obj, lv_obj_user_data_t data) { LV_ASSERT_OBJ(obj, LV_OBJX_NAME); - memcpy(&obj->user_data, &data, sizeof(lv_obj_user_data_t)); + lv_memcpy(&obj->user_data, &data, sizeof(lv_obj_user_data_t)); } #endif @@ -3770,12 +3795,12 @@ 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); + _lv_style_fptr_dptr_t fd1 = _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); + _lv_style_fptr_dptr_t fd2 = _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(&fd1, &fd2, sizeof(_lv_style_fptr_dptr_t)) == 0) return NULL; obj->state = prev_state; fd1 = _lv_obj_get_style_ptr(obj, part, prop); obj->state = new_state; @@ -3853,7 +3878,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; + _lv_style_fptr_dptr_t 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 b41a8b079b..654e4e96ca 100644 --- a/src/lv_core/lv_obj.h +++ b/src/lv_core/lv_obj.h @@ -426,9 +426,23 @@ void lv_obj_set_width(lv_obj_t * obj, lv_coord_t w); */ void lv_obj_set_height(lv_obj_t * obj, lv_coord_t h); +/** + * Set the width reduced by the left and right padding. + * @param obj pointer to an object + * @param w the width without paddings + */ +void lv_obj_set_width_fit(lv_obj_t * obj, lv_coord_t w); + +/** + * Set the height reduced by the top and bottom padding. + * @param obj pointer to an object + * @param h the height without paddings + */ +void lv_obj_set_height_fit(lv_obj_t * obj, lv_coord_t h); + /** * Set the width of an object by taking the left and right margin into account. - * The object heigwidthht will be `obj_w = w - margon_left - margin_right` + * The object width will be `obj_w = w - margon_left - margin_right` * @param obj pointer to an object * @param w new height including margins */ @@ -447,20 +461,20 @@ void lv_obj_set_height_margin(lv_obj_t * obj, lv_coord_t h); * @param obj pointer to an object to align * @param base pointer to an object (if NULL the parent is used). 'obj' will be aligned to it. * @param align type of alignment (see 'lv_align_t' enum) - * @param x_mod x coordinate shift after alignment - * @param y_mod y coordinate shift after alignment + * @param x_ofs x coordinate offset after alignment + * @param y_ofs y coordinate offset after alignment */ -void lv_obj_align(lv_obj_t * obj, const lv_obj_t * base, lv_align_t align, lv_coord_t x_mod, lv_coord_t y_mod); +void lv_obj_align(lv_obj_t * obj, const lv_obj_t * base, lv_align_t align, lv_coord_t x_ofs, lv_coord_t y_ofs); /** * Align an object to an other object. * @param obj pointer to an object to align * @param base pointer to an object (if NULL the parent is used). 'obj' will be aligned to it. * @param align type of alignment (see 'lv_align_t' enum) - * @param x_mod x coordinate shift after alignment - * @param y_mod y coordinate shift after alignment + * @param x_ofs x coordinate offset after alignment + * @param y_ofs y coordinate offset after alignment */ -void lv_obj_align_origo(lv_obj_t * obj, const lv_obj_t * base, lv_align_t align, lv_coord_t x_mod, lv_coord_t y_mod); +void lv_obj_align_origo(lv_obj_t * obj, const lv_obj_t * base, lv_align_t align, lv_coord_t x_ofs, lv_coord_t y_ofs); /** * Realign the object based on the last `lv_obj_align` parameters. @@ -520,8 +534,9 @@ void lv_obj_clean_style_list(lv_obj_t * obj, uint8_t part); void lv_obj_reset_style_list(lv_obj_t * obj, uint8_t part); /** - * Notify an object about its style is modified + * Notify an object (and its children) about its style is modified * @param obj pointer to an object + * @param prop `LV_STYLE_PROP_ALL` or an `LV_STYLE_...` property. It is used to optimize what needs to be refreshed. */ void lv_obj_refresh_style(lv_obj_t * obj, lv_style_property_t prop); @@ -586,7 +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); +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. @@ -601,9 +616,9 @@ void _lv_obj_set_style_local_ptr(lv_obj_t * obj, uint8_t type, lv_style_property * @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_cb_t value) + _lv_style_prop_xcb_t value) { - lv_style_fptr_dptr_t fd; + _lv_style_fptr_dptr_t fd; fd.fptr = value; fd.dptr = NULL; _lv_obj_set_style_local_ptr(obj, type, prop, fd); @@ -623,7 +638,7 @@ static inline void _lv_obj_set_style_local_func_ptr(lv_obj_t * obj, uint8_t 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; + _lv_style_fptr_dptr_t fd; fd.fptr = NULL; fd.dptr = value; _lv_obj_set_style_local_ptr(obj, type, prop, fd); @@ -1133,7 +1148,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); +_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. @@ -1149,10 +1164,10 @@ lv_style_fptr_dptr_t _lv_obj_get_style_ptr(const lv_obj_t * obj, uint8_t part, l * 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_cb_t _lv_obj_get_style_func_ptr(const lv_obj_t * obj, uint8_t part, +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; + _lv_style_fptr_dptr_t fd; fd = _lv_obj_get_style_ptr(obj, part, prop); return fd.fptr; } @@ -1173,7 +1188,7 @@ static inline lv_style_prop_cb_t _lv_obj_get_style_func_ptr(const lv_obj_t * ob */ 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; + _lv_style_fptr_dptr_t fd; fd = _lv_obj_get_style_ptr(obj, part, prop); return fd.dptr; } diff --git a/src/lv_core/lv_obj_style_dec.h b/src/lv_core/lv_obj_style_dec.h index 4849140cf3..a943f29d7e 100644 --- a/src/lv_core/lv_obj_style_dec.h +++ b/src/lv_core/lv_obj_style_dec.h @@ -59,9 +59,9 @@ extern "C" { */ #ifdef __cplusplus -#define FUNC_PTR_CAST(v) reinterpret_cast(v) +#define FUNC_PTR_CAST(v) reinterpret_cast<_lv_style_prop_xcb_t>(v) #else -#define FUNC_PTR_CAST(v) (lv_style_prop_cb_t)v +#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) \ @@ -221,7 +221,7 @@ _LV_OBJ_STYLE_SET_GET_DECLARE(TRANSITION_PROP_6, transition_prop_6, lv_style_int #if LV_USE_ANIMATION _LV_OBJ_STYLE_SET_GET_DECLARE(TRANSITION_PATH, transition_path, lv_anim_path_cb_t, _func_ptr, func_ptr) #else -_LV_OBJ_STYLE_SET_GET_DECLARE(TRANSITION_PATH, transition_path, lv_style_prop_cb_t, _func_ptr, +_LV_OBJ_STYLE_SET_GET_DECLARE(TRANSITION_PATH, transition_path, _lv_style_prop_xcb_t, _func_ptr, func_ptr) /*For compatibility*/ #endif _LV_OBJ_STYLE_SET_GET_DECLARE(SCALE_WIDTH, scale_width, lv_style_int_t, _int, scalar) diff --git a/src/lv_core/lv_refr.c b/src/lv_core/lv_refr.c index addfff02ec..42e8583abf 100644 --- a/src/lv_core/lv_refr.c +++ b/src/lv_core/lv_refr.c @@ -225,7 +225,7 @@ void lv_disp_refr_task(lv_task_t * task) uint32_t line_length = lv_area_get_width(&disp_refr->inv_areas[a]) * sizeof(lv_color_t); for(y = disp_refr->inv_areas[a].y1; y <= disp_refr->inv_areas[a].y2; y++) { - memcpy(buf_act + start_offs, buf_ina + start_offs, line_length); + lv_memcpy(buf_act + start_offs, buf_ina + start_offs, line_length); start_offs += hres * sizeof(lv_color_t); } } diff --git a/src/lv_core/lv_style.c b/src/lv_core/lv_style.c index eda0ddc5c1..f264495d14 100644 --- a/src/lv_core/lv_style.c +++ b/src/lv_core/lv_style.c @@ -60,7 +60,7 @@ static lv_style_t * get_alloc_local_style(lv_style_list_t * list); */ void lv_style_init(lv_style_t * style) { - memset(style, 0x00, sizeof(lv_style_t)); + lv_memset_00(style, sizeof(lv_style_t)); #if LV_USE_ASSERT_STYLE style->sentinel = LV_DEBUG_STYLE_SENTINEL_VALUE; #endif @@ -81,9 +81,8 @@ void lv_style_copy(lv_style_t * style_dest, const lv_style_t * style_src) if(style_src->map == NULL) return; uint16_t size = lv_style_get_mem_size(style_src); - style_dest->map = lv_mem_alloc(size); - memcpy(style_dest->map, style_src->map, size); + lv_memcpy(style_dest->map, style_src->map, size); } /** @@ -113,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(_lv_style_fptr_dptr_t); /*Move the props to fill the space of the property to delete*/ uint32_t i; @@ -136,7 +135,7 @@ bool lv_style_remove_prop(lv_style_t * style, lv_style_property_t prop) */ void lv_style_list_init(lv_style_list_t * list) { - memset(list, 0x00, sizeof(lv_style_list_t)); + lv_memset_00(list, sizeof(lv_style_list_t)); #if LV_USE_ASSERT_STYLE list->sentinel = LV_DEBUG_STYLE_LIST_SENTINEL_VALUE; #endif @@ -160,24 +159,24 @@ void lv_style_list_copy(lv_style_list_t * list_dest, const lv_style_list_t * lis if(list_src->has_local == 0) { if(list_src->has_trans) { list_dest->style_list = lv_mem_alloc((list_src->style_cnt - 1) * sizeof(lv_style_t *)); - memcpy(list_dest->style_list, list_src->style_list + 1, (list_src->style_cnt - 1) * sizeof(lv_style_t *)); + lv_memcpy(list_dest->style_list, list_src->style_list + 1, (list_src->style_cnt - 1) * sizeof(lv_style_t *)); list_dest->style_cnt = list_src->style_cnt - 1; } else { list_dest->style_list = lv_mem_alloc(list_src->style_cnt * sizeof(lv_style_t *)); - memcpy(list_dest->style_list, list_src->style_list, list_src->style_cnt * sizeof(lv_style_t *)); + lv_memcpy(list_dest->style_list, list_src->style_list, list_src->style_cnt * sizeof(lv_style_t *)); list_dest->style_cnt = list_src->style_cnt; } } else { if(list_src->has_trans) { list_dest->style_list = lv_mem_alloc((list_src->style_cnt - 2) * sizeof(lv_style_t *)); - memcpy(list_dest->style_list, list_src->style_list + 2, (list_src->style_cnt - 2) * sizeof(lv_style_t *)); + lv_memcpy(list_dest->style_list, list_src->style_list + 2, (list_src->style_cnt - 2) * sizeof(lv_style_t *)); list_dest->style_cnt = list_src->style_cnt - 2; } else { list_dest->style_list = lv_mem_alloc((list_src->style_cnt - 1) * sizeof(lv_style_t *)); - memcpy(list_dest->style_list, list_src->style_list + 1, (list_src->style_cnt - 1) * sizeof(lv_style_t *)); + lv_memcpy(list_dest->style_list, list_src->style_list + 1, (list_src->style_cnt - 1) * sizeof(lv_style_t *)); list_dest->style_cnt = list_src->style_cnt - 1; } @@ -342,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(_lv_style_fptr_dptr_t); i += sizeof(lv_style_property_t); } @@ -374,7 +373,7 @@ void _lv_style_set_int(lv_style_t * style, lv_style_property_t prop, lv_style_in attr_goal.full = (prop >> 8) & 0xFFU; if(attr_found.bits.state == attr_goal.bits.state) { - memcpy(style->map + id + sizeof(lv_style_property_t), &value, sizeof(lv_style_int_t)); + lv_memcpy_small(style->map + id + sizeof(lv_style_property_t), &value, sizeof(lv_style_int_t)); return; } } @@ -391,9 +390,9 @@ void _lv_style_set_int(lv_style_t * style, lv_style_property_t prop, lv_style_in LV_ASSERT_MEM(style->map); if(style == NULL) return; - memcpy(style->map + size - new_prop_size - end_mark_size, &prop, sizeof(lv_style_property_t)); - memcpy(style->map + size - sizeof(lv_style_int_t) - end_mark_size, &value, sizeof(lv_style_int_t)); - memcpy(style->map + size - end_mark_size, &end_mark, sizeof(end_mark)); + 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_int_t) - end_mark_size, &value, sizeof(lv_style_int_t)); + lv_memcpy_small(style->map + size - end_mark_size, &end_mark, sizeof(end_mark)); } /** @@ -420,7 +419,7 @@ void _lv_style_set_color(lv_style_t * style, lv_style_property_t prop, lv_color_ attr_goal.full = (prop >> 8) & 0xFFU; if(attr_found.bits.state == attr_goal.bits.state) { - memcpy(style->map + id + sizeof(lv_style_property_t), &color, sizeof(lv_color_t)); + lv_memcpy_small(style->map + id + sizeof(lv_style_property_t), &color, sizeof(lv_color_t)); return; } } @@ -438,9 +437,9 @@ void _lv_style_set_color(lv_style_t * style, lv_style_property_t prop, lv_color_ LV_ASSERT_MEM(style->map); if(style == NULL) return; - memcpy(style->map + size - new_prop_size - end_mark_size, &prop, sizeof(lv_style_property_t)); - memcpy(style->map + size - sizeof(lv_color_t) - end_mark_size, &color, sizeof(lv_color_t)); - memcpy(style->map + size - end_mark_size, &end_mark, sizeof(end_mark)); + 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_color_t) - end_mark_size, &color, sizeof(lv_color_t)); + lv_memcpy_small(style->map + size - end_mark_size, &end_mark, sizeof(end_mark)); } /** @@ -467,7 +466,7 @@ void _lv_style_set_opa(lv_style_t * style, lv_style_property_t prop, lv_opa_t op attr_goal.full = (prop >> 8) & 0xFFU; if(attr_found.bits.state == attr_goal.bits.state) { - memcpy(style->map + id + sizeof(lv_style_property_t), &opa, sizeof(lv_opa_t)); + lv_memcpy_small(style->map + id + sizeof(lv_style_property_t), &opa, sizeof(lv_opa_t)); return; } } @@ -485,9 +484,9 @@ void _lv_style_set_opa(lv_style_t * style, lv_style_property_t prop, lv_opa_t op LV_ASSERT_MEM(style->map); if(style == NULL) return; - memcpy(style->map + size - new_prop_size - end_mark_size, &prop, sizeof(lv_style_property_t)); - memcpy(style->map + size - sizeof(lv_opa_t) - end_mark_size, &opa, sizeof(lv_opa_t)); - memcpy(style->map + size - end_mark_size, &end_mark, sizeof(end_mark)); + 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_opa_t) - end_mark_size, &opa, sizeof(lv_opa_t)); + lv_memcpy_small(style->map + size - end_mark_size, &end_mark, sizeof(end_mark)); } /** @@ -500,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, _lv_style_fptr_dptr_t p) { LV_ASSERT_STYLE(style); @@ -514,27 +513,27 @@ void _lv_style_set_ptr(lv_style_t * style, lv_style_property_t prop, lv_style_fp attr_goal.full = (prop >> 8) & 0xFFU; if(attr_found.bits.state == attr_goal.bits.state) { - memcpy(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(_lv_style_fptr_dptr_t)); 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(_lv_style_fptr_dptr_t)); 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(_lv_style_fptr_dptr_t); style->map = lv_mem_realloc(style->map, size); LV_ASSERT_MEM(style->map); if(style == NULL) return; - memcpy(style->map + size - new_prop_size - end_mark_size, &prop, sizeof(lv_style_property_t)); - memcpy(style->map + size - sizeof(lv_style_fptr_dptr_t) - end_mark_size, &p, sizeof(lv_style_fptr_dptr_t)); - memcpy(style->map + size - end_mark_size, &end_mark, sizeof(end_mark)); + 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 - end_mark_size, &end_mark, sizeof(end_mark)); } /** @@ -554,12 +553,13 @@ int16_t _lv_style_get_int(const lv_style_t * style, lv_style_property_t prop, vo if(style == NULL) return -1; if(style->map == NULL) return -1; + int32_t id = get_property_index(style, prop); if(id < 0) { return -1; } else { - memcpy(res, &style->map[id + sizeof(lv_style_property_t)], sizeof(lv_style_int_t)); + lv_memcpy_small(res, &style->map[id + sizeof(lv_style_property_t)], sizeof(lv_style_int_t)); lv_style_attr_t attr_act; attr_act.full = style->map[id + 1]; @@ -590,12 +590,13 @@ int16_t _lv_style_get_opa(const lv_style_t * style, lv_style_property_t prop, vo if(style == NULL) return -1; if(style->map == NULL) return -1; + int32_t id = get_property_index(style, prop); if(id < 0) { return -1; } else { - memcpy(res, &style->map[id + sizeof(lv_style_property_t)], sizeof(lv_opa_t)); + lv_memcpy_small(res, &style->map[id + sizeof(lv_style_property_t)], sizeof(lv_opa_t)); lv_style_attr_t attr_act; attr_act.full = style->map[id + 1]; @@ -629,7 +630,7 @@ int16_t _lv_style_get_color(const lv_style_t * style, lv_style_property_t prop, return -1; } else { - memcpy(res, &style->map[id + sizeof(lv_style_property_t)], sizeof(lv_color_t)); + lv_memcpy_small(res, &style->map[id + sizeof(lv_style_property_t)], sizeof(lv_color_t)); lv_style_attr_t attr_act; attr_act.full = style->map[id + 1]; @@ -655,15 +656,16 @@ 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; + _lv_style_fptr_dptr_t * res = (_lv_style_fptr_dptr_t *)v_res; if(style == NULL) return -1; if(style->map == NULL) return -1; + int32_t id = get_property_index(style, prop); if(id < 0) { return -1; } else { - memcpy(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(_lv_style_fptr_dptr_t)); lv_style_attr_t attr_act; attr_act.full = style->map[id + 1]; @@ -789,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, _lv_style_fptr_dptr_t value) { LV_ASSERT_STYLE_LIST(list); @@ -962,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, _lv_style_fptr_dptr_t * res) { LV_ASSERT_STYLE_LIST(list); @@ -975,7 +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; + _lv_style_fptr_dptr_t value_act; value_act.dptr = NULL; value_act.fptr = NULL; @@ -1020,7 +1022,6 @@ lv_res_t lv_style_list_get_ptr(lv_style_list_t * list, lv_style_property_t prop, */ static inline int32_t get_property_index(const lv_style_t * style, lv_style_property_t prop) { - LV_ASSERT_STYLE(style); if(style->map == NULL) return -1; @@ -1058,7 +1059,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(_lv_style_fptr_dptr_t); i += sizeof(lv_style_property_t); } @@ -1091,4 +1092,3 @@ static lv_style_t * get_alloc_local_style(lv_style_list_t * list) return local_style; } - diff --git a/src/lv_core/lv_style.h b/src/lv_core/lv_style.h index 9828fc83ef..3cfccbfecc 100644 --- a/src/lv_core/lv_style.h +++ b/src/lv_core/lv_style.h @@ -216,12 +216,14 @@ typedef struct { typedef int16_t lv_style_int_t; -typedef void(*lv_style_prop_cb_t)(void); +/*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_cb_t fptr; + _lv_style_prop_xcb_t fptr; const void * dptr; -} lv_style_fptr_dptr_t; +} _lv_style_fptr_dptr_t; typedef struct { @@ -371,7 +373,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 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, _lv_style_fptr_dptr_t p); /** * Set a function pointer typed property in a style. @@ -383,9 +385,9 @@ void _lv_style_set_ptr(lv_style_t * style, lv_style_property_t prop, lv_style_fp * 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_cb_t p) +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; + _lv_style_fptr_dptr_t fd; fd.dptr = NULL; fd.fptr = p; _lv_style_set_ptr(style, prop, fd); @@ -403,7 +405,7 @@ static inline void _lv_style_set_func_ptr(lv_style_t * style, lv_style_property_ */ 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; + _lv_style_fptr_dptr_t fd; fd.fptr = NULL; fd.dptr = p; _lv_style_set_ptr(style, prop, fd); @@ -485,12 +487,12 @@ int16_t _lv_style_get_ptr(const lv_style_t * style, lv_style_property_t prop, vo */ 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; + _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_cb_t * res2 = (lv_style_prop_cb_t *)res; + _lv_style_prop_xcb_t * res2 = (_lv_style_prop_xcb_t *)res; *res2 = fd_res.fptr; return r; } @@ -510,7 +512,7 @@ static inline int16_t _lv_style_get_func_ptr(const lv_style_t * style, lv_style_ */ 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; + _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); @@ -580,7 +582,7 @@ 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, _lv_style_fptr_dptr_t value); /** * Set a local pointer typed property in a style list. @@ -591,9 +593,9 @@ void lv_style_list_set_local_ptr(lv_style_list_t * list, lv_style_property_t pro * @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_cb_t value) + _lv_style_prop_xcb_t value) { - lv_style_fptr_dptr_t fd; + _lv_style_fptr_dptr_t fd; fd.dptr = NULL; fd.fptr = value; lv_style_list_set_local_ptr(list, prop, fd); @@ -610,7 +612,7 @@ static inline void lv_style_list_set_local_func_ptr(lv_style_list_t * list, lv_s 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; + _lv_style_fptr_dptr_t fd; fd.fptr = NULL; fd.dptr = value; lv_style_list_set_local_ptr(list, prop, fd); @@ -667,7 +669,7 @@ lv_res_t lv_style_list_get_opa(lv_style_list_t * list, lv_style_property_t prop, * @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, _lv_style_fptr_dptr_t * res); /** @@ -683,7 +685,7 @@ lv_res_t lv_style_list_get_ptr(lv_style_list_t * list, lv_style_property_t prop, */ 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; + _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); @@ -705,7 +707,7 @@ static inline lv_res_t lv_style_list_get_func_ptr(lv_style_list_t * list, lv_sty */ 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; + _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); diff --git a/src/lv_draw/lv_draw_blend.c b/src/lv_draw/lv_draw_blend.c index 0128eb3e6c..6757034f29 100644 --- a/src/lv_draw/lv_draw_blend.c +++ b/src/lv_draw/lv_draw_blend.c @@ -860,11 +860,11 @@ static inline lv_color_t color_blend_true_color_additive(lv_color_t fg, lv_color fg.ch.red = LV_MATH_MIN(tmp, 255); #endif - tmp = bg.ch.green + fg.ch.green; #if LV_COLOR_DEPTH == 8 fg.ch.green = LV_MATH_MIN(tmp, 7); #elif LV_COLOR_DEPTH == 16 #if LV_COLOR_16_SWAP == 0 + tmp = bg.ch.green + fg.ch.green; fg.ch.green = LV_MATH_MIN(tmp, 63); #else tmp = (bg.ch.green_h << 3) + bg.ch.green_l + (fg.ch.green_h << 3) + fg.ch.green_l; diff --git a/src/lv_draw/lv_draw_img.c b/src/lv_draw/lv_draw_img.c index 294e33f97b..e9ab8f584f 100644 --- a/src/lv_draw/lv_draw_img.c +++ b/src/lv_draw/lv_draw_img.c @@ -48,7 +48,7 @@ static void show_error(const lv_area_t * coords, const lv_area_t * clip_area, co void lv_draw_img_dsc_init(lv_draw_img_dsc_t * dsc) { - memset(dsc, 0x00, sizeof(lv_draw_img_dsc_t)); + lv_memset_00(dsc, sizeof(lv_draw_img_dsc_t)); dsc->recolor = LV_COLOR_BLACK; dsc->opa = LV_OPA_COVER; dsc->zoom = LV_IMG_ZOOM_NONE; diff --git a/src/lv_draw/lv_draw_label.c b/src/lv_draw/lv_draw_label.c index a7e7bf2edc..53d9975d2c 100644 --- a/src/lv_draw/lv_draw_label.c +++ b/src/lv_draw/lv_draw_label.c @@ -82,7 +82,7 @@ static const uint8_t bpp8_opa_table[256] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 void lv_draw_label_dsc_init(lv_draw_label_dsc_t * dsc) { - memset(dsc, 0x00, sizeof(lv_draw_label_dsc_t)); + lv_memset_00(dsc, sizeof(lv_draw_label_dsc_t)); dsc->opa = LV_OPA_COVER; dsc->color = LV_COLOR_BLACK; dsc->font = LV_THEME_DEFAULT_FONT_NORMAL; @@ -275,7 +275,7 @@ void lv_draw_label(const lv_area_t * coords, const lv_area_t * mask, lv_draw_lab /*Get the parameter*/ if(i - par_start == LABEL_RECOLOR_PAR_LENGTH + 1) { char buf[LABEL_RECOLOR_PAR_LENGTH + 1]; - memcpy(buf, &bidi_txt[par_start], LABEL_RECOLOR_PAR_LENGTH); + lv_memcpy_small(buf, &bidi_txt[par_start], LABEL_RECOLOR_PAR_LENGTH); buf[LABEL_RECOLOR_PAR_LENGTH] = '\0'; int r, g, b; r = (hex_char_to_num(buf[0]) << 4) + hex_char_to_num(buf[1]); diff --git a/src/lv_draw/lv_draw_line.c b/src/lv_draw/lv_draw_line.c index 803bb3dd41..b842979ba9 100644 --- a/src/lv_draw/lv_draw_line.c +++ b/src/lv_draw/lv_draw_line.c @@ -45,7 +45,7 @@ static void draw_line_ver(const lv_point_t * point1, const lv_point_t * point2, void lv_draw_line_dsc_init(lv_draw_line_dsc_t * dsc) { - memset(dsc, 0x00, sizeof(lv_draw_line_dsc_t)); + lv_memset_00(dsc, sizeof(lv_draw_line_dsc_t)); dsc->width = 1; dsc->opa = LV_OPA_COVER; dsc->color = LV_COLOR_BLACK; diff --git a/src/lv_draw/lv_draw_mask.c b/src/lv_draw/lv_draw_mask.c index fbc77cab23..1f830d46ea 100644 --- a/src/lv_draw/lv_draw_mask.c +++ b/src/lv_draw/lv_draw_mask.c @@ -210,7 +210,7 @@ void lv_draw_mask_line_points_init(lv_draw_mask_line_param_t * param, lv_coord_t param->flat = (LV_MATH_ABS(p2x - p1x) > LV_MATH_ABS(p2y - p1y)) ? 1 : 0; param->yx_steep = 0; param->xy_steep = 0; - param->dsc.cb = (lv_draw_mask_cb_t)lv_draw_mask_line; + param->dsc.cb = (lv_draw_mask_xcb_t)lv_draw_mask_line; param->dsc.type = LV_DRAW_MASK_TYPE_LINE; int32_t dx = p2x - p1x; @@ -328,7 +328,7 @@ void lv_draw_mask_angle_init(lv_draw_mask_angle_param_t * param, lv_coord_t vert param->cfg.end_angle = end_angle; param->cfg.vertex_p.x = vertex_x; param->cfg.vertex_p.y = vertex_y; - param->dsc.cb = (lv_draw_mask_cb_t)lv_draw_mask_angle; + param->dsc.cb = (lv_draw_mask_xcb_t)lv_draw_mask_angle; param->dsc.type = LV_DRAW_MASK_TYPE_ANGLE; if(start_angle >= 0 && start_angle < 180) { @@ -375,7 +375,7 @@ void lv_draw_mask_radius_init(lv_draw_mask_radius_param_t * param, const lv_area lv_area_copy(¶m->cfg.rect, rect); param->cfg.radius = radius; param->cfg.outer = inv ? 1 : 0; - param->dsc.cb = (lv_draw_mask_cb_t)lv_draw_mask_radius; + param->dsc.cb = (lv_draw_mask_xcb_t)lv_draw_mask_radius; param->dsc.type = LV_DRAW_MASK_TYPE_RADIUS; param->y_prev = INT32_MIN; param->y_prev_x.f = 0; @@ -401,7 +401,7 @@ void lv_draw_mask_fade_init(lv_draw_mask_fade_param_t * param, const lv_area_t * param->cfg.opa_bottom = opa_bottom; param->cfg.y_top = y_top; param->cfg.y_bottom = y_bottom; - param->dsc.cb = (lv_draw_mask_cb_t)lv_draw_mask_fade; + param->dsc.cb = (lv_draw_mask_xcb_t)lv_draw_mask_fade; param->dsc.type = LV_DRAW_MASK_TYPE_FADE; } @@ -416,7 +416,7 @@ void lv_draw_mask_map_init(lv_draw_mask_map_param_t * param, const lv_area_t * c { lv_area_copy(¶m->cfg.coords, coords); param->cfg.map = map; - param->dsc.cb = (lv_draw_mask_cb_t)lv_draw_mask_map; + param->dsc.cb = (lv_draw_mask_xcb_t)lv_draw_mask_map; param->dsc.type = LV_DRAW_MASK_TYPE_MAP; } diff --git a/src/lv_draw/lv_draw_mask.h b/src/lv_draw/lv_draw_mask.h index b2321748ac..6a418ecdc2 100644 --- a/src/lv_draw/lv_draw_mask.h +++ b/src/lv_draw/lv_draw_mask.h @@ -53,13 +53,17 @@ enum { LV_DRAW_MASK_LINE_SIDE_BOTTOM, }; -typedef lv_draw_mask_res_t (*lv_draw_mask_cb_t)(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t len, +/** + * A common callback type for every mask type. + * Used internally by the library. + */ +typedef lv_draw_mask_res_t (*lv_draw_mask_xcb_t)(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t len, void * p); typedef uint8_t lv_draw_mask_line_side_t; typedef struct { - lv_draw_mask_cb_t cb; + lv_draw_mask_xcb_t cb; lv_draw_mask_type_t type; } lv_draw_mask_common_dsc_t; diff --git a/src/lv_draw/lv_draw_rect.c b/src/lv_draw/lv_draw_rect.c index 0b9e3fd65b..377490b342 100644 --- a/src/lv_draw/lv_draw_rect.c +++ b/src/lv_draw/lv_draw_rect.c @@ -59,7 +59,7 @@ static int32_t sh_cache_r = -1; void lv_draw_rect_dsc_init(lv_draw_rect_dsc_t * dsc) { - memset(dsc, 0x00, sizeof(lv_draw_rect_dsc_t)); + lv_memset_00(dsc, sizeof(lv_draw_rect_dsc_t)); dsc->bg_color = LV_COLOR_WHITE; dsc->bg_grad_color = LV_COLOR_BLACK; dsc->border_color = LV_COLOR_BLACK; @@ -274,10 +274,12 @@ static void draw_bg(const lv_area_t * coords, const lv_area_t * clip, lv_draw_re grad_color, mask_buf, mask_res, opa, dsc->bg_blend_mode); /*Center part*/ - fill_area2.x1 = coords_bg.x1 + rout; - fill_area2.x2 = coords_bg.x2 - rout; - lv_blend_fill(clip, &fill_area2, - grad_color, NULL, LV_DRAW_MASK_RES_FULL_COVER, opa, dsc->bg_blend_mode); + if(dsc->bg_grad_dir == LV_GRAD_DIR_VER) { + fill_area2.x1 = coords_bg.x1 + rout; + fill_area2.x2 = coords_bg.x2 - rout; + lv_blend_fill(clip, &fill_area2, + grad_color, NULL, LV_DRAW_MASK_RES_FULL_COVER, opa, dsc->bg_blend_mode); + } /*Right part*/ fill_area2.x1 = coords_bg.x2 - rout + 1; diff --git a/src/lv_draw/lv_img_buf.c b/src/lv_draw/lv_img_buf.c index 5a02f5f46b..b82fbe5afb 100644 --- a/src/lv_draw/lv_img_buf.c +++ b/src/lv_draw/lv_img_buf.c @@ -59,7 +59,7 @@ lv_color_t lv_img_buf_get_px_color(lv_img_dsc_t * dsc, lv_coord_t x, lv_coord_t dsc->header.cf == LV_IMG_CF_TRUE_COLOR_ALPHA) { uint8_t px_size = lv_img_cf_get_px_size(dsc->header.cf) >> 3; uint32_t px = dsc->header.w * y * px_size + x * px_size; - memcpy(&p_color, &buf_u8[px], sizeof(lv_color_t)); + lv_memcpy_small(&p_color, &buf_u8[px], sizeof(lv_color_t)); #if LV_COLOR_SIZE == 32 p_color.ch.alpha = 0xFF; /*Only the color should be get so use a deafult alpha value*/ #endif @@ -246,12 +246,12 @@ void lv_img_buf_set_px_color(lv_img_dsc_t * dsc, lv_coord_t x, lv_coord_t y, lv_ if(dsc->header.cf == LV_IMG_CF_TRUE_COLOR || dsc->header.cf == LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED) { uint8_t px_size = lv_img_cf_get_px_size(dsc->header.cf) >> 3; uint32_t px = dsc->header.w * y * px_size + x * px_size; - memcpy(&buf_u8[px], &c, px_size); + lv_memcpy_small(&buf_u8[px], &c, px_size); } else if(dsc->header.cf == LV_IMG_CF_TRUE_COLOR_ALPHA) { uint8_t px_size = lv_img_cf_get_px_size(dsc->header.cf) >> 3; uint32_t px = dsc->header.w * y * px_size + x * px_size; - memcpy(&buf_u8[px], &c, px_size - 1); /*-1 to not overwrite the alpha value*/ + lv_memcpy_small(&buf_u8[px], &c, px_size - 1); /*-1 to not overwrite the alpha value*/ } else if(dsc->header.cf == LV_IMG_CF_INDEXED_1BIT) { buf_u8 += sizeof(lv_color32_t) * 2; /*Skip the palette*/ @@ -319,7 +319,7 @@ void lv_img_buf_set_palette(lv_img_dsc_t * dsc, uint8_t id, lv_color_t c) lv_color32_t c32; c32.full = lv_color_to32(c); uint8_t * buf = (uint8_t *)dsc->data; - memcpy(&buf[id * sizeof(c32)], &c32, sizeof(c32)); + lv_memcpy_small(&buf[id * sizeof(c32)], &c32, sizeof(c32)); } /** @@ -507,12 +507,12 @@ bool lv_img_buf_transform(lv_img_transform_dsc_t * dsc, lv_coord_t x, lv_coord_t px_size = LV_COLOR_SIZE >> 3; pxi = dsc->cfg.src_w * ys_int * px_size + xs_int * px_size; - memcpy(&dsc->res.color, &src_u8[pxi], px_size); + lv_memcpy_small(&dsc->res.color, &src_u8[pxi], px_size); } else { px_size = LV_IMG_PX_SIZE_ALPHA_BYTE; pxi = dsc->cfg.src_w * ys_int * px_size + xs_int * px_size; - memcpy(&dsc->res.color, &src_u8[pxi], px_size - 1); + lv_memcpy_small(&dsc->res.color, &src_u8[pxi], px_size - 1); dsc->res.opa = src_u8[pxi + px_size - 1]; } } @@ -669,9 +669,9 @@ static inline bool transform_anti_alias(lv_img_transform_dsc_t * dsc) lv_opa_t a11 = 0; if(dsc->tmp.native_color) { - memcpy(&c01, &src_u8[dsc->tmp.pxi + dsc->tmp.px_size * xn], sizeof(lv_color_t)); - memcpy(&c10, &src_u8[dsc->tmp.pxi + dsc->cfg.src_w * dsc->tmp.px_size * yn], sizeof(lv_color_t)); - memcpy(&c11, &src_u8[dsc->tmp.pxi + dsc->cfg.src_w * dsc->tmp.px_size * yn + dsc->tmp.px_size * xn], + lv_memcpy_small(&c01, &src_u8[dsc->tmp.pxi + dsc->tmp.px_size * xn], sizeof(lv_color_t)); + lv_memcpy_small(&c10, &src_u8[dsc->tmp.pxi + dsc->cfg.src_w * dsc->tmp.px_size * yn], sizeof(lv_color_t)); + lv_memcpy_small(&c11, &src_u8[dsc->tmp.pxi + dsc->cfg.src_w * dsc->tmp.px_size * yn + dsc->tmp.px_size * xn], sizeof(lv_color_t)); if(dsc->tmp.has_alpha) { a10 = src_u8[dsc->tmp.pxi + dsc->tmp.px_size * xn + dsc->tmp.px_size - 1]; diff --git a/src/lv_draw/lv_img_cache.c b/src/lv_draw/lv_img_cache.c index eab868aaca..ff1dff9f8e 100644 --- a/src/lv_draw/lv_img_cache.c +++ b/src/lv_draw/lv_img_cache.c @@ -130,8 +130,8 @@ lv_img_cache_entry_t * lv_img_cache_open(const void * src, lv_color_t color) if(open_res == LV_RES_INV) { LV_LOG_WARN("Image draw cannot open the image resource"); lv_img_decoder_close(&cached_src->dec_dsc); - memset(&cached_src->dec_dsc, 0, sizeof(lv_img_decoder_dsc_t)); - memset(cached_src, 0, sizeof(lv_img_cache_entry_t)); + lv_memset_00(&cached_src->dec_dsc, sizeof(lv_img_decoder_dsc_t)); + lv_memset_00(cached_src, sizeof(lv_img_cache_entry_t)); cached_src->life = INT32_MIN; /*Make the empty entry very "weak" to force its use */ return NULL; } @@ -175,8 +175,8 @@ void lv_img_cache_set_size(uint16_t new_entry_cnt) /*Clean the cache*/ uint16_t i; for(i = 0; i < entry_cnt; i++) { - memset(&LV_GC_ROOT(_lv_img_cache_array)[i].dec_dsc, 0, sizeof(lv_img_decoder_dsc_t)); - memset(&LV_GC_ROOT(_lv_img_cache_array)[i], 0, sizeof(lv_img_cache_entry_t)); + lv_memset_00(&LV_GC_ROOT(_lv_img_cache_array)[i].dec_dsc, sizeof(lv_img_decoder_dsc_t)); + lv_memset_00(&LV_GC_ROOT(_lv_img_cache_array)[i], sizeof(lv_img_cache_entry_t)); } } @@ -197,8 +197,8 @@ void lv_img_cache_invalidate_src(const void * src) lv_img_decoder_close(&cache[i].dec_dsc); } - memset(&cache[i].dec_dsc, 0, sizeof(lv_img_decoder_dsc_t)); - memset(&cache[i], 0, sizeof(lv_img_cache_entry_t)); + lv_memset_00(&cache[i].dec_dsc, sizeof(lv_img_decoder_dsc_t)); + lv_memset_00(&cache[i], sizeof(lv_img_cache_entry_t)); } } } diff --git a/src/lv_draw/lv_img_decoder.c b/src/lv_draw/lv_img_decoder.c index 74171a8928..45633001c6 100644 --- a/src/lv_draw/lv_img_decoder.c +++ b/src/lv_draw/lv_img_decoder.c @@ -151,7 +151,7 @@ lv_res_t lv_img_decoder_open(lv_img_decoder_dsc_t * dsc, const void * src, lv_co } if(res == LV_RES_INV) { - memset(dsc, 0, sizeof(lv_img_decoder_dsc_t)); + lv_memset_00(dsc, sizeof(lv_img_decoder_dsc_t)); } return res; @@ -201,7 +201,7 @@ lv_img_decoder_t * lv_img_decoder_create(void) LV_ASSERT_MEM(decoder); if(decoder == NULL) return NULL; - memset(decoder, 0, sizeof(lv_img_decoder_t)); + lv_memset_00(decoder, sizeof(lv_img_decoder_t)); return decoder; } @@ -341,7 +341,7 @@ lv_res_t lv_img_decoder_built_in_open(lv_img_decoder_t * decoder, lv_img_decoder LV_LOG_ERROR("img_decoder_built_in_open: out of memory"); return LV_RES_INV; } - memset(dsc->user_data, 0, sizeof(lv_img_decoder_built_in_data_t)); + lv_memset_00(dsc->user_data, sizeof(lv_img_decoder_built_in_data_t)); } lv_img_decoder_built_in_data_t * user_data = dsc->user_data; @@ -353,7 +353,7 @@ lv_res_t lv_img_decoder_built_in_open(lv_img_decoder_t * decoder, lv_img_decoder return LV_RES_INV; } - memcpy(user_data->f, &f, sizeof(f)); + lv_memcpy_small(user_data->f, &f, sizeof(f)); #else LV_LOG_WARN("Image built-in decoder cannot read file because LV_USE_FILESYSTEM = 0"); @@ -399,7 +399,7 @@ lv_res_t lv_img_decoder_built_in_open(lv_img_decoder_t * decoder, lv_img_decoder lv_img_decoder_built_in_close(decoder, dsc); return LV_RES_INV; } - memset(dsc->user_data, 0, sizeof(lv_img_decoder_built_in_data_t)); + lv_memset_00(dsc->user_data, sizeof(lv_img_decoder_built_in_data_t)); } lv_img_decoder_built_in_data_t * user_data = dsc->user_data; diff --git a/src/lv_font/lv_font.mk b/src/lv_font/lv_font.mk index e41cb2665d..d64245bfc1 100644 --- a/src/lv_font/lv_font.mk +++ b/src/lv_font/lv_font.mk @@ -6,11 +6,19 @@ CSRCS += lv_font_montserrat_16.c CSRCS += lv_font_montserrat_18.c CSRCS += lv_font_montserrat_20.c CSRCS += lv_font_montserrat_22.c -CSRCS += lv_font_montserrat_14.c +CSRCS += lv_font_montserrat_24.c CSRCS += lv_font_montserrat_26.c CSRCS += lv_font_montserrat_28.c CSRCS += lv_font_montserrat_30.c CSRCS += lv_font_montserrat_32.c +CSRCS += lv_font_montserrat_34.c +CSRCS += lv_font_montserrat_36.c +CSRCS += lv_font_montserrat_38.c +CSRCS += lv_font_montserrat_40.c +CSRCS += lv_font_montserrat_42.c +CSRCS += lv_font_montserrat_44.c +CSRCS += lv_font_montserrat_46.c +CSRCS += lv_font_montserrat_48.c CSRCS += lv_font_montserrat_12_subpx.c CSRCS += lv_font_montserrat_28_compressed.c CSRCS += lv_font_unscii_8.c diff --git a/src/lv_hal/lv_hal_disp.c b/src/lv_hal/lv_hal_disp.c index 92f629919e..757293fce1 100644 --- a/src/lv_hal/lv_hal_disp.c +++ b/src/lv_hal/lv_hal_disp.c @@ -56,7 +56,7 @@ static lv_disp_t * disp_def; */ void lv_disp_drv_init(lv_disp_drv_t * driver) { - memset(driver, 0, sizeof(lv_disp_drv_t)); + lv_memset_00(driver, sizeof(lv_disp_drv_t)); driver->flush_cb = NULL; driver->hor_res = LV_HOR_RES_MAX; @@ -103,7 +103,7 @@ void lv_disp_drv_init(lv_disp_drv_t * driver) */ void lv_disp_buf_init(lv_disp_buf_t * disp_buf, void * buf1, void * buf2, uint32_t size_in_px_cnt) { - memset(disp_buf, 0, sizeof(lv_disp_buf_t)); + lv_memset_00(disp_buf, sizeof(lv_disp_buf_t)); disp_buf->buf1 = buf1; disp_buf->buf2 = buf2; @@ -125,9 +125,9 @@ lv_disp_t * lv_disp_drv_register(lv_disp_drv_t * driver) return NULL; } - memcpy(&disp->driver, driver, sizeof(lv_disp_drv_t)); - memset(&disp->inv_area_joined, 0, sizeof(disp->inv_area_joined)); - memset(&disp->inv_areas, 0, sizeof(disp->inv_areas)); + lv_memcpy(&disp->driver, driver, sizeof(lv_disp_drv_t)); + lv_memset_00(&disp->inv_area_joined, sizeof(disp->inv_area_joined)); + lv_memset_00(&disp->inv_areas, sizeof(disp->inv_areas)); lv_ll_init(&disp->scr_ll, sizeof(lv_obj_t)); disp->last_activity_time = 0; diff --git a/src/lv_hal/lv_hal_disp.h b/src/lv_hal/lv_hal_disp.h index 8f7affc327..4416cfd598 100644 --- a/src/lv_hal/lv_hal_disp.h +++ b/src/lv_hal/lv_hal_disp.h @@ -52,10 +52,10 @@ typedef struct { void * buf_act; uint32_t size; /*In pixel count*/ lv_area_t area; - volatile uint32_t flushing :1; - volatile uint32_t flushing_last :1; - volatile uint32_t last_area :1; - volatile uint32_t last_part :1; + volatile int flushing; /*1: flushing is in progress. (It can't be a bitfield because when it's cleared from IRQ Read-Modify-Write issue might occur)*/ + volatile int flushing_last; /*1: It was the last chunk to flush. (It can't be a bitfield because when it's cleared from IRQ Read-Modify-Write issue might occur)*/ + volatile uint32_t last_area :1; /*1: the last area is being rendered*/ + volatile uint32_t last_part :1; /*1: the last part of the current area is being rendered*/ } lv_disp_buf_t; /** diff --git a/src/lv_hal/lv_hal_indev.c b/src/lv_hal/lv_hal_indev.c index 57fef191ee..8b2159d250 100644 --- a/src/lv_hal/lv_hal_indev.c +++ b/src/lv_hal/lv_hal_indev.c @@ -51,7 +51,7 @@ */ void lv_indev_drv_init(lv_indev_drv_t * driver) { - memset(driver, 0, sizeof(lv_indev_drv_t)); + lv_memset_00(driver, sizeof(lv_indev_drv_t)); driver->type = LV_INDEV_TYPE_NONE; driver->drag_limit = LV_INDEV_DEF_DRAG_LIMIT; @@ -84,8 +84,8 @@ lv_indev_t * lv_indev_drv_register(lv_indev_drv_t * driver) return NULL; } - memset(indev, 0, sizeof(lv_indev_t)); - memcpy(&indev->driver, driver, sizeof(lv_indev_drv_t)); + lv_memset_00(indev, sizeof(lv_indev_t)); + lv_memcpy(&indev->driver, driver, sizeof(lv_indev_drv_t)); indev->proc.reset_query = 1; indev->cursor = NULL; @@ -131,7 +131,7 @@ bool lv_indev_read(lv_indev_t * indev, lv_indev_data_t * data) { bool cont = false; - memset(data, 0, sizeof(lv_indev_data_t)); + lv_memset_00(data, sizeof(lv_indev_data_t)); /* For touchpad sometimes users don't the last pressed coordinate on release. * So be sure a coordinates are initialized to the last point */ diff --git a/src/lv_misc/lv_anim.c b/src/lv_misc/lv_anim.c index cb46da69eb..5eb33197de 100644 --- a/src/lv_misc/lv_anim.c +++ b/src/lv_misc/lv_anim.c @@ -77,7 +77,7 @@ void lv_anim_core_init(void) */ void lv_anim_init(lv_anim_t * a) { - memset(a, 0, sizeof(lv_anim_t)); + lv_memset_00(a, sizeof(lv_anim_t)); a->time = 500; a->start = 0; a->end = 100; @@ -107,7 +107,7 @@ void lv_anim_start(lv_anim_t * a) /*Initialize the animation descriptor*/ a->time_orig = a->time; - memcpy(new_anim, a, sizeof(lv_anim_t)); + lv_memcpy(new_anim, a, sizeof(lv_anim_t)); /*Set the start value*/ if(new_anim->early_apply) { @@ -502,7 +502,7 @@ static bool anim_ready_handler(lv_anim_t * a) /*Create copy from the animation and delete the animation from the list. * This way the `ready_cb` will see the animations like it's animation is ready deleted*/ lv_anim_t a_tmp; - memcpy(&a_tmp, a, sizeof(lv_anim_t)); + lv_memcpy(&a_tmp, a, sizeof(lv_anim_t)); lv_ll_remove(&LV_GC_ROOT(_lv_anim_ll), a); lv_mem_free(a); /*Flag that the list has changed */ diff --git a/src/lv_misc/lv_area.h b/src/lv_misc/lv_area.h index aa6de6fa60..17f7b03747 100644 --- a/src/lv_misc/lv_area.h +++ b/src/lv_misc/lv_area.h @@ -17,6 +17,7 @@ extern "C" { #include #include #include +#include "lv_mem.h" /********************* * DEFINES @@ -98,7 +99,7 @@ void lv_area_set(lv_area_t * area_p, lv_coord_t x1, lv_coord_t y1, lv_coord_t x2 */ inline static void lv_area_copy(lv_area_t * dest, const lv_area_t * src) { - memcpy(dest, src, sizeof(lv_area_t)); + lv_memcpy_small(dest, src, sizeof(lv_area_t)); } /** diff --git a/src/lv_misc/lv_async.c b/src/lv_misc/lv_async.c index 4d6e7b095b..4336ff09ad 100644 --- a/src/lv_misc/lv_async.c +++ b/src/lv_misc/lv_async.c @@ -57,7 +57,7 @@ lv_res_t lv_async_call(lv_async_cb_t async_xcb, void * user_data) /* Set the task's user data */ task->user_data = info; - lv_task_once(task); + lv_task_set_repeat_count(task, 1); return LV_RES_OK; } diff --git a/src/lv_misc/lv_bidi.c b/src/lv_misc/lv_bidi.c index 3684c8ddd9..43fb74bc24 100644 --- a/src/lv_misc/lv_bidi.c +++ b/src/lv_misc/lv_bidi.c @@ -316,7 +316,7 @@ void lv_bidi_process_paragraph(const char * str_in, char * str_out, uint32_t len if(rd) { if(base_dir == LV_BIDI_DIR_LTR) { if(str_out) { - memcpy(&str_out[wr], str_in, rd); + lv_memcpy(&str_out[wr], str_in, rd); wr += rd; } if(pos_conv_out) { @@ -339,7 +339,7 @@ void lv_bidi_process_paragraph(const char * str_in, char * str_out, uint32_t len if(base_dir == LV_BIDI_DIR_LTR) { if(run_dir == LV_BIDI_DIR_LTR) { - if(str_out) memcpy(&str_out[wr], &str_in[rd], run_len); + if(str_out) lv_memcpy(&str_out[wr], &str_in[rd], run_len); if(pos_conv_out) fill_pos_conv(&pos_conv_out[pos_conv_wr], pos_conv_run_len, pos_conv_rd); } else rtl_reverse(str_out ? &str_out[wr] : NULL, &str_in[rd], run_len, pos_conv_out ? &pos_conv_out[pos_conv_wr] : NULL, @@ -351,7 +351,7 @@ void lv_bidi_process_paragraph(const char * str_in, char * str_out, uint32_t len wr -= run_len; pos_conv_wr -= pos_conv_run_len; if(run_dir == LV_BIDI_DIR_LTR) { - if(str_out) memcpy(&str_out[wr], &str_in[rd], run_len); + if(str_out) lv_memcpy(&str_out[wr], &str_in[rd], run_len); if(pos_conv_out) fill_pos_conv(&pos_conv_out[pos_conv_wr], pos_conv_run_len, pos_conv_rd); } else rtl_reverse(str_out ? &str_out[wr] : NULL, &str_in[rd], run_len, pos_conv_out ? &pos_conv_out[pos_conv_wr] : NULL, @@ -528,7 +528,7 @@ static void rtl_reverse(char * dest, const char * src, uint32_t len, uint16_t * pos_conv_first_weak = 0; } - if(dest) memcpy(&dest[wr], &src[first_weak], last_weak - first_weak + 1); + if(dest) lv_memcpy(&dest[wr], &src[first_weak], last_weak - first_weak + 1); if(pos_conv_out) fill_pos_conv(&pos_conv_out[pos_conv_wr], pos_conv_last_weak - pos_conv_first_weak + 1, pos_conv_rd_base + pos_conv_first_weak); wr += last_weak - first_weak + 1; @@ -548,7 +548,7 @@ static void rtl_reverse(char * dest, const char * src, uint32_t len, uint16_t * } /*Just store the letter*/ else { - if(dest) memcpy(&dest[wr], &src[i], letter_size); + if(dest) lv_memcpy(&dest[wr], &src[i], letter_size); if(pos_conv_out) pos_conv_out[pos_conv_wr] = SET_RTL_POS(pos_conv_rd_base + pos_conv_i, true); wr += letter_size; pos_conv_wr++; diff --git a/src/lv_misc/lv_fs.c b/src/lv_misc/lv_fs.c index 7a156a638b..5070d5d7ba 100644 --- a/src/lv_misc/lv_fs.c +++ b/src/lv_misc/lv_fs.c @@ -475,7 +475,7 @@ lv_fs_res_t lv_fs_free_space(char letter, uint32_t * total_p, uint32_t * free_p) */ void lv_fs_drv_init(lv_fs_drv_t * drv) { - memset(drv, 0, sizeof(lv_fs_drv_t)); + lv_memset_00(drv, sizeof(lv_fs_drv_t)); } /** @@ -491,7 +491,7 @@ void lv_fs_drv_register(lv_fs_drv_t * drv_p) LV_ASSERT_MEM(new_drv); if(new_drv == NULL) return; - memcpy(new_drv, drv_p, sizeof(lv_fs_drv_t)); + lv_memcpy(new_drv, drv_p, sizeof(lv_fs_drv_t)); } /** diff --git a/src/lv_misc/lv_gc.c b/src/lv_misc/lv_gc.c index 0d568ec4ad..2ce1fa0508 100644 --- a/src/lv_misc/lv_gc.c +++ b/src/lv_misc/lv_gc.c @@ -44,7 +44,7 @@ void lv_gc_clear_roots(void) { -#define LV_CLEAR_ROOT(root_type, root_name) memset(&LV_GC_ROOT(root_name), 0, sizeof(LV_GC_ROOT(root_name))); +#define LV_CLEAR_ROOT(root_type, root_name) lv_memset_00(&LV_GC_ROOT(root_name), sizeof(LV_GC_ROOT(root_name))); LV_ITERATE_ROOTS(LV_CLEAR_ROOT) } diff --git a/src/lv_misc/lv_ll.c b/src/lv_misc/lv_ll.c index c53afe7137..c48fb67d89 100644 --- a/src/lv_misc/lv_ll.c +++ b/src/lv_misc/lv_ll.c @@ -299,7 +299,7 @@ void * lv_ll_get_next(const lv_ll_t * ll_p, const void * n_act) if(ll_p != NULL) { const lv_ll_node_t * n_act_d = n_act; - memcpy(&next, n_act_d + LL_NEXT_P_OFFSET(ll_p), sizeof(void *)); + lv_memcpy_small(&next, n_act_d + LL_NEXT_P_OFFSET(ll_p), sizeof(void *)); } return next; @@ -317,7 +317,7 @@ void * lv_ll_get_prev(const lv_ll_t * ll_p, const void * n_act) if(ll_p != NULL) { const lv_ll_node_t * n_act_d = n_act; - memcpy(&prev, n_act_d + LL_PREV_P_OFFSET(ll_p), sizeof(void *)); + lv_memcpy_small(&prev, n_act_d + LL_PREV_P_OFFSET(ll_p), sizeof(void *)); } return prev; @@ -404,9 +404,9 @@ static void node_set_prev(lv_ll_t * ll_p, lv_ll_node_t * act, lv_ll_node_t * pre uint32_t node_p_size = sizeof(lv_ll_node_t *); if(prev) - memcpy(act + LL_PREV_P_OFFSET(ll_p), &prev, node_p_size); + lv_memcpy_small(act + LL_PREV_P_OFFSET(ll_p), &prev, node_p_size); else - memset(act + LL_PREV_P_OFFSET(ll_p), 0, node_p_size); + lv_memset_00(act + LL_PREV_P_OFFSET(ll_p), node_p_size); } /** @@ -421,7 +421,7 @@ static void node_set_next(lv_ll_t * ll_p, lv_ll_node_t * act, lv_ll_node_t * nex uint32_t node_p_size = sizeof(lv_ll_node_t *); if(next) - memcpy(act + LL_NEXT_P_OFFSET(ll_p), &next, node_p_size); + lv_memcpy_small(act + LL_NEXT_P_OFFSET(ll_p), &next, node_p_size); else - memset(act + LL_NEXT_P_OFFSET(ll_p), 0, node_p_size); + lv_memset_00(act + LL_NEXT_P_OFFSET(ll_p), node_p_size); } diff --git a/src/lv_misc/lv_mem.c b/src/lv_misc/lv_mem.c index 5e510efbf6..dd25af220e 100644 --- a/src/lv_misc/lv_mem.c +++ b/src/lv_misc/lv_mem.c @@ -382,8 +382,11 @@ lv_res_t lv_mem_test(void) lv_mem_ent_t * e; e = ent_get_next(NULL); while(e) { - if((e->header.s.used && e->header.s.d_size > LV_MEM_SIZE) || - (e->header.s.used == 0 && e->header.s.d_size > LV_MEM_SIZE)) { + if(e->header.s.d_size > LV_MEM_SIZE) { + return LV_RES_INV; + } + uint8_t * e8 = (uint8_t*) e; + if(e8 + e->header.s.d_size > work_mem + LV_MEM_SIZE) { return LV_RES_INV; } e = ent_get_next(e); @@ -530,7 +533,6 @@ void lv_mem_buf_free_all(void) /** * Same as `memcpy` but optimized for 4 byte operation. - * `dst` and `src` should be word aligned else normal `memcpy` will be used * @param dst pointer to the destination buffer * @param src pointer to the source buffer * @param len number of byte to copy diff --git a/src/lv_misc/lv_mem.h b/src/lv_misc/lv_mem.h index ea95111269..d1542385af 100644 --- a/src/lv_misc/lv_mem.h +++ b/src/lv_misc/lv_mem.h @@ -135,13 +135,31 @@ void lv_mem_buf_free_all(void); /** * Same as `memcpy` but optimized for 4 byte operation. - * `dst` and `src` should be word aligned else normal `memcpy` will be used * @param dst pointer to the destination buffer * @param src pointer to the source buffer * @param len number of byte to copy */ void * lv_memcpy(void * dst, const void * src, size_t len); +/** + * Same as `memcpy` but optimized to copy only a few bytes. + * @param dst pointer to the destination buffer + * @param src pointer to the source buffer + * @param len number of byte to copy + */ +static inline void * lv_memcpy_small(void * dst, const void * src, size_t len) +{ + uint8_t * d8 = (uint8_t *)dst; + const uint8_t * s8 = (const uint8_t *)src; + + while(len) { + *d8 = *s8; d8++; s8++; + len--; + } + + return dst; +} + /** * Same as `memset` but optimized for 4 byte operation. * `dst` should be word aligned else normal `memcpy` will be used diff --git a/src/lv_misc/lv_task.c b/src/lv_misc/lv_task.c index 8e97ede22d..3cdccd0db4 100644 --- a/src/lv_misc/lv_task.c +++ b/src/lv_misc/lv_task.c @@ -236,7 +236,7 @@ lv_task_t * lv_task_create_basic(void) new_task->task_cb = NULL; new_task->prio = DEF_PRIO; - new_task->once = 0; + new_task->repeat_count = -1; new_task->last_run = lv_tick_get(); new_task->user_data = NULL; @@ -341,12 +341,13 @@ void lv_task_ready(lv_task_t * task) } /** - * Delete the lv_task after one call + * Set the number of times a task will repeat. * @param task pointer to a lv_task. + * @param repeat_count -1 : infinity; 0 : stop ; n>0: residual times */ -void lv_task_once(lv_task_t * task) +void lv_task_set_repeat_count(lv_task_t * task, int32_t repeat_count) { - task->once = 1; + task->repeat_count = repeat_count; } /** @@ -398,9 +399,12 @@ static bool lv_task_exec(lv_task_t * task) /*Delete if it was a one shot lv_task*/ if(task_deleted == false) { /*The task might be deleted by itself as well*/ - if(task->once != 0) { - lv_task_del(task); + if(task->repeat_count > 0) { + task->repeat_count--; } + if(task->repeat_count == 0) { + lv_task_del(task); + } } exec = true; } diff --git a/src/lv_misc/lv_task.h b/src/lv_misc/lv_task.h index ab7ba3b71b..f7184ed58d 100644 --- a/src/lv_misc/lv_task.h +++ b/src/lv_misc/lv_task.h @@ -64,8 +64,8 @@ typedef struct _lv_task_t { void * user_data; /**< Custom user data */ + int32_t repeat_count; /**< 1: Task times; -1 : infinity; 0 : stop ; n>0: residual times */ uint8_t prio : 3; /**< Task priority */ - uint8_t once : 1; /**< 1: one shot task */ } lv_task_t; /********************** @@ -140,10 +140,11 @@ void lv_task_set_period(lv_task_t * task, uint32_t period); void lv_task_ready(lv_task_t * task); /** - * Delete the lv_task after one call + * Set the number of times a task will repeat. * @param task pointer to a lv_task. + * @param repeat_count -1 : infinity; 0 : stop ; n>0: residual times */ -void lv_task_once(lv_task_t * task); +void lv_task_set_repeat_count(lv_task_t * task, int32_t repeat_count); /** * Reset a lv_task. diff --git a/src/lv_misc/lv_txt.c b/src/lv_misc/lv_txt.c index 34bb7f9e9b..a72e2002eb 100644 --- a/src/lv_misc/lv_txt.c +++ b/src/lv_misc/lv_txt.c @@ -445,7 +445,7 @@ void lv_txt_ins(char * txt_buf, uint32_t pos, const char * ins_txt) } /* Copy the text into the new space*/ - memcpy(txt_buf + pos, ins_txt, ins_len); + lv_memcpy_small(txt_buf + pos, ins_txt, ins_len); } /** @@ -537,7 +537,7 @@ static uint32_t lv_txt_utf8_conv_wc(uint32_t c) if((c & 0x80) != 0) { uint32_t swapped; uint8_t c8[4]; - memcpy(c8, &c, 4); + lv_memcpy_small(c8, &c, 4); swapped = (c8[0] << 24) + (c8[1] << 16) + (c8[2] << 8) + (c8[3]); uint8_t i; for(i = 0; i < 4; i++) { diff --git a/src/lv_misc/lv_types.h b/src/lv_misc/lv_types.h index d2db4e39f6..361b0d749a 100644 --- a/src/lv_misc/lv_types.h +++ b/src/lv_misc/lv_types.h @@ -17,20 +17,26 @@ extern "C" { /********************* * DEFINES *********************/ -// Check windows -#ifdef _WIN64 + +#if __STDC_VERSION__ >= 199901L // If c99 or newer, use stdint.h to determine arch size +#include +#endif + + +// If __UINTPTR_MAX__ or UINTPTR_MAX are available, use them to determine arch size +#if defined(__UINTPTR_MAX__) && __UINTPTR_MAX__ > 0xFFFFFFFF #define LV_ARCH_64 -#endif -/* Check GCC */ -#ifdef __GNUC__ -#if defined(__x86_64__) || defined(__ppc64__) +#elif defined(UINTPTR_MAX) && UINTPTR_MAX > 0xFFFFFFFF #define LV_ARCH_64 -#endif + +// Otherwise use compiler-dependent means to determine arch size +#elif defined(_WIN64) || defined(__x86_64__) || defined(__ppc64__) || defined (__aarch64__) +#define LV_ARCH_64 + #endif -#define LV_UNUNSED(x) (void)x; - + /********************** * TYPEDEFS **********************/ @@ -45,12 +51,24 @@ enum { }; typedef uint8_t lv_res_t; + + +#if __STDC_VERSION__ >= 199901L +// If c99 or newer, use the definition of uintptr_t directly from +typedef uintptr_t lv_uintptr_t; + +#else + +// Otherwise, use the arch size determination #ifdef LV_ARCH_64 typedef uint64_t lv_uintptr_t; #else typedef uint32_t lv_uintptr_t; #endif +#endif + + /********************** * GLOBAL PROTOTYPES **********************/ @@ -64,3 +82,4 @@ typedef uint32_t lv_uintptr_t; #endif #endif /*LV_TYPES_H*/ + diff --git a/src/lv_themes/lv_theme.c b/src/lv_themes/lv_theme.c index 66c49ecc25..d3365864bf 100644 --- a/src/lv_themes/lv_theme.c +++ b/src/lv_themes/lv_theme.c @@ -109,7 +109,7 @@ uint32_t lv_theme_get_flags(void) void lv_theme_apply(lv_obj_t * obj, lv_theme_style_t name) { - act_theme->apply_cb(obj, name); + act_theme->apply_xcb(obj, name); } diff --git a/src/lv_themes/lv_theme.h b/src/lv_themes/lv_theme.h index 5698beca76..9470540f15 100644 --- a/src/lv_themes/lv_theme.h +++ b/src/lv_themes/lv_theme.h @@ -144,7 +144,7 @@ typedef enum { } lv_theme_style_t; typedef struct { - void (*apply_cb)(lv_obj_t *, lv_theme_style_t); + void (*apply_xcb)(lv_obj_t *, lv_theme_style_t); lv_color_t color_primary; lv_color_t color_secondary; const lv_font_t * font_small; diff --git a/src/lv_themes/lv_theme_empty.c b/src/lv_themes/lv_theme_empty.c index 784e8d1113..93b34affbf 100644 --- a/src/lv_themes/lv_theme_empty.c +++ b/src/lv_themes/lv_theme_empty.c @@ -62,7 +62,7 @@ lv_theme_t * lv_theme_empty_init(lv_color_t color_primary, lv_color_t color_seco lv_style_init(&opa_cover); lv_style_set_bg_opa(&opa_cover, LV_STATE_DEFAULT, LV_OPA_COVER); - theme.apply_cb = lv_theme_empty_apply; + theme.apply_xcb = lv_theme_empty_apply; return &theme; } diff --git a/src/lv_themes/lv_theme_material.c b/src/lv_themes/lv_theme_material.c index 8615289bc4..e3b506af0c 100644 --- a/src/lv_themes/lv_theme_material.c +++ b/src/lv_themes/lv_theme_material.c @@ -63,7 +63,7 @@ #define COLOR_BG_SEC_TEXT_DIS (IS_LIGHT ? lv_color_hex(0xaaaaaa) : lv_color_hex(0xa5a8ad)) #define TRANSITION_TIME 150 -#define BORDER_WIDTH LV_DPX(3) +#define BORDER_WIDTH LV_DPX(2) #define IS_LIGHT (theme.flags & LV_THEME_MATERIAL_FLAG_LIGHT) /********************** @@ -146,6 +146,9 @@ static lv_style_t pad_small; #if LV_USE_PAGE static lv_style_t sb; +#if LV_USE_ANIMATION + static lv_style_t edge_flash; +#endif #endif #if LV_USE_ROLLER @@ -200,6 +203,7 @@ static void basic_init(void) lv_style_set_bg_color(&bg, LV_STATE_DEFAULT, COLOR_BG); lv_style_set_border_color(&bg, LV_STATE_DEFAULT, COLOR_BG_BORDER); lv_style_set_border_color(&bg, LV_STATE_FOCUSED, theme.color_primary); + lv_style_set_border_color(&bg, LV_STATE_EDITED, theme.color_secondary); lv_style_set_border_width(&bg, LV_STATE_DEFAULT, BORDER_WIDTH); lv_style_set_border_post(&bg, LV_STATE_DEFAULT, true); lv_style_set_text_font(&bg, LV_STATE_DEFAULT, theme.font_normal); @@ -289,6 +293,7 @@ static void basic_init(void) lv_style_set_outline_opa(&btn, LV_STATE_DEFAULT, LV_OPA_0); lv_style_set_outline_opa(&btn, LV_STATE_FOCUSED, LV_OPA_50); lv_style_set_outline_color(&btn, LV_STATE_DEFAULT, theme.color_primary); + lv_style_set_outline_color(&btn, LV_STATE_EDITED, theme.color_secondary); lv_style_set_transition_time(&btn, LV_STATE_DEFAULT, TRANSITION_TIME); lv_style_set_transition_prop_4(&btn, LV_STATE_DEFAULT, LV_STYLE_BORDER_OPA); lv_style_set_transition_prop_5(&btn, LV_STATE_DEFAULT, LV_STYLE_BG_COLOR); @@ -337,6 +342,7 @@ static void bar_init(void) lv_style_set_bg_color(&bar_bg, LV_STATE_DEFAULT, COLOR_BG_SEC); lv_style_set_value_color(&bar_bg, LV_STATE_DEFAULT, IS_LIGHT ? lv_color_hex(0x31404f) : LV_COLOR_WHITE); lv_style_set_outline_color(&bar_bg, LV_STATE_DEFAULT, theme.color_primary); + lv_style_set_outline_color(&bar_bg, LV_STATE_EDITED, theme.color_secondary); lv_style_set_outline_opa(&bar_bg, LV_STATE_DEFAULT, LV_OPA_TRANSP); lv_style_set_outline_opa(&bar_bg, LV_STATE_FOCUSED, LV_OPA_50); lv_style_set_outline_width(&bar_bg, LV_STATE_DEFAULT, 3); @@ -570,6 +576,7 @@ static void cpicker_init(void) lv_style_set_border_width(&cpicker_indic, LV_STATE_DEFAULT, 2); lv_style_set_border_color(&cpicker_indic, LV_STATE_DEFAULT, LV_COLOR_GRAY); lv_style_set_border_color(&cpicker_indic, LV_STATE_FOCUSED, theme.color_primary); + lv_style_set_border_color(&cpicker_indic, LV_STATE_EDITED, theme.color_secondary); lv_style_set_pad_left(&cpicker_indic, LV_STATE_DEFAULT,LV_DPX(13)); lv_style_set_pad_right(&cpicker_indic, LV_STATE_DEFAULT, LV_DPX(13)); lv_style_set_pad_top(&cpicker_indic, LV_STATE_DEFAULT, LV_DPX(13)); @@ -612,6 +619,7 @@ static void keyboard_init(void) lv_style_set_border_width(&kb_bg, LV_STATE_DEFAULT, LV_DPX(4)); lv_style_set_border_side(&kb_bg, LV_STATE_DEFAULT, LV_BORDER_SIDE_TOP); lv_style_set_border_color(&kb_bg, LV_STATE_DEFAULT, IS_LIGHT ? COLOR_BG_TEXT : LV_COLOR_BLACK); + lv_style_set_border_color(&kb_bg, LV_STATE_EDITED, theme.color_secondary); lv_style_set_pad_left(&kb_bg, LV_STATE_DEFAULT, LV_DPX(10)); lv_style_set_pad_right(&kb_bg, LV_STATE_DEFAULT, LV_DPX(10)); lv_style_set_pad_top(&kb_bg, LV_STATE_DEFAULT, LV_DPX(10)); @@ -641,6 +649,11 @@ static void page_init(void) lv_style_set_pad_right(&sb, LV_STATE_DEFAULT, LV_DPX(7)); lv_style_set_pad_bottom(&sb, LV_STATE_DEFAULT, LV_DPX(7)); +#if LV_USE_ANIMATION + style_init_reset(&edge_flash); + lv_style_set_bg_opa(&edge_flash, LV_STATE_DEFAULT, LV_OPA_COVER); + lv_style_set_bg_color(&edge_flash, LV_STATE_DEFAULT, lv_color_hex3(0x888)); +#endif #endif } @@ -774,10 +787,12 @@ static void tabview_init(void) lv_style_set_pad_top(&tabview_btns, LV_STATE_DEFAULT, LV_DPX(20)); lv_style_set_pad_bottom(&tabview_btns, LV_STATE_DEFAULT, LV_DPX(20)); lv_style_set_text_color(&tabview_btns, LV_STATE_FOCUSED, theme.color_primary); + lv_style_set_text_color(&tabview_btns, LV_STATE_EDITED, theme.color_secondary); style_init_reset(&tabview_indic); lv_style_set_bg_opa(&tabview_indic, LV_STATE_DEFAULT, LV_OPA_COVER); lv_style_set_bg_color(&tabview_indic, LV_STATE_DEFAULT, theme.color_primary); + lv_style_set_bg_color(&tabview_indic, LV_STATE_EDITED, theme.color_secondary); lv_style_set_size(&tabview_indic, LV_STATE_DEFAULT, LV_DPX(5)); lv_style_set_radius(&tabview_indic, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE); @@ -878,7 +893,7 @@ lv_theme_t * lv_theme_material_init(lv_color_t color_primary, lv_color_t color_s table_init(); win_init(); - theme.apply_cb = lv_theme_material_apply; + theme.apply_xcb = lv_theme_material_apply; inited = true; @@ -1095,13 +1110,19 @@ void lv_theme_material_apply(lv_obj_t * obj, lv_theme_style_t name) list = lv_obj_get_style_list(obj, LV_PAGE_PART_BG); lv_style_list_add_style(list, &bg); - lv_obj_clean_style_list(obj, LV_PAGE_PART_SCRL); - list = lv_obj_get_style_list(obj, LV_PAGE_PART_SCRL); + lv_obj_clean_style_list(obj, LV_PAGE_PART_SCROLLABLE); + list = lv_obj_get_style_list(obj, LV_PAGE_PART_SCROLLABLE); lv_style_list_add_style(list, &pad_inner); - lv_obj_clean_style_list(obj, LV_PAGE_PART_SCRLBAR); - list = lv_obj_get_style_list(obj, LV_PAGE_PART_SCRLBAR); + lv_obj_clean_style_list(obj, LV_PAGE_PART_SCROLLBAR); + list = lv_obj_get_style_list(obj, LV_PAGE_PART_SCROLLBAR); lv_style_list_add_style(list, &sb); + +#if LV_USE_ANIMATION + lv_obj_clean_style_list(obj, LV_PAGE_PART_EDGE_FLASH); + list = lv_obj_get_style_list(obj, LV_PAGE_PART_EDGE_FLASH); + lv_style_list_add_style(list, &edge_flash); +#endif break; #endif #if LV_USE_TABVIEW @@ -1128,8 +1149,8 @@ void lv_theme_material_apply(lv_obj_t * obj, lv_theme_style_t name) case LV_THEME_TABVIEW_PAGE: lv_obj_clean_style_list(obj, LV_PAGE_PART_BG); - lv_obj_clean_style_list(obj, LV_PAGE_PART_SCRL); - list = lv_obj_get_style_list(obj, LV_PAGE_PART_SCRL); + lv_obj_clean_style_list(obj, LV_PAGE_PART_SCROLLABLE); + list = lv_obj_get_style_list(obj, LV_PAGE_PART_SCROLLABLE); lv_style_list_add_style(list, &tabview_page_scrl); break; @@ -1145,9 +1166,11 @@ void lv_theme_material_apply(lv_obj_t * obj, lv_theme_style_t name) list = lv_obj_get_style_list(obj, LV_TILEVIEW_PART_SCRLBAR); lv_style_list_add_style(list, &sb); +#if LV_USE_ANIMATION lv_obj_clean_style_list(obj, LV_TILEVIEW_PART_EDGE_FLASH); list = lv_obj_get_style_list(obj, LV_TILEVIEW_PART_EDGE_FLASH); - lv_style_list_add_style(list, &btn); + lv_style_list_add_style(list, &edge_flash); +#endif break; #endif @@ -1265,12 +1288,12 @@ void lv_theme_material_apply(lv_obj_t * obj, lv_theme_style_t name) list = lv_obj_get_style_list(obj, LV_WIN_PART_BG); lv_style_list_add_style(list, &scr); - lv_obj_clean_style_list(obj, LV_WIN_PART_SCRLBAR); - list = lv_obj_get_style_list(obj, LV_WIN_PART_SCRLBAR); + lv_obj_clean_style_list(obj, LV_WIN_PART_SCROLLBAR); + list = lv_obj_get_style_list(obj, LV_WIN_PART_SCROLLBAR); lv_style_list_add_style(list, &sb); - lv_obj_clean_style_list(obj, LV_WIN_PART_CONTENT_SCRL); - list = lv_obj_get_style_list(obj, LV_WIN_PART_CONTENT_SCRL); + lv_obj_clean_style_list(obj, LV_WIN_PART_CONTENT_SCROLLABLE); + list = lv_obj_get_style_list(obj, LV_WIN_PART_CONTENT_SCROLLABLE); lv_style_list_add_style(list, &tabview_page_scrl); lv_obj_clean_style_list(obj, LV_WIN_PART_HEADER); diff --git a/src/lv_themes/lv_theme_mono.c b/src/lv_themes/lv_theme_mono.c index 49c4f49559..fed09f973e 100644 --- a/src/lv_themes/lv_theme_mono.c +++ b/src/lv_themes/lv_theme_mono.c @@ -527,7 +527,7 @@ lv_theme_t * lv_theme_mono_init(lv_color_t color_primary, lv_color_t color_secon table_init(); win_init(); - theme.apply_cb = lv_theme_mono_apply; + theme.apply_xcb = lv_theme_mono_apply; return &theme; } @@ -760,12 +760,12 @@ void lv_theme_mono_apply(lv_obj_t * obj, lv_theme_style_t name) list = lv_obj_get_style_list(obj, LV_PAGE_PART_BG); lv_style_list_add_style(list, &style_bg); - lv_obj_clean_style_list(obj, LV_PAGE_PART_SCRL); - list = lv_obj_get_style_list(obj, LV_PAGE_PART_SCRL); + lv_obj_clean_style_list(obj, LV_PAGE_PART_SCROLLABLE); + list = lv_obj_get_style_list(obj, LV_PAGE_PART_SCROLLABLE); lv_style_list_add_style(list, &style_pad_inner); - lv_obj_clean_style_list(obj, LV_PAGE_PART_SCRLBAR); - list = lv_obj_get_style_list(obj, LV_PAGE_PART_SCRLBAR); + lv_obj_clean_style_list(obj, LV_PAGE_PART_SCROLLBAR); + list = lv_obj_get_style_list(obj, LV_PAGE_PART_SCROLLBAR); lv_style_list_add_style(list, &style_sb); break; #endif @@ -794,8 +794,8 @@ void lv_theme_mono_apply(lv_obj_t * obj, lv_theme_style_t name) case LV_THEME_TABVIEW_PAGE: lv_obj_clean_style_list(obj, LV_PAGE_PART_BG); - lv_obj_clean_style_list(obj, LV_PAGE_PART_SCRL); - list = lv_obj_get_style_list(obj, LV_PAGE_PART_SCRL); + lv_obj_clean_style_list(obj, LV_PAGE_PART_SCROLLABLE); + list = lv_obj_get_style_list(obj, LV_PAGE_PART_SCROLLABLE); lv_style_list_add_style(list, &style_pad_normal); break; @@ -939,12 +939,12 @@ void lv_theme_mono_apply(lv_obj_t * obj, lv_theme_style_t name) list = lv_obj_get_style_list(obj, LV_WIN_PART_BG); lv_style_list_add_style(list, &style_bg); - lv_obj_clean_style_list(obj, LV_WIN_PART_SCRLBAR); - list = lv_obj_get_style_list(obj, LV_WIN_PART_SCRLBAR); + lv_obj_clean_style_list(obj, LV_WIN_PART_SCROLLBAR); + list = lv_obj_get_style_list(obj, LV_WIN_PART_SCROLLBAR); lv_style_list_add_style(list, &style_sb); - lv_obj_clean_style_list(obj, LV_WIN_PART_CONTENT_SCRL); - list = lv_obj_get_style_list(obj, LV_WIN_PART_CONTENT_SCRL); + lv_obj_clean_style_list(obj, LV_WIN_PART_CONTENT_SCROLLABLE); + list = lv_obj_get_style_list(obj, LV_WIN_PART_CONTENT_SCROLLABLE); lv_style_list_add_style(list, &style_bg); lv_obj_clean_style_list(obj, LV_WIN_PART_HEADER); diff --git a/src/lv_themes/lv_theme_template.c b/src/lv_themes/lv_theme_template.c index 441a6ea878..ae85c64a80 100644 --- a/src/lv_themes/lv_theme_template.c +++ b/src/lv_themes/lv_theme_template.c @@ -382,7 +382,7 @@ lv_theme_t * lv_theme_template_init(lv_color_t color_primary, lv_color_t color_s table_init(); win_init(); - theme.apply_cb = lv_theme_material_apply; + theme.apply_xcb = lv_theme_material_apply; return &theme; } diff --git a/src/lv_widgets/lv_btn.c b/src/lv_widgets/lv_btn.c index 4064fe7fe1..bf21476b0f 100644 --- a/src/lv_widgets/lv_btn.c +++ b/src/lv_widgets/lv_btn.c @@ -137,27 +137,26 @@ void lv_btn_set_state(lv_obj_t * btn, lv_btn_state_t state) switch(state) { case LV_BTN_STATE_RELEASED: - lv_obj_clear_state(btn, LV_STATE_PRESSED | LV_STATE_CHECKED | LV_STATE_DISABLED); + lv_obj_clear_state(btn, LV_STATE_PRESSED | LV_STATE_CHECKED); break; case LV_BTN_STATE_PRESSED: - lv_obj_clear_state(btn, LV_STATE_CHECKED | LV_STATE_DISABLED); + lv_obj_clear_state(btn, LV_STATE_CHECKED); lv_obj_add_state(btn, LV_STATE_PRESSED); break; case LV_BTN_STATE_CHECKED_RELEASED: lv_obj_add_state(btn, LV_STATE_CHECKED); - lv_obj_clear_state(btn, LV_STATE_PRESSED | LV_STATE_DISABLED); + lv_obj_clear_state(btn, LV_STATE_PRESSED); break; case LV_BTN_STATE_CHECKED_PRESSED: - lv_obj_add_state(btn, LV_STATE_PRESSED | LV_STATE_CHECKED | LV_STATE_DISABLED); + lv_obj_add_state(btn, LV_STATE_PRESSED | LV_STATE_CHECKED); break; case LV_BTN_STATE_DISABLED: - lv_obj_clear_state(btn, LV_STATE_PRESSED | LV_STATE_CHECKED); lv_obj_add_state(btn, LV_STATE_DISABLED); break; + case LV_BTN_STATE_ACTIVE: + lv_obj_clear_state(btn, LV_STATE_DISABLED); + break; } - - // /*Make the state change happen immediately, without transition*/ - // btn->prev_state = btn->state; } /** @@ -185,26 +184,25 @@ void lv_btn_toggle(lv_obj_t * btn) /** * Get the current state of the button * @param btn pointer to a button object - * @return the state of the button (from lv_btn_state_t enum) + * @return the state of the button (from lv_btn_state_t enum). + * If the button is in disabled state `LV_BTN_STATE_DISABLED` will be ORed to the other button states. */ lv_btn_state_t lv_btn_get_state(const lv_obj_t * btn) { LV_ASSERT_OBJ(btn, LV_OBJX_NAME); - lv_state_t state = lv_obj_get_state(btn, LV_BTN_PART_MAIN); + lv_state_t obj_state = lv_obj_get_state(btn, LV_BTN_PART_MAIN); + lv_btn_state_t btn_state = 0; + if(obj_state & LV_STATE_DISABLED) btn_state = LV_BTN_STATE_DISABLED; - if(state & LV_STATE_DISABLED) { - return LV_BTN_STATE_DISABLED; - } - else if(state & LV_STATE_CHECKED) { - if(state & LV_STATE_PRESSED) return LV_BTN_STATE_CHECKED_PRESSED; - else return LV_BTN_STATE_CHECKED_RELEASED; + if(obj_state & LV_STATE_CHECKED) { + if(obj_state & LV_STATE_PRESSED) return btn_state | LV_BTN_STATE_CHECKED_PRESSED; + else return btn_state | LV_BTN_STATE_CHECKED_RELEASED; } else { - if(state & LV_STATE_PRESSED) return LV_BTN_STATE_PRESSED; - else return LV_BTN_STATE_RELEASED; + if(obj_state & LV_STATE_PRESSED) return btn_state | LV_BTN_STATE_PRESSED; + else return btn_state | LV_BTN_STATE_RELEASED; } - } /** diff --git a/src/lv_widgets/lv_btn.h b/src/lv_widgets/lv_btn.h index 3c3f9ede9d..e8af9d5688 100644 --- a/src/lv_widgets/lv_btn.h +++ b/src/lv_widgets/lv_btn.h @@ -36,12 +36,13 @@ extern "C" { /** Possible states of a button. * It can be used not only by buttons but other button-like objects too*/ enum { + LV_BTN_STATE_ACTIVE, LV_BTN_STATE_RELEASED, LV_BTN_STATE_PRESSED, LV_BTN_STATE_CHECKED_RELEASED, LV_BTN_STATE_CHECKED_PRESSED, - LV_BTN_STATE_DISABLED, - _LV_BTN_STATE_LAST, /* Number of states*/ + _LV_BTN_STATE_LAST = LV_BTN_STATE_CHECKED_PRESSED + 1, /* Number of states*/ + LV_BTN_STATE_DISABLED = 0x80 }; typedef uint8_t lv_btn_state_t; @@ -153,6 +154,7 @@ static inline void lv_btn_set_fit(lv_obj_t * btn, lv_fit_t fit) * Get the current state of the button * @param btn pointer to a button object * @return the state of the button (from lv_btn_state_t enum) + * If the button is in disabled state `LV_BTN_STATE_DISABLED` will be ORed to the other button states. */ lv_btn_state_t lv_btn_get_state(const lv_obj_t * btn); diff --git a/src/lv_widgets/lv_btnmatrix.c b/src/lv_widgets/lv_btnmatrix.c index ef2570b287..0e4a8bd60e 100644 --- a/src/lv_widgets/lv_btnmatrix.c +++ b/src/lv_widgets/lv_btnmatrix.c @@ -275,7 +275,7 @@ void lv_btnmatrix_set_ctrl_map(lv_obj_t * btnm, const lv_btnmatrix_ctrl_t ctrl_m LV_ASSERT_OBJ(btnm, LV_OBJX_NAME); lv_btnmatrix_ext_t * ext = lv_obj_get_ext_attr(btnm); - memcpy(ext->ctrl_bits, ctrl_map, sizeof(lv_btnmatrix_ctrl_t) * ext->btn_cnt); + lv_memcpy(ext->ctrl_bits, ctrl_map, sizeof(lv_btnmatrix_ctrl_t) * ext->btn_cnt); lv_btnmatrix_set_map(btnm, ext->map_p); } @@ -497,7 +497,7 @@ uint16_t lv_btnmatrix_get_focused_btn(const lv_obj_t * btnm) LV_ASSERT_OBJ(btnm, LV_OBJX_NAME); lv_btnmatrix_ext_t * ext = lv_obj_get_ext_attr(btnm); - return ext->btn_id_pr; + return ext->btn_id_focused; } /** @@ -612,7 +612,6 @@ static lv_design_res_t lv_btnmatrix_design(lv_obj_t * btnm, const lv_area_t * cl lv_draw_rect_dsc_t draw_rect_tmp_dsc; lv_draw_label_dsc_t draw_label_tmp_dsc; - /*The state changes without re-caching the styles, disable the use of cache*/ lv_state_t state_ori = btnm->state; btnm->state = LV_STATE_DEFAULT; @@ -689,7 +688,10 @@ static lv_design_res_t lv_btnmatrix_design(lv_obj_t * btnm, const lv_area_t * cl btnm->state = LV_STATE_DEFAULT; if(tgl_state) btnm->state = LV_STATE_CHECKED; if(ext->btn_id_pr == btn_i) btnm->state |= LV_STATE_PRESSED; - if(ext->btn_id_focused == btn_i) btnm->state |= LV_STATE_FOCUSED; + if(ext->btn_id_focused == btn_i) { + btnm->state |= LV_STATE_FOCUSED; + if(state_ori & LV_STATE_EDITED) btnm->state |= LV_STATE_EDITED; + } lv_draw_rect_dsc_init(&draw_rect_tmp_dsc); lv_draw_label_dsc_init(&draw_label_tmp_dsc); @@ -1079,7 +1081,7 @@ static void allocate_btn_areas_and_controls(const lv_obj_t * btnm, const char ** LV_ASSERT_MEM(ext->ctrl_bits); if(ext->button_areas == NULL || ext->ctrl_bits == NULL) btn_cnt = 0; - memset(ext->ctrl_bits, 0, sizeof(lv_btnmatrix_ctrl_t) * btn_cnt); + lv_memset_00(ext->ctrl_bits, sizeof(lv_btnmatrix_ctrl_t) * btn_cnt); ext->btn_cnt = btn_cnt; } diff --git a/src/lv_widgets/lv_canvas.c b/src/lv_widgets/lv_canvas.c index 4da3152a82..12f2b7b40f 100644 --- a/src/lv_widgets/lv_canvas.c +++ b/src/lv_widgets/lv_canvas.c @@ -253,7 +253,7 @@ void lv_canvas_copy_buf(lv_obj_t * canvas, const void * to_copy, lv_coord_t x, l uint8_t * to_copy8 = (uint8_t *)to_copy; lv_coord_t i; for(i = 0; i < h; i++) { - memcpy((void *)&ext->dsc.data[px], to_copy8, w * px_size); + lv_memcpy((void *)&ext->dsc.data[px], to_copy8, w * px_size); px += ext->dsc.header.w * px_size; to_copy8 += w * px_size; } @@ -425,7 +425,7 @@ void lv_canvas_blur_hor(lv_obj_t * canvas, const lv_area_t * area, uint16_t r) lv_color_t c; lv_opa_t opa = LV_OPA_TRANSP; - memcpy(line_buf, &ext->dsc.data[y * line_w], line_w); + lv_memcpy(line_buf, &ext->dsc.data[y * line_w], line_w); for(x = a.x1 - r_back; x <= a.x1 + r_front; x++) { diff --git a/src/lv_widgets/lv_chart.c b/src/lv_widgets/lv_chart.c index 25539ac7b7..924e2e3943 100644 --- a/src/lv_widgets/lv_chart.c +++ b/src/lv_widgets/lv_chart.c @@ -108,9 +108,9 @@ lv_obj_t * lv_chart_create(lv_obj_t * par, const lv_obj_t * copy) ext->point_cnt = LV_CHART_PNUM_DEF; ext->type = LV_CHART_TYPE_LINE; ext->update_mode = LV_CHART_UPDATE_MODE_SHIFT; - memset(&ext->x_axis, 0, sizeof(ext->x_axis)); - memset(&ext->y_axis, 0, sizeof(ext->y_axis)); - memset(&ext->secondary_y_axis, 0, sizeof(ext->secondary_y_axis)); + lv_memset_00(&ext->x_axis, sizeof(ext->x_axis)); + lv_memset_00(&ext->y_axis, sizeof(ext->y_axis)); + lv_memset_00(&ext->secondary_y_axis, sizeof(ext->secondary_y_axis)); ext->x_axis.major_tick_len = LV_CHART_TICK_LENGTH_AUTO; ext->x_axis.minor_tick_len = LV_CHART_TICK_LENGTH_AUTO; ext->y_axis.major_tick_len = LV_CHART_TICK_LENGTH_AUTO; @@ -147,9 +147,9 @@ lv_obj_t * lv_chart_create(lv_obj_t * par, const lv_obj_t * copy) ext->hdiv_cnt = ext_copy->hdiv_cnt; ext->vdiv_cnt = ext_copy->vdiv_cnt; ext->point_cnt = ext_copy->point_cnt; - memcpy(&ext->x_axis, &ext_copy->x_axis, sizeof(lv_chart_axis_cfg_t)); - memcpy(&ext->y_axis, &ext_copy->y_axis, sizeof(lv_chart_axis_cfg_t)); - memcpy(&ext->secondary_y_axis, &ext_copy->secondary_y_axis, sizeof(lv_chart_axis_cfg_t)); + lv_memcpy(&ext->x_axis, &ext_copy->x_axis, sizeof(lv_chart_axis_cfg_t)); + lv_memcpy(&ext->y_axis, &ext_copy->y_axis, sizeof(lv_chart_axis_cfg_t)); + lv_memcpy(&ext->secondary_y_axis, &ext_copy->secondary_y_axis, sizeof(lv_chart_axis_cfg_t)); /*Refresh the style with new signal function*/ lv_obj_refresh_style(chart, LV_STYLE_PROP_ALL); diff --git a/src/lv_widgets/lv_cont.c b/src/lv_widgets/lv_cont.c index 57c7f9600c..73bfde21d3 100644 --- a/src/lv_widgets/lv_cont.c +++ b/src/lv_widgets/lv_cont.c @@ -310,6 +310,7 @@ static lv_style_list_t * lv_cont_get_style(lv_obj_t * cont, uint8_t type) */ static void lv_cont_refr_layout(lv_obj_t * cont) { + if(lv_obj_is_protected(cont, LV_PROTECT_CHILD_CHG)) return; lv_layout_t type = lv_cont_get_layout(cont); /*'cont' has to be at least 1 child*/ @@ -379,7 +380,7 @@ static void lv_cont_layout_col(lv_obj_t * cont) LV_LL_READ_BACK(cont->child_ll, child) { if(lv_obj_get_hidden(child) != false || lv_obj_is_protected(child, LV_PROTECT_POS) != false) continue; lv_style_int_t mtop = lv_obj_get_style_margin_top(child, LV_OBJ_PART_MAIN); - lv_style_int_t mbottom = lv_obj_get_style_margin_top(child, LV_OBJ_PART_MAIN); + lv_style_int_t mbottom = lv_obj_get_style_margin_bottom(child, LV_OBJ_PART_MAIN); lv_style_int_t mleft = lv_obj_get_style_margin_left(child, LV_OBJ_PART_MAIN); lv_obj_align(child, cont, align, hpad_corr + mleft, last_cord + mtop); last_cord += lv_obj_get_height(child) + inner + mtop + mbottom; @@ -682,6 +683,7 @@ static void lv_cont_layout_grid(lv_obj_t * cont) */ static void lv_cont_refr_autofit(lv_obj_t * cont) { + if(lv_obj_is_protected(cont, LV_PROTECT_CHILD_CHG)) return; lv_cont_ext_t * ext = lv_obj_get_ext_attr(cont); if(ext->fit_left == LV_FIT_NONE && ext->fit_right == LV_FIT_NONE && ext->fit_top == LV_FIT_NONE && @@ -715,14 +717,27 @@ static void lv_cont_refr_autofit(lv_obj_t * cont) LV_LL_READ(cont->child_ll, child_i) { if(lv_obj_get_hidden(child_i) != false) continue; - lv_style_int_t mleft = lv_obj_get_style_margin_left(child_i, LV_OBJ_PART_MAIN); - lv_style_int_t mright = lv_obj_get_style_margin_right(child_i, LV_OBJ_PART_MAIN); - lv_style_int_t mtop = lv_obj_get_style_margin_top(child_i, LV_OBJ_PART_MAIN); - lv_style_int_t mbottom = lv_obj_get_style_margin_bottom(child_i, LV_OBJ_PART_MAIN); - tight_area.x1 = LV_MATH_MIN(tight_area.x1, child_i->coords.x1 - mleft); - tight_area.y1 = LV_MATH_MIN(tight_area.y1, child_i->coords.y1 - mtop); - tight_area.x2 = LV_MATH_MAX(tight_area.x2, child_i->coords.x2 + mright); - tight_area.y2 = LV_MATH_MAX(tight_area.y2, child_i->coords.y2 + mbottom); + + if(ext->fit_left != LV_FIT_PARENT) + { + lv_style_int_t mleft = lv_obj_get_style_margin_left(child_i, LV_OBJ_PART_MAIN); + tight_area.x1 = LV_MATH_MIN(tight_area.x1, child_i->coords.x1 - mleft); + } + + if(ext->fit_right != LV_FIT_PARENT) { + lv_style_int_t mright = lv_obj_get_style_margin_right(child_i, LV_OBJ_PART_MAIN); + tight_area.x2 = LV_MATH_MAX(tight_area.x2, child_i->coords.x2 + mright); + } + + if(ext->fit_top != LV_FIT_PARENT) { + lv_style_int_t mtop = lv_obj_get_style_margin_top(child_i, LV_OBJ_PART_MAIN); + tight_area.y1 = LV_MATH_MIN(tight_area.y1, child_i->coords.y1 - mtop); + } + + if(ext->fit_bottom != LV_FIT_PARENT) { + lv_style_int_t mbottom = lv_obj_get_style_margin_bottom(child_i, LV_OBJ_PART_MAIN); + tight_area.y2 = LV_MATH_MAX(tight_area.y2, child_i->coords.y2 + mbottom); + } } tight_area.x1 -= lv_obj_get_style_pad_left(cont, LV_CONT_PART_MAIN); diff --git a/src/lv_widgets/lv_cpicker.c b/src/lv_widgets/lv_cpicker.c index 630014b930..d8a6d6dace 100644 --- a/src/lv_widgets/lv_cpicker.c +++ b/src/lv_widgets/lv_cpicker.c @@ -576,10 +576,11 @@ static void draw_rect_grad(lv_obj_t * cpicker, const lv_area_t * mask) /*scale angle (hue/sat/val) to linear coordinate*/ lv_coord_t xi = (i * grad_w) / 360; + lv_coord_t xi2 = ((i+i_step) * grad_w) / 360; rect_area.x1 = LV_MATH_MIN(grad_area.x1 + xi, grad_area.x1 + grad_w - i_step); rect_area.y1 = grad_area.y1; - rect_area.x2 = rect_area.x1 + i_step; + rect_area.x2 = LV_MATH_MIN(grad_area.x1 + xi2, grad_area.x1 + grad_w - i_step); rect_area.y2 = grad_area.y2; lv_draw_rect(&rect_area, mask, &bg_dsc); diff --git a/src/lv_widgets/lv_dropdown.c b/src/lv_widgets/lv_dropdown.c index a2f4341899..265651e611 100644 --- a/src/lv_widgets/lv_dropdown.c +++ b/src/lv_widgets/lv_dropdown.c @@ -123,6 +123,7 @@ lv_obj_t * lv_dropdown_create(lv_obj_t * par, const lv_obj_t * copy) /*Init the new drop down list drop down list*/ if(copy == NULL) { + lv_obj_set_width(ddlist, LV_DPX(150)); lv_dropdown_set_static_options(ddlist, "Option 1\nOption 2\nOption 3"); lv_theme_apply(ddlist, LV_THEME_DROPDOWN); } @@ -604,8 +605,8 @@ void lv_dropdown_open(lv_obj_t * ddlist) lv_obj_set_signal_cb(lv_page_get_scrl(ext->page), lv_dropdown_page_scrl_signal); lv_style_list_copy(lv_obj_get_style_list(ext->page, LV_PAGE_PART_BG), &ext->style_page); - lv_style_list_copy(lv_obj_get_style_list(ext->page, LV_PAGE_PART_SCRLBAR), &ext->style_scrlbar); - lv_obj_clean_style_list(ext->page, LV_PAGE_PART_SCRL); + lv_style_list_copy(lv_obj_get_style_list(ext->page, LV_PAGE_PART_SCROLLBAR), &ext->style_scrlbar); + lv_obj_clean_style_list(ext->page, LV_PAGE_PART_SCROLLABLE); lv_obj_refresh_style(ext->page, LV_STYLE_PROP_ALL); lv_page_set_scrl_fit(ext->page, LV_FIT_TIGHT); @@ -902,13 +903,20 @@ static lv_res_t lv_dropdown_signal(lv_obj_t * ddlist, lv_signal_t sign, void * p lv_dropdown_close(ddlist); } else if(sign == LV_SIGNAL_RELEASED) { - if(lv_indev_is_dragging(lv_indev_get_act()) == false) { + lv_indev_t * indev = lv_indev_get_act(); + if(lv_indev_is_dragging(indev) == false) { if(ext->page) { lv_dropdown_close(ddlist); if(ext->sel_opt_id_orig != ext->sel_opt_id) { ext->sel_opt_id_orig = ext->sel_opt_id; lv_obj_invalidate(ddlist); } +#if LV_USE_GROUP + lv_indev_type_t indev_type = lv_indev_get_type(indev); + if(indev_type == LV_INDEV_TYPE_ENCODER) { + lv_group_set_editing(lv_obj_get_group(ddlist), false); + } +#endif } else { lv_dropdown_open(ddlist); diff --git a/src/lv_widgets/lv_imgbtn.c b/src/lv_widgets/lv_imgbtn.c index 57dc75a6cc..f86fd72b94 100644 --- a/src/lv_widgets/lv_imgbtn.c +++ b/src/lv_widgets/lv_imgbtn.c @@ -73,10 +73,10 @@ lv_obj_t * lv_imgbtn_create(lv_obj_t * par, const lv_obj_t * copy) if(ancestor_design == NULL) ancestor_design = lv_obj_get_design_cb(imgbtn); /*Initialize the allocated 'ext' */ - memset((void *)ext->img_src_mid, 0, sizeof(ext->img_src_mid)); + lv_memset_00((void *)ext->img_src_mid, sizeof(ext->img_src_mid)); #if LV_IMGBTN_TILED - memset(ext->img_src_left, 0, sizeof(ext->img_src_left)); - memset(ext->img_src_right, 0, sizeof(ext->img_src_right)); + lv_memset_00(ext->img_src_left, sizeof(ext->img_src_left)); + lv_memset_00(ext->img_src_right, sizeof(ext->img_src_right)); #endif ext->tiled = 0; @@ -93,10 +93,10 @@ lv_obj_t * lv_imgbtn_create(lv_obj_t * par, const lv_obj_t * copy) /*Copy an existing image button*/ else { lv_imgbtn_ext_t * copy_ext = lv_obj_get_ext_attr(copy); - memcpy((void *)ext->img_src_mid, copy_ext->img_src_mid, sizeof(ext->img_src_mid)); + lv_memcpy((void *)ext->img_src_mid, copy_ext->img_src_mid, sizeof(ext->img_src_mid)); #if LV_IMGBTN_TILED - memcpy((void *)ext->img_src_left, copy_ext->img_src_left, sizeof(ext->img_src_left)); - memcpy((void *)ext->img_src_right, copy_ext->img_src_right, sizeof(ext->img_src_right)); + lv_memcpy((void *)ext->img_src_left, copy_ext->img_src_left, sizeof(ext->img_src_left)); + lv_memcpy((void *)ext->img_src_right, copy_ext->img_src_right, sizeof(ext->img_src_right)); #endif ext->tiled = copy_ext->tiled; /*Refresh the style with new signal function*/ diff --git a/src/lv_widgets/lv_label.c b/src/lv_widgets/lv_label.c index 7e73f4bc96..c474c9327c 100644 --- a/src/lv_widgets/lv_label.c +++ b/src/lv_widgets/lv_label.c @@ -147,7 +147,7 @@ lv_obj_t * lv_label_create(lv_obj_t * par, const lv_obj_t * copy) ext->text = lv_mem_realloc(ext->text, lv_mem_get_size(copy_ext->text)); LV_ASSERT_MEM(ext->text); if(ext->text == NULL) return NULL; - memcpy(ext->text, copy_ext->text, lv_mem_get_size(copy_ext->text)); + lv_memcpy(ext->text, copy_ext->text, lv_mem_get_size(copy_ext->text)); } if(copy_ext->dot_tmp_alloc && copy_ext->dot.tmp_ptr) { @@ -155,7 +155,7 @@ lv_obj_t * lv_label_create(lv_obj_t * par, const lv_obj_t * copy) lv_label_set_dot_tmp(new_label, ext->dot.tmp_ptr, len); } else { - memcpy(ext->dot.tmp, copy_ext->dot.tmp, sizeof(ext->dot.tmp)); + lv_memcpy(ext->dot.tmp, copy_ext->dot.tmp, sizeof(ext->dot.tmp)); } ext->dot_tmp_alloc = copy_ext->dot_tmp_alloc; ext->dot_end = copy_ext->dot_end; @@ -1460,14 +1460,14 @@ static bool lv_label_set_dot_tmp(lv_obj_t * label, char * data, uint16_t len) LV_LOG_ERROR("Failed to allocate memory for dot_tmp_ptr"); return false; } - memcpy(ext->dot.tmp_ptr, data, len); + lv_memcpy(ext->dot.tmp_ptr, data, len); ext->dot.tmp_ptr[len] = '\0'; ext->dot_tmp_alloc = true; } else { /* Characters can be directly stored in object */ ext->dot_tmp_alloc = false; - memcpy(ext->dot.tmp, data, len); + lv_memcpy(ext->dot.tmp, data, len); } return true; } diff --git a/src/lv_widgets/lv_list.c b/src/lv_widgets/lv_list.c index f09d60d04e..b6f1c98bcd 100644 --- a/src/lv_widgets/lv_list.c +++ b/src/lv_widgets/lv_list.c @@ -138,7 +138,6 @@ void lv_list_clean(lv_obj_t * list) /*====================== * Add/remove functions *=====================*/ - /** * Add a list element to the list * @param list pointer to list object @@ -156,10 +155,15 @@ lv_obj_t * lv_list_add_btn(lv_obj_t * list, const void * img_src, const char * t lv_coord_t pos_x_ori = lv_obj_get_x(list); lv_coord_t pos_y_ori = lv_obj_get_y(list); + lv_obj_t * scrl = lv_page_get_scrl(list); + lv_obj_add_protect(scrl, LV_PROTECT_CHILD_CHG); + /*Create a list element with the image an the text*/ lv_obj_t * btn; btn = lv_btn_create(list, NULL); + lv_obj_add_protect(btn, LV_PROTECT_CHILD_CHG); + /*Save the original signal function because it will be required in `lv_list_btn_signal`*/ if(ancestor_btn_signal == NULL) ancestor_btn_signal = lv_obj_get_signal_cb(btn); @@ -189,6 +193,7 @@ lv_obj_t * lv_list_add_btn(lv_obj_t * list, const void * img_src, const char * t lv_obj_add_protect(btn, LV_PROTECT_PRESS_LOST); lv_obj_set_signal_cb(btn, lv_list_btn_signal); + #if LV_USE_IMG != 0 lv_obj_t * img = NULL; if(img_src) { @@ -225,6 +230,10 @@ lv_obj_t * lv_list_add_btn(lv_obj_t * list, const void * img_src, const char * t } #endif + lv_obj_clear_protect(scrl, LV_PROTECT_CHILD_CHG); + lv_obj_clear_protect(btn, LV_PROTECT_CHILD_CHG); + btn->signal_cb(btn, LV_SIGNAL_CHILD_CHG, NULL); + lv_obj_set_pos(list, pos_x_ori, pos_y_ori); return btn; diff --git a/src/lv_widgets/lv_list.h b/src/lv_widgets/lv_list.h index 2c965044df..0c539cf468 100644 --- a/src/lv_widgets/lv_list.h +++ b/src/lv_widgets/lv_list.h @@ -57,10 +57,10 @@ typedef struct { /** List styles. */ enum { LV_LIST_PART_BG = LV_PAGE_PART_BG, /**< List background style */ - LV_LIST_PART_SCRLBAR = LV_PAGE_PART_SCRLBAR, /**< List scrollbar style. */ + LV_LIST_PART_SCRLBAR = LV_PAGE_PART_SCROLLBAR, /**< List scrollbar style. */ LV_LIST_PART_EDGE_FLASH = LV_PAGE_PART_EDGE_FLASH, /**< List edge flash style. */ _LV_LIST_PART_VIRTUAL_LAST = _LV_PAGE_PART_VIRTUAL_LAST, - LV_LIST_PART_SCRL = LV_PAGE_PART_SCRL, /**< List scrollable area style. */ + LV_LIST_PART_SCRL = LV_PAGE_PART_SCROLLABLE, /**< List scrollable area style. */ _LV_LIST_PART_REAL_LAST = _LV_PAGE_PART_REAL_LAST, }; typedef uint8_t lv_list_style_t; diff --git a/src/lv_widgets/lv_msgbox.c b/src/lv_widgets/lv_msgbox.c index 280a3deacd..aa410464e0 100644 --- a/src/lv_widgets/lv_msgbox.c +++ b/src/lv_widgets/lv_msgbox.c @@ -162,6 +162,13 @@ void lv_msgbox_add_btns(lv_obj_t * mbox, const char * btn_map[]) lv_obj_set_event_cb(ext->btnm, lv_msgbox_btnm_event_cb); if(lv_obj_is_focused(mbox)) { + lv_state_t state = lv_obj_get_state(mbox, LV_MSGBOX_PART_BG); + if(state & LV_STATE_EDITED) { + lv_obj_set_state(ext->btnm, LV_STATE_FOCUSED | LV_STATE_EDITED); + } else { + lv_obj_set_state(ext->btnm, LV_STATE_FOCUSED); + } + lv_btnmatrix_set_focused_btn(ext->btnm, 0); } @@ -312,10 +319,14 @@ uint16_t lv_msgbox_get_active_btn(lv_obj_t * mbox) LV_ASSERT_OBJ(mbox, LV_OBJX_NAME); lv_msgbox_ext_t * ext = lv_obj_get_ext_attr(mbox); - if(ext->btnm) - return lv_btnmatrix_get_active_btn(ext->btnm); - else - return LV_BTNMATRIX_BTN_NONE; + if(ext->btnm == NULL) return LV_BTNMATRIX_BTN_NONE; + + uint16_t id = lv_btnmatrix_get_active_btn(ext->btnm); + if(id == LV_BTNMATRIX_BTN_NONE) { + id = lv_btnmatrix_get_focused_btn(ext->btnm); + } + + return id; } /** @@ -442,7 +453,7 @@ static lv_res_t lv_msgbox_signal(lv_obj_t * mbox, lv_signal_t sign, void * param } else if(sign == LV_SIGNAL_RELEASED) { if(ext->btnm) { - uint32_t btn_id = lv_btnmatrix_get_active_btn(ext->btnm); + uint32_t btn_id = lv_btnmatrix_get_focused_btn(ext->btnm); if(btn_id != LV_BTNMATRIX_BTN_NONE) lv_event_send(mbox, LV_EVENT_VALUE_CHANGED, &btn_id); } } @@ -454,20 +465,33 @@ static lv_res_t lv_msgbox_signal(lv_obj_t * mbox, lv_signal_t sign, void * param /* The button matrix with ENCODER input supposes it's in a group but in this case it isn't * (Only the message box's container) So so some actions here instead*/ - if(sign == LV_SIGNAL_FOCUS) { #if LV_USE_GROUP + if(sign == LV_SIGNAL_FOCUS) { lv_indev_t * indev = lv_indev_get_act(); lv_indev_type_t indev_type = lv_indev_get_type(indev); if(indev_type == LV_INDEV_TYPE_ENCODER) { /*In navigation mode don't select any button but in edit mode select the fist*/ - lv_btnmatrix_ext_t * btnm_ext = lv_obj_get_ext_attr(ext->btnm); - if(lv_group_get_editing(lv_obj_get_group(mbox))) - btnm_ext->btn_id_pr = 0; - else - btnm_ext->btn_id_pr = LV_BTNMATRIX_BTN_NONE; + if(lv_group_get_editing(lv_obj_get_group(mbox))) lv_btnmatrix_set_focused_btn(ext->btnm, 0); + else lv_btnmatrix_set_focused_btn(ext->btnm, LV_BTNMATRIX_BTN_NONE); } -#endif } + + if(ext->btnm && (sign == LV_SIGNAL_FOCUS || sign == LV_SIGNAL_DEFOCUS)) { + lv_state_t state = lv_obj_get_state(mbox, LV_MSGBOX_PART_BG); + if(state & LV_STATE_FOCUSED) { + lv_obj_set_state(ext->btnm, LV_STATE_FOCUSED); + } else { + lv_obj_clear_state(ext->btnm, LV_STATE_FOCUSED); + + } + if(state & LV_STATE_EDITED) { + lv_obj_set_state(ext->btnm, LV_STATE_EDITED); + } else { + lv_obj_clear_state(ext->btnm, LV_STATE_EDITED); + + } + } +#endif } return res; diff --git a/src/lv_widgets/lv_objmask.c b/src/lv_widgets/lv_objmask.c index b9ee162383..bd877dd74f 100644 --- a/src/lv_widgets/lv_objmask.c +++ b/src/lv_widgets/lv_objmask.c @@ -121,7 +121,7 @@ lv_objmask_mask_t * lv_objmask_add_mask(lv_obj_t * objmask, void * param) LV_ASSERT_MEM(m->param); if(m->param == NULL) return NULL; - memcpy(m->param, param, param_size); + lv_memcpy(m->param, param, param_size); lv_obj_invalidate(objmask); diff --git a/src/lv_widgets/lv_page.c b/src/lv_widgets/lv_page.c index deb23ea070..a0562ad284 100644 --- a/src/lv_widgets/lv_page.c +++ b/src/lv_widgets/lv_page.c @@ -54,6 +54,7 @@ static void refr_ext_draw_pad(lv_obj_t * page); #if LV_USE_ANIMATION static void edge_flash_anim(void * page, lv_anim_value_t v); static void edge_flash_anim_end(lv_anim_t * a); + static void get_edge_flash_area(lv_obj_t * page, lv_area_t * area, lv_coord_t state); #endif /********************** @@ -391,7 +392,7 @@ lv_coord_t lv_page_get_width_grid(lv_obj_t * page, uint8_t div, uint8_t span) { lv_coord_t obj_w = lv_page_get_width_fit(page); - lv_style_int_t pinner = lv_obj_get_style_pad_inner(page, LV_PAGE_PART_SCRL); + lv_style_int_t pinner = lv_obj_get_style_pad_inner(page, LV_PAGE_PART_SCROLLABLE); lv_coord_t r = (obj_w - (div - 1) * pinner) / div; @@ -413,7 +414,7 @@ lv_coord_t lv_page_get_width_grid(lv_obj_t * page, uint8_t div, uint8_t span) lv_coord_t lv_page_get_height_grid(lv_obj_t * page, uint8_t div, uint8_t span) { lv_coord_t obj_h = lv_page_get_height_fit(page); - lv_style_int_t pinner = lv_obj_get_style_pad_inner(page, LV_PAGE_PART_SCRL); + lv_style_int_t pinner = lv_obj_get_style_pad_inner(page, LV_PAGE_PART_SCROLLABLE); lv_coord_t r = (obj_h - (div - 1) * pinner) / div; @@ -704,7 +705,7 @@ static lv_design_res_t lv_page_design(lv_obj_t * page, const lv_area_t * clip_ar /*Draw the scrollbars*/ lv_draw_rect_dsc_t rect_dsc; lv_draw_rect_dsc_init(&rect_dsc); - lv_obj_init_draw_rect_dsc(page, LV_PAGE_PART_SCRLBAR, &rect_dsc); + lv_obj_init_draw_rect_dsc(page, LV_PAGE_PART_SCROLLBAR, &rect_dsc); if(ext->scrlbar.hor_draw && (ext->scrlbar.mode & LV_SCRLBAR_MODE_HIDE) == 0) { lv_draw_rect(&sb_hor_area, clip_area, &rect_dsc); } @@ -716,38 +717,13 @@ static lv_design_res_t lv_page_design(lv_obj_t * page, const lv_area_t * clip_ar #if LV_USE_ANIMATION { - lv_coord_t page_w = lv_obj_get_width(page); - lv_coord_t page_h = lv_obj_get_height(page); - lv_area_t flash_area; - - if(ext->edge_flash.top_ip) { - flash_area.x1 = page->coords.x1 - page_w; - flash_area.x2 = page->coords.x2 + page_w; - flash_area.y1 = page->coords.y1 - 3 * page_w + ext->edge_flash.state; - flash_area.y2 = page->coords.y1 + ext->edge_flash.state; - } - else if(ext->edge_flash.bottom_ip) { - flash_area.x1 = page->coords.x1 - page_w; - flash_area.x2 = page->coords.x2 + page_w; - flash_area.y1 = page->coords.y2 - ext->edge_flash.state; - flash_area.y2 = page->coords.y2 + 3 * page_w - ext->edge_flash.state; - } - else if(ext->edge_flash.right_ip) { - flash_area.x1 = page->coords.x2 - ext->edge_flash.state; - flash_area.x2 = page->coords.x2 + 3 * page_h - ext->edge_flash.state; - flash_area.y1 = page->coords.y1 - page_h; - flash_area.y2 = page->coords.y2 + page_h; - } - else if(ext->edge_flash.left_ip) { - flash_area.x1 = page->coords.x1 - 3 * page_h + ext->edge_flash.state; - flash_area.x2 = page->coords.x1 + ext->edge_flash.state; - flash_area.y1 = page->coords.y1 - page_h; - flash_area.y2 = page->coords.y2 + page_h; - } if(ext->edge_flash.left_ip || ext->edge_flash.right_ip || ext->edge_flash.top_ip || ext->edge_flash.bottom_ip) { + lv_area_t flash_area; + get_edge_flash_area(page, &flash_area, ext->edge_flash.state); + lv_draw_rect_dsc_t edge_draw_dsc; lv_draw_rect_dsc_init(&edge_draw_dsc); lv_obj_init_draw_rect_dsc(page, LV_PAGE_PART_EDGE_FLASH, &edge_draw_dsc); @@ -781,7 +757,7 @@ static lv_res_t lv_page_signal(lv_obj_t * page, lv_signal_t sign, void * param) } else if(sign == LV_SIGNAL_GET_STATE_DSC) { lv_get_state_info_t * info = param; - if(info->part == LV_PAGE_PART_SCRL) info->result = lv_obj_get_state(lv_page_get_scrl(page), LV_CONT_PART_MAIN); + if(info->part == LV_PAGE_PART_SCROLLABLE) info->result = lv_obj_get_state(lv_page_get_scrl(page), LV_CONT_PART_MAIN); else info->result = lv_obj_get_state(page, info->part); return LV_RES_OK; } @@ -802,7 +778,7 @@ static lv_res_t lv_page_signal(lv_obj_t * page, lv_signal_t sign, void * param) } } - lv_obj_clean_style_list(page, LV_PAGE_PART_SCRLBAR); + lv_obj_clean_style_list(page, LV_PAGE_PART_SCROLLBAR); #if LV_USE_ANIMATION lv_obj_clean_style_list(page, LV_PAGE_PART_EDGE_FLASH); #endif @@ -853,7 +829,7 @@ static lv_res_t lv_page_signal(lv_obj_t * page, lv_signal_t sign, void * param) } } else if(sign == LV_SIGNAL_STYLE_CHG) { - lv_style_int_t sb_width = lv_obj_get_style_size(page, LV_PAGE_PART_SCRLBAR); + lv_style_int_t sb_width = lv_obj_get_style_size(page, LV_PAGE_PART_SCROLLBAR); lv_area_set_height(&ext->scrlbar.hor_area, sb_width); lv_area_set_width(&ext->scrlbar.ver_area, sb_width); @@ -1091,10 +1067,10 @@ static lv_style_list_t * lv_page_get_style(lv_obj_t * page, uint8_t part) case LV_PAGE_PART_BG: style_dsc_p = &page->style_list; break; - case LV_PAGE_PART_SCRL: + case LV_PAGE_PART_SCROLLABLE: style_dsc_p = lv_obj_get_style_list(ext->scrl, LV_CONT_PART_MAIN); break; - case LV_PAGE_PART_SCRLBAR: + case LV_PAGE_PART_SCROLLBAR: style_dsc_p = &ext->scrlbar.style; break; #if LV_USE_ANIMATION @@ -1190,9 +1166,9 @@ static void scrlbar_refresh(lv_obj_t * page) lv_coord_t obj_w = lv_obj_get_width(page); lv_coord_t obj_h = lv_obj_get_height(page); - lv_style_int_t sb_width = lv_obj_get_style_size(page, LV_PAGE_PART_SCRLBAR); - lv_style_int_t sb_right = lv_obj_get_style_pad_right(page, LV_PAGE_PART_SCRLBAR); - lv_style_int_t sb_bottom = lv_obj_get_style_pad_bottom(page, LV_PAGE_PART_SCRLBAR); + lv_style_int_t sb_width = lv_obj_get_style_size(page, LV_PAGE_PART_SCROLLBAR); + lv_style_int_t sb_right = lv_obj_get_style_pad_right(page, LV_PAGE_PART_SCROLLBAR); + lv_style_int_t sb_bottom = lv_obj_get_style_pad_bottom(page, LV_PAGE_PART_SCROLLBAR); lv_style_int_t bg_left = lv_obj_get_style_pad_left(page, LV_PAGE_PART_BG); lv_style_int_t bg_right = lv_obj_get_style_pad_right(page, LV_PAGE_PART_BG); @@ -1314,8 +1290,8 @@ static void scrlbar_refresh(lv_obj_t * page) static void refr_ext_draw_pad(lv_obj_t * page) { - lv_style_int_t sb_bottom = lv_obj_get_style_pad_bottom(page, LV_PAGE_PART_SCRLBAR); - lv_style_int_t sb_right = lv_obj_get_style_pad_right(page, LV_PAGE_PART_SCRLBAR); + lv_style_int_t sb_bottom = lv_obj_get_style_pad_bottom(page, LV_PAGE_PART_SCROLLBAR); + lv_style_int_t sb_right = lv_obj_get_style_pad_right(page, LV_PAGE_PART_SCROLLBAR); /*Ensure ext. size for the scrollbars if they are out of the page*/ if(page->ext_draw_pad < (-sb_right)) page->ext_draw_pad = -sb_right; @@ -1327,18 +1303,60 @@ static void edge_flash_anim(void * page, lv_anim_value_t v) { lv_page_ext_t * ext = lv_obj_get_ext_attr(page); ext->edge_flash.state = v; - lv_obj_invalidate(page); + + lv_area_t flash_area; + get_edge_flash_area(page, &flash_area, LV_PAGE_END_FLASH_SIZE); + lv_obj_invalidate_area(page, &flash_area); } static void edge_flash_anim_end(lv_anim_t * a) { + lv_area_t flash_area; + get_edge_flash_area(a->var, &flash_area, LV_PAGE_END_FLASH_SIZE); + lv_obj_invalidate_area(a->var, &flash_area); + lv_page_ext_t * ext = lv_obj_get_ext_attr(a->var); ext->edge_flash.top_ip = 0; ext->edge_flash.bottom_ip = 0; ext->edge_flash.left_ip = 0; ext->edge_flash.right_ip = 0; - lv_obj_invalidate(a->var); + } + +static void get_edge_flash_area(lv_obj_t * page, lv_area_t * flash_area, lv_coord_t state) +{ + lv_coord_t page_w = lv_obj_get_width(page); + lv_coord_t page_h = lv_obj_get_height(page); + lv_page_ext_t * ext = lv_obj_get_ext_attr(page); + + if(ext->edge_flash.top_ip) { + flash_area->x1 = page->coords.x1 - page_w; + flash_area->x2 = page->coords.x2 + page_w; + flash_area->y1 = page->coords.y1 - 3 * page_w + state; + flash_area->y2 = page->coords.y1 + state; + } + else if(ext->edge_flash.bottom_ip) { + flash_area->x1 = page->coords.x1 - page_w; + flash_area->x2 = page->coords.x2 + page_w; + flash_area->y1 = page->coords.y2 - state; + flash_area->y2 = page->coords.y2 + 3 * page_w - state; + } + else if(ext->edge_flash.right_ip) { + flash_area->x1 = page->coords.x2 - state; + flash_area->x2 = page->coords.x2 + 3 * page_h - state; + flash_area->y1 = page->coords.y1 - page_h; + flash_area->y2 = page->coords.y2 + page_h; + } + else if(ext->edge_flash.left_ip) { + flash_area->x1 = page->coords.x1 - 3 * page_h + state; + flash_area->x2 = page->coords.x1 + state; + flash_area->y1 = page->coords.y1 - page_h; + flash_area->y2 = page->coords.y2 + page_h; + } else { + lv_area_set(flash_area, 0, 0, -1, -1); + } +} + #endif #endif diff --git a/src/lv_widgets/lv_page.h b/src/lv_widgets/lv_page.h index 94f0086430..367f3c6b07 100644 --- a/src/lv_widgets/lv_page.h +++ b/src/lv_widgets/lv_page.h @@ -85,11 +85,11 @@ typedef struct { enum { LV_PAGE_PART_BG = LV_CONT_PART_MAIN, - LV_PAGE_PART_SCRLBAR = _LV_OBJ_PART_VIRTUAL_LAST, + LV_PAGE_PART_SCROLLBAR = _LV_OBJ_PART_VIRTUAL_LAST, LV_PAGE_PART_EDGE_FLASH, _LV_PAGE_PART_VIRTUAL_LAST, - LV_PAGE_PART_SCRL = _LV_OBJ_PART_REAL_LAST, + LV_PAGE_PART_SCROLLABLE = _LV_OBJ_PART_REAL_LAST, _LV_PAGE_PART_REAL_LAST, }; typedef uint8_t lv_part_style_t; diff --git a/src/lv_widgets/lv_roller.c b/src/lv_widgets/lv_roller.c index 910329d9e3..495dd31aa3 100644 --- a/src/lv_widgets/lv_roller.c +++ b/src/lv_widgets/lv_roller.c @@ -111,7 +111,7 @@ lv_obj_t * lv_roller_create(lv_obj_t * par, const lv_obj_t * copy) lv_obj_set_signal_cb(scrl, lv_roller_scrl_signal); - lv_obj_clean_style_list(roller, LV_PAGE_PART_SCRL); /*Use a transparent scrollable*/ + lv_obj_clean_style_list(roller, LV_PAGE_PART_SCROLLABLE); /*Use a transparent scrollable*/ lv_theme_apply(roller, LV_THEME_ROLLER); refr_height(roller); @@ -479,8 +479,10 @@ static lv_res_t lv_roller_signal(lv_obj_t * roller, lv_signal_t sign, void * par } /* Include the ancient signal function */ - res = ancestor_signal(roller, sign, param); - if(res != LV_RES_OK) return res; + if(sign != LV_SIGNAL_CONTROL) { /*Don't let the page to scroll on keys*/ + res = ancestor_signal(roller, sign, param); + if(res != LV_RES_OK) return res; + } if(sign == LV_SIGNAL_GET_TYPE) return lv_obj_handle_get_type_signal(param, LV_OBJX_NAME); diff --git a/src/lv_widgets/lv_slider.h b/src/lv_widgets/lv_slider.h index de66430cd7..9012bb4a5d 100644 --- a/src/lv_widgets/lv_slider.h +++ b/src/lv_widgets/lv_slider.h @@ -108,10 +108,9 @@ static inline void lv_slider_set_range(lv_obj_t * slider, int16_t min, int16_t m } /** - * Make the slider symmetric to zero. The indicator will grow from zero instead of the minimum - * position. - * @param slider pointer to a slider object - * @param en true: enable disable symmetric behavior; false: disable + * Set the animation time of the slider + * @param slider pointer to a bar object + * @param anim_time the animation time in milliseconds. */ static inline void lv_slider_set_anim_time(lv_obj_t * slider, uint16_t anim_time) { @@ -119,9 +118,10 @@ static inline void lv_slider_set_anim_time(lv_obj_t * slider, uint16_t anim_time } /** - * Set the animation time of the slider - * @param slider pointer to a bar object - * @param anim_time the animation time in milliseconds. + * Make the slider symmetric to zero. The indicator will grow from zero instead of the minimum + * position. + * @param slider pointer to a slider object + * @param en true: enable disable symmetric behavior; false: disable */ static inline void lv_slider_set_type(lv_obj_t * slider, lv_slider_type_t type) { diff --git a/src/lv_widgets/lv_spinbox.c b/src/lv_widgets/lv_spinbox.c index 671d469636..c871ee567a 100644 --- a/src/lv_widgets/lv_spinbox.c +++ b/src/lv_widgets/lv_spinbox.c @@ -514,7 +514,7 @@ static void lv_spinbox_updatevalue(lv_obj_t * spinbox) lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox); char buf[LV_SPINBOX_MAX_DIGIT_COUNT + 8]; - memset(buf, 0, sizeof(buf)); + lv_memset_00(buf, sizeof(buf)); char * buf_p = buf; uint8_t cur_shift_left = 0; diff --git a/src/lv_widgets/lv_table.c b/src/lv_widgets/lv_table.c index 42d0436957..4a3205bb17 100644 --- a/src/lv_widgets/lv_table.c +++ b/src/lv_widgets/lv_table.c @@ -79,6 +79,7 @@ lv_obj_t * lv_table_create(lv_obj_t * par, const lv_obj_t * copy) ext->cell_data = NULL; ext->col_cnt = 0; ext->row_cnt = 0; + ext->row_h = NULL; ext->cell_types = 1; uint16_t i; @@ -199,8 +200,12 @@ void lv_table_set_row_cnt(lv_obj_t * table, uint16_t row_cnt) if(old_row_cnt < row_cnt) { uint16_t old_cell_cnt = old_row_cnt * ext->col_cnt; uint32_t new_cell_cnt = ext->col_cnt * ext->row_cnt; - memset(&ext->cell_data[old_cell_cnt], 0, (new_cell_cnt - old_cell_cnt) * sizeof(ext->cell_data[0])); + lv_memset_00(&ext->cell_data[old_cell_cnt], (new_cell_cnt - old_cell_cnt) * sizeof(ext->cell_data[0])); } + + ext->row_h = lv_mem_realloc(ext->row_h, ext->row_cnt * sizeof(ext->row_h[0])); + LV_ASSERT_MEM(ext->cell_data); + if(ext->cell_data == NULL) return; } else { lv_mem_free(ext->cell_data); @@ -237,7 +242,7 @@ void lv_table_set_col_cnt(lv_obj_t * table, uint16_t col_cnt) if(old_col_cnt < col_cnt) { uint16_t old_cell_cnt = old_col_cnt * ext->row_cnt; uint32_t new_cell_cnt = ext->col_cnt * ext->row_cnt; - memset(&ext->cell_data[old_cell_cnt], 0, (new_cell_cnt - old_cell_cnt) * sizeof(ext->cell_data[0])); + lv_memset_00(&ext->cell_data[old_cell_cnt], (new_cell_cnt - old_cell_cnt) * sizeof(ext->cell_data[0])); } } @@ -652,29 +657,9 @@ lv_res_t lv_table_get_pressed_cell(lv_obj_t * table, uint16_t * row, uint16_t * *row = 0; tmp = 0; - lv_style_int_t cell_left[LV_TABLE_CELL_STYLE_CNT]; - lv_style_int_t cell_right[LV_TABLE_CELL_STYLE_CNT]; - lv_style_int_t cell_top[LV_TABLE_CELL_STYLE_CNT]; - lv_style_int_t cell_bottom[LV_TABLE_CELL_STYLE_CNT]; - lv_style_int_t letter_space[LV_TABLE_CELL_STYLE_CNT]; - lv_style_int_t line_space[LV_TABLE_CELL_STYLE_CNT]; - const lv_font_t * font[LV_TABLE_CELL_STYLE_CNT]; - - uint16_t i; - for(i = 0; i < LV_TABLE_CELL_STYLE_CNT; i++) { - if((ext->cell_types & (1 << i)) == 0) continue; /*Skip unused cell types*/ - cell_left[i] = lv_obj_get_style_pad_left(table, LV_TABLE_PART_CELL1 + i); - cell_right[i] = lv_obj_get_style_pad_right(table, LV_TABLE_PART_CELL1 + i); - cell_top[i] = lv_obj_get_style_pad_top(table, LV_TABLE_PART_CELL1 + i); - cell_bottom[i] = lv_obj_get_style_pad_bottom(table, LV_TABLE_PART_CELL1 + i); - letter_space[i] = lv_obj_get_style_text_letter_space(table, LV_TABLE_PART_CELL1 + i); - line_space[i] = lv_obj_get_style_text_line_space(table, LV_TABLE_PART_CELL1 + i); - font[i] = lv_obj_get_style_text_font(table, LV_TABLE_PART_CELL1 + i); - } for(*row = 0; *row < ext->row_cnt; (*row)++) { - tmp += get_row_height(table, *row, font, letter_space, line_space, - cell_left, cell_right, cell_top, cell_bottom); + tmp += ext->row_h[*row]; if(y < tmp) break; } } @@ -726,9 +711,6 @@ static lv_design_res_t lv_table_design(lv_obj_t * table, const lv_area_t * clip_ lv_style_int_t cell_right[LV_TABLE_CELL_STYLE_CNT]; lv_style_int_t cell_top[LV_TABLE_CELL_STYLE_CNT]; lv_style_int_t cell_bottom[LV_TABLE_CELL_STYLE_CNT]; - lv_style_int_t letter_space[LV_TABLE_CELL_STYLE_CNT]; - lv_style_int_t line_space[LV_TABLE_CELL_STYLE_CNT]; - const lv_font_t * font[LV_TABLE_CELL_STYLE_CNT]; uint16_t i; for(i = 0; i < LV_TABLE_CELL_STYLE_CNT; i++) { @@ -746,9 +728,6 @@ static lv_design_res_t lv_table_design(lv_obj_t * table, const lv_area_t * clip_ cell_right[i] = lv_obj_get_style_pad_right(table, LV_TABLE_PART_CELL1 + i); cell_top[i] = lv_obj_get_style_pad_top(table, LV_TABLE_PART_CELL1 + i); cell_bottom[i] = lv_obj_get_style_pad_bottom(table, LV_TABLE_PART_CELL1 + i); - letter_space[i] = label_dsc[i].letter_space; - line_space[i] = label_dsc[i].line_space; - font[i] = label_dsc[i].font; } uint16_t col; @@ -757,8 +736,7 @@ static lv_design_res_t lv_table_design(lv_obj_t * table, const lv_area_t * clip_ cell_area.y2 = table->coords.y1 + bg_top - 1; for(row = 0; row < ext->row_cnt; row++) { - lv_coord_t h_row = get_row_height(table, row, font, letter_space, line_space, - cell_left, cell_right, cell_top, cell_bottom); + lv_coord_t h_row = ext->row_h[row]; cell_area.y1 = cell_area.y2 + 1; cell_area.y2 = cell_area.y1 + h_row - 1; @@ -935,7 +913,8 @@ static lv_res_t lv_table_signal(lv_obj_t * table, lv_signal_t sign, void * param } } - if(ext->cell_data != NULL) lv_mem_free(ext->cell_data); + if(ext->cell_data) lv_mem_free(ext->cell_data); + if(ext->row_h) lv_mem_free(ext->row_h); for(i = 0; i < LV_TABLE_CELL_STYLE_CNT; i++) { lv_obj_clean_style_list(table, LV_TABLE_PART_CELL1 + i); @@ -1018,8 +997,9 @@ static void refr_size(lv_obj_t * table) for(i = 0; i < ext->row_cnt; i++) { - h += get_row_height(table, i, font, letter_space, line_space, + ext->row_h[i] = get_row_height(table, i, font, letter_space, line_space, cell_left, cell_right, cell_top, cell_bottom); + h += ext->row_h[i]; } lv_style_int_t bg_top = lv_obj_get_style_pad_top(table, LV_TABLE_PART_BG); diff --git a/src/lv_widgets/lv_table.h b/src/lv_widgets/lv_table.h index defb8a6fba..58995d60f3 100644 --- a/src/lv_widgets/lv_table.h +++ b/src/lv_widgets/lv_table.h @@ -58,6 +58,7 @@ typedef struct { uint16_t col_cnt; uint16_t row_cnt; char ** cell_data; + lv_coord_t * row_h; lv_style_list_t cell_style[LV_TABLE_CELL_STYLE_CNT]; lv_coord_t col_w[LV_TABLE_COL_MAX]; uint8_t cell_types : 4; /*Keep track which cell types exists to avoid dealing with unused ones*/ diff --git a/src/lv_widgets/lv_tabview.c b/src/lv_widgets/lv_tabview.c index e506017d3b..3dfd7c2b8e 100644 --- a/src/lv_widgets/lv_tabview.c +++ b/src/lv_widgets/lv_tabview.c @@ -176,10 +176,10 @@ lv_obj_t * lv_tabview_create(lv_obj_t * par, const lv_obj_t * copy) for(i = 0; i < copy_ext->tab_cnt; i++) { lv_obj_t * new_tab = lv_tabview_add_tab(tabview, copy_ext->tab_name_ptr[i]); lv_obj_t * copy_tab = lv_tabview_get_tab(copy, i); - lv_style_list_copy(lv_obj_get_style_list(new_tab, LV_PAGE_PART_SCRL), lv_obj_get_style_list(copy_tab, - LV_PAGE_PART_SCRL)); - lv_style_list_copy(lv_obj_get_style_list(new_tab, LV_PAGE_PART_SCRLBAR), lv_obj_get_style_list(copy_tab, - LV_PAGE_PART_SCRLBAR)); + lv_style_list_copy(lv_obj_get_style_list(new_tab, LV_PAGE_PART_SCROLLABLE), lv_obj_get_style_list(copy_tab, + LV_PAGE_PART_SCROLLABLE)); + lv_style_list_copy(lv_obj_get_style_list(new_tab, LV_PAGE_PART_SCROLLBAR), lv_obj_get_style_list(copy_tab, + LV_PAGE_PART_SCROLLBAR)); lv_obj_refresh_style(new_tab, LV_STYLE_PROP_ALL); } @@ -340,8 +340,8 @@ void lv_tabview_set_tab_act(lv_obj_t * tabview, uint16_t id, lv_anim_enable_t an } lv_coord_t cont_x; - lv_style_int_t scrl_inner = lv_obj_get_style_pad_inner(ext->content, LV_PAGE_PART_SCRL); - lv_style_int_t scrl_left = lv_obj_get_style_pad_left(ext->content, LV_PAGE_PART_SCRL); + lv_style_int_t scrl_inner = lv_obj_get_style_pad_inner(ext->content, LV_PAGE_PART_SCROLLABLE); + lv_style_int_t scrl_left = lv_obj_get_style_pad_left(ext->content, LV_PAGE_PART_SCROLLABLE); switch(ext->btns_pos) { default: /*default case is prevented in lv_tabview_set_btns_pos(), but here for safety*/ @@ -599,7 +599,7 @@ static lv_res_t lv_tabview_signal(lv_obj_t * tabview, lv_signal_t sign, void * p if(info->part == LV_TABVIEW_PART_TAB_BG) info->result = lv_obj_get_state(ext->btns, LV_BTNMATRIX_PART_BG); else if(info->part == LV_TABVIEW_PART_TAB_BTN) info->result = lv_obj_get_state(ext->btns, LV_BTNMATRIX_PART_BTN); else if(info->part == LV_TABVIEW_PART_INDIC) info->result = lv_obj_get_state(ext->indic, LV_OBJ_PART_MAIN); - else if(info->part == LV_TABVIEW_PART_BG_SCRL) info->result = lv_obj_get_state(ext->content, LV_PAGE_PART_SCRL); + else if(info->part == LV_TABVIEW_PART_BG_SCRL) info->result = lv_obj_get_state(ext->content, LV_PAGE_PART_SCROLLABLE); return LV_RES_OK; } @@ -652,17 +652,34 @@ static lv_res_t lv_tabview_signal(lv_obj_t * tabview, lv_signal_t sign, void * p /* The button matrix is not in a group (the tab view is in it) but it should handle the * group signals. So propagate the related signals to the button matrix manually*/ - if(ext->btns) { - ext->btns->signal_cb(ext->btns, sign, param); + ext->btns->signal_cb(ext->btns, sign, param); + + /*Make the active tab's button focused*/ + if(sign == LV_SIGNAL_FOCUS) { + lv_btnmatrix_set_focused_btn(ext->btns, ext->tab_cur); + } + + if(sign == LV_SIGNAL_FOCUS || sign == LV_SIGNAL_DEFOCUS) { + lv_state_t state = lv_obj_get_state(tabview, LV_TABVIEW_PART_BG); + if(state & LV_STATE_FOCUSED) { + lv_obj_set_state(ext->btns, LV_STATE_FOCUSED); + lv_obj_set_state(ext->indic, LV_STATE_FOCUSED); + } else { + lv_obj_clear_state(ext->btns, LV_STATE_FOCUSED); + lv_obj_clear_state(ext->indic, LV_STATE_FOCUSED); + + } + if(state & LV_STATE_EDITED) { + lv_obj_set_state(ext->btns, LV_STATE_EDITED); + lv_obj_set_state(ext->indic, LV_STATE_EDITED); + } else { + lv_obj_clear_state(ext->btns, LV_STATE_EDITED); + lv_obj_clear_state(ext->indic, LV_STATE_EDITED); - /*Make the active tab's button focused*/ - if(sign == LV_SIGNAL_FOCUS) { - lv_btnmatrix_set_focused_btn(ext->btns, ext->tab_cur); } } } - return res; } @@ -751,7 +768,7 @@ static lv_style_list_t * lv_tabview_get_style(lv_obj_t * tabview, uint8_t part) style_dsc_p = &tabview->style_list; break; case LV_TABVIEW_PART_BG_SCRL: - style_dsc_p = lv_obj_get_style_list(ext->content, LV_PAGE_PART_SCRL); + style_dsc_p = lv_obj_get_style_list(ext->content, LV_PAGE_PART_SCROLLABLE); break; case LV_TABVIEW_PART_TAB_BG: style_dsc_p = lv_obj_get_style_list(ext->btns, LV_BTNMATRIX_PART_BG); @@ -782,6 +799,8 @@ static void tab_btnm_event_cb(lv_obj_t * tab_btnm, lv_event_t event) uint16_t btn_id = lv_btnmatrix_get_active_btn(tab_btnm); if(btn_id == LV_BTNMATRIX_BTN_NONE) return; + if(lv_btnmatrix_get_btn_ctrl(tab_btnm, btn_id, LV_BTNMATRIX_CTRL_DISABLED)) return; + lv_btnmatrix_clear_btn_ctrl_all(tab_btnm, LV_BTNMATRIX_CTRL_CHECK_STATE); lv_btnmatrix_set_btn_ctrl(tab_btnm, btn_id, LV_BTNMATRIX_CTRL_CHECK_STATE); @@ -794,6 +813,12 @@ static void tab_btnm_event_cb(lv_obj_t * tab_btnm, lv_event_t event) lv_res_t res = LV_RES_OK; if(id_prev != id_new) res = lv_event_send(tabview, LV_EVENT_VALUE_CHANGED, &id_new); +#if LV_USE_GROUP + if(lv_indev_get_type(lv_indev_get_act()) == LV_INDEV_TYPE_ENCODER) { + lv_group_set_editing(lv_obj_get_group(tabview), false); + } +#endif + if(res != LV_RES_OK) return; } diff --git a/src/lv_widgets/lv_textarea.c b/src/lv_widgets/lv_textarea.c index 3099e0fc20..4193c97a7c 100644 --- a/src/lv_widgets/lv_textarea.c +++ b/src/lv_widgets/lv_textarea.c @@ -150,7 +150,7 @@ lv_obj_t * lv_textarea_create(lv_obj_t * par, const lv_obj_t * copy) lv_obj_set_size(ta, LV_TEXTAREA_DEF_WIDTH, LV_TEXTAREA_DEF_HEIGHT); lv_textarea_set_sb_mode(ta, LV_SCRLBAR_MODE_DRAG); - lv_obj_reset_style_list(ta, LV_PAGE_PART_SCRL); + lv_obj_reset_style_list(ta, LV_PAGE_PART_SCROLLABLE); lv_theme_apply(ta, LV_THEME_TEXTAREA); } @@ -181,7 +181,7 @@ lv_obj_t * lv_textarea_create(lv_obj_t * par, const lv_obj_t * copy) LV_ASSERT_MEM(ext->pwd_tmp); if(ext->pwd_tmp == NULL) return NULL; - memcpy(ext->pwd_tmp, copy_ext->pwd_tmp, len); + lv_memcpy(ext->pwd_tmp, copy_ext->pwd_tmp, len); } if(copy_ext->one_line) lv_textarea_set_one_line(ta, true); @@ -1351,7 +1351,7 @@ static lv_design_res_t lv_textarea_scrollable_design(lv_obj_t * scrl, const lv_a lv_draw_rect(&cur_area, clip_area, &cur_dsc); char letter_buf[8] = {0}; - memcpy(letter_buf, &txt[ext->cursor.txt_byte_pos], lv_txt_encoded_size(&txt[ext->cursor.txt_byte_pos])); + lv_memcpy(letter_buf, &txt[ext->cursor.txt_byte_pos], lv_txt_encoded_size(&txt[ext->cursor.txt_byte_pos])); if(cur_dsc.bg_opa == LV_OPA_COVER) { lv_style_int_t left = lv_obj_get_style_pad_left(ta, LV_TEXTAREA_PART_CURSOR); @@ -1637,7 +1637,7 @@ static void pwd_char_hider(lv_obj_t * ta) char * txt_tmp = lv_mem_buf_get(enc_len * bullet_len + 1); uint16_t i; for(i = 0; i < enc_len; i++) { - memcpy(&txt_tmp[i * bullet_len], bullet, bullet_len); + lv_memcpy(&txt_tmp[i * bullet_len], bullet, bullet_len); } txt_tmp[i * bullet_len] = '\0'; diff --git a/src/lv_widgets/lv_textarea.h b/src/lv_widgets/lv_textarea.h index 4b14c6f75b..47ff097df8 100644 --- a/src/lv_widgets/lv_textarea.h +++ b/src/lv_widgets/lv_textarea.h @@ -78,7 +78,7 @@ typedef struct { /** Possible text areas tyles. */ enum { LV_TEXTAREA_PART_BG = LV_PAGE_PART_BG, /**< Text area background style */ - LV_TEXTAREA_PART_SCRLBAR = LV_PAGE_PART_SCRLBAR, /**< Scrollbar style */ + LV_TEXTAREA_PART_SCRLBAR = LV_PAGE_PART_SCROLLBAR, /**< Scrollbar style */ LV_TEXTAREA_PART_EDGE_FLASH = LV_PAGE_PART_EDGE_FLASH, /**< Edge flash style */ LV_TEXTAREA_PART_CURSOR = _LV_PAGE_PART_VIRTUAL_LAST, /**< Cursor style */ LV_TEXTAREA_PART_PLACEHOLDER, /**< Placeholder style */ diff --git a/src/lv_widgets/lv_tileview.c b/src/lv_widgets/lv_tileview.c index 0a8da77db7..56792049f6 100644 --- a/src/lv_widgets/lv_tileview.c +++ b/src/lv_widgets/lv_tileview.c @@ -118,7 +118,7 @@ lv_obj_t * lv_tileview_create(lv_obj_t * par, const lv_obj_t * copy) lv_page_set_scrl_fit(new_tileview, LV_FIT_TIGHT); - lv_obj_reset_style_list(new_tileview, LV_PAGE_PART_SCRL); + lv_obj_reset_style_list(new_tileview, LV_PAGE_PART_SCROLLABLE); lv_theme_apply(new_tileview, LV_THEME_TILEVIEW); } /*Copy an existing tileview*/ diff --git a/src/lv_widgets/lv_tileview.h b/src/lv_widgets/lv_tileview.h index 5b0b3e619b..78d2370bc6 100644 --- a/src/lv_widgets/lv_tileview.h +++ b/src/lv_widgets/lv_tileview.h @@ -46,7 +46,7 @@ typedef struct { /*Parts of the Tileview*/ enum { LV_TILEVIEW_PART_BG = LV_PAGE_PART_BG, - LV_TILEVIEW_PART_SCRLBAR = LV_PAGE_PART_SCRLBAR, + LV_TILEVIEW_PART_SCRLBAR = LV_PAGE_PART_SCROLLBAR, LV_TILEVIEW_PART_EDGE_FLASH = LV_PAGE_PART_EDGE_FLASH, _LV_TILEVIEW_PART_VIRTUAL_LAST = _LV_PAGE_PART_VIRTUAL_LAST, _LV_TILEVIEW_PART_REAL_LAST = _LV_PAGE_PART_REAL_LAST diff --git a/src/lv_widgets/lv_win.c b/src/lv_widgets/lv_win.c index 36dceb689d..0bae32554d 100644 --- a/src/lv_widgets/lv_win.c +++ b/src/lv_widgets/lv_win.c @@ -544,9 +544,9 @@ static lv_res_t lv_win_signal(lv_obj_t * win, lv_signal_t sign, void * param) else if(sign == LV_SIGNAL_GET_STATE_DSC) { lv_win_ext_t * ext = lv_obj_get_ext_attr(win); lv_get_state_info_t * info = param; - if(info->part == LV_WIN_PART_CONTENT_SCRL) info->result = lv_obj_get_state(lv_page_get_scrl(ext->page), + if(info->part == LV_WIN_PART_CONTENT_SCROLLABLE) info->result = lv_obj_get_state(lv_page_get_scrl(ext->page), LV_CONT_PART_MAIN); - else if(info->part == LV_WIN_PART_SCRLBAR) info->result = lv_obj_get_state(ext->page, LV_PAGE_PART_SCRLBAR); + else if(info->part == LV_WIN_PART_SCROLLBAR) info->result = lv_obj_get_state(ext->page, LV_PAGE_PART_SCROLLBAR); else if(info->part == LV_WIN_PART_HEADER) info->result = lv_obj_get_state(ext->header, LV_OBJ_PART_MAIN); return LV_RES_OK; } @@ -616,11 +616,11 @@ static lv_style_list_t * lv_win_get_style(lv_obj_t * win, uint8_t part) case LV_WIN_PART_HEADER: style_dsc_p = lv_obj_get_style_list(ext->header, LV_OBJ_PART_MAIN); break; - case LV_WIN_PART_SCRLBAR: - style_dsc_p = lv_obj_get_style_list(ext->page, LV_PAGE_PART_SCRLBAR); + case LV_WIN_PART_SCROLLBAR: + style_dsc_p = lv_obj_get_style_list(ext->page, LV_PAGE_PART_SCROLLBAR); break; - case LV_WIN_PART_CONTENT_SCRL: - style_dsc_p = lv_obj_get_style_list(ext->page, LV_PAGE_PART_SCRL); + case LV_WIN_PART_CONTENT_SCROLLABLE: + style_dsc_p = lv_obj_get_style_list(ext->page, LV_PAGE_PART_SCROLLABLE); break; default: style_dsc_p = NULL; diff --git a/src/lv_widgets/lv_win.h b/src/lv_widgets/lv_win.h index 96923af643..ebb9e3d647 100644 --- a/src/lv_widgets/lv_win.h +++ b/src/lv_widgets/lv_win.h @@ -64,8 +64,8 @@ enum { LV_WIN_PART_BG = LV_OBJ_PART_MAIN, /**< Window object background style. */ _LV_WIN_PART_VIRTUAL_LAST, LV_WIN_PART_HEADER = _LV_OBJ_PART_REAL_LAST, /**< Window titlebar background style. */ - LV_WIN_PART_CONTENT_SCRL, /**< Window content style. */ - LV_WIN_PART_SCRLBAR, /**< Window scrollbar style. */ + LV_WIN_PART_CONTENT_SCROLLABLE, /**< Window content style. */ + LV_WIN_PART_SCROLLBAR, /**< Window scrollbar style. */ _LV_WIN_PART_REAL_LAST }; diff --git a/tests/Makefile b/tests/Makefile index 418c409284..70d6609870 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -5,7 +5,7 @@ CC ?= gcc LVGL_DIR ?= ${shell pwd}/../.. LVGL_DIR_NAME ?= lvgl -WARNINGS ?= -Werror -Wall -Wextra -Wshadow -Wundef -Wmaybe-uninitialized -Wmissing-prototypes -Wno-discarded-qualifiers -Wall -Wextra -Wno-unused-function -Wundef -Wno-error=strict-prototypes -Wpointer-arith -fno-strict-aliasing -Wno-error=cpp -Wuninitialized -Wmaybe-uninitialized -Wno-unused-parameter -Wno-missing-field-initializers -Wtype-limits -Wsizeof-pointer-memaccess -Wno-format-nonliteral -Wno-cast-qual -Wunreachable-code -Wno-switch-default -Wno-switch-enum -Wreturn-type -Wmultichar -Wformat-security -Wno-ignored-qualifiers -Wno-error=pedantic -Wno-sign-compare -Wno-error=missing-prototypes -Wdouble-promotion -Wclobbered -Wdeprecated -Wempty-body -Wtype-limits -Wshift-negative-value -Wstack-usage=1024 -Wno-unused-value -Wno-unused-parameter -Wno-missing-field-initializers -Wuninitialized -Wmaybe-uninitialized -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wtype-limits -Wsizeof-pointer-memaccess -Wno-format-nonliteral -Wpointer-arith -Wno-cast-qual -Wmissing-prototypes -Wunreachable-code -Wno-switch-default -Wswitch-enum -Wreturn-type -Wmultichar -Wno-discarded-qualifiers -Wformat-security -Wno-ignored-qualifiers -Wno-sign-compare +WARNINGS ?= -Werror -Wall -Wextra -Wshadow -Wundef -Wmaybe-uninitialized -Wmissing-prototypes -Wno-discarded-qualifiers -Wall -Wextra -Wno-unused-function -Wundef -Wno-error=strict-prototypes -Wpointer-arith -fno-strict-aliasing -Wno-error=cpp -Wuninitialized -Wmaybe-uninitialized -Wno-unused-parameter -Wno-missing-field-initializers -Wtype-limits -Wsizeof-pointer-memaccess -Wno-format-nonliteral -Wno-cast-qual -Wunreachable-code -Wno-switch-default -Wno-switch-enum -Wreturn-type -Wmultichar -Wformat-security -Wno-ignored-qualifiers -Wno-error=pedantic -Wno-sign-compare -Wno-error=missing-prototypes -Wdouble-promotion -Wclobbered -Wdeprecated -Wempty-body -Wtype-limits -Wshift-negative-value -Wstack-usage=2048 -Wno-unused-value -Wno-unused-parameter -Wno-missing-field-initializers -Wuninitialized -Wmaybe-uninitialized -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wtype-limits -Wsizeof-pointer-memaccess -Wno-format-nonliteral -Wpointer-arith -Wno-cast-qual -Wmissing-prototypes -Wunreachable-code -Wno-switch-default -Wswitch-enum -Wreturn-type -Wmultichar -Wno-discarded-qualifiers -Wformat-security -Wno-ignored-qualifiers -Wno-sign-compare OPTIMIZATION ?= -O3 -g0 diff --git a/tests/build.py b/tests/build.py index 0c55c991ed..4fe4a4bae7 100755 --- a/tests/build.py +++ b/tests/build.py @@ -204,7 +204,7 @@ all_obj_all_features = { "LV_MEM_SIZE":32*1024, "LV_HOR_RES_MAX":480, "LV_VER_RES_MAX":320, - "LV_COLOR_DEPTH":16, + "LV_COLOR_DEPTH":32, "LV_USE_GROUP":1, "LV_USE_ANIMATION":1, "LV_ANTIALIAS":1, @@ -281,6 +281,7 @@ advanced_features = { "LV_HOR_RES_MAX":800, "LV_VER_RES_MAX":480, "LV_COLOR_DEPTH":16, + "LV_COLOR_16_SWAP":1, "LV_COLOR_SCREEN_TRANSP":1, "LV_USE_GROUP":1, "LV_USE_ANIMATION":1,