diff --git a/src/core/lv_disp.c b/src/core/lv_disp.c index 777aab322..c81a6ca0b 100644 --- a/src/core/lv_disp.c +++ b/src/core/lv_disp.c @@ -126,14 +126,13 @@ lv_obj_t * lv_disp_get_layer_sys(lv_disp_t * disp) */ void lv_disp_set_theme(lv_disp_t * disp, lv_theme_t * th) { - if(disp == NULL) disp = lv_disp_get_default(); + if(disp == NULL) disp = lv_disp_get_default(); disp->theme = th; if(disp->screen_cnt == 3 && - lv_obj_get_child_cnt(disp->screens[0]) == 0 && - lv_obj_get_child_cnt(disp->screens[1]) == 0 && - lv_obj_get_child_cnt(disp->screens[2]) == 0) - { + lv_obj_get_child_cnt(disp->screens[0]) == 0 && + lv_obj_get_child_cnt(disp->screens[1]) == 0 && + lv_obj_get_child_cnt(disp->screens[2]) == 0) { lv_theme_apply(disp->screens[0]); } } @@ -144,7 +143,7 @@ void lv_disp_set_theme(lv_disp_t * disp, lv_theme_t * th) */ lv_theme_t * lv_disp_get_theme(lv_disp_t * disp) { - if(disp == NULL) disp = lv_disp_get_default(); + if(disp == NULL) disp = lv_disp_get_default(); return disp->theme; } diff --git a/src/core/lv_event.c b/src/core/lv_event.c index ba48d57f2..20b54c7fd 100644 --- a/src/core/lv_event.c +++ b/src/core/lv_event.c @@ -17,11 +17,11 @@ /********************** * TYPEDEFS **********************/ -typedef struct _lv_event_dsc_t{ +typedef struct _lv_event_dsc_t { lv_event_cb_t cb; void * user_data; - lv_event_code_t filter :8; -}lv_event_dsc_t; + lv_event_code_t filter : 8; +} lv_event_dsc_t; /********************** * STATIC PROTOTYPES @@ -39,9 +39,9 @@ static lv_event_t * event_head; * MACROS **********************/ #if LV_LOG_TRACE_EVENT -# define EVENT_TRACE(...) LV_LOG_TRACE( __VA_ARGS__) + #define EVENT_TRACE(...) LV_LOG_TRACE( __VA_ARGS__) #else -# define EVENT_TRACE(...) + #define EVENT_TRACE(...) #endif /********************** @@ -147,13 +147,15 @@ void _lv_event_mark_deleted(lv_obj_t * obj) } -struct _lv_event_dsc_t * lv_obj_add_event_cb(lv_obj_t * obj, lv_event_cb_t event_cb, lv_event_code_t filter, void * user_data) +struct _lv_event_dsc_t * lv_obj_add_event_cb(lv_obj_t * obj, lv_event_cb_t event_cb, lv_event_code_t filter, + void * user_data) { LV_ASSERT_OBJ(obj, MY_CLASS); lv_obj_allocate_spec_attr(obj); obj->spec_attr->event_dsc_cnt++; - obj->spec_attr->event_dsc = lv_mem_realloc(obj->spec_attr->event_dsc, obj->spec_attr->event_dsc_cnt * sizeof(lv_event_dsc_t)); + obj->spec_attr->event_dsc = lv_mem_realloc(obj->spec_attr->event_dsc, + obj->spec_attr->event_dsc_cnt * sizeof(lv_event_dsc_t)); LV_ASSERT_MALLOC(obj->spec_attr->event_dsc); obj->spec_attr->event_dsc[obj->spec_attr->event_dsc_cnt - 1].cb = event_cb; @@ -172,11 +174,12 @@ bool lv_obj_remove_event_cb(lv_obj_t * obj, lv_event_cb_t event_cb) for(i = 0; i < obj->spec_attr->event_dsc_cnt; i++) { if(event_cb == NULL || obj->spec_attr->event_dsc[i].cb == event_cb) { /*Shift the remaining event handlers forward*/ - for(; i < (obj->spec_attr->event_dsc_cnt-1); i++) { - obj->spec_attr->event_dsc[i] = obj->spec_attr->event_dsc[i+1]; + for(; i < (obj->spec_attr->event_dsc_cnt - 1); i++) { + obj->spec_attr->event_dsc[i] = obj->spec_attr->event_dsc[i + 1]; } obj->spec_attr->event_dsc_cnt--; - obj->spec_attr->event_dsc = lv_mem_realloc(obj->spec_attr->event_dsc, obj->spec_attr->event_dsc_cnt * sizeof(lv_event_dsc_t)); + obj->spec_attr->event_dsc = lv_mem_realloc(obj->spec_attr->event_dsc, + obj->spec_attr->event_dsc_cnt * sizeof(lv_event_dsc_t)); LV_ASSERT_MALLOC(obj->spec_attr->event_dsc); return true; } @@ -194,14 +197,14 @@ bool lv_obj_remove_event_cb_with_user_data(lv_obj_t * obj, lv_event_cb_t event_c int32_t i = 0; for(i = 0; i < obj->spec_attr->event_dsc_cnt; i++) { if((event_cb == NULL || obj->spec_attr->event_dsc[i].cb) && - obj->spec_attr->event_dsc[i].user_data == user_data) - { + obj->spec_attr->event_dsc[i].user_data == user_data) { /*Shift the remaining event handlers forward*/ - for(; i < (obj->spec_attr->event_dsc_cnt-1); i++) { - obj->spec_attr->event_dsc[i] = obj->spec_attr->event_dsc[i+1]; + for(; i < (obj->spec_attr->event_dsc_cnt - 1); i++) { + obj->spec_attr->event_dsc[i] = obj->spec_attr->event_dsc[i + 1]; } obj->spec_attr->event_dsc_cnt--; - obj->spec_attr->event_dsc = lv_mem_realloc(obj->spec_attr->event_dsc, obj->spec_attr->event_dsc_cnt * sizeof(lv_event_dsc_t)); + obj->spec_attr->event_dsc = lv_mem_realloc(obj->spec_attr->event_dsc, + obj->spec_attr->event_dsc_cnt * sizeof(lv_event_dsc_t)); LV_ASSERT_MALLOC(obj->spec_attr->event_dsc); return true; } @@ -221,11 +224,12 @@ bool lv_obj_remove_event_dsc(lv_obj_t * obj, struct _lv_event_dsc_t * event_dsc) for(i = 0; i < obj->spec_attr->event_dsc_cnt; i++) { if(&obj->spec_attr->event_dsc[i] == event_dsc) { /*Shift the remaining event handlers forward*/ - for(; i < (obj->spec_attr->event_dsc_cnt-1); i++) { - obj->spec_attr->event_dsc[i] = obj->spec_attr->event_dsc[i+1]; + for(; i < (obj->spec_attr->event_dsc_cnt - 1); i++) { + obj->spec_attr->event_dsc[i] = obj->spec_attr->event_dsc[i + 1]; } obj->spec_attr->event_dsc_cnt--; - obj->spec_attr->event_dsc = lv_mem_realloc(obj->spec_attr->event_dsc, obj->spec_attr->event_dsc_cnt * sizeof(lv_event_dsc_t)); + obj->spec_attr->event_dsc = lv_mem_realloc(obj->spec_attr->event_dsc, + obj->spec_attr->event_dsc_cnt * sizeof(lv_event_dsc_t)); LV_ASSERT_MALLOC(obj->spec_attr->event_dsc); return true; } @@ -239,24 +243,24 @@ lv_indev_t * lv_event_get_indev(lv_event_t * e) { if(e->code == LV_EVENT_PRESSED || - e->code == LV_EVENT_PRESSING || - e->code == LV_EVENT_PRESS_LOST || - e->code == LV_EVENT_SHORT_CLICKED || - e->code == LV_EVENT_LONG_PRESSED || - e->code == LV_EVENT_LONG_PRESSED_REPEAT || - e->code == LV_EVENT_CLICKED || - e->code == LV_EVENT_RELEASED || - e->code == LV_EVENT_SCROLL_BEGIN || - e->code == LV_EVENT_SCROLL_END || - e->code == LV_EVENT_SCROLL || - e->code == LV_EVENT_GESTURE || - e->code == LV_EVENT_KEY || - e->code == LV_EVENT_FOCUSED || - e->code == LV_EVENT_DEFOCUSED || - e->code == LV_EVENT_LEAVE) - { + e->code == LV_EVENT_PRESSING || + e->code == LV_EVENT_PRESS_LOST || + e->code == LV_EVENT_SHORT_CLICKED || + e->code == LV_EVENT_LONG_PRESSED || + e->code == LV_EVENT_LONG_PRESSED_REPEAT || + e->code == LV_EVENT_CLICKED || + e->code == LV_EVENT_RELEASED || + e->code == LV_EVENT_SCROLL_BEGIN || + e->code == LV_EVENT_SCROLL_END || + e->code == LV_EVENT_SCROLL || + e->code == LV_EVENT_GESTURE || + e->code == LV_EVENT_KEY || + e->code == LV_EVENT_FOCUSED || + e->code == LV_EVENT_DEFOCUSED || + e->code == LV_EVENT_LEAVE) { return lv_event_get_param(e); - } else { + } + else { LV_LOG_WARN("Not interpreted with this event code"); return NULL; } @@ -264,11 +268,11 @@ lv_indev_t * lv_event_get_indev(lv_event_t * e) lv_obj_draw_part_dsc_t * lv_event_get_draw_part_dsc(lv_event_t * e) { - if(e->code == LV_EVENT_DRAW_PART_BEGIN|| - e->code == LV_EVENT_DRAW_PART_END) - { + if(e->code == LV_EVENT_DRAW_PART_BEGIN || + e->code == LV_EVENT_DRAW_PART_END) { return lv_event_get_param(e); - } else { + } + else { LV_LOG_WARN("Not interpreted with this event code"); return NULL; } @@ -277,14 +281,14 @@ lv_obj_draw_part_dsc_t * lv_event_get_draw_part_dsc(lv_event_t * e) const lv_area_t * lv_event_get_clip_area(lv_event_t * e) { if(e->code == LV_EVENT_DRAW_MAIN || - e->code == LV_EVENT_DRAW_MAIN_BEGIN || - e->code == LV_EVENT_DRAW_MAIN_END || - e->code == LV_EVENT_DRAW_POST || - e->code == LV_EVENT_DRAW_POST_BEGIN || - e->code == LV_EVENT_DRAW_POST_END) - { + e->code == LV_EVENT_DRAW_MAIN_BEGIN || + e->code == LV_EVENT_DRAW_MAIN_END || + e->code == LV_EVENT_DRAW_POST || + e->code == LV_EVENT_DRAW_POST_BEGIN || + e->code == LV_EVENT_DRAW_POST_END) { return lv_event_get_param(e); - } else { + } + else { LV_LOG_WARN("Not interpreted with this event code"); return NULL; } @@ -294,7 +298,8 @@ const lv_area_t * lv_event_get_old_size(lv_event_t * e) { if(e->code == LV_EVENT_SIZE_CHANGED) { return lv_event_get_param(e); - } else { + } + else { LV_LOG_WARN("Not interpreted with this event code"); return NULL; } @@ -306,7 +311,8 @@ uint32_t lv_event_get_key(lv_event_t * e) uint32_t * k = lv_event_get_param(e); if(k) return *k; else return 0; - } else { + } + else { LV_LOG_WARN("Not interpreted with this event code"); return 0; } @@ -316,7 +322,8 @@ lv_anim_t * lv_event_get_scroll_anim(lv_event_t * e) { if(e->code == LV_EVENT_SCROLL_BEGIN) { return lv_event_get_param(e); - } else { + } + else { LV_LOG_WARN("Not interpreted with this event code"); return 0; } @@ -327,7 +334,8 @@ void lv_event_set_ext_draw_size(lv_event_t * e, lv_coord_t size) if(e->code == LV_EVENT_REFR_EXT_DRAW_SIZE) { lv_coord_t * cur_size = lv_event_get_param(e); *cur_size = LV_MAX(*cur_size, size); - } else { + } + else { LV_LOG_WARN("Not interpreted with this event code"); } } @@ -336,7 +344,8 @@ lv_point_t * lv_event_get_self_size_info(lv_event_t * e) { if(e->code == LV_EVENT_GET_SELF_SIZE) { return lv_event_get_param(e); - } else { + } + else { LV_LOG_WARN("Not interpreted with this event code"); return 0; } @@ -346,7 +355,8 @@ lv_hit_test_info_t * lv_event_get_hit_test_info(lv_event_t * e) { if(e->code == LV_EVENT_HIT_TEST) { return lv_event_get_param(e); - } else { + } + else { LV_LOG_WARN("Not interpreted with this event code"); return 0; } @@ -357,7 +367,8 @@ const lv_area_t * lv_event_get_cover_area(lv_event_t * e) if(e->code == LV_EVENT_COVER_CHECK) { lv_cover_check_info_t * p = lv_event_get_param(e); return p->area; - } else { + } + else { LV_LOG_WARN("Not interpreted with this event code"); return NULL; } @@ -368,7 +379,8 @@ void lv_event_set_cover_res(lv_event_t * e, lv_cover_res_t res) if(e->code == LV_EVENT_COVER_CHECK) { lv_cover_check_info_t * p = lv_event_get_param(e); if(res > p->res) p->res = res; /*Save only "stronger" results*/ - } else { + } + else { LV_LOG_WARN("Not interpreted with this event code"); } } @@ -429,25 +441,25 @@ static lv_res_t event_send_core(lv_event_t * e) static bool event_is_bubbled(lv_event_code_t e) { switch(e) { - case LV_EVENT_HIT_TEST: - case LV_EVENT_COVER_CHECK: - case LV_EVENT_REFR_EXT_DRAW_SIZE: - case LV_EVENT_DRAW_MAIN_BEGIN: - case LV_EVENT_DRAW_MAIN: - case LV_EVENT_DRAW_MAIN_END: - case LV_EVENT_DRAW_POST_BEGIN: - case LV_EVENT_DRAW_POST: - case LV_EVENT_DRAW_POST_END: - case LV_EVENT_DRAW_PART_BEGIN: - case LV_EVENT_DRAW_PART_END: - case LV_EVENT_REFRESH: - case LV_EVENT_DELETE: - case LV_EVENT_CHILD_CHANGED: - case LV_EVENT_SIZE_CHANGED: - case LV_EVENT_STYLE_CHANGED: - case LV_EVENT_GET_SELF_SIZE: - return false; - default: - return true; + case LV_EVENT_HIT_TEST: + case LV_EVENT_COVER_CHECK: + case LV_EVENT_REFR_EXT_DRAW_SIZE: + case LV_EVENT_DRAW_MAIN_BEGIN: + case LV_EVENT_DRAW_MAIN: + case LV_EVENT_DRAW_MAIN_END: + case LV_EVENT_DRAW_POST_BEGIN: + case LV_EVENT_DRAW_POST: + case LV_EVENT_DRAW_POST_END: + case LV_EVENT_DRAW_PART_BEGIN: + case LV_EVENT_DRAW_PART_END: + case LV_EVENT_REFRESH: + case LV_EVENT_DELETE: + case LV_EVENT_CHILD_CHANGED: + case LV_EVENT_SIZE_CHANGED: + case LV_EVENT_STYLE_CHANGED: + case LV_EVENT_GET_SELF_SIZE: + return false; + default: + return true; } } diff --git a/src/core/lv_event.h b/src/core/lv_event.h index 3915db0f9..7fac61640 100644 --- a/src/core/lv_event.h +++ b/src/core/lv_event.h @@ -79,7 +79,7 @@ typedef enum { LV_EVENT_GET_SELF_SIZE, /**< Get the internal size of a widget*/ _LV_EVENT_LAST /** Number of default events*/ -}lv_event_code_t; +} lv_event_code_t; typedef struct _lv_event_t { struct _lv_obj_t * target; @@ -88,8 +88,8 @@ typedef struct _lv_event_t { void * user_data; void * param; struct _lv_event_t * prev; - uint8_t deleted :1; -}lv_event_t; + uint8_t deleted : 1; +} lv_event_t; /** * @brief Event callback. @@ -209,7 +209,8 @@ void _lv_event_mark_deleted(struct _lv_obj_t * obj); * @param user_data custom data data will be available in `event_cb` * @return a pointer the event descriptor. Can be used in ::lv_obj_remove_event_dsc */ -struct _lv_event_dsc_t * lv_obj_add_event_cb(struct _lv_obj_t * obj, lv_event_cb_t event_cb, lv_event_code_t filter, void * user_data); +struct _lv_event_dsc_t * lv_obj_add_event_cb(struct _lv_obj_t * obj, lv_event_cb_t event_cb, lv_event_code_t filter, + void * user_data); /** * Remove an event handler function for an object. @@ -226,7 +227,8 @@ bool lv_obj_remove_event_cb(struct _lv_obj_t * obj, lv_event_cb_t event_cb); * @param event_user_data the user_data specified in ::lv_obj_add_event_cb * @return true if any event handlers were removed */ -bool lv_obj_remove_event_cb_with_user_data(struct _lv_obj_t * obj, lv_event_cb_t event_cb, const void * event_user_data); +bool lv_obj_remove_event_cb_with_user_data(struct _lv_obj_t * obj, lv_event_cb_t event_cb, + const void * event_user_data); /** * DEPRACTED because doesn't work if multiple event handlers are added to an object. diff --git a/src/core/lv_group.c b/src/core/lv_group.c index d27e89998..281d67cb0 100644 --- a/src/core/lv_group.c +++ b/src/core/lv_group.c @@ -79,7 +79,7 @@ void lv_group_del(lv_group_t * group) /*Remove the objects from the group*/ lv_obj_t ** obj; _LV_LL_READ(&group->obj_ll, obj) { - if((*obj)->spec_attr) (*obj)->spec_attr->group_p = NULL; + if((*obj)->spec_attr)(*obj)->spec_attr->group_p = NULL; } _lv_ll_clear(&(group->obj_ll)); @@ -149,8 +149,8 @@ void lv_group_swap_obj(lv_obj_t * obj1, lv_obj_t * obj2) /*Do not add the object twice*/ lv_obj_t ** obj_i; _LV_LL_READ(&g1->obj_ll, obj_i) { - if((*obj_i) == obj1) (*obj_i) = obj2; - else if((*obj_i) == obj2) (*obj_i) = obj1; + if((*obj_i) == obj1)(*obj_i) = obj2; + else if((*obj_i) == obj2)(*obj_i) = obj1; } if(*g1->obj_focus == obj1) lv_group_focus_obj(obj2); @@ -211,7 +211,7 @@ void lv_group_remove_all_objs(lv_group_t * group) /*Remove the objects from the group*/ lv_obj_t ** obj; _LV_LL_READ(&group->obj_ll, obj) { - if((*obj)->spec_attr) (*obj)->spec_attr->group_p = NULL; + if((*obj)->spec_attr)(*obj)->spec_attr->group_p = NULL; } _lv_ll_clear(&(group->obj_ll)); diff --git a/src/core/lv_group.h b/src/core/lv_group.h index 6e9a1667b..aadb16ede 100644 --- a/src/core/lv_group.h +++ b/src/core/lv_group.h @@ -76,7 +76,7 @@ typedef struct _lv_group_t { typedef enum { LV_GROUP_REFOCUS_POLICY_NEXT = 0, LV_GROUP_REFOCUS_POLICY_PREV = 1 -}lv_group_refocus_policy_t; +} lv_group_refocus_policy_t; /********************** * GLOBAL PROTOTYPES diff --git a/src/core/lv_indev.c b/src/core/lv_indev.c index 159e4c131..c69992c7b 100644 --- a/src/core/lv_indev.c +++ b/src/core/lv_indev.c @@ -52,9 +52,9 @@ static lv_obj_t * indev_obj_act = NULL; * MACROS **********************/ #if LV_LOG_TRACE_INDEV -# define INDEV_TRACE(...) LV_LOG_TRACE( __VA_ARGS__) + #define INDEV_TRACE(...) LV_LOG_TRACE( __VA_ARGS__) #else -# define INDEV_TRACE(...) + #define INDEV_TRACE(...) #endif /********************** @@ -326,7 +326,7 @@ lv_obj_t * lv_indev_search_obj(lv_obj_t * obj, lv_point_t * point) */ static void indev_pointer_proc(lv_indev_t * i, lv_indev_data_t * data) { - lv_disp_t *disp = i->driver->disp; + lv_disp_t * disp = i->driver->disp; /*Save the raw points so they can be used again in _lv_indev_read*/ i->proc.types.pointer.last_raw_point.x = data->point.x; i->proc.types.pointer.last_raw_point.y = data->point.y; @@ -343,9 +343,11 @@ static void indev_pointer_proc(lv_indev_t * i, lv_indev_data_t * data) /*Simple sanity check*/ if(data->point.x < 0) LV_LOG_WARN("X is %d which is smaller than zero", data->point.x); - if(data->point.x >= lv_disp_get_hor_res(i->driver->disp)) LV_LOG_WARN("X is %d which is greater than hor. res", data->point.x); + if(data->point.x >= lv_disp_get_hor_res(i->driver->disp)) LV_LOG_WARN("X is %d which is greater than hor. res", + data->point.x); if(data->point.y < 0) LV_LOG_WARN("Y is %d which is smaller than zero", data->point.y); - if(data->point.y >= lv_disp_get_ver_res(i->driver->disp)) LV_LOG_WARN("Y is %d which is greater than hor. res", data->point.y); + if(data->point.y >= lv_disp_get_ver_res(i->driver->disp)) LV_LOG_WARN("Y is %d which is greater than hor. res", + data->point.y); /*Move the cursor if set and moved*/ if(i->cursor != NULL && @@ -672,7 +674,8 @@ static void indev_encoder_proc(lv_indev_t * i, lv_indev_data_t * data) lv_group_send_data(g, LV_KEY_ENTER); - } else { + } + else { lv_obj_clear_state(indev_obj_act, LV_STATE_PRESSED); /*Remove the pressed state manually*/ } } diff --git a/src/core/lv_indev_scroll.c b/src/core/lv_indev_scroll.c index ee76e0da5..bf356a87b 100644 --- a/src/core/lv_indev_scroll.c +++ b/src/core/lv_indev_scroll.c @@ -28,7 +28,8 @@ static lv_coord_t find_snap_point_y(const lv_obj_t * obj, lv_coord_t min, lv_coo static void scroll_limit_diff(_lv_indev_proc_t * proc, lv_coord_t * diff_x, lv_coord_t * diff_y); static lv_coord_t scroll_throw_predict_y(_lv_indev_proc_t * proc); static lv_coord_t scroll_throw_predict_x(_lv_indev_proc_t * proc); -static lv_coord_t elastic_diff(lv_obj_t * scroll_obj, lv_coord_t diff, lv_coord_t scroll_start, lv_coord_t scroll_end, lv_dir_t dir); +static lv_coord_t elastic_diff(lv_obj_t * scroll_obj, lv_coord_t diff, lv_coord_t scroll_start, lv_coord_t scroll_end, + lv_dir_t dir); /********************** * STATIC VARIABLES @@ -68,7 +69,8 @@ void _lv_indev_scroll_handler(_lv_indev_proc_t * proc) lv_coord_t sr = lv_obj_get_scroll_right(scroll_obj); lv_coord_t sl = lv_obj_get_scroll_left(scroll_obj); diff_x = elastic_diff(scroll_obj, proc->types.pointer.vect.x, sl, sr, LV_DIR_HOR); - } else { + } + else { lv_coord_t st = lv_obj_get_scroll_top(scroll_obj); lv_coord_t sb = lv_obj_get_scroll_bottom(scroll_obj); diff_y = elastic_diff(scroll_obj, proc->types.pointer.vect.y, st, sb, LV_DIR_VER); @@ -113,12 +115,13 @@ void _lv_indev_scroll_throw_handler(_lv_indev_proc_t * proc) /*If no snapping "throw"*/ if(align_y == LV_SCROLL_SNAP_NONE) { proc->types.pointer.scroll_throw_vect.y = - proc->types.pointer.scroll_throw_vect.y * (100 - scroll_throw) / 100; + proc->types.pointer.scroll_throw_vect.y * (100 - scroll_throw) / 100; lv_coord_t sb = lv_obj_get_scroll_bottom(scroll_obj); lv_coord_t st = lv_obj_get_scroll_top(scroll_obj); - proc->types.pointer.scroll_throw_vect.y = elastic_diff(scroll_obj, proc->types.pointer.scroll_throw_vect.y, st, sb, LV_DIR_VER); + proc->types.pointer.scroll_throw_vect.y = elastic_diff(scroll_obj, proc->types.pointer.scroll_throw_vect.y, st, sb, + LV_DIR_VER); lv_obj_scroll_by(scroll_obj, 0, proc->types.pointer.scroll_throw_vect.y, LV_ANIM_OFF); } @@ -136,12 +139,13 @@ void _lv_indev_scroll_throw_handler(_lv_indev_proc_t * proc) /*If no snapping "throw"*/ if(align_x == LV_SCROLL_SNAP_NONE) { proc->types.pointer.scroll_throw_vect.x = - proc->types.pointer.scroll_throw_vect.x * (100 - scroll_throw) / 100; + proc->types.pointer.scroll_throw_vect.x * (100 - scroll_throw) / 100; lv_coord_t sl = lv_obj_get_scroll_left(scroll_obj); lv_coord_t sr = lv_obj_get_scroll_right(scroll_obj); - proc->types.pointer.scroll_throw_vect.x = elastic_diff(scroll_obj, proc->types.pointer.scroll_throw_vect.x, sl ,sr, LV_DIR_HOR); + proc->types.pointer.scroll_throw_vect.x = elastic_diff(scroll_obj, proc->types.pointer.scroll_throw_vect.x, sl, sr, + LV_DIR_HOR); lv_obj_scroll_by(scroll_obj, proc->types.pointer.scroll_throw_vect.x, 0, LV_ANIM_OFF); } @@ -176,7 +180,7 @@ void _lv_indev_scroll_throw_handler(_lv_indev_proc_t * proc) if(align_x == LV_SCROLL_SNAP_NONE) { lv_coord_t sl = lv_obj_get_scroll_left(scroll_obj); lv_coord_t sr = lv_obj_get_scroll_right(scroll_obj); - if (sl > 0 || sr > 0) { + if(sl > 0 || sr > 0) { if(sl < 0) { lv_obj_scroll_by(scroll_obj, sl, 0, LV_ANIM_ON); } @@ -205,14 +209,14 @@ lv_coord_t lv_indev_scroll_throw_predict(lv_indev_t * indev, lv_dir_t dir) if(indev == NULL) return 0; lv_coord_t v; switch(dir) { - case LV_DIR_VER: - v = indev->proc.types.pointer.scroll_throw_vect_ori.y; - break; - case LV_DIR_HOR: - v = indev->proc.types.pointer.scroll_throw_vect_ori.x; - break; - default: - return 0; + case LV_DIR_VER: + v = indev->proc.types.pointer.scroll_throw_vect_ori.y; + break; + case LV_DIR_HOR: + v = indev->proc.types.pointer.scroll_throw_vect_ori.x; + break; + default: + return 0; } lv_coord_t scroll_throw = indev->driver->scroll_throw; @@ -292,17 +296,15 @@ static lv_obj_t * find_scroll_obj(_lv_indev_proc_t * proc) *is propagated to this object it can show at least elastic scroll effect. *But if not hor/ver scrollable do not scroll it at all (so it's not a good candidate)*/ if((st > 0 || sb > 0) && - ((up_en && proc->types.pointer.scroll_sum.y >= scroll_limit) || - (down_en && proc->types.pointer.scroll_sum.y <= - scroll_limit))) - { + ((up_en && proc->types.pointer.scroll_sum.y >= scroll_limit) || + (down_en && proc->types.pointer.scroll_sum.y <= - scroll_limit))) { obj_candidate = obj_act; dir_candidate = LV_DIR_VER; } if((sl > 0 || sr > 0) && - ((left_en && proc->types.pointer.scroll_sum.x >= scroll_limit) || - (right_en && proc->types.pointer.scroll_sum.x <= - scroll_limit))) - { + ((left_en && proc->types.pointer.scroll_sum.x >= scroll_limit) || + (right_en && proc->types.pointer.scroll_sum.x <= - scroll_limit))) { obj_candidate = obj_act; dir_candidate = LV_DIR_HOR; } @@ -314,10 +316,9 @@ static lv_obj_t * find_scroll_obj(_lv_indev_proc_t * proc) /*If the object really can be scrolled into the current direction the use it.*/ if((left_en && proc->types.pointer.scroll_sum.x >= scroll_limit) || - (right_en && proc->types.pointer.scroll_sum.x <= - scroll_limit) || - (up_en && proc->types.pointer.scroll_sum.y >= scroll_limit) || - (down_en && proc->types.pointer.scroll_sum.y <= - scroll_limit)) - { + (right_en && proc->types.pointer.scroll_sum.x <= - scroll_limit) || + (up_en && proc->types.pointer.scroll_sum.y >= scroll_limit) || + (down_en && proc->types.pointer.scroll_sum.y <= - scroll_limit)) { proc->types.pointer.scroll_dir = hor_en ? LV_DIR_HOR : LV_DIR_VER; break; } @@ -350,45 +351,45 @@ static void init_scroll_limits(_lv_indev_proc_t * proc) /*With STOP limit the scrolling to the perv and next snap point*/ else { switch(lv_obj_get_scroll_snap_y(obj)) { - case LV_SCROLL_SNAP_START: - proc->types.pointer.scroll_area.y1 = find_snap_point_y(obj, obj->coords.y1 + 1, LV_COORD_MAX, 0); - proc->types.pointer.scroll_area.y2 = find_snap_point_y(obj, LV_COORD_MIN, obj->coords.y1 - 1, 0); - break; - case LV_SCROLL_SNAP_END: - proc->types.pointer.scroll_area.y1 = find_snap_point_y(obj, obj->coords.y2, LV_COORD_MAX, 0); - proc->types.pointer.scroll_area.y2 = find_snap_point_y(obj, LV_COORD_MIN, obj->coords.y2, 0); - break; - case LV_SCROLL_SNAP_CENTER: { - lv_coord_t y_mid = obj->coords.y1 + lv_area_get_height(&obj->coords) / 2; - proc->types.pointer.scroll_area.y1 = find_snap_point_y(obj, y_mid + 1, LV_COORD_MAX, 0); - proc->types.pointer.scroll_area.y2 = find_snap_point_y(obj, LV_COORD_MIN, y_mid - 1, 0); - break; - } - default: - proc->types.pointer.scroll_area.y1 = LV_COORD_MIN; - proc->types.pointer.scroll_area.y2 = LV_COORD_MAX; - break; + case LV_SCROLL_SNAP_START: + proc->types.pointer.scroll_area.y1 = find_snap_point_y(obj, obj->coords.y1 + 1, LV_COORD_MAX, 0); + proc->types.pointer.scroll_area.y2 = find_snap_point_y(obj, LV_COORD_MIN, obj->coords.y1 - 1, 0); + break; + case LV_SCROLL_SNAP_END: + proc->types.pointer.scroll_area.y1 = find_snap_point_y(obj, obj->coords.y2, LV_COORD_MAX, 0); + proc->types.pointer.scroll_area.y2 = find_snap_point_y(obj, LV_COORD_MIN, obj->coords.y2, 0); + break; + case LV_SCROLL_SNAP_CENTER: { + lv_coord_t y_mid = obj->coords.y1 + lv_area_get_height(&obj->coords) / 2; + proc->types.pointer.scroll_area.y1 = find_snap_point_y(obj, y_mid + 1, LV_COORD_MAX, 0); + proc->types.pointer.scroll_area.y2 = find_snap_point_y(obj, LV_COORD_MIN, y_mid - 1, 0); + break; + } + default: + proc->types.pointer.scroll_area.y1 = LV_COORD_MIN; + proc->types.pointer.scroll_area.y2 = LV_COORD_MAX; + break; } switch(lv_obj_get_scroll_snap_x(obj)) { - case LV_SCROLL_SNAP_START: - proc->types.pointer.scroll_area.x1 = find_snap_point_x(obj, obj->coords.x1, LV_COORD_MAX, 0); - proc->types.pointer.scroll_area.x2 = find_snap_point_x(obj, LV_COORD_MIN, obj->coords.x1, 0); - break; - case LV_SCROLL_SNAP_END: - proc->types.pointer.scroll_area.x1 = find_snap_point_x(obj, obj->coords.x2, LV_COORD_MAX, 0); - proc->types.pointer.scroll_area.x2 = find_snap_point_x(obj, LV_COORD_MIN, obj->coords.x2, 0); - break; - case LV_SCROLL_SNAP_CENTER: { - lv_coord_t x_mid = obj->coords.x1 + lv_area_get_width(&obj->coords) / 2; - proc->types.pointer.scroll_area.x1 = find_snap_point_x(obj, x_mid + 1, LV_COORD_MAX, 0); - proc->types.pointer.scroll_area.x2 = find_snap_point_x(obj, LV_COORD_MIN, x_mid - 1, 0); - break; - } - default: - proc->types.pointer.scroll_area.x1 = LV_COORD_MIN; - proc->types.pointer.scroll_area.x2 = LV_COORD_MAX; - break; + case LV_SCROLL_SNAP_START: + proc->types.pointer.scroll_area.x1 = find_snap_point_x(obj, obj->coords.x1, LV_COORD_MAX, 0); + proc->types.pointer.scroll_area.x2 = find_snap_point_x(obj, LV_COORD_MIN, obj->coords.x1, 0); + break; + case LV_SCROLL_SNAP_END: + proc->types.pointer.scroll_area.x1 = find_snap_point_x(obj, obj->coords.x2, LV_COORD_MAX, 0); + proc->types.pointer.scroll_area.x2 = find_snap_point_x(obj, LV_COORD_MIN, obj->coords.x2, 0); + break; + case LV_SCROLL_SNAP_CENTER: { + lv_coord_t x_mid = obj->coords.x1 + lv_area_get_width(&obj->coords) / 2; + proc->types.pointer.scroll_area.x1 = find_snap_point_x(obj, x_mid + 1, LV_COORD_MAX, 0); + proc->types.pointer.scroll_area.x2 = find_snap_point_x(obj, LV_COORD_MIN, x_mid - 1, 0); + break; + } + default: + proc->types.pointer.scroll_area.x1 = LV_COORD_MIN; + proc->types.pointer.scroll_area.x2 = LV_COORD_MAX; + break; } } @@ -427,20 +428,20 @@ static lv_coord_t find_snap_point_x(const lv_obj_t * obj, lv_coord_t min, lv_coo lv_coord_t x_child = 0; lv_coord_t x_parent = 0; switch(align) { - case LV_SCROLL_SNAP_START: - x_child = child->coords.x1; - x_parent = obj->coords.x1 + pad_left; - break; - case LV_SCROLL_SNAP_END: - x_child = child->coords.x2; - x_parent = obj->coords.x2 - pad_right; - break; - case LV_SCROLL_SNAP_CENTER: - x_child = child->coords.x1 + lv_area_get_width(&child->coords) / 2; - x_parent = obj->coords.x1 + pad_left + (lv_area_get_width(&obj->coords) - pad_left - pad_right) / 2; - break; - default: - continue; + case LV_SCROLL_SNAP_START: + x_child = child->coords.x1; + x_parent = obj->coords.x1 + pad_left; + break; + case LV_SCROLL_SNAP_END: + x_child = child->coords.x2; + x_parent = obj->coords.x2 - pad_right; + break; + case LV_SCROLL_SNAP_CENTER: + x_child = child->coords.x1 + lv_area_get_width(&child->coords) / 2; + x_parent = obj->coords.x1 + pad_left + (lv_area_get_width(&obj->coords) - pad_left - pad_right) / 2; + break; + default: + continue; } x_child += ofs; @@ -451,7 +452,7 @@ static lv_coord_t find_snap_point_x(const lv_obj_t * obj, lv_coord_t min, lv_coo } } - return dist == LV_COORD_MAX ? 0: -dist; + return dist == LV_COORD_MAX ? 0 : -dist; } /** @@ -482,20 +483,20 @@ static lv_coord_t find_snap_point_y(const lv_obj_t * obj, lv_coord_t min, lv_coo lv_coord_t y_child = 0; lv_coord_t y_parent = 0; switch(align) { - case LV_SCROLL_SNAP_START: - y_child = child->coords.y1; - y_parent = obj->coords.y1 + pad_top; - break; - case LV_SCROLL_SNAP_END: - y_child = child->coords.y2; - y_parent = obj->coords.y2 - pad_bottom; - break; - case LV_SCROLL_SNAP_CENTER: - y_child = child->coords.y1 + lv_area_get_height(&child->coords) / 2; - y_parent = obj->coords.y1 + pad_top + (lv_area_get_height(&obj->coords) - pad_top - pad_bottom) / 2; - break; - default: - continue; + case LV_SCROLL_SNAP_START: + y_child = child->coords.y1; + y_parent = obj->coords.y1 + pad_top; + break; + case LV_SCROLL_SNAP_END: + y_child = child->coords.y2; + y_parent = obj->coords.y2 - pad_bottom; + break; + case LV_SCROLL_SNAP_CENTER: + y_child = child->coords.y1 + lv_area_get_height(&child->coords) / 2; + y_parent = obj->coords.y1 + pad_top + (lv_area_get_height(&obj->coords) - pad_top - pad_bottom) / 2; + break; + default: + continue; } y_child += ofs; @@ -513,7 +514,7 @@ static void scroll_limit_diff(_lv_indev_proc_t * proc, lv_coord_t * diff_x, lv_c { if(diff_y) { if(proc->types.pointer.scroll_sum.y + *diff_y < proc->types.pointer.scroll_area.y1) { - *diff_y = proc->types.pointer.scroll_area.y1 - proc->types.pointer.scroll_sum.y; + *diff_y = proc->types.pointer.scroll_area.y1 - proc->types.pointer.scroll_sum.y; } if(proc->types.pointer.scroll_sum.y + *diff_y > proc->types.pointer.scroll_area.y2) { @@ -565,7 +566,8 @@ static lv_coord_t scroll_throw_predict_x(_lv_indev_proc_t * proc) return move; } -static lv_coord_t elastic_diff(lv_obj_t * scroll_obj, lv_coord_t diff, lv_coord_t scroll_start, lv_coord_t scroll_end, lv_dir_t dir) +static lv_coord_t elastic_diff(lv_obj_t * scroll_obj, lv_coord_t diff, lv_coord_t scroll_start, lv_coord_t scroll_end, + lv_dir_t dir) { if(lv_obj_has_flag(scroll_obj, LV_OBJ_FLAG_SCROLL_ELASTIC)) { /*If there is snapping in the current direction don't use the elastic factor because @@ -582,36 +584,37 @@ static lv_coord_t elastic_diff(lv_obj_t * scroll_obj, lv_coord_t diff, lv_coord_ lv_coord_t pad_right = lv_obj_get_style_pad_right(scroll_obj, LV_PART_MAIN); switch(snap) { - case LV_SCROLL_SNAP_CENTER: - snap_point = pad_left + (lv_area_get_width(&scroll_obj->coords) - pad_left - pad_right) / 2 + scroll_obj->coords.x1; - act_obj_point = lv_area_get_width(&act_obj->coords) / 2 + act_obj->coords.x1; - break; - case LV_SCROLL_SNAP_START: - snap_point = scroll_obj->coords.x1 + pad_left; - act_obj_point = act_obj->coords.x1; - break; - case LV_SCROLL_SNAP_END: - snap_point = scroll_obj->coords.x2 - pad_right; - act_obj_point = act_obj->coords.x2; - break; + case LV_SCROLL_SNAP_CENTER: + snap_point = pad_left + (lv_area_get_width(&scroll_obj->coords) - pad_left - pad_right) / 2 + scroll_obj->coords.x1; + act_obj_point = lv_area_get_width(&act_obj->coords) / 2 + act_obj->coords.x1; + break; + case LV_SCROLL_SNAP_START: + snap_point = scroll_obj->coords.x1 + pad_left; + act_obj_point = act_obj->coords.x1; + break; + case LV_SCROLL_SNAP_END: + snap_point = scroll_obj->coords.x2 - pad_right; + act_obj_point = act_obj->coords.x2; + break; } - } else { + } + else { lv_coord_t pad_top = lv_obj_get_style_pad_top(scroll_obj, LV_PART_MAIN); lv_coord_t pad_bottom = lv_obj_get_style_pad_bottom(scroll_obj, LV_PART_MAIN); switch(snap) { - case LV_SCROLL_SNAP_CENTER: - snap_point = pad_top + (lv_area_get_height(&scroll_obj->coords) - pad_top - pad_bottom) / 2 + scroll_obj->coords.y1; - act_obj_point = lv_area_get_height(&act_obj->coords) / 2 + act_obj->coords.y1; - break; - case LV_SCROLL_SNAP_START: - snap_point = scroll_obj->coords.y1 + pad_top; - act_obj_point = act_obj->coords.y1; - break; - case LV_SCROLL_SNAP_END: - snap_point = scroll_obj->coords.y2 - pad_bottom; - act_obj_point = act_obj->coords.y2; - break; + case LV_SCROLL_SNAP_CENTER: + snap_point = pad_top + (lv_area_get_height(&scroll_obj->coords) - pad_top - pad_bottom) / 2 + scroll_obj->coords.y1; + act_obj_point = lv_area_get_height(&act_obj->coords) / 2 + act_obj->coords.y1; + break; + case LV_SCROLL_SNAP_START: + snap_point = scroll_obj->coords.y1 + pad_top; + act_obj_point = act_obj->coords.y1; + break; + case LV_SCROLL_SNAP_END: + snap_point = scroll_obj->coords.y2 - pad_bottom; + act_obj_point = act_obj->coords.y2; + break; } } @@ -631,7 +634,8 @@ static lv_coord_t elastic_diff(lv_obj_t * scroll_obj, lv_coord_t diff, lv_coord_ if(diff > 0) diff += ELASTIC_SLOWNESS_FACTOR / 2; return diff / ELASTIC_SLOWNESS_FACTOR; } - } else { + } + else { /*Scroll back to the boundary if required*/ if(scroll_end + diff < 0) diff = - scroll_end; if(scroll_start - diff < 0) diff = scroll_start; diff --git a/src/core/lv_obj.c b/src/core/lv_obj.c index 180cfc358..b14b574c4 100644 --- a/src/core/lv_obj.c +++ b/src/core/lv_obj.c @@ -142,13 +142,16 @@ void lv_init(void) } uint32_t endianess_test = 0x11223344; - uint8_t * endianess_test_p = (uint8_t*) &endianess_test; + uint8_t * endianess_test_p = (uint8_t *) &endianess_test; bool big_endian = endianess_test_p[0] == 0x11 ? true : false; if(big_endian) { - LV_ASSERT_MSG(LV_BIG_ENDIAN_SYSTEM == 1, "It's a big endian system but LV_BIG_ENDIAN_SYSTEM is not enabled in lv_conf.h"); - } else { - LV_ASSERT_MSG(LV_BIG_ENDIAN_SYSTEM == 0, "It's a little endian system but LV_BIG_ENDIAN_SYSTEM is enabled in lv_conf.h"); + LV_ASSERT_MSG(LV_BIG_ENDIAN_SYSTEM == 1, + "It's a big endian system but LV_BIG_ENDIAN_SYSTEM is not enabled in lv_conf.h"); + } + else { + LV_ASSERT_MSG(LV_BIG_ENDIAN_SYSTEM == 0, + "It's a little endian system but LV_BIG_ENDIAN_SYSTEM is enabled in lv_conf.h"); } #if LV_USE_ASSERT_MEM_INTEGRITY @@ -460,7 +463,7 @@ static void lv_obj_draw(lv_event_t * e) if(_lv_area_is_in(info->area, &coords, r) == false) { info->res = LV_COVER_RES_NOT_COVER; - return; + return; } if(lv_obj_get_style_bg_opa(obj, LV_PART_MAIN) < LV_OPA_MAX) { @@ -628,7 +631,8 @@ static lv_res_t scrollbar_init_draw_dsc(lv_obj_t * obj, lv_draw_rect_dsc_t * dsc dsc->border_width = lv_obj_get_style_border_width(obj, LV_PART_SCROLLBAR); if(dsc->border_width > 0) { dsc->border_color = lv_obj_get_style_border_color(obj, LV_PART_SCROLLBAR); - } else { + } + else { dsc->border_opa = LV_OPA_TRANSP; } } @@ -640,7 +644,8 @@ static lv_res_t scrollbar_init_draw_dsc(lv_obj_t * obj, lv_draw_rect_dsc_t * dsc if(dsc->shadow_width > 0) { dsc->shadow_spread = lv_obj_get_style_shadow_spread(obj, LV_PART_SCROLLBAR); dsc->shadow_color = lv_obj_get_style_shadow_color(obj, LV_PART_SCROLLBAR); - } else { + } + else { dsc->shadow_opa = LV_OPA_TRANSP; } } @@ -652,10 +657,11 @@ static lv_res_t scrollbar_init_draw_dsc(lv_obj_t * obj, lv_draw_rect_dsc_t * dsc dsc->shadow_opa = (dsc->bg_opa * opa) >> 8; } - if(dsc->bg_opa != LV_OPA_TRANSP || dsc->border_opa != LV_OPA_TRANSP || dsc->shadow_opa != LV_OPA_TRANSP ) { + if(dsc->bg_opa != LV_OPA_TRANSP || dsc->border_opa != LV_OPA_TRANSP || dsc->shadow_opa != LV_OPA_TRANSP) { dsc->radius = lv_obj_get_style_radius(obj, LV_PART_SCROLLBAR); return LV_RES_OK; - } else { + } + else { return LV_RES_INV; } #else @@ -873,7 +879,7 @@ static void lv_obj_set_state(lv_obj_t * obj, lv_state_t new_state) } } - for(i = 0;i < tsi; i++) { + for(i = 0; i < tsi; i++) { lv_part_t part_act = lv_obj_style_get_selector_part(ts[i].selector); _lv_obj_style_create_transition(obj, part_act, prev_state, new_state, &ts[i]); } diff --git a/src/core/lv_obj.h b/src/core/lv_obj.h index 491d58390..9dd80d2ef 100644 --- a/src/core/lv_obj.h +++ b/src/core/lv_obj.h @@ -126,7 +126,7 @@ typedef enum { LV_OBJ_DRAW_PART_RECTANGLE, /**< The main rectangle*/ LV_OBJ_DRAW_PART_BORDER_POST,/**< The border if style_border_post = true*/ LV_OBJ_DRAW_PART_SCROLLBAR, /**< The scrollbar*/ -}lv_obj_draw_part_type_t; +} lv_obj_draw_part_type_t; #include "lv_obj_tree.h" #include "lv_obj_pos.h" @@ -157,12 +157,12 @@ typedef struct { lv_coord_t ext_click_pad; /**< Extra click padding in all direction*/ lv_coord_t ext_draw_size; /**< EXTend the size in every direction for drawing.*/ - lv_scrollbar_mode_t scrollbar_mode :2; /**< How to display scrollbars*/ + lv_scrollbar_mode_t scrollbar_mode : 2; /**< How to display scrollbars*/ lv_scroll_snap_t scroll_snap_x : 2; /**< Where to align the snappable children horizontally*/ lv_scroll_snap_t scroll_snap_y : 2; /**< Where to align the snappable children vertically*/ - lv_dir_t scroll_dir :4; /**< The allowed scroll direction(s)*/ + lv_dir_t scroll_dir : 4; /**< The allowed scroll direction(s)*/ uint8_t event_dsc_cnt; /**< Number of event callbacks stored in `event_dsc` array*/ -}_lv_obj_spec_attr_t; +} _lv_obj_spec_attr_t; typedef struct _lv_obj_t { const lv_obj_class_t * class_p; @@ -175,13 +175,13 @@ typedef struct _lv_obj_t { lv_area_t coords; lv_obj_flag_t flags; lv_state_t state; - uint16_t layout_inv :1; - uint16_t scr_layout_inv :1; - uint16_t skip_trans :1; - uint16_t style_cnt :6; - uint16_t h_layout :1; - uint16_t w_layout :1; -}lv_obj_t; + uint16_t layout_inv : 1; + uint16_t scr_layout_inv : 1; + uint16_t skip_trans : 1; + uint16_t style_cnt : 6; + uint16_t h_layout : 1; + uint16_t w_layout : 1; +} lv_obj_t; /********************** @@ -379,9 +379,9 @@ static inline lv_coord_t lv_obj_dpx(const lv_obj_t * obj, lv_coord_t n) #if LV_USE_ASSERT_OBJ # define LV_ASSERT_OBJ(obj_p, obj_class) \ - LV_ASSERT_MSG(obj_p != NULL, "The object is NULL"); \ - LV_ASSERT_MSG(lv_obj_has_class(obj_p, obj_class) == true, "Incompatible object type."); \ - LV_ASSERT_MSG(lv_obj_is_valid(obj_p) == true, "The object is invalid, deleted or corrupted?"); + LV_ASSERT_MSG(obj_p != NULL, "The object is NULL"); \ + LV_ASSERT_MSG(lv_obj_has_class(obj_p, obj_class) == true, "Incompatible object type."); \ + LV_ASSERT_MSG(lv_obj_is_valid(obj_p) == true, "The object is invalid, deleted or corrupted?"); # else # define LV_ASSERT_OBJ(obj_p, obj_class) do{}while(0) diff --git a/src/core/lv_obj_class.c b/src/core/lv_obj_class.c index 3837639ff..fe1b183d8 100644 --- a/src/core/lv_obj_class.c +++ b/src/core/lv_obj_class.c @@ -63,7 +63,8 @@ lv_obj_t * lv_obj_class_create_obj(const lv_obj_class_t * class_p, lv_obj_t * pa disp->screens = lv_mem_alloc(sizeof(lv_obj_t *)); disp->screens[0] = obj; disp->screen_cnt = 1; - } else { + } + else { disp->screen_cnt++; disp->screens = lv_mem_realloc(disp->screens, sizeof(lv_obj_t *) * disp->screen_cnt); disp->screens[disp->screen_cnt - 1] = obj; @@ -87,9 +88,11 @@ lv_obj_t * lv_obj_class_create_obj(const lv_obj_class_t * class_p, lv_obj_t * pa parent->spec_attr->children = lv_mem_alloc(sizeof(lv_obj_t *)); parent->spec_attr->children[0] = obj; parent->spec_attr->child_cnt = 1; - } else { + } + else { parent->spec_attr->child_cnt++; - parent->spec_attr->children = lv_mem_realloc(parent->spec_attr->children, sizeof(lv_obj_t *) * parent->spec_attr->child_cnt); + parent->spec_attr->children = lv_mem_realloc(parent->spec_attr->children, + sizeof(lv_obj_t *) * parent->spec_attr->child_cnt); parent->spec_attr->children[parent->spec_attr->child_cnt - 1] = obj; } } diff --git a/src/core/lv_obj_class.h b/src/core/lv_obj_class.h index 0bf0dad59..01a7248ba 100644 --- a/src/core/lv_obj_class.h +++ b/src/core/lv_obj_class.h @@ -33,13 +33,13 @@ typedef enum { LV_OBJ_CLASS_EDITABLE_INHERIT, /**< Check the base class. Must have 0 value to let zero initialized class inherit*/ LV_OBJ_CLASS_EDITABLE_TRUE, LV_OBJ_CLASS_EDITABLE_FALSE, -}lv_obj_class_editable_t; +} lv_obj_class_editable_t; typedef enum { LV_OBJ_CLASS_GROUP_DEF_INHERIT, /**< Check the base class. Must have 0 value to let zero initialized class inherit*/ LV_OBJ_CLASS_GROUP_DEF_TRUE, LV_OBJ_CLASS_GROUP_DEF_FALSE, -}lv_obj_class_group_def_t; +} lv_obj_class_group_def_t; typedef void (*lv_obj_class_event_cb_t)(struct _lv_obj_class_t * class_p, struct _lv_event_t * e); /** @@ -53,13 +53,14 @@ typedef struct _lv_obj_class_t { #if LV_USE_USER_DATA void * user_data; #endif - void (*event_cb)(const struct _lv_obj_class_t * class_p, struct _lv_event_t * e); /**< Widget type specific event function*/ + void (*event_cb)(const struct _lv_obj_class_t * class_p, + struct _lv_event_t * e); /**< Widget type specific event function*/ lv_coord_t width_def; lv_coord_t height_def; uint32_t editable : 2; /**< Value from ::lv_obj_class_editable_t*/ uint32_t group_def : 2; /**< Value from ::lv_obj_class_group_def_t*/ uint32_t instance_size : 16; -}lv_obj_class_t; +} lv_obj_class_t; /********************** * GLOBAL PROTOTYPES diff --git a/src/core/lv_obj_draw.c b/src/core/lv_obj_draw.c index f48dc6ef3..411135f30 100644 --- a/src/core/lv_obj_draw.c +++ b/src/core/lv_obj_draw.c @@ -95,9 +95,10 @@ void lv_obj_init_draw_rect_dsc(lv_obj_t * obj, uint32_t part, lv_draw_rect_dsc_t draw_dsc->bg_img_opa = lv_obj_get_style_bg_img_opa(obj, part); if(draw_dsc->bg_img_opa > LV_OPA_MIN) { if(lv_img_src_get_type(draw_dsc->bg_img_src) == LV_IMG_SRC_SYMBOL) { - draw_dsc->bg_img_symbol_font= lv_obj_get_style_text_font(obj, part); + draw_dsc->bg_img_symbol_font = lv_obj_get_style_text_font(obj, part); draw_dsc->bg_img_recolor = lv_obj_get_style_text_color_filtered(obj, part); - } else { + } + else { draw_dsc->bg_img_recolor = lv_obj_get_style_bg_img_recolor_filtered(obj, part); draw_dsc->bg_img_recolor_opa = lv_obj_get_style_bg_img_recolor_opa(obj, part); draw_dsc->bg_img_tiled = lv_obj_get_style_bg_img_tiled(obj, part); @@ -167,13 +168,14 @@ void lv_obj_init_draw_rect_dsc(lv_obj_t * obj, uint32_t part, lv_draw_rect_dsc_t draw_dsc->bg_img_opa = lv_obj_get_style_bg_img_opa(obj, part); if(draw_dsc->bg_img_opa > LV_OPA_MIN) { if(lv_img_src_get_type(draw_dsc->bg_img_src) == LV_IMG_SRC_SYMBOL) { - draw_dsc->bg_img_symbol_font= lv_obj_get_style_text_font(obj, part); - draw_dsc->bg_img_recolor = lv_obj_get_style_text_color_filtered(obj, part); - } else { - draw_dsc->bg_img_recolor = lv_obj_get_style_bg_img_recolor_filtered(obj, part); - draw_dsc->bg_img_recolor_opa = lv_obj_get_style_bg_img_recolor_opa(obj, part); - draw_dsc->bg_img_tiled = lv_obj_get_style_bg_img_tiled(obj, part); - } + draw_dsc->bg_img_symbol_font = lv_obj_get_style_text_font(obj, part); + draw_dsc->bg_img_recolor = lv_obj_get_style_text_color_filtered(obj, part); + } + else { + draw_dsc->bg_img_recolor = lv_obj_get_style_bg_img_recolor_filtered(obj, part); + draw_dsc->bg_img_recolor_opa = lv_obj_get_style_bg_img_recolor_opa(obj, part); + draw_dsc->bg_img_tiled = lv_obj_get_style_bg_img_tiled(obj, part); + } } } } diff --git a/src/core/lv_obj_draw.h b/src/core/lv_obj_draw.h index ab18dd6df..3c4c37544 100644 --- a/src/core/lv_obj_draw.h +++ b/src/core/lv_obj_draw.h @@ -31,28 +31,34 @@ typedef enum { LV_COVER_RES_COVER = 0, LV_COVER_RES_NOT_COVER = 1, LV_COVER_RES_MASKED = 2, -}lv_cover_res_t; +} lv_cover_res_t; -typedef struct -{ +typedef struct { const lv_area_t * clip_area; /**< The current clip area, required if you need to draw something in the event*/ const struct _lv_obj_class_t * class_p; /**< The class that sent the event */ uint32_t type; /**< The type if part being draw. Element of `lv__draw_part_type_t` */ lv_area_t * draw_area; /**< The area of the part being drawn*/ - lv_draw_rect_dsc_t * rect_dsc; /**< A draw descriptor that can be modified to changed what LVGL will draw. Set only for rectangle-like parts*/ - lv_draw_label_dsc_t * label_dsc; /**< A draw descriptor that can be modified to changed what LVGL will draw. Set only for text-like parts*/ - lv_draw_line_dsc_t * line_dsc; /**< A draw descriptor that can be modified to changed what LVGL will draw. Set only for line-like parts*/ - lv_draw_img_dsc_t * img_dsc; /**< A draw descriptor that can be modified to changed what LVGL will draw. Set only for image-like parts*/ - lv_draw_arc_dsc_t * arc_dsc; /**< A draw descriptor that can be modified to changed what LVGL will draw. Set only for arc-like parts*/ - const lv_point_t * p1; /**< A point calculated during drawing. E.g. a point of chart or the center of an arc.*/ + lv_draw_rect_dsc_t * + rect_dsc; /**< A draw descriptor that can be modified to changed what LVGL will draw. Set only for rectangle-like parts*/ + lv_draw_label_dsc_t * + label_dsc; /**< A draw descriptor that can be modified to changed what LVGL will draw. Set only for text-like parts*/ + lv_draw_line_dsc_t * + line_dsc; /**< A draw descriptor that can be modified to changed what LVGL will draw. Set only for line-like parts*/ + lv_draw_img_dsc_t * + img_dsc; /**< A draw descriptor that can be modified to changed what LVGL will draw. Set only for image-like parts*/ + lv_draw_arc_dsc_t * + arc_dsc; /**< A draw descriptor that can be modified to changed what LVGL will draw. Set only for arc-like parts*/ + const lv_point_t * + p1; /**< A point calculated during drawing. E.g. a point of chart or the center of an arc.*/ const lv_point_t * p2; /**< A point calculated during drawing. E.g. a point of chart.*/ - const char * text; /**< A text calculated during drawing. Can be modified. E.g. tick labels on a chart axis.*/ + const char * + text; /**< A text calculated during drawing. Can be modified. E.g. tick labels on a chart axis.*/ uint32_t part; /**< The current part for which the event is sent*/ uint32_t id; /**< The index of the part. E.g. a button's index on button matrix or table cell index.*/ lv_coord_t radius; /**< E.g. the radius of an arc (not the corner radius).*/ int32_t value; /**< A value calculated during drawing. E.g. Chart's tick line value.*/ const void * sub_part_ptr; /**< A pointer the identifies something in the part. E.g. chart series. */ -}lv_obj_draw_part_dsc_t; +} lv_obj_draw_part_dsc_t; /********************** * GLOBAL PROTOTYPES diff --git a/src/core/lv_obj_pos.c b/src/core/lv_obj_pos.c index 0c78ada21..7e81215d4 100644 --- a/src/core/lv_obj_pos.c +++ b/src/core/lv_obj_pos.c @@ -96,7 +96,8 @@ bool lv_obj_refr_size(lv_obj_t * obj) bool w_content = false; if(obj->w_layout) { w = lv_obj_get_width(obj); - } else { + } + else { w = lv_obj_get_style_width(obj, LV_PART_MAIN); w_content = w == LV_SIZE_CONTENT ? true : false; @@ -122,7 +123,8 @@ bool lv_obj_refr_size(lv_obj_t * obj) bool h_content = false; if(obj->h_layout) { h = lv_obj_get_height(obj); - } else { + } + else { h = lv_obj_get_style_height(obj, LV_PART_MAIN); h_content = h == LV_SIZE_CONTENT ? true : false; @@ -357,112 +359,113 @@ void lv_obj_align_to(lv_obj_t * obj, const lv_obj_t * base, lv_align_t align, lv } switch(align) { - case LV_ALIGN_CENTER: - x = lv_obj_get_content_width(base) / 2 - lv_obj_get_width(obj) / 2 + bleft; - y = lv_obj_get_content_height(base) / 2 - lv_obj_get_height(obj) / 2 + btop; - break; - case LV_ALIGN_TOP_LEFT: - x = bleft; - y = btop; - break; - case LV_ALIGN_TOP_MID: - x = lv_obj_get_content_width(base) / 2 - lv_obj_get_width(obj) / 2 + bleft; - y = btop; - break; + case LV_ALIGN_CENTER: + x = lv_obj_get_content_width(base) / 2 - lv_obj_get_width(obj) / 2 + bleft; + y = lv_obj_get_content_height(base) / 2 - lv_obj_get_height(obj) / 2 + btop; + break; + case LV_ALIGN_TOP_LEFT: + x = bleft; + y = btop; + break; + case LV_ALIGN_TOP_MID: + x = lv_obj_get_content_width(base) / 2 - lv_obj_get_width(obj) / 2 + bleft; + y = btop; + break; - case LV_ALIGN_TOP_RIGHT: - x = lv_obj_get_content_width(base) - lv_obj_get_width(obj) + bleft; - y = btop; - break; + case LV_ALIGN_TOP_RIGHT: + x = lv_obj_get_content_width(base) - lv_obj_get_width(obj) + bleft; + y = btop; + break; - case LV_ALIGN_BOTTOM_LEFT: - x = bleft; - y = lv_obj_get_content_height(base) - lv_obj_get_height(obj) + btop; - break; - case LV_ALIGN_BOTTOM_MID: - x = lv_obj_get_content_width(base) / 2 - lv_obj_get_width(obj) / 2 + bleft; - y = lv_obj_get_content_height(base) - lv_obj_get_height(obj) + btop; - break; + case LV_ALIGN_BOTTOM_LEFT: + x = bleft; + y = lv_obj_get_content_height(base) - lv_obj_get_height(obj) + btop; + break; + case LV_ALIGN_BOTTOM_MID: + x = lv_obj_get_content_width(base) / 2 - lv_obj_get_width(obj) / 2 + bleft; + y = lv_obj_get_content_height(base) - lv_obj_get_height(obj) + btop; + break; - case LV_ALIGN_BOTTOM_RIGHT: - x = lv_obj_get_content_width(base) - lv_obj_get_width(obj) + bleft; - y = lv_obj_get_content_height(base) - lv_obj_get_height(obj) + btop; - break; + case LV_ALIGN_BOTTOM_RIGHT: + x = lv_obj_get_content_width(base) - lv_obj_get_width(obj) + bleft; + y = lv_obj_get_content_height(base) - lv_obj_get_height(obj) + btop; + break; - case LV_ALIGN_LEFT_MID: - x = bleft; - y = lv_obj_get_content_height(base) / 2 - lv_obj_get_height(obj) / 2 + btop; - break; + case LV_ALIGN_LEFT_MID: + x = bleft; + y = lv_obj_get_content_height(base) / 2 - lv_obj_get_height(obj) / 2 + btop; + break; - case LV_ALIGN_RIGHT_MID: - x = lv_obj_get_content_width(base) - lv_obj_get_width(obj) + bleft; - y = lv_obj_get_content_height(base) / 2 - lv_obj_get_height(obj) / 2 + btop; - break; + case LV_ALIGN_RIGHT_MID: + x = lv_obj_get_content_width(base) - lv_obj_get_width(obj) + bleft; + y = lv_obj_get_content_height(base) / 2 - lv_obj_get_height(obj) / 2 + btop; + break; - case LV_ALIGN_OUT_TOP_LEFT: - x = 0; - y = -lv_obj_get_height(obj); - break; + case LV_ALIGN_OUT_TOP_LEFT: + x = 0; + y = -lv_obj_get_height(obj); + break; - case LV_ALIGN_OUT_TOP_MID: - x = lv_obj_get_width(base) / 2 - lv_obj_get_width(obj) / 2; - y = -lv_obj_get_height(obj); - break; + case LV_ALIGN_OUT_TOP_MID: + x = lv_obj_get_width(base) / 2 - lv_obj_get_width(obj) / 2; + y = -lv_obj_get_height(obj); + break; - case LV_ALIGN_OUT_TOP_RIGHT: - x = lv_obj_get_width(base) - lv_obj_get_width(obj); - y = -lv_obj_get_height(obj); - break; + case LV_ALIGN_OUT_TOP_RIGHT: + x = lv_obj_get_width(base) - lv_obj_get_width(obj); + y = -lv_obj_get_height(obj); + break; - case LV_ALIGN_OUT_BOTTOM_LEFT: - x = 0; - y = lv_obj_get_height(base); - break; + case LV_ALIGN_OUT_BOTTOM_LEFT: + x = 0; + y = lv_obj_get_height(base); + break; - case LV_ALIGN_OUT_BOTTOM_MID: - x = lv_obj_get_width(base) / 2 - lv_obj_get_width(obj) / 2; - y = lv_obj_get_height(base); - break; + case LV_ALIGN_OUT_BOTTOM_MID: + x = lv_obj_get_width(base) / 2 - lv_obj_get_width(obj) / 2; + y = lv_obj_get_height(base); + break; - case LV_ALIGN_OUT_BOTTOM_RIGHT: - x = lv_obj_get_width(base) - lv_obj_get_width(obj); - y = lv_obj_get_height(base); - break; + case LV_ALIGN_OUT_BOTTOM_RIGHT: + x = lv_obj_get_width(base) - lv_obj_get_width(obj); + y = lv_obj_get_height(base); + break; - case LV_ALIGN_OUT_LEFT_TOP: - x = -lv_obj_get_width(obj); - y = 0; - break; + case LV_ALIGN_OUT_LEFT_TOP: + x = -lv_obj_get_width(obj); + y = 0; + break; - case LV_ALIGN_OUT_LEFT_MID: - x = -lv_obj_get_width(obj); - y = lv_obj_get_height(base) / 2 - lv_obj_get_height(obj) / 2; - break; + case LV_ALIGN_OUT_LEFT_MID: + x = -lv_obj_get_width(obj); + y = lv_obj_get_height(base) / 2 - lv_obj_get_height(obj) / 2; + break; - case LV_ALIGN_OUT_LEFT_BOTTOM: - x = -lv_obj_get_width(obj); - y = lv_obj_get_height(base) - lv_obj_get_height(obj); - break; + case LV_ALIGN_OUT_LEFT_BOTTOM: + x = -lv_obj_get_width(obj); + y = lv_obj_get_height(base) - lv_obj_get_height(obj); + break; - case LV_ALIGN_OUT_RIGHT_TOP: - x = lv_obj_get_width(base); - y = 0; - break; + case LV_ALIGN_OUT_RIGHT_TOP: + x = lv_obj_get_width(base); + y = 0; + break; - case LV_ALIGN_OUT_RIGHT_MID: - x = lv_obj_get_width(base); - y = lv_obj_get_height(base) / 2 - lv_obj_get_height(obj) / 2; - break; + case LV_ALIGN_OUT_RIGHT_MID: + x = lv_obj_get_width(base); + y = lv_obj_get_height(base) / 2 - lv_obj_get_height(obj) / 2; + break; - case LV_ALIGN_OUT_RIGHT_BOTTOM: - x = lv_obj_get_width(base); - y = lv_obj_get_height(base) - lv_obj_get_height(obj); - break; + case LV_ALIGN_OUT_RIGHT_BOTTOM: + x = lv_obj_get_width(base); + y = lv_obj_get_height(base) - lv_obj_get_height(obj); + break; } if(lv_obj_get_style_base_dir(parent, LV_PART_MAIN) == LV_BASE_DIR_RTL) { x += x_ofs + base->coords.x1 - parent->coords.x1 + lv_obj_get_scroll_right(parent) - pleft; - } else { + } + else { x += x_ofs + base->coords.x1 - parent->coords.x1 + lv_obj_get_scroll_left(parent) - pleft; } y += y_ofs + base->coords.y1 - parent->coords.y1 + lv_obj_get_scroll_top(parent) - ptop; @@ -581,14 +584,14 @@ void lv_obj_get_content_coords(const lv_obj_t * obj, lv_area_t * area) lv_coord_t lv_obj_get_self_width(const lv_obj_t * obj) { lv_point_t p = {0, LV_COORD_MIN}; - lv_event_send((lv_obj_t * )obj, LV_EVENT_GET_SELF_SIZE, &p); + lv_event_send((lv_obj_t *)obj, LV_EVENT_GET_SELF_SIZE, &p); return p.x; } lv_coord_t lv_obj_get_self_height(const lv_obj_t * obj) { lv_point_t p = {LV_COORD_MIN, 0}; - lv_event_send((lv_obj_t * )obj, LV_EVENT_GET_SELF_SIZE, &p); + lv_event_send((lv_obj_t *)obj, LV_EVENT_GET_SELF_SIZE, &p); return p.y; } @@ -646,36 +649,36 @@ void lv_obj_refr_pos(lv_obj_t * obj) else { switch(align) { - case LV_ALIGN_TOP_MID: - x += pw / 2 - w / 2; - break; - case LV_ALIGN_TOP_RIGHT: - x += pw - w; - break; - case LV_ALIGN_LEFT_MID: - y += ph / 2 - h / 2; - break; - case LV_ALIGN_BOTTOM_LEFT: - y += ph - h; - break; - case LV_ALIGN_BOTTOM_MID: - x += pw / 2 - w / 2; - y += ph - h; - break; - case LV_ALIGN_BOTTOM_RIGHT: - x += pw - w; - y += ph - h; - break; - case LV_ALIGN_RIGHT_MID: - x += pw - w; - y += ph / 2 - h / 2; - break; - case LV_ALIGN_CENTER: - x += pw / 2 - w / 2; - y += ph / 2 - h / 2; - break; - default: - break; + case LV_ALIGN_TOP_MID: + x += pw / 2 - w / 2; + break; + case LV_ALIGN_TOP_RIGHT: + x += pw - w; + break; + case LV_ALIGN_LEFT_MID: + y += ph / 2 - h / 2; + break; + case LV_ALIGN_BOTTOM_LEFT: + y += ph - h; + break; + case LV_ALIGN_BOTTOM_MID: + x += pw / 2 - w / 2; + y += ph - h; + break; + case LV_ALIGN_BOTTOM_RIGHT: + x += pw - w; + y += ph - h; + break; + case LV_ALIGN_RIGHT_MID: + x += pw - w; + y += ph / 2 - h / 2; + break; + case LV_ALIGN_CENTER: + x += pw / 2 - w / 2; + y += ph / 2 - h / 2; + break; + default: + break; } lv_obj_move_to(obj, x, y); } @@ -693,7 +696,8 @@ void lv_obj_move_to(lv_obj_t * obj, lv_coord_t x, lv_coord_t y) if(lv_obj_has_flag(obj, LV_OBJ_FLAG_FLOATING)) { x += pad_left + parent->coords.x1; y += pad_top + parent->coords.y1; - } else { + } + else { x += pad_left + parent->coords.x1 - lv_obj_get_scroll_x(parent); y += pad_top + parent->coords.y1 - lv_obj_get_scroll_y(parent); } @@ -808,8 +812,7 @@ bool lv_obj_area_is_visible(const lv_obj_t * obj, lv_area_t * area) if(obj_scr != lv_disp_get_scr_act(disp) && obj_scr != lv_disp_get_scr_prev(disp) && obj_scr != lv_disp_get_layer_top(disp) && - obj_scr != lv_disp_get_layer_sys(disp)) - { + obj_scr != lv_disp_get_layer_sys(disp)) { return false; } @@ -832,7 +835,8 @@ bool lv_obj_area_is_visible(const lv_obj_t * obj, lv_area_t * area) while(par != NULL) { is_common = _lv_area_intersect(area, area, &par->coords); if(is_common == false) return false; /*If no common parts with parent break;*/ - if(lv_obj_has_flag(par, LV_OBJ_FLAG_HIDDEN)) return false; /*If the parent is hidden then the child is hidden and won't be drawn*/ + if(lv_obj_has_flag(par, LV_OBJ_FLAG_HIDDEN)) return + false; /*If the parent is hidden then the child is hidden and won't be drawn*/ par = lv_obj_get_parent(par); } @@ -955,8 +959,8 @@ static void layout_update_core(lv_obj_t * obj) if(child_cnt > 0) { uint32_t layout_id = lv_obj_get_style_layout(obj, LV_PART_MAIN); if(layout_id > 0 && layout_id <= layout_cnt) { - void * user_data = LV_GC_ROOT(_lv_layout_list)[layout_id -1].user_data; - LV_GC_ROOT(_lv_layout_list)[layout_id -1].cb(obj, user_data); + void * user_data = LV_GC_ROOT(_lv_layout_list)[layout_id - 1].user_data; + LV_GC_ROOT(_lv_layout_list)[layout_id - 1].cb(obj, user_data); } } } diff --git a/src/core/lv_obj_pos.h b/src/core/lv_obj_pos.h index 9f74db9df..c73159ffd 100644 --- a/src/core/lv_obj_pos.h +++ b/src/core/lv_obj_pos.h @@ -28,7 +28,7 @@ typedef void (*lv_layout_update_cb_t)(struct _lv_obj_t *, void * user_data); typedef struct { lv_layout_update_cb_t cb; void * user_data; -}lv_layout_dsc_t; +} lv_layout_dsc_t; /********************** * GLOBAL PROTOTYPES @@ -176,7 +176,8 @@ void lv_obj_align(struct _lv_obj_t * obj, lv_align_t align, lv_coord_t x_ofs, lv * @param y_ofs y coordinate offset after alignment * @note if the position or size of `base` changes `obj` needs to be aligned manually again */ -void lv_obj_align_to(struct _lv_obj_t * obj, const struct _lv_obj_t * base, lv_align_t align, lv_coord_t x_ofs, lv_coord_t y_ofs); +void lv_obj_align_to(struct _lv_obj_t * obj, const struct _lv_obj_t * base, lv_align_t align, lv_coord_t x_ofs, + lv_coord_t y_ofs); /** * Align an object to the center on its parent. diff --git a/src/core/lv_obj_scroll.c b/src/core/lv_obj_scroll.c index a3a80455f..8fab47ba9 100644 --- a/src/core/lv_obj_scroll.c +++ b/src/core/lv_obj_scroll.c @@ -35,7 +35,8 @@ static void scroll_by_raw(lv_obj_t * obj, lv_coord_t x, lv_coord_t y); static void scroll_x_anim(void * obj, int32_t v); static void scroll_y_anim(void * obj, int32_t v); static void scroll_anim_ready_cb(lv_anim_t * a); -static void scroll_area_into_view(const lv_area_t * area, lv_obj_t * child, lv_point_t * scroll_value, lv_anim_enable_t anim_en); +static void scroll_area_into_view(const lv_area_t * area, lv_obj_t * child, lv_point_t * scroll_value, + lv_anim_enable_t anim_en); /********************** * STATIC VARIABLES @@ -189,7 +190,8 @@ lv_coord_t lv_obj_get_scroll_left(lv_obj_t * obj) if(x1 != LV_COORD_MAX) { child_res = x1; child_res = (obj->coords.x1 + pad_left + border_width) - child_res; - } else { + } + else { child_res = LV_COORD_MIN; } @@ -285,13 +287,14 @@ void lv_obj_scroll_by(lv_obj_t * obj, lv_coord_t x, lv_coord_t y, lv_anim_enable lv_anim_set_values(&a, -sy, -sy + y); lv_anim_set_exec_cb(&a, scroll_y_anim); lv_anim_set_path_cb(&a, lv_anim_path_ease_out); - + lv_res_t res; res = lv_event_send(obj, LV_EVENT_SCROLL_BEGIN, &a); if(res != LV_RES_OK) return; lv_anim_start(&a); } - } else { + } + else { /*Remove pending animations*/ bool y_del = lv_anim_del(obj, scroll_y_anim); bool x_del = lv_anim_del(obj, scroll_x_anim); @@ -323,7 +326,8 @@ void lv_obj_scroll_to_x(lv_obj_t * obj, lv_coord_t x, lv_anim_enable_t anim_en) if(x > scroll_max) x = scroll_max; } - } else { + } + else { if(x > 0) x = 0; if(x < 0) { lv_coord_t scroll_max = lv_obj_get_scroll_left(obj) + lv_obj_get_scroll_right(obj); @@ -429,18 +433,18 @@ void lv_obj_get_scrollbar_area(lv_obj_t * obj, lv_area_t * hor_area, lv_area_t * bool ver_draw = false; if((dir & LV_DIR_VER) && - ((sm == LV_SCROLLBAR_MODE_ON) || - (sm == LV_SCROLLBAR_MODE_AUTO && (st > 0 || sb > 0)) || - (sm == LV_SCROLLBAR_MODE_ACTIVE && lv_indev_get_scroll_dir(indev) == LV_DIR_VER))) { + ((sm == LV_SCROLLBAR_MODE_ON) || + (sm == LV_SCROLLBAR_MODE_AUTO && (st > 0 || sb > 0)) || + (sm == LV_SCROLLBAR_MODE_ACTIVE && lv_indev_get_scroll_dir(indev) == LV_DIR_VER))) { ver_draw = true; } bool hor_draw = false; if((dir & LV_DIR_HOR) && - ((sm == LV_SCROLLBAR_MODE_ON) || - (sm == LV_SCROLLBAR_MODE_AUTO && (sl > 0 || sr > 0)) || - (sm == LV_SCROLLBAR_MODE_ACTIVE && lv_indev_get_scroll_dir(indev) == LV_DIR_HOR))) { + ((sm == LV_SCROLLBAR_MODE_ON) || + (sm == LV_SCROLLBAR_MODE_AUTO && (sl > 0 || sr > 0)) || + (sm == LV_SCROLLBAR_MODE_ACTIVE && lv_indev_get_scroll_dir(indev) == LV_DIR_HOR))) { hor_draw = true; } @@ -472,31 +476,34 @@ void lv_obj_get_scrollbar_area(lv_obj_t * obj, lv_area_t * hor_area, lv_area_t * if(rtl) { ver_area->x1 = obj->coords.x1 + side_space; ver_area->x2 = ver_area->x1 + tickness - 1; - } else { + } + else { ver_area->x2 = obj->coords.x2 - side_space; ver_area->x1 = ver_area->x2 - tickness + 1; } lv_coord_t sb_h = ((obj_h - end_space * 2 - hor_req_space) * obj_h) / content_h; sb_h = LV_MAX(sb_h, SCROLLBAR_MIN_SIZE); - rem = (obj_h - end_space * 2 - hor_req_space) - sb_h; /*Remaining size from the scrollbar track that is not the scrollbar itself*/ + rem = (obj_h - end_space * 2 - hor_req_space) - + sb_h; /*Remaining size from the scrollbar track that is not the scrollbar itself*/ lv_coord_t scroll_h = content_h - obj_h; /*The size of the content which can be really scrolled*/ if(scroll_h <= 0) { ver_area->y1 = obj->coords.y1 + end_space; ver_area->y2 = obj->coords.y2 - end_space - hor_req_space - 1; - } else { + } + else { lv_coord_t sb_y = (rem * sb) / scroll_h; sb_y = rem - sb_y; ver_area->y1 = obj->coords.y1 + sb_y + end_space; - ver_area->y2 =ver_area->y1 + sb_h - 1; + ver_area->y2 = ver_area->y1 + sb_h - 1; if(ver_area->y1 < obj->coords.y1 + end_space) { ver_area->y1 = obj->coords.y1 + end_space; - if(ver_area->y1 + SCROLLBAR_MIN_SIZE >ver_area->y2)ver_area->y2 =ver_area->y1 + SCROLLBAR_MIN_SIZE; + if(ver_area->y1 + SCROLLBAR_MIN_SIZE > ver_area->y2)ver_area->y2 = ver_area->y1 + SCROLLBAR_MIN_SIZE; } if(ver_area->y2 > obj->coords.y2 - hor_req_space - end_space) { ver_area->y2 = obj->coords.y2 - hor_req_space - end_space; - if(ver_area->y2 - SCROLLBAR_MIN_SIZE y1)ver_area->y1 =ver_area->y2 - SCROLLBAR_MIN_SIZE; + if(ver_area->y2 - SCROLLBAR_MIN_SIZE < ver_area->y1)ver_area->y1 = ver_area->y2 - SCROLLBAR_MIN_SIZE; } } } @@ -511,17 +518,20 @@ void lv_obj_get_scrollbar_area(lv_obj_t * obj, lv_area_t * hor_area, lv_area_t * lv_coord_t sb_w = ((obj_w - end_space * 2 - ver_reg_space) * obj_w) / content_w; sb_w = LV_MAX(sb_w, SCROLLBAR_MIN_SIZE); - rem = (obj_w - end_space * 2 - ver_reg_space) - sb_w; /*Remaining size from the scrollbar track that is not the scrollbar itself*/ + rem = (obj_w - end_space * 2 - ver_reg_space) - + sb_w; /*Remaining size from the scrollbar track that is not the scrollbar itself*/ lv_coord_t scroll_w = content_w - obj_w; /*The size of the content which can be really scrolled*/ if(scroll_w <= 0) { if(rtl) { hor_area->x1 = obj->coords.x1 + end_space + ver_reg_space - 1; hor_area->x2 = obj->coords.x2 - end_space; - } else { + } + else { hor_area->x1 = obj->coords.x1 + end_space; hor_area->x2 = obj->coords.x2 - end_space - ver_reg_space - 1; } - } else { + } + else { lv_coord_t sb_x = (rem * sr) / scroll_w; sb_x = rem - sb_x; @@ -536,7 +546,8 @@ void lv_obj_get_scrollbar_area(lv_obj_t * obj, lv_area_t * hor_area, lv_area_t * hor_area->x2 = obj->coords.x2 - end_space; if(hor_area->x2 - SCROLLBAR_MIN_SIZE < hor_area->x1) hor_area->x1 = hor_area->x2 - SCROLLBAR_MIN_SIZE; } - } else { + } + else { hor_area->x1 = obj->coords.x1 + sb_x + end_space; hor_area->x2 = hor_area->x1 + sb_w - 1; if(hor_area->x1 < obj->coords.x1 + end_space) { @@ -586,7 +597,8 @@ void lv_obj_readjust_scroll(lv_obj_t * obj, lv_anim_enable_t anim_en) sr = LV_MIN(sl, -sr); lv_obj_scroll_by(obj, sr, 0, anim_en); } - } else { + } + else { /*Be sure the right side is not remains scrolled in*/ if(sl < 0 && sr > 0) { sr = LV_MIN(sr, -sl); @@ -630,7 +642,8 @@ static void scroll_anim_ready_cb(lv_anim_t * a) lv_event_send(a->var, LV_EVENT_SCROLL_END, NULL); } -static void scroll_area_into_view(const lv_area_t * area, lv_obj_t * child, lv_point_t * scroll_value, lv_anim_enable_t anim_en) +static void scroll_area_into_view(const lv_area_t * area, lv_obj_t * child, lv_point_t * scroll_value, + lv_anim_enable_t anim_en) { lv_obj_t * parent = lv_obj_get_parent(child); lv_dir_t scroll_dir = lv_obj_get_scroll_dir(parent); @@ -663,21 +676,21 @@ static void scroll_area_into_view(const lv_area_t * area, lv_obj_t * child, lv_p } switch(snap_y) { - case LV_SCROLL_SNAP_START: - snap_goal = parent->coords.y1 + ptop; - act = area_tmp->y1 + y_scroll; - y_scroll += snap_goal - act; - break; - case LV_SCROLL_SNAP_END: - snap_goal = parent->coords.y2 - pbottom; - act = area_tmp->y2 + y_scroll; - y_scroll += snap_goal - act; - break; - case LV_SCROLL_SNAP_CENTER: - snap_goal = parent->coords.y1 + ptop + parent_h / 2; - act = lv_area_get_height(area_tmp) / 2 + area_tmp->y1 + y_scroll; - y_scroll += snap_goal - act; - break; + case LV_SCROLL_SNAP_START: + snap_goal = parent->coords.y1 + ptop; + act = area_tmp->y1 + y_scroll; + y_scroll += snap_goal - act; + break; + case LV_SCROLL_SNAP_END: + snap_goal = parent->coords.y2 - pbottom; + act = area_tmp->y2 + y_scroll; + y_scroll += snap_goal - act; + break; + case LV_SCROLL_SNAP_CENTER: + snap_goal = parent->coords.y1 + ptop + parent_h / 2; + act = lv_area_get_height(area_tmp) / 2 + area_tmp->y1 + y_scroll; + y_scroll += snap_goal - act; + break; } lv_coord_t x_scroll = 0; @@ -688,7 +701,7 @@ static void scroll_area_into_view(const lv_area_t * area, lv_obj_t * child, lv_p lv_coord_t pleft = lv_obj_get_style_pad_left(parent, LV_PART_MAIN); lv_coord_t pright = lv_obj_get_style_pad_right(parent, LV_PART_MAIN); lv_coord_t left_diff = parent->coords.x1 + pleft - area_tmp->x1 - scroll_value->x; - lv_coord_t right_diff = -(parent->coords.x2 - pright - area_tmp->x2- scroll_value->x); + lv_coord_t right_diff = -(parent->coords.x2 - pright - area_tmp->x2 - scroll_value->x); if((left_diff > 0 && right_diff > 0)) x_scroll = 0; else if(left_diff > 0) { x_scroll = left_diff; @@ -705,21 +718,21 @@ static void scroll_area_into_view(const lv_area_t * area, lv_obj_t * child, lv_p lv_coord_t parent_w = lv_obj_get_width(parent) - pleft - pright; switch(snap_x) { - case LV_SCROLL_SNAP_START: - snap_goal = parent->coords.x1 + pleft; - act = area_tmp->x1 + x_scroll; - x_scroll += snap_goal - act; - break; - case LV_SCROLL_SNAP_END: - snap_goal = parent->coords.x2 - pright; - act = area_tmp->x2 + x_scroll; - x_scroll += snap_goal - act; - break; - case LV_SCROLL_SNAP_CENTER: - snap_goal = parent->coords.x1 + pleft + parent_w / 2; - act = lv_area_get_width(area_tmp) / 2 + area_tmp->x1 + x_scroll; - x_scroll += snap_goal - act; - break; + case LV_SCROLL_SNAP_START: + snap_goal = parent->coords.x1 + pleft; + act = area_tmp->x1 + x_scroll; + x_scroll += snap_goal - act; + break; + case LV_SCROLL_SNAP_END: + snap_goal = parent->coords.x2 - pright; + act = area_tmp->x2 + x_scroll; + x_scroll += snap_goal - act; + break; + case LV_SCROLL_SNAP_CENTER: + snap_goal = parent->coords.x1 + pleft + parent_w / 2; + act = lv_area_get_width(area_tmp) / 2 + area_tmp->x1 + x_scroll; + x_scroll += snap_goal - act; + break; } /*Remove any pending scroll animations.*/ diff --git a/src/core/lv_obj_style.c b/src/core/lv_obj_style.c index 4182b4f3f..93dfc3be3 100644 --- a/src/core/lv_obj_style.c +++ b/src/core/lv_obj_style.c @@ -33,7 +33,7 @@ typedef enum { CACHE_UNSET = 2, CACHE_255 = 3, CACHE_NEED_CHECK = 4, -}cache_t; +} cache_t; /********************** * GLOBAL PROTOTYPES @@ -117,8 +117,7 @@ void lv_obj_remove_style(lv_obj_t * obj, lv_style_t * style, lv_style_selector_t lv_part_t part_act = lv_obj_style_get_selector_part(obj->styles[i].selector); if((state != LV_STATE_ANY && state_act != state) || (part != LV_PART_ANY && part_act != part) || - (style != NULL && style != obj->styles[i].style)) - { + (style != NULL && style != obj->styles[i].style)) { i++; continue; } @@ -179,13 +178,13 @@ void lv_obj_refresh_style(lv_obj_t * obj, lv_style_selector_t selector, lv_style if(part == LV_PART_ANY || part == LV_PART_MAIN || lv_obj_get_style_height(obj, 0) == LV_SIZE_CONTENT || - lv_obj_get_style_width(obj, 0) == LV_SIZE_CONTENT) - { + lv_obj_get_style_width(obj, 0) == LV_SIZE_CONTENT) { lv_event_send(obj, LV_EVENT_STYLE_CHANGED, NULL); lv_obj_mark_layout_as_dirty(obj); } } - if((part == LV_PART_ANY || part == LV_PART_MAIN) && (prop == LV_STYLE_PROP_ANY || (prop & LV_STYLE_PROP_PARENT_LAYOUT_REFR))) { + if((part == LV_PART_ANY || part == LV_PART_MAIN) && (prop == LV_STYLE_PROP_ANY || + (prop & LV_STYLE_PROP_PARENT_LAYOUT_REFR))) { lv_obj_t * parent = lv_obj_get_parent(obj); if(parent) lv_obj_mark_layout_as_dirty(parent); } @@ -196,8 +195,7 @@ void lv_obj_refresh_style(lv_obj_t * obj, lv_style_selector_t selector, lv_style lv_obj_invalidate(obj); if(prop == LV_STYLE_PROP_ANY || - ((prop & LV_STYLE_PROP_INHERIT) && ((prop & LV_STYLE_PROP_EXT_DRAW) || (prop & LV_STYLE_PROP_LAYOUT_REFR)))) - { + ((prop & LV_STYLE_PROP_INHERIT) && ((prop & LV_STYLE_PROP_EXT_DRAW) || (prop & LV_STYLE_PROP_LAYOUT_REFR)))) { if(part != LV_PART_SCROLLBAR) { refresh_children_style(obj); } @@ -239,14 +237,16 @@ lv_style_value_t lv_obj_get_style_prop(const lv_obj_t * obj, lv_part_t part, lv_ while(cls) { if(prop == LV_STYLE_WIDTH) { if(cls->width_def != 0) break; - } else { + } + else { if(cls->height_def != 0) break; } cls = cls->base_class; } value_act.num = prop == LV_STYLE_WIDTH ? cls->width_def : cls->height_def; - } else { + } + else { value_act = lv_style_prop_get_default(prop); } } @@ -254,7 +254,8 @@ lv_style_value_t lv_obj_get_style_prop(const lv_obj_t * obj, lv_part_t part, lv_ return value_act; } -void lv_obj_set_local_style_prop(lv_obj_t * obj, lv_style_prop_t prop, lv_style_value_t value, lv_style_selector_t selector) +void lv_obj_set_local_style_prop(lv_obj_t * obj, lv_style_prop_t prop, lv_style_value_t value, + lv_style_selector_t selector) { lv_style_t * style = get_local_style(obj, selector); lv_style_set_prop(style, prop, value); @@ -262,13 +263,13 @@ void lv_obj_set_local_style_prop(lv_obj_t * obj, lv_style_prop_t prop, lv_style_ } -lv_res_t lv_obj_get_local_style_prop(lv_obj_t * obj, lv_style_prop_t prop, lv_style_value_t * value, lv_style_selector_t selector) +lv_res_t lv_obj_get_local_style_prop(lv_obj_t * obj, lv_style_prop_t prop, lv_style_value_t * value, + lv_style_selector_t selector) { uint32_t i; for(i = 0; i < obj->style_cnt; i++) { if(obj->styles[i].is_local && - obj->styles[i].selector == selector) - { + obj->styles[i].selector == selector) { return lv_style_get_prop(obj->styles[i].style, prop, value); } } @@ -295,7 +296,8 @@ bool lv_obj_remove_local_style_prop(lv_obj_t * obj, lv_style_prop_t prop, lv_sty return lv_style_remove_prop(obj->styles[i].style, prop); } -void _lv_obj_style_create_transition(lv_obj_t * obj, lv_part_t part, lv_state_t prev_state, lv_state_t new_state, const _lv_obj_style_transition_dsc_t * tr_dsc) +void _lv_obj_style_create_transition(lv_obj_t * obj, lv_part_t part, lv_state_t prev_state, lv_state_t new_state, + const _lv_obj_style_transition_dsc_t * tr_dsc) { trans_t * tr; @@ -483,8 +485,7 @@ static lv_style_t * get_local_style(lv_obj_t * obj, lv_style_selector_t selecto uint32_t i; for(i = 0; i < obj->style_cnt; i++) { if(obj->styles[i].is_local && - obj->styles[i].selector == selector) - { + obj->styles[i].selector == selector) { return obj->styles[i].style; } } @@ -706,7 +707,7 @@ static void trans_anim_cb(void * _tr, int32_t v) if(obj->styles[i].is_trans == 0 || obj->styles[i].selector != tr->selector) continue; lv_style_value_t value_final; - switch (tr->prop) { + switch(tr->prop) { case LV_STYLE_BORDER_SIDE: case LV_STYLE_BORDER_POST: @@ -746,12 +747,13 @@ static void trans_anim_cb(void * _tr, int32_t v) lv_style_value_t old_value; bool refr = true; if(lv_style_get_prop(obj->styles[i].style, tr->prop, &old_value)) { - if(value_final.ptr == old_value.ptr && value_final.color.full == old_value.color.full && value_final.num == old_value.num) { + if(value_final.ptr == old_value.ptr && value_final.color.full == old_value.color.full && + value_final.num == old_value.num) { refr = false; } } lv_style_set_prop(obj->styles[i].style, tr->prop, value_final); - if (refr) lv_obj_refresh_style(tr->obj, tr->selector, tr->prop); + if(refr) lv_obj_refresh_style(tr->obj, tr->selector, tr->prop); break; } diff --git a/src/core/lv_obj_style.h b/src/core/lv_obj_style.h index e58f7d830..d21f40cec 100644 --- a/src/core/lv_obj_style.h +++ b/src/core/lv_obj_style.h @@ -38,10 +38,10 @@ typedef uint32_t lv_style_selector_t; typedef struct { lv_style_t * style; - uint32_t selector :24; - uint32_t is_local :1; - uint32_t is_trans :1; -}_lv_obj_style_t; + uint32_t selector : 24; + uint32_t is_local : 1; + uint32_t is_trans : 1; +} _lv_obj_style_t; typedef struct { uint16_t time; @@ -52,7 +52,7 @@ typedef struct { #if LV_USE_USER_DATA void * user_data; #endif -}_lv_obj_style_transition_dsc_t; +} _lv_obj_style_transition_dsc_t; /********************** * GLOBAL PROTOTYPES @@ -138,9 +138,11 @@ lv_style_value_t lv_obj_get_style_prop(const struct _lv_obj_t * obj, lv_part_t p * @param prop the property * @param value value of the property. The correct element should be set according to the type of the property */ -void lv_obj_set_local_style_prop(struct _lv_obj_t * obj, lv_style_prop_t prop, lv_style_value_t value, lv_style_selector_t selector); +void lv_obj_set_local_style_prop(struct _lv_obj_t * obj, lv_style_prop_t prop, lv_style_value_t value, + lv_style_selector_t selector); -lv_res_t lv_obj_get_local_style_prop(struct _lv_obj_t * obj, lv_style_prop_t prop, lv_style_value_t * value, lv_style_selector_t selector); +lv_res_t lv_obj_get_local_style_prop(struct _lv_obj_t * obj, lv_style_prop_t prop, lv_style_value_t * value, + lv_style_selector_t selector); /** * Remove a local style property from a part of an object with a given state. @@ -160,7 +162,8 @@ bool lv_obj_remove_local_style_prop(struct _lv_obj_t * obj, lv_style_prop_t prop * @param new_state * @param tr */ -void _lv_obj_style_create_transition(struct _lv_obj_t * obj, lv_part_t part, lv_state_t prev_state, lv_state_t new_state, const _lv_obj_style_transition_dsc_t * tr); +void _lv_obj_style_create_transition(struct _lv_obj_t * obj, lv_part_t part, lv_state_t prev_state, + lv_state_t new_state, const _lv_obj_style_transition_dsc_t * tr); /** * Used internally to compare the appearance of an object in 2 states @@ -193,29 +196,34 @@ lv_part_t lv_obj_style_get_selector_part(lv_style_selector_t selector); #include "lv_obj_style_gen.h" -static inline void lv_obj_set_style_pad_all(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector) { +static inline void lv_obj_set_style_pad_all(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector) +{ lv_obj_set_style_pad_left(obj, value, selector); lv_obj_set_style_pad_right(obj, value, selector); lv_obj_set_style_pad_top(obj, value, selector); lv_obj_set_style_pad_bottom(obj, value, selector); } -static inline void lv_obj_set_style_pad_hor(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector) { +static inline void lv_obj_set_style_pad_hor(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector) +{ lv_obj_set_style_pad_left(obj, value, selector); lv_obj_set_style_pad_right(obj, value, selector); } -static inline void lv_obj_set_style_pad_ver(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector) { +static inline void lv_obj_set_style_pad_ver(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector) +{ lv_obj_set_style_pad_top(obj, value, selector); lv_obj_set_style_pad_bottom(obj, value, selector); } -static inline void lv_obj_set_style_pad_gap(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector) { +static inline void lv_obj_set_style_pad_gap(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector) +{ lv_obj_set_style_pad_row(obj, value, selector); lv_obj_set_style_pad_column(obj, value, selector); } -static inline void lv_obj_set_style_size(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector) { +static inline void lv_obj_set_style_size(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector) +{ lv_obj_set_style_width(obj, value, selector); lv_obj_set_style_height(obj, value, selector); } diff --git a/src/core/lv_obj_style_gen.c b/src/core/lv_obj_style_gen.c index 4cf91b329..b0bf97883 100644 --- a/src/core/lv_obj_style_gen.c +++ b/src/core/lv_obj_style_gen.c @@ -191,7 +191,8 @@ void lv_obj_set_style_opa(struct _lv_obj_t * obj, lv_opa_t value, lv_style_selec lv_obj_set_local_style_prop(obj, LV_STYLE_OPA, v, selector); } -void lv_obj_set_style_color_filter_dsc(struct _lv_obj_t * obj, const lv_color_filter_dsc_t * value, lv_style_selector_t selector) +void lv_obj_set_style_color_filter_dsc(struct _lv_obj_t * obj, const lv_color_filter_dsc_t * value, + lv_style_selector_t selector) { lv_style_value_t v = { .ptr = value @@ -223,7 +224,8 @@ void lv_obj_set_style_anim_speed(struct _lv_obj_t * obj, uint32_t value, lv_styl lv_obj_set_local_style_prop(obj, LV_STYLE_ANIM_SPEED, v, selector); } -void lv_obj_set_style_transition(struct _lv_obj_t * obj, const lv_style_transition_dsc_t * value, lv_style_selector_t selector) +void lv_obj_set_style_transition(struct _lv_obj_t * obj, const lv_style_transition_dsc_t * value, + lv_style_selector_t selector) { lv_style_value_t v = { .ptr = value diff --git a/src/core/lv_obj_style_gen.h b/src/core/lv_obj_style_gen.h index 40e490ea0..79afec4d6 100644 --- a/src/core/lv_obj_style_gen.h +++ b/src/core/lv_obj_style_gen.h @@ -142,7 +142,8 @@ static inline lv_opa_t lv_obj_get_style_opa(const struct _lv_obj_t * obj, uint32 return (lv_opa_t)v.num; } -static inline const lv_color_filter_dsc_t * lv_obj_get_style_color_filter_dsc(const struct _lv_obj_t * obj, uint32_t part) +static inline const lv_color_filter_dsc_t * lv_obj_get_style_color_filter_dsc(const struct _lv_obj_t * obj, + uint32_t part) { lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_COLOR_FILTER_DSC); return (const lv_color_filter_dsc_t *)v.ptr; @@ -556,11 +557,13 @@ void lv_obj_set_style_pad_column(struct _lv_obj_t * obj, lv_coord_t value, lv_st void lv_obj_set_style_radius(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector); void lv_obj_set_style_clip_corner(struct _lv_obj_t * obj, bool value, lv_style_selector_t selector); void lv_obj_set_style_opa(struct _lv_obj_t * obj, lv_opa_t value, lv_style_selector_t selector); -void lv_obj_set_style_color_filter_dsc(struct _lv_obj_t * obj, const lv_color_filter_dsc_t * value, lv_style_selector_t selector); +void lv_obj_set_style_color_filter_dsc(struct _lv_obj_t * obj, const lv_color_filter_dsc_t * value, + lv_style_selector_t selector); void lv_obj_set_style_color_filter_opa(struct _lv_obj_t * obj, lv_opa_t value, lv_style_selector_t selector); void lv_obj_set_style_anim_time(struct _lv_obj_t * obj, uint32_t value, lv_style_selector_t selector); void lv_obj_set_style_anim_speed(struct _lv_obj_t * obj, uint32_t value, lv_style_selector_t selector); -void lv_obj_set_style_transition(struct _lv_obj_t * obj, const lv_style_transition_dsc_t * value, lv_style_selector_t selector); +void lv_obj_set_style_transition(struct _lv_obj_t * obj, const lv_style_transition_dsc_t * value, + lv_style_selector_t selector); void lv_obj_set_style_blend_mode(struct _lv_obj_t * obj, lv_blend_mode_t value, lv_style_selector_t selector); void lv_obj_set_style_layout(struct _lv_obj_t * obj, uint16_t value, lv_style_selector_t selector); void lv_obj_set_style_base_dir(struct _lv_obj_t * obj, lv_base_dir_t value, lv_style_selector_t selector); diff --git a/src/core/lv_obj_tree.c b/src/core/lv_obj_tree.c index 9baea74d6..93b56135b 100644 --- a/src/core/lv_obj_tree.c +++ b/src/core/lv_obj_tree.c @@ -30,9 +30,9 @@ /********************** * STATIC PROTOTYPES **********************/ -static void lv_obj_del_async_cb(void* obj); +static void lv_obj_del_async_cb(void * obj); static void obj_del_core(lv_obj_t * obj); -static lv_obj_tree_walk_res_t walk_core(lv_obj_t * obj, lv_obj_tree_walk_cb_t cb, void* user_data); +static lv_obj_tree_walk_res_t walk_core(lv_obj_t * obj, lv_obj_tree_walk_cb_t cb, void * user_data); /********************** * STATIC VARIABLES @@ -166,15 +166,18 @@ void lv_obj_set_parent(lv_obj_t * obj, lv_obj_t * parent) } old_parent->spec_attr->child_cnt--; if(old_parent->spec_attr->child_cnt) { - old_parent->spec_attr->children = lv_mem_realloc(old_parent->spec_attr->children, old_parent->spec_attr->child_cnt * (sizeof(lv_obj_t *))); - } else { + old_parent->spec_attr->children = lv_mem_realloc(old_parent->spec_attr->children, + old_parent->spec_attr->child_cnt * (sizeof(lv_obj_t *))); + } + else { lv_mem_free(old_parent->spec_attr->children); old_parent->spec_attr->children = NULL; } /*Add the child to the new parent as the last (newest child)*/ parent->spec_attr->child_cnt++; - parent->spec_attr->children = lv_mem_realloc(parent->spec_attr->children, parent->spec_attr->child_cnt * (sizeof(lv_obj_t *))); + parent->spec_attr->children = lv_mem_realloc(parent->spec_attr->children, + parent->spec_attr->child_cnt * (sizeof(lv_obj_t *))); parent->spec_attr->children[lv_obj_get_child_cnt(parent) - 1] = obj; obj->parent = parent; @@ -211,13 +214,13 @@ void lv_obj_move_to_index(lv_obj_t * obj, int32_t index) int32_t i = old_index; if(index < old_index) { - while (i > index) { + while(i > index) { parent->spec_attr->children[i] = parent->spec_attr->children[i - 1]; i--; } } else { - while (i < index) { + while(i < index) { parent->spec_attr->children[i] = parent->spec_attr->children[i + 1]; i++; } @@ -247,8 +250,7 @@ void lv_obj_swap(lv_obj_t * obj1, lv_obj_t * obj2) lv_obj_invalidate(parent); - if(parent != parent2) - { + if(parent != parent2) { lv_obj_invalidate(parent2); } lv_group_swap_obj(obj1, obj2); @@ -309,7 +311,8 @@ lv_obj_t * lv_obj_get_child(const lv_obj_t * obj, int32_t id) id = obj->spec_attr->child_cnt + id; if(id < 0) return NULL; idu = (uint32_t) id; - } else { + } + else { idu = id; } @@ -339,7 +342,7 @@ uint32_t lv_obj_get_index(const lv_obj_t * obj) return 0xFFFFFFFF; /*Shouldn't happen*/ } -void lv_obj_tree_walk(lv_obj_t * start_obj, lv_obj_tree_walk_cb_t cb, void* user_data) +void lv_obj_tree_walk(lv_obj_t * start_obj, lv_obj_tree_walk_cb_t cb, void * user_data) { walk_core(start_obj, cb, user_data); } @@ -348,7 +351,7 @@ void lv_obj_tree_walk(lv_obj_t * start_obj, lv_obj_tree_walk_cb_t cb, void* user * STATIC FUNCTIONS **********************/ -static void lv_obj_del_async_cb(void* obj) +static void lv_obj_del_async_cb(void * obj) { LV_ASSERT_OBJ(obj, MY_CLASS); @@ -368,10 +371,10 @@ static void obj_del_core(lv_obj_t * obj) child = lv_obj_get_child(obj, 0); } - lv_group_t* group = lv_obj_get_group(obj); + lv_group_t * group = lv_obj_get_group(obj); /*Reset all input devices if the object to delete is used*/ - lv_indev_t* indev = lv_indev_get_next(NULL); + lv_indev_t * indev = lv_indev_get_next(NULL); while(indev) { if(indev->proc.types.pointer.act_obj == obj || indev->proc.types.pointer.last_obj == obj) { lv_indev_reset(indev, obj); @@ -413,7 +416,8 @@ static void obj_del_core(lv_obj_t * obj) obj->parent->spec_attr->children[i] = obj->parent->spec_attr->children[i + 1]; } obj->parent->spec_attr->child_cnt--; - obj->parent->spec_attr->children = lv_mem_realloc(obj->parent->spec_attr->children, obj->parent->spec_attr->child_cnt * sizeof(lv_obj_t *)); + obj->parent->spec_attr->children = lv_mem_realloc(obj->parent->spec_attr->children, + obj->parent->spec_attr->child_cnt * sizeof(lv_obj_t *)); } /*Free the object itself*/ @@ -421,7 +425,7 @@ static void obj_del_core(lv_obj_t * obj) } -static lv_obj_tree_walk_res_t walk_core(lv_obj_t * obj, lv_obj_tree_walk_cb_t cb, void* user_data) +static lv_obj_tree_walk_res_t walk_core(lv_obj_t * obj, lv_obj_tree_walk_cb_t cb, void * user_data) { lv_obj_tree_walk_res_t res = LV_OBJ_TREE_WALK_NEXT; diff --git a/src/core/lv_obj_tree.h b/src/core/lv_obj_tree.h index bc9219b25..1c714c420 100644 --- a/src/core/lv_obj_tree.h +++ b/src/core/lv_obj_tree.h @@ -91,7 +91,7 @@ void lv_obj_set_parent(struct _lv_obj_t * obj, struct _lv_obj_t * parent); * @param obj1 pointer to the first object * @param obj2 pointer to the second object */ -void lv_obj_swap(struct _lv_obj_t* obj1, struct _lv_obj_t* obj2); +void lv_obj_swap(struct _lv_obj_t * obj1, struct _lv_obj_t * obj2); /** * moves the object to the given index in its parent. @@ -99,9 +99,9 @@ void lv_obj_swap(struct _lv_obj_t* obj1, struct _lv_obj_t* obj2); * @param obj pointer to the object to be moved. * @param index new index in parent. * @note to move to the foreground: lv_obj_move_to_index(obj, 0) - * @note to move forward (up): lv_obj_move_to_index(obj, lv_obj_get_index(obj) - 1) + * @note to move forward (up): lv_obj_move_to_index(obj, lv_obj_get_index(obj) - 1) */ -void lv_obj_move_to_index(struct _lv_obj_t* obj, int32_t index); +void lv_obj_move_to_index(struct _lv_obj_t * obj, int32_t index); /** * Get the screen of an object @@ -150,7 +150,7 @@ uint32_t lv_obj_get_child_cnt(const struct _lv_obj_t * obj); * @return the child index of the object. * E.g. 0: the oldest (firstly created child) */ -uint32_t lv_obj_get_index(const struct _lv_obj_t* obj); +uint32_t lv_obj_get_index(const struct _lv_obj_t * obj); /** * Iterate through all children of any object. diff --git a/src/core/lv_refr.c b/src/core/lv_refr.c index 66a712905..cc6d7e7b9 100644 --- a/src/core/lv_refr.c +++ b/src/core/lv_refr.c @@ -57,9 +57,9 @@ static lv_disp_t * disp_refr; /*Display being refreshed*/ * MACROS **********************/ #if LV_LOG_TRACE_DISP_REFR -# define TRACE_REFR(...) LV_LOG_TRACE( __VA_ARGS__) + #define TRACE_REFR(...) LV_LOG_TRACE( __VA_ARGS__) #else -# define TRACE_REFR(...) + #define TRACE_REFR(...) #endif /********************** @@ -307,7 +307,8 @@ void _lv_disp_refr_timer(lv_timer_t * tmr) uint32_t used_size = mon.total_size - mon.free_size;; uint32_t used_kb = used_size / 1024; uint32_t used_kb_tenth = (used_size - (used_kb * 1024)) / 102; - lv_label_set_text_fmt(mem_label, "%d.%d kB used (%d %%)\n%d%% frag.", used_kb, used_kb_tenth, mon.used_pct, mon.frag_pct); + lv_label_set_text_fmt(mem_label, "%d.%d kB used (%d %%)\n%d%% frag.", used_kb, used_kb_tenth, mon.used_pct, + mon.frag_pct); } #endif @@ -421,7 +422,7 @@ static void lv_refr_area(const lv_area_t * area_p) lv_coord_t w = lv_area_get_width(area_p); lv_coord_t h = lv_area_get_height(area_p); lv_coord_t y2 = area_p->y2 >= lv_disp_get_ver_res(disp_refr) ? - lv_disp_get_ver_res(disp_refr) - 1 : area_p->y2; + lv_disp_get_ver_res(disp_refr) - 1 : area_p->y2; int32_t max_row = (uint32_t)draw_buf->size / w; @@ -495,9 +496,9 @@ static void lv_refr_area_part(const lv_area_t * area_p) /* Below the `area_p` area will be redrawn into the draw buffer. * In single buffered mode wait here until the buffer is freed.*/ if(draw_buf->buf1 && !draw_buf->buf2) { - while(draw_buf->flushing) { - if(disp_refr->driver->wait_cb) disp_refr->driver->wait_cb(disp_refr->driver); - } + while(draw_buf->flushing) { + if(disp_refr->driver->wait_cb) disp_refr->driver->wait_cb(disp_refr->driver); + } } lv_obj_t * top_act_scr = NULL; @@ -641,16 +642,17 @@ static void lv_refr_obj_and_children(lv_obj_t * top_p, const lv_area_t * mask_p) lv_obj_t * child = par->spec_attr->children[i]; if(!go) { if(child == border_p) go = true; - } else { + } + else { /*Refresh the objects*/ lv_refr_obj(child, mask_p); } } /*Call the post draw draw function of the parents of the to object*/ - lv_event_send(par, LV_EVENT_DRAW_POST_BEGIN, (void*)mask_p); - lv_event_send(par, LV_EVENT_DRAW_POST, (void*)mask_p); - lv_event_send(par, LV_EVENT_DRAW_POST_END, (void*)mask_p); + lv_event_send(par, LV_EVENT_DRAW_POST_BEGIN, (void *)mask_p); + lv_event_send(par, LV_EVENT_DRAW_POST, (void *)mask_p); + lv_event_send(par, LV_EVENT_DRAW_POST_END, (void *)mask_p); /*The new border will be the last parents, *so the 'younger' brothers of parent will be refreshed*/ @@ -737,7 +739,8 @@ static void lv_refr_obj(lv_obj_t * obj, const lv_area_t * mask_ori_p) } } -static void draw_buf_rotate_180(lv_disp_drv_t *drv, lv_area_t *area, lv_color_t *color_p) { +static void draw_buf_rotate_180(lv_disp_drv_t * drv, lv_area_t * area, lv_color_t * color_p) +{ lv_coord_t area_w = lv_area_get_width(area); lv_coord_t area_h = lv_area_get_height(area); uint32_t total = area_w * area_h; @@ -760,7 +763,9 @@ static void draw_buf_rotate_180(lv_disp_drv_t *drv, lv_area_t *area, lv_color_t area->x1 = drv->hor_res - tmp_coord - 1; } -static LV_ATTRIBUTE_FAST_MEM void draw_buf_rotate_90(bool invert_i, lv_coord_t area_w, lv_coord_t area_h, lv_color_t *orig_color_p, lv_color_t *rot_buf) { +static LV_ATTRIBUTE_FAST_MEM void draw_buf_rotate_90(bool invert_i, lv_coord_t area_w, lv_coord_t area_h, + lv_color_t * orig_color_p, lv_color_t * rot_buf) +{ uint32_t invert = (area_w * area_h) - 1; uint32_t initial_i = ((area_w - 1) * area_h); @@ -781,7 +786,8 @@ static LV_ATTRIBUTE_FAST_MEM void draw_buf_rotate_90(bool invert_i, lv_coord_t a /** * Helper function for draw_buf_rotate_90_sqr. Given a list of four numbers, rotate the entire list to the left. */ -static inline void draw_buf_rotate4(lv_color_t *a, lv_color_t *b, lv_color_t * c, lv_color_t * d) { +static inline void draw_buf_rotate4(lv_color_t * a, lv_color_t * b, lv_color_t * c, lv_color_t * d) +{ lv_color_t tmp; tmp = *a; *a = *b; @@ -794,9 +800,10 @@ static inline void draw_buf_rotate4(lv_color_t *a, lv_color_t *b, lv_color_t * c * Rotate a square image 90/270 degrees in place. * @note inspired by https://stackoverflow.com/a/43694906 */ -static void draw_buf_rotate_90_sqr(bool is_270, lv_coord_t w, lv_color_t * color_p) { - for(lv_coord_t i = 0; i < w/2; i++) { - for(lv_coord_t j = 0; j < (w + 1)/2; j++) { +static void draw_buf_rotate_90_sqr(bool is_270, lv_coord_t w, lv_color_t * color_p) +{ + for(lv_coord_t i = 0; i < w / 2; i++) { + for(lv_coord_t j = 0; j < (w + 1) / 2; j++) { lv_coord_t inv_i = (w - 1) - i; lv_coord_t inv_j = (w - 1) - j; if(is_270) { @@ -806,7 +813,8 @@ static void draw_buf_rotate_90_sqr(bool is_270, lv_coord_t w, lv_color_t * color &color_p[inv_i * w + inv_j], &color_p[j * w + inv_i] ); - } else { + } + else { draw_buf_rotate4( &color_p[i * w + j], &color_p[j * w + inv_i], @@ -822,7 +830,8 @@ static void draw_buf_rotate_90_sqr(bool is_270, lv_coord_t w, lv_color_t * color /** * Rotate the draw_buf to the display's native orientation. */ -static void draw_buf_rotate(lv_area_t *area, lv_color_t *color_p) { +static void draw_buf_rotate(lv_area_t * area, lv_color_t * color_p) +{ lv_disp_drv_t * drv = disp_refr->driver; if(disp_refr->driver->full_refresh && drv->sw_rotate) { LV_LOG_ERROR("cannot rotate a full refreshed display!"); @@ -831,14 +840,15 @@ static void draw_buf_rotate(lv_area_t *area, lv_color_t *color_p) { if(drv->rotated == LV_DISP_ROT_180) { draw_buf_rotate_180(drv, area, color_p); call_flush_cb(drv, area, color_p); - } else if(drv->rotated == LV_DISP_ROT_90 || drv->rotated == LV_DISP_ROT_270) { + } + else if(drv->rotated == LV_DISP_ROT_90 || drv->rotated == LV_DISP_ROT_270) { /*Allocate a temporary buffer to store rotated image*/ lv_color_t * rot_buf = NULL; lv_disp_draw_buf_t * draw_buf = lv_disp_get_draw_buf(disp_refr); lv_coord_t area_w = lv_area_get_width(area); lv_coord_t area_h = lv_area_get_height(area); /*Determine the maximum number of rows that can be rotated at a time*/ - lv_coord_t max_row = LV_MIN((lv_coord_t)((LV_DISP_ROT_MAX_BUF/sizeof(lv_color_t)) / area_w), area_h); + lv_coord_t max_row = LV_MIN((lv_coord_t)((LV_DISP_ROT_MAX_BUF / sizeof(lv_color_t)) / area_w), area_h); lv_coord_t init_y_off; init_y_off = area->y1; if(drv->rotated == LV_DISP_ROT_90) { @@ -853,7 +863,7 @@ static void draw_buf_rotate(lv_area_t *area, lv_color_t *color_p) { /*Rotate the screen in chunks, flushing after each one*/ lv_coord_t row = 0; while(row < area_h) { - lv_coord_t height = LV_MIN(max_row, area_h-row); + lv_coord_t height = LV_MIN(max_row, area_h - row); draw_buf->flushing = 1; if((row == 0) && (area_h >= area_w)) { /*Rotate the initial area as a square*/ @@ -887,7 +897,8 @@ static void draw_buf_rotate(lv_area_t *area, lv_color_t *color_p) { * Set the original last_part flag on the last part of rotation. */ if(row + height >= area_h && draw_buf->last_area && draw_buf->last_part) { draw_buf->flushing_last = 1; - } else { + } + else { draw_buf->flushing_last = 0; } @@ -917,24 +928,25 @@ static void draw_buf_flush(void) lv_disp_t * disp = _lv_refr_get_disp_refreshing(); if(disp->driver->gpu_wait_cb) disp->driver->gpu_wait_cb(disp->driver); - /* In double buffered mode wait until the other buffer is freed - * and driver is ready to receive the new buffer */ - if(draw_buf->buf1 && draw_buf->buf2) { - while(draw_buf->flushing) { - if(disp_refr->driver->wait_cb) disp_refr->driver->wait_cb(disp_refr->driver); - } - } + /* In double buffered mode wait until the other buffer is freed + * and driver is ready to receive the new buffer */ + if(draw_buf->buf1 && draw_buf->buf2) { + while(draw_buf->flushing) { + if(disp_refr->driver->wait_cb) disp_refr->driver->wait_cb(disp_refr->driver); + } + } - draw_buf->flushing = 1; + draw_buf->flushing = 1; - if(disp_refr->driver->draw_buf->last_area && disp_refr->driver->draw_buf->last_part) draw_buf->flushing_last = 1; - else draw_buf->flushing_last = 0; + if(disp_refr->driver->draw_buf->last_area && disp_refr->driver->draw_buf->last_part) draw_buf->flushing_last = 1; + else draw_buf->flushing_last = 0; if(disp->driver->flush_cb) { /*Rotate the buffer to the display's native orientation if necessary*/ if(disp->driver->rotated != LV_DISP_ROT_NONE && disp->driver->sw_rotate) { draw_buf_rotate(&draw_buf->area, draw_buf->buf_act); - } else { + } + else { call_flush_cb(disp->driver, &draw_buf->area, color_p); } } @@ -948,6 +960,7 @@ static void draw_buf_flush(void) static void call_flush_cb(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_p) { - TRACE_REFR("Calling flush_cb on (%d;%d)(%d;%d) area with %p image pointer", area->x1, area->y1, area->x2, area->y2, color_p); + TRACE_REFR("Calling flush_cb on (%d;%d)(%d;%d) area with %p image pointer", area->x1, area->y1, area->x2, area->y2, + color_p); drv->flush_cb(drv, area, color_p); } diff --git a/src/core/lv_theme.c b/src/core/lv_theme.c index f8a0f50ae..b46cdcc4c 100644 --- a/src/core/lv_theme.c +++ b/src/core/lv_theme.c @@ -33,7 +33,7 @@ static void apply_theme(lv_theme_t * th, lv_obj_t * obj); * GLOBAL FUNCTIONS **********************/ -lv_theme_t * lv_theme_get_from_obj(lv_obj_t * obj) +lv_theme_t * lv_theme_get_from_obj(lv_obj_t * obj) { lv_disp_t * disp = obj ? lv_obj_get_disp(obj) : lv_disp_get_default(); return lv_disp_get_theme(disp); diff --git a/src/core/lv_theme.h b/src/core/lv_theme.h index f287a2c61..f2f390728 100644 --- a/src/core/lv_theme.h +++ b/src/core/lv_theme.h @@ -50,7 +50,7 @@ typedef struct _lv_theme_t { * @param obj pointer to object * @return the theme of the object's display (can be NULL) */ -lv_theme_t * lv_theme_get_from_obj(lv_obj_t * obj); +lv_theme_t * lv_theme_get_from_obj(lv_obj_t * obj); /** * Apply the active theme on an object diff --git a/src/draw/lv_draw_arc.c b/src/draw/lv_draw_arc.c index 3ff102bf5..44084f4d1 100644 --- a/src/draw/lv_draw_arc.c +++ b/src/draw/lv_draw_arc.c @@ -40,11 +40,11 @@ typedef struct { * STATIC PROTOTYPES **********************/ #if LV_DRAW_COMPLEX -static void draw_quarter_0(quarter_draw_dsc_t * q); -static void draw_quarter_1(quarter_draw_dsc_t * q); -static void draw_quarter_2(quarter_draw_dsc_t * q); -static void draw_quarter_3(quarter_draw_dsc_t * q); -static void get_rounded_area(int16_t angle, lv_coord_t radius, uint8_t thickness, lv_area_t * res_area); + static void draw_quarter_0(quarter_draw_dsc_t * q); + static void draw_quarter_1(quarter_draw_dsc_t * q); + static void draw_quarter_2(quarter_draw_dsc_t * q); + static void draw_quarter_3(quarter_draw_dsc_t * q); + static void get_rounded_area(int16_t angle, lv_coord_t radius, uint8_t thickness, lv_area_t * res_area); #endif /*LV_DRAW_COMPLEX*/ /********************** @@ -85,7 +85,8 @@ void lv_draw_arc(lv_coord_t center_x, lv_coord_t center_y, uint16_t radius, uin cir_dsc.bg_opa = LV_OPA_TRANSP; cir_dsc.bg_img_src = dsc->img_src; cir_dsc.bg_img_opa = dsc->opa; - } else { + } + else { cir_dsc.bg_opa = dsc->opa; cir_dsc.bg_color = dsc->color; } @@ -217,7 +218,8 @@ void lv_draw_arc(lv_coord_t center_x, lv_coord_t center_y, uint16_t radius, uin #endif /*LV_DRAW_COMPLEX*/ } -void lv_draw_arc_get_area(lv_coord_t x, lv_coord_t y, uint16_t radius, uint16_t start_angle, uint16_t end_angle, lv_coord_t w, bool rounded, lv_area_t * area) +void lv_draw_arc_get_area(lv_coord_t x, lv_coord_t y, uint16_t radius, uint16_t start_angle, uint16_t end_angle, + lv_coord_t w, bool rounded, lv_area_t * area) { lv_coord_t rout = radius; @@ -275,7 +277,7 @@ void lv_draw_arc_get_area(lv_coord_t x, lv_coord_t y, uint16_t radius, uint16_t else if(start_quarter == 0 && end_quarter == 1) { area->x1 = x + ((lv_trigo_sin(end_angle + 90) * rout) >> LV_TRIGO_SHIFT) - extra_area; area->y1 = y + ((LV_MIN(lv_trigo_sin(end_angle), - lv_trigo_sin(start_angle)) * rin) >> LV_TRIGO_SHIFT) - extra_area; + lv_trigo_sin(start_angle)) * rin) >> LV_TRIGO_SHIFT) - extra_area; area->x2 = x + ((lv_trigo_sin(start_angle + 90) * rout) >> LV_TRIGO_SHIFT) + extra_area; area->y2 = y + rout + extra_area; } @@ -283,7 +285,7 @@ void lv_draw_arc_get_area(lv_coord_t x, lv_coord_t y, uint16_t radius, uint16_t area->x1 = x - rout - extra_area; area->y1 = y + ((lv_trigo_sin(end_angle) * rout) >> LV_TRIGO_SHIFT) - extra_area; area->x2 = x + ((LV_MAX(lv_trigo_sin(start_angle + 90), - lv_trigo_sin(end_angle + 90)) * rin) >> LV_TRIGO_SHIFT) + extra_area; + lv_trigo_sin(end_angle + 90)) * rin) >> LV_TRIGO_SHIFT) + extra_area; area->y2 = y + ((lv_trigo_sin(start_angle) * rout) >> LV_TRIGO_SHIFT) + extra_area; } else if(start_quarter == 2 && end_quarter == 3) { @@ -291,11 +293,11 @@ void lv_draw_arc_get_area(lv_coord_t x, lv_coord_t y, uint16_t radius, uint16_t area->y1 = y - rout - extra_area; area->x2 = x + ((lv_trigo_sin(end_angle + 90) * rout) >> LV_TRIGO_SHIFT) + extra_area; area->y2 = y + (LV_MAX(lv_trigo_sin(end_angle) * rin, - lv_trigo_sin(start_angle) * rin) >> LV_TRIGO_SHIFT) + extra_area; + lv_trigo_sin(start_angle) * rin) >> LV_TRIGO_SHIFT) + extra_area; } else if(start_quarter == 3 && end_quarter == 0) { area->x1 = x + ((LV_MIN(lv_trigo_sin(end_angle + 90), - lv_trigo_sin(start_angle + 90)) * rin) >> LV_TRIGO_SHIFT) - extra_area; + lv_trigo_sin(start_angle + 90)) * rin) >> LV_TRIGO_SHIFT) - extra_area; area->y1 = y + ((lv_trigo_sin(start_angle) * rout) >> LV_TRIGO_SHIFT) - extra_area; area->x2 = x + rout + extra_area; area->y2 = y + ((lv_trigo_sin(end_angle) * rout) >> LV_TRIGO_SHIFT) + extra_area; diff --git a/src/draw/lv_draw_arc.h b/src/draw/lv_draw_arc.h index ed8170936..8868b0fe9 100644 --- a/src/draw/lv_draw_arc.h +++ b/src/draw/lv_draw_arc.h @@ -62,7 +62,8 @@ void lv_draw_arc(lv_coord_t center_x, lv_coord_t center_y, uint16_t radius, uin * @param rounded true: the arc is rounded * @param area store the area to invalidate here */ -void lv_draw_arc_get_area(lv_coord_t x, lv_coord_t y, uint16_t radius, uint16_t start_angle, uint16_t end_angle, lv_coord_t w, bool rounded, lv_area_t * area); +void lv_draw_arc_get_area(lv_coord_t x, lv_coord_t y, uint16_t radius, uint16_t start_angle, uint16_t end_angle, + lv_coord_t w, bool rounded, lv_area_t * area); /********************** * MACROS diff --git a/src/draw/lv_draw_blend.c b/src/draw/lv_draw_blend.c index 8c8958aa5..8f8decdc2 100644 --- a/src/draw/lv_draw_blend.c +++ b/src/draw/lv_draw_blend.c @@ -100,7 +100,7 @@ static inline lv_color_t color_blend_true_color_subtractive(lv_color_t fg, lv_co if(*mask_tmp_x) { \ if(*mask_tmp_x == LV_OPA_COVER) disp_buf_first[x] = map_buf_first[x]; \ else if(disp->driver->screen_transp) lv_color_mix_with_alpha(disp_buf_first[x], disp_buf_first[x].ch.alpha, \ - map_buf_first[x], *mask_tmp_x, &disp_buf_first[x], &disp_buf_first[x].ch.alpha); \ + map_buf_first[x], *mask_tmp_x, &disp_buf_first[x], &disp_buf_first[x].ch.alpha); \ else disp_buf_first[x] = lv_color_mix(map_buf_first[x], disp_buf_first[x], *mask_tmp_x); \ } \ mask_tmp_x++; @@ -210,8 +210,7 @@ LV_ATTRIBUTE_FAST_MEM void _lv_blend_map(const lv_area_t * clip_area, const lv_a draw_area.y2 -= disp_area->y1; /*Round the values in the mask if anti-aliasing is disabled*/ - if(mask && disp->driver->antialiasing == 0) - { + if(mask && disp->driver->antialiasing == 0) { int32_t mask_w = lv_area_get_width(&draw_area); int32_t i; for(i = 0; i < mask_w; i++) mask[i] = mask[i] > 128 ? LV_OPA_COVER : LV_OPA_TRANSP; @@ -266,7 +265,7 @@ static void fill_set_px(const lv_area_t * disp_area, lv_color_t * disp_buf, con for(x = draw_area->x1; x <= draw_area->x2; x++) { if(mask_tmp[x]) { disp->driver->set_px_cb(disp->driver, (void *)disp_buf, disp_w, x, y, color, - (uint32_t)((uint32_t)opa * mask_tmp[x]) >> 8); + (uint32_t)((uint32_t)opa * mask_tmp[x]) >> 8); } } mask_tmp += draw_area_w; @@ -404,11 +403,12 @@ LV_ATTRIBUTE_FAST_MEM static void fill_normal(const lv_area_t * disp_area, lv_co #if LV_COLOR_DEPTH == 16 if((lv_uintptr_t)disp_buf_first & 0x3) { *(disp_buf_first + 0) = color; - uint32_t * d = (uint32_t * )(disp_buf_first + 1); + uint32_t * d = (uint32_t *)(disp_buf_first + 1); *d = c32; *(disp_buf_first + 3) = color; - } else { - uint32_t * d = (uint32_t * )disp_buf_first; + } + else { + uint32_t * d = (uint32_t *)disp_buf_first; *d = c32; *(d + 1) = c32; } @@ -418,7 +418,7 @@ LV_ATTRIBUTE_FAST_MEM static void fill_normal(const lv_area_t * disp_area, lv_co disp_buf_first[2] = color; disp_buf_first[3] = color; #endif - disp_buf_first+= 4; + disp_buf_first += 4; mask += 4; } else if(mask32) { @@ -426,7 +426,8 @@ LV_ATTRIBUTE_FAST_MEM static void fill_normal(const lv_area_t * disp_area, lv_co FILL_NORMAL_MASK_PX(color) FILL_NORMAL_MASK_PX(color) FILL_NORMAL_MASK_PX(color) - } else { + } + else { mask += 4; disp_buf_first += 4; } @@ -435,7 +436,7 @@ LV_ATTRIBUTE_FAST_MEM static void fill_normal(const lv_area_t * disp_area, lv_co for(; x < draw_area_w ; x++) { FILL_NORMAL_MASK_PX(color) } - disp_buf_first += (disp_w-draw_area_w); + disp_buf_first += (disp_w - draw_area_w); } } /*Handle opa and mask values too*/ @@ -614,7 +615,7 @@ static void map_set_px(const lv_area_t * disp_area, lv_color_t * disp_buf, cons for(x = draw_area->x1; x <= draw_area->x2; x++) { if(mask_tmp[x]) { disp->driver->set_px_cb(disp->driver, (void *)disp_buf, disp_w, x, y, map_buf_tmp[x], - (uint32_t)((uint32_t)opa * mask_tmp[x]) >> 8); + (uint32_t)((uint32_t)opa * mask_tmp[x]) >> 8); } } mask_tmp += draw_area_w; diff --git a/src/draw/lv_draw_img.c b/src/draw/lv_draw_img.c index 593c0ecb1..0bd1118dd 100644 --- a/src/draw/lv_draw_img.c +++ b/src/draw/lv_draw_img.c @@ -289,7 +289,7 @@ LV_ATTRIBUTE_FAST_MEM static lv_res_t lv_img_draw_core(const lv_area_t * coords, int32_t width = lv_area_get_width(&mask_com); uint8_t * buf = lv_mem_buf_get(lv_area_get_width(&mask_com) * - LV_IMG_PX_SIZE_ALPHA_BYTE); /*+1 because of the possible alpha byte*/ + LV_IMG_PX_SIZE_ALPHA_BYTE); /*+1 because of the possible alpha byte*/ lv_area_t line; lv_area_copy(&line, &mask_com); @@ -381,7 +381,7 @@ LV_ATTRIBUTE_FAST_MEM static void lv_draw_map(const lv_area_t * map_area, const #endif /*In the other cases every pixel need to be checked one-by-one*/ else { -//#if LV_DRAW_COMPLEX + //#if LV_DRAW_COMPLEX /*The pixel size in byte is different if an alpha byte is added too*/ uint8_t px_size_byte = alpha_byte ? LV_IMG_PX_SIZE_ALPHA_BYTE : sizeof(lv_color_t); @@ -591,7 +591,8 @@ LV_ATTRIBUTE_FAST_MEM static void lv_draw_map(const lv_area_t * map_area, const /*Apply the masks if any*/ if(mask_any) { lv_draw_mask_res_t mask_res_sub; - mask_res_sub = lv_draw_mask_apply(mask_buf + px_i_start, draw_area.x1 + draw_buf->area.x1, y + draw_area.y1 + draw_buf->area.y1, + mask_res_sub = lv_draw_mask_apply(mask_buf + px_i_start, draw_area.x1 + draw_buf->area.x1, + y + draw_area.y1 + draw_buf->area.y1, lv_area_get_width(&draw_area)); if(mask_res_sub == LV_DRAW_MASK_RES_TRANSP) { lv_memset_00(mask_buf + px_i_start, lv_area_get_width(&draw_area)); diff --git a/src/draw/lv_draw_label.c b/src/draw/lv_draw_label.c index 73dea7dea..1121c5749 100644 --- a/src/draw/lv_draw_label.c +++ b/src/draw/lv_draw_label.c @@ -121,7 +121,7 @@ LV_ATTRIBUTE_FAST_MEM void lv_draw_label(const lv_area_t * coords, const lv_area int32_t w; /*No need to waste processor time if string is empty*/ - if (txt == NULL || txt[0] == '\0') + if(txt == NULL || txt[0] == '\0') return; lv_area_t clipped_area; @@ -141,7 +141,7 @@ LV_ATTRIBUTE_FAST_MEM void lv_draw_label(const lv_area_t * coords, const lv_area /*If EXAPND is enabled then not limit the text's width to the object's width*/ lv_point_t p; lv_txt_get_size(&p, txt, dsc->font, dsc->letter_space, dsc->line_space, LV_COORD_MAX, - dsc->flag); + dsc->flag); w = p.x; } @@ -419,8 +419,8 @@ LV_ATTRIBUTE_FAST_MEM void lv_draw_letter(const lv_point_t * pos_p, const lv_are /*Add warning if the dsc is not found *but do not print warning for non printable ASCII chars (e.g. '\n')*/ if(letter >= 0x20 && - letter != 0xf8ff && /*LV_SYMBOL_DUMMY*/ - letter != 0x200c) { /*ZERO WIDTH NON-JOINER*/ + letter != 0xf8ff && /*LV_SYMBOL_DUMMY*/ + letter != 0x200c) { /*ZERO WIDTH NON-JOINER*/ LV_LOG_WARN("lv_draw_letter: glyph dsc. not found for U+%X", letter); } return; @@ -448,11 +448,12 @@ LV_ATTRIBUTE_FAST_MEM void lv_draw_letter(const lv_point_t * pos_p, const lv_are if(font_p->subpx) { #if LV_DRAW_COMPLEX && LV_USE_FONT_SUBPX - draw_letter_subpx(pos_x, pos_y, &g, clip_area, map_p, color, opa, blend_mode); + draw_letter_subpx(pos_x, pos_y, &g, clip_area, map_p, color, opa, blend_mode); #else - LV_LOG_WARN("Can't draw sub-pixel rendered letter because LV_USE_FONT_SUBPX == 0 in lv_conf.h"); + LV_LOG_WARN("Can't draw sub-pixel rendered letter because LV_USE_FONT_SUBPX == 0 in lv_conf.h"); #endif - } else { + } + else { draw_letter_normal(pos_x, pos_y, &g, clip_area, map_p, color, opa, blend_mode); } } diff --git a/src/draw/lv_draw_line.c b/src/draw/lv_draw_line.c index a0eb4c173..d79c597b8 100644 --- a/src/draw/lv_draw_line.c +++ b/src/draw/lv_draw_line.c @@ -182,7 +182,8 @@ LV_ATTRIBUTE_FAST_MEM static void draw_line_hor(const lv_point_t * point1, const int32_t h; for(h = draw_area.y1; h <= draw_area.y2; h++) { lv_memset_ff(mask_buf, draw_area_w); - lv_draw_mask_res_t mask_res = lv_draw_mask_apply(mask_buf, draw_buf->area.x1 + draw_area.x1, draw_buf->area.y1 + h, draw_area_w); + lv_draw_mask_res_t mask_res = lv_draw_mask_apply(mask_buf, draw_buf->area.x1 + draw_area.x1, draw_buf->area.y1 + h, + draw_area_w); if(dashed) { if(mask_res != LV_DRAW_MASK_RES_TRANSP) { @@ -285,7 +286,8 @@ LV_ATTRIBUTE_FAST_MEM static void draw_line_ver(const lv_point_t * point1, const int32_t h; for(h = draw_area.y1; h <= draw_area.y2; h++) { lv_memset_ff(mask_buf, draw_area_w); - lv_draw_mask_res_t mask_res = lv_draw_mask_apply(mask_buf, draw_buf->area.x1 + draw_area.x1, draw_buf->area.y1 + h, draw_area_w); + lv_draw_mask_res_t mask_res = lv_draw_mask_apply(mask_buf, draw_buf->area.x1 + draw_area.x1, draw_buf->area.y1 + h, + draw_area_w); if(dashed) { if(mask_res != LV_DRAW_MASK_RES_TRANSP) { diff --git a/src/draw/lv_draw_mask.c b/src/draw/lv_draw_mask.c index d7ea81774..9860d4b00 100644 --- a/src/draw/lv_draw_mask.c +++ b/src/draw/lv_draw_mask.c @@ -53,7 +53,8 @@ static void circ_init(lv_point_t * c, lv_coord_t * tmp, lv_coord_t radius); static bool circ_cont(lv_point_t * c); static void circ_next(lv_point_t * c, lv_coord_t * tmp); static void circ_calc_aa4(_lv_draw_mask_radius_circle_dsc_t * c, lv_coord_t radius); -static lv_opa_t * get_next_line(_lv_draw_mask_radius_circle_dsc_t * c, lv_coord_t y, lv_coord_t * len, lv_coord_t * x_start); +static lv_opa_t * get_next_line(_lv_draw_mask_radius_circle_dsc_t * c, lv_coord_t y, lv_coord_t * len, + lv_coord_t * x_start); LV_ATTRIBUTE_FAST_MEM static inline lv_opa_t mask_mix(lv_opa_t mask_act, lv_opa_t mask_new); /********************** @@ -179,7 +180,8 @@ void lv_draw_mask_free_param(void * p) if(radius_p->circle->life < 0) { lv_mem_free(radius_p->circle->cir_opa); lv_mem_free(radius_p->circle); - } else { + } + else { radius_p->circle->used_cnt--; } } @@ -227,7 +229,8 @@ bool lv_draw_mask_is_any(const lv_area_t * a) else { if(!_lv_area_is_in(a, &radius_param->cfg.rect, radius_param->cfg.radius)) return true; } - } else { + } + else { return true; } } @@ -476,7 +479,8 @@ void lv_draw_mask_radius_init(lv_draw_mask_radius_param_t * param, const lv_area LV_ASSERT_MALLOC(entry); lv_memset_00(entry, sizeof(_lv_draw_mask_radius_circle_dsc_t)); entry->life = -1; - } else { + } + else { entry->used_cnt++; entry->life = 0; CIRCLE_CACHE_AGING(entry->life, radius); @@ -1035,13 +1039,13 @@ LV_ATTRIBUTE_FAST_MEM static lv_draw_mask_res_t lv_draw_mask_radius(lv_opa_t * m } return LV_DRAW_MASK_RES_CHANGED; } -// printf("exec: x:%d.. %d, y:%d: r:%d, %s\n", abs_x, abs_x + len - 1, abs_y, p->cfg.radius, p->cfg.outer ? "inv" : "norm"); + // printf("exec: x:%d.. %d, y:%d: r:%d, %s\n", abs_x, abs_x + len - 1, abs_y, p->cfg.radius, p->cfg.outer ? "inv" : "norm"); -// if( abs_x == 276 && abs_x + len - 1 == 479 && abs_y == 63 && p->cfg.radius == 5 && p->cfg.outer == 1) { -// char x = 0; -// } -//exec: x:276.. 479, y:63: r:5, inv) + // if( abs_x == 276 && abs_x + len - 1 == 479 && abs_y == 63 && p->cfg.radius == 5 && p->cfg.outer == 1) { + // char x = 0; + // } + //exec: x:276.. 479, y:63: r:5, inv) int32_t k = rect.x1 - abs_x; /*First relevant coordinate on the of the mask*/ int32_t w = lv_area_get_width(&rect); @@ -1054,7 +1058,8 @@ LV_ATTRIBUTE_FAST_MEM static lv_draw_mask_res_t lv_draw_mask_radius(lv_opa_t * m lv_coord_t cir_y; if(abs_y < radius) { cir_y = radius - abs_y - 1; - } else { + } + else { cir_y = abs_y - (h - radius); } lv_opa_t * aa_opa = get_next_line(p->circle, cir_y, &aa_len, &x_start); @@ -1080,7 +1085,8 @@ LV_ATTRIBUTE_FAST_MEM static lv_draw_mask_res_t lv_draw_mask_radius(lv_opa_t * m /*Clean the left side*/ cir_x_left = LV_CLAMP(0, cir_x_left - aa_len + 1, len); lv_memset_00(&mask_buf[0], cir_x_left); - } else { + } + else { for(i = 0; i < aa_len; i++) { lv_opa_t opa = 255 - (aa_opa[aa_len - 1 - i]); if(cir_x_right + i >= 0 && cir_x_right + i < len) { @@ -1212,7 +1218,8 @@ static void circ_next(lv_point_t * c, lv_coord_t * tmp) if(*tmp <= 0) { (*tmp) += 2 * c->y + 3; /*Change in decision criterion for y -> y+1*/ - } else { + } + else { (*tmp) += 2 * (c->y - c->x) + 5; /*Change for y -> y+1, x -> x-1*/ c->x--; } @@ -1230,8 +1237,8 @@ static void circ_calc_aa4(_lv_draw_mask_radius_circle_dsc_t * c, lv_coord_t radi c->buf = lv_mem_alloc(radius * 6 + 6); /*Use uint16_t for opa_start_on_y and x_start_on_y*/ LV_ASSERT_MALLOC(c->buf); c->cir_opa = c->buf; - c->opa_start_on_y = (uint16_t *) (c->buf + 2 * radius + 2); - c->x_start_on_y = (uint16_t *) (c->buf + 4 * radius + 4); + c->opa_start_on_y = (uint16_t *)(c->buf + 2 * radius + 2); + c->x_start_on_y = (uint16_t *)(c->buf + 4 * radius + 4); /*Special case, handle manually*/ if(radius == 1) { @@ -1325,12 +1332,13 @@ static void circ_calc_aa4(_lv_draw_mask_radius_circle_dsc_t * c, lv_coord_t radi /*The point on the 1/8 circle is special, calculate it manually*/ int32_t mid = radius * 723; int32_t mid_int = mid >> 10; - if(cir_x[cir_size-1] != mid_int || cir_y[cir_size-1] != mid_int) { + if(cir_x[cir_size - 1] != mid_int || cir_y[cir_size - 1] != mid_int) { int32_t tmp_val = mid - (mid_int << 10); if(tmp_val <= 512) { tmp_val = tmp_val * tmp_val * 2; tmp_val = tmp_val >> (10 + 6); - } else { + } + else { tmp_val = 1024 - tmp_val; tmp_val = tmp_val * tmp_val * 2; tmp_val = tmp_val >> (10 + 6); @@ -1366,7 +1374,8 @@ static void circ_calc_aa4(_lv_draw_mask_radius_circle_dsc_t * c, lv_coord_t radi lv_mem_buf_release(cir_x); } -static lv_opa_t * get_next_line(_lv_draw_mask_radius_circle_dsc_t * c, lv_coord_t y, lv_coord_t * len, lv_coord_t * x_start) +static lv_opa_t * get_next_line(_lv_draw_mask_radius_circle_dsc_t * c, lv_coord_t y, lv_coord_t * len, + lv_coord_t * x_start) { *len = c->opa_start_on_y[y + 1] - c->opa_start_on_y[y]; *x_start = c->x_start_on_y[y]; diff --git a/src/draw/lv_draw_rect.c b/src/draw/lv_draw_rect.c index 9af8b5bae..341a97621 100644 --- a/src/draw/lv_draw_rect.c +++ b/src/draw/lv_draw_rect.c @@ -31,7 +31,7 @@ LV_ATTRIBUTE_FAST_MEM static void draw_bg(const lv_area_t * coords, const lv_area_t * clip_area, const lv_draw_rect_dsc_t * dsc); LV_ATTRIBUTE_FAST_MEM static void draw_bg_img(const lv_area_t * coords, const lv_area_t * clip, - const lv_draw_rect_dsc_t * dsc); + const lv_draw_rect_dsc_t * dsc); LV_ATTRIBUTE_FAST_MEM static void draw_border(const lv_area_t * coords, const lv_area_t * clip, const lv_draw_rect_dsc_t * dsc); @@ -49,10 +49,10 @@ void draw_border_generic(const lv_area_t * clip_area, const lv_area_t * outer_ar lv_coord_t rout, lv_coord_t rin, lv_color_t color, lv_opa_t opa, lv_blend_mode_t blend_mode); static void draw_border_simple(const lv_area_t * clip, const lv_area_t * outer_area, const lv_area_t * inner_area, - lv_color_t color, lv_opa_t opa); + lv_color_t color, lv_opa_t opa); #if LV_DRAW_COMPLEX -LV_ATTRIBUTE_FAST_MEM static inline lv_color_t grad_get(const lv_draw_rect_dsc_t * dsc, lv_coord_t s, lv_coord_t i); + LV_ATTRIBUTE_FAST_MEM static inline lv_color_t grad_get(const lv_draw_rect_dsc_t * dsc, lv_coord_t s, lv_coord_t i); #endif /********************** @@ -283,7 +283,7 @@ LV_ATTRIBUTE_FAST_MEM static void draw_bg(const lv_area_t * coords, const lv_are blend_area.y1 = h; blend_area.y2 = h; if(grad_dir == LV_GRAD_DIR_NONE) { - _lv_blend_fill(clip_area, &blend_area, dsc->bg_color, mask_buf, mask_res, opa, dsc->blend_mode); + _lv_blend_fill(clip_area, &blend_area, dsc->bg_color, mask_buf, mask_res, opa, dsc->blend_mode); } else if(grad_dir == LV_GRAD_DIR_HOR) { _lv_blend_map(clip_area, &blend_area, grad_map, mask_buf, mask_res, opa, dsc->blend_mode); @@ -308,7 +308,7 @@ bg_clean_up: } LV_ATTRIBUTE_FAST_MEM static void draw_bg_img(const lv_area_t * coords, const lv_area_t * clip, - const lv_draw_rect_dsc_t * dsc) + const lv_draw_rect_dsc_t * dsc) { if(dsc->bg_img_src == NULL) return; if(dsc->bg_img_opa <= LV_OPA_MIN) return; @@ -354,7 +354,8 @@ LV_ATTRIBUTE_FAST_MEM static void draw_bg_img(const lv_area_t * coords, const lv area.y2 = area.y1 + header.h - 1; lv_draw_img(&area, clip, dsc->bg_img_src, &img_dsc); - } else { + } + else { lv_area_t area; area.y1 = coords->y1; area.y2 = area.y1 + header.h - 1; @@ -621,9 +622,11 @@ LV_ATTRIBUTE_FAST_MEM static void draw_shadow(const lv_area_t * coords, const lv mask_res = lv_draw_mask_apply(mask_buf, clip_area_sub.x1, y, w); if(mask_res == LV_DRAW_MASK_RES_FULL_COVER) mask_res = LV_DRAW_MASK_RES_CHANGED; _lv_blend_fill(&clip_area_sub, &blend_area, dsc->shadow_color, mask_buf, mask_res, dsc->shadow_opa, dsc->blend_mode); - } else { + } + else { lv_opa_t line_opa = opa == LV_OPA_COVER ? sh_buf_tmp[0] : (sh_buf_tmp[0] * dsc->shadow_opa) >> 8; - _lv_blend_fill(&clip_area_sub, &blend_area, dsc->shadow_color, NULL, LV_DRAW_MASK_RES_FULL_COVER, line_opa, dsc->blend_mode); + _lv_blend_fill(&clip_area_sub, &blend_area, dsc->shadow_color, NULL, LV_DRAW_MASK_RES_FULL_COVER, line_opa, + dsc->blend_mode); } sh_buf_tmp += corner_size; } @@ -655,9 +658,11 @@ LV_ATTRIBUTE_FAST_MEM static void draw_shadow(const lv_area_t * coords, const lv mask_res = lv_draw_mask_apply(mask_buf, clip_area_sub.x1, y, w); if(mask_res == LV_DRAW_MASK_RES_FULL_COVER) mask_res = LV_DRAW_MASK_RES_CHANGED; _lv_blend_fill(&clip_area_sub, &blend_area, dsc->shadow_color, mask_buf, mask_res, dsc->shadow_opa, dsc->blend_mode); - } else { + } + else { lv_opa_t line_opa = opa == LV_OPA_COVER ? sh_buf_tmp[0] : (sh_buf_tmp[0] * dsc->shadow_opa) >> 8; - _lv_blend_fill(&clip_area_sub, &blend_area, dsc->shadow_color, NULL, LV_DRAW_MASK_RES_FULL_COVER, line_opa, dsc->blend_mode); + _lv_blend_fill(&clip_area_sub, &blend_area, dsc->shadow_color, NULL, LV_DRAW_MASK_RES_FULL_COVER, line_opa, + dsc->blend_mode); } sh_buf_tmp += corner_size; @@ -1145,8 +1150,7 @@ void draw_border_generic(const lv_area_t * clip_area, const lv_area_t * outer_ar bool split_hor = true; if(left_side && right_side && top_side && bottom_side && - core_w < SPLIT_LIMIT) - { + core_w < SPLIT_LIMIT) { split_hor = false; } @@ -1212,7 +1216,8 @@ void draw_border_generic(const lv_area_t * clip_area, const lv_area_t * outer_ar _lv_blend_fill(clip_area, &blend_area, color, mask_buf, mask_res, opa, blend_mode); } } - } else { + } + else { /*Left corners*/ blend_area.x1 = draw_area.x1; blend_area.x2 = LV_MIN(draw_area.x2, core_area.x1 - 1); @@ -1283,7 +1288,7 @@ void draw_border_generic(const lv_area_t * clip_area, const lv_area_t * outer_ar } static void draw_border_simple(const lv_area_t * clip, const lv_area_t * outer_area, const lv_area_t * inner_area, - lv_color_t color, lv_opa_t opa) + lv_color_t color, lv_opa_t opa) { bool top_side = outer_area->y1 <= inner_area->y1 ? true : false; bool bottom_side = outer_area->y2 >= inner_area->y2 ? true : false; diff --git a/src/draw/lv_draw_rect.h b/src/draw/lv_draw_rect.h index f4d05922b..5ad45d836 100644 --- a/src/draw/lv_draw_rect.h +++ b/src/draw/lv_draw_rect.h @@ -37,7 +37,7 @@ typedef struct { uint8_t bg_main_color_stop; uint8_t bg_grad_color_stop; lv_opa_t bg_opa; - lv_grad_dir_t bg_grad_dir :3; + lv_grad_dir_t bg_grad_dir : 3; /*Background img*/ const void * bg_img_src; @@ -52,7 +52,7 @@ typedef struct { lv_coord_t border_width; lv_opa_t border_opa; uint8_t border_post : 1; /*There is a border it will be drawn later.*/ - lv_border_side_t border_side :5; + lv_border_side_t border_side : 5; /*Outline*/ lv_color_t outline_color; diff --git a/src/draw/lv_img_buf.c b/src/draw/lv_img_buf.c index 36083563e..07ea03c52 100644 --- a/src/draw/lv_img_buf.c +++ b/src/draw/lv_img_buf.c @@ -367,7 +367,7 @@ void lv_img_buf_free(lv_img_dsc_t * dsc) { if(dsc != NULL) { if(dsc->data != NULL) - lv_mem_free((void*)dsc->data); + lv_mem_free((void *)dsc->data); lv_mem_free(dsc); } @@ -710,7 +710,7 @@ bool _lv_img_buf_transform_anti_alias(lv_img_transform_dsc_t * dsc) 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)); + 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]; a01 = src_u8[dsc->tmp.pxi + dsc->cfg.src_w * dsc->tmp.px_size * yn + dsc->tmp.px_size - 1]; diff --git a/src/draw/lv_img_decoder.c b/src/draw/lv_img_decoder.c index 886a65958..1bf21162e 100644 --- a/src/draw/lv_img_decoder.c +++ b/src/draw/lv_img_decoder.c @@ -159,7 +159,7 @@ lv_res_t lv_img_decoder_open(lv_img_decoder_dsc_t * dsc, const void * src, lv_co } if(dsc->src_type == LV_IMG_SRC_FILE) - lv_mem_free((void*)dsc->src); + lv_mem_free((void *)dsc->src); return res; } @@ -191,7 +191,7 @@ void lv_img_decoder_close(lv_img_decoder_dsc_t * dsc) if(dsc->decoder->close_cb) dsc->decoder->close_cb(dsc->decoder, dsc); if(dsc->src_type == LV_IMG_SRC_FILE) { - lv_mem_free((void*)dsc->src); + lv_mem_free((void *)dsc->src); dsc->src = NULL; } } @@ -594,7 +594,7 @@ static lv_res_t lv_img_decoder_built_in_line_alpha(lv_img_decoder_dsc_t * dsc, l lv_img_decoder_built_in_data_t * user_data = dsc->user_data; uint8_t * fs_buf = lv_mem_buf_get(w); - if (fs_buf == NULL) return LV_RES_INV; + if(fs_buf == NULL) return LV_RES_INV; const uint8_t * data_tmp = NULL; if(dsc->src_type == LV_IMG_SRC_VARIABLE) { @@ -663,7 +663,7 @@ static lv_res_t lv_img_decoder_built_in_line_indexed(lv_img_decoder_dsc_t * dsc, lv_img_decoder_built_in_data_t * user_data = dsc->user_data; uint8_t * fs_buf = lv_mem_buf_get(w); - if (fs_buf == NULL) return LV_RES_INV; + if(fs_buf == NULL) return LV_RES_INV; const uint8_t * data_tmp = NULL; if(dsc->src_type == LV_IMG_SRC_VARIABLE) { const lv_img_dsc_t * img_dsc = dsc->src; diff --git a/src/extra/layouts/flex/lv_flex.c b/src/extra/layouts/flex/lv_flex.c index c618d16f1..7813123a4 100644 --- a/src/extra/layouts/flex/lv_flex.c +++ b/src/extra/layouts/flex/lv_flex.c @@ -21,10 +21,10 @@ typedef struct { lv_flex_align_t main_place; lv_flex_align_t cross_place; lv_flex_align_t track_place; - uint8_t row :1; - uint8_t wrap :1; - uint8_t rev :1; -}flex_t; + uint8_t row : 1; + uint8_t wrap : 1; + uint8_t rev : 1; +} flex_t; typedef struct { lv_obj_t * item; @@ -32,8 +32,8 @@ typedef struct { lv_coord_t max_size; lv_coord_t final_size; uint32_t grow_value; - uint32_t clamped :1; -}grow_dsc_t; + uint32_t clamped : 1; +} grow_dsc_t; typedef struct { lv_coord_t track_cross_size; @@ -42,8 +42,8 @@ typedef struct { uint32_t item_cnt; grow_dsc_t * grow_dsc; uint32_t grow_item_cnt; - uint32_t grow_dsc_calc :1; -}track_t; + uint32_t grow_dsc_calc : 1; +} track_t; /********************** @@ -54,9 +54,12 @@ typedef struct { * STATIC PROTOTYPES **********************/ static void flex_update(lv_obj_t * cont, void * user_data); -static int32_t find_track_end(lv_obj_t * cont, flex_t * f, int32_t item_start_id, lv_coord_t item_gap, lv_coord_t max_main_size, track_t * t); -static void children_repos(lv_obj_t * cont, flex_t * f, int32_t item_first_id, int32_t item_last_id, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t max_main_size, lv_coord_t item_gap, track_t * t); -static void place_content(lv_flex_align_t place, lv_coord_t max_size, lv_coord_t content_size, lv_coord_t item_cnt, lv_coord_t * start_pos, lv_coord_t * gap); +static int32_t find_track_end(lv_obj_t * cont, flex_t * f, int32_t item_start_id, lv_coord_t item_gap, + lv_coord_t max_main_size, track_t * t); +static void children_repos(lv_obj_t * cont, flex_t * f, int32_t item_first_id, int32_t item_last_id, lv_coord_t abs_x, + lv_coord_t abs_y, lv_coord_t max_main_size, lv_coord_t item_gap, track_t * t); +static void place_content(lv_flex_align_t place, lv_coord_t max_size, lv_coord_t content_size, lv_coord_t item_cnt, + lv_coord_t * start_pos, lv_coord_t * gap); static lv_obj_t * get_next_item(lv_obj_t * cont, bool rev, int32_t * item_id); /********************** @@ -102,7 +105,8 @@ void lv_obj_set_flex_flow(lv_obj_t * obj, lv_flex_flow_t flow) lv_obj_set_style_layout(obj, LV_LAYOUT_FLEX, 0); } -void lv_obj_set_flex_align(lv_obj_t * obj, lv_flex_align_t main_place, lv_flex_align_t cross_place, lv_flex_align_t track_place) +void lv_obj_set_flex_align(lv_obj_t * obj, lv_flex_align_t main_place, lv_flex_align_t cross_place, + lv_flex_align_t track_place) { lv_obj_set_style_flex_main_place(obj, main_place, 0); lv_obj_set_style_flex_cross_place(obj, cross_place, 0); @@ -152,7 +156,7 @@ void lv_style_set_flex_track_place(lv_style_t * style, lv_flex_align_t value) void lv_style_set_flex_grow(lv_style_t * style, uint8_t value) { lv_style_value_t v = { - .num = (int32_t)value + .num = (int32_t)value }; lv_style_set_prop(style, LV_STYLE_FLEX_GROW, v); } @@ -217,12 +221,16 @@ static void flex_update(lv_obj_t * cont, void * user_data) f.track_place = lv_obj_get_style_flex_track_place(cont, LV_PART_MAIN); bool rtl = lv_obj_get_style_base_dir(cont, LV_PART_MAIN) == LV_BASE_DIR_RTL ? true : false; - lv_coord_t track_gap = !f.row ? lv_obj_get_style_pad_column(cont, LV_PART_MAIN) : lv_obj_get_style_pad_row(cont, LV_PART_MAIN); - lv_coord_t item_gap = f.row ? lv_obj_get_style_pad_column(cont, LV_PART_MAIN) : lv_obj_get_style_pad_row(cont, LV_PART_MAIN); + lv_coord_t track_gap = !f.row ? lv_obj_get_style_pad_column(cont, LV_PART_MAIN) : lv_obj_get_style_pad_row(cont, + LV_PART_MAIN); + lv_coord_t item_gap = f.row ? lv_obj_get_style_pad_column(cont, LV_PART_MAIN) : lv_obj_get_style_pad_row(cont, + LV_PART_MAIN); lv_coord_t max_main_size = (f.row ? lv_obj_get_content_width(cont) : lv_obj_get_content_height(cont)); lv_coord_t border_widt = lv_obj_get_style_border_width(cont, LV_PART_MAIN); - lv_coord_t abs_y = cont->coords.y1 + lv_obj_get_style_pad_top(cont, LV_PART_MAIN) + border_widt - lv_obj_get_scroll_y(cont); - lv_coord_t abs_x = cont->coords.x1 + lv_obj_get_style_pad_left(cont, LV_PART_MAIN) + border_widt - lv_obj_get_scroll_x(cont); + lv_coord_t abs_y = cont->coords.y1 + lv_obj_get_style_pad_top(cont, + LV_PART_MAIN) + border_widt - lv_obj_get_scroll_y(cont); + lv_coord_t abs_x = cont->coords.x1 + lv_obj_get_style_pad_left(cont, + LV_PART_MAIN) + border_widt - lv_obj_get_scroll_x(cont); lv_flex_align_t track_cross_place = f.track_place; lv_coord_t * cross_pos = (f.row ? &abs_y : &abs_x); @@ -232,8 +240,7 @@ static void flex_update(lv_obj_t * cont, void * user_data) /*Content sized objects should squeezed the gap between the children, therefore any alignment will look like `START`*/ if((f.row && h_set == LV_SIZE_CONTENT && cont->h_layout == 0) || - (!f.row && w_set == LV_SIZE_CONTENT && cont->w_layout == 0)) - { + (!f.row && w_set == LV_SIZE_CONTENT && cont->w_layout == 0)) { track_cross_place = LV_FLEX_ALIGN_START; } @@ -270,7 +277,7 @@ static void flex_update(lv_obj_t * cont, void * user_data) track_first_item = f.rev ? cont->spec_attr->child_cnt - 1 : 0; if(rtl && !f.row) { - *cross_pos += total_track_cross_size; + *cross_pos += total_track_cross_size; } while(track_first_item < (int32_t)cont->spec_attr->child_cnt && track_first_item >= 0) { @@ -288,7 +295,8 @@ static void flex_update(lv_obj_t * cont, void * user_data) t.grow_dsc = NULL; if(rtl && !f.row) { *cross_pos -= gap + track_gap; - } else { + } + else { *cross_pos += t.track_cross_size + gap + track_gap; } } @@ -306,7 +314,8 @@ static void flex_update(lv_obj_t * cont, void * user_data) /** * Find the last item of a track */ -static int32_t find_track_end(lv_obj_t * cont, flex_t * f, int32_t item_start_id, lv_coord_t max_main_size, lv_coord_t item_gap, track_t * t) +static int32_t find_track_end(lv_obj_t * cont, flex_t * f, int32_t item_start_id, lv_coord_t max_main_size, + lv_coord_t item_gap, track_t * t) { lv_coord_t w_set = lv_obj_get_style_width(cont, LV_PART_MAIN); lv_coord_t h_set = lv_obj_get_style_height(cont, LV_PART_MAIN); @@ -348,13 +357,16 @@ static int32_t find_track_end(lv_obj_t * cont, flex_t * f, int32_t item_start_id lv_mem_buf_release(t->grow_dsc); } new_dsc[t->grow_item_cnt - 1].item = item; - new_dsc[t->grow_item_cnt - 1].min_size = f->row ? lv_obj_get_style_min_width(item, LV_PART_MAIN) : lv_obj_get_style_min_height(item, LV_PART_MAIN); - new_dsc[t->grow_item_cnt - 1].max_size = f->row ? lv_obj_get_style_max_width(item, LV_PART_MAIN) : lv_obj_get_style_max_height(item, LV_PART_MAIN); + new_dsc[t->grow_item_cnt - 1].min_size = f->row ? lv_obj_get_style_min_width(item, + LV_PART_MAIN) : lv_obj_get_style_min_height(item, LV_PART_MAIN); + new_dsc[t->grow_item_cnt - 1].max_size = f->row ? lv_obj_get_style_max_width(item, + LV_PART_MAIN) : lv_obj_get_style_max_height(item, LV_PART_MAIN); new_dsc[t->grow_item_cnt - 1].grow_value = grow_value; new_dsc[t->grow_item_cnt - 1].clamped = 0; t->grow_dsc = new_dsc; } - } else { + } + else { lv_coord_t item_size = get_main_size(item); if(f->wrap && t->track_fix_main_size + item_size > max_main_size) break; t->track_fix_main_size += item_size + item_gap; @@ -392,7 +404,8 @@ static int32_t find_track_end(lv_obj_t * cont, flex_t * f, int32_t item_start_id /** * Position the children in the same track */ -static void children_repos(lv_obj_t * cont, flex_t * f, int32_t item_first_id, int32_t item_last_id, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t max_main_size, lv_coord_t item_gap, track_t * t) +static void children_repos(lv_obj_t * cont, flex_t * f, int32_t item_first_id, int32_t item_last_id, lv_coord_t abs_x, + lv_coord_t abs_y, lv_coord_t max_main_size, lv_coord_t item_gap, track_t * t) { void (*area_set_main_size)(lv_area_t *, lv_coord_t) = (f->row ? lv_area_set_width : lv_area_set_height); lv_coord_t (*area_get_main_size)(const lv_area_t *) = (f->row ? lv_area_get_width : lv_area_get_height); @@ -408,7 +421,8 @@ static void children_repos(lv_obj_t * cont, flex_t * f, int32_t item_first_id, i for(i = 0; i < t->grow_item_cnt; i++) { if(t->grow_dsc[i].clamped == 0) { grow_value_sum += t->grow_dsc[i].grow_value; - } else { + } + else { grow_max_size -= t->grow_dsc[i].final_size; } } @@ -470,23 +484,24 @@ static void children_repos(lv_obj_t * cont, flex_t * f, int32_t item_first_id, i lv_event_send(lv_obj_get_parent(item), LV_EVENT_CHILD_CHANGED, item); lv_obj_invalidate(item); } - } else { + } + else { item->w_layout = 0; item->h_layout = 0; } lv_coord_t cross_pos = 0; switch(f->cross_place) { - case LV_FLEX_ALIGN_CENTER: - /*Round up the cross size to avoid rounding error when dividing by 2 - *The issue comes up e,g, with column direction with center cross direction if an element's width changes*/ - cross_pos = (((t->track_cross_size + 1) & (~1)) - area_get_cross_size(&item->coords)) / 2; - break; - case LV_FLEX_ALIGN_END: - cross_pos = t->track_cross_size - area_get_cross_size(&item->coords); - break; - default: - break; + case LV_FLEX_ALIGN_CENTER: + /*Round up the cross size to avoid rounding error when dividing by 2 + *The issue comes up e,g, with column direction with center cross direction if an element's width changes*/ + cross_pos = (((t->track_cross_size + 1) & (~1)) - area_get_cross_size(&item->coords)) / 2; + break; + case LV_FLEX_ALIGN_END: + cross_pos = t->track_cross_size - area_get_cross_size(&item->coords); + break; + default: + break; } if(f->row && rtl) main_pos -= area_get_main_size(&item->coords); @@ -525,7 +540,8 @@ static void children_repos(lv_obj_t * cont, flex_t * f, int32_t item_first_id, i /** * Tell a start coordinate and gap for a placement type. */ -static void place_content(lv_flex_align_t place, lv_coord_t max_size, lv_coord_t content_size, lv_coord_t item_cnt, lv_coord_t * start_pos, lv_coord_t * gap) +static void place_content(lv_flex_align_t place, lv_coord_t max_size, lv_coord_t content_size, lv_coord_t item_cnt, + lv_coord_t * start_pos, lv_coord_t * gap) { if(item_cnt <= 1) { switch(place) { @@ -540,27 +556,27 @@ static void place_content(lv_flex_align_t place, lv_coord_t max_size, lv_coord_t } switch(place) { - case LV_FLEX_ALIGN_CENTER: - *gap = 0; - *start_pos += (max_size - content_size) / 2; - break; - case LV_FLEX_ALIGN_END: - *gap = 0; - *start_pos += max_size - content_size; - break; - case LV_FLEX_ALIGN_SPACE_BETWEEN: - *gap = (lv_coord_t)(max_size - content_size) / (lv_coord_t)(item_cnt - 1); - break; - case LV_FLEX_ALIGN_SPACE_AROUND: - *gap += (lv_coord_t)(max_size - content_size) / (lv_coord_t)(item_cnt); - *start_pos += *gap / 2; - break; - case LV_FLEX_ALIGN_SPACE_EVENLY: - *gap = (lv_coord_t)(max_size - content_size) / (lv_coord_t)(item_cnt + 1); - *start_pos += *gap; - break; - default: - *gap = 0; + case LV_FLEX_ALIGN_CENTER: + *gap = 0; + *start_pos += (max_size - content_size) / 2; + break; + case LV_FLEX_ALIGN_END: + *gap = 0; + *start_pos += max_size - content_size; + break; + case LV_FLEX_ALIGN_SPACE_BETWEEN: + *gap = (lv_coord_t)(max_size - content_size) / (lv_coord_t)(item_cnt - 1); + break; + case LV_FLEX_ALIGN_SPACE_AROUND: + *gap += (lv_coord_t)(max_size - content_size) / (lv_coord_t)(item_cnt); + *start_pos += *gap / 2; + break; + case LV_FLEX_ALIGN_SPACE_EVENLY: + *gap = (lv_coord_t)(max_size - content_size) / (lv_coord_t)(item_cnt + 1); + *start_pos += *gap; + break; + default: + *gap = 0; } } @@ -570,7 +586,8 @@ static lv_obj_t * get_next_item(lv_obj_t * cont, bool rev, int32_t * item_id) (*item_id)--; if(*item_id >= 0) return cont->spec_attr->children[*item_id]; else return NULL; - } else { + } + else { (*item_id)++; if((*item_id) < (int32_t)cont->spec_attr->child_cnt) return cont->spec_attr->children[*item_id]; else return NULL; diff --git a/src/extra/layouts/flex/lv_flex.h b/src/extra/layouts/flex/lv_flex.h index 4a8bdd558..139fd4810 100644 --- a/src/extra/layouts/flex/lv_flex.h +++ b/src/extra/layouts/flex/lv_flex.h @@ -41,7 +41,7 @@ typedef enum { LV_FLEX_ALIGN_SPACE_EVENLY, LV_FLEX_ALIGN_SPACE_AROUND, LV_FLEX_ALIGN_SPACE_BETWEEN, -}lv_flex_align_t; +} lv_flex_align_t; typedef enum { LV_FLEX_FLOW_ROW = 0x00, @@ -52,7 +52,7 @@ typedef enum { LV_FLEX_FLOW_COLUMN_WRAP = LV_FLEX_FLOW_COLUMN | _LV_FLEX_WRAP, LV_FLEX_FLOW_COLUMN_REVERSE = LV_FLEX_FLOW_COLUMN | _LV_FLEX_REVERSE, LV_FLEX_FLOW_COLUMN_WRAP_REVERSE = LV_FLEX_FLOW_COLUMN | _LV_FLEX_WRAP | _LV_FLEX_REVERSE, -}lv_flex_flow_t; +} lv_flex_flow_t; /********************** * GLOBAL VARIABLES @@ -88,7 +88,8 @@ void lv_obj_set_flex_flow(lv_obj_t * obj, lv_flex_flow_t flow); * @param cross_place where to place the item in their track on the cross axis. `LV_FLEX_ALIGN_START/END/CENTER` * @param track_place where to place the tracks in the cross direction. Any value of `lv_flex_align_t`. */ -void lv_obj_set_flex_align(lv_obj_t * obj, lv_flex_align_t main_place, lv_flex_align_t cross_place, lv_flex_align_t track_cross_place); +void lv_obj_set_flex_align(lv_obj_t * obj, lv_flex_align_t main_place, lv_flex_align_t cross_place, + lv_flex_align_t track_cross_place); /** * Sets the width or height (on main axis) to grow the object in order fill the free space diff --git a/src/extra/layouts/grid/lv_grid.c b/src/extra/layouts/grid/lv_grid.c index 6564ffc1d..673808821 100644 --- a/src/extra/layouts/grid/lv_grid.c +++ b/src/extra/layouts/grid/lv_grid.c @@ -27,7 +27,7 @@ typedef struct { uint32_t col; uint32_t row; lv_point_t grid_abs; -}item_repos_hint_t; +} item_repos_hint_t; typedef struct { lv_coord_t * x; @@ -38,7 +38,7 @@ typedef struct { uint32_t row_num; lv_coord_t grid_w; lv_coord_t grid_h; -}_lv_grid_calc_t; +} _lv_grid_calc_t; /********************** @@ -54,19 +54,50 @@ static void calc_free(_lv_grid_calc_t * calc); static void calc_cols(lv_obj_t * cont, _lv_grid_calc_t * c); static void calc_rows(lv_obj_t * cont, _lv_grid_calc_t * c); static void item_repos(lv_obj_t * item, _lv_grid_calc_t * c, item_repos_hint_t * hint); -static lv_coord_t grid_align(lv_coord_t cont_size, bool auto_size, uint8_t align, lv_coord_t gap, uint32_t track_num, lv_coord_t * size_array, lv_coord_t * pos_array, bool reverse); +static lv_coord_t grid_align(lv_coord_t cont_size, bool auto_size, uint8_t align, lv_coord_t gap, uint32_t track_num, + lv_coord_t * size_array, lv_coord_t * pos_array, bool reverse); static uint32_t count_tracks(const lv_coord_t * templ); -static inline const lv_coord_t * get_col_dsc(lv_obj_t * obj) {return lv_obj_get_style_grid_column_dsc_array(obj, 0); } -static inline const lv_coord_t * get_row_dsc(lv_obj_t * obj) {return lv_obj_get_style_grid_row_dsc_array(obj, 0); } -static inline uint8_t get_col_pos(lv_obj_t * obj) {return lv_obj_get_style_grid_cell_column_pos(obj, 0); } -static inline uint8_t get_row_pos(lv_obj_t * obj) {return lv_obj_get_style_grid_cell_row_pos(obj, 0); } -static inline uint8_t get_col_span(lv_obj_t * obj) {return lv_obj_get_style_grid_cell_column_span(obj, 0); } -static inline uint8_t get_row_span(lv_obj_t * obj) {return lv_obj_get_style_grid_cell_row_span(obj, 0); } -static inline uint8_t get_cell_col_align(lv_obj_t * obj) {return lv_obj_get_style_grid_cell_x_align(obj, 0); } -static inline uint8_t get_cell_row_align(lv_obj_t * obj) {return lv_obj_get_style_grid_cell_y_align(obj, 0); } -static inline uint8_t get_grid_col_align(lv_obj_t * obj) {return lv_obj_get_style_grid_column_align(obj, 0); } -static inline uint8_t get_grid_row_align(lv_obj_t * obj) {return lv_obj_get_style_grid_row_align(obj, 0); } +static inline const lv_coord_t * get_col_dsc(lv_obj_t * obj) +{ + return lv_obj_get_style_grid_column_dsc_array(obj, 0); +} +static inline const lv_coord_t * get_row_dsc(lv_obj_t * obj) +{ + return lv_obj_get_style_grid_row_dsc_array(obj, 0); +} +static inline uint8_t get_col_pos(lv_obj_t * obj) +{ + return lv_obj_get_style_grid_cell_column_pos(obj, 0); +} +static inline uint8_t get_row_pos(lv_obj_t * obj) +{ + return lv_obj_get_style_grid_cell_row_pos(obj, 0); +} +static inline uint8_t get_col_span(lv_obj_t * obj) +{ + return lv_obj_get_style_grid_cell_column_span(obj, 0); +} +static inline uint8_t get_row_span(lv_obj_t * obj) +{ + return lv_obj_get_style_grid_cell_row_span(obj, 0); +} +static inline uint8_t get_cell_col_align(lv_obj_t * obj) +{ + return lv_obj_get_style_grid_cell_x_align(obj, 0); +} +static inline uint8_t get_cell_row_align(lv_obj_t * obj) +{ + return lv_obj_get_style_grid_cell_y_align(obj, 0); +} +static inline uint8_t get_grid_col_align(lv_obj_t * obj) +{ + return lv_obj_get_style_grid_column_align(obj, 0); +} +static inline uint8_t get_grid_row_align(lv_obj_t * obj) +{ + return lv_obj_get_style_grid_row_align(obj, 0); +} /********************** * GLOBAL VARIABLES @@ -128,7 +159,7 @@ void lv_obj_set_grid_align(lv_obj_t * obj, lv_grid_align_t column_align, lv_grid } void lv_obj_set_grid_cell(lv_obj_t * obj, lv_grid_align_t x_align, uint8_t col_pos, uint8_t col_span, - lv_grid_align_t y_align, uint8_t row_pos, uint8_t row_span) + lv_grid_align_t y_align, uint8_t row_pos, uint8_t row_span) { lv_obj_set_style_grid_cell_column_pos(obj, col_pos, 0); @@ -228,7 +259,7 @@ void lv_obj_set_style_grid_row_dsc_array(lv_obj_t * obj, const lv_coord_t value[ lv_style_value_t v = { .ptr = (const void *)value }; - lv_obj_set_local_style_prop(obj,LV_STYLE_GRID_ROW_DSC_ARRAY, v, selector); + lv_obj_set_local_style_prop(obj, LV_STYLE_GRID_ROW_DSC_ARRAY, v, selector); } void lv_obj_set_style_grid_column_dsc_array(lv_obj_t * obj, const lv_coord_t value[], lv_style_selector_t selector) @@ -262,7 +293,7 @@ void lv_obj_set_style_grid_cell_column_pos(lv_obj_t * obj, lv_coord_t value, lv_ lv_style_value_t v = { .num = value }; - lv_obj_set_local_style_prop(obj,LV_STYLE_GRID_CELL_COLUMN_POS, v, selector); + lv_obj_set_local_style_prop(obj, LV_STYLE_GRID_CELL_COLUMN_POS, v, selector); } void lv_obj_set_style_grid_cell_column_span(lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector) @@ -270,7 +301,7 @@ void lv_obj_set_style_grid_cell_column_span(lv_obj_t * obj, lv_coord_t value, lv lv_style_value_t v = { .num = value }; - lv_obj_set_local_style_prop(obj,LV_STYLE_GRID_CELL_COLUMN_SPAN, v, selector); + lv_obj_set_local_style_prop(obj, LV_STYLE_GRID_CELL_COLUMN_SPAN, v, selector); } void lv_obj_set_style_grid_cell_row_pos(lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector) @@ -278,7 +309,7 @@ void lv_obj_set_style_grid_cell_row_pos(lv_obj_t * obj, lv_coord_t value, lv_sty lv_style_value_t v = { .num = value }; - lv_obj_set_local_style_prop(obj,LV_STYLE_GRID_CELL_ROW_POS, v, selector); + lv_obj_set_local_style_prop(obj, LV_STYLE_GRID_CELL_ROW_POS, v, selector); } void lv_obj_set_style_grid_cell_row_span(lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector) @@ -376,11 +407,13 @@ static void calc(lv_obj_t * cont, _lv_grid_calc_t * calc_out) lv_coord_t h_set = lv_obj_get_style_height(cont, LV_PART_MAIN); bool auto_w = (w_set == LV_SIZE_CONTENT && !cont->w_layout) ? true : false; lv_coord_t cont_w = lv_obj_get_content_width(cont); - calc_out->grid_w = grid_align(cont_w, auto_w, get_grid_col_align(cont), col_gap, calc_out->col_num, calc_out->w, calc_out->x, rev); + calc_out->grid_w = grid_align(cont_w, auto_w, get_grid_col_align(cont), col_gap, calc_out->col_num, calc_out->w, + calc_out->x, rev); bool auto_h = (h_set == LV_SIZE_CONTENT && !cont->h_layout) ? true : false; lv_coord_t cont_h = lv_obj_get_content_height(cont); - calc_out->grid_h = grid_align(cont_h, auto_h, get_grid_row_align(cont), row_gap, calc_out->row_num, calc_out->h, calc_out->y, false); + calc_out->grid_h = grid_align(cont_h, auto_h, get_grid_row_align(cont), row_gap, calc_out->row_num, calc_out->h, + calc_out->y, false); LV_ASSERT_MEM_INTEGRITY(); } @@ -437,7 +470,7 @@ static void calc_cols(lv_obj_t * cont, _lv_grid_calc_t * c) if(IS_FR(x)) { col_fr_cnt += GET_FR(x); } - else if (IS_CONTENT(x)) { + else if(IS_CONTENT(x)) { grid_w += c->w[i]; } else { @@ -465,7 +498,7 @@ static void calc_cols(lv_obj_t * cont, _lv_grid_calc_t * c) /*To avoid rounding errors set the last FR track to the remaining size */ if(last_fr_i >= 0) { - c->w[last_fr_i] = free_w - ((free_w * (col_fr_cnt - last_fr_x)) / col_fr_cnt); + c->w[last_fr_i] = free_w - ((free_w * (col_fr_cnt - last_fr_x)) / col_fr_cnt); } } @@ -505,9 +538,11 @@ static void calc_rows(lv_obj_t * cont, _lv_grid_calc_t * c) lv_coord_t x = row_templ[i]; if(IS_FR(x)) { row_fr_cnt += GET_FR(x); - } else if (IS_CONTENT(x)) { + } + else if(IS_CONTENT(x)) { grid_h += c->h[i]; - } else { + } + else { c->h[i] = x; grid_h += x; } @@ -531,7 +566,7 @@ static void calc_rows(lv_obj_t * cont, _lv_grid_calc_t * c) /*To avoid rounding errors set the last FR track to the remaining size */ if(last_fr_i >= 0) { - c->h[last_fr_i] = free_h - ((free_h * (row_fr_cnt - last_fr_x)) / row_fr_cnt); + c->h[last_fr_i] = free_h - ((free_h * (row_fr_cnt - last_fr_x)) / row_fr_cnt); } } @@ -666,14 +701,16 @@ static void item_repos(lv_obj_t * item, _lv_grid_calc_t * c, item_repos_hint_t * * @param pos_array write the positions of the tracks here * @return the total size of the grid */ -static lv_coord_t grid_align(lv_coord_t cont_size, bool auto_size, uint8_t align, lv_coord_t gap, uint32_t track_num, lv_coord_t * size_array, lv_coord_t * pos_array, bool reverse) +static lv_coord_t grid_align(lv_coord_t cont_size, bool auto_size, uint8_t align, lv_coord_t gap, uint32_t track_num, + lv_coord_t * size_array, lv_coord_t * pos_array, bool reverse) { lv_coord_t grid_size = 0; uint32_t i; if(auto_size) { pos_array[0] = 0; - } else { + } + else { /*With spaced alignment gap will be calculated from the remaining space*/ if(align == LV_GRID_ALIGN_SPACE_AROUND || align == LV_GRID_ALIGN_SPACE_BETWEEN || align == LV_GRID_ALIGN_SPACE_EVENLY) { gap = 0; @@ -688,27 +725,27 @@ static lv_coord_t grid_align(lv_coord_t cont_size, bool auto_size, uint8_t alig /*Calculate the position of the first item and set gap is necessary*/ switch(align) { - case LV_GRID_ALIGN_START: - pos_array[0] = 0; - break; - case LV_GRID_ALIGN_CENTER: - pos_array[0] = (cont_size - grid_size) / 2; - break; - case LV_GRID_ALIGN_END: - pos_array[0] = cont_size - grid_size; - break; - case LV_GRID_ALIGN_SPACE_BETWEEN: - pos_array[0] = 0; - gap = (lv_coord_t)(cont_size - grid_size) / (lv_coord_t)(track_num - 1); - break; - case LV_GRID_ALIGN_SPACE_AROUND: - gap = (lv_coord_t)(cont_size - grid_size) / (lv_coord_t)(track_num); - pos_array[0] = gap / 2; - break; - case LV_GRID_ALIGN_SPACE_EVENLY: - gap = (lv_coord_t)(cont_size - grid_size) / (lv_coord_t)(track_num + 1); - pos_array[0] = gap; - break; + case LV_GRID_ALIGN_START: + pos_array[0] = 0; + break; + case LV_GRID_ALIGN_CENTER: + pos_array[0] = (cont_size - grid_size) / 2; + break; + case LV_GRID_ALIGN_END: + pos_array[0] = cont_size - grid_size; + break; + case LV_GRID_ALIGN_SPACE_BETWEEN: + pos_array[0] = 0; + gap = (lv_coord_t)(cont_size - grid_size) / (lv_coord_t)(track_num - 1); + break; + case LV_GRID_ALIGN_SPACE_AROUND: + gap = (lv_coord_t)(cont_size - grid_size) / (lv_coord_t)(track_num); + pos_array[0] = gap / 2; + break; + case LV_GRID_ALIGN_SPACE_EVENLY: + gap = (lv_coord_t)(cont_size - grid_size) / (lv_coord_t)(track_num + 1); + pos_array[0] = gap; + break; } } diff --git a/src/extra/layouts/grid/lv_grid.h b/src/extra/layouts/grid/lv_grid.h index 0403eb5e5..cd2510ec0 100644 --- a/src/extra/layouts/grid/lv_grid.h +++ b/src/extra/layouts/grid/lv_grid.h @@ -47,7 +47,7 @@ typedef enum { LV_GRID_ALIGN_SPACE_EVENLY, LV_GRID_ALIGN_SPACE_AROUND, LV_GRID_ALIGN_SPACE_BETWEEN, -}lv_grid_align_t; +} lv_grid_align_t; /********************** * GLOBAL VARIABLES @@ -86,7 +86,7 @@ void lv_obj_set_grid_align(lv_obj_t * obj, lv_grid_align_t column_align, lv_grid * @param row_span number of rows to take (>= 1) */ void lv_obj_set_grid_cell(lv_obj_t * obj, lv_grid_align_t column_align, uint8_t col_pos, uint8_t col_span, - lv_grid_align_t row_align, uint8_t row_pos, uint8_t row_span); + lv_grid_align_t row_align, uint8_t row_pos, uint8_t row_span); /** * Just a wrapper to `LV_GRID_FR` for bindings. diff --git a/src/extra/themes/basic/lv_theme_basic.c b/src/extra/themes/basic/lv_theme_basic.c index f37fe9b97..fd5bc2d02 100644 --- a/src/extra/themes/basic/lv_theme_basic.c +++ b/src/extra/themes/basic/lv_theme_basic.c @@ -406,8 +406,8 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj) #if LV_USE_LED else if(lv_obj_check_type(obj, &lv_led_class)) { - lv_obj_add_style(obj, &styles->light, 0); - } + lv_obj_add_style(obj, &styles->light, 0); + } #endif } diff --git a/src/extra/themes/default/lv_theme_default.c b/src/extra/themes/default/lv_theme_default.c index 6f5073d1a..d6952dbee 100644 --- a/src/extra/themes/default/lv_theme_default.c +++ b/src/extra/themes/default/lv_theme_default.c @@ -147,14 +147,14 @@ typedef struct { typedef struct { lv_theme_t base; - uint8_t light :1; -}my_theme_t; + uint8_t light : 1; +} my_theme_t; typedef enum { DISP_SMALL = 3, DISP_MEDIUM = 2, DISP_LARGE = 1, -}disp_size_t; +} disp_size_t; /********************** * STATIC PROTOTYPES @@ -200,12 +200,12 @@ static lv_color_t grey_filter_cb(const lv_color_filter_dsc_t * f, lv_color_t col static void style_init(void) { static const lv_style_prop_t trans_props[] = { - LV_STYLE_BG_OPA, LV_STYLE_BG_COLOR, - LV_STYLE_TRANSFORM_WIDTH, LV_STYLE_TRANSFORM_HEIGHT, - LV_STYLE_TRANSLATE_Y, LV_STYLE_TRANSLATE_X, - LV_STYLE_TRANSFORM_ZOOM, LV_STYLE_TRANSFORM_ANGLE, - LV_STYLE_COLOR_FILTER_OPA, LV_STYLE_COLOR_FILTER_DSC, - 0 + LV_STYLE_BG_OPA, LV_STYLE_BG_COLOR, + LV_STYLE_TRANSFORM_WIDTH, LV_STYLE_TRANSFORM_HEIGHT, + LV_STYLE_TRANSLATE_Y, LV_STYLE_TRANSLATE_X, + LV_STYLE_TRANSFORM_ZOOM, LV_STYLE_TRANSFORM_ANGLE, + LV_STYLE_COLOR_FILTER_OPA, LV_STYLE_COLOR_FILTER_DSC, + 0 }; color_scr = theme.flags & MODE_DARK ? DARK_COLOR_SCR : LIGHT_COLOR_SCR; @@ -226,7 +226,8 @@ static void style_init(void) lv_style_set_transition(&styles->transition_normal, &trans_normal); /*Go back to default state with delay*/ style_init_reset(&styles->scrollbar); - lv_style_set_bg_color(&styles->scrollbar, (theme.flags & MODE_DARK) ? lv_palette_darken(LV_PALETTE_GREY, 2) : lv_palette_main(LV_PALETTE_GREY)); + lv_style_set_bg_color(&styles->scrollbar, (theme.flags & MODE_DARK) ? lv_palette_darken(LV_PALETTE_GREY, + 2) : lv_palette_main(LV_PALETTE_GREY)); lv_style_set_radius(&styles->scrollbar, LV_RADIUS_CIRCLE); lv_style_set_pad_right(&styles->scrollbar, lv_disp_dpx(theme.disp, 7)); lv_style_set_pad_top(&styles->scrollbar, lv_disp_dpx(theme.disp, 7)); @@ -270,7 +271,8 @@ static void style_init(void) lv_style_set_outline_opa(&styles->outline_secondary, LV_OPA_50); style_init_reset(&styles->btn); - lv_style_set_radius(&styles->btn, (disp_size == DISP_LARGE ? lv_disp_dpx(theme.disp, 16) : disp_size == DISP_MEDIUM ? lv_disp_dpx(theme.disp, 12) : lv_disp_dpx(theme.disp, 8))); + lv_style_set_radius(&styles->btn, (disp_size == DISP_LARGE ? lv_disp_dpx(theme.disp, + 16) : disp_size == DISP_MEDIUM ? lv_disp_dpx(theme.disp, 12) : lv_disp_dpx(theme.disp, 8))); lv_style_set_bg_opa(&styles->btn, LV_OPA_COVER); lv_style_set_bg_color(&styles->btn, color_grey); if(!(theme.flags & MODE_DARK)) { @@ -440,7 +442,7 @@ static void style_init(void) lv_style_set_pad_column(&styles->chart_series, lv_disp_dpx(theme.disp, 2)); style_init_reset(&styles->chart_indic); - lv_style_set_radius(&styles->chart_indic,LV_RADIUS_CIRCLE); + lv_style_set_radius(&styles->chart_indic, LV_RADIUS_CIRCLE); lv_style_set_size(&styles->chart_indic, lv_disp_dpx(theme.disp, 8)); lv_style_set_bg_color(&styles->chart_indic, theme.color_primary); lv_style_set_bg_opa(&styles->chart_indic, LV_OPA_COVER); @@ -470,7 +472,7 @@ static void style_init(void) style_init_reset(&styles->table_cell); lv_style_set_border_width(&styles->table_cell, lv_disp_dpx(theme.disp, 1)); lv_style_set_border_color(&styles->table_cell, color_grey); - lv_style_set_border_side(&styles->table_cell, LV_BORDER_SIDE_TOP | LV_BORDER_SIDE_BOTTOM ); + lv_style_set_border_side(&styles->table_cell, LV_BORDER_SIDE_TOP | LV_BORDER_SIDE_BOTTOM); #endif #if LV_USE_TEXTAREA @@ -482,7 +484,8 @@ static void style_init(void) lv_style_set_anim_time(&styles->ta_cursor, 400); style_init_reset(&styles->ta_placeholder); - lv_style_set_text_color(&styles->ta_placeholder, (theme.flags & MODE_DARK) ? lv_palette_darken(LV_PALETTE_GREY, 2) : lv_palette_lighten(LV_PALETTE_GREY, 1)); + lv_style_set_text_color(&styles->ta_placeholder, (theme.flags & MODE_DARK) ? lv_palette_darken(LV_PALETTE_GREY, + 2) : lv_palette_lighten(LV_PALETTE_GREY, 1)); #endif #if LV_USE_CALENDAR @@ -562,7 +565,8 @@ static void style_init(void) * GLOBAL FUNCTIONS **********************/ -lv_theme_t * lv_theme_default_init(lv_disp_t * disp, lv_color_t color_primary, lv_color_t color_secondary, bool dark, const lv_font_t * font) +lv_theme_t * lv_theme_default_init(lv_disp_t * disp, lv_color_t color_primary, lv_color_t color_secondary, bool dark, + const lv_font_t * font) { /*This trick is required only to avoid the garbage collection of @@ -648,7 +652,7 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj) lv_obj_add_style(obj, &styles->scrollbar, LV_PART_SCROLLBAR); lv_obj_add_style(obj, &styles->scrollbar_scrolled, LV_PART_SCROLLBAR | LV_STATE_SCROLLED); } - #if LV_USE_BTN +#if LV_USE_BTN else if(lv_obj_check_type(obj, &lv_btn_class)) { lv_obj_add_style(obj, &styles->btn, 0); lv_obj_add_style(obj, &styles->bg_color_primary, 0); @@ -999,8 +1003,8 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj) #if LV_USE_LED else if(lv_obj_check_type(obj, &lv_led_class)) { - lv_obj_add_style(obj, &styles->led, 0); - } + lv_obj_add_style(obj, &styles->led, 0); + } #endif } diff --git a/src/extra/themes/default/lv_theme_default.h b/src/extra/themes/default/lv_theme_default.h index ef8502622..e3d854205 100644 --- a/src/extra/themes/default/lv_theme_default.h +++ b/src/extra/themes/default/lv_theme_default.h @@ -36,7 +36,8 @@ extern "C" { * @param font pointer to a font to use. * @return a pointer to reference this theme later */ -lv_theme_t * lv_theme_default_init(lv_disp_t * disp, lv_color_t color_primary, lv_color_t color_secondary, bool dark, const lv_font_t * font); +lv_theme_t * lv_theme_default_init(lv_disp_t * disp, lv_color_t color_primary, lv_color_t color_secondary, bool dark, + const lv_font_t * font); bool lv_theme_default_is_inited(void); diff --git a/src/extra/themes/mono/lv_theme_mono.c b/src/extra/themes/mono/lv_theme_mono.c index 0bd4a86a2..637564274 100644 --- a/src/extra/themes/mono/lv_theme_mono.c +++ b/src/extra/themes/mono/lv_theme_mono.c @@ -78,7 +78,7 @@ static void style_init(bool dark_bg, const lv_font_t * font) { style_init_reset(&styles->scrollbar); lv_style_set_bg_opa(&styles->scrollbar, LV_OPA_COVER); - lv_style_set_bg_color(&styles->scrollbar,COLOR_FG); + lv_style_set_bg_color(&styles->scrollbar, COLOR_FG); lv_style_set_width(&styles->scrollbar, PAD_DEF); style_init_reset(&styles->scr); @@ -279,7 +279,7 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj) lv_obj_add_style(obj, &styles->inv, LV_PART_ITEMS | LV_STATE_CHECKED); lv_obj_add_style(obj, &styles->disabled, LV_PART_ITEMS | LV_STATE_DISABLED); lv_obj_add_style(obj, &styles->underline, LV_PART_ITEMS | LV_STATE_FOCUS_KEY); - lv_obj_add_style(obj, &styles->large_border, LV_PART_ITEMS | LV_STATE_FOCUS_KEY); + lv_obj_add_style(obj, &styles->large_border, LV_PART_ITEMS | LV_STATE_FOCUS_KEY); } #endif @@ -476,8 +476,8 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj) #if LV_USE_LED else if(lv_obj_check_type(obj, &lv_led_class)) { - lv_obj_add_style(obj, &styles->card, 0); - } + lv_obj_add_style(obj, &styles->card, 0); + } #endif } diff --git a/src/extra/widgets/animimg/lv_animimg.c b/src/extra/widgets/animimg/lv_animimg.c index 83f7f1a06..fe4ebfbd2 100644 --- a/src/extra/widgets/animimg/lv_animimg.c +++ b/src/extra/widgets/animimg/lv_animimg.c @@ -67,7 +67,7 @@ void lv_animimg_set_src(lv_obj_t * obj, lv_img_dsc_t * dsc[], uint8_t num) lv_animimg_t * animimg = (lv_animimg_t *)obj; animimg->dsc = dsc; animimg->pic_count = num; - lv_anim_set_values(&animimg->anim, 0 , num); + lv_anim_set_values(&animimg->anim, 0, num); } void lv_animimg_start(lv_obj_t * obj) @@ -115,7 +115,7 @@ static void lv_animimg_constructor(const lv_obj_class_t * class_p, lv_obj_t * ob lv_anim_set_var(&animimg->anim, obj); lv_anim_set_time(&animimg->anim, 30); lv_anim_set_exec_cb(&animimg->anim, (lv_anim_exec_xcb_t)index_change); - lv_anim_set_values(&animimg->anim, 0 , 1); + lv_anim_set_values(&animimg->anim, 0, 1); lv_anim_set_repeat_count(&animimg->anim, LV_ANIM_REPEAT_INFINITE); } diff --git a/src/extra/widgets/animimg/lv_animimg.h b/src/extra/widgets/animimg/lv_animimg.h index bb1dd672e..a61da3539 100644 --- a/src/extra/widgets/animimg/lv_animimg.h +++ b/src/extra/widgets/animimg/lv_animimg.h @@ -37,8 +37,8 @@ typedef struct { lv_img_t img; lv_anim_t anim; /*picture sequence */ - lv_img_dsc_t **dsc; - int8_t pic_count; + lv_img_dsc_t ** dsc; + int8_t pic_count; } lv_animimg_t; diff --git a/src/extra/widgets/calendar/lv_calendar.c b/src/extra/widgets/calendar/lv_calendar.c index edb0aa3a1..afc319b2c 100644 --- a/src/extra/widgets/calendar/lv_calendar.c +++ b/src/extra/widgets/calendar/lv_calendar.c @@ -37,7 +37,7 @@ static void highlight_update(lv_obj_t * calendar); const lv_obj_class_t lv_calendar_class = { .constructor_cb = lv_calendar_constructor, .width_def = (LV_DPI_DEF * 3) / 2, - .height_def =(LV_DPI_DEF * 3) / 2, + .height_def = (LV_DPI_DEF * 3) / 2, .group_def = LV_OBJ_CLASS_GROUP_DEF_TRUE, .instance_size = sizeof(lv_calendar_t), .base_class = &lv_btnmatrix_class @@ -238,9 +238,11 @@ static void lv_calendar_constructor(const lv_obj_class_t * class_p, lv_obj_t * o /*Every 8th string is "\n"*/ if(i != 0 && (i + 1) % 8 == 0) { calendar->map[i] = "\n"; - } else if(i < 8){ + } + else if(i < 8) { calendar->map[i] = day_names_def[i]; - } else { + } + else { calendar->nums[j][0] = 'x'; calendar->map[i] = calendar->nums[j]; j++; @@ -359,7 +361,8 @@ static void highlight_update(lv_obj_t * obj) uint8_t day_first = get_day_of_week(calendar->showed_date.year, calendar->showed_date.month, 1); if(calendar->highlighted_dates) { for(i = 0; i < calendar->highlighted_dates_num; i++) { - if(calendar->highlighted_dates[i].year == calendar->showed_date.year && calendar->highlighted_dates[i].month == calendar->showed_date.month) { + if(calendar->highlighted_dates[i].year == calendar->showed_date.year && + calendar->highlighted_dates[i].month == calendar->showed_date.month) { lv_btnmatrix_set_btn_ctrl(obj, calendar->highlighted_dates[i].day - 1 + day_first + 7, LV_CALENDAR_CTRL_HIGHLIGHT); } } diff --git a/src/extra/widgets/calendar/lv_calendar.h b/src/extra/widgets/calendar/lv_calendar.h index 1fe0c4654..89cee9637 100644 --- a/src/extra/widgets/calendar/lv_calendar.h +++ b/src/extra/widgets/calendar/lv_calendar.h @@ -40,7 +40,8 @@ typedef struct { /*New data for this type*/ lv_calendar_date_t today; /*Date of today*/ lv_calendar_date_t showed_date; /*Currently visible month (day is ignored)*/ - lv_calendar_date_t * highlighted_dates; /*Apply different style on these days (pointer to an array defined by the user)*/ + lv_calendar_date_t * + highlighted_dates; /*Apply different style on these days (pointer to an array defined by the user)*/ uint16_t highlighted_dates_num; /*Number of elements in `highlighted_days`*/ const char * map[8 * 7]; char nums [7 * 6][4]; diff --git a/src/extra/widgets/calendar/lv_calendar_header_arrow.c b/src/extra/widgets/calendar/lv_calendar_header_arrow.c index c38e09e89..890ce49d8 100644 --- a/src/extra/widgets/calendar/lv_calendar_header_arrow.c +++ b/src/extra/widgets/calendar/lv_calendar_header_arrow.c @@ -32,8 +32,8 @@ static void month_event_cb(lv_event_t * e); * STATIC VARIABLES **********************/ const lv_obj_class_t lv_calendar_header_arrow_class = { - .base_class = &lv_obj_class, - .constructor_cb = my_constructor + .base_class = &lv_obj_class, + .constructor_cb = my_constructor }; static const char * month_names_def[12] = LV_CALENDAR_DEFAULT_MONTH_NAMES; @@ -120,14 +120,17 @@ static void month_event_cb(lv_event_t * e) if(newd.month == 1) { newd.month = 12; newd.year --; - } else { + } + else { newd.month --; } - } else { + } + else { if(newd.month == 12) { newd.month = 1; newd.year ++; - } else { + } + else { newd.month ++; } } diff --git a/src/extra/widgets/calendar/lv_calendar_header_dropdown.c b/src/extra/widgets/calendar/lv_calendar_header_dropdown.c index 18af0d94a..41d30445c 100644 --- a/src/extra/widgets/calendar/lv_calendar_header_dropdown.c +++ b/src/extra/widgets/calendar/lv_calendar_header_dropdown.c @@ -32,19 +32,19 @@ static void month_event_cb(lv_event_t * e); * STATIC VARIABLES **********************/ const lv_obj_class_t lv_calendar_header_dropdown_class = { - .base_class = &lv_obj_class, - .constructor_cb = my_constructor - }; + .base_class = &lv_obj_class, + .constructor_cb = my_constructor +}; static const char * month_list = "01\n02\n03\n04\n05\n06\n07\n08\n09\n10\n11\n12"; static const char * year_list = { - "2023\n2022\n2021\n" - "2020\n2019\n2018\n2017\n2016\n2015\n2014\n2013\n2012\n2011\n2010\n2009\n2008\n2007\n2006\n2005\n2004\n2003\n2002\n2001\n" - "2000\n1999\n1998\n1997\n1996\n1995\n1994\n1993\n1992\n1991\n1990\n1989\n1988\n1987\n1986\n1985\n1984\n1983\n1982\n1981\n" - "1980\n1979\n1978\n1977\n1976\n1975\n1974\n1973\n1972\n1971\n1970\n1969\n1968\n1967\n1966\n1965\n1964\n1963\n1962\n1961\n" - "1960\n1959\n1958\n1957\n1956\n1955\n1954\n1953\n1952\n1951\n1950\n1949\n1948\n1947\n1946\n1945\n1944\n1943\n1942\n1941\n" - "1940\n1939\n1938\n1937\n1936\n1935\n1934\n1933\n1932\n1931\n1930\n1929\n1928\n1927\n1926\n1925\n1924\n1923\n1922\n1921\n" - "1920\n1919\n1918\n1917\n1916\n1915\n1914\n1913\n1912\n1911\n1910\n1909\n1908\n1907\n1906\n1905\n1904\n1903\n1902\n1901" + "2023\n2022\n2021\n" + "2020\n2019\n2018\n2017\n2016\n2015\n2014\n2013\n2012\n2011\n2010\n2009\n2008\n2007\n2006\n2005\n2004\n2003\n2002\n2001\n" + "2000\n1999\n1998\n1997\n1996\n1995\n1994\n1993\n1992\n1991\n1990\n1989\n1988\n1987\n1986\n1985\n1984\n1983\n1982\n1981\n" + "1980\n1979\n1978\n1977\n1976\n1975\n1974\n1973\n1972\n1971\n1970\n1969\n1968\n1967\n1966\n1965\n1964\n1963\n1962\n1961\n" + "1960\n1959\n1958\n1957\n1956\n1955\n1954\n1953\n1952\n1951\n1950\n1949\n1948\n1947\n1946\n1945\n1944\n1943\n1942\n1941\n" + "1940\n1939\n1938\n1937\n1936\n1935\n1934\n1933\n1932\n1931\n1930\n1929\n1928\n1927\n1926\n1925\n1924\n1923\n1922\n1921\n" + "1920\n1919\n1918\n1917\n1916\n1915\n1914\n1913\n1912\n1911\n1910\n1909\n1908\n1907\n1906\n1905\n1904\n1903\n1902\n1901" }; static lv_obj_t * calendar_param; @@ -77,12 +77,12 @@ static void my_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj) LV_UNUSED(class_p); /*Use the same paddings as the calendar_param*/ - lv_obj_set_style_pad_left(obj,lv_obj_get_style_pad_left(calendar_param, LV_PART_MAIN), 0); - lv_obj_set_style_pad_right(obj,lv_obj_get_style_pad_right(calendar_param, LV_PART_MAIN), 0); - lv_obj_set_style_pad_top(obj,lv_obj_get_style_pad_top(calendar_param, LV_PART_MAIN), 0); - lv_obj_set_style_pad_bottom(obj,lv_obj_get_style_pad_bottom(calendar_param, LV_PART_MAIN), 0); - lv_obj_set_style_pad_column(obj,lv_obj_get_style_pad_column(calendar_param, LV_PART_MAIN), 0); - lv_obj_set_style_radius(obj,lv_obj_get_style_radius(calendar_param, LV_PART_MAIN), 0); + lv_obj_set_style_pad_left(obj, lv_obj_get_style_pad_left(calendar_param, LV_PART_MAIN), 0); + lv_obj_set_style_pad_right(obj, lv_obj_get_style_pad_right(calendar_param, LV_PART_MAIN), 0); + lv_obj_set_style_pad_top(obj, lv_obj_get_style_pad_top(calendar_param, LV_PART_MAIN), 0); + lv_obj_set_style_pad_bottom(obj, lv_obj_get_style_pad_bottom(calendar_param, LV_PART_MAIN), 0); + lv_obj_set_style_pad_column(obj, lv_obj_get_style_pad_column(calendar_param, LV_PART_MAIN), 0); + lv_obj_set_style_radius(obj, lv_obj_get_style_radius(calendar_param, LV_PART_MAIN), 0); const lv_calendar_date_t * cur_date = lv_calendar_get_showed_date(calendar_param); diff --git a/src/extra/widgets/chart/lv_chart.c b/src/extra/widgets/chart/lv_chart.c index ce658ce1a..8b2a75c3c 100644 --- a/src/extra/widgets/chart/lv_chart.c +++ b/src/extra/widgets/chart/lv_chart.c @@ -29,7 +29,7 @@ static void lv_chart_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj) static void lv_chart_destructor(const lv_obj_class_t * class_p, lv_obj_t * obj); static void lv_chart_event(const lv_obj_class_t * class_p, lv_event_t * e); -static void draw_div_lines(lv_obj_t * obj , const lv_area_t * mask); +static void draw_div_lines(lv_obj_t * obj, const lv_area_t * mask); static void draw_series_line(lv_obj_t * obj, const lv_area_t * clip_area); static void draw_series_bar(lv_obj_t * obj, const lv_area_t * clip_area); static void draw_series_scatter(lv_obj_t * obj, const lv_area_t * clip_area); @@ -130,25 +130,25 @@ void lv_chart_set_range(lv_obj_t * obj, lv_chart_axis_t axis, lv_coord_t min, lv lv_chart_t * chart = (lv_chart_t *)obj; switch(axis) { - case LV_CHART_AXIS_PRIMARY_Y: - chart->ymin[0] = min; - chart->ymax[0] = max; - break; - case LV_CHART_AXIS_SECONDARY_Y: - chart->ymin[1] = min; - chart->ymax[1] = max; - break; - case LV_CHART_AXIS_PRIMARY_X: - chart->xmin[0] = min; - chart->xmax[0] = max; - break; - case LV_CHART_AXIS_SECONDARY_X: - chart->xmin[1] = min; - chart->xmax[1] = max; - break; - default: - LV_LOG_WARN("Invalid axis: %d", axis); - return; + case LV_CHART_AXIS_PRIMARY_Y: + chart->ymin[0] = min; + chart->ymax[0] = max; + break; + case LV_CHART_AXIS_SECONDARY_Y: + chart->ymin[1] = min; + chart->ymax[1] = max; + break; + case LV_CHART_AXIS_PRIMARY_X: + chart->xmin[0] = min; + chart->xmax[0] = max; + break; + case LV_CHART_AXIS_SECONDARY_X: + chart->xmin[1] = min; + chart->xmax[1] = max; + break; + default: + LV_LOG_WARN("Invalid axis: %d", axis); + return; } lv_chart_refresh(obj); @@ -223,7 +223,8 @@ uint16_t lv_chart_get_zoom_y(const lv_obj_t * obj) return chart->zoom_y; } -void lv_chart_set_axis_tick(lv_obj_t * obj, lv_chart_axis_t axis, lv_coord_t major_len, lv_coord_t minor_len, lv_coord_t major_cnt, lv_coord_t minor_cnt, bool label_en, lv_coord_t draw_size) +void lv_chart_set_axis_tick(lv_obj_t * obj, lv_chart_axis_t axis, lv_coord_t major_len, lv_coord_t minor_len, + lv_coord_t major_cnt, lv_coord_t minor_cnt, bool label_en, lv_coord_t draw_size) { LV_ASSERT_OBJ(obj, MY_CLASS); @@ -287,8 +288,10 @@ void lv_chart_get_point_pos_by_id(lv_obj_t * obj, lv_chart_series_t * ser, uint1 } else if(chart->type == LV_CHART_TYPE_BAR) { uint32_t ser_cnt = _lv_ll_get_len(&chart->series_ll); - int32_t ser_gap = ((int32_t)lv_obj_get_style_pad_column(obj, LV_PART_ITEMS) * chart->zoom_x) >> 8; /*Gap between the column on the ~same X*/ - int32_t block_gap = ((int32_t)lv_obj_get_style_pad_column(obj, LV_PART_MAIN) * chart->zoom_x) >> 8; /*Gap between the column on ~adjacent X*/ + int32_t ser_gap = ((int32_t)lv_obj_get_style_pad_column(obj, + LV_PART_ITEMS) * chart->zoom_x) >> 8; /*Gap between the column on the ~same X*/ + int32_t block_gap = ((int32_t)lv_obj_get_style_pad_column(obj, + LV_PART_MAIN) * chart->zoom_x) >> 8; /*Gap between the column on ~adjacent X*/ lv_coord_t block_w = (w - ((chart->point_cnt - 1) * block_gap)) / chart->point_cnt; lv_coord_t col_w = block_w / ser_cnt; @@ -565,7 +568,8 @@ void lv_chart_set_value_by_id(lv_obj_t * obj, lv_chart_series_t * ser, uint16_t ser->y_points[id] = value; } -void lv_chart_set_value_by_id2(lv_obj_t * obj, lv_chart_series_t * ser, uint16_t id, lv_coord_t x_value, lv_coord_t y_value) +void lv_chart_set_value_by_id2(lv_obj_t * obj, lv_chart_series_t * ser, uint16_t id, lv_coord_t x_value, + lv_coord_t y_value) { LV_ASSERT_OBJ(obj, MY_CLASS); LV_ASSERT_NULL(ser); @@ -707,18 +711,24 @@ static void lv_chart_event(const lv_obj_class_t * class_p, lv_event_t * e) chart->pressed_point_id = id; lv_event_send(obj, LV_EVENT_VALUE_CHANGED, NULL); } - } else if(code == LV_EVENT_RELEASED) { + } + else if(code == LV_EVENT_RELEASED) { invalidate_point(obj, chart->pressed_point_id); chart->pressed_point_id = LV_CHART_POINT_NONE; - } else if(code == LV_EVENT_SIZE_CHANGED) { + } + else if(code == LV_EVENT_SIZE_CHANGED) { lv_obj_refresh_self_size(obj); - } else if(code == LV_EVENT_REFR_EXT_DRAW_SIZE) { - lv_event_set_ext_draw_size(e, LV_MAX4(chart->tick[0].draw_size, chart->tick[1].draw_size, chart->tick[2].draw_size, chart->tick[3].draw_size)); - } else if(code == LV_EVENT_GET_SELF_SIZE) { + } + else if(code == LV_EVENT_REFR_EXT_DRAW_SIZE) { + lv_event_set_ext_draw_size(e, LV_MAX4(chart->tick[0].draw_size, chart->tick[1].draw_size, chart->tick[2].draw_size, + chart->tick[3].draw_size)); + } + else if(code == LV_EVENT_GET_SELF_SIZE) { lv_point_t * p = lv_event_get_param(e); p->x = ((int32_t)lv_obj_get_content_width(obj) * chart->zoom_x) >> 8; p->y = ((int32_t)lv_obj_get_content_height(obj) * chart->zoom_y) >> 8; - } else if(code == LV_EVENT_DRAW_MAIN) { + } + else if(code == LV_EVENT_DRAW_MAIN) { const lv_area_t * clip_area = lv_event_get_param(e); draw_div_lines(obj, clip_area); draw_axes(obj, clip_area); @@ -881,7 +891,7 @@ static void draw_series_line(lv_obj_t * obj, const lv_area_t * clip_area) /*Go through all data lines*/ _LV_LL_READ_BACK(&chart->series_ll, ser) { - if (ser->hidden) continue; + if(ser->hidden) continue; line_dsc_default.color = ser->color; point_dsc_default.bg_color = ser->color; @@ -946,7 +956,8 @@ static void draw_series_line(lv_obj_t * obj, const lv_area_t * clip_area) y_max = y_cur; } } - } else { + } + else { lv_area_t point_area; point_area.x1 = p1.x - point_w; point_area.x2 = p1.x + point_w; @@ -1040,7 +1051,7 @@ static void draw_series_scatter(lv_obj_t * obj, const lv_area_t * clip_area) /*Go through all data lines*/ _LV_LL_READ_BACK(&chart->series_ll, ser) { - if (ser->hidden) continue; + if(ser->hidden) continue; line_dsc_default.color = ser->color; point_dsc_default.bg_color = ser->color; @@ -1058,7 +1069,8 @@ static void draw_series_scatter(lv_obj_t * obj, const lv_area_t * clip_area) p2.y = lv_map(ser->y_points[p_act], chart->ymin[ser->y_axis_sec], chart->ymax[ser->y_axis_sec], 0, h); p2.y = h - p2.y; p2.y += y_ofs; - } else { + } + else { p2.x = LV_COORD_MIN; p2.y = LV_COORD_MIN; } @@ -1084,7 +1096,8 @@ static void draw_series_scatter(lv_obj_t * obj, const lv_area_t * clip_area) p2.x = lv_map(ser->x_points[p_act], chart->xmin[ser->x_axis_sec], chart->xmax[ser->x_axis_sec], 0, w); p2.x += x_ofs; - } else { + } + else { p_prev = p_act; continue; } @@ -1156,10 +1169,12 @@ static void draw_series_bar(lv_obj_t * obj, const lv_area_t * clip_area) int32_t y_tmp; lv_chart_series_t * ser; uint32_t ser_cnt = _lv_ll_get_len(&chart->series_ll); - int32_t block_gap = ((int32_t)lv_obj_get_style_pad_column(obj, LV_PART_MAIN) * chart->zoom_x) >> 8; /*Gap between the column on ~adjacent X*/ + int32_t block_gap = ((int32_t)lv_obj_get_style_pad_column(obj, + LV_PART_MAIN) * chart->zoom_x) >> 8; /*Gap between the column on ~adjacent X*/ lv_coord_t block_w = (w - ((chart->point_cnt - 1) * block_gap)) / chart->point_cnt; lv_coord_t col_w = block_w / ser_cnt; - int32_t ser_gap = ((int32_t)lv_obj_get_style_pad_column(obj, LV_PART_ITEMS) * chart->zoom_x) >> 8; /*Gap between the column on the ~same X*/ + int32_t ser_gap = ((int32_t)lv_obj_get_style_pad_column(obj, + LV_PART_ITEMS) * chart->zoom_x) >> 8; /*Gap between the column on the ~same X*/ lv_coord_t x_ofs = pad_left - lv_obj_get_scroll_left(obj); lv_coord_t y_ofs = pad_top - lv_obj_get_scroll_top(obj); @@ -1190,7 +1205,7 @@ static void draw_series_bar(lv_obj_t * obj, const lv_area_t * clip_area) /*Draw the current point of all data line*/ _LV_LL_READ_BACK(&chart->series_ll, ser) { - if (ser->hidden) continue; + if(ser->hidden) continue; lv_coord_t start_point = chart->update_mode == LV_CHART_UPDATE_MODE_SHIFT ? ser->start_point : 0; col_a.x1 = x_act; @@ -1272,7 +1287,8 @@ static void draw_cursors(lv_obj_t * obj, const lv_area_t * clip_area) if(cursor->pos_set) { cx = cursor->pos.x; cy = cursor->pos.y; - } else { + } + else { if(cursor->point_id == LV_CHART_POINT_NONE) continue; lv_point_t p; lv_chart_get_point_pos_by_id(obj, cursor->ser, cursor->point_id, &p); @@ -1291,7 +1307,8 @@ static void draw_cursors(lv_obj_t * obj, const lv_area_t * clip_area) point_area.y2 = cy + point_h; part_draw_dsc.draw_area = &point_area; - } else { + } + else { part_draw_dsc.draw_area = NULL; } @@ -1348,7 +1365,8 @@ static void draw_y_ticks(lv_obj_t * obj, const lv_area_t * clip_area, lv_chart_a if(axis == LV_CHART_AXIS_PRIMARY_Y) { label_gap = lv_obj_get_style_pad_left(obj, LV_PART_TICKS); x_ofs = obj->coords.x1; - } else { + } + else { label_gap = lv_obj_get_style_pad_right(obj, LV_PART_TICKS); x_ofs = obj->coords.x2; } @@ -1413,7 +1431,8 @@ static void draw_y_ticks(lv_obj_t * obj, const lv_area_t * clip_area, lv_chart_a /*reserve appropriate area*/ lv_point_t size; - lv_txt_get_size(&size, part_draw_dsc.text, label_dsc.font, label_dsc.letter_space, label_dsc.line_space, LV_COORD_MAX, LV_TEXT_FLAG_NONE); + lv_txt_get_size(&size, part_draw_dsc.text, label_dsc.font, label_dsc.letter_space, label_dsc.line_space, LV_COORD_MAX, + LV_TEXT_FLAG_NONE); /*set the area at some distance of the major tick len left of the tick*/ lv_area_t a; @@ -1430,19 +1449,18 @@ static void draw_y_ticks(lv_obj_t * obj, const lv_area_t * clip_area, lv_chart_a } if(a.y2 >= obj->coords.y1 && - a.y1 <= obj->coords.y2) - { + a.y1 <= obj->coords.y2) { lv_draw_label(&a, clip_area, &label_dsc, part_draw_dsc.text, NULL); } - } else { + } + else { part_draw_dsc.label_dsc = NULL; part_draw_dsc.text = NULL; lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &part_draw_dsc); } if(p1.y + line_dsc.width / 2 >= obj->coords.y1 && - p2.y - line_dsc.width / 2 <= obj->coords.y2) - { + p2.y - line_dsc.width / 2 <= obj->coords.y2) { lv_draw_line(&p1, &p2, clip_area, &line_dsc); } @@ -1476,7 +1494,8 @@ static void draw_x_ticks(lv_obj_t * obj, const lv_area_t * clip_area, lv_chart_a if(axis == LV_CHART_AXIS_PRIMARY_X) { label_gap = t->label_en ? lv_obj_get_style_pad_bottom(obj, LV_PART_TICKS) : 0; y_ofs = obj->coords.y2; - } else { + } + else { label_gap = t->label_en ? lv_obj_get_style_pad_top(obj, LV_PART_TICKS) : 0; y_ofs = obj->coords.y1; } @@ -1505,7 +1524,8 @@ static void draw_x_ticks(lv_obj_t * obj, const lv_area_t * clip_area, lv_chart_a /*The columns ticks should be aligned to the center of blocks*/ if(chart->type == LV_CHART_TYPE_BAR) { - int32_t block_gap = ((int32_t)lv_obj_get_style_pad_column(obj, LV_PART_MAIN) * chart->zoom_x) >> 8; /*Gap between the columns on ~adjacent X*/ + int32_t block_gap = ((int32_t)lv_obj_get_style_pad_column(obj, + LV_PART_MAIN) * chart->zoom_x) >> 8; /*Gap between the columns on ~adjacent X*/ lv_coord_t block_w = (w + block_gap) / (chart->point_cnt); x_ofs += (block_w - block_gap) / 2; w -= block_w - block_gap; @@ -1530,7 +1550,8 @@ static void draw_x_ticks(lv_obj_t * obj, const lv_area_t * clip_area, lv_chart_a int32_t tick_value; if(chart->type == LV_CHART_TYPE_SCATTER) { tick_value = lv_map(i, 0, total_tick_num, chart->xmin[sec_axis], chart->xmax[sec_axis]); - } else { + } + else { tick_value = i / t->minor_cnt; } part_draw_dsc.value = tick_value; @@ -1545,7 +1566,8 @@ static void draw_x_ticks(lv_obj_t * obj, const lv_area_t * clip_area, lv_chart_a /*reserve appropriate area*/ lv_point_t size; - lv_txt_get_size(&size, part_draw_dsc.text, label_dsc.font, label_dsc.letter_space, label_dsc.line_space, LV_COORD_MAX, LV_TEXT_FLAG_NONE); + lv_txt_get_size(&size, part_draw_dsc.text, label_dsc.font, label_dsc.letter_space, label_dsc.line_space, LV_COORD_MAX, + LV_TEXT_FLAG_NONE); /*set the area at some distance of the major tick len under of the tick*/ lv_area_t a; @@ -1561,11 +1583,11 @@ static void draw_x_ticks(lv_obj_t * obj, const lv_area_t * clip_area, lv_chart_a } if(a.x2 >= obj->coords.x1 && - a.x1 <= obj->coords.x2) - { + a.x1 <= obj->coords.x2) { lv_draw_label(&a, clip_area, &label_dsc, part_draw_dsc.text, NULL); } - } else { + } + else { part_draw_dsc.label_dsc = NULL; part_draw_dsc.text = NULL; lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &part_draw_dsc); @@ -1573,8 +1595,7 @@ static void draw_x_ticks(lv_obj_t * obj, const lv_area_t * clip_area, lv_chart_a if(p1.x + line_dsc.width / 2 >= obj->coords.x1 && - p2.x - line_dsc.width / 2 <= obj->coords.x2) - { + p2.x - line_dsc.width / 2 <= obj->coords.x2) { lv_draw_line(&p1, &p2, clip_area, &line_dsc); } @@ -1601,7 +1622,7 @@ static uint32_t get_index_from_x(lv_obj_t * obj, lv_coord_t x) lv_chart_t * chart = (lv_chart_t *)obj; lv_coord_t w = ((int32_t)lv_obj_get_content_width(obj) * chart->zoom_x) >> 8; lv_coord_t pad_left = lv_obj_get_style_pad_left(obj, LV_PART_MAIN); - x-= pad_left; + x -= pad_left; if(x < 0) return 0; if(x > w) return chart->point_cnt - 1; @@ -1651,7 +1672,8 @@ static void invalidate_point(lv_obj_t * obj, uint16_t i) } else if(chart->type == LV_CHART_TYPE_BAR) { lv_area_t col_a; - int32_t block_gap = ((int32_t)lv_obj_get_style_pad_column(obj, LV_PART_MAIN) * chart->zoom_x) >> 8; /*Gap between the column on ~adjacent X*/ + int32_t block_gap = ((int32_t)lv_obj_get_style_pad_column(obj, + LV_PART_MAIN) * chart->zoom_x) >> 8; /*Gap between the column on ~adjacent X*/ lv_coord_t block_w = (w + block_gap) / chart->point_cnt; lv_coord_t x_act; @@ -1677,7 +1699,7 @@ static void new_points_alloc(lv_obj_t * obj, lv_chart_series_t * ser, uint32_t c { if((*a) == NULL) return; - lv_chart_t * chart = (lv_chart_t*) obj; + lv_chart_t * chart = (lv_chart_t *) obj; uint32_t point_cnt_old = chart->point_cnt; uint32_t i; @@ -1689,7 +1711,7 @@ static void new_points_alloc(lv_obj_t * obj, lv_chart_series_t * ser, uint32_t c if(cnt >= point_cnt_old) { for(i = 0; i < point_cnt_old; i++) { new_points[i] = - (*a)[(i + ser->start_point) % point_cnt_old]; /*Copy old contents to new array*/ + (*a)[(i + ser->start_point) % point_cnt_old]; /*Copy old contents to new array*/ } for(i = point_cnt_old; i < cnt; i++) { new_points[i] = LV_CHART_POINT_NONE; /*Fill up the rest with default value*/ @@ -1698,7 +1720,7 @@ static void new_points_alloc(lv_obj_t * obj, lv_chart_series_t * ser, uint32_t c else { for(i = 0; i < cnt; i++) { new_points[i] = - (*a)[(i + ser->start_point) % point_cnt_old]; /*Copy old contents to new array*/ + (*a)[(i + ser->start_point) % point_cnt_old]; /*Copy old contents to new array*/ } } @@ -1721,13 +1743,18 @@ static void new_points_alloc(lv_obj_t * obj, lv_chart_series_t * ser, uint32_t c lv_chart_tick_dsc_t * get_tick_gsc(lv_obj_t * obj, lv_chart_axis_t axis) { - lv_chart_t * chart = (lv_chart_t*) obj; + lv_chart_t * chart = (lv_chart_t *) obj; switch(axis) { - case LV_CHART_AXIS_PRIMARY_Y: return &chart->tick[0]; - case LV_CHART_AXIS_PRIMARY_X: return &chart->tick[1]; - case LV_CHART_AXIS_SECONDARY_Y: return &chart->tick[2]; - case LV_CHART_AXIS_SECONDARY_X: return &chart->tick[3]; - default: return NULL; + case LV_CHART_AXIS_PRIMARY_Y: + return &chart->tick[0]; + case LV_CHART_AXIS_PRIMARY_X: + return &chart->tick[1]; + case LV_CHART_AXIS_SECONDARY_Y: + return &chart->tick[2]; + case LV_CHART_AXIS_SECONDARY_X: + return &chart->tick[3]; + default: + return NULL; } } diff --git a/src/extra/widgets/chart/lv_chart.h b/src/extra/widgets/chart/lv_chart.h index c1adbf542..364c58d2d 100644 --- a/src/extra/widgets/chart/lv_chart.h +++ b/src/extra/widgets/chart/lv_chart.h @@ -82,17 +82,17 @@ typedef struct { lv_color_t color; lv_chart_series_t * ser; lv_dir_t dir; - uint8_t pos_set:1; /*1: pos is set; 0: point_id is set*/ + uint8_t pos_set: 1; /*1: pos is set; 0: point_id is set*/ } lv_chart_cursor_t; typedef struct { lv_coord_t major_len; lv_coord_t minor_len; lv_coord_t draw_size; - uint32_t minor_cnt :15; - uint32_t major_cnt :15; - uint32_t label_en :1; -}lv_chart_tick_dsc_t; + uint32_t minor_cnt : 15; + uint32_t major_cnt : 15; + uint32_t label_en : 1; +} lv_chart_tick_dsc_t; typedef struct { @@ -110,9 +110,9 @@ typedef struct { uint16_t point_cnt; /**< Point number in a data line*/ uint16_t zoom_x; uint16_t zoom_y; - lv_chart_type_t type :3; /**< Line or column chart*/ + lv_chart_type_t type : 3; /**< Line or column chart*/ lv_chart_update_mode_t update_mode : 1; -}lv_chart_t; +} lv_chart_t; extern const lv_obj_class_t lv_chart_class; @@ -128,7 +128,7 @@ typedef enum { LV_CHART_DRAW_PART_BAR, /**< Used on bar charts for the rectangles*/ LV_CHART_DRAW_PART_CURSOR, /**< Used on cursor lines and points*/ LV_CHART_DRAW_PART_TICK_LABEL, /**< Used on tick lines and labels*/ -}lv_chart_draw_part_type_t; +} lv_chart_draw_part_type_t; /********************** * GLOBAL PROTOTYPES @@ -218,7 +218,8 @@ uint16_t lv_chart_get_zoom_y(const lv_obj_t * obj); * @param draw_size extra size required to draw the tick and labels * (start with 20 px and increase if the ticks/labels are clipped) */ -void lv_chart_set_axis_tick(lv_obj_t * obj, lv_chart_axis_t axis, lv_coord_t major_len, lv_coord_t minor_len, lv_coord_t major_cnt, lv_coord_t minor_cnt, bool label_en, lv_coord_t draw_size); +void lv_chart_set_axis_tick(lv_obj_t * obj, lv_chart_axis_t axis, lv_coord_t major_len, lv_coord_t minor_len, + lv_coord_t major_cnt, lv_coord_t minor_cnt, bool label_en, lv_coord_t draw_size); /** * Get the type of a chart @@ -340,7 +341,8 @@ void lv_chart_set_cursor_pos(lv_obj_t * chart, lv_chart_cursor_t * cursor, lv_po * @param ser pointer to a series * @param point_id the point's index or `LV_CHART_POINT_NONE` to not assign to any points. */ -void lv_chart_set_cursor_point(lv_obj_t * chart, lv_chart_cursor_t * cursor, lv_chart_series_t * ser, uint16_t point_id); +void lv_chart_set_cursor_point(lv_obj_t * chart, lv_chart_cursor_t * cursor, lv_chart_series_t * ser, + uint16_t point_id); /** * Get the coordinate of the cursor with respect to the paddings @@ -397,7 +399,8 @@ void lv_chart_set_value_by_id(lv_obj_t * obj, lv_chart_series_t * ser, uint16_t * @param x_value the new X value of the next data * @param y_value the new Y value of the next data */ -void lv_chart_set_value_by_id2(lv_obj_t * obj, lv_chart_series_t * ser, uint16_t id, lv_coord_t x_value, lv_coord_t y_value); +void lv_chart_set_value_by_id2(lv_obj_t * obj, lv_chart_series_t * ser, uint16_t id, lv_coord_t x_value, + lv_coord_t y_value); /** * Set an external array for the y data points to use for the chart diff --git a/src/extra/widgets/colorwheel/lv_colorwheel.c b/src/extra/widgets/colorwheel/lv_colorwheel.c index c3d7d1c72..21bfcbdef 100644 --- a/src/extra/widgets/colorwheel/lv_colorwheel.c +++ b/src/extra/widgets/colorwheel/lv_colorwheel.c @@ -50,12 +50,12 @@ static uint16_t get_angle(lv_obj_t * obj); * STATIC VARIABLES **********************/ const lv_obj_class_t lv_colorwheel_class = {.instance_size = sizeof(lv_colorwheel_t), .base_class = &lv_obj_class, - .constructor_cb = lv_colorwheel_constructor, - .event_cb = lv_colorwheel_event, - .width_def = LV_DPI_DEF * 2, - .height_def = LV_DPI_DEF * 2, - .editable = LV_OBJ_CLASS_EDITABLE_TRUE, -}; + .constructor_cb = lv_colorwheel_constructor, + .event_cb = lv_colorwheel_event, + .width_def = LV_DPI_DEF * 2, + .height_def = LV_DPI_DEF * 2, + .editable = LV_OBJ_CLASS_EDITABLE_TRUE, + }; static bool create_knob_recolor; @@ -590,7 +590,7 @@ static lv_res_t double_click_reset(lv_obj_t * obj) #define SWAPPTR(A, B) do { uint8_t * t = A; A = B; B = t; } while(0) #define HSV_PTR_SWAP(sextant,r,g,b) if((sextant) & 2) { SWAPPTR((r), (b)); } if((sextant) & 4) { SWAPPTR((g), (b)); } if(!((sextant) & 6)) { \ - if(!((sextant) & 1)) { SWAPPTR((r), (g)); } } else { if((sextant) & 1) { SWAPPTR((r), (g)); } } + if(!((sextant) & 1)) { SWAPPTR((r), (g)); } } else { if((sextant) & 1) { SWAPPTR((r), (g)); } } /** * Based on the idea from https://www.vagrearg.org/content/hsvrgb @@ -604,10 +604,13 @@ static lv_res_t double_click_reset(lv_obj_t * obj) * We replace division by 255 by a division by 256, a.k.a a shift right by 8 bits. * This is wrong, but since this is only used to compute the pixels on the screen and not the final color, it's ok. */ -static void fast_hsv2rgb(uint16_t h, uint8_t s, uint8_t v, uint8_t *r, uint8_t *g , uint8_t *b); -static void fast_hsv2rgb(uint16_t h, uint8_t s, uint8_t v, uint8_t *r, uint8_t *g , uint8_t *b) +static void fast_hsv2rgb(uint16_t h, uint8_t s, uint8_t v, uint8_t * r, uint8_t * g, uint8_t * b); +static void fast_hsv2rgb(uint16_t h, uint8_t s, uint8_t v, uint8_t * r, uint8_t * g, uint8_t * b) { - if (!s) { *r = *g = *b = v; return; } + if(!s) { + *r = *g = *b = v; + return; + } uint8_t sextant = h >> 8; HSV_PTR_SWAP(sextant, r, g, b); /*Swap pointers so the conversion code is the same*/ @@ -623,7 +626,8 @@ static void fast_hsv2rgb(uint16_t h, uint8_t s, uint8_t v, uint8_t *r, uint8_t * if(!(sextant & 1)) { /*Up slope*/ ww = !h_frac ? ((uint16_t)s << 8) : (s * (uint8_t)(-h_frac)); /*Skip multiply if not required*/ - } else { + } + else { /*Down slope*/ ww = s * h_frac; } @@ -635,7 +639,7 @@ static void fast_hsv2rgb(uint16_t h, uint8_t s, uint8_t v, uint8_t *r, uint8_t * static lv_color_t angle_to_mode_color_fast(lv_obj_t * obj, uint16_t angle) { - lv_colorwheel_t * ext = (lv_colorwheel_t*)obj; + lv_colorwheel_t * ext = (lv_colorwheel_t *)obj; uint8_t r = 0, g = 0, b = 0; static uint16_t h = 0; static uint8_t s = 0, v = 0, m = 255; @@ -644,25 +648,29 @@ static lv_color_t angle_to_mode_color_fast(lv_obj_t * obj, uint16_t angle) default: case LV_COLORWHEEL_MODE_HUE: /*Don't recompute costly scaling if it does not change*/ - if (m != ext->mode) { - s = (uint8_t)(((uint16_t)ext->hsv.s * 51) / 20); v = (uint8_t)(((uint16_t)ext->hsv.v * 51) / 20); - m = ext->mode; + if(m != ext->mode) { + s = (uint8_t)(((uint16_t)ext->hsv.s * 51) / 20); + v = (uint8_t)(((uint16_t)ext->hsv.v * 51) / 20); + m = ext->mode; } - fast_hsv2rgb(angle * 6, s, v, &r, &g, &b); /*A smart compiler will replace x * 6 by (x << 2) + (x << 1) if it's more efficient*/ + fast_hsv2rgb(angle * 6, s, v, &r, &g, + &b); /*A smart compiler will replace x * 6 by (x << 2) + (x << 1) if it's more efficient*/ break; case LV_COLORWHEEL_MODE_SATURATION: /*Don't recompute costly scaling if it does not change*/ - if (m != ext->mode) { - h = (uint16_t)(((uint32_t)ext->hsv.h * 6 * 256) / 360); v = (uint8_t)(((uint16_t)ext->hsv.v * 51) / 20); - m = ext->mode; + if(m != ext->mode) { + h = (uint16_t)(((uint32_t)ext->hsv.h * 6 * 256) / 360); + v = (uint8_t)(((uint16_t)ext->hsv.v * 51) / 20); + m = ext->mode; } fast_hsv2rgb(h, angle, v, &r, &g, &b); break; case LV_COLORWHEEL_MODE_VALUE: /*Don't recompute costly scaling if it does not change*/ - if (m != ext->mode) { - h = (uint16_t)(((uint32_t)ext->hsv.h * 6 * 256) / 360); s = (uint8_t)(((uint16_t)ext->hsv.s * 51) / 20); - m = ext->mode; + if(m != ext->mode) { + h = (uint16_t)(((uint32_t)ext->hsv.h * 6 * 256) / 360); + s = (uint8_t)(((uint16_t)ext->hsv.s * 51) / 20); + m = ext->mode; } fast_hsv2rgb(h, s, angle, &r, &g, &b); break; diff --git a/src/extra/widgets/imgbtn/lv_imgbtn.c b/src/extra/widgets/imgbtn/lv_imgbtn.c index 0d167ebaa..78ae570d6 100644 --- a/src/extra/widgets/imgbtn/lv_imgbtn.c +++ b/src/extra/widgets/imgbtn/lv_imgbtn.c @@ -34,10 +34,10 @@ lv_imgbtn_state_t get_state(const lv_obj_t * imgbtn); * STATIC VARIABLES **********************/ const lv_obj_class_t lv_imgbtn_class = { - .base_class = &lv_obj_class, - .instance_size = sizeof(lv_imgbtn_t), - .constructor_cb = lv_imgbtn_constructor, - .event_cb = lv_imgbtn_event, + .base_class = &lv_obj_class, + .instance_size = sizeof(lv_imgbtn_t), + .constructor_cb = lv_imgbtn_constructor, + .event_cb = lv_imgbtn_event, }; /********************** @@ -77,7 +77,7 @@ lv_obj_t * lv_imgbtn_create(lv_obj_t * parent) * to a file) */ void lv_imgbtn_set_src(lv_obj_t * obj, lv_imgbtn_state_t state, const void * src_left, const void * src_mid, - const void * src_right) + const void * src_right) { LV_ASSERT_OBJ(obj, MY_CLASS); @@ -146,13 +146,13 @@ const void * lv_imgbtn_get_src_right(lv_obj_t * obj, lv_imgbtn_state_t state) static void lv_imgbtn_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj) { LV_UNUSED(class_p); - lv_imgbtn_t * imgbtn = (lv_imgbtn_t *)obj; - /*Initialize the allocated 'ext'*/ - lv_memset_00((void *)imgbtn->img_src_mid, sizeof(imgbtn->img_src_mid)); - lv_memset_00(imgbtn->img_src_left, sizeof(imgbtn->img_src_left)); - lv_memset_00(imgbtn->img_src_right, sizeof(imgbtn->img_src_right)); + lv_imgbtn_t * imgbtn = (lv_imgbtn_t *)obj; + /*Initialize the allocated 'ext'*/ + lv_memset_00((void *)imgbtn->img_src_mid, sizeof(imgbtn->img_src_mid)); + lv_memset_00(imgbtn->img_src_left, sizeof(imgbtn->img_src_left)); + lv_memset_00(imgbtn->img_src_right, sizeof(imgbtn->img_src_right)); - imgbtn->act_cf = LV_IMG_CF_UNKNOWN; + imgbtn->act_cf = LV_IMG_CF_UNKNOWN; } @@ -181,8 +181,7 @@ static void lv_imgbtn_event(const lv_obj_class_t * class_p, lv_event_t * e) lv_imgbtn_state_t state = suggest_state(obj, get_state(obj)); if(imgbtn->img_src_left[state] == NULL && imgbtn->img_src_mid[state] != NULL && - imgbtn->img_src_right[state] == NULL) - { + imgbtn->img_src_right[state] == NULL) { lv_img_header_t header; lv_img_decoder_get_info(imgbtn->img_src_mid[state], &header); p->x = LV_MAX(p->x, header.w); diff --git a/src/extra/widgets/imgbtn/lv_imgbtn.h b/src/extra/widgets/imgbtn/lv_imgbtn.h index 20eee9ce2..a3d7a1608 100644 --- a/src/extra/widgets/imgbtn/lv_imgbtn.h +++ b/src/extra/widgets/imgbtn/lv_imgbtn.h @@ -28,7 +28,7 @@ typedef enum { LV_IMGBTN_STATE_CHECKED_PRESSED, LV_IMGBTN_STATE_CHECKED_DISABLED, _LV_IMGBTN_STATE_NUM, -}lv_imgbtn_state_t; +} lv_imgbtn_state_t; /********************** * TYPEDEFS @@ -75,7 +75,7 @@ lv_obj_t * lv_imgbtn_create(lv_obj_t * parent); * to a file) */ void lv_imgbtn_set_src(lv_obj_t * imgbtn, lv_imgbtn_state_t state, const void * src_left, const void * src_mid, - const void * src_right); + const void * src_right); /*===================== diff --git a/src/extra/widgets/keyboard/lv_keyboard.c b/src/extra/widgets/keyboard/lv_keyboard.c index 8359e2a88..f88915bca 100644 --- a/src/extra/widgets/keyboard/lv_keyboard.c +++ b/src/extra/widgets/keyboard/lv_keyboard.c @@ -179,7 +179,8 @@ void lv_keyboard_set_mode(lv_obj_t * obj, lv_keyboard_mode_t mode) * @param map pointer to a string array to describe the map. * See 'lv_btnmatrix_set_map()' for more info. */ -void lv_keyboard_set_map(lv_obj_t * obj, lv_keyboard_mode_t mode, const char * map[], const lv_btnmatrix_ctrl_t ctrl_map[]) +void lv_keyboard_set_map(lv_obj_t * obj, lv_keyboard_mode_t mode, const char * map[], + const lv_btnmatrix_ctrl_t ctrl_map[]) { kb_map[mode] = map; kb_ctrl[mode] = ctrl_map; @@ -282,13 +283,17 @@ void lv_keyboard_def_event_cb(lv_event_t * e) lv_res_t res = lv_event_send(keyboard->ta, LV_EVENT_READY, NULL); if(res != LV_RES_OK) return; } - } else if(strcmp(txt, LV_SYMBOL_LEFT) == 0) { + } + else if(strcmp(txt, LV_SYMBOL_LEFT) == 0) { lv_textarea_cursor_left(keyboard->ta); - } else if(strcmp(txt, LV_SYMBOL_RIGHT) == 0) { + } + else if(strcmp(txt, LV_SYMBOL_RIGHT) == 0) { lv_textarea_cursor_right(keyboard->ta); - } else if(strcmp(txt, LV_SYMBOL_BACKSPACE) == 0) { + } + else if(strcmp(txt, LV_SYMBOL_BACKSPACE) == 0) { lv_textarea_del_char(keyboard->ta); - } else if(strcmp(txt, "+/-") == 0) { + } + else if(strcmp(txt, "+/-") == 0) { uint16_t cur = lv_textarea_get_cursor_pos(keyboard->ta); const char * ta_txt = lv_textarea_get_text(keyboard->ta); if(ta_txt[0] == '-') { diff --git a/src/extra/widgets/keyboard/lv_keyboard.h b/src/extra/widgets/keyboard/lv_keyboard.h index 9351b3a69..1384a6948 100644 --- a/src/extra/widgets/keyboard/lv_keyboard.h +++ b/src/extra/widgets/keyboard/lv_keyboard.h @@ -89,7 +89,8 @@ void lv_keyboard_set_mode(lv_obj_t * kb, lv_keyboard_mode_t mode); * @param map pointer to a string array to describe the map. * See 'lv_btnmatrix_set_map()' for more info. */ -void lv_keyboard_set_map(lv_obj_t * kb, lv_keyboard_mode_t mode, const char * map[], const lv_btnmatrix_ctrl_t ctrl_map[]); +void lv_keyboard_set_map(lv_obj_t * kb, lv_keyboard_mode_t mode, const char * map[], + const lv_btnmatrix_ctrl_t ctrl_map[]); /*===================== * Getter functions diff --git a/src/extra/widgets/led/lv_led.c b/src/extra/widgets/led/lv_led.c index 62b2d7c60..e610319fa 100644 --- a/src/extra/widgets/led/lv_led.c +++ b/src/extra/widgets/led/lv_led.c @@ -28,12 +28,12 @@ static void lv_led_event(const lv_obj_class_t * class_p, lv_event_t * e); * STATIC VARIABLES **********************/ const lv_obj_class_t lv_led_class = { - .base_class = &lv_obj_class, - .constructor_cb = lv_led_constructor, - .width_def = LV_DPI_DEF / 5, - .height_def = LV_DPI_DEF / 5, - .event_cb = lv_led_event, - .instance_size = sizeof(lv_led_t), + .base_class = &lv_obj_class, + .constructor_cb = lv_led_constructor, + .width_def = LV_DPI_DEF / 5, + .height_def = LV_DPI_DEF / 5, + .event_cb = lv_led_event, + .instance_size = sizeof(lv_led_t), }; /********************** @@ -186,9 +186,9 @@ static void lv_led_event(const lv_obj_class_t * class_p, lv_event_t * e) /*Set the current shadow width according to brightness proportionally between LV_LED_BRIGHT_OFF * and LV_LED_BRIGHT_ON*/ rect_dsc.shadow_width = ((led->bright - LV_LED_BRIGHT_MIN) * rect_dsc.shadow_width) / - (LV_LED_BRIGHT_MAX - LV_LED_BRIGHT_MIN); + (LV_LED_BRIGHT_MAX - LV_LED_BRIGHT_MIN); rect_dsc.shadow_spread = ((led->bright - LV_LED_BRIGHT_MIN) * rect_dsc.shadow_spread) / - (LV_LED_BRIGHT_MAX - LV_LED_BRIGHT_MIN); + (LV_LED_BRIGHT_MAX - LV_LED_BRIGHT_MIN); const lv_area_t * clip_area = lv_event_get_param(e); diff --git a/src/extra/widgets/led/lv_led.h b/src/extra/widgets/led/lv_led.h index 256c03a12..0bc4aaa71 100644 --- a/src/extra/widgets/led/lv_led.h +++ b/src/extra/widgets/led/lv_led.h @@ -50,7 +50,7 @@ extern const lv_obj_class_t lv_led_class; */ typedef enum { LV_LED_DRAW_PART_RECTANGLE, /**< The main rectangle*/ -}lv_led_draw_part_type_t; +} lv_led_draw_part_type_t; /********************** * GLOBAL PROTOTYPES diff --git a/src/extra/widgets/meter/lv_meter.c b/src/extra/widgets/meter/lv_meter.c index d19de90aa..d14b4a973 100644 --- a/src/extra/widgets/meter/lv_meter.c +++ b/src/extra/widgets/meter/lv_meter.c @@ -81,7 +81,8 @@ lv_meter_scale_t * lv_meter_add_scale(lv_obj_t * obj) return scale; } -void lv_meter_set_scale_ticks(lv_obj_t * obj, lv_meter_scale_t * scale, uint16_t cnt, uint16_t width, uint16_t len, lv_color_t color) +void lv_meter_set_scale_ticks(lv_obj_t * obj, lv_meter_scale_t * scale, uint16_t cnt, uint16_t width, uint16_t len, + lv_color_t color) { scale->tick_cnt = cnt; scale->tick_width = width; @@ -90,7 +91,8 @@ void lv_meter_set_scale_ticks(lv_obj_t * obj, lv_meter_scale_t * scale, uint16_t lv_obj_invalidate(obj); } -void lv_meter_set_scale_major_ticks(lv_obj_t * obj, lv_meter_scale_t * scale, uint16_t nth, uint16_t width, uint16_t len, lv_color_t color, int16_t label_gap) +void lv_meter_set_scale_major_ticks(lv_obj_t * obj, lv_meter_scale_t * scale, uint16_t nth, uint16_t width, + uint16_t len, lv_color_t color, int16_t label_gap) { scale->tick_major_nth = nth; scale->tick_major_width = width; @@ -100,7 +102,8 @@ void lv_meter_set_scale_major_ticks(lv_obj_t * obj, lv_meter_scale_t * scale, ui lv_obj_invalidate(obj); } -void lv_meter_set_scale_range(lv_obj_t * obj, lv_meter_scale_t * scale, int32_t min, int32_t max, uint32_t angle_range, uint32_t rotation) +void lv_meter_set_scale_range(lv_obj_t * obj, lv_meter_scale_t * scale, int32_t min, int32_t max, uint32_t angle_range, + uint32_t rotation) { scale->min = min; scale->max = max; @@ -113,7 +116,8 @@ void lv_meter_set_scale_range(lv_obj_t * obj, lv_meter_scale_t * scale, int32_t * Add indicator *====================*/ -lv_meter_indicator_t * lv_meter_add_needle_line(lv_obj_t * obj, lv_meter_scale_t * scale, uint16_t width, lv_color_t color, int16_t r_mod) +lv_meter_indicator_t * lv_meter_add_needle_line(lv_obj_t * obj, lv_meter_scale_t * scale, uint16_t width, + lv_color_t color, int16_t r_mod) { lv_meter_t * meter = (lv_meter_t *)obj; lv_meter_indicator_t * indic = _lv_ll_ins_head(&meter->indicator_ll); @@ -131,7 +135,8 @@ lv_meter_indicator_t * lv_meter_add_needle_line(lv_obj_t * obj, lv_meter_scale_t return indic; } -lv_meter_indicator_t * lv_meter_add_needle_img(lv_obj_t * obj, lv_meter_scale_t * scale, const void * src, lv_coord_t pivot_x, lv_coord_t pivot_y) +lv_meter_indicator_t * lv_meter_add_needle_img(lv_obj_t * obj, lv_meter_scale_t * scale, const void * src, + lv_coord_t pivot_x, lv_coord_t pivot_y) { lv_meter_t * meter = (lv_meter_t *)obj; lv_meter_indicator_t * indic = _lv_ll_ins_head(&meter->indicator_ll); @@ -149,7 +154,8 @@ lv_meter_indicator_t * lv_meter_add_needle_img(lv_obj_t * obj, lv_meter_scale_t return indic; } -lv_meter_indicator_t * lv_meter_add_arc(lv_obj_t * obj, lv_meter_scale_t * scale, uint16_t width, lv_color_t color, int16_t r_mod) +lv_meter_indicator_t * lv_meter_add_arc(lv_obj_t * obj, lv_meter_scale_t * scale, uint16_t width, lv_color_t color, + int16_t r_mod) { lv_meter_t * meter = (lv_meter_t *)obj; lv_meter_indicator_t * indic = _lv_ll_ins_head(&meter->indicator_ll); @@ -167,7 +173,8 @@ lv_meter_indicator_t * lv_meter_add_arc(lv_obj_t * obj, lv_meter_scale_t * scale return indic; } -lv_meter_indicator_t * lv_meter_add_scale_lines(lv_obj_t * obj, lv_meter_scale_t * scale, lv_color_t color_start, lv_color_t color_end, bool local, int16_t width_mod) +lv_meter_indicator_t * lv_meter_add_scale_lines(lv_obj_t * obj, lv_meter_scale_t * scale, lv_color_t color_start, + lv_color_t color_end, bool local, int16_t width_mod) { lv_meter_t * meter = (lv_meter_t *)obj; lv_meter_indicator_t * indic = _lv_ll_ins_head(&meter->indicator_ll); @@ -205,7 +212,8 @@ void lv_meter_set_indicator_value(lv_obj_t * obj, lv_meter_indicator_t * indic, inv_line(obj, indic, old_start); inv_line(obj, indic, old_end); inv_line(obj, indic, value); - } else { + } + else { lv_obj_invalidate(obj); } } @@ -339,8 +347,10 @@ static void draw_arcs(lv_obj_t * obj, const lv_area_t * clip_area, const lv_area lv_meter_scale_t * scale = indic->scale; - int32_t start_angle = lv_map(indic->start_value, scale->min, scale->max, scale->rotation, scale->rotation + scale->angle_range); - int32_t end_angle = lv_map(indic->end_value, scale->min, scale->max, scale->rotation, scale->rotation + scale->angle_range); + int32_t start_angle = lv_map(indic->start_value, scale->min, scale->max, scale->rotation, + scale->rotation + scale->angle_range); + int32_t end_angle = lv_map(indic->end_value, scale->min, scale->max, scale->rotation, + scale->rotation + scale->angle_range); part_draw_dsc.radius = r_out + indic->type_data.arc.r_mod; part_draw_dsc.sub_part_ptr = indic; @@ -442,11 +452,13 @@ static void draw_ticks_and_labels(lv_obj_t * obj, const lv_area_t * clip_area, c if(indic->type_data.scale_lines.color_start.full == indic->type_data.scale_lines.color_end.full) { line_color = indic->type_data.scale_lines.color_start; - } else { + } + else { lv_opa_t ratio; if(indic->type_data.scale_lines.local_grad) { ratio = lv_map(value_of_line, indic->start_value, indic->end_value, LV_OPA_TRANSP, LV_OPA_COVER); - } else { + } + else { ratio = lv_map(value_of_line, scale->min, scale->max, LV_OPA_TRANSP, LV_OPA_COVER); } line_color = lv_color_mix(indic->type_data.scale_lines.color_end, indic->type_data.scale_lines.color_start, ratio); @@ -504,7 +516,7 @@ static void draw_ticks_and_labels(lv_obj_t * obj, const lv_area_t * clip_area, c lv_point_t label_size; lv_txt_get_size(&label_size, part_draw_dsc.text, label_dsc.font, label_dsc.letter_space, label_dsc.line_space, - LV_COORD_MAX, LV_TEXT_FLAG_NONE); + LV_COORD_MAX, LV_TEXT_FLAG_NONE); lv_area_t label_cord; label_cord.x1 = p.x - label_size.x / 2; @@ -515,7 +527,8 @@ static void draw_ticks_and_labels(lv_obj_t * obj, const lv_area_t * clip_area, c lv_draw_label(&label_cord, clip_area, &label_dsc, part_draw_dsc.text, NULL); outer_mask_id = lv_draw_mask_add(&outer_mask, NULL); - } else { + } + else { part_draw_dsc.label_dsc = NULL; part_draw_dsc.text = NULL; lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &part_draw_dsc); @@ -632,7 +645,8 @@ static void inv_arc(lv_obj_t * obj, lv_meter_indicator_t * indic, int32_t old_va int32_t end_angle = lv_map(new_value, scale->min, scale->max, scale->rotation, scale->angle_range + scale->rotation); lv_area_t a; - lv_draw_arc_get_area(scale_center.x, scale_center.y, r_out, LV_MIN(start_angle, end_angle), LV_MAX(start_angle, end_angle), indic->type_data.arc.width, rounded, &a); + lv_draw_arc_get_area(scale_center.x, scale_center.y, r_out, LV_MIN(start_angle, end_angle), LV_MAX(start_angle, + end_angle), indic->type_data.arc.width, rounded, &a); lv_obj_invalidate_area(obj, &a); } @@ -682,6 +696,6 @@ static void inv_line(lv_obj_t * obj, lv_meter_indicator_t * indic, int32_t value a.y2 += scale_center.y + 2; lv_obj_invalidate_area(obj, &a); - } + } } #endif diff --git a/src/extra/widgets/meter/lv_meter.h b/src/extra/widgets/meter/lv_meter.h index 2084f1c89..f93496366 100644 --- a/src/extra/widgets/meter/lv_meter.h +++ b/src/extra/widgets/meter/lv_meter.h @@ -49,14 +49,14 @@ typedef struct { int16_t r_mod; uint16_t angle_range; int16_t rotation; -}lv_meter_scale_t; +} lv_meter_scale_t; typedef enum { LV_METER_INDICATOR_TYPE_NEEDLE_IMG, LV_METER_INDICATOR_TYPE_NEEDLE_LINE, LV_METER_INDICATOR_TYPE_SCALE_LINES, LV_METER_INDICATOR_TYPE_ARC, -}lv_meter_indicator_type_t; +} lv_meter_indicator_type_t; typedef struct { lv_meter_scale_t * scale; @@ -68,26 +68,26 @@ typedef struct { struct { const void * src; lv_point_t pivot; - }needle_img; + } needle_img; struct { uint16_t width; int16_t r_mod; lv_color_t color; - }needle_line; + } needle_line; struct { uint16_t width; const void * src; lv_color_t color; int16_t r_mod; - }arc; + } arc; struct { int16_t width_mod; lv_color_t color_start; lv_color_t color_end; - uint8_t local_grad :1; - }scale_lines; + uint8_t local_grad : 1; + } scale_lines; } type_data; -}lv_meter_indicator_t; +} lv_meter_indicator_t; /*Data of line meter*/ typedef struct { @@ -107,7 +107,7 @@ typedef enum { LV_METER_DRAW_PART_NEEDLE_LINE, /**< The needle lines*/ LV_METER_DRAW_PART_NEEDLE_IMG, /**< The needle images*/ LV_METER_DRAW_PART_TICK, /**< The tick lines and labels*/ -}lv_meter_draw_part_type_t; +} lv_meter_draw_part_type_t; /********************** * GLOBAL PROTOTYPES @@ -141,7 +141,8 @@ lv_meter_scale_t * lv_meter_add_scale(lv_obj_t * obj); * @param len length of tick lines * @param color color of tick lines */ -void lv_meter_set_scale_ticks(lv_obj_t * obj, lv_meter_scale_t * scale, uint16_t cnt, uint16_t width, uint16_t len, lv_color_t color); +void lv_meter_set_scale_ticks(lv_obj_t * obj, lv_meter_scale_t * scale, uint16_t cnt, uint16_t width, uint16_t len, + lv_color_t color); /** * Make some "normal" ticks major ticks and set their attributes. @@ -154,7 +155,8 @@ void lv_meter_set_scale_ticks(lv_obj_t * obj, lv_meter_scale_t * scale, uint16_t * @param color color of the major ticks * @param label_gap gap between the major ticks and the labels */ -void lv_meter_set_scale_major_ticks(lv_obj_t * obj, lv_meter_scale_t * scale, uint16_t nth, uint16_t width, uint16_t len, lv_color_t color, int16_t label_gap); +void lv_meter_set_scale_major_ticks(lv_obj_t * obj, lv_meter_scale_t * scale, uint16_t nth, uint16_t width, + uint16_t len, lv_color_t color, int16_t label_gap); /** * Set the value and angular range of a scale. @@ -165,7 +167,8 @@ void lv_meter_set_scale_major_ticks(lv_obj_t * obj, lv_meter_scale_t * scale, ui * @param angle_range the angular range of the scale * @param rotation the angular offset from the 3 o'clock position (clock-wise) */ -void lv_meter_set_scale_range(lv_obj_t * obj, lv_meter_scale_t * scale, int32_t min, int32_t max, uint32_t angle_range, uint32_t rotation); +void lv_meter_set_scale_range(lv_obj_t * obj, lv_meter_scale_t * scale, int32_t min, int32_t max, uint32_t angle_range, + uint32_t rotation); /*===================== * Add indicator @@ -180,7 +183,8 @@ void lv_meter_set_scale_range(lv_obj_t * obj, lv_meter_scale_t * scale, int32_t * @param r_mod the radius modifier (added to the scale's radius) to get the lines length * @return the new indicator */ -lv_meter_indicator_t * lv_meter_add_needle_line(lv_obj_t * obj, lv_meter_scale_t * scale, uint16_t width, lv_color_t color, int16_t r_mod); +lv_meter_indicator_t * lv_meter_add_needle_line(lv_obj_t * obj, lv_meter_scale_t * scale, uint16_t width, + lv_color_t color, int16_t r_mod); /** * Add a needle image indicator the scale @@ -192,7 +196,8 @@ lv_meter_indicator_t * lv_meter_add_needle_line(lv_obj_t * obj, lv_meter_scale_t * @return the new indicator * @note the needle image should point to the right, like -O-----> */ -lv_meter_indicator_t * lv_meter_add_needle_img(lv_obj_t * obj, lv_meter_scale_t * scale, const void * src, lv_coord_t pivot_x, lv_coord_t pivot_y); +lv_meter_indicator_t * lv_meter_add_needle_img(lv_obj_t * obj, lv_meter_scale_t * scale, const void * src, + lv_coord_t pivot_x, lv_coord_t pivot_y); /** * Add an arc indicator the scale @@ -203,7 +208,8 @@ lv_meter_indicator_t * lv_meter_add_needle_img(lv_obj_t * obj, lv_meter_scale_t * @param r_mod the radius modifier (added to the scale's radius) to get the outer radius of the arc * @return the new indicator */ -lv_meter_indicator_t * lv_meter_add_arc(lv_obj_t * obj, lv_meter_scale_t * scale, uint16_t width, lv_color_t color, int16_t r_mod); +lv_meter_indicator_t * lv_meter_add_arc(lv_obj_t * obj, lv_meter_scale_t * scale, uint16_t width, lv_color_t color, + int16_t r_mod); /** @@ -216,7 +222,8 @@ lv_meter_indicator_t * lv_meter_add_arc(lv_obj_t * obj, lv_meter_scale_t * scale * @param width_mod add this the affected tick's width * @return the new indicator */ -lv_meter_indicator_t * lv_meter_add_scale_lines(lv_obj_t * obj, lv_meter_scale_t * scale, lv_color_t color_start, lv_color_t color_end, bool local, int16_t width_mod); +lv_meter_indicator_t * lv_meter_add_scale_lines(lv_obj_t * obj, lv_meter_scale_t * scale, lv_color_t color_start, + lv_color_t color_end, bool local, int16_t width_mod); /*===================== * Set indicator value diff --git a/src/extra/widgets/msgbox/lv_msgbox.c b/src/extra/widgets/msgbox/lv_msgbox.c index c15d7d875..0e28754aa 100644 --- a/src/extra/widgets/msgbox/lv_msgbox.c +++ b/src/extra/widgets/msgbox/lv_msgbox.c @@ -37,7 +37,8 @@ const lv_obj_class_t lv_msgbox_class = {.base_class = &lv_obj_class, .instance_s * GLOBAL FUNCTIONS **********************/ -lv_obj_t * lv_msgbox_create(lv_obj_t * parent, const char * title, const char * txt, const char * btn_txts[], bool add_close_btn) +lv_obj_t * lv_msgbox_create(lv_obj_t * parent, const char * title, const char * txt, const char * btn_txts[], + bool add_close_btn) { LV_LOG_INFO("begin"); bool auto_parent = false; diff --git a/src/extra/widgets/msgbox/lv_msgbox.h b/src/extra/widgets/msgbox/lv_msgbox.h index 275e27f2b..62484ce45 100644 --- a/src/extra/widgets/msgbox/lv_msgbox.h +++ b/src/extra/widgets/msgbox/lv_msgbox.h @@ -40,7 +40,7 @@ typedef struct { lv_obj_t * close_btn; lv_obj_t * text; lv_obj_t * btns; -}lv_msgbox_t; +} lv_msgbox_t; extern const lv_obj_class_t lv_msgbox_class; @@ -57,7 +57,8 @@ extern const lv_obj_class_t lv_msgbox_class; * @param add_close_btn true: add a close button * @return pointer to the message box object */ -lv_obj_t * lv_msgbox_create(lv_obj_t * parent, const char * title, const char * txt, const char * btn_txts[], bool add_close_btn); +lv_obj_t * lv_msgbox_create(lv_obj_t * parent, const char * title, const char * txt, const char * btn_txts[], + bool add_close_btn); lv_obj_t * lv_msgbox_get_title(lv_obj_t * obj); diff --git a/src/extra/widgets/spinbox/lv_spinbox.c b/src/extra/widgets/spinbox/lv_spinbox.c index 1327a18a2..5e6f9e167 100644 --- a/src/extra/widgets/spinbox/lv_spinbox.c +++ b/src/extra/widgets/spinbox/lv_spinbox.c @@ -158,8 +158,8 @@ void lv_spinbox_set_pos(lv_obj_t * obj, uint8_t pos) step_limit = LV_MAX(spinbox->range_max, (spinbox->range_min < 0 ? (-spinbox->range_min) : spinbox->range_min)); int32_t new_step = spinbox->step * lv_pow(10, pos); if(pos <= 0) spinbox->step = 1; - else if(new_step <= step_limit) spinbox->step = new_step; - + else if(new_step <= step_limit) spinbox->step = new_step; + lv_spinbox_updatevalue(obj); } /*===================== diff --git a/src/extra/widgets/spinner/lv_spinner.c b/src/extra/widgets/spinner/lv_spinner.c index 98bbca49e..65b6b046a 100644 --- a/src/extra/widgets/spinner/lv_spinner.c +++ b/src/extra/widgets/spinner/lv_spinner.c @@ -28,8 +28,8 @@ static void arc_anim_end_angle(void * obj, int32_t v); * STATIC VARIABLES **********************/ const lv_obj_class_t lv_spinner_class = { - .base_class = &lv_arc_class, - .constructor_cb = lv_spinner_constructor + .base_class = &lv_arc_class, + .constructor_cb = lv_spinner_constructor }; static uint32_t time_param; diff --git a/src/extra/widgets/tabview/lv_tabview.c b/src/extra/widgets/tabview/lv_tabview.c index 2fbf6d2f4..7cb006870 100644 --- a/src/extra/widgets/tabview/lv_tabview.c +++ b/src/extra/widgets/tabview/lv_tabview.c @@ -30,13 +30,14 @@ static void cont_scroll_end_event_cb(lv_event_t * e); * STATIC VARIABLES **********************/ const lv_obj_class_t lv_tabview_class = { - .constructor_cb = lv_tabview_constructor, - .destructor_cb = lv_tabview_destructor, - .event_cb = lv_tabview_event, - .width_def = LV_PCT(100), - .height_def = LV_PCT(100), - .base_class = &lv_obj_class, - .instance_size = sizeof(lv_tabview_t)}; + .constructor_cb = lv_tabview_constructor, + .destructor_cb = lv_tabview_destructor, + .event_cb = lv_tabview_event, + .width_def = LV_PCT(100), + .height_def = LV_PCT(100), + .base_class = &lv_obj_class, + .instance_size = sizeof(lv_tabview_t) +}; static lv_dir_t tabpos_create; static lv_coord_t tabsize_create; @@ -91,7 +92,8 @@ lv_obj_t * lv_tabview_add_tab(lv_obj_t * obj, const char * name) new_map[0] = lv_mem_alloc(strlen(name) + 1); strcpy((char *)new_map[0], name); new_map[1] = ""; - } else { + } + else { new_map[tab_id * 2 - 3] = "\n"; new_map[tab_id * 2 - 2] = lv_mem_alloc(strlen(name) + 1); new_map[tab_id * 2 - 1] = ""; @@ -102,7 +104,8 @@ lv_obj_t * lv_tabview_add_tab(lv_obj_t * obj, const char * name) lv_btnmatrix_set_map(btns, (const char **)new_map); lv_mem_free(old_map); - lv_btnmatrix_set_btn_ctrl_all(btns, LV_BTNMATRIX_CTRL_CHECKABLE | LV_BTNMATRIX_CTRL_CLICK_TRIG | LV_BTNMATRIX_CTRL_NO_REPEAT); + lv_btnmatrix_set_btn_ctrl_all(btns, LV_BTNMATRIX_CTRL_CHECKABLE | LV_BTNMATRIX_CTRL_CLICK_TRIG | + LV_BTNMATRIX_CTRL_NO_REPEAT); tabview->tab_cnt++; if(tabview->tab_cnt == 1) { @@ -131,7 +134,8 @@ void lv_tabview_set_act(lv_obj_t * obj, uint32_t id, lv_anim_enable_t anim_en) lv_coord_t w = lv_obj_get_content_width(cont); if(lv_obj_get_style_base_dir(obj, LV_PART_MAIN) != LV_BASE_DIR_RTL) { lv_obj_scroll_to_x(cont, id * (gap + w), anim_en); - } else { + } + else { int32_t id_rtl = -(int32_t)id; lv_obj_scroll_to_x(cont, (gap + w) * id_rtl, anim_en); } @@ -169,18 +173,18 @@ static void lv_tabview_constructor(const lv_obj_class_t * class_p, lv_obj_t * ob tabview->tab_pos = tabpos_create; switch(tabview->tab_pos) { - case LV_DIR_TOP: - lv_obj_set_flex_flow(obj, LV_FLEX_FLOW_COLUMN); - break; - case LV_DIR_BOTTOM: - lv_obj_set_flex_flow(obj, LV_FLEX_FLOW_COLUMN_REVERSE); - break; - case LV_DIR_LEFT: - lv_obj_set_flex_flow(obj, LV_FLEX_FLOW_ROW); - break; - case LV_DIR_RIGHT: - lv_obj_set_flex_flow(obj, LV_FLEX_FLOW_ROW_REVERSE); - break; + case LV_DIR_TOP: + lv_obj_set_flex_flow(obj, LV_FLEX_FLOW_COLUMN); + break; + case LV_DIR_BOTTOM: + lv_obj_set_flex_flow(obj, LV_FLEX_FLOW_COLUMN_REVERSE); + break; + case LV_DIR_LEFT: + lv_obj_set_flex_flow(obj, LV_FLEX_FLOW_ROW); + break; + case LV_DIR_RIGHT: + lv_obj_set_flex_flow(obj, LV_FLEX_FLOW_ROW_REVERSE); + break; } lv_obj_set_size(obj, LV_PCT(100), LV_PCT(100)); @@ -202,19 +206,19 @@ static void lv_tabview_constructor(const lv_obj_class_t * class_p, lv_obj_t * ob lv_obj_set_scrollbar_mode(cont, LV_SCROLLBAR_MODE_OFF); switch(tabview->tab_pos) { - case LV_DIR_TOP: - case LV_DIR_BOTTOM: - lv_obj_set_size(btnm, LV_PCT(100), tabsize_create); - lv_obj_set_width(cont, LV_PCT(100)); - lv_obj_set_flex_grow(cont, 1); - break; - case LV_DIR_LEFT: - case LV_DIR_RIGHT: - lv_obj_set_size(btnm, tabsize_create, LV_PCT(100)); - lv_obj_set_height(cont, LV_PCT(100)); - lv_obj_set_flex_grow(cont, 1); - break; - } + case LV_DIR_TOP: + case LV_DIR_BOTTOM: + lv_obj_set_size(btnm, LV_PCT(100), tabsize_create); + lv_obj_set_width(cont, LV_PCT(100)); + lv_obj_set_flex_grow(cont, 1); + break; + case LV_DIR_LEFT: + case LV_DIR_RIGHT: + lv_obj_set_size(btnm, tabsize_create, LV_PCT(100)); + lv_obj_set_height(cont, LV_PCT(100)); + lv_obj_set_flex_grow(cont, 1); + break; + } lv_group_t * g = lv_group_get_default(); if(g) lv_group_add_obj(g, btnm); @@ -289,8 +293,8 @@ static void cont_scroll_end_event_cb(lv_event_t * e) lv_coord_t w = lv_obj_get_content_width(cont); lv_coord_t t; - if(lv_obj_get_style_base_dir(tv, LV_PART_MAIN) == LV_BASE_DIR_RTL) t = -(p.x - w/ 2) / w; - else t = (p.x + w/ 2) / w; + if(lv_obj_get_style_base_dir(tv, LV_PART_MAIN) == LV_BASE_DIR_RTL) t = -(p.x - w / 2) / w; + else t = (p.x + w / 2) / w; if(t < 0) t = 0; bool new_tab = false; diff --git a/src/extra/widgets/tabview/lv_tabview.h b/src/extra/widgets/tabview/lv_tabview.h index 4cfc4971b..a01c6b9ba 100644 --- a/src/extra/widgets/tabview/lv_tabview.h +++ b/src/extra/widgets/tabview/lv_tabview.h @@ -25,14 +25,13 @@ extern "C" { * TYPEDEFS **********************/ -typedef struct -{ +typedef struct { lv_obj_t obj; char ** map; uint16_t tab_cnt; uint16_t tab_cur; lv_dir_t tab_pos; -}lv_tabview_t; +} lv_tabview_t; extern const lv_obj_class_t lv_tabview_class; diff --git a/src/extra/widgets/tileview/lv_tileview.c b/src/extra/widgets/tileview/lv_tileview.c index 63a6c09a9..7e00c42af 100644 --- a/src/extra/widgets/tileview/lv_tileview.c +++ b/src/extra/widgets/tileview/lv_tileview.c @@ -29,12 +29,14 @@ static void tileview_event_cb(lv_event_t * e); **********************/ const lv_obj_class_t lv_tileview_class = {.constructor_cb = lv_tileview_constructor, - .base_class = &lv_obj_class, - .instance_size = sizeof(lv_tileview_t)}; + .base_class = &lv_obj_class, + .instance_size = sizeof(lv_tileview_t) + }; const lv_obj_class_t lv_tileview_tile_class = {.constructor_cb = lv_tileview_tile_constructor, - .base_class = &lv_obj_class, - .instance_size = sizeof(lv_tileview_tile_t)}; + .base_class = &lv_obj_class, + .instance_size = sizeof(lv_tileview_tile_t) + }; static lv_dir_t create_dir; static uint32_t create_col_id; @@ -135,7 +137,8 @@ static void lv_tileview_tile_constructor(const lv_obj_class_t * class_p, lv_obj_ lv_obj_t * parent = lv_obj_get_parent(obj); lv_obj_set_size(obj, LV_PCT(100), LV_PCT(100)); lv_obj_update_layout(obj); /*Be sure the size is correct*/ - lv_obj_set_pos(obj, create_col_id * lv_obj_get_content_width(parent), create_row_id * lv_obj_get_content_height(parent)); + lv_obj_set_pos(obj, create_col_id * lv_obj_get_content_width(parent), + create_row_id * lv_obj_get_content_height(parent)); lv_tileview_tile_t * tile = (lv_tileview_tile_t *)obj; tile->dir = create_dir; diff --git a/src/extra/widgets/tileview/lv_tileview.h b/src/extra/widgets/tileview/lv_tileview.h index 79f1acd46..172338196 100644 --- a/src/extra/widgets/tileview/lv_tileview.h +++ b/src/extra/widgets/tileview/lv_tileview.h @@ -27,12 +27,12 @@ extern "C" { typedef struct { lv_obj_t obj; lv_obj_t * tile_act; -}lv_tileview_t; +} lv_tileview_t; typedef struct { lv_obj_t obj; lv_dir_t dir; -}lv_tileview_tile_t; +} lv_tileview_tile_t; extern const lv_obj_class_t lv_tileview_class; extern const lv_obj_class_t lv_tileview_tile_class; diff --git a/src/extra/widgets/win/lv_win.c b/src/extra/widgets/win/lv_win.c index fe4fb57f2..92c3b8baa 100644 --- a/src/extra/widgets/win/lv_win.c +++ b/src/extra/widgets/win/lv_win.c @@ -27,11 +27,11 @@ static void lv_win_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj); * STATIC VARIABLES **********************/ const lv_obj_class_t lv_win_class = { - .constructor_cb = lv_win_constructor, - .width_def = LV_PCT(100), - .height_def = LV_PCT(100), - .base_class = &lv_obj_class, - .instance_size = sizeof(lv_win_t) + .constructor_cb = lv_win_constructor, + .width_def = LV_PCT(100), + .height_def = LV_PCT(100), + .base_class = &lv_obj_class, + .instance_size = sizeof(lv_win_t) }; static lv_coord_t create_header_height; /********************** diff --git a/src/extra/widgets/win/lv_win.h b/src/extra/widgets/win/lv_win.h index 524596339..4342b3104 100644 --- a/src/extra/widgets/win/lv_win.h +++ b/src/extra/widgets/win/lv_win.h @@ -24,7 +24,7 @@ extern "C" { **********************/ typedef struct { lv_obj_t obj; -}lv_win_t; +} lv_win_t; extern const lv_obj_class_t lv_win_class; diff --git a/src/font/lv_font_fmt_txt.c b/src/font/lv_font_fmt_txt.c index 73bed69b7..991b23e6d 100644 --- a/src/font/lv_font_fmt_txt.c +++ b/src/font/lv_font_fmt_txt.c @@ -128,7 +128,7 @@ const uint8_t * lv_font_get_bitmap_fmt_txt(const lv_font_t * font, uint32_t unic (uint8_t)fdsc->bpp, prefilter); return LV_GC_ROOT(_lv_font_decompr_buf); #else /*!LV_USE_FONT_COMPRESSED*/ -// LV_LOG_WARN("Compressed fonts is used but LV_USE_FONT_COMPRESSED is not enabled in lv_conf.h"); + LV_LOG_WARN("Compressed fonts is used but LV_USE_FONT_COMPRESSED is not enabled in lv_conf.h"); return NULL; #endif } diff --git a/src/font/lv_font_montserrat_10.c b/src/font/lv_font_montserrat_10.c index b6a806d5a..54f9f98e7 100644 --- a/src/font/lv_font_montserrat_10.c +++ b/src/font/lv_font_montserrat_10.c @@ -5,13 +5,13 @@ ******************************************************************************/ #ifdef LV_LVGL_H_INCLUDE_SIMPLE -#include "lvgl.h" + #include "lvgl.h" #else -#include "../../lvgl.h" + #include "../../lvgl.h" #endif #ifndef LV_FONT_MONTSERRAT_10 -#define LV_FONT_MONTSERRAT_10 1 + #define LV_FONT_MONTSERRAT_10 1 #endif #if LV_FONT_MONTSERRAT_10 @@ -1155,8 +1155,7 @@ static const uint16_t unicode_list_1[] = { }; /*Collect the unicode lists and glyph_id offsets*/ -static const lv_font_fmt_txt_cmap_t cmaps[] = -{ +static const lv_font_fmt_txt_cmap_t cmaps[] = { { .range_start = 32, .range_length = 95, .glyph_id_start = 1, .unicode_list = NULL, .glyph_id_ofs_list = NULL, .list_length = 0, .type = LV_FONT_FMT_TXT_CMAP_FORMAT0_TINY @@ -1173,8 +1172,7 @@ static const lv_font_fmt_txt_cmap_t cmaps[] = /*Map glyph_ids to kern left classes*/ -static const uint8_t kern_left_class_mapping[] = -{ +static const uint8_t kern_left_class_mapping[] = { 0, 0, 1, 2, 0, 3, 4, 5, 2, 6, 7, 8, 9, 10, 9, 10, 11, 12, 0, 13, 14, 15, 16, 17, @@ -1198,8 +1196,7 @@ static const uint8_t kern_left_class_mapping[] = }; /*Map glyph_ids to kern right classes*/ -static const uint8_t kern_right_class_mapping[] = -{ +static const uint8_t kern_right_class_mapping[] = { 0, 0, 1, 2, 0, 3, 4, 5, 2, 6, 7, 8, 9, 10, 9, 10, 11, 12, 13, 14, 15, 16, 17, 12, @@ -1223,8 +1220,7 @@ static const uint8_t kern_right_class_mapping[] = }; /*Kern values between classes*/ -static const int8_t kern_class_values[] = -{ +static const int8_t kern_class_values[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, @@ -1603,8 +1599,7 @@ static const int8_t kern_class_values[] = /*Collect the kern class' data in one place*/ -static const lv_font_fmt_txt_kern_classes_t kern_classes = -{ +static const lv_font_fmt_txt_kern_classes_t kern_classes = { .class_pair_values = kern_class_values, .left_class_mapping = kern_left_class_mapping, .right_class_mapping = kern_right_class_mapping, diff --git a/src/font/lv_font_montserrat_8.c b/src/font/lv_font_montserrat_8.c index 8cd303f69..9d8b154b6 100644 --- a/src/font/lv_font_montserrat_8.c +++ b/src/font/lv_font_montserrat_8.c @@ -5,13 +5,13 @@ ******************************************************************************/ #ifdef LV_LVGL_H_INCLUDE_SIMPLE -#include "lvgl.h" + #include "lvgl.h" #else -#include "../../lvgl.h" + #include "../../lvgl.h" #endif #ifndef LV_FONT_MONTSERRAT_8 -#define LV_FONT_MONTSERRAT_8 1 + #define LV_FONT_MONTSERRAT_8 1 #endif #if LV_FONT_MONTSERRAT_8 @@ -941,8 +941,7 @@ static const uint16_t unicode_list_1[] = { }; /*Collect the unicode lists and glyph_id offsets*/ -static const lv_font_fmt_txt_cmap_t cmaps[] = -{ +static const lv_font_fmt_txt_cmap_t cmaps[] = { { .range_start = 32, .range_length = 95, .glyph_id_start = 1, .unicode_list = NULL, .glyph_id_ofs_list = NULL, .list_length = 0, .type = LV_FONT_FMT_TXT_CMAP_FORMAT0_TINY @@ -959,8 +958,7 @@ static const lv_font_fmt_txt_cmap_t cmaps[] = /*Map glyph_ids to kern left classes*/ -static const uint8_t kern_left_class_mapping[] = -{ +static const uint8_t kern_left_class_mapping[] = { 0, 0, 1, 2, 0, 3, 4, 5, 2, 6, 7, 8, 9, 10, 9, 10, 11, 12, 0, 13, 14, 15, 16, 17, @@ -984,8 +982,7 @@ static const uint8_t kern_left_class_mapping[] = }; /*Map glyph_ids to kern right classes*/ -static const uint8_t kern_right_class_mapping[] = -{ +static const uint8_t kern_right_class_mapping[] = { 0, 0, 1, 2, 0, 3, 4, 5, 2, 6, 7, 8, 9, 10, 9, 10, 11, 12, 13, 14, 15, 16, 17, 12, @@ -1009,8 +1006,7 @@ static const uint8_t kern_right_class_mapping[] = }; /*Kern values between classes*/ -static const int8_t kern_class_values[] = -{ +static const int8_t kern_class_values[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, @@ -1389,8 +1385,7 @@ static const int8_t kern_class_values[] = /*Collect the kern class' data in one place*/ -static const lv_font_fmt_txt_kern_classes_t kern_classes = -{ +static const lv_font_fmt_txt_kern_classes_t kern_classes = { .class_pair_values = kern_class_values, .left_class_mapping = kern_left_class_mapping, .right_class_mapping = kern_right_class_mapping, diff --git a/src/font/lv_font_unscii_16.c b/src/font/lv_font_unscii_16.c index 451cd1ea3..104bc2bce 100644 --- a/src/font/lv_font_unscii_16.c +++ b/src/font/lv_font_unscii_16.c @@ -5,13 +5,13 @@ ******************************************************************************/ #ifdef LV_LVGL_H_INCLUDE_SIMPLE -#include "lvgl.h" + #include "lvgl.h" #else -#include "../../lvgl.h" + #include "../../lvgl.h" #endif #ifndef LV_FONT_UNSCII_16 -#define LV_FONT_UNSCII_16 1 + #define LV_FONT_UNSCII_16 1 #endif #if LV_FONT_UNSCII_16 @@ -587,8 +587,7 @@ static const lv_font_fmt_txt_glyph_dsc_t glyph_dsc[] = { /*Collect the unicode lists and glyph_id offsets*/ -static const lv_font_fmt_txt_cmap_t cmaps[] = -{ +static const lv_font_fmt_txt_cmap_t cmaps[] = { { .range_start = 32, .range_length = 96, .glyph_id_start = 1, .unicode_list = NULL, .glyph_id_ofs_list = NULL, .list_length = 0, .type = LV_FONT_FMT_TXT_CMAP_FORMAT0_TINY diff --git a/src/font/lv_font_unscii_8.c b/src/font/lv_font_unscii_8.c index 49ea8394a..e67c5166d 100644 --- a/src/font/lv_font_unscii_8.c +++ b/src/font/lv_font_unscii_8.c @@ -5,13 +5,13 @@ ******************************************************************************/ #ifdef LV_LVGL_H_INCLUDE_SIMPLE -#include "lvgl.h" + #include "lvgl.h" #else -#include "../../lvgl.h" + #include "../../lvgl.h" #endif #ifndef LV_FONT_UNSCII_8 -#define LV_FONT_UNSCII_8 1 + #define LV_FONT_UNSCII_8 1 #endif #if LV_FONT_UNSCII_8 @@ -423,8 +423,7 @@ static const lv_font_fmt_txt_glyph_dsc_t glyph_dsc[] = { /*Collect the unicode lists and glyph_id offsets*/ -static const lv_font_fmt_txt_cmap_t cmaps[] = -{ +static const lv_font_fmt_txt_cmap_t cmaps[] = { { .range_start = 32, .range_length = 96, .glyph_id_start = 1, .unicode_list = NULL, .glyph_id_ofs_list = NULL, .list_length = 0, .type = LV_FONT_FMT_TXT_CMAP_FORMAT0_TINY diff --git a/src/gpu/lv_gpu_nxp_vglite.c b/src/gpu/lv_gpu_nxp_vglite.c index 6021300e7..8e6ee193d 100644 --- a/src/gpu/lv_gpu_nxp_vglite.c +++ b/src/gpu/lv_gpu_nxp_vglite.c @@ -79,9 +79,9 @@ defined(CPU_MIMXRT595SFFOC) || defined(CPU_MIMXRT595SFFOC_cm33)) && \ ((LV_HOR_RES_MAX > RT595_BLIT_WRKRND_THR) || (LV_VER_RES_MAX > RT595_BLIT_WRKRND_THR)) && \ RT595_BLIT_WRKRND_ENABLED - #define _BLIT_SPLIT_ENABLED 1 +#define _BLIT_SPLIT_ENABLED 1 #else - #define _BLIT_SPLIT_ENABLED 0 +#define _BLIT_SPLIT_ENABLED 0 #endif /* BLIT split threshold - BLITs with width or height higher than this value will be done @@ -153,7 +153,8 @@ lv_res_t lv_gpu_nxp_vglite_fill(lv_color_t * dest_buf, lv_coord_t dest_width, lv lv_color32_t col32 = {.full = lv_color_to32(color)}; /*Convert color to RGBA8888*/ lv_disp_t * disp = _lv_refr_get_disp_refreshing(); - if(_init_vg_buf(&rt, (uint32_t) dest_width, (uint32_t) dest_height, (uint32_t) dest_width * sizeof(lv_color_t), (const lv_color_t *) dest_buf, false) != LV_RES_OK) { + if(_init_vg_buf(&rt, (uint32_t) dest_width, (uint32_t) dest_height, (uint32_t) dest_width * sizeof(lv_color_t), + (const lv_color_t *) dest_buf, false) != LV_RES_OK) { #if LV_GPU_NXP_VG_LITE_LOG_ERRORS LV_LOG_ERROR("init_vg_buf reported error. Fill failed."); #endif @@ -171,17 +172,17 @@ lv_res_t lv_gpu_nxp_vglite_fill(lv_color_t * dest_buf, lv_coord_t dest_width, lv } err = vg_lite_clear(&rt, &rect, col32.full); - if (err != VG_LITE_SUCCESS) { - #if LV_GPU_NXP_VG_LITE_LOG_ERRORS + if(err != VG_LITE_SUCCESS) { +#if LV_GPU_NXP_VG_LITE_LOG_ERRORS LV_LOG_ERROR("vg_lite_clear reported error. Fill failed."); - #endif +#endif return LV_RES_INV; } err = vg_lite_finish(); - if (err != VG_LITE_SUCCESS) { - #if LV_GPU_NXP_VG_LITE_LOG_ERRORS + if(err != VG_LITE_SUCCESS) { +#if LV_GPU_NXP_VG_LITE_LOG_ERRORS LV_LOG_ERROR("vg_lite_finish reported error. Fill failed."); - #endif +#endif return LV_RES_INV; } } @@ -199,7 +200,8 @@ lv_res_t lv_gpu_nxp_vglite_fill(lv_color_t * dest_buf, lv_coord_t dest_width, lv }; err = vg_lite_init_path(&path, VG_LITE_S16, VG_LITE_LOW, sizeof(path_data), path_data, - (vg_lite_float_t) fill_area->x1, (vg_lite_float_t) fill_area->y1, ((vg_lite_float_t) fill_area->x2) + 1.0f, ((vg_lite_float_t) fill_area->y2) + 1.0f); + (vg_lite_float_t) fill_area->x1, (vg_lite_float_t) fill_area->y1, ((vg_lite_float_t) fill_area->x2) + 1.0f, + ((vg_lite_float_t) fill_area->y2) + 1.0f); if(err != VG_LITE_SUCCESS) { #if LV_GPU_NXP_VG_LITE_LOG_ERRORS LV_LOG_ERROR("vg_lite_init_path() failed."); @@ -449,8 +451,8 @@ static lv_res_t _lv_gpu_nxp_vglite_blit_single(lv_gpu_nxp_vglite_blit_info_t * b lv_disp_t * disp = _lv_refr_get_disp_refreshing(); if(blit == NULL) { - /*Wrong parameter*/ - return LV_RES_INV; + /*Wrong parameter*/ + return LV_RES_INV; } if(blit->opa < (lv_opa_t) LV_OPA_MIN) { @@ -458,14 +460,16 @@ static lv_res_t _lv_gpu_nxp_vglite_blit_single(lv_gpu_nxp_vglite_blit_info_t * b } /*Wrap src/dst buffer into VG-Lite buffer*/ - if(_init_vg_buf(&src_vgbuf, (uint32_t) blit->src_width, (uint32_t) blit->src_height, (uint32_t) blit->src_stride, blit->src, true) != LV_RES_OK) { + if(_init_vg_buf(&src_vgbuf, (uint32_t) blit->src_width, (uint32_t) blit->src_height, (uint32_t) blit->src_stride, + blit->src, true) != LV_RES_OK) { #if LV_GPU_NXP_VG_LITE_LOG_ERRORS LV_LOG_ERROR("init_vg_buf reported error. BLIT failed."); #endif return LV_RES_INV; } - if(_init_vg_buf(&dst_vgbuf, (uint32_t) blit->dst_width, (uint32_t) blit->dst_height, (uint32_t) blit->dst_stride, blit->dst, false) != LV_RES_OK) { + if(_init_vg_buf(&dst_vgbuf, (uint32_t) blit->dst_width, (uint32_t) blit->dst_height, (uint32_t) blit->dst_stride, + blit->dst, false) != LV_RES_OK) { #if LV_GPU_NXP_VG_LITE_LOG_ERRORS LV_LOG_ERROR("init_vg_buf reported error. BLIT failed."); #endif @@ -543,9 +547,11 @@ static lv_res_t _init_vg_buf(vg_lite_buffer_t * dst, uint32_t width, uint32_t he return LV_RES_INV; } - if(source && (stride % (LV_GPU_NXP_VG_LITE_STRIDE_ALIGN_PX * sizeof(lv_color_t))) != 0x0U) { /*Test for stride alignment*/ + if(source && + (stride % (LV_GPU_NXP_VG_LITE_STRIDE_ALIGN_PX * sizeof(lv_color_t))) != 0x0U) { /*Test for stride alignment*/ #if LV_GPU_NXP_VG_LITE_LOG_ERRORS - LV_LOG_ERROR("Buffer stride (%d px) not aligned to %d bytes.", stride, LV_GPU_NXP_VG_LITE_STRIDE_ALIGN_PX * sizeof(lv_color_t)); + LV_LOG_ERROR("Buffer stride (%d px) not aligned to %d bytes.", stride, + LV_GPU_NXP_VG_LITE_STRIDE_ALIGN_PX * sizeof(lv_color_t)); #endif return LV_RES_INV; } @@ -559,8 +565,8 @@ static lv_res_t _init_vg_buf(vg_lite_buffer_t * dst, uint32_t width, uint32_t he dst->height = (int32_t) height; dst->stride = (int32_t) stride; - void *r_ptr = memset(&dst->yuv, 0, sizeof(dst->yuv)); - if (r_ptr == NULL) { + void * r_ptr = memset(&dst->yuv, 0, sizeof(dst->yuv)); + if(r_ptr == NULL) { return LV_RES_INV; } @@ -642,16 +648,20 @@ static lv_res_t _lv_gpu_nxp_vglite_check_blit(lv_gpu_nxp_vglite_blit_info_t * bl } /* No alignment requirement for destination pixel buffer when using mode VG_LITE_LINEAR */ - if((blit->src_stride % (LV_GPU_NXP_VG_LITE_STRIDE_ALIGN_PX * LV_COLOR_DEPTH / 8)) != 0x0) { /* Test for stride alignment */ + if((blit->src_stride % (LV_GPU_NXP_VG_LITE_STRIDE_ALIGN_PX * LV_COLOR_DEPTH / 8)) != + 0x0) { /* Test for stride alignment */ #if LV_GPU_NXP_VG_LITE_LOG_ERRORS - LV_LOG_ERROR("source buffer stride (%d px) not aligned to %d px.", blit->src_stride, LV_GPU_NXP_VG_LITE_STRIDE_ALIGN_PX); + LV_LOG_ERROR("source buffer stride (%d px) not aligned to %d px.", blit->src_stride, + LV_GPU_NXP_VG_LITE_STRIDE_ALIGN_PX); #endif return LV_RES_INV; } - if((blit->dst_stride % (LV_GPU_NXP_VG_LITE_STRIDE_ALIGN_PX * LV_COLOR_DEPTH / 8)) != 0x0) { /* Test for stride alignment */ + if((blit->dst_stride % (LV_GPU_NXP_VG_LITE_STRIDE_ALIGN_PX * LV_COLOR_DEPTH / 8)) != + 0x0) { /* Test for stride alignment */ #if LV_GPU_NXP_VG_LITE_LOG_ERRORS - LV_LOG_ERROR("destination buffer stride (%d px) not aligned to %d px.", blit->dst_stride, LV_GPU_NXP_VG_LITE_STRIDE_ALIGN_PX); + LV_LOG_ERROR("destination buffer stride (%d px) not aligned to %d px.", blit->dst_stride, + LV_GPU_NXP_VG_LITE_STRIDE_ALIGN_PX); #endif return LV_RES_INV; } @@ -675,7 +685,7 @@ static lv_res_t _lv_gpu_nxp_vglite_check_blit(lv_gpu_nxp_vglite_blit_info_t * bl static void _align_x(lv_area_t * area, lv_color_t ** buf) { - int alignedAreaStartPx = area->x1 - (area->x1 % (LV_ATTRIBUTE_MEM_ALIGN_SIZE * 8 / LV_COLOR_DEPTH) ); + int alignedAreaStartPx = area->x1 - (area->x1 % (LV_ATTRIBUTE_MEM_ALIGN_SIZE * 8 / LV_COLOR_DEPTH)); CHECK(alignedAreaStartPx < 0, "Should never happen."); area->x1 -= alignedAreaStartPx; @@ -696,9 +706,11 @@ static void _align_y(lv_area_t * area, lv_color_t ** buf, uint32_t stridePx) /* find how many lines of pixels will respect memory alignment requirement */ if(stridePx % LV_ATTRIBUTE_MEM_ALIGN_SIZE == 0) { alignedAreaStartPy = area->y1; - } else { + } + else { LineToAlignMem = LV_ATTRIBUTE_MEM_ALIGN_SIZE / (sizeof(lv_color_t) * LV_GPU_NXP_VG_LITE_STRIDE_ALIGN_PX); - CHECK(LV_ATTRIBUTE_MEM_ALIGN_SIZE % (sizeof(lv_color_t) * LV_GPU_NXP_VG_LITE_STRIDE_ALIGN_PX) != 0, "Complex case: need gcd function."); + CHECK(LV_ATTRIBUTE_MEM_ALIGN_SIZE % (sizeof(lv_color_t) * LV_GPU_NXP_VG_LITE_STRIDE_ALIGN_PX) != 0, + "Complex case: need gcd function."); alignedAreaStartPy = area->y1 - (area->y1 % LineToAlignMem); CHECK(alignedAreaStartPy < 0, "Should never happen."); } diff --git a/src/hal/lv_hal_disp.c b/src/hal/lv_hal_disp.c index 400dda73f..7d19e7ae8 100644 --- a/src/hal/lv_hal_disp.c +++ b/src/hal/lv_hal_disp.c @@ -18,7 +18,7 @@ #include "../core/lv_refr.h" #include "../core/lv_theme.h" #if LV_USE_THEME_DEFAULT -#include "../extra/themes/default/lv_theme_default.h" + #include "../extra/themes/default/lv_theme_default.h" #endif /********************* @@ -77,7 +77,7 @@ void lv_disp_drv_init(lv_disp_drv_t * driver) driver->hor_res = 320; driver->ver_res = 240; - driver->antialiasing = LV_COLOR_DEPTH > 8 ? 1: 0; + driver->antialiasing = LV_COLOR_DEPTH > 8 ? 1 : 0; driver->screen_transp = LV_COLOR_SCREEN_TRANSP; driver->dpi = LV_DPI_DEF; driver->color_chroma_key = LV_COLOR_CHROMA_KEY; @@ -151,7 +151,8 @@ lv_disp_t * lv_disp_drv_register(lv_disp_drv_t * driver) #if LV_USE_THEME_DEFAULT if(lv_theme_default_is_inited() == false) { - disp->theme = lv_theme_default_init(disp, lv_palette_main(LV_PALETTE_BLUE), lv_palette_main(LV_PALETTE_RED), LV_THEME_DEFAULT_DARK, LV_FONT_DEFAULT); + disp->theme = lv_theme_default_init(disp, lv_palette_main(LV_PALETTE_BLUE), lv_palette_main(LV_PALETTE_RED), + LV_THEME_DEFAULT_DARK, LV_FONT_DEFAULT); } #endif @@ -185,7 +186,8 @@ void lv_disp_drv_update(lv_disp_t * disp, lv_disp_drv_t * new_drv) { disp->driver = new_drv; - if(disp->driver->full_refresh && disp->driver->draw_buf->size < (uint32_t)disp->driver->hor_res * disp->driver->ver_res) { + if(disp->driver->full_refresh && + disp->driver->draw_buf->size < (uint32_t)disp->driver->hor_res * disp->driver->ver_res) { disp->driver->full_refresh = 0; LV_LOG_WARN("full_refresh requires at least screen sized draw buffer(s)"); } @@ -237,15 +239,15 @@ void lv_disp_remove(lv_disp_t * disp) } /** delete screen and other obj */ - if (disp->sys_layer) { + if(disp->sys_layer) { lv_obj_del(disp->sys_layer); disp->sys_layer = NULL; } - if (disp->top_layer) { + if(disp->top_layer) { lv_obj_del(disp->top_layer); disp->top_layer = NULL; } - while (disp->screen_cnt != 0) { + while(disp->screen_cnt != 0) { /*Delete the screenst*/ lv_obj_del(disp->screens[0]); } @@ -286,7 +288,8 @@ lv_coord_t lv_disp_get_hor_res(lv_disp_t * disp) if(disp == NULL) { return 0; - } else { + } + else { switch(disp->driver->rotated) { case LV_DISP_ROT_90: case LV_DISP_ROT_270: @@ -308,7 +311,8 @@ lv_coord_t lv_disp_get_ver_res(lv_disp_t * disp) if(disp == NULL) { return 0; - } else { + } + else { switch(disp->driver->rotated) { case LV_DISP_ROT_90: case LV_DISP_ROT_270: diff --git a/src/hal/lv_hal_disp.h b/src/hal/lv_hal_disp.h index 22344df3c..1c3d83bcd 100644 --- a/src/hal/lv_hal_disp.h +++ b/src/hal/lv_hal_disp.h @@ -47,7 +47,7 @@ struct _lv_theme_t; /** * Structure for holding display buffer information. */ -typedef struct _lv_disp_draw_buf_t{ +typedef struct _lv_disp_draw_buf_t { void * buf1; /**< First display buffer.*/ void * buf2; /**< Second display buffer.*/ @@ -161,7 +161,8 @@ typedef struct _lv_disp_t { struct _lv_obj_t * top_layer; /**< @see lv_disp_get_layer_top*/ struct _lv_obj_t * sys_layer; /**< @see lv_disp_get_layer_sys*/ uint32_t screen_cnt; - uint8_t del_prev : 1; /**< 1: Automatically delete the previous screen when the screen load animation is ready*/ +uint8_t del_prev : + 1; /**< 1: Automatically delete the previous screen when the screen load animation is ready*/ lv_opa_t bg_opa; /**= _LV_PALETTE_LAST) { - LV_LOG_WARN("Invalid palette: %d", p); - return lv_color_black(); - } + if(p >= _LV_PALETTE_LAST) { + LV_LOG_WARN("Invalid palette: %d", p); + return lv_color_black(); + } - if(lvl == 0 || lvl > 5) { - LV_LOG_WARN("Invalid level: %d. Must be 1..5", lvl); - return lv_color_black(); - } + if(lvl == 0 || lvl > 5) { + LV_LOG_WARN("Invalid level: %d. Must be 1..5", lvl); + return lv_color_black(); + } - lvl--; + lvl--; - return colors[p][lvl]; + return colors[p][lvl]; } lv_color_t lv_palette_darken(lv_palette_t p, uint8_t lvl) { static const lv_color_t colors[][4] = { - {LV_COLOR_MAKE(0xE5, 0x39, 0x35), LV_COLOR_MAKE(0xD3, 0x2F, 0x2F), LV_COLOR_MAKE(0xC6, 0x28, 0x28), LV_COLOR_MAKE(0xB7, 0x1C, 0x1C)}, - {LV_COLOR_MAKE(0xD8, 0x1B, 0x60), LV_COLOR_MAKE(0xC2, 0x18, 0x5B), LV_COLOR_MAKE(0xAD, 0x14, 0x57), LV_COLOR_MAKE(0x88, 0x0E, 0x4F)}, - {LV_COLOR_MAKE(0x8E, 0x24, 0xAA), LV_COLOR_MAKE(0x7B, 0x1F, 0xA2), LV_COLOR_MAKE(0x6A, 0x1B, 0x9A), LV_COLOR_MAKE(0x4A, 0x14, 0x8C)}, - {LV_COLOR_MAKE(0x5E, 0x35, 0xB1), LV_COLOR_MAKE(0x51, 0x2D, 0xA8), LV_COLOR_MAKE(0x45, 0x27, 0xA0), LV_COLOR_MAKE(0x31, 0x1B, 0x92)}, - {LV_COLOR_MAKE(0x39, 0x49, 0xAB), LV_COLOR_MAKE(0x30, 0x3F, 0x9F), LV_COLOR_MAKE(0x28, 0x35, 0x93), LV_COLOR_MAKE(0x1A, 0x23, 0x7E)}, - {LV_COLOR_MAKE(0x1E, 0x88, 0xE5), LV_COLOR_MAKE(0x19, 0x76, 0xD2), LV_COLOR_MAKE(0x15, 0x65, 0xC0), LV_COLOR_MAKE(0x0D, 0x47, 0xA1)}, - {LV_COLOR_MAKE(0x03, 0x9B, 0xE5), LV_COLOR_MAKE(0x02, 0x88, 0xD1), LV_COLOR_MAKE(0x02, 0x77, 0xBD), LV_COLOR_MAKE(0x01, 0x57, 0x9B)}, - {LV_COLOR_MAKE(0x00, 0xAC, 0xC1), LV_COLOR_MAKE(0x00, 0x97, 0xA7), LV_COLOR_MAKE(0x00, 0x83, 0x8F), LV_COLOR_MAKE(0x00, 0x60, 0x64)}, - {LV_COLOR_MAKE(0x00, 0x89, 0x7B), LV_COLOR_MAKE(0x00, 0x79, 0x6B), LV_COLOR_MAKE(0x00, 0x69, 0x5C), LV_COLOR_MAKE(0x00, 0x4D, 0x40)}, - {LV_COLOR_MAKE(0x43, 0xA0, 0x47), LV_COLOR_MAKE(0x38, 0x8E, 0x3C), LV_COLOR_MAKE(0x2E, 0x7D, 0x32), LV_COLOR_MAKE(0x1B, 0x5E, 0x20)}, - {LV_COLOR_MAKE(0x7C, 0xB3, 0x42), LV_COLOR_MAKE(0x68, 0x9F, 0x38), LV_COLOR_MAKE(0x55, 0x8B, 0x2F), LV_COLOR_MAKE(0x33, 0x69, 0x1E)}, - {LV_COLOR_MAKE(0xC0, 0xCA, 0x33), LV_COLOR_MAKE(0xAF, 0xB4, 0x2B), LV_COLOR_MAKE(0x9E, 0x9D, 0x24), LV_COLOR_MAKE(0x82, 0x77, 0x17)}, - {LV_COLOR_MAKE(0xFD, 0xD8, 0x35), LV_COLOR_MAKE(0xFB, 0xC0, 0x2D), LV_COLOR_MAKE(0xF9, 0xA8, 0x25), LV_COLOR_MAKE(0xF5, 0x7F, 0x17)}, - {LV_COLOR_MAKE(0xFF, 0xB3, 0x00), LV_COLOR_MAKE(0xFF, 0xA0, 0x00), LV_COLOR_MAKE(0xFF, 0x8F, 0x00), LV_COLOR_MAKE(0xFF, 0x6F, 0x00)}, - {LV_COLOR_MAKE(0xFB, 0x8C, 0x00), LV_COLOR_MAKE(0xF5, 0x7C, 0x00), LV_COLOR_MAKE(0xEF, 0x6C, 0x00), LV_COLOR_MAKE(0xE6, 0x51, 0x00)}, - {LV_COLOR_MAKE(0xF4, 0x51, 0x1E), LV_COLOR_MAKE(0xE6, 0x4A, 0x19), LV_COLOR_MAKE(0xD8, 0x43, 0x15), LV_COLOR_MAKE(0xBF, 0x36, 0x0C)}, - {LV_COLOR_MAKE(0x6D, 0x4C, 0x41), LV_COLOR_MAKE(0x5D, 0x40, 0x37), LV_COLOR_MAKE(0x4E, 0x34, 0x2E), LV_COLOR_MAKE(0x3E, 0x27, 0x23)}, - {LV_COLOR_MAKE(0x54, 0x6E, 0x7A), LV_COLOR_MAKE(0x45, 0x5A, 0x64), LV_COLOR_MAKE(0x37, 0x47, 0x4F), LV_COLOR_MAKE(0x26, 0x32, 0x38)}, - {LV_COLOR_MAKE(0x75, 0x75, 0x75), LV_COLOR_MAKE(0x61, 0x61, 0x61), LV_COLOR_MAKE(0x42, 0x42, 0x42), LV_COLOR_MAKE(0x21, 0x21, 0x21)}, + {LV_COLOR_MAKE(0xE5, 0x39, 0x35), LV_COLOR_MAKE(0xD3, 0x2F, 0x2F), LV_COLOR_MAKE(0xC6, 0x28, 0x28), LV_COLOR_MAKE(0xB7, 0x1C, 0x1C)}, + {LV_COLOR_MAKE(0xD8, 0x1B, 0x60), LV_COLOR_MAKE(0xC2, 0x18, 0x5B), LV_COLOR_MAKE(0xAD, 0x14, 0x57), LV_COLOR_MAKE(0x88, 0x0E, 0x4F)}, + {LV_COLOR_MAKE(0x8E, 0x24, 0xAA), LV_COLOR_MAKE(0x7B, 0x1F, 0xA2), LV_COLOR_MAKE(0x6A, 0x1B, 0x9A), LV_COLOR_MAKE(0x4A, 0x14, 0x8C)}, + {LV_COLOR_MAKE(0x5E, 0x35, 0xB1), LV_COLOR_MAKE(0x51, 0x2D, 0xA8), LV_COLOR_MAKE(0x45, 0x27, 0xA0), LV_COLOR_MAKE(0x31, 0x1B, 0x92)}, + {LV_COLOR_MAKE(0x39, 0x49, 0xAB), LV_COLOR_MAKE(0x30, 0x3F, 0x9F), LV_COLOR_MAKE(0x28, 0x35, 0x93), LV_COLOR_MAKE(0x1A, 0x23, 0x7E)}, + {LV_COLOR_MAKE(0x1E, 0x88, 0xE5), LV_COLOR_MAKE(0x19, 0x76, 0xD2), LV_COLOR_MAKE(0x15, 0x65, 0xC0), LV_COLOR_MAKE(0x0D, 0x47, 0xA1)}, + {LV_COLOR_MAKE(0x03, 0x9B, 0xE5), LV_COLOR_MAKE(0x02, 0x88, 0xD1), LV_COLOR_MAKE(0x02, 0x77, 0xBD), LV_COLOR_MAKE(0x01, 0x57, 0x9B)}, + {LV_COLOR_MAKE(0x00, 0xAC, 0xC1), LV_COLOR_MAKE(0x00, 0x97, 0xA7), LV_COLOR_MAKE(0x00, 0x83, 0x8F), LV_COLOR_MAKE(0x00, 0x60, 0x64)}, + {LV_COLOR_MAKE(0x00, 0x89, 0x7B), LV_COLOR_MAKE(0x00, 0x79, 0x6B), LV_COLOR_MAKE(0x00, 0x69, 0x5C), LV_COLOR_MAKE(0x00, 0x4D, 0x40)}, + {LV_COLOR_MAKE(0x43, 0xA0, 0x47), LV_COLOR_MAKE(0x38, 0x8E, 0x3C), LV_COLOR_MAKE(0x2E, 0x7D, 0x32), LV_COLOR_MAKE(0x1B, 0x5E, 0x20)}, + {LV_COLOR_MAKE(0x7C, 0xB3, 0x42), LV_COLOR_MAKE(0x68, 0x9F, 0x38), LV_COLOR_MAKE(0x55, 0x8B, 0x2F), LV_COLOR_MAKE(0x33, 0x69, 0x1E)}, + {LV_COLOR_MAKE(0xC0, 0xCA, 0x33), LV_COLOR_MAKE(0xAF, 0xB4, 0x2B), LV_COLOR_MAKE(0x9E, 0x9D, 0x24), LV_COLOR_MAKE(0x82, 0x77, 0x17)}, + {LV_COLOR_MAKE(0xFD, 0xD8, 0x35), LV_COLOR_MAKE(0xFB, 0xC0, 0x2D), LV_COLOR_MAKE(0xF9, 0xA8, 0x25), LV_COLOR_MAKE(0xF5, 0x7F, 0x17)}, + {LV_COLOR_MAKE(0xFF, 0xB3, 0x00), LV_COLOR_MAKE(0xFF, 0xA0, 0x00), LV_COLOR_MAKE(0xFF, 0x8F, 0x00), LV_COLOR_MAKE(0xFF, 0x6F, 0x00)}, + {LV_COLOR_MAKE(0xFB, 0x8C, 0x00), LV_COLOR_MAKE(0xF5, 0x7C, 0x00), LV_COLOR_MAKE(0xEF, 0x6C, 0x00), LV_COLOR_MAKE(0xE6, 0x51, 0x00)}, + {LV_COLOR_MAKE(0xF4, 0x51, 0x1E), LV_COLOR_MAKE(0xE6, 0x4A, 0x19), LV_COLOR_MAKE(0xD8, 0x43, 0x15), LV_COLOR_MAKE(0xBF, 0x36, 0x0C)}, + {LV_COLOR_MAKE(0x6D, 0x4C, 0x41), LV_COLOR_MAKE(0x5D, 0x40, 0x37), LV_COLOR_MAKE(0x4E, 0x34, 0x2E), LV_COLOR_MAKE(0x3E, 0x27, 0x23)}, + {LV_COLOR_MAKE(0x54, 0x6E, 0x7A), LV_COLOR_MAKE(0x45, 0x5A, 0x64), LV_COLOR_MAKE(0x37, 0x47, 0x4F), LV_COLOR_MAKE(0x26, 0x32, 0x38)}, + {LV_COLOR_MAKE(0x75, 0x75, 0x75), LV_COLOR_MAKE(0x61, 0x61, 0x61), LV_COLOR_MAKE(0x42, 0x42, 0x42), LV_COLOR_MAKE(0x21, 0x21, 0x21)}, }; - if(p >= _LV_PALETTE_LAST) { - LV_LOG_WARN("Invalid palette: %d", p); - return lv_color_black(); - } + if(p >= _LV_PALETTE_LAST) { + LV_LOG_WARN("Invalid palette: %d", p); + return lv_color_black(); + } - if(lvl == 0 || lvl > 4) { - LV_LOG_WARN("Invalid level: %d. Must be 1..4", lvl); - return lv_color_black(); - } + if(lvl == 0 || lvl > 4) { + LV_LOG_WARN("Invalid level: %d. Must be 1..4", lvl); + return lv_color_black(); + } - lvl--; + lvl--; - return colors[p][lvl]; + return colors[p][lvl]; } diff --git a/src/misc/lv_color.h b/src/misc/lv_color.h index 3b2825c26..6e3b4bea8 100644 --- a/src/misc/lv_color.h +++ b/src/misc/lv_color.h @@ -272,7 +272,7 @@ typedef lv_color_t (*lv_color_filter_cb_t)(const struct _lv_color_filter_dsc_t * typedef struct _lv_color_filter_dsc_t { lv_color_filter_cb_t filter_cb; void * user_data; -}lv_color_filter_dsc_t; +} lv_color_filter_dsc_t; typedef enum { @@ -297,7 +297,7 @@ typedef enum { LV_PALETTE_GREY, _LV_PALETTE_LAST, LV_PALETTE_NONE = 0xff, -}lv_palette_t; +} lv_palette_t; /********************** * GLOBAL PROTOTYPES @@ -462,19 +462,20 @@ LV_ATTRIBUTE_FAST_MEM static inline lv_color_t lv_color_mix(lv_color_t c1, lv_co #if LV_COLOR_DEPTH == 16 && LV_COLOR_16_SWAP == 0 /*Source: https://stackoverflow.com/a/50012418/1999969*/ - mix = ( mix + 4 ) >> 3; - uint32_t bg = (uint32_t)((uint32_t)c2.full | ((uint32_t)c2.full << 16)) & 0x7E0F81F; /*0b00000111111000001111100000011111*/ + mix = (mix + 4) >> 3; + uint32_t bg = (uint32_t)((uint32_t)c2.full | ((uint32_t)c2.full << 16)) & + 0x7E0F81F; /*0b00000111111000001111100000011111*/ uint32_t fg = (uint32_t)((uint32_t)c1.full | ((uint32_t)c1.full << 16)) & 0x7E0F81F; uint32_t result = ((((fg - bg) * mix) >> 5) + bg) & 0x7E0F81F; ret.full = (uint16_t)((result >> 16) | result); #elif LV_COLOR_DEPTH != 1 /*LV_COLOR_DEPTH == 8, 16 or 32*/ LV_COLOR_SET_R(ret, LV_UDIV255((uint16_t) LV_COLOR_GET_R(c1) * mix + LV_COLOR_GET_R(c2) * - (255 - mix) + LV_COLOR_MIX_ROUND_OFS)); + (255 - mix) + LV_COLOR_MIX_ROUND_OFS)); LV_COLOR_SET_G(ret, LV_UDIV255((uint16_t) LV_COLOR_GET_G(c1) * mix + LV_COLOR_GET_G(c2) * - (255 - mix) + LV_COLOR_MIX_ROUND_OFS)); + (255 - mix) + LV_COLOR_MIX_ROUND_OFS)); LV_COLOR_SET_B(ret, LV_UDIV255((uint16_t) LV_COLOR_GET_B(c1) * mix + LV_COLOR_GET_B(c2) * - (255 - mix) + LV_COLOR_MIX_ROUND_OFS)); + (255 - mix) + LV_COLOR_MIX_ROUND_OFS)); LV_COLOR_SET_A(ret, 0xFF); #else /*LV_COLOR_DEPTH == 1*/ @@ -679,8 +680,14 @@ static inline lv_color_t lv_color_chroma_key(void) /*Source: https://vuetifyjs.com/en/styles/colors/#material-colors*/ lv_color_t lv_palette_main(lv_palette_t p); -static inline lv_color_t lv_color_white(void) { return lv_color_make(0xff, 0xff, 0xff);} -static inline lv_color_t lv_color_black(void) { return lv_color_make(0x00, 0x0, 0x00);} +static inline lv_color_t lv_color_white(void) +{ + return lv_color_make(0xff, 0xff, 0xff); +} +static inline lv_color_t lv_color_black(void) +{ + return lv_color_make(0x00, 0x0, 0x00); +} lv_color_t lv_palette_lighten(lv_palette_t p, uint8_t lvl); lv_color_t lv_palette_darken(lv_palette_t p, uint8_t lvl); diff --git a/src/misc/lv_fs.c b/src/misc/lv_fs.c index 6d6444331..eecda27d9 100644 --- a/src/misc/lv_fs.c +++ b/src/misc/lv_fs.c @@ -91,9 +91,9 @@ lv_fs_res_t lv_fs_open(lv_fs_file_t * file_p, const char * path, lv_fs_mode_t mo } const char * real_path = lv_fs_get_real_path(path); - void *file_d = drv->open_cb(drv, real_path, mode); + void * file_d = drv->open_cb(drv, real_path, mode); - if(file_d == NULL || file_d == (void*)(-1)) { + if(file_d == NULL || file_d == (void *)(-1)) { return LV_FS_RES_UNKNOWN; } @@ -207,9 +207,9 @@ lv_fs_res_t lv_fs_dir_open(lv_fs_dir_t * rddir_p, const char * path) } const char * real_path = lv_fs_get_real_path(path); - void *dir_d = drv->dir_open_cb(drv, real_path); + void * dir_d = drv->dir_open_cb(drv, real_path); - if(dir_d == NULL || dir_d == (void*)(-1)) { + if(dir_d == NULL || dir_d == (void *)(-1)) { return LV_FS_RES_UNKNOWN; } diff --git a/src/misc/lv_fs.h b/src/misc/lv_fs.h index d07f9668a..9afc2bf57 100644 --- a/src/misc/lv_fs.h +++ b/src/misc/lv_fs.h @@ -65,7 +65,7 @@ typedef enum { LV_FS_SEEK_SET = 0x00, /**< Set the position from absolutely (from the start of file)*/ LV_FS_SEEK_CUR = 0x01, /**< Set the position from the current position*/ LV_FS_SEEK_END = 0x02, /**< Set the position from the end of the file*/ -}lv_fs_whence_t; +} lv_fs_whence_t; typedef struct _lv_fs_drv_t { char letter; diff --git a/src/misc/lv_log.c b/src/misc/lv_log.c index 9b008d417..4cca4a3b5 100644 --- a/src/misc/lv_log.c +++ b/src/misc/lv_log.c @@ -88,7 +88,8 @@ void _lv_log_add(lv_log_level_t level, const char * file, int line, const char * char buf[512]; uint32_t t = lv_tick_get(); static const char * lvl_prefix[] = {"Trace", "Info", "Warn", "Error", "User"}; - lv_snprintf(buf, sizeof(buf), "[%s]\t(%" LV_PRId32 ".%03" LV_PRId32 ", +%" LV_PRId32 ")\t %s: %s \t(in %s line #%d)\n", lvl_prefix[level], t / 1000, t % 1000, t - last_log_time, func, msg, &file[p], line); + lv_snprintf(buf, sizeof(buf), "[%s]\t(%" LV_PRId32 ".%03" LV_PRId32 ", +%" LV_PRId32 ")\t %s: %s \t(in %s line #%d)\n", + lvl_prefix[level], t / 1000, t % 1000, t - last_log_time, func, msg, &file[p], line); last_log_time = t; lv_log(buf); } diff --git a/src/misc/lv_log.h b/src/misc/lv_log.h index 05ecce3ac..e1f2df9ca 100644 --- a/src/misc/lv_log.h +++ b/src/misc/lv_log.h @@ -47,7 +47,7 @@ typedef int8_t lv_log_level_t; /** * Log print function. Receives a string buffer to print". */ -typedef void (*lv_log_print_g_cb_t)(const char *buf); +typedef void (*lv_log_print_g_cb_t)(const char * buf); /********************** * GLOBAL PROTOTYPES diff --git a/src/misc/lv_mem.c b/src/misc/lv_mem.c index 7d4477b3b..b50bebe99 100644 --- a/src/misc/lv_mem.c +++ b/src/misc/lv_mem.c @@ -26,15 +26,15 @@ *********************/ /*memset the allocated memories to 0xaa and freed memories to 0xbb (just for testing purposes)*/ #ifndef LV_MEM_ADD_JUNK -# define LV_MEM_ADD_JUNK 0 + #define LV_MEM_ADD_JUNK 0 #endif #ifdef LV_ARCH_64 -# define MEM_UNIT uint64_t -# define ALIGN_MASK 0x7 + #define MEM_UNIT uint64_t + #define ALIGN_MASK 0x7 #else -# define MEM_UNIT uint32_t -# define ALIGN_MASK 0x7 + #define MEM_UNIT uint32_t + #define ALIGN_MASK 0x7 #endif #define ZERO_MEM_SENTINEL 0xa1b2c3d4 @@ -63,9 +63,9 @@ static uint32_t zero_mem = ZERO_MEM_SENTINEL; /*Give the address of this variabl * MACROS **********************/ #if LV_LOG_TRACE_MEM -# define MEM_TRACE(...) LV_LOG_TRACE( __VA_ARGS__) + #define MEM_TRACE(...) LV_LOG_TRACE( __VA_ARGS__) #else -# define MEM_TRACE(...) + #define MEM_TRACE(...) #endif #define COPY32 *d32 = *s32; d32++; s32++; @@ -143,8 +143,8 @@ void * lv_mem_alloc(size_t size) lv_mem_monitor_t mon; lv_mem_monitor(&mon); LV_LOG_ERROR("used: %6d (%3d %%), frag: %3d %%, biggest free: %6d", - (int)mon.total_size - mon.free_size, mon.used_pct, mon.frag_pct, - (int)mon.free_biggest_size); + (int)mon.total_size - mon.free_size, mon.used_pct, mon.frag_pct, + (int)mon.free_biggest_size); } MEM_TRACE("allocated at %p", alloc); @@ -216,7 +216,7 @@ lv_res_t lv_mem_test(void) return LV_RES_INV; } - if (lv_tlsf_check_pool(lv_tlsf_get_pool(tlsf))) { + if(lv_tlsf_check_pool(lv_tlsf_get_pool(tlsf))) { LV_LOG_WARN("pool failed"); return LV_RES_INV; } @@ -284,7 +284,8 @@ void * lv_mem_buf_get(uint32_t size) if(i_guess >= 0) { LV_GC_ROOT(lv_mem_buf[i_guess]).used = 1; - MEM_TRACE("returning already allocated buffer (buffer id: %d, address: %p)", i_guess, LV_GC_ROOT(lv_mem_buf[i_guess]).p); + MEM_TRACE("returning already allocated buffer (buffer id: %d, address: %p)", i_guess, + LV_GC_ROOT(lv_mem_buf[i_guess]).p); return LV_GC_ROOT(lv_mem_buf[i_guess]).p; } diff --git a/src/misc/lv_printf.h b/src/misc/lv_printf.h index 933519765..3b99b7112 100644 --- a/src/misc/lv_printf.h +++ b/src/misc/lv_printf.h @@ -35,12 +35,12 @@ #define _LV_PRINTF_H_ #if defined(__has_include) && __has_include() - #include - /* platform-specific printf format for int32_t, usually "d" or "ld" */ - #define LV_PRId32 PRId32 + #include + /* platform-specific printf format for int32_t, usually "d" or "ld" */ + #define LV_PRId32 PRId32 #else - /* hope this is correct for ports without __has_include or without inttypes.h */ - #define LV_PRId32 "d" + /* hope this is correct for ports without __has_include or without inttypes.h */ + #define LV_PRId32 "d" #endif #ifdef __cplusplus diff --git a/src/misc/lv_style.c b/src/misc/lv_style.c index 2755b285f..bcf76c948 100644 --- a/src/misc/lv_style.c +++ b/src/misc/lv_style.c @@ -106,7 +106,8 @@ bool lv_style_remove_prop(lv_style_t * style, lv_style_prop_t prop) style->prop_cnt = 1; style->prop1 = i == 0 ? old_props[1] : old_props[0]; style->v_p.value1 = i == 0 ? old_values[1] : old_values[0]; - } else { + } + else { size_t size = (style->prop_cnt - 1) * (sizeof(lv_style_value_t) + sizeof(uint16_t)); uint8_t * new_values_and_props = lv_mem_alloc(size); if(new_values_and_props == NULL) return false; @@ -118,7 +119,8 @@ bool lv_style_remove_prop(lv_style_t * style, lv_style_prop_t prop) lv_style_value_t * new_values = (lv_style_value_t *)new_values_and_props; uint32_t j; - for(i = j = 0; j <= style->prop_cnt; j++) { /*<=: because prop_cnt already reduced but all the old props. needs to be checked.*/ + for(i = j = 0; j <= style->prop_cnt; + j++) { /*<=: because prop_cnt already reduced but all the old props. needs to be checked.*/ if(old_props[j] != prop) { new_values[i] = old_values[j]; new_props[i++] = old_props[j]; @@ -164,7 +166,7 @@ void lv_style_set_prop(lv_style_t * style, lv_style_prop_t prop, lv_style_value_ props = (uint16_t *)tmp; /*Shift all props to make place for the value before them*/ for(i = style->prop_cnt - 1; i >= 0; i--) { - props[i + sizeof(lv_style_value_t) /sizeof(uint16_t)] = props[i]; + props[i + sizeof(lv_style_value_t) / sizeof(uint16_t)] = props[i]; } style->prop_cnt++; @@ -176,7 +178,8 @@ void lv_style_set_prop(lv_style_t * style, lv_style_prop_t prop, lv_style_value_ /*Set the new property and value*/ props[style->prop_cnt - 1] = prop; values[style->prop_cnt - 1] = value; - } else if(style->prop_cnt == 1) { + } + else if(style->prop_cnt == 1) { if(style->prop1 == prop) { style->v_p.value1 = value; return; @@ -195,7 +198,8 @@ void lv_style_set_prop(lv_style_t * style, lv_style_prop_t prop, lv_style_value_ props[1] = prop; values[0] = value_tmp; values[1] = value; - } else { + } + else { style->prop_cnt = 1; style->prop1 = prop; style->v_p.value1 = value; @@ -207,10 +211,11 @@ void lv_style_set_prop(lv_style_t * style, lv_style_prop_t prop, lv_style_value_ lv_res_t lv_style_get_prop(lv_style_t * style, lv_style_prop_t prop, lv_style_value_t * value) { - return lv_style_get_prop_inlined(style, prop, value); + return lv_style_get_prop_inlined(style, prop, value); } -void lv_style_transition_dsc_init(lv_style_transition_dsc_t * tr, const lv_style_prop_t props[], lv_anim_path_cb_t path_cb, uint32_t time, uint32_t delay, void * user_data) +void lv_style_transition_dsc_init(lv_style_transition_dsc_t * tr, const lv_style_prop_t props[], + lv_anim_path_cb_t path_cb, uint32_t time, uint32_t delay, void * user_data) { lv_memset_00(tr, sizeof(lv_style_transition_dsc_t)); tr->props = props; diff --git a/src/misc/lv_style.h b/src/misc/lv_style.h index 74f1e6a11..a5f193d7a 100644 --- a/src/misc/lv_style.h +++ b/src/misc/lv_style.h @@ -110,7 +110,7 @@ typedef union { int32_t num; /**< Number integer number (opacity, enums, booleans or "normal" numbers)*/ const void * ptr; /**< Constant pointers (font, cone text, etc)*/ lv_color_t color; /**< Colors*/ -}lv_style_value_t; +} lv_style_value_t; /** * Enumeration of all built in style properties @@ -229,7 +229,7 @@ typedef enum { _LV_STYLE_LAST_BUILT_IN_PROP = 111, LV_STYLE_PROP_ANY = 0xFFFF -}lv_style_prop_t; +} lv_style_prop_t; /** * Descriptor for style transitions @@ -242,7 +242,7 @@ typedef struct { lv_anim_path_cb_t path_xcb; /**< A path for the animation.*/ uint32_t time; /**< Duration of the transition in [ms]*/ uint32_t delay; /**< Delay before the transition in [ms]*/ -}lv_style_transition_dsc_t; +} lv_style_transition_dsc_t; /** * Descriptor of a constant style property. @@ -269,8 +269,8 @@ typedef struct { const lv_style_const_prop_t * const_props; } v_p; - uint16_t prop1 :15; - uint16_t is_const :1; + uint16_t prop1 : 15; + uint16_t is_const : 1; uint8_t has_group; uint8_t prop_cnt; } lv_style_t; @@ -353,7 +353,7 @@ lv_res_t lv_style_get_prop(lv_style_t * style, lv_style_prop_t prop, lv_style_va static inline lv_res_t lv_style_get_prop_inlined(lv_style_t * style, lv_style_prop_t prop, lv_style_value_t * value) { if(style->is_const) { - const lv_style_const_prop_t *const_prop; + const lv_style_const_prop_t * const_prop; for(const_prop = style->v_p.const_props; const_prop->prop != LV_STYLE_PROP_INV; const_prop++) { if(const_prop->prop == prop) { *value = const_prop->value; @@ -376,7 +376,8 @@ static inline lv_res_t lv_style_get_prop_inlined(lv_style_t * style, lv_style_pr return LV_RES_OK; } } - } else if(style->prop1 == prop) { + } + else if(style->prop1 == prop) { *value = style->v_p.value1; return LV_RES_OK; } @@ -396,7 +397,8 @@ static inline lv_res_t lv_style_get_prop_inlined(lv_style_t * style, lv_style_pr * static lv_style_transition_dsc_t trans1; * lv_style_transition_dsc_init(&trans1, trans_props, NULL, 300, 0, NULL); */ -void lv_style_transition_dsc_init(lv_style_transition_dsc_t * tr, const lv_style_prop_t props[], lv_anim_path_cb_t path_cb, uint32_t time, uint32_t delay, void * user_data); +void lv_style_transition_dsc_init(lv_style_transition_dsc_t * tr, const lv_style_prop_t props[], + lv_anim_path_cb_t path_cb, uint32_t time, uint32_t delay, void * user_data); /** * Get the default value of a property @@ -422,29 +424,34 @@ uint8_t _lv_style_get_prop_group(lv_style_prop_t prop); #include "lv_style_gen.h" -static inline void lv_style_set_pad_all(lv_style_t * style, lv_coord_t value) { +static inline void lv_style_set_pad_all(lv_style_t * style, lv_coord_t value) +{ lv_style_set_pad_left(style, value); lv_style_set_pad_right(style, value); lv_style_set_pad_top(style, value); lv_style_set_pad_bottom(style, value); } -static inline void lv_style_set_pad_hor(lv_style_t * style, lv_coord_t value) { +static inline void lv_style_set_pad_hor(lv_style_t * style, lv_coord_t value) +{ lv_style_set_pad_left(style, value); lv_style_set_pad_right(style, value); } -static inline void lv_style_set_pad_ver(lv_style_t * style, lv_coord_t value) { +static inline void lv_style_set_pad_ver(lv_style_t * style, lv_coord_t value) +{ lv_style_set_pad_top(style, value); lv_style_set_pad_bottom(style, value); } -static inline void lv_style_set_pad_gap(lv_style_t * style, lv_coord_t value) { +static inline void lv_style_set_pad_gap(lv_style_t * style, lv_coord_t value) +{ lv_style_set_pad_row(style, value); lv_style_set_pad_column(style, value); } -static inline void lv_style_set_size(lv_style_t * style, lv_coord_t value) { +static inline void lv_style_set_size(lv_style_t * style, lv_coord_t value) +{ lv_style_set_width(style, value); lv_style_set_height(style, value); } @@ -460,7 +467,7 @@ static inline void lv_style_set_size(lv_style_t * style, lv_coord_t value) { #if LV_USE_ASSERT_STYLE # define LV_ASSERT_STYLE(style_p) LV_ASSERT_MSG(style_p != NULL, "The style is NULL"); \ - LV_ASSERT_MSG(style_p->sentinel == LV_STYLE_SENTINEL_VALUE, "Style is not initialized or corrupted"); + LV_ASSERT_MSG(style_p->sentinel == LV_STYLE_SENTINEL_VALUE, "Style is not initialized or corrupted"); #else # define LV_ASSERT_STYLE(p) #endif diff --git a/src/misc/lv_style_gen.h b/src/misc/lv_style_gen.h index eeb648ece..00672d892 100644 --- a/src/misc/lv_style_gen.h +++ b/src/misc/lv_style_gen.h @@ -90,712 +90,712 @@ void lv_style_set_arc_img_src(lv_style_t * style, const void * value); #define LV_STYLE_CONST_WIDTH(val) \ { \ .prop = LV_STYLE_WIDTH, \ - .value = { \ - .num = (int32_t)val \ - } \ + .value = { \ + .num = (int32_t)val \ + } \ } #define LV_STYLE_CONST_MIN_WIDTH(val) \ { \ .prop = LV_STYLE_MIN_WIDTH, \ - .value = { \ - .num = (int32_t)val \ - } \ + .value = { \ + .num = (int32_t)val \ + } \ } #define LV_STYLE_CONST_MAX_WIDTH(val) \ { \ .prop = LV_STYLE_MAX_WIDTH, \ - .value = { \ - .num = (int32_t)val \ - } \ + .value = { \ + .num = (int32_t)val \ + } \ } #define LV_STYLE_CONST_HEIGHT(val) \ { \ .prop = LV_STYLE_HEIGHT, \ - .value = { \ - .num = (int32_t)val \ - } \ + .value = { \ + .num = (int32_t)val \ + } \ } #define LV_STYLE_CONST_MIN_HEIGHT(val) \ { \ .prop = LV_STYLE_MIN_HEIGHT, \ - .value = { \ - .num = (int32_t)val \ - } \ + .value = { \ + .num = (int32_t)val \ + } \ } #define LV_STYLE_CONST_MAX_HEIGHT(val) \ { \ .prop = LV_STYLE_MAX_HEIGHT, \ - .value = { \ - .num = (int32_t)val \ - } \ + .value = { \ + .num = (int32_t)val \ + } \ } #define LV_STYLE_CONST_X(val) \ { \ .prop = LV_STYLE_X, \ - .value = { \ - .num = (int32_t)val \ - } \ + .value = { \ + .num = (int32_t)val \ + } \ } #define LV_STYLE_CONST_Y(val) \ { \ .prop = LV_STYLE_Y, \ - .value = { \ - .num = (int32_t)val \ - } \ + .value = { \ + .num = (int32_t)val \ + } \ } #define LV_STYLE_CONST_ALIGN(val) \ { \ .prop = LV_STYLE_ALIGN, \ - .value = { \ - .num = (int32_t)val \ - } \ + .value = { \ + .num = (int32_t)val \ + } \ } #define LV_STYLE_CONST_TRANSFORM_WIDTH(val) \ { \ .prop = LV_STYLE_TRANSFORM_WIDTH, \ - .value = { \ - .num = (int32_t)val \ - } \ + .value = { \ + .num = (int32_t)val \ + } \ } #define LV_STYLE_CONST_TRANSFORM_HEIGHT(val) \ { \ .prop = LV_STYLE_TRANSFORM_HEIGHT, \ - .value = { \ - .num = (int32_t)val \ - } \ + .value = { \ + .num = (int32_t)val \ + } \ } #define LV_STYLE_CONST_TRANSLATE_X(val) \ { \ .prop = LV_STYLE_TRANSLATE_X, \ - .value = { \ - .num = (int32_t)val \ - } \ + .value = { \ + .num = (int32_t)val \ + } \ } #define LV_STYLE_CONST_TRANSLATE_Y(val) \ { \ .prop = LV_STYLE_TRANSLATE_Y, \ - .value = { \ - .num = (int32_t)val \ - } \ + .value = { \ + .num = (int32_t)val \ + } \ } #define LV_STYLE_CONST_TRANSFORM_ZOOM(val) \ { \ .prop = LV_STYLE_TRANSFORM_ZOOM, \ - .value = { \ - .num = (int32_t)val \ - } \ + .value = { \ + .num = (int32_t)val \ + } \ } #define LV_STYLE_CONST_TRANSFORM_ANGLE(val) \ { \ .prop = LV_STYLE_TRANSFORM_ANGLE, \ - .value = { \ - .num = (int32_t)val \ - } \ + .value = { \ + .num = (int32_t)val \ + } \ } #define LV_STYLE_CONST_PAD_TOP(val) \ { \ .prop = LV_STYLE_PAD_TOP, \ - .value = { \ - .num = (int32_t)val \ - } \ + .value = { \ + .num = (int32_t)val \ + } \ } #define LV_STYLE_CONST_PAD_BOTTOM(val) \ { \ .prop = LV_STYLE_PAD_BOTTOM, \ - .value = { \ - .num = (int32_t)val \ - } \ + .value = { \ + .num = (int32_t)val \ + } \ } #define LV_STYLE_CONST_PAD_LEFT(val) \ { \ .prop = LV_STYLE_PAD_LEFT, \ - .value = { \ - .num = (int32_t)val \ - } \ + .value = { \ + .num = (int32_t)val \ + } \ } #define LV_STYLE_CONST_PAD_RIGHT(val) \ { \ .prop = LV_STYLE_PAD_RIGHT, \ - .value = { \ - .num = (int32_t)val \ - } \ + .value = { \ + .num = (int32_t)val \ + } \ } #define LV_STYLE_CONST_PAD_ROW(val) \ { \ .prop = LV_STYLE_PAD_ROW, \ - .value = { \ - .num = (int32_t)val \ - } \ + .value = { \ + .num = (int32_t)val \ + } \ } #define LV_STYLE_CONST_PAD_COLUMN(val) \ { \ .prop = LV_STYLE_PAD_COLUMN, \ - .value = { \ - .num = (int32_t)val \ - } \ + .value = { \ + .num = (int32_t)val \ + } \ } #define LV_STYLE_CONST_RADIUS(val) \ { \ .prop = LV_STYLE_RADIUS, \ - .value = { \ - .num = (int32_t)val \ - } \ + .value = { \ + .num = (int32_t)val \ + } \ } #define LV_STYLE_CONST_CLIP_CORNER(val) \ { \ .prop = LV_STYLE_CLIP_CORNER, \ - .value = { \ - .num = (int32_t)val \ - } \ + .value = { \ + .num = (int32_t)val \ + } \ } #define LV_STYLE_CONST_OPA(val) \ { \ .prop = LV_STYLE_OPA, \ - .value = { \ - .num = (int32_t)val \ - } \ + .value = { \ + .num = (int32_t)val \ + } \ } #define LV_STYLE_CONST_COLOR_FILTER_DSC(val) \ { \ .prop = LV_STYLE_COLOR_FILTER_DSC, \ - .value = { \ - .ptr = val \ - } \ + .value = { \ + .ptr = val \ + } \ } #define LV_STYLE_CONST_COLOR_FILTER_OPA(val) \ { \ .prop = LV_STYLE_COLOR_FILTER_OPA, \ - .value = { \ - .num = (int32_t)val \ - } \ + .value = { \ + .num = (int32_t)val \ + } \ } #define LV_STYLE_CONST_ANIM_TIME(val) \ { \ .prop = LV_STYLE_ANIM_TIME, \ - .value = { \ - .num = (int32_t)val \ - } \ + .value = { \ + .num = (int32_t)val \ + } \ } #define LV_STYLE_CONST_ANIM_SPEED(val) \ { \ .prop = LV_STYLE_ANIM_SPEED, \ - .value = { \ - .num = (int32_t)val \ - } \ + .value = { \ + .num = (int32_t)val \ + } \ } #define LV_STYLE_CONST_TRANSITION(val) \ { \ .prop = LV_STYLE_TRANSITION, \ - .value = { \ - .ptr = val \ - } \ + .value = { \ + .ptr = val \ + } \ } #define LV_STYLE_CONST_BLEND_MODE(val) \ { \ .prop = LV_STYLE_BLEND_MODE, \ - .value = { \ - .num = (int32_t)val \ - } \ + .value = { \ + .num = (int32_t)val \ + } \ } #define LV_STYLE_CONST_LAYOUT(val) \ { \ .prop = LV_STYLE_LAYOUT, \ - .value = { \ - .num = (int32_t)val \ - } \ + .value = { \ + .num = (int32_t)val \ + } \ } #define LV_STYLE_CONST_BASE_DIR(val) \ { \ .prop = LV_STYLE_BASE_DIR, \ - .value = { \ - .num = (int32_t)val \ - } \ + .value = { \ + .num = (int32_t)val \ + } \ } #define LV_STYLE_CONST_BG_COLOR(val) \ { \ .prop = LV_STYLE_BG_COLOR, \ - .value = { \ - .color = val \ - } \ + .value = { \ + .color = val \ + } \ } #define LV_STYLE_CONST_BG_COLOR_FILTERED(val) \ { \ .prop = LV_STYLE_BG_COLOR_FILTERED, \ - .value = { \ - .color = val \ - } \ + .value = { \ + .color = val \ + } \ } #define LV_STYLE_CONST_BG_OPA(val) \ { \ .prop = LV_STYLE_BG_OPA, \ - .value = { \ - .num = (int32_t)val \ - } \ + .value = { \ + .num = (int32_t)val \ + } \ } #define LV_STYLE_CONST_BG_GRAD_COLOR(val) \ { \ .prop = LV_STYLE_BG_GRAD_COLOR, \ - .value = { \ - .color = val \ - } \ + .value = { \ + .color = val \ + } \ } #define LV_STYLE_CONST_BG_GRAD_COLOR_FILTERED(val) \ { \ .prop = LV_STYLE_BG_GRAD_COLOR_FILTERED, \ - .value = { \ - .color = val \ - } \ + .value = { \ + .color = val \ + } \ } #define LV_STYLE_CONST_BG_GRAD_DIR(val) \ { \ .prop = LV_STYLE_BG_GRAD_DIR, \ - .value = { \ - .num = (int32_t)val \ - } \ + .value = { \ + .num = (int32_t)val \ + } \ } #define LV_STYLE_CONST_BG_MAIN_STOP(val) \ { \ .prop = LV_STYLE_BG_MAIN_STOP, \ - .value = { \ - .num = (int32_t)val \ - } \ + .value = { \ + .num = (int32_t)val \ + } \ } #define LV_STYLE_CONST_BG_GRAD_STOP(val) \ { \ .prop = LV_STYLE_BG_GRAD_STOP, \ - .value = { \ - .num = (int32_t)val \ - } \ + .value = { \ + .num = (int32_t)val \ + } \ } #define LV_STYLE_CONST_BG_IMG_SRC(val) \ { \ .prop = LV_STYLE_BG_IMG_SRC, \ - .value = { \ - .ptr = val \ - } \ + .value = { \ + .ptr = val \ + } \ } #define LV_STYLE_CONST_BG_IMG_OPA(val) \ { \ .prop = LV_STYLE_BG_IMG_OPA, \ - .value = { \ - .num = (int32_t)val \ - } \ + .value = { \ + .num = (int32_t)val \ + } \ } #define LV_STYLE_CONST_BG_IMG_RECOLOR(val) \ { \ .prop = LV_STYLE_BG_IMG_RECOLOR, \ - .value = { \ - .color = val \ - } \ + .value = { \ + .color = val \ + } \ } #define LV_STYLE_CONST_BG_IMG_RECOLOR_FILTERED(val) \ { \ .prop = LV_STYLE_BG_IMG_RECOLOR_FILTERED, \ - .value = { \ - .color = val \ - } \ + .value = { \ + .color = val \ + } \ } #define LV_STYLE_CONST_BG_IMG_RECOLOR_OPA(val) \ { \ .prop = LV_STYLE_BG_IMG_RECOLOR_OPA, \ - .value = { \ - .num = (int32_t)val \ - } \ + .value = { \ + .num = (int32_t)val \ + } \ } #define LV_STYLE_CONST_BG_IMG_TILED(val) \ { \ .prop = LV_STYLE_BG_IMG_TILED, \ - .value = { \ - .num = (int32_t)val \ - } \ + .value = { \ + .num = (int32_t)val \ + } \ } #define LV_STYLE_CONST_BORDER_COLOR(val) \ { \ .prop = LV_STYLE_BORDER_COLOR, \ - .value = { \ - .color = val \ - } \ + .value = { \ + .color = val \ + } \ } #define LV_STYLE_CONST_BORDER_COLOR_FILTERED(val) \ { \ .prop = LV_STYLE_BORDER_COLOR_FILTERED, \ - .value = { \ - .color = val \ - } \ + .value = { \ + .color = val \ + } \ } #define LV_STYLE_CONST_BORDER_OPA(val) \ { \ .prop = LV_STYLE_BORDER_OPA, \ - .value = { \ - .num = (int32_t)val \ - } \ + .value = { \ + .num = (int32_t)val \ + } \ } #define LV_STYLE_CONST_BORDER_WIDTH(val) \ { \ .prop = LV_STYLE_BORDER_WIDTH, \ - .value = { \ - .num = (int32_t)val \ - } \ + .value = { \ + .num = (int32_t)val \ + } \ } #define LV_STYLE_CONST_BORDER_SIDE(val) \ { \ .prop = LV_STYLE_BORDER_SIDE, \ - .value = { \ - .num = (int32_t)val \ - } \ + .value = { \ + .num = (int32_t)val \ + } \ } #define LV_STYLE_CONST_BORDER_POST(val) \ { \ .prop = LV_STYLE_BORDER_POST, \ - .value = { \ - .num = (int32_t)val \ - } \ + .value = { \ + .num = (int32_t)val \ + } \ } #define LV_STYLE_CONST_TEXT_COLOR(val) \ { \ .prop = LV_STYLE_TEXT_COLOR, \ - .value = { \ - .color = val \ - } \ + .value = { \ + .color = val \ + } \ } #define LV_STYLE_CONST_TEXT_COLOR_FILTERED(val) \ { \ .prop = LV_STYLE_TEXT_COLOR_FILTERED, \ - .value = { \ - .color = val \ - } \ + .value = { \ + .color = val \ + } \ } #define LV_STYLE_CONST_TEXT_OPA(val) \ { \ .prop = LV_STYLE_TEXT_OPA, \ - .value = { \ - .num = (int32_t)val \ - } \ + .value = { \ + .num = (int32_t)val \ + } \ } #define LV_STYLE_CONST_TEXT_FONT(val) \ { \ .prop = LV_STYLE_TEXT_FONT, \ - .value = { \ - .ptr = val \ - } \ + .value = { \ + .ptr = val \ + } \ } #define LV_STYLE_CONST_TEXT_LETTER_SPACE(val) \ { \ .prop = LV_STYLE_TEXT_LETTER_SPACE, \ - .value = { \ - .num = (int32_t)val \ - } \ + .value = { \ + .num = (int32_t)val \ + } \ } #define LV_STYLE_CONST_TEXT_LINE_SPACE(val) \ { \ .prop = LV_STYLE_TEXT_LINE_SPACE, \ - .value = { \ - .num = (int32_t)val \ - } \ + .value = { \ + .num = (int32_t)val \ + } \ } #define LV_STYLE_CONST_TEXT_DECOR(val) \ { \ .prop = LV_STYLE_TEXT_DECOR, \ - .value = { \ - .num = (int32_t)val \ - } \ + .value = { \ + .num = (int32_t)val \ + } \ } #define LV_STYLE_CONST_TEXT_ALIGN(val) \ { \ .prop = LV_STYLE_TEXT_ALIGN, \ - .value = { \ - .num = (int32_t)val \ - } \ + .value = { \ + .num = (int32_t)val \ + } \ } #define LV_STYLE_CONST_IMG_OPA(val) \ { \ .prop = LV_STYLE_IMG_OPA, \ - .value = { \ - .num = (int32_t)val \ - } \ + .value = { \ + .num = (int32_t)val \ + } \ } #define LV_STYLE_CONST_IMG_RECOLOR(val) \ { \ .prop = LV_STYLE_IMG_RECOLOR, \ - .value = { \ - .color = val \ - } \ + .value = { \ + .color = val \ + } \ } #define LV_STYLE_CONST_IMG_RECOLOR_FILTERED(val) \ { \ .prop = LV_STYLE_IMG_RECOLOR_FILTERED, \ - .value = { \ - .color = val \ - } \ + .value = { \ + .color = val \ + } \ } #define LV_STYLE_CONST_IMG_RECOLOR_OPA(val) \ { \ .prop = LV_STYLE_IMG_RECOLOR_OPA, \ - .value = { \ - .num = (int32_t)val \ - } \ + .value = { \ + .num = (int32_t)val \ + } \ } #define LV_STYLE_CONST_OUTLINE_WIDTH(val) \ { \ .prop = LV_STYLE_OUTLINE_WIDTH, \ - .value = { \ - .num = (int32_t)val \ - } \ + .value = { \ + .num = (int32_t)val \ + } \ } #define LV_STYLE_CONST_OUTLINE_COLOR(val) \ { \ .prop = LV_STYLE_OUTLINE_COLOR, \ - .value = { \ - .color = val \ - } \ + .value = { \ + .color = val \ + } \ } #define LV_STYLE_CONST_OUTLINE_COLOR_FILTERED(val) \ { \ .prop = LV_STYLE_OUTLINE_COLOR_FILTERED, \ - .value = { \ - .color = val \ - } \ + .value = { \ + .color = val \ + } \ } #define LV_STYLE_CONST_OUTLINE_OPA(val) \ { \ .prop = LV_STYLE_OUTLINE_OPA, \ - .value = { \ - .num = (int32_t)val \ - } \ + .value = { \ + .num = (int32_t)val \ + } \ } #define LV_STYLE_CONST_OUTLINE_PAD(val) \ { \ .prop = LV_STYLE_OUTLINE_PAD, \ - .value = { \ - .num = (int32_t)val \ - } \ + .value = { \ + .num = (int32_t)val \ + } \ } #define LV_STYLE_CONST_SHADOW_WIDTH(val) \ { \ .prop = LV_STYLE_SHADOW_WIDTH, \ - .value = { \ - .num = (int32_t)val \ - } \ + .value = { \ + .num = (int32_t)val \ + } \ } #define LV_STYLE_CONST_SHADOW_OFS_X(val) \ { \ .prop = LV_STYLE_SHADOW_OFS_X, \ - .value = { \ - .num = (int32_t)val \ - } \ + .value = { \ + .num = (int32_t)val \ + } \ } #define LV_STYLE_CONST_SHADOW_OFS_Y(val) \ { \ .prop = LV_STYLE_SHADOW_OFS_Y, \ - .value = { \ - .num = (int32_t)val \ - } \ + .value = { \ + .num = (int32_t)val \ + } \ } #define LV_STYLE_CONST_SHADOW_SPREAD(val) \ { \ .prop = LV_STYLE_SHADOW_SPREAD, \ - .value = { \ - .num = (int32_t)val \ - } \ + .value = { \ + .num = (int32_t)val \ + } \ } #define LV_STYLE_CONST_SHADOW_COLOR(val) \ { \ .prop = LV_STYLE_SHADOW_COLOR, \ - .value = { \ - .color = val \ - } \ + .value = { \ + .color = val \ + } \ } #define LV_STYLE_CONST_SHADOW_COLOR_FILTERED(val) \ { \ .prop = LV_STYLE_SHADOW_COLOR_FILTERED, \ - .value = { \ - .color = val \ - } \ + .value = { \ + .color = val \ + } \ } #define LV_STYLE_CONST_SHADOW_OPA(val) \ { \ .prop = LV_STYLE_SHADOW_OPA, \ - .value = { \ - .num = (int32_t)val \ - } \ + .value = { \ + .num = (int32_t)val \ + } \ } #define LV_STYLE_CONST_LINE_WIDTH(val) \ { \ .prop = LV_STYLE_LINE_WIDTH, \ - .value = { \ - .num = (int32_t)val \ - } \ + .value = { \ + .num = (int32_t)val \ + } \ } #define LV_STYLE_CONST_LINE_DASH_WIDTH(val) \ { \ .prop = LV_STYLE_LINE_DASH_WIDTH, \ - .value = { \ - .num = (int32_t)val \ - } \ + .value = { \ + .num = (int32_t)val \ + } \ } #define LV_STYLE_CONST_LINE_DASH_GAP(val) \ { \ .prop = LV_STYLE_LINE_DASH_GAP, \ - .value = { \ - .num = (int32_t)val \ - } \ + .value = { \ + .num = (int32_t)val \ + } \ } #define LV_STYLE_CONST_LINE_ROUNDED(val) \ { \ .prop = LV_STYLE_LINE_ROUNDED, \ - .value = { \ - .num = (int32_t)val \ - } \ + .value = { \ + .num = (int32_t)val \ + } \ } #define LV_STYLE_CONST_LINE_COLOR(val) \ { \ .prop = LV_STYLE_LINE_COLOR, \ - .value = { \ - .color = val \ - } \ + .value = { \ + .color = val \ + } \ } #define LV_STYLE_CONST_LINE_COLOR_FILTERED(val) \ { \ .prop = LV_STYLE_LINE_COLOR_FILTERED, \ - .value = { \ - .color = val \ - } \ + .value = { \ + .color = val \ + } \ } #define LV_STYLE_CONST_LINE_OPA(val) \ { \ .prop = LV_STYLE_LINE_OPA, \ - .value = { \ - .num = (int32_t)val \ - } \ + .value = { \ + .num = (int32_t)val \ + } \ } #define LV_STYLE_CONST_ARC_WIDTH(val) \ { \ .prop = LV_STYLE_ARC_WIDTH, \ - .value = { \ - .num = (int32_t)val \ - } \ + .value = { \ + .num = (int32_t)val \ + } \ } #define LV_STYLE_CONST_ARC_ROUNDED(val) \ { \ .prop = LV_STYLE_ARC_ROUNDED, \ - .value = { \ - .num = (int32_t)val \ - } \ + .value = { \ + .num = (int32_t)val \ + } \ } #define LV_STYLE_CONST_ARC_COLOR(val) \ { \ .prop = LV_STYLE_ARC_COLOR, \ - .value = { \ - .color = val \ - } \ + .value = { \ + .color = val \ + } \ } #define LV_STYLE_CONST_ARC_COLOR_FILTERED(val) \ { \ .prop = LV_STYLE_ARC_COLOR_FILTERED, \ - .value = { \ - .color = val \ - } \ + .value = { \ + .color = val \ + } \ } #define LV_STYLE_CONST_ARC_OPA(val) \ { \ .prop = LV_STYLE_ARC_OPA, \ - .value = { \ - .num = (int32_t)val \ - } \ + .value = { \ + .num = (int32_t)val \ + } \ } #define LV_STYLE_CONST_ARC_IMG_SRC(val) \ { \ .prop = LV_STYLE_ARC_IMG_SRC, \ - .value = { \ - .ptr = val \ - } \ + .value = { \ + .ptr = val \ + } \ } diff --git a/src/misc/lv_timer.c b/src/misc/lv_timer.c index facca6b23..3c0d61786 100644 --- a/src/misc/lv_timer.c +++ b/src/misc/lv_timer.c @@ -39,9 +39,9 @@ static bool timer_created; * MACROS **********************/ #if LV_LOG_TRACE_TIMER -# define TIMER_TRACE(...) LV_LOG_TRACE( __VA_ARGS__) + #define TIMER_TRACE(...) LV_LOG_TRACE( __VA_ARGS__) #else -# define TIMER_TRACE(...) + #define TIMER_TRACE(...) #endif /********************** diff --git a/src/misc/lv_timer.h b/src/misc/lv_timer.h index cead04f3b..093009cc3 100644 --- a/src/misc/lv_timer.h +++ b/src/misc/lv_timer.h @@ -48,7 +48,7 @@ typedef struct _lv_timer_t { lv_timer_cb_t timer_cb; /**< Timer function*/ void * user_data; /**< Custom user data*/ int32_t repeat_count; /**< 1: One time; -1 : infinity; n>0: residual times*/ - uint32_t paused :1; + uint32_t paused : 1; } lv_timer_t; /********************** diff --git a/src/misc/lv_tlsf.c b/src/misc/lv_tlsf.c index 998f0f055..ec97d2fdb 100644 --- a/src/misc/lv_tlsf.c +++ b/src/misc/lv_tlsf.c @@ -1,1288 +1,1237 @@ -#include "../lv_conf_internal.h" -#if LV_MEM_CUSTOM == 0 - -#include -#include -#include "lv_tlsf.h" -#include "lv_mem.h" -#include "lv_log.h" -#include "lv_assert.h" -#define printf LV_LOG_ERROR - -#define TLSF_MAX_POOL_SIZE LV_MEM_SIZE - -#if !defined(_DEBUG) -#define _DEBUG 0 -#endif - -#if defined(__cplusplus) -#define tlsf_decl inline -#else -#define tlsf_decl static -#endif - -/* -** Architecture-specific bit manipulation routines. -** -** TLSF achieves O(1) cost for malloc and free operations by limiting -** the search for a free block to a free list of guaranteed size -** adequate to fulfill the request, combined with efficient free list -** queries using bitmasks and architecture-specific bit-manipulation -** routines. -** -** Most modern processors provide instructions to count leading zeroes -** in a word, find the lowest and highest set bit, etc. These -** specific implementations will be used when available, falling back -** to a reasonably efficient generic implementation. -** -** NOTE: TLSF spec relies on ffs/fls returning value 0..31. -** ffs/fls return 1-32 by default, returning 0 for error. -*/ - -/* -** Detect whether or not we are building for a 32- or 64-bit (LP/LLP) -** architecture. There is no reliable portable method at compile-time. -*/ -#if defined (__alpha__) || defined (__ia64__) || defined (__x86_64__) \ - || defined (_WIN64) || defined (__LP64__) || defined (__LLP64__) -#define TLSF_64BIT -#endif - -/* -** Returns one plus the index of the most significant 1-bit of n, -** or if n is zero, returns zero. -*/ -#ifdef TLSF_64BIT -#define TLSF_FLS(n) ((n) & 0xffffffff00000000ull ? 32 + TLSF_FLS32((size_t)(n) >> 32) : TLSF_FLS32(n)) -#else -#define TLSF_FLS(n) TLSF_FLS32(n) -#endif - -#define TLSF_FLS32(n) ((n) & 0xffff0000 ? 16 + TLSF_FLS16((n) >> 16) : TLSF_FLS16(n)) -#define TLSF_FLS16(n) ((n) & 0xff00 ? 8 + TLSF_FLS8 ((n) >> 8) : TLSF_FLS8 (n)) -#define TLSF_FLS8(n) ((n) & 0xf0 ? 4 + TLSF_FLS4 ((n) >> 4) : TLSF_FLS4 (n)) -#define TLSF_FLS4(n) ((n) & 0xc ? 2 + TLSF_FLS2 ((n) >> 2) : TLSF_FLS2 (n)) -#define TLSF_FLS2(n) ((n) & 0x2 ? 1 + TLSF_FLS1 ((n) >> 1) : TLSF_FLS1 (n)) -#define TLSF_FLS1(n) ((n) & 0x1 ? 1 : 0) - -/* -** Returns round up value of log2(n). -** Note: it is used at compile time. -*/ -#define TLSF_LOG2_CEIL(n) ((n) & (n - 1) ? TLSF_FLS(n) : TLSF_FLS(n) - 1) - -/* -** gcc 3.4 and above have builtin support, specialized for architecture. -** Some compilers masquerade as gcc; patchlevel test filters them out. -*/ -#if defined (__GNUC__) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) \ - && defined (__GNUC_PATCHLEVEL__) - -#if defined (__SNC__) -/* SNC for Playstation 3. */ - -tlsf_decl int tlsf_ffs(unsigned int word) -{ - const unsigned int reverse = word & (~word + 1); - const int bit = 32 - __builtin_clz(reverse); - return bit - 1; -} - -#else - -tlsf_decl int tlsf_ffs(unsigned int word) -{ - return __builtin_ffs(word) - 1; -} - -#endif - -tlsf_decl int tlsf_fls(unsigned int word) -{ - const int bit = word ? 32 - __builtin_clz(word) : 0; - return bit - 1; -} - -#elif defined (_MSC_VER) && (_MSC_VER >= 1400) && (defined (_M_IX86) || defined (_M_X64)) -/* Microsoft Visual C++ support on x86/X64 architectures. */ - -#include - -#pragma intrinsic(_BitScanReverse) -#pragma intrinsic(_BitScanForward) - -tlsf_decl int tlsf_fls(unsigned int word) -{ - unsigned long index; - return _BitScanReverse(&index, word) ? index : -1; -} - -tlsf_decl int tlsf_ffs(unsigned int word) -{ - unsigned long index; - return _BitScanForward(&index, word) ? index : -1; -} - -#elif defined (_MSC_VER) && defined (_M_PPC) -/* Microsoft Visual C++ support on PowerPC architectures. */ - -#include - -tlsf_decl int tlsf_fls(unsigned int word) -{ - const int bit = 32 - _CountLeadingZeros(word); - return bit - 1; -} - -tlsf_decl int tlsf_ffs(unsigned int word) -{ - const unsigned int reverse = word & (~word + 1); - const int bit = 32 - _CountLeadingZeros(reverse); - return bit - 1; -} - -#elif defined (__ARMCC_VERSION) -/* RealView Compilation Tools for ARM */ - -tlsf_decl int tlsf_ffs(unsigned int word) -{ - const unsigned int reverse = word & (~word + 1); - const int bit = 32 - __clz(reverse); - return bit - 1; -} - -tlsf_decl int tlsf_fls(unsigned int word) -{ - const int bit = word ? 32 - __clz(word) : 0; - return bit - 1; -} - -#elif defined (__ghs__) -/* Green Hills support for PowerPC */ - -#include - -tlsf_decl int tlsf_ffs(unsigned int word) -{ - const unsigned int reverse = word & (~word + 1); - const int bit = 32 - __CLZ32(reverse); - return bit - 1; -} - -tlsf_decl int tlsf_fls(unsigned int word) -{ - const int bit = word ? 32 - __CLZ32(word) : 0; - return bit - 1; -} - -#else -/* Fall back to generic implementation. */ - -/* Implement ffs in terms of fls. */ -tlsf_decl int tlsf_ffs(unsigned int word) -{ - const unsigned int reverse = word & (~word + 1); - return TLSF_FLS32(reverse) - 1; -} - -tlsf_decl int tlsf_fls(unsigned int word) -{ - return TLSF_FLS32(word) - 1; -} - -#endif - -/* Possibly 64-bit version of tlsf_fls. */ -#if defined (TLSF_64BIT) -tlsf_decl int tlsf_fls_sizet(size_t size) -{ - int high = (int)(size >> 32); - int bits = 0; - if (high) - { - bits = 32 + tlsf_fls(high); - } - else - { - bits = tlsf_fls((int)size & 0xffffffff); - - } - return bits; -} -#else -#define tlsf_fls_sizet tlsf_fls -#endif - -#undef tlsf_decl - -/* -** Constants. -*/ - -/* Public constants: may be modified. */ -enum tlsf_public -{ - /* log2 of number of linear subdivisions of block sizes. Larger - ** values require more memory in the control structure. Values of - ** 4 or 5 are typical. - */ - SL_INDEX_COUNT_LOG2 = 5, -}; - -/* Private constants: do not modify. */ -enum tlsf_private -{ -#if defined (TLSF_64BIT) - /* All allocation sizes and addresses are aligned to 8 bytes. */ - ALIGN_SIZE_LOG2 = 3, -#else - /* All allocation sizes and addresses are aligned to 4 bytes. */ - ALIGN_SIZE_LOG2 = 2, -#endif - ALIGN_SIZE = (1 << ALIGN_SIZE_LOG2), - - /* - ** We support allocations of sizes up to (1 << FL_INDEX_MAX) bits. - ** However, because we linearly subdivide the second-level lists, and - ** our minimum size granularity is 4 bytes, it doesn't make sense to - ** create first-level lists for sizes smaller than SL_INDEX_COUNT * 4, - ** or (1 << (SL_INDEX_COUNT_LOG2 + 2)) bytes, as there we will be - ** trying to split size ranges into more slots than we have available. - ** Instead, we calculate the minimum threshold size, and place all - ** blocks below that size into the 0th first-level list. - */ - -#if defined (TLSF_MAX_POOL_SIZE) - FL_INDEX_MAX = TLSF_LOG2_CEIL(TLSF_MAX_POOL_SIZE), -#elif defined (TLSF_64BIT) - /* - ** TODO: We can increase this to support larger sizes, at the expense - ** of more overhead in the TLSF structure. - */ - FL_INDEX_MAX = 32, -#else - FL_INDEX_MAX = 30, -#endif - SL_INDEX_COUNT = (1 << SL_INDEX_COUNT_LOG2), - FL_INDEX_SHIFT = (SL_INDEX_COUNT_LOG2 + ALIGN_SIZE_LOG2), - FL_INDEX_COUNT = (FL_INDEX_MAX - FL_INDEX_SHIFT + 1), - - SMALL_BLOCK_SIZE = (1 << FL_INDEX_SHIFT), -}; - -/* -** Cast and min/max macros. -*/ - -#define tlsf_cast(t, exp) ((t) (exp)) -#define tlsf_min(a, b) ((a) < (b) ? (a) : (b)) -#define tlsf_max(a, b) ((a) > (b) ? (a) : (b)) - -/* -** Set assert macro, if it has not been provided by the user. -*/ -#define tlsf_assert LV_ASSERT - -#if !defined (tlsf_assert) -#define tlsf_assert assert -#endif - -/* -** Static assertion mechanism. -*/ - -#define _tlsf_glue2(x, y) x ## y -#define _tlsf_glue(x, y) _tlsf_glue2(x, y) -#define tlsf_static_assert(exp) \ - typedef char _tlsf_glue(static_assert, __LINE__) [(exp) ? 1 : -1] - -/* This code has been tested on 32- and 64-bit (LP/LLP) architectures. */ -tlsf_static_assert(sizeof(int) * CHAR_BIT == 32); -tlsf_static_assert(sizeof(size_t) * CHAR_BIT >= 32); -tlsf_static_assert(sizeof(size_t) * CHAR_BIT <= 64); - -/* SL_INDEX_COUNT must be <= number of bits in sl_bitmap's storage type. */ -tlsf_static_assert(sizeof(unsigned int) * CHAR_BIT >= SL_INDEX_COUNT); - -/* Ensure we've properly tuned our sizes. */ -tlsf_static_assert(ALIGN_SIZE == SMALL_BLOCK_SIZE / SL_INDEX_COUNT); - -/* -** Data structures and associated constants. -*/ - -/* -** Block header structure. -** -** There are several implementation subtleties involved: -** - The prev_phys_block field is only valid if the previous block is free. -** - The prev_phys_block field is actually stored at the end of the -** previous block. It appears at the beginning of this structure only to -** simplify the implementation. -** - The next_free / prev_free fields are only valid if the block is free. -*/ -typedef struct block_header_t -{ - /* Points to the previous physical block. */ - struct block_header_t* prev_phys_block; - - /* The size of this block, excluding the block header. */ - size_t size; - - /* Next and previous free blocks. */ - struct block_header_t* next_free; - struct block_header_t* prev_free; -} block_header_t; - -/* -** Since block sizes are always at least a multiple of 4, the two least -** significant bits of the size field are used to store the block status: -** - bit 0: whether block is busy or free -** - bit 1: whether previous block is busy or free -*/ -static const size_t block_header_free_bit = 1 << 0; -static const size_t block_header_prev_free_bit = 1 << 1; - -/* -** The size of the block header exposed to used blocks is the size field. -** The prev_phys_block field is stored *inside* the previous free block. -*/ -static const size_t block_header_overhead = sizeof(size_t); - -/* User data starts directly after the size field in a used block. */ -static const size_t block_start_offset = - offsetof(block_header_t, size) + sizeof(size_t); - -/* -** A free block must be large enough to store its header minus the size of -** the prev_phys_block field, and no larger than the number of addressable -** bits for FL_INDEX. -*/ -static const size_t block_size_min = - sizeof(block_header_t) - sizeof(block_header_t*); -static const size_t block_size_max = tlsf_cast(size_t, 1) << FL_INDEX_MAX; - - -/* The TLSF control structure. */ -typedef struct control_t -{ - /* Empty lists point at this block to indicate they are free. */ - block_header_t block_null; - - /* Bitmaps for free lists. */ - unsigned int fl_bitmap; - unsigned int sl_bitmap[FL_INDEX_COUNT]; - - /* Head of free lists. */ - block_header_t* blocks[FL_INDEX_COUNT][SL_INDEX_COUNT]; -} control_t; - -/* A type used for casting when doing pointer arithmetic. */ -typedef ptrdiff_t tlsfptr_t; - -/* -** block_header_t member functions. -*/ - -static size_t block_size(const block_header_t* block) -{ - return block->size & ~(block_header_free_bit | block_header_prev_free_bit); -} - -static void block_set_size(block_header_t* block, size_t size) -{ - const size_t oldsize = block->size; - block->size = size | (oldsize & (block_header_free_bit | block_header_prev_free_bit)); -} - -static int block_is_last(const block_header_t* block) -{ - return block_size(block) == 0; -} - -static int block_is_free(const block_header_t* block) -{ - return tlsf_cast(int, block->size & block_header_free_bit); -} - -static void block_set_free(block_header_t* block) -{ - block->size |= block_header_free_bit; -} - -static void block_set_used(block_header_t* block) -{ - block->size &= ~block_header_free_bit; -} - -static int block_is_prev_free(const block_header_t* block) -{ - return tlsf_cast(int, block->size & block_header_prev_free_bit); -} - -static void block_set_prev_free(block_header_t* block) -{ - block->size |= block_header_prev_free_bit; -} - -static void block_set_prev_used(block_header_t* block) -{ - block->size &= ~block_header_prev_free_bit; -} - -static block_header_t* block_from_ptr(const void* ptr) -{ - return tlsf_cast(block_header_t*, - tlsf_cast(unsigned char*, ptr) - block_start_offset); -} - -static void* block_to_ptr(const block_header_t* block) -{ - return tlsf_cast(void*, - tlsf_cast(unsigned char*, block) + block_start_offset); -} - -/* Return location of next block after block of given size. */ -static block_header_t* offset_to_block(const void* ptr, size_t size) -{ - return tlsf_cast(block_header_t*, tlsf_cast(tlsfptr_t, ptr) + size); -} - -/* Return location of previous block. */ -static block_header_t* block_prev(const block_header_t* block) -{ - tlsf_assert(block_is_prev_free(block) && "previous block must be free"); - return block->prev_phys_block; -} - -/* Return location of next existing block. */ -static block_header_t* block_next(const block_header_t* block) -{ - block_header_t* next = offset_to_block(block_to_ptr(block), - block_size(block) - block_header_overhead); - tlsf_assert(!block_is_last(block)); - return next; -} - -/* Link a new block with its physical neighbor, return the neighbor. */ -static block_header_t* block_link_next(block_header_t* block) -{ - block_header_t* next = block_next(block); - next->prev_phys_block = block; - return next; -} - -static void block_mark_as_free(block_header_t* block) -{ - /* Link the block to the next block, first. */ - block_header_t* next = block_link_next(block); - block_set_prev_free(next); - block_set_free(block); -} - -static void block_mark_as_used(block_header_t* block) -{ - block_header_t* next = block_next(block); - block_set_prev_used(next); - block_set_used(block); -} - -static size_t align_up(size_t x, size_t align) -{ - tlsf_assert(0 == (align & (align - 1)) && "must align to a power of two"); - return (x + (align - 1)) & ~(align - 1); -} - -static size_t align_down(size_t x, size_t align) -{ - tlsf_assert(0 == (align & (align - 1)) && "must align to a power of two"); - return x - (x & (align - 1)); -} - -static void* align_ptr(const void* ptr, size_t align) -{ - const tlsfptr_t aligned = - (tlsf_cast(tlsfptr_t, ptr) + (align - 1)) & ~(align - 1); - tlsf_assert(0 == (align & (align - 1)) && "must align to a power of two"); - return tlsf_cast(void*, aligned); -} - -/* -** Adjust an allocation size to be aligned to word size, and no smaller -** than internal minimum. -*/ -static size_t adjust_request_size(size_t size, size_t align) -{ - size_t adjust = 0; - if (size) - { - const size_t aligned = align_up(size, align); - - /* aligned sized must not exceed block_size_max or we'll go out of bounds on sl_bitmap */ - if (aligned < block_size_max) - { - adjust = tlsf_max(aligned, block_size_min); - } - } - return adjust; -} - -/* -** TLSF utility functions. In most cases, these are direct translations of -** the documentation found in the white paper. -*/ - -static void mapping_insert(size_t size, int* fli, int* sli) -{ - int fl, sl; - if (size < SMALL_BLOCK_SIZE) - { - /* Store small blocks in first list. */ - fl = 0; - sl = tlsf_cast(int, size) / (SMALL_BLOCK_SIZE / SL_INDEX_COUNT); - } - else - { - fl = tlsf_fls_sizet(size); - sl = tlsf_cast(int, size >> (fl - SL_INDEX_COUNT_LOG2)) ^ (1 << SL_INDEX_COUNT_LOG2); - fl -= (FL_INDEX_SHIFT - 1); - } - *fli = fl; - *sli = sl; -} - -/* This version rounds up to the next block size (for allocations) */ -static void mapping_search(size_t size, int* fli, int* sli) -{ - if (size >= SMALL_BLOCK_SIZE) - { - const size_t round = (1 << (tlsf_fls_sizet(size) - SL_INDEX_COUNT_LOG2)) - 1; - size += round; - } - mapping_insert(size, fli, sli); -} - -static block_header_t* search_suitable_block(control_t* control, int* fli, int* sli) -{ - int fl = *fli; - int sl = *sli; - - /* - ** First, search for a block in the list associated with the given - ** fl/sl index. - */ - unsigned int sl_map = control->sl_bitmap[fl] & (~0U << sl); - if (!sl_map) - { - /* No block exists. Search in the next largest first-level list. */ - const unsigned int fl_map = control->fl_bitmap & (~0U << (fl + 1)); - if (!fl_map) - { - /* No free blocks available, memory has been exhausted. */ - return 0; - } - - fl = tlsf_ffs(fl_map); - *fli = fl; - sl_map = control->sl_bitmap[fl]; - } - tlsf_assert(sl_map && "internal error - second level bitmap is null"); - sl = tlsf_ffs(sl_map); - *sli = sl; - - /* Return the first block in the free list. */ - return control->blocks[fl][sl]; -} - -/* Remove a free block from the free list.*/ -static void remove_free_block(control_t* control, block_header_t* block, int fl, int sl) -{ - block_header_t* prev = block->prev_free; - block_header_t* next = block->next_free; - tlsf_assert(prev && "prev_free field can not be null"); - tlsf_assert(next && "next_free field can not be null"); - next->prev_free = prev; - prev->next_free = next; - - /* If this block is the head of the free list, set new head. */ - if (control->blocks[fl][sl] == block) - { - control->blocks[fl][sl] = next; - - /* If the new head is null, clear the bitmap. */ - if (next == &control->block_null) - { - control->sl_bitmap[fl] &= ~(1U << sl); - - /* If the second bitmap is now empty, clear the fl bitmap. */ - if (!control->sl_bitmap[fl]) - { - control->fl_bitmap &= ~(1U << fl); - } - } - } -} - -/* Insert a free block into the free block list. */ -static void insert_free_block(control_t* control, block_header_t* block, int fl, int sl) -{ - block_header_t* current = control->blocks[fl][sl]; - tlsf_assert(current && "free list cannot have a null entry"); - tlsf_assert(block && "cannot insert a null entry into the free list"); - block->next_free = current; - block->prev_free = &control->block_null; - current->prev_free = block; - - tlsf_assert(block_to_ptr(block) == align_ptr(block_to_ptr(block), ALIGN_SIZE) - && "block not aligned properly"); - /* - ** Insert the new block at the head of the list, and mark the first- - ** and second-level bitmaps appropriately. - */ - control->blocks[fl][sl] = block; - control->fl_bitmap |= (1U << fl); - control->sl_bitmap[fl] |= (1U << sl); -} - -/* Remove a given block from the free list. */ -static void block_remove(control_t* control, block_header_t* block) -{ - int fl, sl; - mapping_insert(block_size(block), &fl, &sl); - remove_free_block(control, block, fl, sl); -} - -/* Insert a given block into the free list. */ -static void block_insert(control_t* control, block_header_t* block) -{ - int fl, sl; - mapping_insert(block_size(block), &fl, &sl); - insert_free_block(control, block, fl, sl); -} - -static int block_can_split(block_header_t* block, size_t size) -{ - return block_size(block) >= sizeof(block_header_t) + size; -} - -/* Split a block into two, the second of which is free. */ -static block_header_t* block_split(block_header_t* block, size_t size) -{ - /* Calculate the amount of space left in the remaining block. */ - block_header_t* remaining = - offset_to_block(block_to_ptr(block), size - block_header_overhead); - - const size_t remain_size = block_size(block) - (size + block_header_overhead); - - tlsf_assert(block_to_ptr(remaining) == align_ptr(block_to_ptr(remaining), ALIGN_SIZE) - && "remaining block not aligned properly"); - - tlsf_assert(block_size(block) == remain_size + size + block_header_overhead); - block_set_size(remaining, remain_size); - tlsf_assert(block_size(remaining) >= block_size_min && "block split with invalid size"); - - block_set_size(block, size); - block_mark_as_free(remaining); - - return remaining; -} - -/* Absorb a free block's storage into an adjacent previous free block. */ -static block_header_t* block_absorb(block_header_t* prev, block_header_t* block) -{ - tlsf_assert(!block_is_last(prev) && "previous block can't be last"); - /* Note: Leaves flags untouched. */ - prev->size += block_size(block) + block_header_overhead; - block_link_next(prev); - return prev; -} - -/* Merge a just-freed block with an adjacent previous free block. */ -static block_header_t* block_merge_prev(control_t* control, block_header_t* block) -{ - if (block_is_prev_free(block)) - { - block_header_t* prev = block_prev(block); - tlsf_assert(prev && "prev physical block can't be null"); - tlsf_assert(block_is_free(prev) && "prev block is not free though marked as such"); - block_remove(control, prev); - block = block_absorb(prev, block); - } - - return block; -} - -/* Merge a just-freed block with an adjacent free block. */ -static block_header_t* block_merge_next(control_t* control, block_header_t* block) -{ - block_header_t* next = block_next(block); - tlsf_assert(next && "next physical block can't be null"); - - if (block_is_free(next)) - { - tlsf_assert(!block_is_last(block) && "previous block can't be last"); - block_remove(control, next); - block = block_absorb(block, next); - } - - return block; -} - -/* Trim any trailing block space off the end of a block, return to pool. */ -static void block_trim_free(control_t* control, block_header_t* block, size_t size) -{ - tlsf_assert(block_is_free(block) && "block must be free"); - if (block_can_split(block, size)) - { - block_header_t* remaining_block = block_split(block, size); - block_link_next(block); - block_set_prev_free(remaining_block); - block_insert(control, remaining_block); - } -} - -/* Trim any trailing block space off the end of a used block, return to pool. */ -static void block_trim_used(control_t* control, block_header_t* block, size_t size) -{ - tlsf_assert(!block_is_free(block) && "block must be used"); - if (block_can_split(block, size)) - { - /* If the next block is free, we must coalesce. */ - block_header_t* remaining_block = block_split(block, size); - block_set_prev_used(remaining_block); - - remaining_block = block_merge_next(control, remaining_block); - block_insert(control, remaining_block); - } -} - -static block_header_t* block_trim_free_leading(control_t* control, block_header_t* block, size_t size) -{ - block_header_t* remaining_block = block; - if (block_can_split(block, size)) - { - /* We want the 2nd block. */ - remaining_block = block_split(block, size - block_header_overhead); - block_set_prev_free(remaining_block); - - block_link_next(block); - block_insert(control, block); - } - - return remaining_block; -} - -static block_header_t* block_locate_free(control_t* control, size_t size) -{ - int fl = 0, sl = 0; - block_header_t* block = 0; - - if (size) - { - mapping_search(size, &fl, &sl); - - /* - ** mapping_search can futz with the size, so for excessively large sizes it can sometimes wind up - ** with indices that are off the end of the block array. - ** So, we protect against that here, since this is the only callsite of mapping_search. - ** Note that we don't need to check sl, since it comes from a modulo operation that guarantees it's always in range. - */ - if (fl < FL_INDEX_COUNT) - { - block = search_suitable_block(control, &fl, &sl); - } - } - - if (block) - { - tlsf_assert(block_size(block) >= size); - remove_free_block(control, block, fl, sl); - } - - return block; -} - -static void* block_prepare_used(control_t* control, block_header_t* block, size_t size) -{ - void* p = 0; - if (block) - { - tlsf_assert(size && "size must be non-zero"); - block_trim_free(control, block, size); - block_mark_as_used(block); - p = block_to_ptr(block); - } - return p; -} - -/* Clear structure and point all empty lists at the null block. */ -static void control_constructor(control_t* control) -{ - int i, j; - - control->block_null.next_free = &control->block_null; - control->block_null.prev_free = &control->block_null; - - control->fl_bitmap = 0; - for (i = 0; i < FL_INDEX_COUNT; ++i) - { - control->sl_bitmap[i] = 0; - for (j = 0; j < SL_INDEX_COUNT; ++j) - { - control->blocks[i][j] = &control->block_null; - } - } -} - -/* -** Debugging utilities. -*/ - -typedef struct integrity_t -{ - int prev_status; - int status; -} integrity_t; - -#define tlsf_insist(x) { tlsf_assert(x); if (!(x)) { status--; } } - -static void integrity_walker(void* ptr, size_t size, int used, void* user) -{ - block_header_t* block = block_from_ptr(ptr); - integrity_t* integ = tlsf_cast(integrity_t*, user); - const int this_prev_status = block_is_prev_free(block) ? 1 : 0; - const int this_status = block_is_free(block) ? 1 : 0; - const size_t this_block_size = block_size(block); - - int status = 0; - (void)used; - tlsf_insist(integ->prev_status == this_prev_status && "prev status incorrect"); - tlsf_insist(size == this_block_size && "block size incorrect"); - - integ->prev_status = this_status; - integ->status += status; -} - -int lv_tlsf_check(lv_tlsf_t tlsf) -{ - int i, j; - - control_t* control = tlsf_cast(control_t*, tlsf); - int status = 0; - - /* Check that the free lists and bitmaps are accurate. */ - for (i = 0; i < FL_INDEX_COUNT; ++i) - { - for (j = 0; j < SL_INDEX_COUNT; ++j) - { - const int fl_map = control->fl_bitmap & (1U << i); - const int sl_list = control->sl_bitmap[i]; - const int sl_map = sl_list & (1U << j); - const block_header_t* block = control->blocks[i][j]; - - /* Check that first- and second-level lists agree. */ - if (!fl_map) - { - tlsf_insist(!sl_map && "second-level map must be null"); - } - - if (!sl_map) - { - tlsf_insist(block == &control->block_null && "block list must be null"); - continue; - } - - /* Check that there is at least one free block. */ - tlsf_insist(sl_list && "no free blocks in second-level map"); - tlsf_insist(block != &control->block_null && "block should not be null"); - - while (block != &control->block_null) - { - int fli, sli; - tlsf_insist(block_is_free(block) && "block should be free"); - tlsf_insist(!block_is_prev_free(block) && "blocks should have coalesced"); - tlsf_insist(!block_is_free(block_next(block)) && "blocks should have coalesced"); - tlsf_insist(block_is_prev_free(block_next(block)) && "block should be free"); - tlsf_insist(block_size(block) >= block_size_min && "block not minimum size"); - - mapping_insert(block_size(block), &fli, &sli); - tlsf_insist(fli == i && sli == j && "block size indexed in wrong list"); - block = block->next_free; - } - } - } - - return status; -} - -#undef tlsf_insist - -static void default_walker(void* ptr, size_t size, int used, void* user) -{ - (void)user; - printf("\t%p %s size: %x (%p)\n", ptr, used ? "used" : "free", (unsigned int)size, (void*)block_from_ptr(ptr)); -} - -void lv_tlsf_walk_pool(lv_pool_t pool, lv_tlsf_walker walker, void* user) -{ - lv_tlsf_walker pool_walker = walker ? walker : default_walker; - block_header_t* block = - offset_to_block(pool, -(int)block_header_overhead); - - while (block && !block_is_last(block)) - { - pool_walker( - block_to_ptr(block), - block_size(block), - !block_is_free(block), - user); - block = block_next(block); - } -} - -size_t lv_tlsf_block_size(void* ptr) -{ - size_t size = 0; - if (ptr) - { - const block_header_t* block = block_from_ptr(ptr); - size = block_size(block); - } - return size; -} - -int lv_tlsf_check_pool(lv_pool_t pool) -{ - /* Check that the blocks are physically correct. */ - integrity_t integ = { 0, 0 }; - lv_tlsf_walk_pool(pool, integrity_walker, &integ); - - return integ.status; -} - -/* -** Size of the TLSF structures in a given memory block passed to -** lv_tlsf_create, equal to the size of a control_t -*/ -size_t lv_tlsf_size(void) -{ - return sizeof(control_t); -} - -size_t lv_tlsf_align_size(void) -{ - return ALIGN_SIZE; -} - -size_t lv_tlsf_block_size_min(void) -{ - return block_size_min; -} - -size_t lv_tlsf_block_size_max(void) -{ - return block_size_max; -} - -/* -** Overhead of the TLSF structures in a given memory block passed to -** lv_tlsf_add_pool, equal to the overhead of a free block and the -** sentinel block. -*/ -size_t lv_tlsf_pool_overhead(void) -{ - return 2 * block_header_overhead; -} - -size_t lv_tlsf_alloc_overhead(void) -{ - return block_header_overhead; -} - -lv_pool_t lv_tlsf_add_pool(lv_tlsf_t tlsf, void* mem, size_t bytes) -{ - block_header_t* block; - block_header_t* next; - - const size_t pool_overhead = lv_tlsf_pool_overhead(); - const size_t pool_bytes = align_down(bytes - pool_overhead, ALIGN_SIZE); - - if (((ptrdiff_t)mem % ALIGN_SIZE) != 0) - { - printf("lv_tlsf_add_pool: Memory must be aligned by %u bytes.\n", - (unsigned int)ALIGN_SIZE); - return 0; - } - - if (pool_bytes < block_size_min || pool_bytes > block_size_max) - { -#if defined (TLSF_64BIT) - printf("lv_tlsf_add_pool: Memory size must be between 0x%x and 0x%x00 bytes.\n", - (unsigned int)(pool_overhead + block_size_min), - (unsigned int)((pool_overhead + block_size_max) / 256)); -#else - printf("lv_tlsf_add_pool: Memory size must be between %u and %u bytes.\n", - (unsigned int)(pool_overhead + block_size_min), - (unsigned int)(pool_overhead + block_size_max)); -#endif - return 0; - } - - /* - ** Create the main free block. Offset the start of the block slightly - ** so that the prev_phys_block field falls outside of the pool - - ** it will never be used. - */ - block = offset_to_block(mem, -(tlsfptr_t)block_header_overhead); - block_set_size(block, pool_bytes); - block_set_free(block); - block_set_prev_used(block); - block_insert(tlsf_cast(control_t*, tlsf), block); - - /* Split the block to create a zero-size sentinel block. */ - next = block_link_next(block); - block_set_size(next, 0); - block_set_used(next); - block_set_prev_free(next); - - return mem; -} - -void lv_tlsf_remove_pool(lv_tlsf_t tlsf, lv_pool_t pool) -{ - control_t* control = tlsf_cast(control_t*, tlsf); - block_header_t* block = offset_to_block(pool, -(int)block_header_overhead); - - int fl = 0, sl = 0; - - tlsf_assert(block_is_free(block) && "block should be free"); - tlsf_assert(!block_is_free(block_next(block)) && "next block should not be free"); - tlsf_assert(block_size(block_next(block)) == 0 && "next block size should be zero"); - - mapping_insert(block_size(block), &fl, &sl); - remove_free_block(control, block, fl, sl); -} - -/* -** TLSF main interface. -*/ - -#if _DEBUG -int test_ffs_fls() -{ - /* Verify ffs/fls work properly. */ - int rv = 0; - rv += (tlsf_ffs(0) == -1) ? 0 : 0x1; - rv += (tlsf_fls(0) == -1) ? 0 : 0x2; - rv += (tlsf_ffs(1) == 0) ? 0 : 0x4; - rv += (tlsf_fls(1) == 0) ? 0 : 0x8; - rv += (tlsf_ffs(0x80000000) == 31) ? 0 : 0x10; - rv += (tlsf_ffs(0x80008000) == 15) ? 0 : 0x20; - rv += (tlsf_fls(0x80000008) == 31) ? 0 : 0x40; - rv += (tlsf_fls(0x7FFFFFFF) == 30) ? 0 : 0x80; - -#if defined (TLSF_64BIT) - rv += (tlsf_fls_sizet(0x80000000) == 31) ? 0 : 0x100; - rv += (tlsf_fls_sizet(0x100000000) == 32) ? 0 : 0x200; - rv += (tlsf_fls_sizet(0xffffffffffffffff) == 63) ? 0 : 0x400; -#endif - - if (rv) - { - printf("test_ffs_fls: %x ffs/fls tests failed.\n", rv); - } - return rv; -} -#endif - -lv_tlsf_t lv_tlsf_create(void* mem) -{ -#if _DEBUG - if (test_ffs_fls()) - { - return 0; - } -#endif - - if (((tlsfptr_t)mem % ALIGN_SIZE) != 0) - { - printf("lv_tlsf_create: Memory must be aligned to %u bytes.\n", - (unsigned int)ALIGN_SIZE); - return 0; - } - - control_constructor(tlsf_cast(control_t*, mem)); - - return tlsf_cast(lv_tlsf_t, mem); -} - -lv_tlsf_t lv_tlsf_create_with_pool(void* mem, size_t bytes) -{ - lv_tlsf_t tlsf = lv_tlsf_create(mem); - lv_tlsf_add_pool(tlsf, (char*)mem + lv_tlsf_size(), bytes - lv_tlsf_size()); - return tlsf; -} - -void lv_tlsf_destroy(lv_tlsf_t tlsf) -{ - /* Nothing to do. */ - (void)tlsf; -} - -lv_pool_t lv_tlsf_get_pool(lv_tlsf_t tlsf) -{ - return tlsf_cast(lv_pool_t, (char*)tlsf + lv_tlsf_size()); -} - -void* lv_tlsf_malloc(lv_tlsf_t tlsf, size_t size) -{ - control_t* control = tlsf_cast(control_t*, tlsf); - const size_t adjust = adjust_request_size(size, ALIGN_SIZE); - block_header_t* block = block_locate_free(control, adjust); - return block_prepare_used(control, block, adjust); -} - -void* lv_tlsf_memalign(lv_tlsf_t tlsf, size_t align, size_t size) -{ - control_t* control = tlsf_cast(control_t*, tlsf); - const size_t adjust = adjust_request_size(size, ALIGN_SIZE); - - /* - ** We must allocate an additional minimum block size bytes so that if - ** our free block will leave an alignment gap which is smaller, we can - ** trim a leading free block and release it back to the pool. We must - ** do this because the previous physical block is in use, therefore - ** the prev_phys_block field is not valid, and we can't simply adjust - ** the size of that block. - */ - const size_t gap_minimum = sizeof(block_header_t); - const size_t size_with_gap = adjust_request_size(adjust + align + gap_minimum, align); - - /* - ** If alignment is less than or equals base alignment, we're done. - ** If we requested 0 bytes, return null, as lv_tlsf_malloc(0) does. - */ - const size_t aligned_size = (adjust && align > ALIGN_SIZE) ? size_with_gap : adjust; - - block_header_t* block = block_locate_free(control, aligned_size); - - /* This can't be a static assert. */ - tlsf_assert(sizeof(block_header_t) == block_size_min + block_header_overhead); - - if (block) - { - void* ptr = block_to_ptr(block); - void* aligned = align_ptr(ptr, align); - size_t gap = tlsf_cast(size_t, - tlsf_cast(tlsfptr_t, aligned) - tlsf_cast(tlsfptr_t, ptr)); - - /* If gap size is too small, offset to next aligned boundary. */ - if (gap && gap < gap_minimum) - { - const size_t gap_remain = gap_minimum - gap; - const size_t offset = tlsf_max(gap_remain, align); - const void* next_aligned = tlsf_cast(void*, - tlsf_cast(tlsfptr_t, aligned) + offset); - - aligned = align_ptr(next_aligned, align); - gap = tlsf_cast(size_t, - tlsf_cast(tlsfptr_t, aligned) - tlsf_cast(tlsfptr_t, ptr)); - } - - if (gap) - { - tlsf_assert(gap >= gap_minimum && "gap size too small"); - block = block_trim_free_leading(control, block, gap); - } - } - - return block_prepare_used(control, block, adjust); -} - -void lv_tlsf_free(lv_tlsf_t tlsf, void* ptr) -{ - /* Don't attempt to free a NULL pointer. */ - if (ptr) - { - control_t* control = tlsf_cast(control_t*, tlsf); - block_header_t* block = block_from_ptr(ptr); - tlsf_assert(!block_is_free(block) && "block already marked as free"); - block_mark_as_free(block); - block = block_merge_prev(control, block); - block = block_merge_next(control, block); - block_insert(control, block); - } -} - -/* -** The TLSF block information provides us with enough information to -** provide a reasonably intelligent implementation of realloc, growing or -** shrinking the currently allocated block as required. -** -** This routine handles the somewhat esoteric edge cases of realloc: -** - a non-zero size with a null pointer will behave like malloc -** - a zero size with a non-null pointer will behave like free -** - a request that cannot be satisfied will leave the original buffer -** untouched -** - an extended buffer size will leave the newly-allocated area with -** contents undefined -*/ -void* lv_tlsf_realloc(lv_tlsf_t tlsf, void* ptr, size_t size) -{ - control_t* control = tlsf_cast(control_t*, tlsf); - void* p = 0; - - /* Zero-size requests are treated as free. */ - if (ptr && size == 0) - { - lv_tlsf_free(tlsf, ptr); - } - /* Requests with NULL pointers are treated as malloc. */ - else if (!ptr) - { - p = lv_tlsf_malloc(tlsf, size); - } - else - { - block_header_t* block = block_from_ptr(ptr); - block_header_t* next = block_next(block); - - const size_t cursize = block_size(block); - const size_t combined = cursize + block_size(next) + block_header_overhead; - const size_t adjust = adjust_request_size(size, ALIGN_SIZE); - - tlsf_assert(!block_is_free(block) && "block already marked as free"); - - /* - ** If the next block is used, or when combined with the current - ** block, does not offer enough space, we must reallocate and copy. - */ - if (adjust > cursize && (!block_is_free(next) || adjust > combined)) - { - p = lv_tlsf_malloc(tlsf, size); - if (p) - { - const size_t minsize = tlsf_min(cursize, size); - lv_memcpy(p, ptr, minsize); - lv_tlsf_free(tlsf, ptr); - } - } - else - { - /* Do we need to expand to the next block? */ - if (adjust > cursize) - { - block_merge_next(control, block); - block_mark_as_used(block); - } - - /* Trim the resulting block and return the original pointer. */ - block_trim_used(control, block, adjust); - p = ptr; - } - } - - return p; -} - -#endif /* LV_MEM_CUSTOM == 0 */ +#include "../lv_conf_internal.h" +#if LV_MEM_CUSTOM == 0 + +#include +#include +#include "lv_tlsf.h" +#include "lv_mem.h" +#include "lv_log.h" +#include "lv_assert.h" +#define printf LV_LOG_ERROR + +#define TLSF_MAX_POOL_SIZE LV_MEM_SIZE + +#if !defined(_DEBUG) + #define _DEBUG 0 +#endif + +#if defined(__cplusplus) + #define tlsf_decl inline +#else + #define tlsf_decl static +#endif + +/* +** Architecture-specific bit manipulation routines. +** +** TLSF achieves O(1) cost for malloc and free operations by limiting +** the search for a free block to a free list of guaranteed size +** adequate to fulfill the request, combined with efficient free list +** queries using bitmasks and architecture-specific bit-manipulation +** routines. +** +** Most modern processors provide instructions to count leading zeroes +** in a word, find the lowest and highest set bit, etc. These +** specific implementations will be used when available, falling back +** to a reasonably efficient generic implementation. +** +** NOTE: TLSF spec relies on ffs/fls returning value 0..31. +** ffs/fls return 1-32 by default, returning 0 for error. +*/ + +/* +** Detect whether or not we are building for a 32- or 64-bit (LP/LLP) +** architecture. There is no reliable portable method at compile-time. +*/ +#if defined (__alpha__) || defined (__ia64__) || defined (__x86_64__) \ + || defined (_WIN64) || defined (__LP64__) || defined (__LLP64__) + #define TLSF_64BIT +#endif + +/* +** Returns one plus the index of the most significant 1-bit of n, +** or if n is zero, returns zero. +*/ +#ifdef TLSF_64BIT + #define TLSF_FLS(n) ((n) & 0xffffffff00000000ull ? 32 + TLSF_FLS32((size_t)(n) >> 32) : TLSF_FLS32(n)) +#else + #define TLSF_FLS(n) TLSF_FLS32(n) +#endif + +#define TLSF_FLS32(n) ((n) & 0xffff0000 ? 16 + TLSF_FLS16((n) >> 16) : TLSF_FLS16(n)) +#define TLSF_FLS16(n) ((n) & 0xff00 ? 8 + TLSF_FLS8 ((n) >> 8) : TLSF_FLS8 (n)) +#define TLSF_FLS8(n) ((n) & 0xf0 ? 4 + TLSF_FLS4 ((n) >> 4) : TLSF_FLS4 (n)) +#define TLSF_FLS4(n) ((n) & 0xc ? 2 + TLSF_FLS2 ((n) >> 2) : TLSF_FLS2 (n)) +#define TLSF_FLS2(n) ((n) & 0x2 ? 1 + TLSF_FLS1 ((n) >> 1) : TLSF_FLS1 (n)) +#define TLSF_FLS1(n) ((n) & 0x1 ? 1 : 0) + +/* +** Returns round up value of log2(n). +** Note: it is used at compile time. +*/ +#define TLSF_LOG2_CEIL(n) ((n) & (n - 1) ? TLSF_FLS(n) : TLSF_FLS(n) - 1) + +/* +** gcc 3.4 and above have builtin support, specialized for architecture. +** Some compilers masquerade as gcc; patchlevel test filters them out. +*/ +#if defined (__GNUC__) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) \ + && defined (__GNUC_PATCHLEVEL__) + +#if defined (__SNC__) +/* SNC for Playstation 3. */ + +tlsf_decl int tlsf_ffs(unsigned int word) +{ + const unsigned int reverse = word & (~word + 1); + const int bit = 32 - __builtin_clz(reverse); + return bit - 1; +} + +#else + +tlsf_decl int tlsf_ffs(unsigned int word) +{ + return __builtin_ffs(word) - 1; +} + +#endif + +tlsf_decl int tlsf_fls(unsigned int word) +{ + const int bit = word ? 32 - __builtin_clz(word) : 0; + return bit - 1; +} + +#elif defined (_MSC_VER) && (_MSC_VER >= 1400) && (defined (_M_IX86) || defined (_M_X64)) +/* Microsoft Visual C++ support on x86/X64 architectures. */ + +#include + +#pragma intrinsic(_BitScanReverse) +#pragma intrinsic(_BitScanForward) + +tlsf_decl int tlsf_fls(unsigned int word) +{ + unsigned long index; + return _BitScanReverse(&index, word) ? index : -1; +} + +tlsf_decl int tlsf_ffs(unsigned int word) +{ + unsigned long index; + return _BitScanForward(&index, word) ? index : -1; +} + +#elif defined (_MSC_VER) && defined (_M_PPC) +/* Microsoft Visual C++ support on PowerPC architectures. */ + +#include + +tlsf_decl int tlsf_fls(unsigned int word) +{ + const int bit = 32 - _CountLeadingZeros(word); + return bit - 1; +} + +tlsf_decl int tlsf_ffs(unsigned int word) +{ + const unsigned int reverse = word & (~word + 1); + const int bit = 32 - _CountLeadingZeros(reverse); + return bit - 1; +} + +#elif defined (__ARMCC_VERSION) +/* RealView Compilation Tools for ARM */ + +tlsf_decl int tlsf_ffs(unsigned int word) +{ + const unsigned int reverse = word & (~word + 1); + const int bit = 32 - __clz(reverse); + return bit - 1; +} + +tlsf_decl int tlsf_fls(unsigned int word) +{ + const int bit = word ? 32 - __clz(word) : 0; + return bit - 1; +} + +#elif defined (__ghs__) +/* Green Hills support for PowerPC */ + +#include + +tlsf_decl int tlsf_ffs(unsigned int word) +{ + const unsigned int reverse = word & (~word + 1); + const int bit = 32 - __CLZ32(reverse); + return bit - 1; +} + +tlsf_decl int tlsf_fls(unsigned int word) +{ + const int bit = word ? 32 - __CLZ32(word) : 0; + return bit - 1; +} + +#else +/* Fall back to generic implementation. */ + +/* Implement ffs in terms of fls. */ +tlsf_decl int tlsf_ffs(unsigned int word) +{ + const unsigned int reverse = word & (~word + 1); + return TLSF_FLS32(reverse) - 1; +} + +tlsf_decl int tlsf_fls(unsigned int word) +{ + return TLSF_FLS32(word) - 1; +} + +#endif + +/* Possibly 64-bit version of tlsf_fls. */ +#if defined (TLSF_64BIT) +tlsf_decl int tlsf_fls_sizet(size_t size) +{ + int high = (int)(size >> 32); + int bits = 0; + if(high) { + bits = 32 + tlsf_fls(high); + } + else { + bits = tlsf_fls((int)size & 0xffffffff); + + } + return bits; +} +#else +#define tlsf_fls_sizet tlsf_fls +#endif + +#undef tlsf_decl + +/* +** Constants. +*/ + +/* Public constants: may be modified. */ +enum tlsf_public { + /* log2 of number of linear subdivisions of block sizes. Larger + ** values require more memory in the control structure. Values of + ** 4 or 5 are typical. + */ + SL_INDEX_COUNT_LOG2 = 5, +}; + +/* Private constants: do not modify. */ +enum tlsf_private { +#if defined (TLSF_64BIT) + /* All allocation sizes and addresses are aligned to 8 bytes. */ + ALIGN_SIZE_LOG2 = 3, +#else + /* All allocation sizes and addresses are aligned to 4 bytes. */ + ALIGN_SIZE_LOG2 = 2, +#endif + ALIGN_SIZE = (1 << ALIGN_SIZE_LOG2), + + /* + ** We support allocations of sizes up to (1 << FL_INDEX_MAX) bits. + ** However, because we linearly subdivide the second-level lists, and + ** our minimum size granularity is 4 bytes, it doesn't make sense to + ** create first-level lists for sizes smaller than SL_INDEX_COUNT * 4, + ** or (1 << (SL_INDEX_COUNT_LOG2 + 2)) bytes, as there we will be + ** trying to split size ranges into more slots than we have available. + ** Instead, we calculate the minimum threshold size, and place all + ** blocks below that size into the 0th first-level list. + */ + +#if defined (TLSF_MAX_POOL_SIZE) + FL_INDEX_MAX = TLSF_LOG2_CEIL(TLSF_MAX_POOL_SIZE), +#elif defined (TLSF_64BIT) + /* + ** TODO: We can increase this to support larger sizes, at the expense + ** of more overhead in the TLSF structure. + */ + FL_INDEX_MAX = 32, +#else + FL_INDEX_MAX = 30, +#endif + SL_INDEX_COUNT = (1 << SL_INDEX_COUNT_LOG2), + FL_INDEX_SHIFT = (SL_INDEX_COUNT_LOG2 + ALIGN_SIZE_LOG2), + FL_INDEX_COUNT = (FL_INDEX_MAX - FL_INDEX_SHIFT + 1), + + SMALL_BLOCK_SIZE = (1 << FL_INDEX_SHIFT), +}; + +/* +** Cast and min/max macros. +*/ + +#define tlsf_cast(t, exp) ((t) (exp)) +#define tlsf_min(a, b) ((a) < (b) ? (a) : (b)) +#define tlsf_max(a, b) ((a) > (b) ? (a) : (b)) + +/* +** Set assert macro, if it has not been provided by the user. +*/ +#define tlsf_assert LV_ASSERT + +#if !defined (tlsf_assert) + #define tlsf_assert assert +#endif + +/* +** Static assertion mechanism. +*/ + +#define _tlsf_glue2(x, y) x ## y +#define _tlsf_glue(x, y) _tlsf_glue2(x, y) +#define tlsf_static_assert(exp) \ + typedef char _tlsf_glue(static_assert, __LINE__) [(exp) ? 1 : -1] + +/* This code has been tested on 32- and 64-bit (LP/LLP) architectures. */ +tlsf_static_assert(sizeof(int) * CHAR_BIT == 32); +tlsf_static_assert(sizeof(size_t) * CHAR_BIT >= 32); +tlsf_static_assert(sizeof(size_t) * CHAR_BIT <= 64); + +/* SL_INDEX_COUNT must be <= number of bits in sl_bitmap's storage type. */ +tlsf_static_assert(sizeof(unsigned int) * CHAR_BIT >= SL_INDEX_COUNT); + +/* Ensure we've properly tuned our sizes. */ +tlsf_static_assert(ALIGN_SIZE == SMALL_BLOCK_SIZE / SL_INDEX_COUNT); + +/* +** Data structures and associated constants. +*/ + +/* +** Block header structure. +** +** There are several implementation subtleties involved: +** - The prev_phys_block field is only valid if the previous block is free. +** - The prev_phys_block field is actually stored at the end of the +** previous block. It appears at the beginning of this structure only to +** simplify the implementation. +** - The next_free / prev_free fields are only valid if the block is free. +*/ +typedef struct block_header_t { + /* Points to the previous physical block. */ + struct block_header_t * prev_phys_block; + + /* The size of this block, excluding the block header. */ + size_t size; + + /* Next and previous free blocks. */ + struct block_header_t * next_free; + struct block_header_t * prev_free; +} block_header_t; + +/* +** Since block sizes are always at least a multiple of 4, the two least +** significant bits of the size field are used to store the block status: +** - bit 0: whether block is busy or free +** - bit 1: whether previous block is busy or free +*/ +static const size_t block_header_free_bit = 1 << 0; +static const size_t block_header_prev_free_bit = 1 << 1; + +/* +** The size of the block header exposed to used blocks is the size field. +** The prev_phys_block field is stored *inside* the previous free block. +*/ +static const size_t block_header_overhead = sizeof(size_t); + +/* User data starts directly after the size field in a used block. */ +static const size_t block_start_offset = + offsetof(block_header_t, size) + sizeof(size_t); + +/* +** A free block must be large enough to store its header minus the size of +** the prev_phys_block field, and no larger than the number of addressable +** bits for FL_INDEX. +*/ +static const size_t block_size_min = + sizeof(block_header_t) - sizeof(block_header_t *); +static const size_t block_size_max = tlsf_cast(size_t, 1) << FL_INDEX_MAX; + + +/* The TLSF control structure. */ +typedef struct control_t { + /* Empty lists point at this block to indicate they are free. */ + block_header_t block_null; + + /* Bitmaps for free lists. */ + unsigned int fl_bitmap; + unsigned int sl_bitmap[FL_INDEX_COUNT]; + + /* Head of free lists. */ + block_header_t * blocks[FL_INDEX_COUNT][SL_INDEX_COUNT]; +} control_t; + +/* A type used for casting when doing pointer arithmetic. */ +typedef ptrdiff_t tlsfptr_t; + +/* +** block_header_t member functions. +*/ + +static size_t block_size(const block_header_t * block) +{ + return block->size & ~(block_header_free_bit | block_header_prev_free_bit); +} + +static void block_set_size(block_header_t * block, size_t size) +{ + const size_t oldsize = block->size; + block->size = size | (oldsize & (block_header_free_bit | block_header_prev_free_bit)); +} + +static int block_is_last(const block_header_t * block) +{ + return block_size(block) == 0; +} + +static int block_is_free(const block_header_t * block) +{ + return tlsf_cast(int, block->size & block_header_free_bit); +} + +static void block_set_free(block_header_t * block) +{ + block->size |= block_header_free_bit; +} + +static void block_set_used(block_header_t * block) +{ + block->size &= ~block_header_free_bit; +} + +static int block_is_prev_free(const block_header_t * block) +{ + return tlsf_cast(int, block->size & block_header_prev_free_bit); +} + +static void block_set_prev_free(block_header_t * block) +{ + block->size |= block_header_prev_free_bit; +} + +static void block_set_prev_used(block_header_t * block) +{ + block->size &= ~block_header_prev_free_bit; +} + +static block_header_t * block_from_ptr(const void * ptr) +{ + return tlsf_cast(block_header_t *, + tlsf_cast(unsigned char *, ptr) - block_start_offset); +} + +static void * block_to_ptr(const block_header_t * block) +{ + return tlsf_cast(void *, + tlsf_cast(unsigned char *, block) + block_start_offset); +} + +/* Return location of next block after block of given size. */ +static block_header_t * offset_to_block(const void * ptr, size_t size) +{ + return tlsf_cast(block_header_t *, tlsf_cast(tlsfptr_t, ptr) + size); +} + +/* Return location of previous block. */ +static block_header_t * block_prev(const block_header_t * block) +{ + tlsf_assert(block_is_prev_free(block) && "previous block must be free"); + return block->prev_phys_block; +} + +/* Return location of next existing block. */ +static block_header_t * block_next(const block_header_t * block) +{ + block_header_t * next = offset_to_block(block_to_ptr(block), + block_size(block) - block_header_overhead); + tlsf_assert(!block_is_last(block)); + return next; +} + +/* Link a new block with its physical neighbor, return the neighbor. */ +static block_header_t * block_link_next(block_header_t * block) +{ + block_header_t * next = block_next(block); + next->prev_phys_block = block; + return next; +} + +static void block_mark_as_free(block_header_t * block) +{ + /* Link the block to the next block, first. */ + block_header_t * next = block_link_next(block); + block_set_prev_free(next); + block_set_free(block); +} + +static void block_mark_as_used(block_header_t * block) +{ + block_header_t * next = block_next(block); + block_set_prev_used(next); + block_set_used(block); +} + +static size_t align_up(size_t x, size_t align) +{ + tlsf_assert(0 == (align & (align - 1)) && "must align to a power of two"); + return (x + (align - 1)) & ~(align - 1); +} + +static size_t align_down(size_t x, size_t align) +{ + tlsf_assert(0 == (align & (align - 1)) && "must align to a power of two"); + return x - (x & (align - 1)); +} + +static void * align_ptr(const void * ptr, size_t align) +{ + const tlsfptr_t aligned = + (tlsf_cast(tlsfptr_t, ptr) + (align - 1)) & ~(align - 1); + tlsf_assert(0 == (align & (align - 1)) && "must align to a power of two"); + return tlsf_cast(void *, aligned); +} + +/* +** Adjust an allocation size to be aligned to word size, and no smaller +** than internal minimum. +*/ +static size_t adjust_request_size(size_t size, size_t align) +{ + size_t adjust = 0; + if(size) { + const size_t aligned = align_up(size, align); + + /* aligned sized must not exceed block_size_max or we'll go out of bounds on sl_bitmap */ + if(aligned < block_size_max) { + adjust = tlsf_max(aligned, block_size_min); + } + } + return adjust; +} + +/* +** TLSF utility functions. In most cases, these are direct translations of +** the documentation found in the white paper. +*/ + +static void mapping_insert(size_t size, int * fli, int * sli) +{ + int fl, sl; + if(size < SMALL_BLOCK_SIZE) { + /* Store small blocks in first list. */ + fl = 0; + sl = tlsf_cast(int, size) / (SMALL_BLOCK_SIZE / SL_INDEX_COUNT); + } + else { + fl = tlsf_fls_sizet(size); + sl = tlsf_cast(int, size >> (fl - SL_INDEX_COUNT_LOG2)) ^ (1 << SL_INDEX_COUNT_LOG2); + fl -= (FL_INDEX_SHIFT - 1); + } + *fli = fl; + *sli = sl; +} + +/* This version rounds up to the next block size (for allocations) */ +static void mapping_search(size_t size, int * fli, int * sli) +{ + if(size >= SMALL_BLOCK_SIZE) { + const size_t round = (1 << (tlsf_fls_sizet(size) - SL_INDEX_COUNT_LOG2)) - 1; + size += round; + } + mapping_insert(size, fli, sli); +} + +static block_header_t * search_suitable_block(control_t * control, int * fli, int * sli) +{ + int fl = *fli; + int sl = *sli; + + /* + ** First, search for a block in the list associated with the given + ** fl/sl index. + */ + unsigned int sl_map = control->sl_bitmap[fl] & (~0U << sl); + if(!sl_map) { + /* No block exists. Search in the next largest first-level list. */ + const unsigned int fl_map = control->fl_bitmap & (~0U << (fl + 1)); + if(!fl_map) { + /* No free blocks available, memory has been exhausted. */ + return 0; + } + + fl = tlsf_ffs(fl_map); + *fli = fl; + sl_map = control->sl_bitmap[fl]; + } + tlsf_assert(sl_map && "internal error - second level bitmap is null"); + sl = tlsf_ffs(sl_map); + *sli = sl; + + /* Return the first block in the free list. */ + return control->blocks[fl][sl]; +} + +/* Remove a free block from the free list.*/ +static void remove_free_block(control_t * control, block_header_t * block, int fl, int sl) +{ + block_header_t * prev = block->prev_free; + block_header_t * next = block->next_free; + tlsf_assert(prev && "prev_free field can not be null"); + tlsf_assert(next && "next_free field can not be null"); + next->prev_free = prev; + prev->next_free = next; + + /* If this block is the head of the free list, set new head. */ + if(control->blocks[fl][sl] == block) { + control->blocks[fl][sl] = next; + + /* If the new head is null, clear the bitmap. */ + if(next == &control->block_null) { + control->sl_bitmap[fl] &= ~(1U << sl); + + /* If the second bitmap is now empty, clear the fl bitmap. */ + if(!control->sl_bitmap[fl]) { + control->fl_bitmap &= ~(1U << fl); + } + } + } +} + +/* Insert a free block into the free block list. */ +static void insert_free_block(control_t * control, block_header_t * block, int fl, int sl) +{ + block_header_t * current = control->blocks[fl][sl]; + tlsf_assert(current && "free list cannot have a null entry"); + tlsf_assert(block && "cannot insert a null entry into the free list"); + block->next_free = current; + block->prev_free = &control->block_null; + current->prev_free = block; + + tlsf_assert(block_to_ptr(block) == align_ptr(block_to_ptr(block), ALIGN_SIZE) + && "block not aligned properly"); + /* + ** Insert the new block at the head of the list, and mark the first- + ** and second-level bitmaps appropriately. + */ + control->blocks[fl][sl] = block; + control->fl_bitmap |= (1U << fl); + control->sl_bitmap[fl] |= (1U << sl); +} + +/* Remove a given block from the free list. */ +static void block_remove(control_t * control, block_header_t * block) +{ + int fl, sl; + mapping_insert(block_size(block), &fl, &sl); + remove_free_block(control, block, fl, sl); +} + +/* Insert a given block into the free list. */ +static void block_insert(control_t * control, block_header_t * block) +{ + int fl, sl; + mapping_insert(block_size(block), &fl, &sl); + insert_free_block(control, block, fl, sl); +} + +static int block_can_split(block_header_t * block, size_t size) +{ + return block_size(block) >= sizeof(block_header_t) + size; +} + +/* Split a block into two, the second of which is free. */ +static block_header_t * block_split(block_header_t * block, size_t size) +{ + /* Calculate the amount of space left in the remaining block. */ + block_header_t * remaining = + offset_to_block(block_to_ptr(block), size - block_header_overhead); + + const size_t remain_size = block_size(block) - (size + block_header_overhead); + + tlsf_assert(block_to_ptr(remaining) == align_ptr(block_to_ptr(remaining), ALIGN_SIZE) + && "remaining block not aligned properly"); + + tlsf_assert(block_size(block) == remain_size + size + block_header_overhead); + block_set_size(remaining, remain_size); + tlsf_assert(block_size(remaining) >= block_size_min && "block split with invalid size"); + + block_set_size(block, size); + block_mark_as_free(remaining); + + return remaining; +} + +/* Absorb a free block's storage into an adjacent previous free block. */ +static block_header_t * block_absorb(block_header_t * prev, block_header_t * block) +{ + tlsf_assert(!block_is_last(prev) && "previous block can't be last"); + /* Note: Leaves flags untouched. */ + prev->size += block_size(block) + block_header_overhead; + block_link_next(prev); + return prev; +} + +/* Merge a just-freed block with an adjacent previous free block. */ +static block_header_t * block_merge_prev(control_t * control, block_header_t * block) +{ + if(block_is_prev_free(block)) { + block_header_t * prev = block_prev(block); + tlsf_assert(prev && "prev physical block can't be null"); + tlsf_assert(block_is_free(prev) && "prev block is not free though marked as such"); + block_remove(control, prev); + block = block_absorb(prev, block); + } + + return block; +} + +/* Merge a just-freed block with an adjacent free block. */ +static block_header_t * block_merge_next(control_t * control, block_header_t * block) +{ + block_header_t * next = block_next(block); + tlsf_assert(next && "next physical block can't be null"); + + if(block_is_free(next)) { + tlsf_assert(!block_is_last(block) && "previous block can't be last"); + block_remove(control, next); + block = block_absorb(block, next); + } + + return block; +} + +/* Trim any trailing block space off the end of a block, return to pool. */ +static void block_trim_free(control_t * control, block_header_t * block, size_t size) +{ + tlsf_assert(block_is_free(block) && "block must be free"); + if(block_can_split(block, size)) { + block_header_t * remaining_block = block_split(block, size); + block_link_next(block); + block_set_prev_free(remaining_block); + block_insert(control, remaining_block); + } +} + +/* Trim any trailing block space off the end of a used block, return to pool. */ +static void block_trim_used(control_t * control, block_header_t * block, size_t size) +{ + tlsf_assert(!block_is_free(block) && "block must be used"); + if(block_can_split(block, size)) { + /* If the next block is free, we must coalesce. */ + block_header_t * remaining_block = block_split(block, size); + block_set_prev_used(remaining_block); + + remaining_block = block_merge_next(control, remaining_block); + block_insert(control, remaining_block); + } +} + +static block_header_t * block_trim_free_leading(control_t * control, block_header_t * block, size_t size) +{ + block_header_t * remaining_block = block; + if(block_can_split(block, size)) { + /* We want the 2nd block. */ + remaining_block = block_split(block, size - block_header_overhead); + block_set_prev_free(remaining_block); + + block_link_next(block); + block_insert(control, block); + } + + return remaining_block; +} + +static block_header_t * block_locate_free(control_t * control, size_t size) +{ + int fl = 0, sl = 0; + block_header_t * block = 0; + + if(size) { + mapping_search(size, &fl, &sl); + + /* + ** mapping_search can futz with the size, so for excessively large sizes it can sometimes wind up + ** with indices that are off the end of the block array. + ** So, we protect against that here, since this is the only callsite of mapping_search. + ** Note that we don't need to check sl, since it comes from a modulo operation that guarantees it's always in range. + */ + if(fl < FL_INDEX_COUNT) { + block = search_suitable_block(control, &fl, &sl); + } + } + + if(block) { + tlsf_assert(block_size(block) >= size); + remove_free_block(control, block, fl, sl); + } + + return block; +} + +static void * block_prepare_used(control_t * control, block_header_t * block, size_t size) +{ + void * p = 0; + if(block) { + tlsf_assert(size && "size must be non-zero"); + block_trim_free(control, block, size); + block_mark_as_used(block); + p = block_to_ptr(block); + } + return p; +} + +/* Clear structure and point all empty lists at the null block. */ +static void control_constructor(control_t * control) +{ + int i, j; + + control->block_null.next_free = &control->block_null; + control->block_null.prev_free = &control->block_null; + + control->fl_bitmap = 0; + for(i = 0; i < FL_INDEX_COUNT; ++i) { + control->sl_bitmap[i] = 0; + for(j = 0; j < SL_INDEX_COUNT; ++j) { + control->blocks[i][j] = &control->block_null; + } + } +} + +/* +** Debugging utilities. +*/ + +typedef struct integrity_t { + int prev_status; + int status; +} integrity_t; + +#define tlsf_insist(x) { tlsf_assert(x); if (!(x)) { status--; } } + +static void integrity_walker(void * ptr, size_t size, int used, void * user) +{ + block_header_t * block = block_from_ptr(ptr); + integrity_t * integ = tlsf_cast(integrity_t *, user); + const int this_prev_status = block_is_prev_free(block) ? 1 : 0; + const int this_status = block_is_free(block) ? 1 : 0; + const size_t this_block_size = block_size(block); + + int status = 0; + (void)used; + tlsf_insist(integ->prev_status == this_prev_status && "prev status incorrect"); + tlsf_insist(size == this_block_size && "block size incorrect"); + + integ->prev_status = this_status; + integ->status += status; +} + +int lv_tlsf_check(lv_tlsf_t tlsf) +{ + int i, j; + + control_t * control = tlsf_cast(control_t *, tlsf); + int status = 0; + + /* Check that the free lists and bitmaps are accurate. */ + for(i = 0; i < FL_INDEX_COUNT; ++i) { + for(j = 0; j < SL_INDEX_COUNT; ++j) { + const int fl_map = control->fl_bitmap & (1U << i); + const int sl_list = control->sl_bitmap[i]; + const int sl_map = sl_list & (1U << j); + const block_header_t * block = control->blocks[i][j]; + + /* Check that first- and second-level lists agree. */ + if(!fl_map) { + tlsf_insist(!sl_map && "second-level map must be null"); + } + + if(!sl_map) { + tlsf_insist(block == &control->block_null && "block list must be null"); + continue; + } + + /* Check that there is at least one free block. */ + tlsf_insist(sl_list && "no free blocks in second-level map"); + tlsf_insist(block != &control->block_null && "block should not be null"); + + while(block != &control->block_null) { + int fli, sli; + tlsf_insist(block_is_free(block) && "block should be free"); + tlsf_insist(!block_is_prev_free(block) && "blocks should have coalesced"); + tlsf_insist(!block_is_free(block_next(block)) && "blocks should have coalesced"); + tlsf_insist(block_is_prev_free(block_next(block)) && "block should be free"); + tlsf_insist(block_size(block) >= block_size_min && "block not minimum size"); + + mapping_insert(block_size(block), &fli, &sli); + tlsf_insist(fli == i && sli == j && "block size indexed in wrong list"); + block = block->next_free; + } + } + } + + return status; +} + +#undef tlsf_insist + +static void default_walker(void * ptr, size_t size, int used, void * user) +{ + (void)user; + printf("\t%p %s size: %x (%p)\n", ptr, used ? "used" : "free", (unsigned int)size, (void *)block_from_ptr(ptr)); +} + +void lv_tlsf_walk_pool(lv_pool_t pool, lv_tlsf_walker walker, void * user) +{ + lv_tlsf_walker pool_walker = walker ? walker : default_walker; + block_header_t * block = + offset_to_block(pool, -(int)block_header_overhead); + + while(block && !block_is_last(block)) { + pool_walker( + block_to_ptr(block), + block_size(block), + !block_is_free(block), + user); + block = block_next(block); + } +} + +size_t lv_tlsf_block_size(void * ptr) +{ + size_t size = 0; + if(ptr) { + const block_header_t * block = block_from_ptr(ptr); + size = block_size(block); + } + return size; +} + +int lv_tlsf_check_pool(lv_pool_t pool) +{ + /* Check that the blocks are physically correct. */ + integrity_t integ = { 0, 0 }; + lv_tlsf_walk_pool(pool, integrity_walker, &integ); + + return integ.status; +} + +/* +** Size of the TLSF structures in a given memory block passed to +** lv_tlsf_create, equal to the size of a control_t +*/ +size_t lv_tlsf_size(void) +{ + return sizeof(control_t); +} + +size_t lv_tlsf_align_size(void) +{ + return ALIGN_SIZE; +} + +size_t lv_tlsf_block_size_min(void) +{ + return block_size_min; +} + +size_t lv_tlsf_block_size_max(void) +{ + return block_size_max; +} + +/* +** Overhead of the TLSF structures in a given memory block passed to +** lv_tlsf_add_pool, equal to the overhead of a free block and the +** sentinel block. +*/ +size_t lv_tlsf_pool_overhead(void) +{ + return 2 * block_header_overhead; +} + +size_t lv_tlsf_alloc_overhead(void) +{ + return block_header_overhead; +} + +lv_pool_t lv_tlsf_add_pool(lv_tlsf_t tlsf, void * mem, size_t bytes) +{ + block_header_t * block; + block_header_t * next; + + const size_t pool_overhead = lv_tlsf_pool_overhead(); + const size_t pool_bytes = align_down(bytes - pool_overhead, ALIGN_SIZE); + + if(((ptrdiff_t)mem % ALIGN_SIZE) != 0) { + printf("lv_tlsf_add_pool: Memory must be aligned by %u bytes.\n", + (unsigned int)ALIGN_SIZE); + return 0; + } + + if(pool_bytes < block_size_min || pool_bytes > block_size_max) { +#if defined (TLSF_64BIT) + printf("lv_tlsf_add_pool: Memory size must be between 0x%x and 0x%x00 bytes.\n", + (unsigned int)(pool_overhead + block_size_min), + (unsigned int)((pool_overhead + block_size_max) / 256)); +#else + printf("lv_tlsf_add_pool: Memory size must be between %u and %u bytes.\n", + (unsigned int)(pool_overhead + block_size_min), + (unsigned int)(pool_overhead + block_size_max)); +#endif + return 0; + } + + /* + ** Create the main free block. Offset the start of the block slightly + ** so that the prev_phys_block field falls outside of the pool - + ** it will never be used. + */ + block = offset_to_block(mem, -(tlsfptr_t)block_header_overhead); + block_set_size(block, pool_bytes); + block_set_free(block); + block_set_prev_used(block); + block_insert(tlsf_cast(control_t *, tlsf), block); + + /* Split the block to create a zero-size sentinel block. */ + next = block_link_next(block); + block_set_size(next, 0); + block_set_used(next); + block_set_prev_free(next); + + return mem; +} + +void lv_tlsf_remove_pool(lv_tlsf_t tlsf, lv_pool_t pool) +{ + control_t * control = tlsf_cast(control_t *, tlsf); + block_header_t * block = offset_to_block(pool, -(int)block_header_overhead); + + int fl = 0, sl = 0; + + tlsf_assert(block_is_free(block) && "block should be free"); + tlsf_assert(!block_is_free(block_next(block)) && "next block should not be free"); + tlsf_assert(block_size(block_next(block)) == 0 && "next block size should be zero"); + + mapping_insert(block_size(block), &fl, &sl); + remove_free_block(control, block, fl, sl); +} + +/* +** TLSF main interface. +*/ + +#if _DEBUG +int test_ffs_fls() +{ + /* Verify ffs/fls work properly. */ + int rv = 0; + rv += (tlsf_ffs(0) == -1) ? 0 : 0x1; + rv += (tlsf_fls(0) == -1) ? 0 : 0x2; + rv += (tlsf_ffs(1) == 0) ? 0 : 0x4; + rv += (tlsf_fls(1) == 0) ? 0 : 0x8; + rv += (tlsf_ffs(0x80000000) == 31) ? 0 : 0x10; + rv += (tlsf_ffs(0x80008000) == 15) ? 0 : 0x20; + rv += (tlsf_fls(0x80000008) == 31) ? 0 : 0x40; + rv += (tlsf_fls(0x7FFFFFFF) == 30) ? 0 : 0x80; + +#if defined (TLSF_64BIT) + rv += (tlsf_fls_sizet(0x80000000) == 31) ? 0 : 0x100; + rv += (tlsf_fls_sizet(0x100000000) == 32) ? 0 : 0x200; + rv += (tlsf_fls_sizet(0xffffffffffffffff) == 63) ? 0 : 0x400; +#endif + + if(rv) { + printf("test_ffs_fls: %x ffs/fls tests failed.\n", rv); + } + return rv; +} +#endif + +lv_tlsf_t lv_tlsf_create(void * mem) +{ +#if _DEBUG + if(test_ffs_fls()) { + return 0; + } +#endif + + if(((tlsfptr_t)mem % ALIGN_SIZE) != 0) { + printf("lv_tlsf_create: Memory must be aligned to %u bytes.\n", + (unsigned int)ALIGN_SIZE); + return 0; + } + + control_constructor(tlsf_cast(control_t *, mem)); + + return tlsf_cast(lv_tlsf_t, mem); +} + +lv_tlsf_t lv_tlsf_create_with_pool(void * mem, size_t bytes) +{ + lv_tlsf_t tlsf = lv_tlsf_create(mem); + lv_tlsf_add_pool(tlsf, (char *)mem + lv_tlsf_size(), bytes - lv_tlsf_size()); + return tlsf; +} + +void lv_tlsf_destroy(lv_tlsf_t tlsf) +{ + /* Nothing to do. */ + (void)tlsf; +} + +lv_pool_t lv_tlsf_get_pool(lv_tlsf_t tlsf) +{ + return tlsf_cast(lv_pool_t, (char *)tlsf + lv_tlsf_size()); +} + +void * lv_tlsf_malloc(lv_tlsf_t tlsf, size_t size) +{ + control_t * control = tlsf_cast(control_t *, tlsf); + const size_t adjust = adjust_request_size(size, ALIGN_SIZE); + block_header_t * block = block_locate_free(control, adjust); + return block_prepare_used(control, block, adjust); +} + +void * lv_tlsf_memalign(lv_tlsf_t tlsf, size_t align, size_t size) +{ + control_t * control = tlsf_cast(control_t *, tlsf); + const size_t adjust = adjust_request_size(size, ALIGN_SIZE); + + /* + ** We must allocate an additional minimum block size bytes so that if + ** our free block will leave an alignment gap which is smaller, we can + ** trim a leading free block and release it back to the pool. We must + ** do this because the previous physical block is in use, therefore + ** the prev_phys_block field is not valid, and we can't simply adjust + ** the size of that block. + */ + const size_t gap_minimum = sizeof(block_header_t); + const size_t size_with_gap = adjust_request_size(adjust + align + gap_minimum, align); + + /* + ** If alignment is less than or equals base alignment, we're done. + ** If we requested 0 bytes, return null, as lv_tlsf_malloc(0) does. + */ + const size_t aligned_size = (adjust && align > ALIGN_SIZE) ? size_with_gap : adjust; + + block_header_t * block = block_locate_free(control, aligned_size); + + /* This can't be a static assert. */ + tlsf_assert(sizeof(block_header_t) == block_size_min + block_header_overhead); + + if(block) { + void * ptr = block_to_ptr(block); + void * aligned = align_ptr(ptr, align); + size_t gap = tlsf_cast(size_t, + tlsf_cast(tlsfptr_t, aligned) - tlsf_cast(tlsfptr_t, ptr)); + + /* If gap size is too small, offset to next aligned boundary. */ + if(gap && gap < gap_minimum) { + const size_t gap_remain = gap_minimum - gap; + const size_t offset = tlsf_max(gap_remain, align); + const void * next_aligned = tlsf_cast(void *, + tlsf_cast(tlsfptr_t, aligned) + offset); + + aligned = align_ptr(next_aligned, align); + gap = tlsf_cast(size_t, + tlsf_cast(tlsfptr_t, aligned) - tlsf_cast(tlsfptr_t, ptr)); + } + + if(gap) { + tlsf_assert(gap >= gap_minimum && "gap size too small"); + block = block_trim_free_leading(control, block, gap); + } + } + + return block_prepare_used(control, block, adjust); +} + +void lv_tlsf_free(lv_tlsf_t tlsf, void * ptr) +{ + /* Don't attempt to free a NULL pointer. */ + if(ptr) { + control_t * control = tlsf_cast(control_t *, tlsf); + block_header_t * block = block_from_ptr(ptr); + tlsf_assert(!block_is_free(block) && "block already marked as free"); + block_mark_as_free(block); + block = block_merge_prev(control, block); + block = block_merge_next(control, block); + block_insert(control, block); + } +} + +/* +** The TLSF block information provides us with enough information to +** provide a reasonably intelligent implementation of realloc, growing or +** shrinking the currently allocated block as required. +** +** This routine handles the somewhat esoteric edge cases of realloc: +** - a non-zero size with a null pointer will behave like malloc +** - a zero size with a non-null pointer will behave like free +** - a request that cannot be satisfied will leave the original buffer +** untouched +** - an extended buffer size will leave the newly-allocated area with +** contents undefined +*/ +void * lv_tlsf_realloc(lv_tlsf_t tlsf, void * ptr, size_t size) +{ + control_t * control = tlsf_cast(control_t *, tlsf); + void * p = 0; + + /* Zero-size requests are treated as free. */ + if(ptr && size == 0) { + lv_tlsf_free(tlsf, ptr); + } + /* Requests with NULL pointers are treated as malloc. */ + else if(!ptr) { + p = lv_tlsf_malloc(tlsf, size); + } + else { + block_header_t * block = block_from_ptr(ptr); + block_header_t * next = block_next(block); + + const size_t cursize = block_size(block); + const size_t combined = cursize + block_size(next) + block_header_overhead; + const size_t adjust = adjust_request_size(size, ALIGN_SIZE); + + tlsf_assert(!block_is_free(block) && "block already marked as free"); + + /* + ** If the next block is used, or when combined with the current + ** block, does not offer enough space, we must reallocate and copy. + */ + if(adjust > cursize && (!block_is_free(next) || adjust > combined)) { + p = lv_tlsf_malloc(tlsf, size); + if(p) { + const size_t minsize = tlsf_min(cursize, size); + lv_memcpy(p, ptr, minsize); + lv_tlsf_free(tlsf, ptr); + } + } + else { + /* Do we need to expand to the next block? */ + if(adjust > cursize) { + block_merge_next(control, block); + block_mark_as_used(block); + } + + /* Trim the resulting block and return the original pointer. */ + block_trim_used(control, block, adjust); + p = ptr; + } + } + + return p; +} + +#endif /* LV_MEM_CUSTOM == 0 */ diff --git a/src/misc/lv_tlsf.h b/src/misc/lv_tlsf.h index 0510dbfa2..c31e5b493 100644 --- a/src/misc/lv_tlsf.h +++ b/src/misc/lv_tlsf.h @@ -1,95 +1,95 @@ -#include "../lv_conf_internal.h" -#if LV_MEM_CUSTOM == 0 - -#ifndef INCLUDED_tlsf -#define INCLUDED_tlsf - -/* -** Two Level Segregated Fit memory allocator, version 3.1. -** Written by Matthew Conte -** http://tlsf.baisoku.org -** -** Based on the original documentation by Miguel Masmano: -** http://www.gii.upv.es/tlsf/main/docs -** -** This implementation was written to the specification -** of the document, therefore no GPL restrictions apply. -** -** Copyright (c) 2006-2016, Matthew Conte -** All rights reserved. -** -** Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in the -** documentation and/or other materials provided with the distribution. -** * Neither the name of the copyright holder nor the -** names of its contributors may be used to endorse or promote products -** derived from this software without specific prior written permission. -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -** DISCLAIMED. IN NO EVENT SHALL MATTHEW CONTE BE LIABLE FOR ANY -** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#include - -#if defined(__cplusplus) -extern "C" { -#endif - -/* lv_tlsf_t: a TLSF structure. Can contain 1 to N pools. */ -/* lv_pool_t: a block of memory that TLSF can manage. */ -typedef void* lv_tlsf_t; -typedef void* lv_pool_t; - -/* Create/destroy a memory pool. */ -lv_tlsf_t lv_tlsf_create(void* mem); -lv_tlsf_t lv_tlsf_create_with_pool(void* mem, size_t bytes); -void lv_tlsf_destroy(lv_tlsf_t tlsf); -lv_pool_t lv_tlsf_get_pool(lv_tlsf_t tlsf); - -/* Add/remove memory pools. */ -lv_pool_t lv_tlsf_add_pool(lv_tlsf_t tlsf, void* mem, size_t bytes); -void lv_tlsf_remove_pool(lv_tlsf_t tlsf, lv_pool_t pool); - -/* malloc/memalign/realloc/free replacements. */ -void* lv_tlsf_malloc(lv_tlsf_t tlsf, size_t bytes); -void* lv_tlsf_memalign(lv_tlsf_t tlsf, size_t align, size_t bytes); -void* lv_tlsf_realloc(lv_tlsf_t tlsf, void* ptr, size_t size); -void lv_tlsf_free(lv_tlsf_t tlsf, void* ptr); - -/* Returns internal block size, not original request size */ -size_t lv_tlsf_block_size(void* ptr); - -/* Overheads/limits of internal structures. */ -size_t lv_tlsf_size(void); -size_t lv_tlsf_align_size(void); -size_t lv_tlsf_block_size_min(void); -size_t lv_tlsf_block_size_max(void); -size_t lv_tlsf_pool_overhead(void); -size_t lv_tlsf_alloc_overhead(void); - -/* Debugging. */ -typedef void (*lv_tlsf_walker)(void* ptr, size_t size, int used, void* user); -void lv_tlsf_walk_pool(lv_pool_t pool, lv_tlsf_walker walker, void* user); -/* Returns nonzero if any internal consistency check fails. */ -int lv_tlsf_check(lv_tlsf_t tlsf); -int lv_tlsf_check_pool(lv_pool_t pool); - -#if defined(__cplusplus) -}; -#endif - -#endif - -#endif /* LV_MEM_CUSTOM == 0 */ +#include "../lv_conf_internal.h" +#if LV_MEM_CUSTOM == 0 + +#ifndef INCLUDED_tlsf +#define INCLUDED_tlsf + +/* +** Two Level Segregated Fit memory allocator, version 3.1. +** Written by Matthew Conte +** http://tlsf.baisoku.org +** +** Based on the original documentation by Miguel Masmano: +** http://www.gii.upv.es/tlsf/main/docs +** +** This implementation was written to the specification +** of the document, therefore no GPL restrictions apply. +** +** Copyright (c) 2006-2016, Matthew Conte +** All rights reserved. +** +** Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** * Neither the name of the copyright holder nor the +** names of its contributors may be used to endorse or promote products +** derived from this software without specific prior written permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +** DISCLAIMED. IN NO EVENT SHALL MATTHEW CONTE BE LIABLE FOR ANY +** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include + +#if defined(__cplusplus) +extern "C" { +#endif + +/* lv_tlsf_t: a TLSF structure. Can contain 1 to N pools. */ +/* lv_pool_t: a block of memory that TLSF can manage. */ +typedef void * lv_tlsf_t; +typedef void * lv_pool_t; + +/* Create/destroy a memory pool. */ +lv_tlsf_t lv_tlsf_create(void * mem); +lv_tlsf_t lv_tlsf_create_with_pool(void * mem, size_t bytes); +void lv_tlsf_destroy(lv_tlsf_t tlsf); +lv_pool_t lv_tlsf_get_pool(lv_tlsf_t tlsf); + +/* Add/remove memory pools. */ +lv_pool_t lv_tlsf_add_pool(lv_tlsf_t tlsf, void * mem, size_t bytes); +void lv_tlsf_remove_pool(lv_tlsf_t tlsf, lv_pool_t pool); + +/* malloc/memalign/realloc/free replacements. */ +void * lv_tlsf_malloc(lv_tlsf_t tlsf, size_t bytes); +void * lv_tlsf_memalign(lv_tlsf_t tlsf, size_t align, size_t bytes); +void * lv_tlsf_realloc(lv_tlsf_t tlsf, void * ptr, size_t size); +void lv_tlsf_free(lv_tlsf_t tlsf, void * ptr); + +/* Returns internal block size, not original request size */ +size_t lv_tlsf_block_size(void * ptr); + +/* Overheads/limits of internal structures. */ +size_t lv_tlsf_size(void); +size_t lv_tlsf_align_size(void); +size_t lv_tlsf_block_size_min(void); +size_t lv_tlsf_block_size_max(void); +size_t lv_tlsf_pool_overhead(void); +size_t lv_tlsf_alloc_overhead(void); + +/* Debugging. */ +typedef void (*lv_tlsf_walker)(void * ptr, size_t size, int used, void * user); +void lv_tlsf_walk_pool(lv_pool_t pool, lv_tlsf_walker walker, void * user); +/* Returns nonzero if any internal consistency check fails. */ +int lv_tlsf_check(lv_tlsf_t tlsf); +int lv_tlsf_check_pool(lv_pool_t pool); + +#if defined(__cplusplus) +}; +#endif + +#endif + +#endif /* LV_MEM_CUSTOM == 0 */ diff --git a/src/misc/lv_txt.c b/src/misc/lv_txt.c index 0ad59e1c4..b212cdbed 100644 --- a/src/misc/lv_txt.c +++ b/src/misc/lv_txt.c @@ -94,7 +94,7 @@ * line breaks */ void lv_txt_get_size(lv_point_t * size_res, const char * text, const lv_font_t * font, lv_coord_t letter_space, - lv_coord_t line_space, lv_coord_t max_width, lv_text_flag_t flag) + lv_coord_t line_space, lv_coord_t max_width, lv_text_flag_t flag) { size_res->x = 0; size_res->y = 0; @@ -123,7 +123,7 @@ void lv_txt_get_size(lv_point_t * size_res, const char * text, const lv_font_t * /*Calculate the longest line*/ lv_coord_t act_line_length = lv_txt_get_width(&text[line_start], new_line_start - line_start, font, letter_space, - flag); + flag); size_res->x = LV_MAX(act_line_length, size_res->x); line_start = new_line_start; @@ -353,7 +353,7 @@ uint32_t _lv_txt_get_next_line(const char * txt, const lv_font_t * font, * @return length of a char_num long text */ lv_coord_t lv_txt_get_width(const char * txt, uint32_t length, const lv_font_t * font, lv_coord_t letter_space, - lv_text_flag_t flag) + lv_text_flag_t flag) { if(txt == NULL) return 0; if(font == NULL) return 0; @@ -526,7 +526,7 @@ LV_FORMAT_ATTRIBUTE(1, 0) char * _lv_txt_set_text_vfmt(const char * fmt, va_list return text; } -void _lv_txt_encoded_letter_next_2(const char * txt, uint32_t * letter, uint32_t * letter_next, uint32_t *ofs) +void _lv_txt_encoded_letter_next_2(const char * txt, uint32_t * letter, uint32_t * letter_next, uint32_t * ofs) { *letter = _lv_txt_encoded_next(txt, ofs); *letter_next = *letter != '\0' ? _lv_txt_encoded_next(&txt[*ofs], NULL) : 0; diff --git a/src/misc/lv_txt.h b/src/misc/lv_txt.h index 138d0f416..b69858f14 100644 --- a/src/misc/lv_txt.h +++ b/src/misc/lv_txt.h @@ -81,7 +81,7 @@ typedef uint8_t lv_text_align_t; * line breaks */ void lv_txt_get_size(lv_point_t * size_res, const char * text, const lv_font_t * font, lv_coord_t letter_space, - lv_coord_t line_space, lv_coord_t max_width, lv_text_flag_t flag); + lv_coord_t line_space, lv_coord_t max_width, lv_text_flag_t flag); /** * Get the next line of text. Check line length and break chars too. @@ -108,7 +108,7 @@ uint32_t _lv_txt_get_next_line(const char * txt, const lv_font_t * font, lv_coor * @return length of a char_num long text */ lv_coord_t lv_txt_get_width(const char * txt, uint32_t length, const lv_font_t * font, lv_coord_t letter_space, - lv_text_flag_t flag); + lv_text_flag_t flag); /** * Check next character in a string and decide if the character is part of the command or not @@ -153,7 +153,7 @@ char * _lv_txt_set_text_vfmt(const char * fmt, va_list ap) LV_FORMAT_ATTRIBUTE(1 * After the call it will point to the next encoded char in 'txt'. * NULL to use txt[0] as index */ -void _lv_txt_encoded_letter_next_2(const char * txt, uint32_t * letter, uint32_t * letter_next, uint32_t *ofs); +void _lv_txt_encoded_letter_next_2(const char * txt, uint32_t * letter, uint32_t * letter_next, uint32_t * ofs); /** * Test if char is break char or not (a text can broken here or not) @@ -166,7 +166,7 @@ static inline bool _lv_txt_is_break_char(uint32_t letter) bool ret = false; /* each chinese character can be break */ - if (letter >= 0x4E00 && letter <= 0x9FA5) { + if(letter >= 0x4E00 && letter <= 0x9FA5) { return true; } diff --git a/src/widgets/lv_arc.c b/src/widgets/lv_arc.c index 4c971dc25..4df3dc015 100644 --- a/src/widgets/lv_arc.c +++ b/src/widgets/lv_arc.c @@ -234,13 +234,13 @@ void lv_arc_set_mode(lv_obj_t * obj, lv_arc_mode_t type) LV_ASSERT_OBJ(obj, MY_CLASS); lv_arc_t * arc = (lv_arc_t *)obj; - int16_t val =arc->value; + int16_t val = arc->value; arc->type = type; arc->value = -1; /** Force set_value handling*/ - int16_t bg_midpoint, bg_end =arc->bg_angle_end; - if(arc->bg_angle_end bg_angle_start) bg_end =arc->bg_angle_end + 360; + int16_t bg_midpoint, bg_end = arc->bg_angle_end; + if(arc->bg_angle_end < arc->bg_angle_start) bg_end = arc->bg_angle_end + 360; switch(arc->type) { case LV_ARC_MODE_SYMMETRICAL: @@ -249,10 +249,10 @@ void lv_arc_set_mode(lv_obj_t * obj, lv_arc_mode_t type) lv_arc_set_end_angle(obj, bg_midpoint); break; case LV_ARC_MODE_REVERSE: - lv_arc_set_end_angle(obj,arc->bg_angle_end); + lv_arc_set_end_angle(obj, arc->bg_angle_end); break; default: /** LV_ARC_TYPE_NORMAL*/ - lv_arc_set_start_angle(obj,arc->bg_angle_start); + lv_arc_set_start_angle(obj, arc->bg_angle_start); } lv_arc_set_value(obj, val); @@ -291,16 +291,16 @@ void lv_arc_set_range(lv_obj_t * obj, int16_t min, int16_t max) LV_ASSERT_OBJ(obj, MY_CLASS); lv_arc_t * arc = (lv_arc_t *)obj; - if(arc->min_value == min &&arc->max_value == max) return; + if(arc->min_value == min && arc->max_value == max) return; - arc->min_value = min; - arc->max_value = max; + arc->min_value = min; + arc->max_value = max; if(arc->value < min) { - arc->value = min; + arc->value = min; } if(arc->value > max) { - arc->value = max; + arc->value = max; } value_update(obj); /*value has changed relative to the new range*/ @@ -317,7 +317,7 @@ void lv_arc_set_change_rate(lv_obj_t * obj, uint16_t rate) LV_ASSERT_OBJ(obj, MY_CLASS); lv_arc_t * arc = (lv_arc_t *)obj; - arc->chg_rate = rate; + arc->chg_rate = rate; } /*===================== @@ -332,7 +332,7 @@ void lv_arc_set_change_rate(lv_obj_t * obj, uint16_t rate) uint16_t lv_arc_get_angle_start(lv_obj_t * obj) { LV_ASSERT_OBJ(obj, MY_CLASS); - return ((lv_arc_t*) obj)->indic_angle_start; + return ((lv_arc_t *) obj)->indic_angle_start; } /** @@ -340,10 +340,10 @@ uint16_t lv_arc_get_angle_start(lv_obj_t * obj) * @param arc pointer to an arc object * @return the end angle [0..360] */ - uint16_t lv_arc_get_angle_end(lv_obj_t * obj) +uint16_t lv_arc_get_angle_end(lv_obj_t * obj) { LV_ASSERT_OBJ(obj, MY_CLASS); - return ((lv_arc_t*) obj)->indic_angle_end; + return ((lv_arc_t *) obj)->indic_angle_end; } /** @@ -354,7 +354,7 @@ uint16_t lv_arc_get_angle_start(lv_obj_t * obj) uint16_t lv_arc_get_bg_angle_start(lv_obj_t * obj) { LV_ASSERT_OBJ(obj, MY_CLASS); - return ((lv_arc_t*) obj)->bg_angle_start; + return ((lv_arc_t *) obj)->bg_angle_start; } /** @@ -365,7 +365,7 @@ uint16_t lv_arc_get_bg_angle_start(lv_obj_t * obj) uint16_t lv_arc_get_bg_angle_end(lv_obj_t * obj) { LV_ASSERT_OBJ(obj, MY_CLASS); - return ((lv_arc_t*) obj)->bg_angle_end; + return ((lv_arc_t *) obj)->bg_angle_end; } @@ -377,7 +377,7 @@ uint16_t lv_arc_get_bg_angle_end(lv_obj_t * obj) int16_t lv_arc_get_value(const lv_obj_t * obj) { LV_ASSERT_OBJ(obj, MY_CLASS); - return ((lv_arc_t*) obj)->value; + return ((lv_arc_t *) obj)->value; } /** @@ -388,7 +388,7 @@ int16_t lv_arc_get_value(const lv_obj_t * obj) int16_t lv_arc_get_min_value(const lv_obj_t * obj) { LV_ASSERT_OBJ(obj, MY_CLASS); - return ((lv_arc_t*) obj)->min_value; + return ((lv_arc_t *) obj)->min_value; } /** @@ -399,7 +399,7 @@ int16_t lv_arc_get_min_value(const lv_obj_t * obj) int16_t lv_arc_get_max_value(const lv_obj_t * obj) { LV_ASSERT_OBJ(obj, MY_CLASS); - return ((lv_arc_t*) obj)->max_value; + return ((lv_arc_t *) obj)->max_value; } /** @@ -410,7 +410,7 @@ int16_t lv_arc_get_max_value(const lv_obj_t * obj) lv_arc_mode_t lv_arc_get_mode(const lv_obj_t * obj) { LV_ASSERT_OBJ(obj, MY_CLASS); - return ((lv_arc_t*) obj)->type; + return ((lv_arc_t *) obj)->type; } /*===================== @@ -432,25 +432,25 @@ static void lv_arc_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj) lv_arc_t * arc = (lv_arc_t *)obj; - /*Initialize the allocated 'ext'*/ - arc->rotation = 0; - arc->bg_angle_start = 135; - arc->bg_angle_end = 45; - arc->indic_angle_start = 135; - arc->indic_angle_end = 270; - arc->type = LV_ARC_MODE_NORMAL; - arc->value = VALUE_UNSET; - arc->min_close = 1; - arc->min_value = 0; - arc->max_value = 100; - arc->dragging = false; - arc->chg_rate = 720; - arc->last_tick = lv_tick_get(); - arc->last_angle =arc->indic_angle_end; + /*Initialize the allocated 'ext'*/ + arc->rotation = 0; + arc->bg_angle_start = 135; + arc->bg_angle_end = 45; + arc->indic_angle_start = 135; + arc->indic_angle_end = 270; + arc->type = LV_ARC_MODE_NORMAL; + arc->value = VALUE_UNSET; + arc->min_close = 1; + arc->min_value = 0; + arc->max_value = 100; + arc->dragging = false; + arc->chg_rate = 720; + arc->last_tick = lv_tick_get(); + arc->last_angle = arc->indic_angle_end; - lv_obj_add_flag(obj, LV_OBJ_FLAG_CLICKABLE); - lv_obj_clear_flag(obj, LV_OBJ_FLAG_SCROLL_CHAIN); - lv_obj_set_ext_click_area(obj, LV_DPI_DEF / 10); + lv_obj_add_flag(obj, LV_OBJ_FLAG_CLICKABLE); + lv_obj_clear_flag(obj, LV_OBJ_FLAG_SCROLL_CHAIN); + lv_obj_set_ext_click_area(obj, LV_DPI_DEF / 10); LV_TRACE_OBJ_CREATE("finished"); @@ -494,8 +494,8 @@ static void lv_arc_event(const lv_obj_class_t * class_p, lv_event_t * e) r -= indic_width; r -= r / 2; /*Add some more sensitive area*/ if(p.x * p.x + p.y * p.y > r * r) { - arc->dragging = true; - arc->last_tick = lv_tick_get(); /*Capture timestamp at dragging start*/ + arc->dragging = true; + arc->last_tick = lv_tick_get(); /*Capture timestamp at dragging start*/ } } @@ -507,20 +507,20 @@ static void lv_arc_event(const lv_obj_class_t * class_p, lv_event_t * e) /*Calculate the angle of the pressed point*/ int16_t angle; - int16_t bg_end =arc->bg_angle_end; - if(arc->bg_angle_end bg_angle_start) { - bg_end =arc->bg_angle_end + 360; + int16_t bg_end = arc->bg_angle_end; + if(arc->bg_angle_end < arc->bg_angle_start) { + bg_end = arc->bg_angle_end + 360; } angle = lv_atan2(p.y, p.x); - angle -=arc->rotation; - angle -=arc->bg_angle_start; /*Make the angle relative to the start angle*/ + angle -= arc->rotation; + angle -= arc->bg_angle_start; /*Make the angle relative to the start angle*/ if(angle < 0) angle += 360; - int16_t deg_range = bg_end -arc->bg_angle_start; + int16_t deg_range = bg_end - arc->bg_angle_start; - int16_t last_angle_rel =arc->last_angle -arc->bg_angle_start; + int16_t last_angle_rel = arc->last_angle - arc->bg_angle_start; int16_t delta_angle = angle - last_angle_rel; /*Do not allow big jumps. @@ -550,17 +550,17 @@ static void lv_arc_event(const lv_obj_class_t * class_p, lv_event_t * e) angle = last_angle_rel + delta_angle; /*Apply the limited angle change*/ /*Rounding for symmetry*/ - int32_t round = ((bg_end -arc->bg_angle_start) * 8) / (arc->max_value -arc->min_value); + int32_t round = ((bg_end - arc->bg_angle_start) * 8) / (arc->max_value - arc->min_value); round = (round + 4) >> 4; angle += round; - angle +=arc->bg_angle_start; /*Make the angle absolute again*/ + angle += arc->bg_angle_start; /*Make the angle absolute again*/ /*Set the new value*/ - int16_t old_value =arc->value; - int16_t new_value = lv_map(angle,arc->bg_angle_start, bg_end,arc->min_value,arc->max_value); + int16_t old_value = arc->value; + int16_t new_value = lv_map(angle, arc->bg_angle_start, bg_end, arc->min_value, arc->max_value); if(new_value != lv_arc_get_value(obj)) { - arc->last_tick = lv_tick_get(); /*Cache timestamp for the next iteration*/ + arc->last_tick = lv_tick_get(); /*Cache timestamp for the next iteration*/ lv_arc_set_value(obj, new_value); /*set_value caches the last_angle for the next iteration*/ if(new_value != old_value) { res = lv_event_send(obj, LV_EVENT_VALUE_CHANGED, NULL); @@ -569,12 +569,12 @@ static void lv_arc_event(const lv_obj_class_t * class_p, lv_event_t * e) } /*Don't let the elapsed time become too big while sitting on an end point*/ - if(new_value ==arc->min_value || new_value ==arc->max_value) { - arc->last_tick = lv_tick_get(); /*Cache timestamp for the next iteration*/ + if(new_value == arc->min_value || new_value == arc->max_value) { + arc->last_tick = lv_tick_get(); /*Cache timestamp for the next iteration*/ } } else if(code == LV_EVENT_RELEASED || code == LV_EVENT_PRESS_LOST) { - arc->dragging = false; + arc->dragging = false; /*Leave edit mode if released. (No need to wait for LONG_PRESS)*/ lv_group_t * g = lv_obj_get_group(obj); @@ -588,7 +588,7 @@ static void lv_arc_event(const lv_obj_class_t * class_p, lv_event_t * e) else if(code == LV_EVENT_KEY) { char c = *((char *)lv_event_get_param(e)); - int16_t old_value =arc->value; + int16_t old_value = arc->value; if(c == LV_KEY_RIGHT || c == LV_KEY_UP) { lv_arc_set_value(obj, lv_arc_get_value(obj) + 1); } @@ -596,7 +596,7 @@ static void lv_arc_event(const lv_obj_class_t * class_p, lv_event_t * e) lv_arc_set_value(obj, lv_arc_get_value(obj) - 1); } - if(old_value !=arc->value) { + if(old_value != arc->value) { res = lv_event_send(obj, LV_EVENT_VALUE_CHANGED, NULL); if(res != LV_RES_OK) return; } @@ -616,7 +616,8 @@ static void lv_arc_event(const lv_obj_class_t * class_p, lv_event_t * e) lv_coord_t * s = lv_event_get_param(e); *s = LV_MAX(*s, knob_pad - bg_pad); - } else if(code == LV_EVENT_DRAW_MAIN) { + } + else if(code == LV_EVENT_DRAW_MAIN) { lv_arc_draw(e); } } @@ -650,7 +651,7 @@ static void lv_arc_draw(lv_event_t * e) lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &part_draw_dsc); lv_draw_arc(center.x, center.y, part_draw_dsc.radius, arc->bg_angle_start + arc->rotation, - arc->bg_angle_end + arc->rotation, clip_area, + arc->bg_angle_end + arc->rotation, clip_area, &arc_dsc); lv_event_send(obj, LV_EVENT_DRAW_PART_END, &part_draw_dsc); @@ -676,8 +677,8 @@ static void lv_arc_draw(lv_event_t * e) lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &part_draw_dsc); if(arc_dsc.width > part_draw_dsc.radius) arc_dsc.width = part_draw_dsc.radius; - lv_draw_arc(center.x, center.y, part_draw_dsc.radius, arc->indic_angle_start +arc->rotation, - arc->indic_angle_end + arc->rotation, clip_area, + lv_draw_arc(center.x, center.y, part_draw_dsc.radius, arc->indic_angle_start + arc->rotation, + arc->indic_angle_end + arc->rotation, clip_area, &arc_dsc); lv_event_send(obj, LV_EVENT_DRAW_PART_END, &part_draw_dsc); @@ -758,7 +759,7 @@ static void get_center(lv_obj_t * obj, lv_point_t * center, lv_coord_t * arc_r) lv_coord_t bottom_bg = lv_obj_get_style_pad_bottom(obj, LV_PART_MAIN); lv_coord_t r = (LV_MIN(lv_obj_get_width(obj) - left_bg - right_bg, - lv_obj_get_height(obj) - top_bg - bottom_bg)) / 2; + lv_obj_get_height(obj) - top_bg - bottom_bg)) / 2; *arc_r = r; center->x = obj->coords.x1 + r + left_bg; @@ -777,17 +778,17 @@ static void get_knob_area(lv_obj_t * obj, const lv_point_t * center, lv_coord_t lv_coord_t indic_width_half = indic_width / 2; r -= indic_width_half; - uint16_t angle =arc->rotation; + uint16_t angle = arc->rotation; if(arc->type == LV_ARC_MODE_NORMAL) { - angle +=arc->indic_angle_end; + angle += arc->indic_angle_end; } else if(arc->type == LV_ARC_MODE_REVERSE) { - angle +=arc->indic_angle_start; + angle += arc->indic_angle_start; } else if(arc->type == LV_ARC_MODE_SYMMETRICAL) { - int32_t range_midpoint = (int32_t)(arc->min_value +arc->max_value) / 2; - if(arc->value < range_midpoint) angle +=arc->indic_angle_start; - else angle +=arc->indic_angle_end; + int32_t range_midpoint = (int32_t)(arc->min_value + arc->max_value) / 2; + if(arc->value < range_midpoint) angle += arc->indic_angle_start; + else angle += arc->indic_angle_end; } lv_coord_t knob_x = (r * lv_trigo_sin(angle + 90)) >> LV_TRIGO_SHIFT; lv_coord_t knob_y = (r * lv_trigo_sin(angle)) >> LV_TRIGO_SHIFT; @@ -815,39 +816,39 @@ static void value_update(lv_obj_t * obj) /*If the value is still not set to any value do not update*/ if(arc->value == VALUE_UNSET) return; - int16_t bg_midpoint, range_midpoint, bg_end =arc->bg_angle_end; - if(arc->bg_angle_end bg_angle_start) bg_end =arc->bg_angle_end + 360; + int16_t bg_midpoint, range_midpoint, bg_end = arc->bg_angle_end; + if(arc->bg_angle_end < arc->bg_angle_start) bg_end = arc->bg_angle_end + 360; int16_t angle; switch(arc->type) { case LV_ARC_MODE_SYMMETRICAL: bg_midpoint = (arc->bg_angle_start + bg_end) / 2; - range_midpoint = (int32_t)(arc->min_value +arc->max_value) / 2; + range_midpoint = (int32_t)(arc->min_value + arc->max_value) / 2; if(arc->value < range_midpoint) { - angle = lv_map(arc->value,arc->min_value, range_midpoint,arc->bg_angle_start, bg_midpoint); + angle = lv_map(arc->value, arc->min_value, range_midpoint, arc->bg_angle_start, bg_midpoint); lv_arc_set_start_angle(obj, angle); lv_arc_set_end_angle(obj, bg_midpoint); } else { - angle = lv_map(arc->value, range_midpoint,arc->max_value, bg_midpoint, bg_end); + angle = lv_map(arc->value, range_midpoint, arc->max_value, bg_midpoint, bg_end); lv_arc_set_start_angle(obj, bg_midpoint); lv_arc_set_end_angle(obj, angle); } break; case LV_ARC_MODE_REVERSE: - angle = lv_map(arc->value,arc->min_value,arc->max_value,arc->bg_angle_start, bg_end); - lv_arc_set_angles(obj, angle ,arc->bg_angle_end); + angle = lv_map(arc->value, arc->min_value, arc->max_value, arc->bg_angle_start, bg_end); + lv_arc_set_angles(obj, angle, arc->bg_angle_end); break; case LV_ARC_MODE_NORMAL: - angle = lv_map(arc->value,arc->min_value,arc->max_value,arc->bg_angle_start, bg_end); + angle = lv_map(arc->value, arc->min_value, arc->max_value, arc->bg_angle_start, bg_end); lv_arc_set_angles(obj, arc->bg_angle_start, angle); break; default: LV_LOG_WARN("Invalid mode: %d", arc->type); return; } - arc->last_angle = angle; /*Cache angle for slew rate limiting*/ + arc->last_angle = angle; /*Cache angle for slew rate limiting*/ } #endif diff --git a/src/widgets/lv_arc.h b/src/widgets/lv_arc.h index 27883e1fa..db9b786a1 100644 --- a/src/widgets/lv_arc.h +++ b/src/widgets/lv_arc.h @@ -41,16 +41,16 @@ typedef struct { uint16_t indic_angle_end; uint16_t bg_angle_start; uint16_t bg_angle_end; - int16_t value; /*Current value of the arc*/ - int16_t min_value; /*Minimum value of the arc*/ - int16_t max_value; /*Maximum value of the arc*/ + int16_t value; /*Current value of the arc*/ + int16_t min_value; /*Minimum value of the arc*/ + int16_t max_value; /*Maximum value of the arc*/ uint16_t dragging : 1; uint16_t type : 2; - uint16_t min_close : 1; /*1: the last pressed angle was closer to minimum end*/ - uint16_t chg_rate; /*Drag angle rate of change of the arc (degrees/sec)*/ - uint32_t last_tick; /*Last dragging event timestamp of the arc*/ - int16_t last_angle; /*Last dragging angle of the arc*/ -}lv_arc_t; + uint16_t min_close : 1; /*1: the last pressed angle was closer to minimum end*/ + uint16_t chg_rate; /*Drag angle rate of change of the arc (degrees/sec)*/ + uint32_t last_tick; /*Last dragging event timestamp of the arc*/ + int16_t last_angle; /*Last dragging angle of the arc*/ +} lv_arc_t; extern const lv_obj_class_t lv_arc_class; @@ -62,7 +62,7 @@ typedef enum { LV_ARC_DRAW_PART_BACKGROUND, /**< The background arc*/ LV_ARC_DRAW_PART_FOREGROUND, /**< The foreground arc*/ LV_ARC_DRAW_PART_KNOB, /**< The knob*/ -}lv_arc_draw_part_type_t; +} lv_arc_draw_part_type_t; /********************** * GLOBAL PROTOTYPES @@ -85,81 +85,81 @@ lv_obj_t * lv_arc_create(lv_obj_t * parent); /** * Set the start angle of an arc. 0 deg: right, 90 bottom, etc. - * @param arc pointer to an arc object + * @param arc pointer to an arc object * @param start the start angle */ void lv_arc_set_start_angle(lv_obj_t * arc, uint16_t start); /** * Set the end angle of an arc. 0 deg: right, 90 bottom, etc. - * @param arc pointer to an arc object - * @param end the end angle + * @param arc pointer to an arc object + * @param end the end angle */ void lv_arc_set_end_angle(lv_obj_t * arc, uint16_t end); /** * Set the start and end angles - * @param arc pointer to an arc object + * @param arc pointer to an arc object * @param start the start angle - * @param end the end angle + * @param end the end angle */ void lv_arc_set_angles(lv_obj_t * arc, uint16_t start, uint16_t end); /** * Set the start angle of an arc background. 0 deg: right, 90 bottom, etc. - * @param arc pointer to an arc object + * @param arc pointer to an arc object * @param start the start angle */ void lv_arc_set_bg_start_angle(lv_obj_t * arc, uint16_t start); /** * Set the start angle of an arc background. 0 deg: right, 90 bottom etc. - * @param arc pointer to an arc object - * @param end the end angle + * @param arc pointer to an arc object + * @param end the end angle */ void lv_arc_set_bg_end_angle(lv_obj_t * arc, uint16_t end); /** * Set the start and end angles of the arc background - * @param arc pointer to an arc object + * @param arc pointer to an arc object * @param start the start angle - * @param end the end angle + * @param end the end angle */ void lv_arc_set_bg_angles(lv_obj_t * arc, uint16_t start, uint16_t end); /** * Set the rotation for the whole arc - * @param arc pointer to an arc object - * @param rotation rotation angle + * @param arc pointer to an arc object + * @param rotation rotation angle */ void lv_arc_set_rotation(lv_obj_t * arc, uint16_t rotation); /** * Set the type of arc. - * @param arc pointer to arc object - * @param mode arc's mode + * @param arc pointer to arc object + * @param mode arc's mode */ void lv_arc_set_mode(lv_obj_t * arc, lv_arc_mode_t type); /** * Set a new value on the arc - * @param arc pointer to an arc object + * @param arc pointer to an arc object * @param value new value */ void lv_arc_set_value(lv_obj_t * arc, int16_t value); /** * Set minimum and the maximum values of an arc - * @param arc pointer to the arc object - * @param min minimum value - * @param max maximum value + * @param arc pointer to the arc object + * @param min minimum value + * @param max maximum value */ void lv_arc_set_range(lv_obj_t * arc, int16_t min, int16_t max); /** * Set a change rate to limit the speed how fast the arc should reach the pressed point. - * @param arc pointer to an arc object - * @param rate the change rate + * @param arc pointer to an arc object + * @param rate the change rate */ void lv_arc_set_change_rate(lv_obj_t * arc, uint16_t rate); @@ -169,57 +169,57 @@ void lv_arc_set_change_rate(lv_obj_t * arc, uint16_t rate); /** * Get the start angle of an arc. - * @param arc pointer to an arc object - * @return the start angle [0..360] + * @param arc pointer to an arc object + * @return the start angle [0..360] */ uint16_t lv_arc_get_angle_start(lv_obj_t * obj); /** * Get the end angle of an arc. - * @param arc pointer to an arc object - * @return the end angle [0..360] + * @param arc pointer to an arc object + * @return the end angle [0..360] */ uint16_t lv_arc_get_angle_end(lv_obj_t * obj); /** * Get the start angle of an arc background. - * @param arc pointer to an arc object - * @return the start angle [0..360] + * @param arc pointer to an arc object + * @return the start angle [0..360] */ uint16_t lv_arc_get_bg_angle_start(lv_obj_t * obj); /** * Get the end angle of an arc background. - * @param arc pointer to an arc object - * @return the end angle [0..360] + * @param arc pointer to an arc object + * @return the end angle [0..360] */ uint16_t lv_arc_get_bg_angle_end(lv_obj_t * obj); /** * Get the value of an arc - * @param arc pointer to an arc object - * @return the value of the arc + * @param arc pointer to an arc object + * @return the value of the arc */ int16_t lv_arc_get_value(const lv_obj_t * obj); /** * Get the minimum value of an arc - * @param arc pointer to an arc object - * @return the minimum value of the arc + * @param arc pointer to an arc object + * @return the minimum value of the arc */ int16_t lv_arc_get_min_value(const lv_obj_t * obj); /** * Get the maximum value of an arc - * @param arc pointer to an arc object - * @return the maximum value of the arc + * @param arc pointer to an arc object + * @return the maximum value of the arc */ int16_t lv_arc_get_max_value(const lv_obj_t * obj); /** * Get whether the arc is type or not. - * @param arc pointer to an arc object - * @return arc's mode + * @param arc pointer to an arc object + * @return arc's mode */ lv_arc_mode_t lv_arc_get_mode(const lv_obj_t * obj); diff --git a/src/widgets/lv_bar.c b/src/widgets/lv_bar.c index 4558d8565..5037f4288 100644 --- a/src/widgets/lv_bar.c +++ b/src/widgets/lv_bar.c @@ -310,8 +310,7 @@ static void draw_indic(lv_event_t * e) anim_start_value_x += anim_start_value_start_x; } - else - { + else { anim_start_value_x = (int32_t)((int32_t)anim_length * (bar->start_value - bar->min_value)) / range; } @@ -325,8 +324,7 @@ static void draw_indic(lv_event_t * e) bar->cur_value_anim.anim_state) / LV_BAR_ANIM_STATE_END); } - else - { + else { anim_cur_value_x = (int32_t)((int32_t)anim_length * (bar->cur_value - bar->min_value)) / range; } @@ -411,9 +409,9 @@ static void draw_indic(lv_event_t * e) part_draw_dsc.class_p = MY_CLASS; part_draw_dsc.type = LV_BAR_DRAW_PART_INDICATOR; part_draw_dsc.rect_dsc = &draw_rect_dsc; - part_draw_dsc.draw_area = &bar->indic_area; + part_draw_dsc.draw_area = &bar->indic_area; - lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &part_draw_dsc); + lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &part_draw_dsc); /*Draw only the shadow if the indicator is long enough. *The radius of the bg and the indicator can make a strange shape where @@ -526,10 +524,12 @@ static void lv_bar_event(const lv_obj_class_t * class_p, lv_event_t * e) if(pad < 0) { *s = LV_MAX(*s, -pad); } - } else if(code == LV_EVENT_PRESSED || code == LV_EVENT_RELEASED) { + } + else if(code == LV_EVENT_PRESSED || code == LV_EVENT_RELEASED) { lv_bar_t * bar = (lv_bar_t *)obj; lv_obj_invalidate_area(obj, &bar->indic_area); - } else if(code == LV_EVENT_DRAW_MAIN) { + } + else if(code == LV_EVENT_DRAW_MAIN) { draw_indic(e); } } @@ -560,7 +560,7 @@ static void lv_bar_set_value_with_anim(lv_obj_t * obj, int32_t new_value, int32_ { if(en == LV_ANIM_OFF) { *value_ptr = new_value; - lv_obj_invalidate((lv_obj_t*)obj); + lv_obj_invalidate((lv_obj_t *)obj); } else { /*No animation in progress -> simply set the values*/ diff --git a/src/widgets/lv_bar.h b/src/widgets/lv_bar.h index 8091923e3..b839b1453 100644 --- a/src/widgets/lv_bar.h +++ b/src/widgets/lv_bar.h @@ -54,7 +54,7 @@ typedef struct { _lv_bar_anim_t cur_value_anim; _lv_bar_anim_t start_value_anim; lv_bar_mode_t mode : 2; /**< Type of bar*/ -}lv_bar_t; +} lv_bar_t; extern const lv_obj_class_t lv_bar_class; @@ -64,7 +64,7 @@ extern const lv_obj_class_t lv_bar_class; */ typedef enum { LV_BAR_DRAW_PART_INDICATOR, /**< The indicator*/ -}lv_bar_draw_part_type_t; +} lv_bar_draw_part_type_t; /********************** * GLOBAL PROTOTYPES diff --git a/src/widgets/lv_btn.h b/src/widgets/lv_btn.h index 8a5af5102..1d471f975 100644 --- a/src/widgets/lv_btn.h +++ b/src/widgets/lv_btn.h @@ -28,7 +28,7 @@ extern "C" { typedef struct { lv_obj_t obj; -}lv_btn_t; +} lv_btn_t; extern const lv_obj_class_t lv_btn_class; diff --git a/src/widgets/lv_btnmatrix.c b/src/widgets/lv_btnmatrix.c index fdd09d4c9..ad1d3ee83 100644 --- a/src/widgets/lv_btnmatrix.c +++ b/src/widgets/lv_btnmatrix.c @@ -58,16 +58,16 @@ static void make_one_button_checked(lv_obj_t * obj, uint16_t btn_idx); static const char * lv_btnmatrix_def_map[] = {"Btn1", "Btn2", "Btn3", "\n", "Btn4", "Btn5", ""}; const lv_obj_class_t lv_btnmatrix_class = { - .constructor_cb = lv_btnmatrix_constructor, - .destructor_cb = lv_btnmatrix_destructor, - .event_cb = lv_btnmatrix_event, - .width_def = LV_DPI_DEF * 2, - .height_def = LV_DPI_DEF, - .instance_size = sizeof(lv_btnmatrix_t), - .editable = LV_OBJ_CLASS_EDITABLE_TRUE, - .group_def = LV_OBJ_CLASS_GROUP_DEF_TRUE, - .base_class = &lv_obj_class - }; + .constructor_cb = lv_btnmatrix_constructor, + .destructor_cb = lv_btnmatrix_destructor, + .event_cb = lv_btnmatrix_event, + .width_def = LV_DPI_DEF * 2, + .height_def = LV_DPI_DEF, + .instance_size = sizeof(lv_btnmatrix_t), + .editable = LV_OBJ_CLASS_EDITABLE_TRUE, + .group_def = LV_OBJ_CLASS_GROUP_DEF_TRUE, + .base_class = &lv_obj_class +}; /********************** * MACROS @@ -519,16 +519,19 @@ static void lv_btnmatrix_event(const lv_obj_class_t * class_p, lv_event_t * e) bool editing = lv_group_get_editing(lv_obj_get_group(obj)); /*Focus the first button if there is not selected button*/ if(btnm->btn_id_sel == LV_BTNMATRIX_BTN_NONE) { - if (indev_type == LV_INDEV_TYPE_KEYPAD || (indev_type == LV_INDEV_TYPE_ENCODER && editing)) { + if(indev_type == LV_INDEV_TYPE_KEYPAD || (indev_type == LV_INDEV_TYPE_ENCODER && editing)) { uint32_t b = 0; if(btnm->one_check) { - while(button_is_hidden(btnm->ctrl_bits[b]) || button_is_inactive(btnm->ctrl_bits[b]) || button_is_checked(btnm->ctrl_bits[b]) == false) b++; - } else { + while(button_is_hidden(btnm->ctrl_bits[b]) || button_is_inactive(btnm->ctrl_bits[b]) || + button_is_checked(btnm->ctrl_bits[b]) == false) b++; + } + else { while(button_is_hidden(btnm->ctrl_bits[b]) || button_is_inactive(btnm->ctrl_bits[b])) b++; } btnm->btn_id_sel = b; - } else { + } + else { btnm->btn_id_sel = LV_BTNMATRIX_BTN_NONE; } } @@ -620,7 +623,8 @@ static void lv_btnmatrix_event(const lv_obj_class_t * class_p, lv_event_t * e) } invalidate_button_area(obj, btnm->btn_id_sel); - } else if(code == LV_EVENT_DRAW_MAIN) { + } + else if(code == LV_EVENT_DRAW_MAIN) { draw_main(e); } @@ -729,7 +733,7 @@ static void draw_main(lv_event_t * e) part_draw_dsc.draw_area = &btn_area; part_draw_dsc.id = btn_i; - lv_event_send(obj,LV_EVENT_DRAW_PART_BEGIN, &part_draw_dsc); + lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &part_draw_dsc); /*Remove borders on the edges if `LV_BORDER_SIDE_INTERNAL`*/ if(draw_rect_dsc_act.border_side & LV_BORDER_SIDE_INTERNAL) { @@ -759,7 +763,7 @@ static void draw_main(lv_event_t * e) #endif lv_point_t txt_size; lv_txt_get_size(&txt_size, txt, font, letter_space, - line_space, lv_area_get_width(&area_obj), draw_label_dsc_act.flag); + line_space, lv_area_get_width(&area_obj), draw_label_dsc_act.flag); btn_area.x1 += (lv_area_get_width(&btn_area) - txt_size.x) / 2; btn_area.y1 += (lv_area_get_height(&btn_area) - txt_size.y) / 2; @@ -769,7 +773,7 @@ static void draw_main(lv_event_t * e) /*Draw the text*/ lv_draw_label(&btn_area, clip_area, &draw_label_dsc_act, txt, NULL); - lv_event_send(obj,LV_EVENT_DRAW_PART_END, &part_draw_dsc); + lv_event_send(obj, LV_EVENT_DRAW_PART_END, &part_draw_dsc); } obj->skip_trans = 0; @@ -911,11 +915,11 @@ static uint16_t get_button_from_point(lv_obj_t * obj, lv_point_t * p) else btn_area.y1 += obj_cords.y1 - prow; if(btn_area.x2 >= w - pright - 2) btn_area.x2 += obj_cords.x1 + LV_MIN(pright, - BTN_EXTRA_CLICK_AREA_MAX); /*-2 for rounding error*/ + BTN_EXTRA_CLICK_AREA_MAX); /*-2 for rounding error*/ else btn_area.x2 += obj_cords.x1 + pcol; if(btn_area.y2 >= h - pbottom - 2) btn_area.y2 += obj_cords.y1 + LV_MIN(pbottom, - BTN_EXTRA_CLICK_AREA_MAX); /*-2 for rounding error*/ + BTN_EXTRA_CLICK_AREA_MAX); /*-2 for rounding error*/ else btn_area.y2 += obj_cords.y1 + prow; if(_lv_area_is_point_on(&btn_area, p, 0) != false) { diff --git a/src/widgets/lv_btnmatrix.h b/src/widgets/lv_btnmatrix.h index d5cca5533..0d6e5e2b1 100644 --- a/src/widgets/lv_btnmatrix.h +++ b/src/widgets/lv_btnmatrix.h @@ -47,7 +47,8 @@ enum { typedef uint16_t lv_btnmatrix_ctrl_t; -typedef bool (*lv_btnmatrix_btn_draw_cb_t)(lv_obj_t * btnm, uint32_t btn_id, const lv_area_t * draw_area, const lv_area_t * clip_area); +typedef bool (*lv_btnmatrix_btn_draw_cb_t)(lv_obj_t * btnm, uint32_t btn_id, const lv_area_t * draw_area, + const lv_area_t * clip_area); /*Data of button matrix*/ typedef struct { @@ -68,7 +69,7 @@ extern const lv_obj_class_t lv_btnmatrix_class; */ typedef enum { LV_BTNMATRIX_DRAW_PART_BTN, /**< The rectangle and label of buttons*/ -}lv_btnmatrix_draw_part_type_t; +} lv_btnmatrix_draw_part_type_t; /********************** * GLOBAL PROTOTYPES diff --git a/src/widgets/lv_checkbox.c b/src/widgets/lv_checkbox.c index e940fdad3..2128f2d13 100644 --- a/src/widgets/lv_checkbox.c +++ b/src/widgets/lv_checkbox.c @@ -94,7 +94,7 @@ void lv_checkbox_set_text_static(lv_obj_t * obj, const char * txt) if(!cb->static_txt) lv_mem_free(cb->txt); - cb->txt = (char*)txt; + cb->txt = (char *)txt; cb->static_txt = 1; lv_obj_refresh_self_size(obj); @@ -156,10 +156,10 @@ static void lv_checkbox_event(const lv_obj_class_t * class_p, lv_event_t * e) lv_event_code_t code = lv_event_get_code(e); lv_obj_t * obj = lv_event_get_target(e); - if (code == LV_EVENT_PRESSED || code == LV_EVENT_RELEASED) { - lv_obj_invalidate(obj); + if(code == LV_EVENT_PRESSED || code == LV_EVENT_RELEASED) { + lv_obj_invalidate(obj); } - else if (code == LV_EVENT_GET_SELF_SIZE) { + else if(code == LV_EVENT_GET_SELF_SIZE) { lv_point_t * p = lv_event_get_param(e); lv_checkbox_t * cb = (lv_checkbox_t *)obj; @@ -184,7 +184,7 @@ static void lv_checkbox_event(const lv_obj_class_t * class_p, lv_event_t * e) p->y = LV_MAX(marker_size.y, txt_size.y); } else if(code == LV_EVENT_REFR_EXT_DRAW_SIZE) { - lv_coord_t *s = lv_event_get_param(e); + lv_coord_t * s = lv_event_get_param(e); lv_coord_t m = lv_obj_calculate_ext_draw_size(obj, LV_PART_INDICATOR); *s = LV_MAX(*s, m); } @@ -194,7 +194,8 @@ static void lv_checkbox_event(const lv_obj_class_t * class_p, lv_event_t * e) if(res != LV_RES_OK) return; lv_obj_invalidate(obj); - } else if(code == LV_EVENT_DRAW_MAIN) { + } + else if(code == LV_EVENT_DRAW_MAIN) { lv_checkbox_draw(e); } } diff --git a/src/widgets/lv_checkbox.h b/src/widgets/lv_checkbox.h index a21cfd7be..94e82f087 100644 --- a/src/widgets/lv_checkbox.h +++ b/src/widgets/lv_checkbox.h @@ -29,8 +29,8 @@ extern "C" { typedef struct { lv_obj_t obj; char * txt; - uint32_t static_txt :1; -}lv_checkbox_t; + uint32_t static_txt : 1; +} lv_checkbox_t; extern const lv_obj_class_t lv_checkbox_class; @@ -40,7 +40,7 @@ extern const lv_obj_class_t lv_checkbox_class; */ typedef enum { LV_CHECKBOX_DRAW_PART_BOX, /**< The tick box*/ -}lv_checkbox_draw_part_type_t; +} lv_checkbox_draw_part_type_t; /********************** * GLOBAL PROTOTYPES diff --git a/src/widgets/lv_dropdown.c b/src/widgets/lv_dropdown.c index 6516958cb..627bcf63e 100644 --- a/src/widgets/lv_dropdown.c +++ b/src/widgets/lv_dropdown.c @@ -424,7 +424,7 @@ void lv_dropdown_open(lv_obj_t * dropdown_obj) if(dropdown->list == NULL) { lv_obj_t * list_obj = lv_dropdown_list_create(lv_obj_get_screen(dropdown_obj)); - ((lv_dropdown_list_t*) list_obj)->dropdown = dropdown_obj; + ((lv_dropdown_list_t *) list_obj)->dropdown = dropdown_obj; dropdown->list = list_obj; lv_obj_clear_flag(dropdown->list, LV_OBJ_FLAG_CLICK_FOCUSABLE); lv_obj_add_flag(dropdown->list, LV_OBJ_FLAG_IGNORE_LAYOUT); @@ -504,16 +504,16 @@ void lv_dropdown_open(lv_obj_t * dropdown_obj) lv_text_align_t align = lv_obj_calculate_style_text_align(label, LV_PART_MAIN, dropdown->options); switch(align) { - default: - case LV_TEXT_ALIGN_LEFT: - lv_obj_align(label, LV_ALIGN_TOP_LEFT, 0, 0); - break; - case LV_TEXT_ALIGN_RIGHT: - lv_obj_align(label, LV_ALIGN_TOP_RIGHT, 0, 0); - break; - case LV_TEXT_ALIGN_CENTER: - lv_obj_align(label, LV_ALIGN_CENTER, 0, 0); - break; + default: + case LV_TEXT_ALIGN_LEFT: + lv_obj_align(label, LV_ALIGN_TOP_LEFT, 0, 0); + break; + case LV_TEXT_ALIGN_RIGHT: + lv_obj_align(label, LV_ALIGN_TOP_RIGHT, 0, 0); + break; + case LV_TEXT_ALIGN_CENTER: + lv_obj_align(label, LV_ALIGN_CENTER, 0, 0); + break; } } @@ -763,16 +763,19 @@ static void draw_main(lv_event_t * e) lv_coord_t symbol_h; if(symbol_type == LV_IMG_SRC_SYMBOL) { lv_point_t size; - lv_txt_get_size(&size, dropdown->symbol, symbol_dsc.font, symbol_dsc.letter_space, symbol_dsc.line_space, LV_COORD_MAX, symbol_dsc.flag); + lv_txt_get_size(&size, dropdown->symbol, symbol_dsc.font, symbol_dsc.letter_space, symbol_dsc.line_space, LV_COORD_MAX, + symbol_dsc.flag); symbol_w = size.x; symbol_h = size.y; - } else { + } + else { lv_img_header_t header; lv_res_t res = lv_img_decoder_get_info(dropdown->symbol, &header); if(res == LV_RES_OK) { symbol_w = header.w; symbol_h = header.h; - } else { + } + else { symbol_w = -1; symbol_h = -1; } @@ -782,7 +785,8 @@ static void draw_main(lv_event_t * e) if(symbol_to_left) { symbol_area.x1 = obj->coords.x1 + left; symbol_area.x2 = symbol_area.x1 + symbol_w - 1; - } else { + } + else { symbol_area.x1 = obj->coords.x2 - right - symbol_w; symbol_area.x2 = symbol_area.x1 + symbol_w - 1; } @@ -791,7 +795,8 @@ static void draw_main(lv_event_t * e) symbol_area.y1 = obj->coords.y1 + top; symbol_area.y2 = symbol_area.y1 + symbol_h - 1; lv_draw_label(&symbol_area, clip_area, &symbol_dsc, dropdown->symbol, NULL); - } else { + } + else { symbol_area.y1 = obj->coords.y1 + (lv_obj_get_height(obj) - symbol_h) / 2; symbol_area.y2 = symbol_area.y1 + symbol_h - 1; lv_draw_img_dsc_t img_dsc; @@ -809,7 +814,8 @@ static void draw_main(lv_event_t * e) lv_obj_init_draw_label_dsc(obj, LV_PART_MAIN, &label_dsc); lv_point_t size; - lv_txt_get_size(&size, opt_txt, label_dsc.font, label_dsc.letter_space, label_dsc.line_space, LV_COORD_MAX, label_dsc.flag); + lv_txt_get_size(&size, opt_txt, label_dsc.font, label_dsc.letter_space, label_dsc.line_space, LV_COORD_MAX, + label_dsc.flag); lv_area_t txt_area; txt_area.y1 = obj->coords.y1 + top; @@ -824,7 +830,8 @@ static void draw_main(lv_event_t * e) if(symbol_to_left) { txt_area.x1 = obj->coords.x2 - right - size.x; txt_area.x2 = txt_area.x1 + size.x; - } else { + } + else { txt_area.x1 = obj->coords.x1 + left; txt_area.x2 = txt_area.x1 + size.x; } @@ -856,13 +863,15 @@ static void draw_list(lv_event_t * e) if(dropdown->pr_opt_id == dropdown->sel_opt_id) { draw_box(dropdown_obj, &clip_area_core, dropdown->pr_opt_id, LV_STATE_CHECKED | LV_STATE_PRESSED); draw_box_label(dropdown_obj, &clip_area_core, dropdown->pr_opt_id, LV_STATE_CHECKED | LV_STATE_PRESSED); - } else { + } + else { draw_box(dropdown_obj, &clip_area_core, dropdown->pr_opt_id, LV_STATE_PRESSED); draw_box_label(dropdown_obj, &clip_area_core, dropdown->pr_opt_id, LV_STATE_PRESSED); draw_box(dropdown_obj, &clip_area_core, dropdown->sel_opt_id, LV_STATE_CHECKED); draw_box_label(dropdown_obj, &clip_area_core, dropdown->sel_opt_id, LV_STATE_CHECKED); } - } else { + } + else { draw_box(dropdown_obj, &clip_area_core, dropdown->pr_opt_id, LV_STATE_PRESSED); draw_box_label(dropdown_obj, &clip_area_core, dropdown->pr_opt_id, LV_STATE_PRESSED); } @@ -925,7 +934,8 @@ static void draw_box_label(lv_obj_t * dropdown_obj, const lv_area_t * clip_area, lv_draw_label_dsc_init(&label_dsc); lv_obj_init_draw_label_dsc(list_obj, LV_PART_SELECTED, &label_dsc); - label_dsc.line_space = lv_obj_get_style_text_line_space(list_obj, LV_PART_SELECTED); /*Line space should come from the list*/ + label_dsc.line_space = lv_obj_get_style_text_line_space(list_obj, + LV_PART_SELECTED); /*Line space should come from the list*/ lv_obj_t * label = get_label(dropdown_obj); if(label == NULL) return; @@ -989,7 +999,7 @@ static lv_res_t btn_release_handler(lv_obj_t * obj) */ static lv_res_t list_release_handler(lv_obj_t * list_obj) { - lv_dropdown_list_t * list = (lv_dropdown_list_t*) list_obj; + lv_dropdown_list_t * list = (lv_dropdown_list_t *) list_obj; lv_obj_t * dropdown_obj = list->dropdown; lv_dropdown_t * dropdown = (lv_dropdown_t *)dropdown_obj; @@ -1025,7 +1035,7 @@ static lv_res_t list_release_handler(lv_obj_t * list_obj) static void list_press_handler(lv_obj_t * list_obj) { - lv_dropdown_list_t * list = (lv_dropdown_list_t*) list_obj; + lv_dropdown_list_t * list = (lv_dropdown_list_t *) list_obj; lv_obj_t * dropdown_obj = list->dropdown; lv_dropdown_t * dropdown = (lv_dropdown_t *)dropdown_obj; diff --git a/src/widgets/lv_dropdown.h b/src/widgets/lv_dropdown.h index 14caf74ad..402a37ce5 100644 --- a/src/widgets/lv_dropdown.h +++ b/src/widgets/lv_dropdown.h @@ -45,15 +45,15 @@ typedef struct { uint16_t sel_opt_id; /**< Index of the currently selected option*/ uint16_t sel_opt_id_orig; /**< Store the original index on focus*/ uint16_t pr_opt_id; /**< Index of the currently pressed option*/ - lv_dir_t dir :4; /**< Direction in which the list should open*/ - uint8_t static_txt :1; /**< 1: Only a pointer is saved in `options`*/ - uint8_t selected_highlight:1; /**< 1: Make the selected option highlighted in the list*/ -}lv_dropdown_t; + lv_dir_t dir : 4; /**< Direction in which the list should open*/ + uint8_t static_txt : 1; /**< 1: Only a pointer is saved in `options`*/ + uint8_t selected_highlight: 1; /**< 1: Make the selected option highlighted in the list*/ +} lv_dropdown_t; typedef struct { - lv_obj_t obj; - lv_obj_t * dropdown; -}lv_dropdown_list_t; + lv_obj_t obj; + lv_obj_t * dropdown; +} lv_dropdown_list_t; extern const lv_obj_class_t lv_dropdown_class; extern const lv_obj_class_t lv_dropdownlist_class; diff --git a/src/widgets/lv_img.c b/src/widgets/lv_img.c index c38da60e6..126e8805b 100644 --- a/src/widgets/lv_img.c +++ b/src/widgets/lv_img.c @@ -37,14 +37,14 @@ static void draw_img(lv_event_t * e); * STATIC VARIABLES **********************/ const lv_obj_class_t lv_img_class = { - .constructor_cb = lv_img_constructor, - .destructor_cb = lv_img_destructor, - .event_cb = lv_img_event, - .width_def = LV_SIZE_CONTENT, - .height_def = LV_SIZE_CONTENT, - .instance_size = sizeof(lv_img_t), - .base_class = &lv_obj_class - }; + .constructor_cb = lv_img_constructor, + .destructor_cb = lv_img_destructor, + .event_cb = lv_img_event, + .width_def = LV_SIZE_CONTENT, + .height_def = LV_SIZE_CONTENT, + .instance_size = sizeof(lv_img_t), + .base_class = &lv_obj_class +}; /********************** * MACROS @@ -95,7 +95,7 @@ void lv_img_set_src(lv_obj_t * obj, const void * src) if(src_type == LV_IMG_SRC_UNKNOWN) { LV_LOG_WARN("lv_img_set_src: unknown image type"); if(img->src_type == LV_IMG_SRC_SYMBOL || img->src_type == LV_IMG_SRC_FILE) { - lv_mem_free((void*)img->src); + lv_mem_free((void *)img->src); } img->src = NULL; img->src_type = LV_IMG_SRC_UNKNOWN; @@ -109,7 +109,7 @@ void lv_img_set_src(lv_obj_t * obj, const void * src) if(src_type == LV_IMG_SRC_VARIABLE) { /*If memory was allocated because of the previous `src_type` then free it*/ if(img->src_type == LV_IMG_SRC_FILE || img->src_type == LV_IMG_SRC_SYMBOL) { - lv_mem_free((void*)img->src); + lv_mem_free((void *)img->src); } img->src = src; } @@ -129,7 +129,7 @@ void lv_img_set_src(lv_obj_t * obj, const void * src) strcpy(new_str, src); img->src = new_str; - if(old_src) lv_mem_free((void*)old_src); + if(old_src) lv_mem_free((void *)old_src); } } @@ -163,7 +163,7 @@ void lv_img_set_offset_x(lv_obj_t * obj, lv_coord_t x) { LV_ASSERT_OBJ(obj, MY_CLASS); - lv_img_t * img = (lv_img_t *)obj; + lv_img_t * img = (lv_img_t *)obj; x = x % img->w; @@ -175,7 +175,7 @@ void lv_img_set_offset_y(lv_obj_t * obj, lv_coord_t y) { LV_ASSERT_OBJ(obj, MY_CLASS); - lv_img_t * img = (lv_img_t *)obj; + lv_img_t * img = (lv_img_t *)obj; y = y % img->h; @@ -187,7 +187,7 @@ void lv_img_set_angle(lv_obj_t * obj, int16_t angle) { if(angle < 0 || angle >= 3600) angle = angle % 3600; - lv_img_t * img = (lv_img_t *)obj; + lv_img_t * img = (lv_img_t *)obj; if(angle == img->angle) return; lv_coord_t transf_zoom = lv_obj_get_style_transform_zoom(obj, LV_PART_MAIN); @@ -251,7 +251,7 @@ void lv_img_set_pivot(lv_obj_t * obj, lv_coord_t x, lv_coord_t y) void lv_img_set_zoom(lv_obj_t * obj, uint16_t zoom) { - lv_img_t * img = (lv_img_t *)obj; + lv_img_t * img = (lv_img_t *)obj; if(zoom == img->zoom) return; if(zoom == 0) zoom = 1; @@ -284,7 +284,7 @@ void lv_img_set_zoom(lv_obj_t * obj, uint16_t zoom) void lv_img_set_antialias(lv_obj_t * obj, bool antialias) { - lv_img_t * img = (lv_img_t *)obj; + lv_img_t * img = (lv_img_t *)obj; if(antialias == img->antialias) return; img->antialias = antialias; @@ -309,7 +309,7 @@ const void * lv_img_get_src(lv_obj_t * obj) { LV_ASSERT_OBJ(obj, MY_CLASS); - lv_img_t * img = (lv_img_t *)obj; + lv_img_t * img = (lv_img_t *)obj; return img->src; } @@ -318,7 +318,7 @@ lv_coord_t lv_img_get_offset_x(lv_obj_t * obj) { LV_ASSERT_OBJ(obj, MY_CLASS); - lv_img_t * img = (lv_img_t *)obj; + lv_img_t * img = (lv_img_t *)obj; return img->offset.x; } @@ -327,7 +327,7 @@ lv_coord_t lv_img_get_offset_y(lv_obj_t * obj) { LV_ASSERT_OBJ(obj, MY_CLASS); - lv_img_t * img = (lv_img_t *)obj; + lv_img_t * img = (lv_img_t *)obj; return img->offset.y; } @@ -336,7 +336,7 @@ uint16_t lv_img_get_angle(lv_obj_t * obj) { LV_ASSERT_OBJ(obj, MY_CLASS); - lv_img_t * img = (lv_img_t *)obj; + lv_img_t * img = (lv_img_t *)obj; return img->angle; } @@ -345,7 +345,7 @@ void lv_img_get_pivot(lv_obj_t * obj, lv_point_t * pivot) { LV_ASSERT_OBJ(obj, MY_CLASS); - lv_img_t * img = (lv_img_t *)obj; + lv_img_t * img = (lv_img_t *)obj; *pivot = img->pivot; } @@ -354,7 +354,7 @@ uint16_t lv_img_get_zoom(lv_obj_t * obj) { LV_ASSERT_OBJ(obj, MY_CLASS); - lv_img_t * img = (lv_img_t *)obj; + lv_img_t * img = (lv_img_t *)obj; return img->zoom; } @@ -363,7 +363,7 @@ bool lv_img_get_antialias(lv_obj_t * obj) { LV_ASSERT_OBJ(obj, MY_CLASS); - lv_img_t * img = (lv_img_t *)obj; + lv_img_t * img = (lv_img_t *)obj; return img->antialias ? true : false; } @@ -411,13 +411,13 @@ static void lv_img_destructor(const lv_obj_class_t * class_p, lv_obj_t * obj) LV_UNUSED(class_p); lv_img_t * img = (lv_img_t *)obj; if(img->src_type == LV_IMG_SRC_FILE || img->src_type == LV_IMG_SRC_SYMBOL) { - lv_mem_free((void*)img->src); + lv_mem_free((void *)img->src); img->src = NULL; img->src_type = LV_IMG_SRC_UNKNOWN; } } -static lv_point_t lv_img_get_transformed_size(lv_obj_t* obj) +static lv_point_t lv_img_get_transformed_size(lv_obj_t * obj) { lv_img_t * img = (lv_img_t *)obj; @@ -427,10 +427,12 @@ static lv_point_t lv_img_get_transformed_size(lv_obj_t* obj) angle_final += img->angle; lv_area_t area_transform; - _lv_img_buf_get_transformed_area(&area_transform, img->w, img->h , - angle_final, zoom_final, &img->pivot); + _lv_img_buf_get_transformed_area(&area_transform, img->w, img->h, + angle_final, zoom_final, &img->pivot); - return (lv_point_t){lv_area_get_width(&area_transform), lv_area_get_height(&area_transform)}; + return (lv_point_t) { + lv_area_get_width(&area_transform), lv_area_get_height(&area_transform) + }; } static void lv_img_event(const lv_obj_class_t * class_p, lv_event_t * e) @@ -453,7 +455,8 @@ static void lv_img_event(const lv_obj_class_t * class_p, lv_event_t * e) /*Refresh the file name to refresh the symbol text size*/ if(img->src_type == LV_IMG_SRC_SYMBOL) { lv_img_set_src(obj, img->src); - } else { + } + else { /*With transformation it might change*/ lv_obj_refresh_ext_draw_size(obj); } @@ -491,7 +494,7 @@ static void lv_img_event(const lv_obj_class_t * class_p, lv_event_t * e) /*If the object is exactly image sized (not cropped, not mosaic) and transformed *perform hit test on its transformed area*/ if(img->w == lv_obj_get_width(obj) && img->h == lv_obj_get_height(obj) && - (zoom != LV_IMG_ZOOM_NONE || angle != 0 || img->pivot.x != img->w / 2 || img->pivot.y != img->h / 2)) { + (zoom != LV_IMG_ZOOM_NONE || angle != 0 || img->pivot.x != img->w / 2 || img->pivot.y != img->h / 2)) { lv_coord_t w = lv_obj_get_width(obj); lv_coord_t h = lv_obj_get_height(obj); @@ -512,7 +515,7 @@ static void lv_img_event(const lv_obj_class_t * class_p, lv_event_t * e) } else if(code == LV_EVENT_GET_SELF_SIZE) { lv_point_t * p = lv_event_get_param(e); - if (img->obj_size_mode == LV_IMG_SIZE_MODE_REAL){ + if(img->obj_size_mode == LV_IMG_SIZE_MODE_REAL) { *p = lv_img_get_transformed_size(obj); } else { @@ -604,13 +607,13 @@ static void draw_img(lv_event_t * e) bg_pivot.y = img->pivot.y + ptop; lv_area_t bg_coords; - if (img->obj_size_mode == LV_IMG_SIZE_MODE_REAL) { + if(img->obj_size_mode == LV_IMG_SIZE_MODE_REAL) { /*Object size equals to transformed image size*/ lv_obj_get_coords(obj, &bg_coords); } else { _lv_img_buf_get_transformed_area(&bg_coords, obj_w, obj_h, - angle_final, zoom_final, &bg_pivot); + angle_final, zoom_final, &bg_pivot); /*Modify the coordinates to draw the background for the rotated and scaled coordinates*/ bg_coords.x1 += obj->coords.x1; @@ -639,7 +642,7 @@ static void draw_img(lv_event_t * e) lv_point_t img_size_final = lv_img_get_transformed_size(obj); - if(img->obj_size_mode == LV_IMG_SIZE_MODE_REAL){ + if(img->obj_size_mode == LV_IMG_SIZE_MODE_REAL) { img_max_area.x1 -= ((img->w - img_size_final.x) + 1) / 2; img_max_area.x2 -= ((img->w - img_size_final.x) + 1) / 2; img_max_area.y1 -= ((img->h - img_size_final.y) + 1) / 2; diff --git a/src/widgets/lv_label.c b/src/widgets/lv_label.c index b7c11cda8..800acd1d4 100644 --- a/src/widgets/lv_label.c +++ b/src/widgets/lv_label.c @@ -359,7 +359,7 @@ void lv_label_get_letter_pos(const lv_obj_t * obj, uint32_t char_id, lv_point_t bool is_rtl; uint32_t visual_char_pos = _lv_bidi_get_visual_pos(&txt[line_start], &mutable_bidi_txt, new_line_start - line_start, - lv_obj_get_style_base_dir(obj, LV_PART_MAIN), line_char_id, &is_rtl); + lv_obj_get_style_base_dir(obj, LV_PART_MAIN), line_char_id, &is_rtl); bidi_txt = mutable_bidi_txt; if(is_rtl) visual_char_pos++; @@ -510,7 +510,7 @@ uint32_t lv_label_get_letter_on(const lv_obj_t * obj, lv_point_t * pos_in) txt_len, lv_obj_get_style_base_dir(obj, LV_PART_MAIN), cid, &is_rtl); if(is_rtl) logical_pos++; } - lv_mem_buf_release(bidi_txt); + lv_mem_buf_release(bidi_txt); #else logical_pos = _lv_txt_encoded_get_char_id(bidi_txt, i); #endif @@ -526,7 +526,7 @@ bool lv_label_is_char_under_pos(const lv_obj_t * obj, lv_point_t * pos) lv_area_t txt_coords; lv_obj_get_content_coords(obj, &txt_coords); const char * txt = lv_label_get_text(obj); - lv_label_t * label = (lv_label_t*)obj; + lv_label_t * label = (lv_label_t *)obj; uint32_t line_start = 0; uint32_t new_line_start = 0; lv_coord_t max_w = lv_area_get_width(&txt_coords); @@ -824,7 +824,7 @@ static void draw_main(lv_event_t * e) (label_draw_dsc.align == LV_TEXT_ALIGN_CENTER || label_draw_dsc.align == LV_TEXT_ALIGN_RIGHT)) { lv_point_t size; lv_txt_get_size(&size, label->text, label_draw_dsc.font, label_draw_dsc.letter_space, label_draw_dsc.line_space, - LV_COORD_MAX, flag); + LV_COORD_MAX, flag); if(size.x > lv_area_get_width(&txt_coords)) { label_draw_dsc.align = LV_TEXT_ALIGN_LEFT; } @@ -854,7 +854,7 @@ static void draw_main(lv_event_t * e) if(label->long_mode == LV_LABEL_LONG_SCROLL_CIRCULAR) { lv_point_t size; lv_txt_get_size(&size, label->text, label_draw_dsc.font, label_draw_dsc.letter_space, label_draw_dsc.line_space, - LV_COORD_MAX, flag); + LV_COORD_MAX, flag); /*Draw the text again on label to the original to make a circular effect */ if(size.x > lv_area_get_width(&txt_coords)) { @@ -922,7 +922,7 @@ static void lv_label_refr_text(lv_obj_t * obj) int32_t start, end; lv_base_dir_t base_dir = lv_obj_get_style_base_dir(obj, LV_PART_MAIN); - if (base_dir == LV_BASE_DIR_AUTO) + if(base_dir == LV_BASE_DIR_AUTO) base_dir = _lv_bidi_detect_base_dir(label->text); if(base_dir == LV_BASE_DIR_RTL) { @@ -1021,7 +1021,7 @@ static void lv_label_refr_text(lv_obj_t * obj) int32_t start, end; lv_base_dir_t base_dir = lv_obj_get_style_base_dir(obj, LV_PART_MAIN); - if (base_dir == LV_BASE_DIR_AUTO) + if(base_dir == LV_BASE_DIR_AUTO) base_dir = _lv_bidi_detect_base_dir(label->text); if(base_dir == LV_BASE_DIR_RTL) { diff --git a/src/widgets/lv_label.h b/src/widgets/lv_label.h index 74decde95..b9a0e5013 100644 --- a/src/widgets/lv_label.h +++ b/src/widgets/lv_label.h @@ -64,7 +64,8 @@ typedef struct { #endif #if LV_LABEL_TEXT_SELECTION - uint32_t sel_start; uint32_t sel_end; + uint32_t sel_start; + uint32_t sel_end; #endif lv_point_t offset; /*Text draw position offset*/ @@ -73,7 +74,7 @@ typedef struct { uint8_t recolor : 1; /*Enable in-line letter re-coloring*/ uint8_t expand : 1; /*Ignore real width (used by the library with LV_LABEL_LONG_SROLL)*/ uint8_t dot_tmp_alloc : 1; /*1: dot_tmp has been allocated;.0: dot_tmp directly holds up to 4 bytes of characters*/ -}lv_label_t; +} lv_label_t; extern const lv_obj_class_t lv_label_class; diff --git a/src/widgets/lv_line.c b/src/widgets/lv_line.c index 6fd297740..e73e6e89e 100644 --- a/src/widgets/lv_line.c +++ b/src/widgets/lv_line.c @@ -159,7 +159,8 @@ static void lv_line_event(const lv_obj_class_t * class_p, lv_event_t * e) p->x = w; p->y = h; } - } else if(code == LV_EVENT_DRAW_MAIN) { + } + else if(code == LV_EVENT_DRAW_MAIN) { lv_line_t * line = (lv_line_t *)obj; const lv_area_t * clip_area = lv_event_get_param(e); diff --git a/src/widgets/lv_roller.c b/src/widgets/lv_roller.c index f8c0354dc..fa558782d 100644 --- a/src/widgets/lv_roller.c +++ b/src/widgets/lv_roller.c @@ -46,21 +46,21 @@ static void set_y_anim(void * obj, int32_t v); * STATIC VARIABLES **********************/ const lv_obj_class_t lv_roller_class = { - .constructor_cb = lv_roller_constructor, - .event_cb = lv_roller_event, - .width_def = LV_SIZE_CONTENT, - .height_def = LV_DPI_DEF, - .instance_size = sizeof(lv_roller_t), - .editable = LV_OBJ_CLASS_EDITABLE_TRUE, - .group_def = LV_OBJ_CLASS_GROUP_DEF_TRUE, - .base_class = &lv_obj_class + .constructor_cb = lv_roller_constructor, + .event_cb = lv_roller_event, + .width_def = LV_SIZE_CONTENT, + .height_def = LV_DPI_DEF, + .instance_size = sizeof(lv_roller_t), + .editable = LV_OBJ_CLASS_EDITABLE_TRUE, + .group_def = LV_OBJ_CLASS_GROUP_DEF_TRUE, + .base_class = &lv_obj_class }; const lv_obj_class_t lv_roller_label_class = { - .event_cb = lv_roller_label_event, - .instance_size = sizeof(lv_label_t), - .base_class = &lv_label_class - }; + .event_cb = lv_roller_label_event, + .instance_size = sizeof(lv_label_t), + .base_class = &lv_label_class +}; /********************** * MACROS @@ -98,7 +98,7 @@ void lv_roller_set_options(lv_obj_t * obj, const char * options, lv_roller_mode_ LV_ASSERT_OBJ(obj, MY_CLASS); LV_ASSERT_NULL(options); - lv_roller_t * roller = (lv_roller_t*)obj; + lv_roller_t * roller = (lv_roller_t *)obj; lv_obj_t * label = get_label(obj); roller->sel_opt_id = 0; @@ -157,7 +157,7 @@ void lv_roller_set_selected(lv_obj_t * obj, uint16_t sel_opt, lv_anim_enable_t a *if moving to the next option with an animation which was just deleted in the PRESS Call the ancestor's event handler *nothing will continue the animation.*/ - lv_roller_t * roller = (lv_roller_t*)obj; + lv_roller_t * roller = (lv_roller_t *)obj; /*In infinite mode interpret the new ID relative to the currently visible "page"*/ if(roller->mode == LV_ROLLER_MODE_INFINITE) { @@ -208,7 +208,7 @@ uint16_t lv_roller_get_selected(const lv_obj_t * obj) { LV_ASSERT_OBJ(obj, MY_CLASS); - lv_roller_t * roller = (lv_roller_t*)obj; + lv_roller_t * roller = (lv_roller_t *)obj; if(roller->mode == LV_ROLLER_MODE_INFINITE) { uint16_t real_id_cnt = roller->option_cnt / LV_ROLLER_INF_PAGES; return roller->sel_opt_id % real_id_cnt; @@ -228,7 +228,7 @@ void lv_roller_get_selected_str(const lv_obj_t * obj, char * buf, uint32_t buf_s { LV_ASSERT_OBJ(obj, MY_CLASS); - lv_roller_t * roller = (lv_roller_t*)obj; + lv_roller_t * roller = (lv_roller_t *)obj; lv_obj_t * label = get_label(obj); uint32_t i; uint16_t line = 0; @@ -274,7 +274,7 @@ uint16_t lv_roller_get_option_cnt(const lv_obj_t * obj) { LV_ASSERT_OBJ(obj, MY_CLASS); - lv_roller_t * roller = (lv_roller_t*)obj; + lv_roller_t * roller = (lv_roller_t *)obj; if(roller->mode == LV_ROLLER_MODE_INFINITE) { return roller->option_cnt / LV_ROLLER_INF_PAGES; } @@ -291,7 +291,7 @@ uint16_t lv_roller_get_option_cnt(const lv_obj_t * obj) static void lv_roller_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj) { LV_UNUSED(class_p); - lv_roller_t * roller = (lv_roller_t*)obj; + lv_roller_t * roller = (lv_roller_t *)obj; roller->mode = LV_ROLLER_MODE_NORMAL; roller->option_cnt = 0; @@ -321,7 +321,7 @@ static void lv_roller_event(const lv_obj_class_t * class_p, lv_event_t * e) lv_event_code_t code = lv_event_get_code(e); lv_obj_t * obj = lv_event_get_target(e); - lv_roller_t * roller = (lv_roller_t*)obj; + lv_roller_t * roller = (lv_roller_t *)obj; if(code == LV_EVENT_GET_SELF_SIZE) { lv_point_t * p = lv_event_get_param(e); @@ -478,12 +478,12 @@ static void draw_main(lv_event_t * e) /*Get the size of the "selected text"*/ lv_point_t res_p; lv_txt_get_size(&res_p, lv_label_get_text(label), label_dsc.font, label_dsc.letter_space, label_dsc.line_space, - lv_obj_get_width(obj), LV_TEXT_FLAG_EXPAND); + lv_obj_get_width(obj), LV_TEXT_FLAG_EXPAND); /*Move the selected label proportionally with the background label*/ lv_coord_t roller_h = lv_obj_get_height(obj); int32_t label_y_prop = label->coords.y1 - (roller_h / 2 + - obj->coords.y1); /*label offset from the middle line of the roller*/ + obj->coords.y1); /*label offset from the middle line of the roller*/ label_y_prop = (label_y_prop * 16384) / lv_obj_get_height( label); /*Proportional position from the middle line (upscaled by << 14)*/ @@ -578,18 +578,18 @@ static void refr_position(lv_obj_t * obj, lv_anim_enable_t anim_en) lv_text_align_t align = lv_obj_calculate_style_text_align(label, LV_PART_MAIN, lv_label_get_text(label)); switch(align) { - case LV_TEXT_ALIGN_CENTER: - lv_obj_set_x(label, (lv_obj_get_content_width(obj) - lv_obj_get_width(label)) / 2); - break; - case LV_TEXT_ALIGN_RIGHT: - lv_obj_set_x(label, lv_obj_get_content_width(obj) - lv_obj_get_width(label)); - break; - case LV_TEXT_ALIGN_LEFT: - lv_obj_set_x(label, 0); - break; + case LV_TEXT_ALIGN_CENTER: + lv_obj_set_x(label, (lv_obj_get_content_width(obj) - lv_obj_get_width(label)) / 2); + break; + case LV_TEXT_ALIGN_RIGHT: + lv_obj_set_x(label, lv_obj_get_content_width(obj) - lv_obj_get_width(label)); + break; + case LV_TEXT_ALIGN_LEFT: + lv_obj_set_x(label, 0); + break; } - lv_roller_t * roller = (lv_roller_t*)obj; + lv_roller_t * roller = (lv_roller_t *)obj; const lv_font_t * font = lv_obj_get_style_text_font(obj, LV_PART_MAIN); lv_coord_t line_space = lv_obj_get_style_text_line_space(obj, LV_PART_MAIN); lv_coord_t font_h = lv_font_get_line_height(font); @@ -631,7 +631,7 @@ static lv_res_t release_handler(lv_obj_t * obj) if(label == NULL) return LV_RES_OK; lv_indev_t * indev = lv_indev_get_act(); - lv_roller_t * roller = (lv_roller_t*)obj; + lv_roller_t * roller = (lv_roller_t *)obj; /*Leave edit mode once a new option is selected*/ lv_indev_type_t indev_type = lv_indev_get_type(indev); @@ -670,7 +670,8 @@ static lv_res_t release_handler(lv_obj_t * obj) if(letter == '\n' && i_prev != letter_i) new_opt++; i_prev = i; } - } else { + } + else { /*If dragged then align the list to have an element in the middle*/ const lv_font_t * font = lv_obj_get_style_text_font(obj, LV_PART_MAIN); lv_coord_t line_space = lv_obj_get_style_text_line_space(obj, LV_PART_MAIN); @@ -703,7 +704,7 @@ static lv_res_t release_handler(lv_obj_t * obj) */ static void inf_normalize(lv_obj_t * obj) { - lv_roller_t * roller = (lv_roller_t*)obj; + lv_roller_t * roller = (lv_roller_t *)obj; if(roller->mode == LV_ROLLER_MODE_INFINITE) { uint16_t real_id_cnt = roller->option_cnt / LV_ROLLER_INF_PAGES; diff --git a/src/widgets/lv_roller.h b/src/widgets/lv_roller.h index 24202734b..1520c4a57 100644 --- a/src/widgets/lv_roller.h +++ b/src/widgets/lv_roller.h @@ -37,13 +37,13 @@ enum { typedef uint8_t lv_roller_mode_t; typedef struct { - lv_obj_t obj; - uint16_t option_cnt; /**< Number of options*/ - uint16_t sel_opt_id; /**< Index of the current option*/ - uint16_t sel_opt_id_ori; /**< Store the original index on focus*/ - lv_roller_mode_t mode : 1; - uint32_t moved : 1; -}lv_roller_t; + lv_obj_t obj; + uint16_t option_cnt; /**< Number of options*/ + uint16_t sel_opt_id; /**< Index of the current option*/ + uint16_t sel_opt_id_ori; /**< Store the original index on focus*/ + lv_roller_mode_t mode : 1; + uint32_t moved : 1; +} lv_roller_t; extern const lv_obj_class_t lv_roller_class; diff --git a/src/widgets/lv_slider.c b/src/widgets/lv_slider.c index 24d48114a..79b43719f 100644 --- a/src/widgets/lv_slider.c +++ b/src/widgets/lv_slider.c @@ -134,11 +134,11 @@ static void lv_slider_event(const lv_obj_class_t * class_p, lv_event_t * e) lv_coord_t dist_left, dist_right; if(hor) { if((base_dir != LV_BASE_DIR_RTL && p.x > slider->right_knob_area.x2) || (base_dir == LV_BASE_DIR_RTL && - p.x < slider->right_knob_area.x1)) { + p.x < slider->right_knob_area.x1)) { slider->value_to_set = &slider->bar.cur_value; } else if((base_dir != LV_BASE_DIR_RTL && p.x < slider->left_knob_area.x1) || (base_dir == LV_BASE_DIR_RTL && - p.x > slider->left_knob_area.x2)) { + p.x > slider->left_knob_area.x2)) { slider->value_to_set = &slider->bar.start_value; } else { @@ -277,7 +277,7 @@ static void lv_slider_event(const lv_obj_class_t * class_p, lv_event_t * e) } else if(code == LV_EVENT_REFR_EXT_DRAW_SIZE) { lv_coord_t knob_left = lv_obj_get_style_pad_left(obj, LV_PART_KNOB); - lv_coord_t knob_right = lv_obj_get_style_pad_right(obj,LV_PART_KNOB); + lv_coord_t knob_right = lv_obj_get_style_pad_right(obj, LV_PART_KNOB); lv_coord_t knob_top = lv_obj_get_style_pad_top(obj, LV_PART_KNOB); lv_coord_t knob_bottom = lv_obj_get_style_pad_bottom(obj, LV_PART_KNOB); @@ -313,7 +313,8 @@ static void lv_slider_event(const lv_obj_class_t * class_p, lv_event_t * e) res = lv_event_send(obj, LV_EVENT_VALUE_CHANGED, NULL); if(res != LV_RES_OK) return; } - } else if(code == LV_EVENT_DRAW_MAIN) { + } + else if(code == LV_EVENT_DRAW_MAIN) { draw_knob(e); } } @@ -383,7 +384,8 @@ static void draw_knob(lv_event_t * e) lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &part_draw_dsc); lv_draw_rect(&slider->right_knob_area, clip_area, &knob_rect_dsc); lv_event_send(obj, LV_EVENT_DRAW_PART_END, &part_draw_dsc); - } else { + } + else { /*Save the draw part_draw_dsc. because it can be modified in the event*/ lv_draw_rect_dsc_t knob_rect_dsc_tmp; lv_memcpy(&knob_rect_dsc_tmp, &knob_rect_dsc, sizeof(lv_draw_rect_dsc_t)); diff --git a/src/widgets/lv_slider.h b/src/widgets/lv_slider.h index c845c8923..28b7543db 100644 --- a/src/widgets/lv_slider.h +++ b/src/widgets/lv_slider.h @@ -47,7 +47,7 @@ typedef struct { int32_t * value_to_set; /*Which bar value to set*/ uint8_t dragging : 1; /*1: the slider is being dragged*/ uint8_t left_knob_focus : 1; /*1: with encoder now the right knob can be adjusted*/ -}lv_slider_t; +} lv_slider_t; extern const lv_obj_class_t lv_slider_class; @@ -58,7 +58,7 @@ extern const lv_obj_class_t lv_slider_class; typedef enum { LV_SLIDER_DRAW_PART_KNOB, /**< The main (right) knob's rectangle*/ LV_SLIDER_DRAW_PART_KNOB_LEFT, /**< The left knob's rectangle*/ -}lv_slider_draw_part_type_t; +} lv_slider_draw_part_type_t; /********************** * GLOBAL PROTOTYPES diff --git a/src/widgets/lv_switch.c b/src/widgets/lv_switch.c index b90b86f6d..7bc89512c 100644 --- a/src/widgets/lv_switch.c +++ b/src/widgets/lv_switch.c @@ -55,7 +55,7 @@ const lv_obj_class_t lv_switch_class = { .constructor_cb = lv_switch_constructor, .destructor_cb = lv_switch_destructor, .event_cb = lv_switch_event, - .width_def = (4 * LV_DPI_DEF) / 10, + .width_def = (4 * LV_DPI_DEF) / 10, .height_def = (4 * LV_DPI_DEF) / 17, .group_def = LV_OBJ_CLASS_GROUP_DEF_TRUE, .instance_size = sizeof(lv_switch_t), @@ -247,7 +247,7 @@ static void lv_switch_trigger_anim(lv_obj_t * obj) uint32_t anim_dur_full = lv_obj_get_style_anim_time(obj, LV_PART_MAIN); - if(anim_dur_full>0) { + if(anim_dur_full > 0) { bool chk = lv_obj_get_state(obj) & LV_STATE_CHECKED; int32_t anim_start; int32_t anim_end; @@ -262,7 +262,7 @@ static void lv_switch_trigger_anim(lv_obj_t * obj) anim_end = chk ? LV_SWITCH_ANIM_STATE_END : LV_SWITCH_ANIM_STATE_START; } /*Calculate actual animation duration*/ - uint32_t anim_dur = (anim_dur_full * LV_ABS(anim_start - anim_end))/LV_SWITCH_ANIM_STATE_END; + uint32_t anim_dur = (anim_dur_full * LV_ABS(anim_start - anim_end)) / LV_SWITCH_ANIM_STATE_END; /*Stop the previous animation if it exists*/ lv_anim_del(sw, NULL); diff --git a/src/widgets/lv_switch.h b/src/widgets/lv_switch.h index cb7328b6d..7d573f2af 100644 --- a/src/widgets/lv_switch.h +++ b/src/widgets/lv_switch.h @@ -30,7 +30,7 @@ extern "C" { typedef struct { lv_obj_t obj; int32_t anim_state; -}lv_switch_t; +} lv_switch_t; extern const lv_obj_class_t lv_switch_class; diff --git a/src/widgets/lv_table.c b/src/widgets/lv_table.c index ebde389f0..5b5e4e557 100644 --- a/src/widgets/lv_table.c +++ b/src/widgets/lv_table.c @@ -131,7 +131,7 @@ void lv_table_set_cell_value_fmt(lv_obj_t * obj, uint16_t row, uint16_t col, con lv_table_cell_ctrl_t ctrl = 0; /*Save the control byte*/ - if(table->cell_data[cell]) ctrl= table->cell_data[cell][0]; + if(table->cell_data[cell]) ctrl = table->cell_data[cell][0]; va_list ap, ap2; va_start(ap, fmt); @@ -191,7 +191,7 @@ void lv_table_set_cell_value_fmt(lv_obj_t * obj, uint16_t row, uint16_t col, con const lv_font_t * font = lv_obj_get_style_text_font(obj, LV_PART_ITEMS); lv_coord_t h = get_row_height(obj, row, font, letter_space, line_space, - cell_left, cell_right, cell_top, cell_bottom); + cell_left, cell_right, cell_top, cell_bottom); lv_coord_t minh = lv_obj_get_style_min_height(obj, LV_PART_ITEMS); @@ -251,13 +251,13 @@ void lv_table_set_col_cnt(lv_obj_t * obj, uint16_t col_cnt) /*Free the unused cells*/ if(old_col_cnt > col_cnt) { - uint16_t old_cell_cnt = old_col_cnt * table->row_cnt; - uint32_t new_cell_cnt = table->col_cnt * table->row_cnt; - uint32_t i; - for(i = new_cell_cnt; i < old_cell_cnt; i++) { - lv_mem_free(table->cell_data[i]); - } - } + uint16_t old_cell_cnt = old_col_cnt * table->row_cnt; + uint32_t new_cell_cnt = table->col_cnt * table->row_cnt; + uint32_t i; + for(i = new_cell_cnt; i < old_cell_cnt; i++) { + lv_mem_free(table->cell_data[i]); + } + } char ** new_cell_data = lv_mem_alloc(table->row_cnt * table->col_cnt * sizeof(char *)); LV_ASSERT_MALLOC(new_cell_data); @@ -282,7 +282,8 @@ void lv_table_set_col_cnt(lv_obj_t * obj, uint16_t col_cnt) old_col_start = row * old_col_cnt; new_col_start = row * col_cnt; - lv_memcpy_small(&new_cell_data[new_col_start], &table->cell_data[old_col_start], sizeof(new_cell_data[0]) * min_col_cnt); + lv_memcpy_small(&new_cell_data[new_col_start], &table->cell_data[old_col_start], + sizeof(new_cell_data[0]) * min_col_cnt); } lv_mem_free(table->cell_data); @@ -522,7 +523,8 @@ static void lv_table_event(const lv_obj_class_t * class_p, lv_event_t * e) } else if(code == LV_EVENT_FOCUSED) { lv_obj_invalidate(obj); - } else if(code == LV_EVENT_KEY) { + } + else if(code == LV_EVENT_KEY) { int32_t c = *((int32_t *)lv_event_get_param(e)); int32_t col = table->col_act; int32_t row = table->row_act; @@ -546,21 +548,25 @@ static void lv_table_event(const lv_obj_class_t * class_p, lv_event_t * e) if(row < table->row_cnt - 1) { col = 0; row++; - } else { + } + else { col = table->col_cnt - 1; } - } else if (col < 0) { + } + else if(col < 0) { if(row != 0) { col = table->col_cnt - 1; row--; - } else { + } + else { col = 0; } } if(row >= table->row_cnt) { row = table->row_cnt - 1; - } else if(row < 0) { + } + else if(row < 0) { row = 0; } @@ -572,7 +578,8 @@ static void lv_table_event(const lv_obj_class_t * class_p, lv_event_t * e) res = lv_event_send(obj, LV_EVENT_VALUE_CHANGED, NULL); if(res != LV_RES_OK) return; } - } else if(code == LV_EVENT_DRAW_MAIN) { + } + else if(code == LV_EVENT_DRAW_MAIN) { draw_main(e); } } @@ -694,7 +701,7 @@ static void draw_main(lv_event_t * e) cell_area_border.x2 += rect_dsc_def.border_width / 2 + (rect_dsc_def.border_width & 0x1); } if((rect_dsc_def.border_side & LV_BORDER_SIDE_BOTTOM) && - cell_area_border.y2 < obj->coords.y2 - bg_bottom - 1) { + cell_area_border.y2 < obj->coords.y2 - bg_bottom - 1) { cell_area_border.y2 += rect_dsc_def.border_width / 2 + (rect_dsc_def.border_width & 0x1); } @@ -741,8 +748,8 @@ static void draw_main(lv_event_t * e) else txt_flags = LV_TEXT_FLAG_NONE; lv_txt_get_size(&txt_size, table->cell_data[cell] + 1, label_dsc_def.font, - label_dsc_act.letter_space, label_dsc_act.line_space, - lv_area_get_width(&txt_area), txt_flags); + label_dsc_act.letter_space, label_dsc_act.line_space, + lv_area_get_width(&txt_area), txt_flags); /*Align the content to the middle if not cropped*/ if(!crop) { @@ -786,7 +793,7 @@ static void refr_size(lv_obj_t * obj, uint32_t strat_row) for(i = strat_row; i < table->row_cnt; i++) { table->row_h[i] = get_row_height(obj, i, font, letter_space, line_space, - cell_left, cell_right, cell_top, cell_bottom); + cell_left, cell_right, cell_top, cell_bottom); table->row_h[i] = LV_CLAMP(minh, table->row_h[i], maxh); } @@ -832,14 +839,14 @@ static lv_coord_t get_row_height(lv_obj_t * obj, uint16_t row_id, const lv_font_ /*With text crop assume 1 line*/ if(ctrl & LV_TABLE_CELL_CTRL_TEXT_CROP) { h_max = LV_MAX(lv_font_get_line_height(font) + cell_top + cell_bottom, - h_max); + h_max); } /*Without text crop calculate the height of the text in the cell*/ else { txt_w -= cell_left + cell_right; lv_txt_get_size(&txt_size, table->cell_data[cell] + 1, font, - letter_space, line_space, txt_w, LV_TEXT_FLAG_NONE); + letter_space, line_space, txt_w, LV_TEXT_FLAG_NONE); h_max = LV_MAX(txt_size.y + cell_top + cell_bottom, h_max); cell += col_merge; @@ -853,7 +860,7 @@ static lv_coord_t get_row_height(lv_obj_t * obj, uint16_t row_id, const lv_font_ static lv_res_t get_pressed_cell(lv_obj_t * obj, uint16_t * row, uint16_t * col) { - lv_table_t * table = (lv_table_t *)obj; + lv_table_t * table = (lv_table_t *)obj; lv_indev_type_t type = lv_indev_get_type(lv_indev_get_act()); if(type != LV_INDEV_TYPE_POINTER && type != LV_INDEV_TYPE_BUTTON) { diff --git a/src/widgets/lv_table.h b/src/widgets/lv_table.h index bd7611946..910627087 100644 --- a/src/widgets/lv_table.h +++ b/src/widgets/lv_table.h @@ -66,7 +66,7 @@ extern const lv_obj_class_t lv_table_class; */ typedef enum { LV_TABLE_DRAW_PART_CELL, /**< A cell*/ -}lv_table_draw_part_type_t; +} lv_table_draw_part_type_t; /********************** * GLOBAL PROTOTYPES diff --git a/src/widgets/lv_textarea.c b/src/widgets/lv_textarea.c index 64a8610c8..a4ae81eb5 100644 --- a/src/widgets/lv_textarea.c +++ b/src/widgets/lv_textarea.c @@ -97,7 +97,7 @@ void lv_textarea_add_char(lv_obj_t * obj, uint32_t c) { LV_ASSERT_OBJ(obj, MY_CLASS); - lv_textarea_t * ta = (lv_textarea_t *)obj; + lv_textarea_t * ta = (lv_textarea_t *)obj; const char * letter_buf; @@ -172,7 +172,7 @@ void lv_textarea_add_text(lv_obj_t * obj, const char * txt) LV_ASSERT_OBJ(obj, MY_CLASS); LV_ASSERT_NULL(txt); - lv_textarea_t * ta = (lv_textarea_t *)obj; + lv_textarea_t * ta = (lv_textarea_t *)obj; if(ta->pwd_mode != 0) pwd_char_hider(obj); /*Make sure all the current text contains only '*'*/ @@ -233,7 +233,7 @@ void lv_textarea_del_char(lv_obj_t * obj) { LV_ASSERT_OBJ(obj, MY_CLASS); - lv_textarea_t * ta = (lv_textarea_t *)obj; + lv_textarea_t * ta = (lv_textarea_t *)obj; uint32_t cur_pos = ta->cursor.pos; if(cur_pos == 0) return; @@ -292,7 +292,7 @@ void lv_textarea_set_text(lv_obj_t * obj, const char * txt) LV_ASSERT_OBJ(obj, MY_CLASS); LV_ASSERT_NULL(txt); - lv_textarea_t * ta = (lv_textarea_t *)obj; + lv_textarea_t * ta = (lv_textarea_t *)obj; /*Clear the existing selection*/ lv_textarea_clear_selection(obj); @@ -352,7 +352,7 @@ void lv_textarea_set_placeholder_text(lv_obj_t * obj, const char * txt) LV_ASSERT_OBJ(obj, MY_CLASS); LV_ASSERT_NULL(txt); - lv_textarea_t * ta = (lv_textarea_t *)obj; + lv_textarea_t * ta = (lv_textarea_t *)obj; size_t txt_len = strlen(txt); @@ -387,7 +387,7 @@ void lv_textarea_set_cursor_pos(lv_obj_t * obj, int32_t pos) { LV_ASSERT_OBJ(obj, MY_CLASS); - lv_textarea_t * ta = (lv_textarea_t *)obj; + lv_textarea_t * ta = (lv_textarea_t *)obj; if((uint32_t)ta->cursor.pos == (uint32_t)pos) return; uint32_t len = _lv_txt_get_encoded_length(lv_label_get_text(ta->label)); @@ -399,27 +399,27 @@ void lv_textarea_set_cursor_pos(lv_obj_t * obj, int32_t pos) ta->cursor.pos = pos; /*Position the label to make the cursor visible*/ - lv_point_t cur_pos; - const lv_font_t * font = lv_obj_get_style_text_font(obj, LV_PART_MAIN); - lv_area_t label_cords; - lv_area_t ta_cords; - lv_label_get_letter_pos(ta->label, pos, &cur_pos); - lv_obj_get_coords(obj, &ta_cords); - lv_obj_get_coords(ta->label, &label_cords); + lv_point_t cur_pos; + const lv_font_t * font = lv_obj_get_style_text_font(obj, LV_PART_MAIN); + lv_area_t label_cords; + lv_area_t ta_cords; + lv_label_get_letter_pos(ta->label, pos, &cur_pos); + lv_obj_get_coords(obj, &ta_cords); + lv_obj_get_coords(ta->label, &label_cords); - /*The text area needs to have it's final size to see if the cursor is out of the area or not*/ - lv_obj_update_layout(obj); + /*The text area needs to have it's final size to see if the cursor is out of the area or not*/ + lv_obj_update_layout(obj); - /*Check the top*/ - lv_coord_t font_h = lv_font_get_line_height(font); - if(cur_pos.y < lv_obj_get_scroll_top(obj)) { - lv_obj_scroll_to_y(obj, cur_pos.y, LV_ANIM_ON); - } - /*Check the bottom*/ - lv_coord_t h = lv_obj_get_content_height(obj); - if(cur_pos.y + font_h - lv_obj_get_scroll_top(obj) > h) { - lv_obj_scroll_to_y(obj, cur_pos.y - h + font_h, LV_ANIM_ON); - } + /*Check the top*/ + lv_coord_t font_h = lv_font_get_line_height(font); + if(cur_pos.y < lv_obj_get_scroll_top(obj)) { + lv_obj_scroll_to_y(obj, cur_pos.y, LV_ANIM_ON); + } + /*Check the bottom*/ + lv_coord_t h = lv_obj_get_content_height(obj); + if(cur_pos.y + font_h - lv_obj_get_scroll_top(obj) > h) { + lv_obj_scroll_to_y(obj, cur_pos.y - h + font_h, LV_ANIM_ON); + } /*Check the left*/ if(cur_pos.x < lv_obj_get_scroll_left(obj)) { @@ -450,7 +450,7 @@ void lv_textarea_set_password_mode(lv_obj_t * obj, bool en) { LV_ASSERT_OBJ(obj, MY_CLASS); - lv_textarea_t * ta = (lv_textarea_t *)obj; + lv_textarea_t * ta = (lv_textarea_t *)obj; if(ta->pwd_mode == en) return; ta->pwd_mode = en == false ? 0 : 1; @@ -483,7 +483,7 @@ void lv_textarea_set_one_line(lv_obj_t * obj, bool en) { LV_ASSERT_OBJ(obj, MY_CLASS); - lv_textarea_t * ta = (lv_textarea_t *)obj; + lv_textarea_t * ta = (lv_textarea_t *)obj; if(ta->one_line == en) return; if(en) { @@ -505,7 +505,7 @@ void lv_textarea_set_accepted_chars(lv_obj_t * obj, const char * list) { LV_ASSERT_OBJ(obj, MY_CLASS); - lv_textarea_t * ta = (lv_textarea_t *)obj; + lv_textarea_t * ta = (lv_textarea_t *)obj; ta->accepted_chars = list; } @@ -514,7 +514,7 @@ void lv_textarea_set_max_length(lv_obj_t * obj, uint32_t num) { LV_ASSERT_OBJ(obj, MY_CLASS); - lv_textarea_t * ta = (lv_textarea_t *)obj; + lv_textarea_t * ta = (lv_textarea_t *)obj; ta->max_length = num; } @@ -532,7 +532,7 @@ void lv_textarea_set_text_selection(lv_obj_t * obj, bool en) LV_ASSERT_OBJ(obj, MY_CLASS); #if LV_LABEL_TEXT_SELECTION - lv_textarea_t * ta = (lv_textarea_t *)obj; + lv_textarea_t * ta = (lv_textarea_t *)obj; ta->text_sel_en = en; @@ -556,16 +556,16 @@ void lv_textarea_set_align(lv_obj_t * obj, lv_text_align_t align) lv_obj_set_style_text_align(obj, align, 0); switch(align) { - default: - case LV_TEXT_ALIGN_LEFT: - lv_obj_align(lv_textarea_get_label(obj), LV_ALIGN_TOP_LEFT, 0, 0); - break; - case LV_TEXT_ALIGN_RIGHT: - lv_obj_align(lv_textarea_get_label(obj), LV_ALIGN_TOP_RIGHT, 0, 0); - break; - case LV_TEXT_ALIGN_CENTER: - lv_obj_align(lv_textarea_get_label(obj), LV_ALIGN_TOP_MID, 0, 0); - break; + default: + case LV_TEXT_ALIGN_LEFT: + lv_obj_align(lv_textarea_get_label(obj), LV_ALIGN_TOP_LEFT, 0, 0); + break; + case LV_TEXT_ALIGN_RIGHT: + lv_obj_align(lv_textarea_get_label(obj), LV_ALIGN_TOP_RIGHT, 0, 0); + break; + case LV_TEXT_ALIGN_CENTER: + lv_obj_align(lv_textarea_get_label(obj), LV_ALIGN_TOP_MID, 0, 0); + break; } } @@ -577,7 +577,7 @@ const char * lv_textarea_get_text(const lv_obj_t * obj) { LV_ASSERT_OBJ(obj, MY_CLASS); - lv_textarea_t * ta = (lv_textarea_t *)obj; + lv_textarea_t * ta = (lv_textarea_t *)obj; const char * txt; if(ta->pwd_mode == 0) { @@ -594,7 +594,7 @@ const char * lv_textarea_get_placeholder_text(lv_obj_t * obj) { LV_ASSERT_OBJ(obj, MY_CLASS); - lv_textarea_t * ta = (lv_textarea_t *)obj; + lv_textarea_t * ta = (lv_textarea_t *)obj; if(ta->placeholder_txt) return ta->placeholder_txt; else return ""; } @@ -603,7 +603,7 @@ lv_obj_t * lv_textarea_get_label(const lv_obj_t * obj) { LV_ASSERT_OBJ(obj, MY_CLASS); - lv_textarea_t * ta = (lv_textarea_t *)obj; + lv_textarea_t * ta = (lv_textarea_t *)obj; return ta->label; } @@ -611,7 +611,7 @@ uint32_t lv_textarea_get_cursor_pos(const lv_obj_t * obj) { LV_ASSERT_OBJ(obj, MY_CLASS); - lv_textarea_t * ta = (lv_textarea_t *)obj; + lv_textarea_t * ta = (lv_textarea_t *)obj; return ta->cursor.pos; } @@ -619,7 +619,7 @@ bool lv_textarea_get_cursor_click_pos(lv_obj_t * obj) { LV_ASSERT_OBJ(obj, MY_CLASS); - lv_textarea_t * ta = (lv_textarea_t *)obj; + lv_textarea_t * ta = (lv_textarea_t *)obj; return ta->cursor.click_pos ? true : false; } @@ -627,7 +627,7 @@ bool lv_textarea_get_password_mode(const lv_obj_t * obj) { LV_ASSERT_OBJ(obj, MY_CLASS); - lv_textarea_t * ta = (lv_textarea_t *)obj; + lv_textarea_t * ta = (lv_textarea_t *)obj; return ta->pwd_mode == 0 ? false : true; } @@ -635,7 +635,7 @@ bool lv_textarea_get_one_line(const lv_obj_t * obj) { LV_ASSERT_OBJ(obj, MY_CLASS); - lv_textarea_t * ta = (lv_textarea_t *)obj; + lv_textarea_t * ta = (lv_textarea_t *)obj; return ta->one_line == 0 ? false : true; } @@ -643,7 +643,7 @@ const char * lv_textarea_get_accepted_chars(lv_obj_t * obj) { LV_ASSERT_OBJ(obj, MY_CLASS); - lv_textarea_t * ta = (lv_textarea_t *)obj; + lv_textarea_t * ta = (lv_textarea_t *)obj; return ta->accepted_chars; } @@ -652,7 +652,7 @@ uint32_t lv_textarea_get_max_length(lv_obj_t * obj) { LV_ASSERT_OBJ(obj, MY_CLASS); - lv_textarea_t * ta = (lv_textarea_t *)obj; + lv_textarea_t * ta = (lv_textarea_t *)obj; return ta->max_length; } @@ -661,7 +661,7 @@ bool lv_textarea_text_is_selected(const lv_obj_t * obj) LV_ASSERT_OBJ(obj, MY_CLASS); #if LV_LABEL_TEXT_SELECTION - lv_textarea_t * ta = (lv_textarea_t *)obj; + lv_textarea_t * ta = (lv_textarea_t *)obj; if((lv_label_get_text_selection_start(ta->label) != LV_DRAW_LABEL_NO_TXT_SEL || lv_label_get_text_selection_end(ta->label) != LV_DRAW_LABEL_NO_TXT_SEL)) { @@ -681,7 +681,7 @@ bool lv_textarea_get_text_selection(lv_obj_t * obj) LV_ASSERT_OBJ(obj, MY_CLASS); #if LV_LABEL_TEXT_SELECTION - lv_textarea_t * ta = (lv_textarea_t *)obj; + lv_textarea_t * ta = (lv_textarea_t *)obj; return ta->text_sel_en; #else (void)obj; /*Unused*/ @@ -693,7 +693,7 @@ uint16_t lv_textarea_get_password_show_time(lv_obj_t * obj) { LV_ASSERT_OBJ(obj, MY_CLASS); - lv_textarea_t * ta = (lv_textarea_t *)obj; + lv_textarea_t * ta = (lv_textarea_t *)obj; return ta->pwd_show_time; } @@ -707,7 +707,7 @@ void lv_textarea_clear_selection(lv_obj_t * obj) LV_ASSERT_OBJ(obj, MY_CLASS); #if LV_LABEL_TEXT_SELECTION - lv_textarea_t * ta = (lv_textarea_t *)obj; + lv_textarea_t * ta = (lv_textarea_t *)obj; if(lv_label_get_text_selection_start(ta->label) != LV_DRAW_LABEL_NO_TXT_SEL || lv_label_get_text_selection_end(ta->label) != LV_DRAW_LABEL_NO_TXT_SEL) { @@ -743,7 +743,7 @@ void lv_textarea_cursor_down(lv_obj_t * obj) { LV_ASSERT_OBJ(obj, MY_CLASS); - lv_textarea_t * ta = (lv_textarea_t *)obj; + lv_textarea_t * ta = (lv_textarea_t *)obj; lv_point_t pos; /*Get the position of the current letter*/ @@ -772,7 +772,7 @@ void lv_textarea_cursor_up(lv_obj_t * obj) { LV_ASSERT_OBJ(obj, MY_CLASS); - lv_textarea_t * ta = (lv_textarea_t *)obj; + lv_textarea_t * ta = (lv_textarea_t *)obj; lv_point_t pos; /*Get the position of the current letter*/ @@ -809,7 +809,8 @@ static void lv_textarea_constructor(const lv_obj_class_t * class_p, lv_obj_t * o ta->accepted_chars = NULL; ta->max_length = 0; ta->cursor.show = 1; - ta->cursor.pos = 1; /*It will be set to zero later (with zero value lv_textarea_set_cursor_pos(obj, 0); woldn't do anything as there is no difference)*/ + ta->cursor.pos = + 1; /*It will be set to zero later (with zero value lv_textarea_set_cursor_pos(obj, 0); woldn't do anything as there is no difference)*/ ta->cursor.click_pos = 1; ta->cursor.valid_x = 0; ta->one_line = 0; @@ -920,7 +921,7 @@ static void lv_textarea_event(const lv_obj_class_t * class_p, lv_event_t * e) */ static void cursor_blink_anim_cb(void * obj, int32_t show) { - lv_textarea_t * ta = (lv_textarea_t *)obj; + lv_textarea_t * ta = (lv_textarea_t *)obj; if(show != ta->cursor.show) { ta->cursor.show = show == 0 ? 0 : 1; lv_area_t area_tmp; @@ -962,7 +963,7 @@ static void pwd_char_hider_anim_ready(lv_anim_t * a) */ static void pwd_char_hider(lv_obj_t * obj) { - lv_textarea_t * ta = (lv_textarea_t *)obj; + lv_textarea_t * ta = (lv_textarea_t *)obj; if(ta->pwd_mode != 0) { char * txt = lv_label_get_text(ta->label); int32_t enc_len = _lv_txt_get_encoded_length(txt); @@ -1000,7 +1001,7 @@ static void pwd_char_hider(lv_obj_t * obj) */ static bool char_is_accepted(lv_obj_t * obj, uint32_t c) { - lv_textarea_t * ta = (lv_textarea_t *)obj; + lv_textarea_t * ta = (lv_textarea_t *)obj; /*If no restriction accept it*/ if(ta->accepted_chars == NULL && ta->max_length == 0) return true; @@ -1033,7 +1034,8 @@ static void start_cursor_blink(lv_obj_t * obj) if(blink_time == 0) { lv_anim_del(obj, cursor_blink_anim_cb); ta->cursor.show = 1; - } else { + } + else { lv_anim_t a; lv_anim_init(&a); lv_anim_set_var(&a, ta); @@ -1080,7 +1082,8 @@ static void refr_cursor_area(lv_obj_t * obj) lv_text_align_t align = lv_obj_calculate_style_text_align(ta->label, LV_PART_MAIN, lv_label_get_text(ta->label)); /*If the cursor is out of the text (most right) draw it to the next line*/ - if(letter_pos.x + ta->label->coords.x1 + letter_w > ta->label->coords.x2 && ta->one_line == 0 && align != LV_TEXT_ALIGN_RIGHT) { + if(letter_pos.x + ta->label->coords.x1 + letter_w > ta->label->coords.x2 && ta->one_line == 0 && + align != LV_TEXT_ALIGN_RIGHT) { letter_pos.x = 0; letter_pos.y += letter_h + line_space; @@ -1138,7 +1141,7 @@ static void update_cursor_position_on_click(lv_event_t * e) lv_event_code_t code = lv_event_get_code(e); lv_obj_t * obj = lv_event_get_target(e); - lv_textarea_t * ta = (lv_textarea_t *)obj; + lv_textarea_t * ta = (lv_textarea_t *)obj; if(ta->cursor.click_pos == 0) return; if(lv_indev_get_type(click_source) == LV_INDEV_TYPE_KEYPAD || @@ -1250,7 +1253,7 @@ static void update_cursor_position_on_click(lv_event_t * e) static lv_res_t insert_handler(lv_obj_t * obj, const char * txt) { ta_insert_replace = NULL; - lv_event_send(obj, LV_EVENT_INSERT, (char*)txt); + lv_event_send(obj, LV_EVENT_INSERT, (char *)txt); if(ta_insert_replace) { if(ta_insert_replace[0] == '\0') return LV_RES_INV; /*Drop this text*/