diff --git a/src/lv_api_map.h b/src/lv_api_map.h index 58369a793..1f27c3a8e 100644 --- a/src/lv_api_map.h +++ b/src/lv_api_map.h @@ -77,7 +77,8 @@ static inline void lv_bar_set_sym(lv_obj_t * bar, bool en) * @return true: symmetric is enabled; false: disable * @deprecated As of v7.0, you should use `lv_bar_get_type` instead. */ -static inline bool lv_bar_get_sym(lv_obj_t * bar) { +static inline bool lv_bar_get_sym(lv_obj_t * bar) +{ return lv_bar_get_type(bar) == LV_BAR_TYPE_SYM; } @@ -94,7 +95,7 @@ static inline bool lv_bar_get_sym(lv_obj_t * bar) { */ static inline void lv_slider_set_sym(lv_obj_t * slider, bool en) { - lv_bar_set_sym(slider, en); + lv_bar_set_sym(slider, en); } /** @@ -103,8 +104,9 @@ static inline void lv_slider_set_sym(lv_obj_t * slider, bool en) * @return true: symmetric is enabled; false: disable * @deprecated As of v7.0, you should use `lv_slider_get_type` instead. */ -static inline bool lv_slider_get_sym(lv_obj_t * slider) { - return lv_bar_get_sym(slider); +static inline bool lv_slider_get_sym(lv_obj_t * slider) +{ + return lv_bar_get_sym(slider); } #endif diff --git a/src/lv_core/lv_debug.c b/src/lv_core/lv_debug.c index ccdd7f846..5bfdeac00 100644 --- a/src/lv_core/lv_debug.c +++ b/src/lv_core/lv_debug.c @@ -15,11 +15,11 @@ * DEFINES *********************/ #ifndef LV_DEBUG_STR_MAX_LENGTH -#define LV_DEBUG_STR_MAX_LENGTH (1024 * 8) + #define LV_DEBUG_STR_MAX_LENGTH (1024 * 8) #endif #ifndef LV_DEBUG_STR_MAX_REPEAT -#define LV_DEBUG_STR_MAX_REPEAT 8 + #define LV_DEBUG_STR_MAX_REPEAT 8 #endif /********************** * TYPEDEFS @@ -126,7 +126,8 @@ bool lv_debug_check_str(const void * str) if(s[i] != last_byte) { last_byte = s[i]; rep = 1; - } else if(s[i] > 0x7F){ + } + else if(s[i] > 0x7F) { rep++; if(rep > LV_DEBUG_STR_MAX_REPEAT) { LV_LOG_WARN("lv_debug_check_str: a non-ASCII char has repeated more than LV_DEBUG_STR_MAX_REPEAT times)"); @@ -184,7 +185,8 @@ void lv_debug_log_error(const char * msg, uint64_t value) *bufp = '\0'; LV_LOG_ERROR(buf); - } else { + } + else { LV_LOG_ERROR(msg); } } diff --git a/src/lv_core/lv_debug.h b/src/lv_core/lv_debug.h index 196a16b3b..3b47f7dfa 100644 --- a/src/lv_core/lv_debug.h +++ b/src/lv_core/lv_debug.h @@ -50,13 +50,13 @@ void lv_debug_log_error(const char * msg, uint64_t value); #ifndef LV_DEBUG_ASSERT #define LV_DEBUG_ASSERT(expr, msg, value) \ -do { \ - if(!(expr)) { \ - LV_LOG_ERROR(__func__); \ - lv_debug_log_error(msg, (uint64_t)((uintptr_t)value)); \ - while(1); \ - } \ -} while(0) + do { \ + if(!(expr)) { \ + LV_LOG_ERROR(__func__); \ + lv_debug_log_error(msg, (uint64_t)((uintptr_t)value)); \ + while(1); \ + } \ + } while(0) #endif /*---------------- diff --git a/src/lv_core/lv_group.c b/src/lv_core/lv_group.c index e046e029d..fd6216e5e 100644 --- a/src/lv_core/lv_group.c +++ b/src/lv_core/lv_group.c @@ -14,7 +14,7 @@ #include "../lv_misc/lv_gc.h" #if defined(LV_GC_INCLUDE) -#include LV_GC_INCLUDE + #include LV_GC_INCLUDE #endif /* LV_ENABLE_GC */ /********************* @@ -93,8 +93,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) - { + LV_LL_READ(group->obj_ll, obj) { (*obj)->group_p = NULL; } @@ -114,8 +113,7 @@ void lv_group_add_obj(lv_group_t * group, lv_obj_t * obj) /*Do not add the object twice*/ lv_obj_t ** obj_i; - LV_LL_READ(group->obj_ll, obj_i) - { + LV_LL_READ(group->obj_ll, obj_i) { if((*obj_i) == obj) { LV_LOG_INFO("lv_group_add_obj: the object is already added to this group"); return; @@ -175,8 +173,7 @@ void lv_group_remove_obj(lv_obj_t * obj) /*Search the object and remove it from its group */ lv_obj_t ** i; - LV_LL_READ(g->obj_ll, i) - { + LV_LL_READ(g->obj_ll, i) { if(*i == obj) { lv_ll_remove(&g->obj_ll, i); lv_mem_free(i); @@ -201,8 +198,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) - { + LV_LL_READ(group->obj_ll, obj) { (*obj)->group_p = NULL; } @@ -227,8 +223,7 @@ void lv_group_focus_obj(lv_obj_t * obj) lv_group_set_editing(g, false); lv_obj_t ** i; - LV_LL_READ(g->obj_ll, i) - { + LV_LL_READ(g->obj_ll, i) { if(*i == obj) { if(g->obj_focus != NULL) { (*g->obj_focus)->signal_cb(*g->obj_focus, LV_SIGNAL_DEFOCUS, NULL); @@ -400,7 +395,8 @@ lv_style_t * lv_group_mod_style(lv_group_t * group, const lv_style_t * style) if(group->editing) { if(group->style_mod_edit_cb) group->style_mod_edit_cb(group, &group->style_tmp); - } else { + } + else { if(group->style_mod_cb) group->style_mod_cb(group, &group->style_tmp); } return &group->style_tmp; @@ -532,7 +528,8 @@ static void focus_next_core(lv_group_t * group, void * (*begin)(const lv_ll_t *) obj_next = begin(&group->obj_ll); can_move = false; can_begin = false; - } else { + } + else { /*Currently focused object is the last/first in the group, keep it that way*/ return; } diff --git a/src/lv_core/lv_group.h b/src/lv_core/lv_group.h index 194de6619..68dc23707 100644 --- a/src/lv_core/lv_group.h +++ b/src/lv_core/lv_group.h @@ -51,8 +51,7 @@ typedef void (*lv_group_focus_cb_t)(struct _lv_group_t *); * Groups can be used to logically hold objects so that they can be individually focused. * They are NOT for laying out objects on a screen (try `lv_cont` for that). */ -typedef struct _lv_group_t -{ +typedef struct _lv_group_t { lv_ll_t obj_ll; /**< Linked list to store the objects in the group */ lv_obj_t ** obj_focus; /**< The object in focus*/ diff --git a/src/lv_core/lv_indev.c b/src/lv_core/lv_indev.c index 4f08a86d1..d269aa19d 100644 --- a/src/lv_core/lv_indev.c +++ b/src/lv_core/lv_indev.c @@ -21,7 +21,7 @@ *********************/ #if LV_INDEV_DEF_DRAG_THROW <= 0 -#warning "LV_INDEV_DRAG_THROW must be greater than 0" + #warning "LV_INDEV_DRAG_THROW must be greater than 0" #endif /********************** @@ -101,17 +101,21 @@ void lv_indev_read_task(lv_task_t * task) /*Save the last activity time*/ if(indev_act->proc.state == LV_INDEV_STATE_PR) { indev_act->driver.disp->last_activity_time = lv_tick_get(); - } else if(indev_act->driver.type == LV_INDEV_TYPE_ENCODER && data.enc_diff) { + } + else if(indev_act->driver.type == LV_INDEV_TYPE_ENCODER && data.enc_diff) { indev_act->driver.disp->last_activity_time = lv_tick_get(); } if(indev_act->driver.type == LV_INDEV_TYPE_POINTER) { indev_pointer_proc(indev_act, &data); - } else if(indev_act->driver.type == LV_INDEV_TYPE_KEYPAD) { + } + else if(indev_act->driver.type == LV_INDEV_TYPE_KEYPAD) { indev_keypad_proc(indev_act, &data); - } else if(indev_act->driver.type == LV_INDEV_TYPE_ENCODER) { + } + else if(indev_act->driver.type == LV_INDEV_TYPE_ENCODER) { indev_encoder_proc(indev_act, &data); - } else if(indev_act->driver.type == LV_INDEV_TYPE_BUTTON) { + } + else if(indev_act->driver.type == LV_INDEV_TYPE_BUTTON) { indev_button_proc(indev_act, &data); } /*Handle reset query if it happened in during processing*/ @@ -159,7 +163,8 @@ void lv_indev_reset(lv_indev_t * indev, lv_obj_t * obj) if(obj == NULL || indev->proc.types.pointer.last_pressed == obj) { indev->proc.types.pointer.last_pressed = NULL; } - } else { + } + else { lv_indev_t * i = lv_indev_get_next(NULL); while(i) { i->proc.reset_query = 1; @@ -245,7 +250,8 @@ void lv_indev_get_point(const lv_indev_t * indev, lv_point_t * point) if(indev->driver.type != LV_INDEV_TYPE_POINTER && indev->driver.type != LV_INDEV_TYPE_BUTTON) { point->x = -1; point->y = -1; - } else { + } + else { point->x = indev->proc.types.pointer.act_point.x; point->y = indev->proc.types.pointer.act_point.y; } @@ -304,7 +310,8 @@ void lv_indev_get_vect(const lv_indev_t * indev, lv_point_t * point) if(indev->driver.type != LV_INDEV_TYPE_POINTER && indev->driver.type != LV_INDEV_TYPE_BUTTON) { point->x = 0; point->y = 0; - } else { + } + else { point->x = indev->proc.types.pointer.vect.x; point->y = indev->proc.types.pointer.vect.y; } @@ -396,7 +403,8 @@ static void indev_pointer_proc(lv_indev_t * i, lv_indev_data_t * data) if(i->proc.state == LV_INDEV_STATE_PR) { indev_proc_press(&i->proc); - } else { + } + else { indev_proc_release(&i->proc); } @@ -453,7 +461,8 @@ static void indev_keypad_proc(lv_indev_t * i, lv_indev_data_t * data) if(indev_reset_check(&i->proc)) return; lv_event_send(indev_obj_act, LV_EVENT_PRESSED, NULL); if(indev_reset_check(&i->proc)) return; - } else if(data->key == LV_KEY_ESC) { + } + else if(data->key == LV_KEY_ESC) { /*Send the ESC as a normal KEY*/ lv_group_send_data(g, LV_KEY_ESC); @@ -589,7 +598,8 @@ static void indev_encoder_proc(lv_indev_t * i, lv_indev_data_t * data) int32_t s; if(data->enc_diff < 0) { for(s = 0; s < -data->enc_diff; s++) lv_group_send_data(g, LV_KEY_LEFT); - } else if(data->enc_diff > 0) { + } + else if(data->enc_diff > 0) { for(s = 0; s < data->enc_diff; s++) lv_group_send_data(g, LV_KEY_RIGHT); } } @@ -598,7 +608,8 @@ static void indev_encoder_proc(lv_indev_t * i, lv_indev_data_t * data) int32_t s; if(data->enc_diff < 0) { for(s = 0; s < -data->enc_diff; s++) lv_group_focus_prev(g); - } else if(data->enc_diff > 0) { + } + else if(data->enc_diff > 0) { for(s = 0; s < data->enc_diff; s++) lv_group_focus_next(g); } } @@ -715,7 +726,8 @@ static void indev_button_proc(lv_indev_t * i, lv_indev_data_t * data) if(i->proc.types.pointer.last_point.x == i->proc.types.pointer.act_point.x && i->proc.types.pointer.last_point.y == i->proc.types.pointer.act_point.y && data->state == LV_INDEV_STATE_PR) { indev_proc_press(&i->proc); - } else { + } + else { /*If a new point comes always make a release*/ indev_proc_release(&i->proc); } @@ -741,16 +753,20 @@ static void indev_proc_press(lv_indev_proc_t * proc) /*If there is no last object then search*/ if(indev_obj_act == NULL) { indev_obj_act = lv_indev_search_obj(lv_disp_get_layer_sys(disp), &proc->types.pointer.act_point); - if(indev_obj_act == NULL) indev_obj_act = lv_indev_search_obj(lv_disp_get_layer_top(disp), &proc->types.pointer.act_point); - if(indev_obj_act == NULL) indev_obj_act = lv_indev_search_obj(lv_disp_get_scr_act(disp), &proc->types.pointer.act_point); + if(indev_obj_act == NULL) indev_obj_act = lv_indev_search_obj(lv_disp_get_layer_top(disp), + &proc->types.pointer.act_point); + if(indev_obj_act == NULL) indev_obj_act = lv_indev_search_obj(lv_disp_get_scr_act(disp), + &proc->types.pointer.act_point); new_obj_searched = true; } /*If there is last object but it is not dragged and not protected also search*/ else if(proc->types.pointer.drag_in_prog == 0 && lv_obj_is_protected(indev_obj_act, LV_PROTECT_PRESS_LOST) == false) { indev_obj_act = lv_indev_search_obj(lv_disp_get_layer_sys(disp), &proc->types.pointer.act_point); - if(indev_obj_act == NULL) indev_obj_act = lv_indev_search_obj(lv_disp_get_layer_top(disp), &proc->types.pointer.act_point); - if(indev_obj_act == NULL) indev_obj_act = lv_indev_search_obj(lv_disp_get_scr_act(disp), &proc->types.pointer.act_point); + if(indev_obj_act == NULL) indev_obj_act = lv_indev_search_obj(lv_disp_get_layer_top(disp), + &proc->types.pointer.act_point); + if(indev_obj_act == NULL) indev_obj_act = lv_indev_search_obj(lv_disp_get_scr_act(disp), + &proc->types.pointer.act_point); new_obj_searched = true; } /*If a dragable or a protected object was the last then keep it*/ @@ -1009,7 +1025,7 @@ static void indev_proc_reset_query_handler(lv_indev_t * indev) * @param point pointer to a point for searhing the most top child * @return pointer to the found object or NULL if there was no suitable object */ -lv_obj_t * lv_indev_search_obj(lv_obj_t * obj, lv_point_t *point) +lv_obj_t * lv_indev_search_obj(lv_obj_t * obj, lv_point_t * point) { lv_obj_t * found_p = NULL; @@ -1017,8 +1033,7 @@ lv_obj_t * lv_indev_search_obj(lv_obj_t * obj, lv_point_t *point) if(lv_obj_hittest(obj, point)) { lv_obj_t * i; - LV_LL_READ(obj->child_ll, i) - { + LV_LL_READ(obj->child_ll, i) { found_p = lv_indev_search_obj(i, point); /*If a child was found then break*/ @@ -1029,7 +1044,8 @@ lv_obj_t * lv_indev_search_obj(lv_obj_t * obj, lv_point_t *point) /*If then the children was not ok, and this obj is clickable * and it or its parent is not hidden then save this object*/ - if(found_p == NULL && lv_obj_get_click(obj) != false && (lv_obj_get_state(obj, LV_OBJ_PART_MAIN) & LV_STATE_DISABLED) == 0) { + if(found_p == NULL && lv_obj_get_click(obj) != false && + (lv_obj_get_state(obj, LV_OBJ_PART_MAIN) & LV_STATE_DISABLED) == 0) { lv_obj_t * hidden_i = obj; while(hidden_i != NULL) { if(lv_obj_get_hidden(hidden_i) == true) break; @@ -1051,7 +1067,7 @@ static void indev_click_focus(lv_indev_proc_t * proc) { /*Handle click focus*/ if(lv_obj_is_protected(indev_obj_act, LV_PROTECT_CLICK_FOCUS) == false && - proc->types.pointer.last_pressed != indev_obj_act) { + proc->types.pointer.last_pressed != indev_obj_act) { #if LV_USE_GROUP lv_group_t * g_act = lv_obj_get_group(indev_obj_act); lv_group_t * g_prev = proc->types.pointer.last_pressed ? lv_obj_get_group(proc->types.pointer.last_pressed) : NULL; @@ -1170,7 +1186,8 @@ static void indev_drag(lv_indev_proc_t * proc) if(allowed_dirs == LV_DRAG_DIR_ONE) { if(LV_MATH_ABS(proc->types.pointer.drag_sum.x) > LV_MATH_ABS(proc->types.pointer.drag_sum.y)) { hor_en = true; - } else { + } + else { ver_en = true; } } @@ -1203,25 +1220,29 @@ static void indev_drag(lv_indev_proc_t * proc) act_x += proc->types.pointer.drag_sum.x; act_y += proc->types.pointer.drag_sum.y; } - } else if(allowed_dirs == LV_DRAG_DIR_HOR) { + } + else if(allowed_dirs == LV_DRAG_DIR_HOR) { if(drag_just_started) { proc->types.pointer.drag_dir = LV_DRAG_DIR_HOR; proc->types.pointer.drag_sum.y = 0; act_x += proc->types.pointer.drag_sum.x; } - } else if(allowed_dirs == LV_DRAG_DIR_VER) { + } + else if(allowed_dirs == LV_DRAG_DIR_VER) { if(drag_just_started) { proc->types.pointer.drag_dir = LV_DRAG_DIR_VER; proc->types.pointer.drag_sum.x = 0; act_y += proc->types.pointer.drag_sum.y; } - } else if(allowed_dirs == LV_DRAG_DIR_ONE) { + } + else if(allowed_dirs == LV_DRAG_DIR_ONE) { if(drag_just_started) { if(LV_MATH_ABS(proc->types.pointer.drag_sum.x) > LV_MATH_ABS(proc->types.pointer.drag_sum.y)) { proc->types.pointer.drag_dir = LV_DRAG_DIR_HOR; proc->types.pointer.drag_sum.y = 0; act_x += proc->types.pointer.drag_sum.x; - } else { + } + else { proc->types.pointer.drag_dir = LV_DRAG_DIR_VER; proc->types.pointer.drag_sum.x = 0; act_y += proc->types.pointer.drag_sum.y; @@ -1374,51 +1395,51 @@ static lv_obj_t * get_dragged_obj(lv_obj_t * obj) static void indev_gesture(lv_indev_proc_t * proc) { - if (proc->types.pointer.drag_in_prog) return; - if (proc->types.pointer.gesture_sent) return; + if(proc->types.pointer.drag_in_prog) return; + if(proc->types.pointer.gesture_sent) return; - lv_obj_t * gesture_obj = proc->types.pointer.act_obj; + lv_obj_t * gesture_obj = proc->types.pointer.act_obj; - /*If gesture parent is active check recursively the drag_parent attribute*/ - while (gesture_obj && lv_obj_get_gesture_parent(gesture_obj)) { - gesture_obj = lv_obj_get_parent(gesture_obj); - } + /*If gesture parent is active check recursively the drag_parent attribute*/ + while(gesture_obj && lv_obj_get_gesture_parent(gesture_obj)) { + gesture_obj = lv_obj_get_parent(gesture_obj); + } - if (gesture_obj == NULL) return; + if(gesture_obj == NULL) return; - if ((LV_MATH_ABS(proc->types.pointer.vect.x) < indev_act->driver.gesture_min_velocity) && - (LV_MATH_ABS(proc->types.pointer.vect.y) < indev_act->driver.gesture_min_velocity)) { - proc->types.pointer.gesture_sum.x = 0; - proc->types.pointer.gesture_sum.y = 0; - } + if((LV_MATH_ABS(proc->types.pointer.vect.x) < indev_act->driver.gesture_min_velocity) && + (LV_MATH_ABS(proc->types.pointer.vect.y) < indev_act->driver.gesture_min_velocity)) { + proc->types.pointer.gesture_sum.x = 0; + proc->types.pointer.gesture_sum.y = 0; + } - /*Count the movement by gesture*/ - proc->types.pointer.gesture_sum.x += proc->types.pointer.vect.x; - proc->types.pointer.gesture_sum.y += proc->types.pointer.vect.y; + /*Count the movement by gesture*/ + proc->types.pointer.gesture_sum.x += proc->types.pointer.vect.x; + proc->types.pointer.gesture_sum.y += proc->types.pointer.vect.y; - if ((LV_MATH_ABS(proc->types.pointer.gesture_sum.x) > indev_act->driver.gesture_limit) || - (LV_MATH_ABS(proc->types.pointer.gesture_sum.y) > indev_act->driver.gesture_limit)){ + if((LV_MATH_ABS(proc->types.pointer.gesture_sum.x) > indev_act->driver.gesture_limit) || + (LV_MATH_ABS(proc->types.pointer.gesture_sum.y) > indev_act->driver.gesture_limit)) { - proc->types.pointer.gesture_sent = 1; + proc->types.pointer.gesture_sent = 1; - if (LV_MATH_ABS(proc->types.pointer.gesture_sum.x) > LV_MATH_ABS(proc->types.pointer.gesture_sum.y)){ - if (proc->types.pointer.gesture_sum.x > 0) - proc->types.pointer.gesture_dir = LV_GESTURE_DIR_RIGHT; - else - proc->types.pointer.gesture_dir = LV_GESTURE_DIR_LEFT; - } - else{ - if (proc->types.pointer.gesture_sum.y > 0) - proc->types.pointer.gesture_dir = LV_GESTURE_DIR_BOTTOM; - else - proc->types.pointer.gesture_dir = LV_GESTURE_DIR_TOP; - } + if(LV_MATH_ABS(proc->types.pointer.gesture_sum.x) > LV_MATH_ABS(proc->types.pointer.gesture_sum.y)) { + if(proc->types.pointer.gesture_sum.x > 0) + proc->types.pointer.gesture_dir = LV_GESTURE_DIR_RIGHT; + else + proc->types.pointer.gesture_dir = LV_GESTURE_DIR_LEFT; + } + else { + if(proc->types.pointer.gesture_sum.y > 0) + proc->types.pointer.gesture_dir = LV_GESTURE_DIR_BOTTOM; + else + proc->types.pointer.gesture_dir = LV_GESTURE_DIR_TOP; + } - gesture_obj->signal_cb(gesture_obj, LV_SIGNAL_GESTURE, indev_act); - if (indev_reset_check(proc)) return; - lv_event_send(gesture_obj, LV_EVENT_GESTURE, NULL); - if (indev_reset_check(proc)) return; - } + gesture_obj->signal_cb(gesture_obj, LV_SIGNAL_GESTURE, indev_act); + if(indev_reset_check(proc)) return; + lv_event_send(gesture_obj, LV_EVENT_GESTURE, NULL); + if(indev_reset_check(proc)) return; + } } diff --git a/src/lv_core/lv_indev.h b/src/lv_core/lv_indev.h index 7fc2d1a77..4c241bed6 100644 --- a/src/lv_core/lv_indev.h +++ b/src/lv_core/lv_indev.h @@ -170,7 +170,7 @@ lv_obj_t * lv_indev_get_obj_act(void); * @param point pointer to a point for searhing the most top child * @return pointer to the found object or NULL if there was no suitable object */ -lv_obj_t * lv_indev_search_obj(lv_obj_t * obj, lv_point_t *point); +lv_obj_t * lv_indev_search_obj(lv_obj_t * obj, lv_point_t * point); /********************** * MACROS diff --git a/src/lv_core/lv_obj.c b/src/lv_core/lv_obj.c index 9d2e0015e..9899fc795 100644 --- a/src/lv_core/lv_obj.c +++ b/src/lv_core/lv_obj.c @@ -28,12 +28,12 @@ #include #if defined(LV_GC_INCLUDE) -#include LV_GC_INCLUDE + #include LV_GC_INCLUDE #endif /* LV_ENABLE_GC */ #if defined(LV_USER_DATA_FREE_INCLUDE) -#include LV_USER_DATA_FREE_INCLUDE + #include LV_USER_DATA_FREE_INCLUDE #endif /* LV_USE_USER_DATA_FREE */ /********************* @@ -47,8 +47,7 @@ /********************** * TYPEDEFS **********************/ -typedef struct _lv_event_temp_data -{ +typedef struct _lv_event_temp_data { lv_obj_t * obj; bool deleted; struct _lv_event_temp_data * prev; @@ -63,14 +62,14 @@ typedef struct { lv_style_int_t _int; lv_opa_t _opa; const void * _ptr; - }start_value; + } start_value; union { lv_color_t _color; lv_style_int_t _int; lv_opa_t _opa; const void * _ptr; - }end_value; -}lv_style_trans_t; + } end_value; +} lv_style_trans_t; /********************** * STATIC PROTOTYPES @@ -83,12 +82,13 @@ static void refresh_children_style(lv_obj_t * obj); static void delete_children(lv_obj_t * obj); static void base_dir_refr_children(lv_obj_t * obj); #if LV_USE_ANIMATION -static lv_style_trans_t * trans_create(lv_obj_t * obj, lv_style_property_t prop, uint8_t part, lv_state_t prev_state, lv_state_t new_state); -static void trans_del(lv_obj_t * obj, uint8_t part, lv_style_property_t prop); -static void trans_anim_cb(lv_style_trans_t * tr, lv_anim_value_t v); -static void trans_anim_start_cb(lv_anim_t * a); -static void trans_anim_ready_cb(lv_anim_t * a); -static void opa_scale_anim(lv_obj_t * obj, lv_anim_value_t v); + static lv_style_trans_t * trans_create(lv_obj_t * obj, lv_style_property_t prop, uint8_t part, lv_state_t prev_state, + lv_state_t new_state); + static void trans_del(lv_obj_t * obj, uint8_t part, lv_style_property_t prop); + static void trans_anim_cb(lv_style_trans_t * tr, lv_anim_value_t v); + static void trans_anim_start_cb(lv_anim_t * a); + static void trans_anim_ready_cb(lv_anim_t * a); + static void opa_scale_anim(lv_obj_t * obj, lv_anim_value_t v); #endif static void lv_event_mark_deleted(lv_obj_t * obj); static void lv_obj_del_async_cb(void * obj); @@ -140,8 +140,8 @@ void lv_init(void) lv_ll_init(&LV_GC_ROOT(_lv_obj_style_trans_ll), sizeof(lv_style_trans_t)); lv_theme_t * th = LV_THEME_DEFAULT_INIT(LV_THEME_DEFAULT_COLOR_PRIMARY, LV_THEME_DEFAULT_COLOR_SECONDARY, - LV_THEME_DEFAULT_FLAGS, - LV_THEME_DEFAULT_FONT_SMALL, LV_THEME_DEFAULT_FONT_NORMAL, LV_THEME_DEFAULT_FONT_SUBTITLE, LV_THEME_DEFAULT_FONT_TITLE); + LV_THEME_DEFAULT_FLAGS, + LV_THEME_DEFAULT_FONT_SMALL, LV_THEME_DEFAULT_FONT_NORMAL, LV_THEME_DEFAULT_FONT_SUBTITLE, LV_THEME_DEFAULT_FONT_TITLE); lv_theme_set_act(th); /*Initialize the screen refresh system*/ @@ -234,7 +234,8 @@ lv_obj_t * lv_obj_create(lv_obj_t * parent, const lv_obj_t * copy) if(lv_obj_get_base_dir(new_obj) == LV_BIDI_DIR_RTL) { new_obj->coords.x2 = parent->coords.x2; new_obj->coords.x1 = parent->coords.x2 - LV_OBJ_DEF_WIDTH; - } else { + } + else { new_obj->coords.x1 = parent->coords.x1; new_obj->coords.x2 = parent->coords.x1 + LV_OBJ_DEF_WIDTH; } @@ -304,7 +305,8 @@ lv_obj_t * lv_obj_create(lv_obj_t * parent, const lv_obj_t * copy) if(copy == NULL) { if(parent != NULL) lv_theme_apply(new_obj, LV_THEME_OBJ); else lv_theme_apply(new_obj, LV_THEME_SCR); - } else { + } + else { lv_style_list_copy(&new_obj->style_list, ©->style_list); } /*Copy the attributes if required*/ @@ -451,7 +453,8 @@ lv_res_t lv_obj_del(lv_obj_t * obj) if(par == NULL) { /*It is a screen*/ lv_disp_t * d = lv_obj_get_disp(obj); lv_ll_remove(&d->scr_ll, obj); - } else { + } + else { lv_ll_remove(&(par->child_ll), obj); } @@ -613,7 +616,8 @@ void lv_obj_set_parent(lv_obj_t * obj, lv_obj_t * parent) if(new_base_dir != LV_BIDI_DIR_RTL) { old_pos.x = lv_obj_get_x(obj); - } else { + } + else { old_pos.x = old_par->coords.x2 - obj->coords.x2; } @@ -623,10 +627,11 @@ void lv_obj_set_parent(lv_obj_t * obj, lv_obj_t * parent) if(new_base_dir != LV_BIDI_DIR_RTL) { lv_obj_set_pos(obj, old_pos.x, old_pos.y); - } else { + } + else { /*Align to the right in case of RTL base dir*/ lv_coord_t new_x = lv_obj_get_width(parent) - old_pos.x - lv_obj_get_width(obj); - lv_obj_set_pos(obj, new_x , old_pos.y); + lv_obj_set_pos(obj, new_x, old_pos.y); } /*Notify the original parent because one of its children is lost*/ @@ -700,7 +705,7 @@ void lv_obj_set_pos(lv_obj_t * obj, lv_coord_t x, lv_coord_t y) /*Convert x and y to absolute coordinates*/ lv_obj_t * par = obj->parent; - + if(par == NULL) { LV_LOG_WARN("lv_obj_set_pos: not changing position of screen object"); return; @@ -795,7 +800,8 @@ void lv_obj_set_size(lv_obj_t * obj, lv_coord_t w, lv_coord_t h) obj->coords.y2 = obj->coords.y1 + h - 1; if(lv_obj_get_base_dir(obj) == LV_BIDI_DIR_RTL) { obj->coords.x1 = obj->coords.x2 - w + 1; - } else { + } + else { obj->coords.x2 = obj->coords.x1 + w - 1; } @@ -1303,8 +1309,7 @@ void lv_obj_report_style_mod(lv_style_t * style) while(d) { lv_obj_t * i; - LV_LL_READ(d->scr_ll, i) - { + LV_LL_READ(d->scr_ll, i) { report_style_mod_core(style, i); } d = lv_disp_get_next(d); @@ -1339,7 +1344,8 @@ void lv_obj_set_hidden(lv_obj_t * obj, bool en) * @param obj pointer to an object * @param en true: advanced hit-testing is enabled */ -void lv_obj_set_adv_hittest(lv_obj_t * obj, bool en) { +void lv_obj_set_adv_hittest(lv_obj_t * obj, bool en) +{ LV_ASSERT_OBJ(obj, LV_OBJX_NAME); obj->adv_hittest = en == false ? 0 : 1; @@ -1545,7 +1551,8 @@ void lv_obj_set_state(lv_obj_t * obj, lv_state_t new_state) if(time == 0) { trans_anim_cb(tr, 255); - } else { + } + else { lv_anim_t a; lv_anim_init(&a); lv_anim_set_var(&a, tr); @@ -1612,17 +1619,17 @@ void lv_obj_clear_state(lv_obj_t * obj, lv_state_t state) */ void lv_obj_finish_transitions(lv_obj_t * obj, uint8_t part) { - /*Animate all related transition to the end value*/ - lv_style_trans_t * tr; - tr = lv_ll_get_head(&LV_GC_ROOT(_lv_obj_style_trans_ll)); - LV_LL_READ(LV_GC_ROOT(_lv_obj_style_trans_ll), tr) { - if(tr->obj == obj && (part == tr->part || part == LV_OBJ_PART_ALL)) { - trans_anim_cb(tr, 255); - } - } + /*Animate all related transition to the end value*/ + lv_style_trans_t * tr; + tr = lv_ll_get_head(&LV_GC_ROOT(_lv_obj_style_trans_ll)); + LV_LL_READ(LV_GC_ROOT(_lv_obj_style_trans_ll), tr) { + if(tr->obj == obj && (part == tr->part || part == LV_OBJ_PART_ALL)) { + trans_anim_cb(tr, 255); + } + } - /*Free all related transition data*/ - trans_del(obj, part, 0xFF); + /*Free all related transition data*/ + trans_del(obj, part, 0xFF); } #endif @@ -1847,11 +1854,9 @@ lv_disp_t * lv_obj_get_disp(const lv_obj_t * obj) scr = lv_obj_get_screen(obj); /*get the screen of `obj`*/ lv_disp_t * d; - LV_LL_READ(LV_GC_ROOT(_lv_disp_ll), d) - { + LV_LL_READ(LV_GC_ROOT(_lv_disp_ll), d) { lv_obj_t * s; - LV_LL_READ(d->scr_ll, s) - { + LV_LL_READ(d->scr_ll, s) { if(s == scr) return d; } } @@ -1891,7 +1896,8 @@ lv_obj_t * lv_obj_get_child(const lv_obj_t * obj, const lv_obj_t * child) if(child == NULL) { result = lv_ll_get_head(&obj->child_ll); - } else { + } + else { result = lv_ll_get_next(&obj->child_ll, child); } @@ -1913,7 +1919,8 @@ lv_obj_t * lv_obj_get_child_back(const lv_obj_t * obj, const lv_obj_t * child) if(child == NULL) { result = lv_ll_get_tail(&obj->child_ll); - } else { + } + else { result = lv_ll_get_prev(&obj->child_ll, child); } @@ -1948,8 +1955,7 @@ uint16_t lv_obj_count_children_recursive(const lv_obj_t * obj) lv_obj_t * i; uint16_t cnt = 0; - LV_LL_READ(obj->child_ll, i) - { + LV_LL_READ(obj->child_ll, i) { cnt++; /*Count the child*/ cnt += lv_obj_count_children_recursive(i); /*recursively count children's children*/ } @@ -2007,7 +2013,8 @@ lv_coord_t lv_obj_get_x(const lv_obj_t * obj) lv_obj_t * parent = lv_obj_get_parent(obj); if(parent) { rel_x = obj->coords.x1 - parent->coords.x1; - } else { + } + else { rel_x = obj->coords.x1; } return rel_x; @@ -2024,11 +2031,12 @@ lv_coord_t lv_obj_get_y(const lv_obj_t * obj) lv_coord_t rel_y; lv_obj_t * parent = lv_obj_get_parent(obj); - if(parent) { - rel_y = obj->coords.y1 - parent->coords.y1; - } else { - rel_y = obj->coords.y1; - } + if(parent) { + rel_y = obj->coords.y1 - parent->coords.y1; + } + else { + rel_y = obj->coords.y1; + } return rel_y; } @@ -2197,14 +2205,14 @@ lv_coord_t lv_obj_get_ext_draw_pad(const lv_obj_t * obj) lv_style_list_t * lv_obj_get_style_list(const lv_obj_t * obj, uint8_t part) { - if(part == LV_OBJ_PART_MAIN) return &((lv_obj_t*)obj)->style_list; + if(part == LV_OBJ_PART_MAIN) return &((lv_obj_t *)obj)->style_list; - lv_get_style_info_t info; - info.part = part; - info.result = NULL; + lv_get_style_info_t info; + info.part = part; + info.result = NULL; lv_res_t res; - res = lv_signal_send((lv_obj_t*)obj, LV_SIGNAL_GET_STYLE, &info); + res = lv_signal_send((lv_obj_t *)obj, LV_SIGNAL_GET_STYLE, &info); if(res != LV_RES_OK) return NULL; @@ -2259,14 +2267,14 @@ lv_style_int_t _lv_obj_get_style_int(const lv_obj_t * obj, uint8_t part, lv_styl /*Handle unset values*/ prop = prop & (~LV_STYLE_STATE_MASK); switch(prop) { - case LV_STYLE_BORDER_SIDE: - return LV_BORDER_SIDE_FULL; - case LV_STYLE_SIZE: - return LV_DPI / 20; - case LV_STYLE_SCALE_WIDTH: - return LV_DPI / 8; - case LV_STYLE_BG_GRAD_STOP: - return 255; + case LV_STYLE_BORDER_SIDE: + return LV_BORDER_SIDE_FULL; + case LV_STYLE_SIZE: + return LV_DPI / 20; + case LV_STYLE_SCALE_WIDTH: + return LV_DPI / 8; + case LV_STYLE_BG_GRAD_STOP: + return 255; } return 0; @@ -2320,9 +2328,9 @@ lv_color_t _lv_obj_get_style_color(const lv_obj_t * obj, uint8_t part, lv_style_ /*Handle unset values*/ prop = prop & (~LV_STYLE_STATE_MASK); switch(prop) { - case LV_STYLE_BG_COLOR: - case LV_STYLE_BG_GRAD_COLOR: - return LV_COLOR_WHITE; + case LV_STYLE_BG_COLOR: + case LV_STYLE_BG_GRAD_COLOR: + return LV_COLOR_WHITE; } return LV_COLOR_BLACK; @@ -2376,10 +2384,10 @@ lv_opa_t _lv_obj_get_style_opa(const lv_obj_t * obj, uint8_t part, lv_style_prop /*Handle unset values*/ prop = prop & (~LV_STYLE_STATE_MASK); switch(prop) { - case LV_STYLE_BG_OPA: - case LV_STYLE_IMAGE_RECOLOR_OPA: - case LV_STYLE_PATTERN_RECOLOR_OPA: - return LV_OPA_TRANSP; + case LV_STYLE_BG_OPA: + case LV_STYLE_IMAGE_RECOLOR_OPA: + case LV_STYLE_PATTERN_RECOLOR_OPA: + return LV_OPA_TRANSP; } return LV_OPA_COVER; @@ -2433,12 +2441,12 @@ const void * _lv_obj_get_style_ptr(const lv_obj_t * obj, uint8_t part, lv_style_ /*Handle unset values*/ prop = prop & (~LV_STYLE_STATE_MASK); switch(prop) { - case LV_STYLE_TEXT_FONT: - case LV_STYLE_VALUE_FONT: - return LV_THEME_DEFAULT_FONT_NORMAL; + case LV_STYLE_TEXT_FONT: + case LV_STYLE_VALUE_FONT: + return LV_THEME_DEFAULT_FONT_NORMAL; #if LV_USE_ANIMATION - case LV_STYLE_TRANSITION_PATH: - return lv_anim_path_linear; + case LV_STYLE_TRANSITION_PATH: + return lv_anim_path_linear; #endif } @@ -2627,7 +2635,7 @@ lv_state_t lv_obj_get_state(const lv_obj_t * obj, uint8_t part) { LV_ASSERT_OBJ(obj, LV_OBJX_NAME); - if(part < _LV_OBJ_PART_REAL_LAST) return ((lv_obj_t*)obj)->state; + if(part < _LV_OBJ_PART_REAL_LAST) return ((lv_obj_t *)obj)->state; /*If a real part is asked, then use the object's signal to get its state. * A real object can be in different state then the main part @@ -2635,7 +2643,7 @@ lv_state_t lv_obj_get_state(const lv_obj_t * obj, uint8_t part) lv_get_state_info_t info; info.part = part; info.result = LV_STATE_DEFAULT; - lv_signal_send((lv_obj_t*)obj, LV_SIGNAL_GET_STATE_DSC, &info); + lv_signal_send((lv_obj_t *)obj, LV_SIGNAL_GET_STATE_DSC, &info); return info.result; @@ -2800,13 +2808,14 @@ bool lv_obj_is_focused(const lv_obj_t * obj) /** * Check if a given screen-space point is on an object's coordinates. - * + * * This method is intended to be used mainly by advanced hit testing algorithms to check * whether the point is even within the object (as an optimization). * @param obj object to check * @param point screen-space point */ -bool lv_obj_is_point_on_coords(lv_obj_t * obj, const lv_point_t * point) { +bool lv_obj_is_point_on_coords(lv_obj_t * obj, const lv_point_t * point) +{ #if LV_USE_EXT_CLICK_AREA == LV_EXT_CLICK_AREA_TINY lv_area_t ext_area; ext_area.x1 = obj->coords.x1 - obj->ext_click_pad_hor; @@ -2837,14 +2846,16 @@ bool lv_obj_is_point_on_coords(lv_obj_t * obj, const lv_point_t * point) { * @param point screen-space point * @return true if the object is considered under the point */ -bool lv_obj_hittest(lv_obj_t * obj, lv_point_t * point) { +bool lv_obj_hittest(lv_obj_t * obj, lv_point_t * point) +{ if(obj->adv_hittest) { lv_hit_test_info_t hit_info; hit_info.point = point; hit_info.result = true; obj->signal_cb(obj, LV_SIGNAL_HIT_TEST, &hit_info); return hit_info.result; - } else + } + else return lv_obj_is_point_on_coords(obj, point); } @@ -2881,7 +2892,7 @@ void lv_obj_init_draw_rect_dsc(lv_obj_t * obj, uint8_t part, lv_draw_rect_dsc_t #if LV_USE_OPA_SCALE lv_opa_t opa_scale = lv_obj_get_style_opa_scale(obj, part); if(opa_scale <= LV_OPA_MIN) { - draw_dsc->bg_opa = LV_OPA_TRANSP; + draw_dsc->bg_opa = LV_OPA_TRANSP; draw_dsc->border_opa = LV_OPA_TRANSP; draw_dsc->shadow_opa = LV_OPA_TRANSP; draw_dsc->pattern_opa = LV_OPA_TRANSP; @@ -2946,7 +2957,8 @@ void lv_obj_init_draw_rect_dsc(lv_obj_t * obj, uint8_t part, lv_draw_rect_dsc_t if(lv_img_src_get_type(draw_dsc->pattern_image) == LV_IMG_SRC_SYMBOL) { draw_dsc->pattern_recolor = lv_obj_get_style_pattern_recolor(obj, part); draw_dsc->pattern_font = lv_obj_get_style_text_font(obj, part); - } else if(draw_dsc->pattern_recolor_opa > LV_OPA_MIN ) { + } + else if(draw_dsc->pattern_recolor_opa > LV_OPA_MIN) { draw_dsc->pattern_recolor = lv_obj_get_style_pattern_recolor(obj, part); } #if LV_USE_BLEND_MODES @@ -3106,7 +3118,7 @@ lv_coord_t lv_obj_get_draw_rect_ext_pad_size(lv_obj_t * obj, uint8_t part) sh_width++; sh_width += lv_obj_get_style_shadow_spread(obj, part); sh_width += LV_MATH_MAX(LV_MATH_ABS(lv_obj_get_style_shadow_ofs_x(obj, part)), - LV_MATH_ABS(lv_obj_get_style_shadow_ofs_y(obj, part))); + LV_MATH_ABS(lv_obj_get_style_shadow_ofs_y(obj, part))); s = LV_MATH_MAX(s, sh_width); } } @@ -3172,18 +3184,18 @@ lv_coord_t lv_obj_get_draw_rect_ext_pad_size(lv_obj_t * obj, uint8_t part) void lv_obj_fade_in(lv_obj_t * obj, uint32_t time, uint32_t delay) { #if LV_USE_ANIMATION - lv_anim_t a; - lv_anim_init(&a); - lv_anim_set_var(&a, obj); - lv_anim_set_values(&a, LV_OPA_TRANSP, LV_OPA_COVER); - lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)opa_scale_anim); - lv_anim_set_time(&a, time); - lv_anim_set_delay(&a, delay); - lv_anim_start(&a); + lv_anim_t a; + lv_anim_init(&a); + lv_anim_set_var(&a, obj); + lv_anim_set_values(&a, LV_OPA_TRANSP, LV_OPA_COVER); + lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)opa_scale_anim); + lv_anim_set_time(&a, time); + lv_anim_set_delay(&a, delay); + lv_anim_start(&a); #else - (void) obj; /*Unused*/ - (void) time; /*Unused*/ - (void) delay; /*Unused*/ + (void) obj; /*Unused*/ + (void) time; /*Unused*/ + (void) delay; /*Unused*/ #endif } @@ -3196,18 +3208,18 @@ void lv_obj_fade_in(lv_obj_t * obj, uint32_t time, uint32_t delay) void lv_obj_fade_out(lv_obj_t * obj, uint32_t time, uint32_t delay) { #if LV_USE_ANIMATION - lv_anim_t a; - lv_anim_init(&a); - lv_anim_set_var(&a, obj); - lv_anim_set_values(&a, LV_OPA_COVER, LV_OPA_TRANSP); - lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)opa_scale_anim); - lv_anim_set_time(&a, time); - lv_anim_set_delay(&a, delay); - lv_anim_start(&a); + lv_anim_t a; + lv_anim_init(&a); + lv_anim_set_var(&a, obj); + lv_anim_set_values(&a, LV_OPA_COVER, LV_OPA_TRANSP); + lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)opa_scale_anim); + lv_anim_set_time(&a, time); + lv_anim_set_delay(&a, delay); + lv_anim_start(&a); #else - (void) obj; /*Unused*/ - (void) time; /*Unused*/ - (void) delay; /*Unused*/ + (void) obj; /*Unused*/ + (void) time; /*Unused*/ + (void) delay; /*Unused*/ #endif } @@ -3344,7 +3356,8 @@ static lv_res_t lv_obj_signal(lv_obj_t * obj, lv_signal_t sign, void * param) if(sign == LV_SIGNAL_CHILD_CHG) { /*Return 'invalid' if the child change signal is not enabled*/ if(lv_obj_is_protected(obj, LV_PROTECT_CHILD_CHG) != false) res = LV_RES_INV; - } else if(sign == LV_SIGNAL_REFR_EXT_DRAW_PAD) { + } + else if(sign == LV_SIGNAL_REFR_EXT_DRAW_PAD) { obj->ext_draw_pad = LV_MATH_MAX(obj->ext_draw_pad, lv_obj_get_draw_rect_ext_pad_size(obj, LV_OBJ_PART_MAIN)); } #if LV_USE_OBJ_REALIGN @@ -3369,11 +3382,13 @@ static lv_res_t lv_obj_signal(lv_obj_t * obj, lv_signal_t sign, void * param) uint8_t state = LV_STATE_FOCUSED; state |= LV_STATE_EDITED; lv_obj_add_state(obj, state); - } else { + } + else { lv_obj_add_state(obj, LV_STATE_FOCUSED); lv_obj_clear_state(obj, LV_STATE_EDITED); } - } else if(sign == LV_SIGNAL_DEFOCUS) { + } + else if(sign == LV_SIGNAL_DEFOCUS) { lv_obj_clear_state(obj, LV_STATE_FOCUSED | LV_STATE_EDITED); } #endif @@ -3393,8 +3408,7 @@ static lv_res_t lv_obj_signal(lv_obj_t * obj, lv_signal_t sign, void * param) static void refresh_children_position(lv_obj_t * obj, lv_coord_t x_diff, lv_coord_t y_diff) { lv_obj_t * i; - LV_LL_READ(obj->child_ll, i) - { + LV_LL_READ(obj->child_ll, i) { i->coords.x1 += x_diff; i->coords.y1 += y_diff; i->coords.x2 += x_diff; @@ -3556,7 +3570,8 @@ static void base_dir_refr_children(lv_obj_t * obj) * @param new_state the new state of the object * @return pointer to the allocated `the transaction` variable or `NULL` if no transtion created */ -static lv_style_trans_t * trans_create(lv_obj_t * obj, lv_style_property_t prop, uint8_t part, lv_state_t prev_state, lv_state_t new_state) +static lv_style_trans_t * trans_create(lv_obj_t * obj, lv_style_property_t prop, uint8_t part, lv_state_t prev_state, + lv_state_t new_state) { lv_style_trans_t * tr; lv_style_list_t * style_list = lv_obj_get_style_list(obj, part); @@ -3630,9 +3645,10 @@ static lv_style_trans_t * trans_create(lv_obj_t * obj, lv_style_property_t prop, tr = lv_ll_ins_head(&LV_GC_ROOT(_lv_obj_style_trans_ll)); LV_ASSERT_MEM(tr); if(tr == NULL) return NULL; - tr->start_value._opa= o1; + tr->start_value._opa = o1; tr->end_value._opa = o2; - } else { /*Ptr*/ + } + else { /*Ptr*/ obj->state = prev_state; style_list->skip_trans = 1; const void * p1 = _lv_obj_get_style_ptr(obj, part, prop); @@ -3649,7 +3665,7 @@ static lv_style_trans_t * trans_create(lv_obj_t * obj, lv_style_property_t prop, tr = lv_ll_ins_head(&LV_GC_ROOT(_lv_obj_style_trans_ll)); LV_ASSERT_MEM(tr); if(tr == NULL) return NULL; - tr->start_value._ptr= p1; + tr->start_value._ptr = p1; tr->end_value._ptr = p2; } @@ -3669,9 +3685,9 @@ static void trans_del(lv_obj_t * obj, uint8_t part, lv_style_property_t prop) lv_style_trans_t * tr; lv_style_trans_t * tr_next; tr = lv_ll_get_head(&LV_GC_ROOT(_lv_obj_style_trans_ll)); - while(tr != NULL) { - /*'tr' might be deleted, so get the next object while 'tr' is valid*/ - tr_next = lv_ll_get_next(&LV_GC_ROOT(_lv_obj_style_trans_ll), tr); + while(tr != NULL) { + /*'tr' might be deleted, so get the next object while 'tr' is valid*/ + tr_next = lv_ll_get_next(&LV_GC_ROOT(_lv_obj_style_trans_ll), tr); if(tr->obj == obj && (part == tr->part || part == 0xFF) && (prop == tr->prop || prop == 0xFF)) { lv_anim_del(tr, NULL); @@ -3707,7 +3723,8 @@ static void trans_anim_cb(lv_style_trans_t * tr, lv_anim_value_t v) else if(v >= 255) x = tr->end_value._opa; else x = tr->start_value._opa + (((tr->end_value._opa - tr->start_value._opa) * v) >> 8); _lv_style_set_opa(style, tr->prop, x); - } else { + } + else { const void * x; if(v < 128) x = tr->start_value._ptr; else x = tr->end_value._ptr; @@ -3738,8 +3755,9 @@ static void trans_anim_start_cb(lv_anim_t * a) } else if((prop_tmp & 0xF) < LV_STYLE_ID_PTR) { /*Opa*/ tr->start_value._opa = _lv_obj_get_style_opa(tr->obj, tr->part, prop_tmp); - } else { /*Ptr*/ - tr->start_value._ptr= _lv_obj_get_style_ptr(tr->obj, tr->part, prop_tmp); + } + else { /*Ptr*/ + tr->start_value._ptr = _lv_obj_get_style_ptr(tr->obj, tr->part, prop_tmp); } @@ -3754,7 +3772,7 @@ static void trans_anim_ready_cb(lv_anim_t * a) static void opa_scale_anim(lv_obj_t * obj, lv_anim_value_t v) { - lv_obj_set_style_local_opa_scale(obj, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, v); + lv_obj_set_style_local_opa_scale(obj, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, v); } #endif diff --git a/src/lv_core/lv_obj.h b/src/lv_core/lv_obj.h index c167bb8e6..67741d9a7 100644 --- a/src/lv_core/lv_obj.h +++ b/src/lv_core/lv_obj.h @@ -89,16 +89,16 @@ enum { LV_EVENT_LONG_PRESSED_REPEAT, /**< Called after `LV_INDEV_LONG_PRESS_TIME` in every `LV_INDEV_LONG_PRESS_REP_TIME` ms. Not called if dragged.*/ LV_EVENT_CLICKED, /**< Called on release if not dragged (regardless to long press)*/ - LV_EVENT_RELEASED, /**< Called in every cases when the object has been released*/ - LV_EVENT_DRAG_BEGIN, + LV_EVENT_RELEASED, /**< Called in every cases when the object has been released*/ + LV_EVENT_DRAG_BEGIN, LV_EVENT_DRAG_END, LV_EVENT_DRAG_THROW_BEGIN, - LV_EVENT_GESTURE, /**< The object has been getture*/ + LV_EVENT_GESTURE, /**< The object has been getture*/ LV_EVENT_KEY, LV_EVENT_FOCUSED, LV_EVENT_DEFOCUSED, LV_EVENT_LEAVE, - LV_EVENT_VALUE_CHANGED, /**< The object's value has changed (i.e. slider moved) */ + LV_EVENT_VALUE_CHANGED, /**< The object's value has changed (i.e. slider moved) */ LV_EVENT_INSERT, LV_EVENT_REFRESH, LV_EVENT_APPLY, /**< "Ok", "Apply" or similar specific button has clicked*/ @@ -138,10 +138,10 @@ enum { LV_SIGNAL_RELEASED, /**< User pressed object for a short period of time, then released it. Not called if dragged. */ LV_SIGNAL_LONG_PRESS, /**< Object has been pressed for at least `LV_INDEV_LONG_PRESS_TIME`. Not called if dragged.*/ LV_SIGNAL_LONG_PRESS_REP, /**< Called after `LV_INDEV_LONG_PRESS_TIME` in every `LV_INDEV_LONG_PRESS_REP_TIME` ms. Not called if dragged.*/ - LV_SIGNAL_DRAG_BEGIN, + LV_SIGNAL_DRAG_BEGIN, LV_SIGNAL_DRAG_THROW_BEGIN, - LV_SIGNAL_DRAG_END, - LV_SIGNAL_GESTURE, /**< The object has been gesture*/ + LV_SIGNAL_DRAG_END, + LV_SIGNAL_GESTURE, /**< The object has been gesture*/ LV_SIGNAL_LEAVE, /**< Another object is clicked or chosen via an input device */ /*Group related*/ @@ -155,8 +155,7 @@ typedef uint8_t lv_signal_t; typedef lv_res_t (*lv_signal_cb_t)(struct _lv_obj_t * obj, lv_signal_t sign, void * param); #if LV_USE_OBJ_REALIGN -typedef struct -{ +typedef struct { const struct _lv_obj_t * base; lv_coord_t xofs; lv_coord_t yofs; @@ -193,8 +192,7 @@ enum { typedef uint8_t lv_state_t; -typedef struct _lv_obj_t -{ +typedef struct _lv_obj_t { struct _lv_obj_t * parent; /**< Pointer to the parent object*/ lv_ll_t child_ll; /**< Linked list to store the children objects*/ @@ -217,18 +215,18 @@ typedef struct _lv_obj_t lv_coord_t ext_draw_pad; /**< EXTtend the size in every direction for drawing. */ /*Attributes and states*/ - uint8_t click :1; /**< 1: Can be pressed by an input device*/ - uint8_t drag :1; /**< 1: Enable the dragging*/ - uint8_t drag_throw :1; /**< 1: Enable throwing with drag*/ - uint8_t drag_parent :1; /**< 1: Parent will be dragged instead*/ - uint8_t hidden :1; /**< 1: Object is hidden*/ - uint8_t top :1; /**< 1: If the object or its children is clicked it goes to the foreground*/ - uint8_t parent_event :1; /**< 1: Send the object's events to the parent too. */ - uint8_t adv_hittest :1; /**< 1: Use advanced hit-testing (slower) */ + uint8_t click : 1; /**< 1: Can be pressed by an input device*/ + uint8_t drag : 1; /**< 1: Enable the dragging*/ + uint8_t drag_throw : 1; /**< 1: Enable throwing with drag*/ + uint8_t drag_parent : 1; /**< 1: Parent will be dragged instead*/ + uint8_t hidden : 1; /**< 1: Object is hidden*/ + uint8_t top : 1; /**< 1: If the object or its children is clicked it goes to the foreground*/ + uint8_t parent_event : 1; /**< 1: Send the object's events to the parent too. */ + uint8_t adv_hittest : 1; /**< 1: Use advanced hit-testing (slower) */ uint8_t gesture_parent : 1; /**< 1: Parent will be gesture instead*/ - lv_drag_dir_t drag_dir :3; /**< Which directions the object can be dragged in */ - lv_bidi_dir_t base_dir :2; /**< Base direction of texts related to this object */ + lv_drag_dir_t drag_dir : 3; /**< Which directions the object can be dragged in */ + lv_bidi_dir_t base_dir : 2; /**< Base direction of texts related to this object */ #if LV_USE_GROUP != 0 void * group_p; @@ -258,26 +256,22 @@ enum { typedef uint8_t lv_obj_part_t; /** Used by `lv_obj_get_type()`. The object's and its ancestor types are stored here*/ -typedef struct -{ +typedef struct { const char * type[LV_MAX_ANCESTOR_NUM]; /**< [0]: the actual type, [1]: ancestor, [2] #1's ancestor ... [x]: "lv_obj" */ } lv_obj_type_t; -typedef struct -{ - lv_point_t *point; +typedef struct { + lv_point_t * point; bool result; } lv_hit_test_info_t; -typedef struct -{ +typedef struct { uint8_t part; lv_style_list_t * result; } lv_get_style_info_t; -typedef struct -{ +typedef struct { uint8_t part; lv_state_t result; } lv_get_state_info_t; @@ -334,7 +328,7 @@ void lv_obj_del_anim_ready_cb(lv_anim_t * a); * @param obj object to delete * @see lv_async_call */ -void lv_obj_del_async(struct _lv_obj_t *obj); +void lv_obj_del_async(struct _lv_obj_t * obj); /** * Delete all children of an object @@ -1190,7 +1184,7 @@ lv_event_cb_t lv_obj_get_event_cb(const lv_obj_t * obj); /** * Check if a given screen-space point is on an object's coordinates. - * + * * This method is intended to be used mainly by advanced hit testing algorithms to check * whether the point is even within the object (as an optimization). * @param obj object to check diff --git a/src/lv_core/lv_obj_style_dec.h b/src/lv_core/lv_obj_style_dec.h index 6f9217976..1c991b946 100644 --- a/src/lv_core/lv_obj_style_dec.h +++ b/src/lv_core/lv_obj_style_dec.h @@ -60,41 +60,41 @@ extern "C" { #define _LV_OBJ_STYLE_DECLARE_GET_scalar(prop_name, func_name, value_type, style_type) \ -static inline value_type lv_obj_get_style_##func_name (const lv_obj_t * obj, uint8_t part) \ -{ \ - return (value_type) _lv_obj_get_style##style_type (obj, part, LV_STYLE_##prop_name); \ -} + static inline value_type lv_obj_get_style_##func_name (const lv_obj_t * obj, uint8_t part) \ + { \ + return (value_type) _lv_obj_get_style##style_type (obj, part, LV_STYLE_##prop_name); \ + } #define _LV_OBJ_STYLE_DECLARE_GET_nonscalar(prop_name, func_name, value_type, style_type) \ -static inline value_type lv_obj_get_style_##func_name (const lv_obj_t * obj, uint8_t part) \ -{ \ - return _lv_obj_get_style##style_type (obj, part, LV_STYLE_##prop_name); \ -} + static inline value_type lv_obj_get_style_##func_name (const lv_obj_t * obj, uint8_t part) \ + { \ + return _lv_obj_get_style##style_type (obj, part, LV_STYLE_##prop_name); \ + } #define _LV_OBJ_STYLE_SET_GET_DECLARE(prop_name, func_name, value_type, style_type, scalar) \ -_LV_OBJ_STYLE_DECLARE_GET_##scalar(prop_name, func_name, value_type, style_type) \ -static inline void lv_obj_set_style_local_##func_name (lv_obj_t * obj, uint8_t part, lv_state_t state, value_type value) \ -{ \ - _lv_obj_set_style_local##style_type (obj, part, LV_STYLE_##prop_name | (state << LV_STYLE_STATE_POS), value); \ -} \ -static inline void lv_obj_get_style_local_##func_name (lv_obj_t * obj, uint8_t part, lv_state_t state, void * res) \ -{ \ - _lv_style_get##style_type (lv_obj_get_local_style(obj, part), LV_STYLE_##prop_name | (state << LV_STYLE_STATE_POS), res); \ -} \ -static inline void lv_obj_remove_style_local_##func_name (lv_obj_t * obj, uint8_t part, lv_state_t state) \ -{ \ - _lv_obj_remove_style_local_prop(obj, part, LV_STYLE_##prop_name | (state << LV_STYLE_STATE_POS)); \ -} \ -static inline int16_t lv_style_get_##func_name (lv_style_t * style, lv_state_t state, void * res) \ -{ \ - return _lv_style_get##style_type (style, LV_STYLE_##prop_name | (state << LV_STYLE_STATE_POS), res); \ -} \ -static inline void lv_style_set_##func_name (lv_style_t * style, lv_state_t state, value_type value) \ -{ \ - _lv_style_set##style_type (style, LV_STYLE_##prop_name | (state << LV_STYLE_STATE_POS), value); \ -} + _LV_OBJ_STYLE_DECLARE_GET_##scalar(prop_name, func_name, value_type, style_type) \ + static inline void lv_obj_set_style_local_##func_name (lv_obj_t * obj, uint8_t part, lv_state_t state, value_type value) \ + { \ + _lv_obj_set_style_local##style_type (obj, part, LV_STYLE_##prop_name | (state << LV_STYLE_STATE_POS), value); \ + } \ + static inline void lv_obj_get_style_local_##func_name (lv_obj_t * obj, uint8_t part, lv_state_t state, void * res) \ + { \ + _lv_style_get##style_type (lv_obj_get_local_style(obj, part), LV_STYLE_##prop_name | (state << LV_STYLE_STATE_POS), res); \ + } \ + static inline void lv_obj_remove_style_local_##func_name (lv_obj_t * obj, uint8_t part, lv_state_t state) \ + { \ + _lv_obj_remove_style_local_prop(obj, part, LV_STYLE_##prop_name | (state << LV_STYLE_STATE_POS)); \ + } \ + static inline int16_t lv_style_get_##func_name (lv_style_t * style, lv_state_t state, void * res) \ + { \ + return _lv_style_get##style_type (style, LV_STYLE_##prop_name | (state << LV_STYLE_STATE_POS), res); \ + } \ + static inline void lv_style_set_##func_name (lv_style_t * style, lv_state_t state, value_type value) \ + { \ + _lv_style_set##style_type (style, LV_STYLE_##prop_name | (state << LV_STYLE_STATE_POS), value); \ + } -_LV_OBJ_STYLE_SET_GET_DECLARE(RADIUS, radius, lv_style_int_t,_int, scalar) +_LV_OBJ_STYLE_SET_GET_DECLARE(RADIUS, radius, lv_style_int_t, _int, scalar) _LV_OBJ_STYLE_SET_GET_DECLARE(CLIP_CORNER, clip_corner, bool, _int, scalar) _LV_OBJ_STYLE_SET_GET_DECLARE(SIZE, size, lv_style_int_t, _int, scalar) _LV_OBJ_STYLE_SET_GET_DECLARE(TRANSFORM_WIDTH, transform_width, lv_style_int_t, _int, scalar) @@ -111,7 +111,7 @@ _LV_OBJ_STYLE_SET_GET_DECLARE(BG_GRAD_STOP, bg_grad_stop, lv_style_int_t, _int, _LV_OBJ_STYLE_SET_GET_DECLARE(BG_GRAD_DIR, bg_grad_dir, lv_grad_dir_t, _int, scalar) _LV_OBJ_STYLE_SET_GET_DECLARE(BG_COLOR, bg_color, lv_color_t, _color, nonscalar) _LV_OBJ_STYLE_SET_GET_DECLARE(BG_GRAD_COLOR, bg_grad_color, lv_color_t, _color, nonscalar) -_LV_OBJ_STYLE_SET_GET_DECLARE(BG_OPA, bg_opa, lv_opa_t , _opa, scalar) +_LV_OBJ_STYLE_SET_GET_DECLARE(BG_OPA, bg_opa, lv_opa_t, _opa, scalar) _LV_OBJ_STYLE_SET_GET_DECLARE(BORDER_WIDTH, border_width, lv_style_int_t, _int, scalar) _LV_OBJ_STYLE_SET_GET_DECLARE(BORDER_SIDE, border_side, lv_border_side_t, _int, scalar) _LV_OBJ_STYLE_SET_GET_DECLARE(BORDER_BLEND_MODE, border_blend_mode, lv_blend_mode_t, _int, scalar) @@ -144,8 +144,8 @@ _LV_OBJ_STYLE_SET_GET_DECLARE(VALUE_OFS_Y, value_ofs_y, lv_style_int_t, _int, sc _LV_OBJ_STYLE_SET_GET_DECLARE(VALUE_ALIGN, value_align, lv_align_t, _int, scalar) _LV_OBJ_STYLE_SET_GET_DECLARE(VALUE_COLOR, value_color, lv_color_t, _color, nonscalar) _LV_OBJ_STYLE_SET_GET_DECLARE(VALUE_OPA, value_opa, lv_opa_t, _opa, scalar) -_LV_OBJ_STYLE_SET_GET_DECLARE(VALUE_FONT, value_font, const lv_font_t * , _ptr, scalar) -_LV_OBJ_STYLE_SET_GET_DECLARE(VALUE_STR, value_str, const char * , _ptr, scalar) +_LV_OBJ_STYLE_SET_GET_DECLARE(VALUE_FONT, value_font, const lv_font_t *, _ptr, scalar) +_LV_OBJ_STYLE_SET_GET_DECLARE(VALUE_STR, value_str, const char *, _ptr, scalar) _LV_OBJ_STYLE_SET_GET_DECLARE(TEXT_LETTER_SPACE, text_letter_space, lv_style_int_t, _int, scalar) _LV_OBJ_STYLE_SET_GET_DECLARE(TEXT_LINE_SPACE, text_line_space, lv_style_int_t, _int, scalar) _LV_OBJ_STYLE_SET_GET_DECLARE(TEXT_DECOR, text_decor, lv_text_decor_t, _int, scalar) @@ -153,7 +153,7 @@ _LV_OBJ_STYLE_SET_GET_DECLARE(TEXT_BLEND_MODE, text_blend_mode, lv_blend_mode_t, _LV_OBJ_STYLE_SET_GET_DECLARE(TEXT_COLOR, text_color, lv_color_t, _color, nonscalar) _LV_OBJ_STYLE_SET_GET_DECLARE(TEXT_SEL_COLOR, text_sel_color, lv_color_t, _color, nonscalar) _LV_OBJ_STYLE_SET_GET_DECLARE(TEXT_OPA, text_opa, lv_opa_t, _opa, scalar) -_LV_OBJ_STYLE_SET_GET_DECLARE(TEXT_FONT, text_font, const lv_font_t * , _ptr, scalar) +_LV_OBJ_STYLE_SET_GET_DECLARE(TEXT_FONT, text_font, const lv_font_t *, _ptr, scalar) _LV_OBJ_STYLE_SET_GET_DECLARE(LINE_WIDTH, line_width, lv_style_int_t, _int, scalar) _LV_OBJ_STYLE_SET_GET_DECLARE(LINE_BLEND_MODE, line_blend_mode, lv_blend_mode_t, _int, scalar) _LV_OBJ_STYLE_SET_GET_DECLARE(LINE_DASH_WIDTH, line_dash_width, lv_style_int_t, _int, scalar) @@ -174,9 +174,9 @@ _LV_OBJ_STYLE_SET_GET_DECLARE(TRANSITION_PROP_4, transition_prop_4, lv_style_int _LV_OBJ_STYLE_SET_GET_DECLARE(TRANSITION_PROP_5, transition_prop_5, lv_style_int_t, _int, scalar) _LV_OBJ_STYLE_SET_GET_DECLARE(TRANSITION_PROP_6, transition_prop_6, lv_style_int_t, _int, scalar) #if LV_USE_ANIMATION -_LV_OBJ_STYLE_SET_GET_DECLARE(TRANSITION_PATH, transition_path, lv_anim_path_cb_t , _ptr, scalar) +_LV_OBJ_STYLE_SET_GET_DECLARE(TRANSITION_PATH, transition_path, lv_anim_path_cb_t, _ptr, scalar) #else -_LV_OBJ_STYLE_SET_GET_DECLARE(TRANSITION_PATH, transition_path, void * , _ptr, scalar) /*For compatibility*/ +_LV_OBJ_STYLE_SET_GET_DECLARE(TRANSITION_PATH, transition_path, void *, _ptr, scalar) /*For compatibility*/ #endif _LV_OBJ_STYLE_SET_GET_DECLARE(SCALE_WIDTH, scale_width, lv_style_int_t, _int, scalar) _LV_OBJ_STYLE_SET_GET_DECLARE(SCALE_BORDER_WIDTH, scale_border_width, lv_style_int_t, _int, scalar) diff --git a/src/lv_core/lv_refr.c b/src/lv_core/lv_refr.c index d16b2a03e..32c113d7d 100644 --- a/src/lv_core/lv_refr.c +++ b/src/lv_core/lv_refr.c @@ -17,7 +17,7 @@ #include "../lv_draw/lv_draw.h" #if defined(LV_GC_INCLUDE) -#include LV_GC_INCLUDE + #include LV_GC_INCLUDE #endif /* LV_ENABLE_GC */ /********************* @@ -74,12 +74,13 @@ void lv_refr_init(void) void lv_refr_now(lv_disp_t * disp) { #if LV_USE_ANIMATION - lv_anim_refr_now(); + lv_anim_refr_now(); #endif if(disp) { lv_disp_refr_task(disp->refr_task); - } else { + } + else { lv_disp_t * d; d = lv_disp_get_next(NULL); while(d) { @@ -130,12 +131,13 @@ void lv_inv_area(lv_disp_t * disp, const lv_area_t * area_p) /*Save the area*/ if(disp->inv_p < LV_INV_BUF_SIZE) { lv_area_copy(&disp->inv_areas[disp->inv_p], &com_area); - } else { /*If no place for the area add the screen*/ + } + else { /*If no place for the area add the screen*/ disp->inv_p = 0; lv_area_copy(&disp->inv_areas[disp->inv_p], &scr_area); } disp->inv_p++; - lv_task_set_prio(disp->refr_task, LV_REFR_TASK_PRIO); + lv_task_set_prio(disp->refr_task, LV_REFR_TASK_PRIO); } } @@ -169,16 +171,16 @@ void lv_disp_refr_task(lv_task_t * task) uint32_t start = lv_tick_get(); - /* Ensure the task does not run again automatically. + /* Ensure the task does not run again automatically. * This is done before refreshing in case refreshing invalidates something else. */ - lv_task_set_prio(task, LV_TASK_PRIO_OFF); + lv_task_set_prio(task, LV_TASK_PRIO_OFF); disp_refr = task->user_data; -// extern rect_cache_t cache[]; -// extern uint32_t cp; + // extern rect_cache_t cache[]; + // extern uint32_t cp; lv_refr_join_area(); @@ -348,7 +350,8 @@ static void lv_refr_area(const lv_area_t * area_p) LV_LOG_WARN("Can't set VDB height using the round function. (Wrong round_cb or to " "small VDB)"); return; - } else { + } + else { max_row = tmp.y2 + 1; } } @@ -433,12 +436,12 @@ static lv_obj_t * lv_refr_get_top_obj(const lv_area_t * area_p, lv_obj_t * obj) /*If this object is fully cover the draw area check the children too */ if(lv_area_is_in(area_p, &obj->coords, 0) && obj->hidden == 0) { - lv_design_res_t design_res = obj->design_cb ? obj->design_cb(obj, area_p, LV_DESIGN_COVER_CHK) : LV_DESIGN_RES_NOT_COVER; + lv_design_res_t design_res = obj->design_cb ? obj->design_cb(obj, area_p, + LV_DESIGN_COVER_CHK) : LV_DESIGN_RES_NOT_COVER; if(design_res == LV_DESIGN_RES_MASKED) return NULL; lv_obj_t * i; - LV_LL_READ(obj->child_ll, i) - { + LV_LL_READ(obj->child_ll, i) { found_p = lv_refr_get_top_obj(area_p, i); /*If a children is ok then break*/ @@ -555,8 +558,7 @@ static void lv_refr_obj(lv_obj_t * obj, const lv_area_t * mask_ori_p) lv_area_t mask_child; /*Mask from obj and its child*/ lv_obj_t * child_p; lv_area_t child_area; - LV_LL_READ_BACK(obj->child_ll, child_p) - { + LV_LL_READ_BACK(obj->child_ll, child_p) { lv_obj_get_coords(child_p, &child_area); ext_size = child_p->ext_draw_pad; child_area.x1 -= ext_size; diff --git a/src/lv_core/lv_style.c b/src/lv_core/lv_style.c index cef64183a..78c39caf9 100644 --- a/src/lv_core/lv_style.c +++ b/src/lv_core/lv_style.c @@ -106,8 +106,7 @@ bool lv_style_remove_prop(lv_style_t * style, lv_style_property_t prop) attr_found.full = *(style->map + id + 1); attr_goal.full = (prop >> 8) & 0xFFU; - if(attr_found.bits.state == attr_goal.bits.state) - { + if(attr_found.bits.state == attr_goal.bits.state) { uint32_t map_size = lv_style_get_mem_size(style); uint8_t prop_size = sizeof(lv_style_property_t); if((prop & 0xF) < LV_STYLE_ID_COLOR) prop_size += sizeof(lv_style_int_t); @@ -162,17 +161,20 @@ void lv_style_list_copy(lv_style_list_t * list_dest, const lv_style_list_t * lis list_dest->style_list = lv_mem_alloc((list_src->style_cnt - 1) * sizeof(lv_style_t *)); memcpy(list_dest->style_list, list_src->style_list + 1, (list_src->style_cnt - 1) * sizeof(lv_style_t *)); list_dest->style_cnt = list_src->style_cnt - 1; - } else { + } + else { list_dest->style_list = lv_mem_alloc(list_src->style_cnt * sizeof(lv_style_t *)); memcpy(list_dest->style_list, list_src->style_list, list_src->style_cnt * sizeof(lv_style_t *)); list_dest->style_cnt = list_src->style_cnt; } - } else { + } + else { if(list_src->has_trans) { list_dest->style_list = lv_mem_alloc((list_src->style_cnt - 2) * sizeof(lv_style_t *)); memcpy(list_dest->style_list, list_src->style_list + 2, (list_src->style_cnt - 2) * sizeof(lv_style_t *)); list_dest->style_cnt = list_src->style_cnt - 2; - } else { + } + else { list_dest->style_list = lv_mem_alloc((list_src->style_cnt - 1) * sizeof(lv_style_t *)); memcpy(list_dest->style_list, list_src->style_list + 1, (list_src->style_cnt - 1) * sizeof(lv_style_t *)); list_dest->style_cnt = list_src->style_cnt - 1; @@ -336,10 +338,10 @@ uint16_t lv_style_get_mem_size(const lv_style_t * style) size_t i = 0; while(style->map[i] != _LV_STYLE_CLOSEING_PROP) { /*Go to the next property*/ - if((style->map[i] & 0xF) < LV_STYLE_ID_COLOR) i+= sizeof(lv_style_int_t); - else if((style->map[i] & 0xF) < LV_STYLE_ID_OPA) i+= sizeof(lv_color_t); - else if((style->map[i] & 0xF) < LV_STYLE_ID_PTR) i+= sizeof(lv_opa_t); - else i+= sizeof(void*); + if((style->map[i] & 0xF) < LV_STYLE_ID_COLOR) i += sizeof(lv_style_int_t); + else if((style->map[i] & 0xF) < LV_STYLE_ID_OPA) i += sizeof(lv_color_t); + else if((style->map[i] & 0xF) < LV_STYLE_ID_PTR) i += sizeof(lv_opa_t); + else i += sizeof(void *); i += sizeof(lv_style_property_t); } @@ -388,7 +390,7 @@ void _lv_style_set_int(lv_style_t * style, lv_style_property_t prop, lv_style_in LV_ASSERT_MEM(style->map); if(style == NULL) return; - memcpy(style->map + size - new_prop_size - end_mark_size , &prop, sizeof(lv_style_property_t)); + memcpy(style->map + size - new_prop_size - end_mark_size, &prop, sizeof(lv_style_property_t)); memcpy(style->map + size - sizeof(lv_style_int_t) - end_mark_size, &value, sizeof(lv_style_int_t)); memcpy(style->map + size - end_mark_size, &end_mark, sizeof(end_mark)); } @@ -529,8 +531,8 @@ void _lv_style_set_ptr(lv_style_t * style, lv_style_property_t prop, const void LV_ASSERT_MEM(style->map); if(style == NULL) return; - memcpy(style->map + size - new_prop_size - end_mark_size , &prop, sizeof(lv_style_property_t)); - memcpy(style->map + size - sizeof(void *) - end_mark_size , &p, sizeof(void *)); + memcpy(style->map + size - new_prop_size - end_mark_size, &prop, sizeof(lv_style_property_t)); + memcpy(style->map + size - sizeof(void *) - end_mark_size, &p, sizeof(void *)); memcpy(style->map + size - end_mark_size, &end_mark, sizeof(end_mark)); } @@ -554,7 +556,8 @@ int16_t _lv_style_get_int(const lv_style_t * style, lv_style_property_t prop, vo int32_t id = get_property_index(style, prop); if(id < 0) { return -1; - } else { + } + else { memcpy(res, &style->map[id + sizeof(lv_style_property_t)], sizeof(lv_style_int_t)); lv_style_attr_t attr_act; attr_act.full = style->map[id + 1]; @@ -589,7 +592,8 @@ int16_t _lv_style_get_opa(const lv_style_t * style, lv_style_property_t prop, vo int32_t id = get_property_index(style, prop); if(id < 0) { return -1; - } else { + } + else { memcpy(res, &style->map[id + sizeof(lv_style_property_t)], sizeof(lv_opa_t)); lv_style_attr_t attr_act; attr_act.full = style->map[id + 1]; @@ -622,7 +626,8 @@ int16_t _lv_style_get_color(const lv_style_t * style, lv_style_property_t prop, int32_t id = get_property_index(style, prop); if(id < 0) { return -1; - } else { + } + else { memcpy(res, &style->map[id + sizeof(lv_style_property_t)], sizeof(lv_color_t)); lv_style_attr_t attr_act; attr_act.full = style->map[id + 1]; @@ -649,14 +654,15 @@ int16_t _lv_style_get_color(const lv_style_t * style, lv_style_property_t prop, */ int16_t _lv_style_get_ptr(const lv_style_t * style, lv_style_property_t prop, void * v_res) { - void **res = (void *)v_res; + void ** res = (void *)v_res; if(style == NULL) return -1; if(style->map == NULL) return -1; int32_t id = get_property_index(style, prop); if(id < 0) { return -1; - } else { - memcpy(res, &style->map[id + sizeof(lv_style_property_t)], sizeof(void*)); + } + else { + memcpy(res, &style->map[id + sizeof(lv_style_property_t)], sizeof(void *)); lv_style_attr_t attr_act; attr_act.full = style->map[id + 1]; @@ -1021,8 +1027,8 @@ static inline int32_t get_property_index(const lv_style_t * style, lv_style_prop size_t i = 0; while(style->map[i] != _LV_STYLE_CLOSEING_PROP) { if(style->map[i] == id_to_find) { - lv_style_attr_t attr_i; - attr_i.full = style->map[i + 1]; + lv_style_attr_t attr_i; + attr_i.full = style->map[i + 1]; /*If the state perfectly matches return this property*/ if(attr_i.bits.state == attr.bits.state) { @@ -1041,10 +1047,10 @@ static inline int32_t get_property_index(const lv_style_t * style, lv_style_prop } /*Go to the next property*/ - if((style->map[i] & 0xF) < LV_STYLE_ID_COLOR) i+= sizeof(lv_style_int_t); - else if((style->map[i] & 0xF) < LV_STYLE_ID_OPA) i+= sizeof(lv_color_t); - else if((style->map[i] & 0xF) < LV_STYLE_ID_PTR) i+= sizeof(lv_opa_t); - else i+= sizeof(void*); + if((style->map[i] & 0xF) < LV_STYLE_ID_COLOR) i += sizeof(lv_style_int_t); + else if((style->map[i] & 0xF) < LV_STYLE_ID_OPA) i += sizeof(lv_color_t); + else if((style->map[i] & 0xF) < LV_STYLE_ID_PTR) i += sizeof(lv_opa_t); + else i += sizeof(void *); i += sizeof(lv_style_property_t); } diff --git a/src/lv_core/lv_style.h b/src/lv_core/lv_style.h index a4c2de6e0..7c9a34a2a 100644 --- a/src/lv_core/lv_style.h +++ b/src/lv_core/lv_style.h @@ -79,11 +79,11 @@ typedef uint8_t lv_text_decor_t; typedef union { struct { - uint8_t state :7; /* To which state the property refers to*/ - uint8_t inherit :1; /*1: The property can be inherited*/ - }bits; + uint8_t state : 7; /* To which state the property refers to*/ + uint8_t inherit : 1; /*1: The property can be inherited*/ + } bits; uint8_t full; -}lv_style_attr_t; +} lv_style_attr_t; #define LV_STYLE_ID_VALUE 0x0 /*max 8 pcs*/ @@ -205,7 +205,7 @@ typedef struct { #if LV_USE_ASSERT_STYLE uint32_t sentinel; #endif -}lv_style_t; +} lv_style_t; typedef int16_t lv_style_int_t; @@ -216,11 +216,11 @@ typedef struct { uint32_t sentinel; #endif uint8_t style_cnt; - uint8_t has_local :1; - uint8_t has_trans :1; - uint8_t skip_trans :1; /*1: Temporally skip the transition style if any*/ - uint8_t ignore_trans :1; /*1: Mark that this style list shouldn't receive transitions at all*/ -}lv_style_list_t; + uint8_t has_local : 1; + uint8_t has_trans : 1; + uint8_t skip_trans : 1; /*1: Temporally skip the transition style if any*/ + uint8_t ignore_trans : 1; /*1: Mark that this style list shouldn't receive transitions at all*/ +} lv_style_list_t; /********************** * GLOBAL PROTOTYPES diff --git a/src/lv_draw/lv_draw_arc.c b/src/lv_draw/lv_draw_arc.c index e7c5a1cd5..6be0b1aa1 100644 --- a/src/lv_draw/lv_draw_arc.c +++ b/src/lv_draw/lv_draw_arc.c @@ -32,16 +32,16 @@ typedef struct { lv_draw_rect_dsc_t * draw_dsc; const lv_area_t * draw_area; const lv_area_t * clip_area; -}quarter_draw_dsc_t; +} quarter_draw_dsc_t; /********************** * STATIC PROTOTYPES **********************/ -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 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 tickness, lv_area_t * res_area); @@ -68,7 +68,8 @@ static void get_rounded_area(int16_t angle, lv_coord_t radius, uint8_t tickness, * @param style style of the arc (`body.thickness`, `body.main_color`, `body.opa` is used) * @param opa_scale scale down all opacities by the factor */ -void lv_draw_arc(lv_coord_t center_x, lv_coord_t center_y, uint16_t radius, uint16_t start_angle, uint16_t end_angle, const lv_area_t * clip_area, lv_draw_line_dsc_t * dsc) +void lv_draw_arc(lv_coord_t center_x, lv_coord_t center_y, uint16_t radius, uint16_t start_angle, uint16_t end_angle, + const lv_area_t * clip_area, lv_draw_line_dsc_t * dsc) { if(dsc->opa <= LV_OPA_MIN) return; if(dsc->width == 0) return; @@ -104,7 +105,8 @@ void lv_draw_arc(lv_coord_t center_x, lv_coord_t center_y, uint16_t radius, uin int32_t angle_gap; if(end_angle > start_angle) { angle_gap = 360 - (end_angle - start_angle); - } else { + } + else { angle_gap = start_angle - end_angle; } if(angle_gap > SPLIT_ANGLE_GAP_LIMIT && radius > SPLIT_RADIUS_LIMIT) { @@ -115,7 +117,7 @@ void lv_draw_arc(lv_coord_t center_x, lv_coord_t center_y, uint16_t radius, uin q_dsc.radius = radius; q_dsc.start_angle = start_angle; q_dsc.end_angle = end_angle; - q_dsc.start_quarter= (start_angle / 90) & 0x3; + q_dsc.start_quarter = (start_angle / 90) & 0x3; q_dsc.end_quarter = (end_angle / 90) & 0x3; q_dsc.width = dsc->width; q_dsc.draw_dsc = &cir_dsc; @@ -126,7 +128,8 @@ void lv_draw_arc(lv_coord_t center_x, lv_coord_t center_y, uint16_t radius, uin draw_quarter_1(&q_dsc); draw_quarter_2(&q_dsc); draw_quarter_3(&q_dsc); - } else { + } + else { lv_draw_rect(&area, clip_area, &cir_dsc); } lv_draw_mask_remove_id(mask_angle_id); @@ -191,7 +194,7 @@ static void draw_quarter_0(quarter_draw_dsc_t * q) bool ok = lv_area_intersect(&quarter_area, &quarter_area, q->clip_area); if(ok) lv_draw_rect(q->draw_area, &quarter_area, q->draw_dsc); } - if(q->end_quarter == 0) { + if(q->end_quarter == 0) { quarter_area.x2 = q->center_x + q->radius; quarter_area.y1 = q->center_y; @@ -244,12 +247,12 @@ static void draw_quarter_1(quarter_draw_dsc_t * q) bool ok = lv_area_intersect(&quarter_area, &quarter_area, q->clip_area); if(ok) lv_draw_rect(q->draw_area, &quarter_area, q->draw_dsc); } - if(q->end_quarter == 1) { + if(q->end_quarter == 1) { quarter_area.x2 = q->center_x - 1; quarter_area.y2 = q->center_y + q->radius; - quarter_area.y1 = q->center_y + ((lv_trigo_sin(q->end_angle) * (q->radius- q->width)) >> LV_TRIGO_SHIFT); - quarter_area.x1 = q->center_x + ((lv_trigo_sin(q->end_angle + 90) * (q->radius )) >> LV_TRIGO_SHIFT); + quarter_area.y1 = q->center_y + ((lv_trigo_sin(q->end_angle) * (q->radius - q->width)) >> LV_TRIGO_SHIFT); + quarter_area.x1 = q->center_x + ((lv_trigo_sin(q->end_angle + 90) * (q->radius)) >> LV_TRIGO_SHIFT); bool ok = lv_area_intersect(&quarter_area, &quarter_area, q->clip_area); if(ok) lv_draw_rect(q->draw_area, &quarter_area, q->draw_dsc); @@ -291,13 +294,13 @@ static void draw_quarter_2(quarter_draw_dsc_t * q) quarter_area.x2 = q->center_x - 1; quarter_area.y1 = q->center_y - q->radius; - quarter_area.x1 = q->center_x + ((lv_trigo_sin(q->start_angle + 90) * (q->radius )) >> LV_TRIGO_SHIFT); - quarter_area.y2 = q->center_y + ((lv_trigo_sin(q->start_angle) * (q->radius- q->width)) >> LV_TRIGO_SHIFT); + quarter_area.x1 = q->center_x + ((lv_trigo_sin(q->start_angle + 90) * (q->radius)) >> LV_TRIGO_SHIFT); + quarter_area.y2 = q->center_y + ((lv_trigo_sin(q->start_angle) * (q->radius - q->width)) >> LV_TRIGO_SHIFT); bool ok = lv_area_intersect(&quarter_area, &quarter_area, q->clip_area); if(ok) lv_draw_rect(q->draw_area, &quarter_area, q->draw_dsc); } - if(q->end_quarter == 2) { + if(q->end_quarter == 2) { quarter_area.x1 = q->center_x - q->radius; quarter_area.y2 = q->center_y - 1; @@ -351,7 +354,7 @@ static void draw_quarter_3(quarter_draw_dsc_t * q) bool ok = lv_area_intersect(&quarter_area, &quarter_area, q->clip_area); if(ok) lv_draw_rect(q->draw_area, &quarter_area, q->draw_dsc); } - if(q->end_quarter == 3) { + if(q->end_quarter == 3) { quarter_area.x1 = q->center_x; quarter_area.y1 = q->center_y - q->radius; diff --git a/src/lv_draw/lv_draw_arc.h b/src/lv_draw/lv_draw_arc.h index 22e3faac3..7e1352eb9 100644 --- a/src/lv_draw/lv_draw_arc.h +++ b/src/lv_draw/lv_draw_arc.h @@ -38,7 +38,8 @@ extern "C" { * @param style style of the arc (`body.thickness`, `body.main_color`, `body.opa` is used) * @param opa_scale scale down all opacities by the factor */ -void lv_draw_arc(lv_coord_t center_x, lv_coord_t center_y, uint16_t radius, uint16_t start_angle, uint16_t end_angle, const lv_area_t * clip_area, lv_draw_line_dsc_t * dsc); +void lv_draw_arc(lv_coord_t center_x, lv_coord_t center_y, uint16_t radius, uint16_t start_angle, uint16_t end_angle, + const lv_area_t * clip_area, lv_draw_line_dsc_t * dsc); /********************** * MACROS diff --git a/src/lv_draw/lv_draw_blend.c b/src/lv_draw/lv_draw_blend.c index 0e2378177..9f2a23e84 100644 --- a/src/lv_draw/lv_draw_blend.c +++ b/src/lv_draw/lv_draw_blend.c @@ -28,28 +28,28 @@ **********************/ static void fill_set_px(const lv_area_t * disp_area, lv_color_t * disp_buf, const lv_area_t * draw_area, - lv_color_t color, lv_opa_t opa, - const lv_opa_t * mask, lv_draw_mask_res_t mask_res); + lv_color_t color, lv_opa_t opa, + const lv_opa_t * mask, lv_draw_mask_res_t mask_res); static void fill_normal(const lv_area_t * disp_area, lv_color_t * disp_buf, const lv_area_t * draw_area, - lv_color_t color, lv_opa_t opa, - const lv_opa_t * mask, lv_draw_mask_res_t mask_res); + lv_color_t color, lv_opa_t opa, + const lv_opa_t * mask, lv_draw_mask_res_t mask_res); static void fill_blended(const lv_area_t * disp_area, lv_color_t * disp_buf, const lv_area_t * draw_area, - lv_color_t color, lv_opa_t opa, - const lv_opa_t * mask, lv_draw_mask_res_t mask_res, lv_blend_mode_t mode); + lv_color_t color, lv_opa_t opa, + const lv_opa_t * mask, lv_draw_mask_res_t mask_res, lv_blend_mode_t mode); static void map_set_px(const lv_area_t * disp_area, lv_color_t * disp_buf, const lv_area_t * draw_area, - const lv_area_t * map_area, const lv_color_t * map_buf, lv_opa_t opa, - const lv_opa_t * mask, lv_draw_mask_res_t mask_res); + const lv_area_t * map_area, const lv_color_t * map_buf, lv_opa_t opa, + const lv_opa_t * mask, lv_draw_mask_res_t mask_res); static void map_normal(const lv_area_t * disp_area, lv_color_t * disp_buf, const lv_area_t * draw_area, - const lv_area_t * map_area, const lv_color_t * map_buf, lv_opa_t opa, - const lv_opa_t * mask, lv_draw_mask_res_t mask_res); + const lv_area_t * map_area, const lv_color_t * map_buf, lv_opa_t opa, + const lv_opa_t * mask, lv_draw_mask_res_t mask_res); static void map_blended(const lv_area_t * disp_area, lv_color_t * disp_buf, const lv_area_t * draw_area, - const lv_area_t * map_area, const lv_color_t * map_buf, lv_opa_t opa, - const lv_opa_t * mask, lv_draw_mask_res_t mask_res, lv_blend_mode_t mode); + const lv_area_t * map_area, const lv_color_t * map_buf, lv_opa_t opa, + const lv_opa_t * mask, lv_draw_mask_res_t mask_res, lv_blend_mode_t mode); static inline lv_color_t color_blend_true_color_additive(lv_color_t fg, lv_color_t bg, lv_opa_t opa); static inline lv_color_t color_blend_true_color_subtractive(lv_color_t fg, lv_color_t bg, lv_opa_t opa); @@ -81,8 +81,8 @@ static inline lv_color_t color_blend_true_color_subtractive(lv_color_t fg, lv_co * @param mode */ void lv_blend_fill(const lv_area_t * clip_area, const lv_area_t * fill_area, - lv_color_t color, lv_opa_t * mask, lv_draw_mask_res_t mask_res, lv_opa_t opa, - lv_blend_mode_t mode) + lv_color_t color, lv_opa_t * mask, lv_draw_mask_res_t mask_res, lv_opa_t opa, + lv_blend_mode_t mode) { /*Do not draw transparent things*/ if(opa < LV_OPA_MIN) return; @@ -112,7 +112,7 @@ void lv_blend_fill(const lv_area_t * clip_area, const lv_area_t * fill_area, 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; + for(i = 0; i < mask_w; i++) mask[i] = mask[i] > 128 ? LV_OPA_COVER : LV_OPA_TRANSP; } if(disp->driver.set_px_cb) { @@ -128,8 +128,8 @@ void lv_blend_fill(const lv_area_t * clip_area, const lv_area_t * fill_area, void lv_blend_map(const lv_area_t * clip_area, const lv_area_t * map_area, const lv_color_t * map_buf, - lv_opa_t * mask, lv_draw_mask_res_t mask_res, - lv_opa_t opa, lv_blend_mode_t mode) + lv_opa_t * mask, lv_draw_mask_res_t mask_res, + lv_opa_t opa, lv_blend_mode_t mode) { /*Do not draw transparent things*/ if(opa < LV_OPA_MIN) return; @@ -158,14 +158,15 @@ void lv_blend_map(const lv_area_t * clip_area, const lv_area_t * map_area, const 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; + for(i = 0; i < mask_w; i++) mask[i] = mask[i] > 128 ? LV_OPA_COVER : LV_OPA_TRANSP; } if(disp->driver.set_px_cb) { map_set_px(disp_area, disp_buf, &draw_area, map_area, map_buf, opa, mask, mask_res); } else if(mode == LV_BLEND_MODE_NORMAL) { map_normal(disp_area, disp_buf, &draw_area, map_area, map_buf, opa, mask, mask_res); - } else { + } + else { map_blended(disp_area, disp_buf, &draw_area, map_area, map_buf, opa, mask, mask_res, mode); } } @@ -176,8 +177,8 @@ void lv_blend_map(const lv_area_t * clip_area, const lv_area_t * map_area, const **********************/ static void fill_set_px(const lv_area_t * disp_area, lv_color_t * disp_buf, const lv_area_t * draw_area, - lv_color_t color, lv_opa_t opa, - const lv_opa_t * mask, lv_draw_mask_res_t mask_res) + lv_color_t color, lv_opa_t opa, + const lv_opa_t * mask, lv_draw_mask_res_t mask_res) { lv_disp_t * disp = lv_refr_get_disp_refreshing(); @@ -191,10 +192,11 @@ static void fill_set_px(const lv_area_t * disp_area, lv_color_t * disp_buf, con if(mask_res == LV_DRAW_MASK_RES_FULL_COVER) { for(y = draw_area->y1; y <= draw_area->y2; y++) { for(x = draw_area->x1; x <= draw_area->x2; x++) { - disp->driver.set_px_cb(&disp->driver, (void*)disp_buf, disp_w, x, y, color, opa); + disp->driver.set_px_cb(&disp->driver, (void *)disp_buf, disp_w, x, y, color, opa); } } - } else { + } + else { /* The mask is relative to the clipped area. * In the cycles below mask will be indexed from `draw_area.x1` * but it corresponds to zero index. So prepare `mask_tmp` accordingly. */ @@ -205,7 +207,8 @@ static void fill_set_px(const lv_area_t * disp_area, lv_color_t * disp_buf, con for(y = draw_area->y1; y <= draw_area->y2; y++) { for(x = draw_area->x1; x <= draw_area->x2; 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); + disp->driver.set_px_cb(&disp->driver, (void *)disp_buf, disp_w, x, y, color, + (uint32_t)((uint32_t)opa * mask_tmp[x]) >> 8); } mask_tmp += draw_area_w; } @@ -213,8 +216,8 @@ static void fill_set_px(const lv_area_t * disp_area, lv_color_t * disp_buf, con } static void fill_normal(const lv_area_t * disp_area, lv_color_t * disp_buf, const lv_area_t * draw_area, - lv_color_t color, lv_opa_t opa, - const lv_opa_t * mask, lv_draw_mask_res_t mask_res) + lv_color_t color, lv_opa_t opa, + const lv_opa_t * mask, lv_draw_mask_res_t mask_res) { #if LV_USE_GPU @@ -247,7 +250,8 @@ static void fill_normal(const lv_area_t * disp_area, lv_color_t * disp_buf, con /*Fill the first line. Use `memcpy` because it's faster then simple value assignment*/ /*Set the first pixels manually*/ - int32_t direct_fill_end = LV_MATH_MIN(draw_area->x2, draw_area->x1 + FILL_DIRECT_LEN + (draw_area_w & FILL_DIRECT_MASK) - 1); + int32_t direct_fill_end = LV_MATH_MIN(draw_area->x2, + draw_area->x1 + FILL_DIRECT_LEN + (draw_area_w & FILL_DIRECT_MASK) - 1); for(x = draw_area->x1; x <= direct_fill_end ; x++) { disp_buf_tmp[x].full = color.full; } @@ -286,8 +290,10 @@ static void fill_normal(const lv_area_t * disp_area, lv_color_t * disp_buf, con #if LV_COLOR_SCREEN_TRANSP if(disp->driver.screen_transp) { - lv_color_mix_with_alpha(disp_buf_tmp[x], disp_buf_tmp[x].ch.alpha, color, opa, &last_res_color, &last_res_color.ch.alpha); - } else + lv_color_mix_with_alpha(disp_buf_tmp[x], disp_buf_tmp[x].ch.alpha, color, opa, &last_res_color, + &last_res_color.ch.alpha); + } + else #endif { last_res_color = lv_color_mix(color, disp_buf_tmp[x], opa); @@ -318,12 +324,13 @@ static void fill_normal(const lv_area_t * disp_area, lv_color_t * disp_buf, con for(y = draw_area->y1; y <= draw_area->y2; y++) { for(x = draw_area->x1; x <= draw_area->x2; x++) { if(mask_tmp[x] == 0) continue; - if(mask_tmp[x] != last_mask || last_dest_color.full != disp_buf_tmp[x].full) - { + if(mask_tmp[x] != last_mask || last_dest_color.full != disp_buf_tmp[x].full) { #if LV_COLOR_SCREEN_TRANSP if(disp->driver.screen_transp) { - lv_color_mix_with_alpha(disp_buf_tmp[x], disp_buf_tmp[x].ch.alpha, color, mask_tmp[x], &last_res_color, &last_res_color.ch.alpha); - } else + lv_color_mix_with_alpha(disp_buf_tmp[x], disp_buf_tmp[x].ch.alpha, color, mask_tmp[x], &last_res_color, + &last_res_color.ch.alpha); + } + else #endif { if(mask_tmp[x] == LV_OPA_COVER) last_res_color = color; @@ -349,13 +356,15 @@ static void fill_normal(const lv_area_t * disp_area, lv_color_t * disp_buf, con lv_opa_t opa_tmp = mask_tmp[x] == LV_OPA_COVER ? opa : (uint32_t)((uint32_t)mask_tmp[x] * opa) >> 8; #if LV_COLOR_SCREEN_TRANSP if(disp->driver.screen_transp) { - lv_color_mix_with_alpha(disp_buf_tmp[x], disp_buf_tmp[x].ch.alpha, color, opa_tmp, &last_res_color, &last_res_color.ch.alpha); - } else + lv_color_mix_with_alpha(disp_buf_tmp[x], disp_buf_tmp[x].ch.alpha, color, opa_tmp, &last_res_color, + &last_res_color.ch.alpha); + } + else #endif { if(opa_tmp == LV_OPA_COVER) last_res_color = lv_color_mix(color, disp_buf_tmp[x], mask_tmp[x]); else if(opa_tmp == LV_OPA_TRANSP) last_res_color = disp_buf_tmp[x]; - else last_res_color = lv_color_mix(color, disp_buf_tmp[x],opa_tmp); + else last_res_color = lv_color_mix(color, disp_buf_tmp[x], opa_tmp); } last_mask = mask_tmp[x]; last_dest_color.full = disp_buf_tmp[x].full; @@ -371,8 +380,8 @@ static void fill_normal(const lv_area_t * disp_area, lv_color_t * disp_buf, con static void fill_blended(const lv_area_t * disp_area, lv_color_t * disp_buf, const lv_area_t * draw_area, - lv_color_t color, lv_opa_t opa, - const lv_opa_t * mask, lv_draw_mask_res_t mask_res, lv_blend_mode_t mode) + lv_color_t color, lv_opa_t opa, + const lv_opa_t * mask, lv_draw_mask_res_t mask_res, lv_blend_mode_t mode) { /*Get the width of the `disp_area` it will be used to go to the next line*/ int32_t disp_w = lv_area_get_width(disp_area); @@ -382,17 +391,17 @@ static void fill_blended(const lv_area_t * disp_area, lv_color_t * disp_buf, co lv_color_t (*blend_fp)(lv_color_t, lv_color_t, lv_opa_t); - switch (mode) { - case LV_BLEND_MODE_ADDITIVE: - blend_fp = color_blend_true_color_additive; - break; - case LV_BLEND_MODE_SUBTRACTIVE: - blend_fp = color_blend_true_color_subtractive; - break; - default: - LV_LOG_WARN("fill_blended: unsupported blend mode"); - return; - break; + switch(mode) { + case LV_BLEND_MODE_ADDITIVE: + blend_fp = color_blend_true_color_additive; + break; + case LV_BLEND_MODE_SUBTRACTIVE: + blend_fp = color_blend_true_color_subtractive; + break; + default: + LV_LOG_WARN("fill_blended: unsupported blend mode"); + return; + break; } int32_t x; @@ -449,8 +458,8 @@ static void fill_blended(const lv_area_t * disp_area, lv_color_t * disp_buf, co } static void map_set_px(const lv_area_t * disp_area, lv_color_t * disp_buf, const lv_area_t * draw_area, - const lv_area_t * map_area, const lv_color_t * map_buf, lv_opa_t opa, - const lv_opa_t * mask, lv_draw_mask_res_t mask_res) + const lv_area_t * map_area, const lv_color_t * map_buf, lv_opa_t opa, + const lv_opa_t * mask, lv_draw_mask_res_t mask_res) { lv_disp_t * disp = lv_refr_get_disp_refreshing(); @@ -475,11 +484,12 @@ static void map_set_px(const lv_area_t * disp_area, lv_color_t * disp_buf, cons if(mask_res == LV_DRAW_MASK_RES_FULL_COVER) { for(y = draw_area->y1; y <= draw_area->y2; y++) { for(x = draw_area->x1; x <= draw_area->x2; x++) { - disp->driver.set_px_cb(&disp->driver, (void*)disp_buf, disp_w, x, y, map_buf_tmp[x], opa); + disp->driver.set_px_cb(&disp->driver, (void *)disp_buf, disp_w, x, y, map_buf_tmp[x], opa); } map_buf_tmp += map_w; } - } else { + } + else { /* The mask is relative to the clipped area. * In the cycles below mask will be indexed from `draw_area.x1` * but it corresponds to zero index. So prepare `mask_tmp` accordingly. */ @@ -487,7 +497,8 @@ static void map_set_px(const lv_area_t * disp_area, lv_color_t * disp_buf, cons for(y = draw_area->y1; y <= draw_area->y2; y++) { for(x = draw_area->x1; x <= draw_area->x2; 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); + 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); } mask_tmp += draw_area_w; map_buf_tmp += map_w; @@ -497,8 +508,8 @@ static void map_set_px(const lv_area_t * disp_area, lv_color_t * disp_buf, cons static void map_normal(const lv_area_t * disp_area, lv_color_t * disp_buf, const lv_area_t * draw_area, - const lv_area_t * map_area, const lv_color_t * map_buf, lv_opa_t opa, - const lv_opa_t * mask, lv_draw_mask_res_t mask_res) + const lv_area_t * map_area, const lv_color_t * map_buf, lv_opa_t opa, + const lv_opa_t * mask, lv_draw_mask_res_t mask_res) { /*Get the width of the `disp_area` it will be used to go to the next line*/ @@ -533,8 +544,8 @@ static void map_normal(const lv_area_t * disp_area, lv_color_t * disp_buf, cons map_buf_tmp += (draw_area->x1 - (map_area->x1 - disp_area->x1)); #if LV_USE_GPU if(disp->driver.gpu_blend_cb && - ((draw_area_w > GPU_WIDTH_LIMIT * 4 && opa == LV_OPA_COVER) || - (draw_area_w > GPU_WIDTH_LIMIT && opa != LV_OPA_COVER))) { + ((draw_area_w > GPU_WIDTH_LIMIT * 4 && opa == LV_OPA_COVER) || + (draw_area_w > GPU_WIDTH_LIMIT && opa != LV_OPA_COVER))) { for(y = draw_area->y1; y <= draw_area->y2; y++) { disp->driver.gpu_blend_cb(&disp->driver, &disp_buf_tmp[draw_area->x1], map_buf_tmp, draw_area_w, opa); disp_buf_tmp += disp_w; @@ -558,8 +569,10 @@ static void map_normal(const lv_area_t * disp_area, lv_color_t * disp_buf, cons for(x = draw_area->x1; x <= draw_area->x2; x++) { #if LV_COLOR_SCREEN_TRANSP if(disp->driver.screen_transp) { - lv_color_mix_with_alpha(disp_buf_tmp[x], disp_buf_tmp[x].ch.alpha, map_buf_tmp[x], opa, &disp_buf_tmp[x], &disp_buf_tmp[x].ch.alpha); - } else + lv_color_mix_with_alpha(disp_buf_tmp[x], disp_buf_tmp[x].ch.alpha, map_buf_tmp[x], opa, &disp_buf_tmp[x], + &disp_buf_tmp[x].ch.alpha); + } + else #endif { disp_buf_tmp[x] = lv_color_mix(map_buf_tmp[x], disp_buf_tmp[x], opa); @@ -591,15 +604,17 @@ static void map_normal(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] < LV_OPA_MIN) continue; #if LV_COLOR_SCREEN_TRANSP - if(disp->driver.screen_transp) { - lv_color_mix_with_alpha(disp_buf_tmp[x], disp_buf_tmp[x].ch.alpha, map_buf_tmp[x], mask_tmp[x], &res_color, &opa_composed); - res_color.ch.alpha = opa_composed; - } else + if(disp->driver.screen_transp) { + lv_color_mix_with_alpha(disp_buf_tmp[x], disp_buf_tmp[x].ch.alpha, map_buf_tmp[x], mask_tmp[x], &res_color, + &opa_composed); + res_color.ch.alpha = opa_composed; + } + else #endif - { - if(mask_tmp[x] > LV_OPA_MAX) res_color = map_buf_tmp[x]; - else res_color = lv_color_mix(map_buf_tmp[x], disp_buf_tmp[x], mask_tmp[x]); - } + { + if(mask_tmp[x] > LV_OPA_MAX) res_color = map_buf_tmp[x]; + else res_color = lv_color_mix(map_buf_tmp[x], disp_buf_tmp[x], mask_tmp[x]); + } disp_buf_tmp[x] = res_color;//lv_color_mix(map_buf_tmp[x], disp_buf_tmp[x], mask_tmp[x]); } disp_buf_tmp += disp_w; @@ -616,8 +631,10 @@ static void map_normal(const lv_area_t * disp_area, lv_color_t * disp_buf, cons lv_opa_t opa_tmp = mask_tmp[x] >= LV_OPA_MAX ? opa : ((opa * mask_tmp[x]) >> 8); #if LV_COLOR_SCREEN_TRANSP if(disp->driver.screen_transp) { - lv_color_mix_with_alpha(disp_buf_tmp[x], disp_buf_tmp[x].ch.alpha, map_buf_tmp[x], opa_tmp, &disp_buf_tmp[x], &disp_buf_tmp[x].ch.alpha); - } else + lv_color_mix_with_alpha(disp_buf_tmp[x], disp_buf_tmp[x].ch.alpha, map_buf_tmp[x], opa_tmp, &disp_buf_tmp[x], + &disp_buf_tmp[x].ch.alpha); + } + else #endif { disp_buf_tmp[x] = lv_color_mix(map_buf_tmp[x], disp_buf_tmp[x], opa_tmp); @@ -632,8 +649,8 @@ static void map_normal(const lv_area_t * disp_area, lv_color_t * disp_buf, cons } static void map_blended(const lv_area_t * disp_area, lv_color_t * disp_buf, const lv_area_t * draw_area, - const lv_area_t * map_area, const lv_color_t * map_buf, lv_opa_t opa, - const lv_opa_t * mask, lv_draw_mask_res_t mask_res, lv_blend_mode_t mode) + const lv_area_t * map_area, const lv_color_t * map_buf, lv_opa_t opa, + const lv_opa_t * mask, lv_draw_mask_res_t mask_res, lv_blend_mode_t mode) { /*Get the width of the `disp_area` it will be used to go to the next line*/ @@ -652,17 +669,17 @@ static void map_blended(const lv_area_t * disp_area, lv_color_t * disp_buf, con const lv_color_t * map_buf_tmp = map_buf + map_w * (draw_area->y1 - (map_area->y1 - disp_area->y1)); lv_color_t (*blend_fp)(lv_color_t, lv_color_t, lv_opa_t); - switch (mode) { - case LV_BLEND_MODE_ADDITIVE: - blend_fp = color_blend_true_color_additive; - break; - case LV_BLEND_MODE_SUBTRACTIVE: - blend_fp = color_blend_true_color_subtractive; - break; - default: - LV_LOG_WARN("fill_blended: unsupported blend mode"); - return; - break; + switch(mode) { + case LV_BLEND_MODE_ADDITIVE: + blend_fp = color_blend_true_color_additive; + break; + case LV_BLEND_MODE_SUBTRACTIVE: + blend_fp = color_blend_true_color_subtractive; + break; + default: + LV_LOG_WARN("fill_blended: unsupported blend mode"); + return; + break; } int32_t x; diff --git a/src/lv_draw/lv_draw_blend.h b/src/lv_draw/lv_draw_blend.h index c2ebe2849..07c6f576c 100644 --- a/src/lv_draw/lv_draw_blend.h +++ b/src/lv_draw/lv_draw_blend.h @@ -37,7 +37,7 @@ typedef uint8_t lv_blend_mode_t; **********************/ void lv_blend_fill(const lv_area_t * clip_area, const lv_area_t * fill_area, lv_color_t color, - lv_opa_t * mask, lv_draw_mask_res_t mask_res, lv_opa_t opa, lv_blend_mode_t mode); + lv_opa_t * mask, lv_draw_mask_res_t mask_res, lv_opa_t opa, lv_blend_mode_t mode); void lv_blend_map(const lv_area_t * clip_area, const lv_area_t * map_area, const lv_color_t * map_buf, diff --git a/src/lv_draw/lv_draw_img.c b/src/lv_draw/lv_draw_img.c index 5dce0e172..91c2f6a59 100644 --- a/src/lv_draw/lv_draw_img.c +++ b/src/lv_draw/lv_draw_img.c @@ -25,10 +25,12 @@ /********************** * STATIC PROTOTYPES **********************/ -static lv_res_t lv_img_draw_core(const lv_area_t * coords, const lv_area_t * mask, const void * src, lv_draw_img_dsc_t * draw_dsc); +static lv_res_t lv_img_draw_core(const lv_area_t * coords, const lv_area_t * mask, const void * src, + lv_draw_img_dsc_t * draw_dsc); -static void lv_draw_map(const lv_area_t * map_area, const lv_area_t * clip_area, const uint8_t * map_p, lv_draw_img_dsc_t * draw_dsc, - bool chroma_key, bool alpha_byte); +static void lv_draw_map(const lv_area_t * map_area, const lv_area_t * clip_area, const uint8_t * map_p, + lv_draw_img_dsc_t * draw_dsc, + bool chroma_key, bool alpha_byte); void show_error(const lv_area_t * coords, const lv_area_t * clip_area, const char * msg); /********************** @@ -94,20 +96,36 @@ uint8_t lv_img_cf_get_px_size(lv_img_cf_t cf) uint8_t px_size = 0; switch(cf) { - case LV_IMG_CF_UNKNOWN: - case LV_IMG_CF_RAW: px_size = 0; break; - case LV_IMG_CF_TRUE_COLOR: - case LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED: px_size = LV_COLOR_SIZE; break; - case LV_IMG_CF_TRUE_COLOR_ALPHA: px_size = LV_IMG_PX_SIZE_ALPHA_BYTE << 3; break; - case LV_IMG_CF_INDEXED_1BIT: - case LV_IMG_CF_ALPHA_1BIT: px_size = 1; break; - case LV_IMG_CF_INDEXED_2BIT: - case LV_IMG_CF_ALPHA_2BIT: px_size = 2; break; - case LV_IMG_CF_INDEXED_4BIT: - case LV_IMG_CF_ALPHA_4BIT: px_size = 4; break; - case LV_IMG_CF_INDEXED_8BIT: - case LV_IMG_CF_ALPHA_8BIT: px_size = 8; break; - default: px_size = 0; break; + case LV_IMG_CF_UNKNOWN: + case LV_IMG_CF_RAW: + px_size = 0; + break; + case LV_IMG_CF_TRUE_COLOR: + case LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED: + px_size = LV_COLOR_SIZE; + break; + case LV_IMG_CF_TRUE_COLOR_ALPHA: + px_size = LV_IMG_PX_SIZE_ALPHA_BYTE << 3; + break; + case LV_IMG_CF_INDEXED_1BIT: + case LV_IMG_CF_ALPHA_1BIT: + px_size = 1; + break; + case LV_IMG_CF_INDEXED_2BIT: + case LV_IMG_CF_ALPHA_2BIT: + px_size = 2; + break; + case LV_IMG_CF_INDEXED_4BIT: + case LV_IMG_CF_ALPHA_4BIT: + px_size = 4; + break; + case LV_IMG_CF_INDEXED_8BIT: + case LV_IMG_CF_ALPHA_8BIT: + px_size = 8; + break; + default: + px_size = 0; + break; } return px_size; @@ -123,17 +141,20 @@ bool lv_img_cf_is_chroma_keyed(lv_img_cf_t cf) bool is_chroma_keyed = false; switch(cf) { - case LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED: - case LV_IMG_CF_RAW_CHROMA_KEYED: + case LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED: + case LV_IMG_CF_RAW_CHROMA_KEYED: #if LV_INDEXED_CHROMA - case LV_IMG_CF_INDEXED_1BIT: - case LV_IMG_CF_INDEXED_2BIT: - case LV_IMG_CF_INDEXED_4BIT: - case LV_IMG_CF_INDEXED_8BIT: + case LV_IMG_CF_INDEXED_1BIT: + case LV_IMG_CF_INDEXED_2BIT: + case LV_IMG_CF_INDEXED_4BIT: + case LV_IMG_CF_INDEXED_8BIT: #endif - is_chroma_keyed = true; break; + is_chroma_keyed = true; + break; - default: is_chroma_keyed = false; break; + default: + is_chroma_keyed = false; + break; } return is_chroma_keyed; @@ -149,17 +170,21 @@ bool lv_img_cf_has_alpha(lv_img_cf_t cf) bool has_alpha = false; switch(cf) { - case LV_IMG_CF_TRUE_COLOR_ALPHA: - case LV_IMG_CF_RAW_ALPHA: - case LV_IMG_CF_INDEXED_1BIT: - case LV_IMG_CF_INDEXED_2BIT: - case LV_IMG_CF_INDEXED_4BIT: - case LV_IMG_CF_INDEXED_8BIT: - case LV_IMG_CF_ALPHA_1BIT: - case LV_IMG_CF_ALPHA_2BIT: - case LV_IMG_CF_ALPHA_4BIT: - case LV_IMG_CF_ALPHA_8BIT: has_alpha = true; break; - default: has_alpha = false; break; + case LV_IMG_CF_TRUE_COLOR_ALPHA: + case LV_IMG_CF_RAW_ALPHA: + case LV_IMG_CF_INDEXED_1BIT: + case LV_IMG_CF_INDEXED_2BIT: + case LV_IMG_CF_INDEXED_4BIT: + case LV_IMG_CF_INDEXED_8BIT: + case LV_IMG_CF_ALPHA_1BIT: + case LV_IMG_CF_ALPHA_2BIT: + case LV_IMG_CF_ALPHA_4BIT: + case LV_IMG_CF_ALPHA_8BIT: + has_alpha = true; + break; + default: + has_alpha = false; + break; } return has_alpha; @@ -183,9 +208,11 @@ lv_img_src_t lv_img_src_get_type(const void * src) /*The first byte shows the type of the image source*/ if(u8_p[0] >= 0x20 && u8_p[0] <= 0x7F) { img_src_type = LV_IMG_SRC_FILE; /*If it's an ASCII character then it's file name*/ - } else if(u8_p[0] >= 0x80) { + } + else if(u8_p[0] >= 0x80) { img_src_type = LV_IMG_SRC_SYMBOL; /*Symbols begins after 0x7F*/ - } else { + } + else { img_src_type = LV_IMG_SRC_VARIABLE; /*`lv_img_dsc_t` is design to the first byte < 0x20*/ } @@ -200,7 +227,8 @@ lv_img_src_t lv_img_src_get_type(const void * src) * STATIC FUNCTIONS **********************/ -static lv_res_t lv_img_draw_core(const lv_area_t * coords, const lv_area_t * mask, const void * src, lv_draw_img_dsc_t * draw_dsc) +static lv_res_t lv_img_draw_core(const lv_area_t * coords, const lv_area_t * mask, const void * src, + lv_draw_img_dsc_t * draw_dsc) { if(draw_dsc->opa <= LV_OPA_MIN) return LV_RES_OK; @@ -255,7 +283,8 @@ static lv_res_t lv_img_draw_core(const lv_area_t * coords, const lv_area_t * mas 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*/ + 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_area_t line; lv_area_copy(&line, &mask_com); @@ -303,7 +332,8 @@ static lv_res_t lv_img_draw_core(const lv_area_t * coords, const lv_area_t * mas * @param zoom zoom factor * @param antialias anti-alias transformations (rotate, zoom) or not */ -static void lv_draw_map(const lv_area_t * map_area, const lv_area_t * clip_area, const uint8_t * map_p, lv_draw_img_dsc_t * draw_dsc, bool chroma_key, bool alpha_byte) +static void lv_draw_map(const lv_area_t * map_area, const lv_area_t * clip_area, const uint8_t * map_p, + lv_draw_img_dsc_t * draw_dsc, bool chroma_key, bool alpha_byte) { /* Use the clip area as draw area*/ lv_area_t draw_area; @@ -326,7 +356,8 @@ static void lv_draw_map(const lv_area_t * map_area, const lv_area_t * clip_area, if(other_mask_cnt == 0 && draw_dsc->angle == 0 && draw_dsc->zoom == LV_IMG_ZOOM_NONE && chroma_key == false && alpha_byte == false && draw_dsc->opa == LV_OPA_COVER && draw_dsc->recolor_opa == LV_OPA_TRANSP) { - lv_blend_map(clip_area, map_area, (lv_color_t *)map_p, NULL, LV_DRAW_MASK_RES_FULL_COVER, LV_OPA_COVER, draw_dsc->blend_mode); + lv_blend_map(clip_area, map_area, (lv_color_t *)map_p, NULL, LV_DRAW_MASK_RES_FULL_COVER, LV_OPA_COVER, + draw_dsc->blend_mode); } /*In the other cases every pixel need to be checked one-by-one*/ else { @@ -406,7 +437,8 @@ static void lv_draw_map(const lv_area_t * map_area, const lv_area_t * clip_area, #endif continue; } - } else { + } + else { mask_buf[px_i] = LV_OPA_COVER; } @@ -415,15 +447,16 @@ static void lv_draw_map(const lv_area_t * map_area, const lv_area_t * clip_area, #elif LV_COLOR_DEPTH == 16 c.full = map_px[0] + (map_px[1] << 8); #elif LV_COLOR_DEPTH == 32 - c.full = *((uint32_t*)map_px); + c.full = *((uint32_t *)map_px); #endif - if (chroma_key) { + if(chroma_key) { if(c.full == chroma_keyed_color.full) { mask_buf[px_i] = LV_OPA_TRANSP; continue; } } - } else { + } + else { /*Rotate*/ bool ret; int32_t rot_x = x + (disp_area->x1 + draw_area.x1) - map_area->x1; @@ -432,7 +465,8 @@ static void lv_draw_map(const lv_area_t * map_area, const lv_area_t * clip_area, if(ret == false) { mask_buf[px_i] = LV_OPA_TRANSP; continue; - } else { + } + else { mask_buf[px_i] = trans_dsc.res.opa; c.full = trans_dsc.res.color.full; } @@ -448,11 +482,13 @@ static void lv_draw_map(const lv_area_t * map_area, const lv_area_t * clip_area, /*Apply the masks if any*/ if(other_mask_cnt) { lv_draw_mask_res_t mask_res_sub; - mask_res_sub = lv_draw_mask_apply(mask_buf + px_i_start, draw_area.x1 + vdb->area.x1, y + draw_area.y1 + vdb->area.y1, lv_area_get_width(&draw_area)); + mask_res_sub = lv_draw_mask_apply(mask_buf + px_i_start, draw_area.x1 + vdb->area.x1, y + draw_area.y1 + vdb->area.y1, + lv_area_get_width(&draw_area)); if(mask_res_sub == LV_DRAW_MASK_RES_FULL_TRANSP) { memset(mask_buf + px_i_start, 0x00, lv_area_get_width(&draw_area)); mask_res = LV_DRAW_MASK_RES_CHANGED; - } else if(mask_res_sub == LV_DRAW_MASK_RES_CHANGED) { + } + else if(mask_res_sub == LV_DRAW_MASK_RES_CHANGED) { mask_res = LV_DRAW_MASK_RES_CHANGED; } } @@ -460,7 +496,8 @@ static void lv_draw_map(const lv_area_t * map_area, const lv_area_t * clip_area, map_buf_tmp += map_w * px_size_byte; if(px_i + lv_area_get_width(&draw_area) < mask_buf_size) { blend_area.y2 ++; - } else { + } + else { lv_blend_map(clip_area, &blend_area, map2, mask_buf, mask_res, draw_dsc->opa, draw_dsc->blend_mode); blend_area.y1 = blend_area.y2 + 1; diff --git a/src/lv_draw/lv_draw_img.h b/src/lv_draw/lv_draw_img.h index 752604e49..735777684 100644 --- a/src/lv_draw/lv_draw_img.h +++ b/src/lv_draw/lv_draw_img.h @@ -40,7 +40,7 @@ typedef struct { lv_blend_mode_t blend_mode; - uint8_t antialias :1; + uint8_t antialias : 1; } lv_draw_img_dsc_t; /********************** diff --git a/src/lv_draw/lv_draw_label.c b/src/lv_draw/lv_draw_label.c index d0f569598..00b5ace04 100644 --- a/src/lv_draw/lv_draw_label.c +++ b/src/lv_draw/lv_draw_label.c @@ -32,10 +32,13 @@ typedef uint8_t cmd_state_t; /********************** * STATIC PROTOTYPES **********************/ -static void lv_draw_letter(const lv_point_t * pos_p, const lv_area_t * clip_area, const lv_font_t * font_p, uint32_t letter, - lv_color_t color, lv_opa_t opa); -static void draw_letter_normal(lv_coord_t pos_x, lv_coord_t pos_y, lv_font_glyph_dsc_t * g, const lv_area_t * clip_area, const uint8_t * map_p, lv_color_t color, lv_opa_t opa); -static void draw_letter_subpx(lv_coord_t pos_x, lv_coord_t pos_y, lv_font_glyph_dsc_t * g, const lv_area_t * clip_area, const uint8_t * map_p, lv_color_t color, lv_opa_t opa); +static void lv_draw_letter(const lv_point_t * pos_p, const lv_area_t * clip_area, const lv_font_t * font_p, + uint32_t letter, + lv_color_t color, lv_opa_t opa); +static void draw_letter_normal(lv_coord_t pos_x, lv_coord_t pos_y, lv_font_glyph_dsc_t * g, const lv_area_t * clip_area, + const uint8_t * map_p, lv_color_t color, lv_opa_t opa); +static void draw_letter_subpx(lv_coord_t pos_x, lv_coord_t pos_y, lv_font_glyph_dsc_t * g, const lv_area_t * clip_area, + const uint8_t * map_p, lv_color_t color, lv_opa_t opa); static uint8_t hex_char_to_num(char hex); @@ -49,8 +52,9 @@ static const uint8_t bpp2_opa_table[4] = {0, 85, 170, 255}; /*Opacity mapping w static const uint8_t bpp4_opa_table[16] = {0, 17, 34, 51, /*Opacity mapping with bpp = 4*/ 68, 85, 102, 119, 136, 153, 170, 187, - 204, 221, 238, 255}; - /*clang-format on*/ + 204, 221, 238, 255 + }; +/*clang-format on*/ /********************** * MACROS @@ -87,7 +91,7 @@ void lv_draw_label(const lv_area_t * coords, const lv_area_t * mask, lv_draw_lab int32_t w; /*No need to waste processor time if string is empty*/ - if (txt[0] == '\0') return; + if(txt[0] == '\0') return; lv_area_t clipped_area; bool clip_ok = lv_area_intersect(&clipped_area, coords, mask); @@ -97,11 +101,12 @@ void lv_draw_label(const lv_area_t * coords, const lv_area_t * mask, lv_draw_lab if((dsc->flag & LV_TXT_FLAG_EXPAND) == 0) { /*Normally use the label's width as width*/ w = lv_area_get_width(coords); - } else { + } + else { /*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; } @@ -209,10 +214,10 @@ void lv_draw_label(const lv_area_t * coords, const lv_area_t * mask, lv_draw_lab cmd_state = CMD_STATE_WAIT; i = 0; #if LV_USE_BIDI - char *bidi_txt = lv_mem_buf_get(line_end - line_start + 1); + char * bidi_txt = lv_mem_buf_get(line_end - line_start + 1); lv_bidi_process_paragraph(txt + line_start, bidi_txt, line_end - line_start, dsc->bidi_dir, NULL, 0); #else - const char *bidi_txt = txt + line_start; + const char * bidi_txt = txt + line_start; #endif while(i < line_end - line_start) { @@ -237,9 +242,11 @@ void lv_draw_label(const lv_area_t * coords, const lv_area_t * mask, lv_draw_lab par_start = i; cmd_state = CMD_STATE_PAR; continue; - } else if(cmd_state == CMD_STATE_PAR) { /*Other start char in parameter escaped cmd. char */ + } + else if(cmd_state == CMD_STATE_PAR) { /*Other start char in parameter escaped cmd. char */ cmd_state = CMD_STATE_WAIT; - } else if(cmd_state == CMD_STATE_IN) { /*Command end */ + } + else if(cmd_state == CMD_STATE_IN) { /*Command end */ cmd_state = CMD_STATE_WAIT; continue; } @@ -258,7 +265,8 @@ void lv_draw_label(const lv_area_t * coords, const lv_area_t * mask, lv_draw_lab g = (hex_char_to_num(buf[2]) << 4) + hex_char_to_num(buf[3]); b = (hex_char_to_num(buf[4]) << 4) + hex_char_to_num(buf[5]); recolor = lv_color_make(r, g, b); - } else { + } + else { recolor.full = dsc->color.full; } cmd_state = CMD_STATE_IN; /*After the parameter the text is in the command*/ @@ -323,7 +331,7 @@ void lv_draw_label(const lv_area_t * coords, const lv_area_t * mask, lv_draw_lab /*Align to middle*/ if(dsc->flag & LV_TXT_FLAG_CENTER) { line_width = - lv_txt_get_width(&txt[line_start], line_end - line_start, font, dsc->letter_space, dsc->flag); + lv_txt_get_width(&txt[line_start], line_end - line_start, font, dsc->letter_space, dsc->flag); pos.x += (lv_area_get_width(coords) - line_width) / 2; @@ -331,7 +339,7 @@ void lv_draw_label(const lv_area_t * coords, const lv_area_t * mask, lv_draw_lab /*Align to the right*/ else if(dsc->flag & LV_TXT_FLAG_RIGHT) { line_width = - lv_txt_get_width(&txt[line_start], line_end - line_start, font, dsc->letter_space, dsc->flag); + lv_txt_get_width(&txt[line_start], line_end - line_start, font, dsc->letter_space, dsc->flag); pos.x += lv_area_get_width(coords) - line_width; } @@ -358,8 +366,9 @@ void lv_draw_label(const lv_area_t * coords, const lv_area_t * mask, lv_draw_lab * @param color color of letter * @param opa opacity of letter (0..255) */ -static void lv_draw_letter(const lv_point_t * pos_p, const lv_area_t * clip_area, const lv_font_t * font_p, uint32_t letter, - lv_color_t color, lv_opa_t opa) +static void lv_draw_letter(const lv_point_t * pos_p, const lv_area_t * clip_area, const lv_font_t * font_p, + uint32_t letter, + lv_color_t color, lv_opa_t opa) { if(opa < LV_OPA_MIN) return; if(opa > LV_OPA_MAX) opa = LV_OPA_COVER; @@ -385,9 +394,9 @@ static void lv_draw_letter(const lv_point_t * pos_p, const lv_area_t * clip_area /*If the letter is completely out of mask don't draw it */ if(pos_x + g.box_w < clip_area->x1 || - pos_x > clip_area->x2 || - pos_y + g.box_h < clip_area->y1 || - pos_y > clip_area->y2) return; + pos_x > clip_area->x2 || + pos_y + g.box_h < clip_area->y1 || + pos_y > clip_area->y2) return; const uint8_t * map_p = lv_font_get_glyph_bitmap(font_p, letter); @@ -398,13 +407,15 @@ static void lv_draw_letter(const lv_point_t * pos_p, const lv_area_t * clip_area if(font_p->subpx) { draw_letter_subpx(pos_x, pos_y, &g, clip_area, map_p, color, opa); - } else { + } + else { draw_letter_normal(pos_x, pos_y, &g, clip_area, map_p, color, opa); } } -static void draw_letter_normal(lv_coord_t pos_x, lv_coord_t pos_y, lv_font_glyph_dsc_t * g, const lv_area_t * clip_area, const uint8_t * map_p, lv_color_t color, lv_opa_t opa) +static void draw_letter_normal(lv_coord_t pos_x, lv_coord_t pos_y, lv_font_glyph_dsc_t * g, const lv_area_t * clip_area, + const uint8_t * map_p, lv_color_t color, lv_opa_t opa) { const uint8_t * bpp_opa_table; @@ -414,25 +425,25 @@ static void draw_letter_normal(lv_coord_t pos_x, lv_coord_t pos_y, lv_font_glyph if(bpp == 3) bpp = 4; switch(bpp) { - case 1: - bpp_opa_table = bpp1_opa_table; - bitmask_init = 0x80; - break; - case 2: - bpp_opa_table = bpp2_opa_table; - bitmask_init = 0xC0; - break; - case 4: - bpp_opa_table = bpp4_opa_table; - bitmask_init = 0xF0; - break; - case 8: - bpp_opa_table = NULL; - bitmask_init = 0xFF; - break; /*No opa table, pixel value will be used directly*/ - default: - LV_LOG_WARN("lv_draw_letter: invalid bpp not found"); - return; /*Invalid bpp. Can't render the letter*/ + case 1: + bpp_opa_table = bpp1_opa_table; + bitmask_init = 0x80; + break; + case 2: + bpp_opa_table = bpp2_opa_table; + bitmask_init = 0xC0; + break; + case 4: + bpp_opa_table = bpp4_opa_table; + bitmask_init = 0xF0; + break; + case 8: + bpp_opa_table = NULL; + bitmask_init = 0xFF; + break; /*No opa table, pixel value will be used directly*/ + default: + LV_LOG_WARN("lv_draw_letter: invalid bpp not found"); + return; /*Invalid bpp. Can't render the letter*/ } @@ -482,14 +493,16 @@ static void draw_letter_normal(lv_coord_t pos_x, lv_coord_t pos_y, lv_font_glyph if(letter_px != 0) { if(opa == LV_OPA_COVER) { px_opa = bpp == 8 ? letter_px : bpp_opa_table[letter_px]; - } else { + } + else { px_opa = bpp == 8 ? (uint32_t)((uint32_t)letter_px * opa) >> 8 - : (uint32_t)((uint32_t)bpp_opa_table[letter_px] * opa) >> 8; + : (uint32_t)((uint32_t)bpp_opa_table[letter_px] * opa) >> 8; } mask_buf[mask_p] = px_opa; - } else { + } + else { mask_buf[mask_p] = 0; } @@ -497,7 +510,8 @@ static void draw_letter_normal(lv_coord_t pos_x, lv_coord_t pos_y, lv_font_glyph if(col_bit < 8 - bpp) { col_bit += bpp; bitmask = bitmask >> bpp; - } else { + } + else { col_bit = 0; bitmask = bitmask_init; map_p++; @@ -509,7 +523,8 @@ static void draw_letter_normal(lv_coord_t pos_x, lv_coord_t pos_y, lv_font_glyph /*Apply masks if any*/ if(other_mask_cnt) { - lv_draw_mask_res_t mask_res = lv_draw_mask_apply(mask_buf + mask_p_start, fill_area.x1, fill_area.y2, lv_area_get_width(&fill_area)); + lv_draw_mask_res_t mask_res = lv_draw_mask_apply(mask_buf + mask_p_start, fill_area.x1, fill_area.y2, + lv_area_get_width(&fill_area)); if(mask_res == LV_DRAW_MASK_RES_FULL_TRANSP) { memset(mask_buf + mask_p_start, 0x00, lv_area_get_width(&fill_area)); } @@ -517,10 +532,11 @@ static void draw_letter_normal(lv_coord_t pos_x, lv_coord_t pos_y, lv_font_glyph if((uint32_t) mask_p + (row_end - row_start) < mask_buf_size) { fill_area.y2 ++; - } else { + } + else { lv_blend_fill(clip_area, &fill_area, - color, mask_buf, LV_DRAW_MASK_RES_CHANGED, opa, - LV_BLEND_MODE_NORMAL); + color, mask_buf, LV_DRAW_MASK_RES_CHANGED, opa, + LV_BLEND_MODE_NORMAL); fill_area.y1 = fill_area.y2 + 1; fill_area.y2 = fill_area.y1; @@ -537,15 +553,16 @@ static void draw_letter_normal(lv_coord_t pos_x, lv_coord_t pos_y, lv_font_glyph if(fill_area.y1 != fill_area.y2) { fill_area.y2--; lv_blend_fill(clip_area, &fill_area, - color, mask_buf, LV_DRAW_MASK_RES_CHANGED, opa, - LV_BLEND_MODE_NORMAL); + color, mask_buf, LV_DRAW_MASK_RES_CHANGED, opa, + LV_BLEND_MODE_NORMAL); mask_p = 0; } lv_mem_buf_release(mask_buf); } -static void draw_letter_subpx(lv_coord_t pos_x, lv_coord_t pos_y, lv_font_glyph_dsc_t * g, const lv_area_t * clip_area, const uint8_t * map_p, lv_color_t color, lv_opa_t opa) +static void draw_letter_subpx(lv_coord_t pos_x, lv_coord_t pos_y, lv_font_glyph_dsc_t * g, const lv_area_t * clip_area, + const uint8_t * map_p, lv_color_t color, lv_opa_t opa) { const uint8_t * bpp_opa_table; uint32_t bitmask_init; @@ -554,25 +571,25 @@ static void draw_letter_subpx(lv_coord_t pos_x, lv_coord_t pos_y, lv_font_glyph_ if(bpp == 3) bpp = 4; switch(bpp) { - case 1: - bpp_opa_table = bpp1_opa_table; - bitmask_init = 0x80; - break; - case 2: - bpp_opa_table = bpp2_opa_table; - bitmask_init = 0xC0; - break; - case 4: - bpp_opa_table = bpp4_opa_table; - bitmask_init = 0xF0; - break; - case 8: - bpp_opa_table = NULL; - bitmask_init = 0xFF; - break; /*No opa table, pixel value will be used directly*/ - default: - LV_LOG_WARN("lv_draw_letter: invalid bpp not found"); - return; /*Invalid bpp. Can't render the letter*/ + case 1: + bpp_opa_table = bpp1_opa_table; + bitmask_init = 0x80; + break; + case 2: + bpp_opa_table = bpp2_opa_table; + bitmask_init = 0xC0; + break; + case 4: + bpp_opa_table = bpp4_opa_table; + bitmask_init = 0xF0; + break; + case 8: + bpp_opa_table = NULL; + bitmask_init = 0xFF; + break; /*No opa table, pixel value will be used directly*/ + default: + LV_LOG_WARN("lv_draw_letter: invalid bpp not found"); + return; /*Invalid bpp. Can't render the letter*/ } int32_t col, row; @@ -644,11 +661,13 @@ static void draw_letter_subpx(lv_coord_t pos_x, lv_coord_t pos_y, lv_font_glyph_ if(letter_px != 0) { if(opa == LV_OPA_COVER) { px_opa = bpp == 8 ? letter_px : bpp_opa_table[letter_px]; - } else { - px_opa = bpp == 8 ? (uint32_t)((uint32_t)letter_px * opa) >> 8 - : (uint32_t)((uint32_t)bpp_opa_table[letter_px] * opa) >> 8; } - } else { + else { + px_opa = bpp == 8 ? (uint32_t)((uint32_t)letter_px * opa) >> 8 + : (uint32_t)((uint32_t)bpp_opa_table[letter_px] * opa) >> 8; + } + } + else { px_opa = 0; } @@ -660,11 +679,12 @@ static void draw_letter_subpx(lv_coord_t pos_x, lv_coord_t pos_y, lv_font_glyph_ lv_color_t res_color; #if LV_COLOR_16_SWAP == 0 - uint8_t bg_rgb[3] = {vdb_buf_tmp->ch.red, vdb_buf_tmp->ch.green, vdb_buf_tmp->ch.blue}; + uint8_t bg_rgb[3] = {vdb_buf_tmp->ch.red, vdb_buf_tmp->ch.green, vdb_buf_tmp->ch.blue}; #else - uint8_t bg_rgb[3] = {vdb_buf_tmp->ch.red, - (vdb_buf_tmp->ch.green_h << 3) + vdb_buf_tmp->ch.green_l, - vdb_buf_tmp->ch.blue}; + uint8_t bg_rgb[3] = {vdb_buf_tmp->ch.red, + (vdb_buf_tmp->ch.green_h << 3) + vdb_buf_tmp->ch.green_l, + vdb_buf_tmp->ch.blue + }; #endif #if LV_FONT_SUBPX_BGR @@ -676,11 +696,11 @@ static void draw_letter_subpx(lv_coord_t pos_x, lv_coord_t pos_y, lv_font_glyph_ #endif #if LV_COLOR_16_SWAP == 0 - res_color.ch.green = (uint32_t)((uint32_t)txt_rgb[1] * font_rgb[1] + (bg_rgb[1] * (255 - font_rgb[1]))) >> 8; + res_color.ch.green = (uint32_t)((uint32_t)txt_rgb[1] * font_rgb[1] + (bg_rgb[1] * (255 - font_rgb[1]))) >> 8; #else - uint8_t green = (uint32_t)((uint32_t)txt_rgb[1] * font_rgb[1] + (bg_rgb[1] * (255 - font_rgb[1]))) >> 8; - res_color.ch.green_h = green >> 3; - res_color.ch.green_l = green & 0x7; + uint8_t green = (uint32_t)((uint32_t)txt_rgb[1] * font_rgb[1] + (bg_rgb[1] * (255 - font_rgb[1]))) >> 8; + res_color.ch.green_h = green >> 3; + res_color.ch.green_l = green & 0x7; #endif if(font_rgb[0] == 0 && font_rgb[1] == 0 && font_rgb[2] == 0) mask_buf[mask_p] = LV_OPA_TRANSP; @@ -696,7 +716,8 @@ static void draw_letter_subpx(lv_coord_t pos_x, lv_coord_t pos_y, lv_font_glyph_ if(col_bit < 8 - bpp) { col_bit += bpp; bitmask = bitmask >> bpp; - } else { + } + else { col_bit = 0; bitmask = bitmask_init; map_p++; @@ -705,7 +726,8 @@ static void draw_letter_subpx(lv_coord_t pos_x, lv_coord_t pos_y, lv_font_glyph_ /*Apply masks if any*/ if(other_mask_cnt) { - lv_draw_mask_res_t mask_res = lv_draw_mask_apply(mask_buf + mask_p_start, map_area.x1, map_area.y2, lv_area_get_width(&map_area)); + lv_draw_mask_res_t mask_res = lv_draw_mask_apply(mask_buf + mask_p_start, map_area.x1, map_area.y2, + lv_area_get_width(&map_area)); if(mask_res == LV_DRAW_MASK_RES_FULL_TRANSP) { memset(mask_buf + mask_p_start, 0x00, lv_area_get_width(&map_area)); } @@ -713,7 +735,8 @@ static void draw_letter_subpx(lv_coord_t pos_x, lv_coord_t pos_y, lv_font_glyph_ if((uint32_t) mask_p + (row_end - row_start) < mask_buf_size) { map_area.y2 ++; - } else { + } + else { lv_blend_map(clip_area, &map_area, color_buf, mask_buf, LV_DRAW_MASK_RES_CHANGED, opa, LV_BLEND_MODE_NORMAL); map_area.y1 = map_area.y2 + 1; @@ -752,17 +775,32 @@ static uint8_t hex_char_to_num(char hex) if(hex >= '0' && hex <= '9') { result = hex - '0'; - } else { + } + else { if(hex >= 'a') hex -= 'a' - 'A'; /*Convert to upper case*/ switch(hex) { - case 'A': result = 10; break; - case 'B': result = 11; break; - case 'C': result = 12; break; - case 'D': result = 13; break; - case 'E': result = 14; break; - case 'F': result = 15; break; - default: result = 0; break; + case 'A': + result = 10; + break; + case 'B': + result = 11; + break; + case 'C': + result = 12; + break; + case 'D': + result = 13; + break; + case 'E': + result = 14; + break; + case 'F': + result = 15; + break; + default: + result = 0; + break; } } diff --git a/src/lv_draw/lv_draw_label.h b/src/lv_draw/lv_draw_label.h index 842414378..9e5df892c 100644 --- a/src/lv_draw/lv_draw_label.h +++ b/src/lv_draw/lv_draw_label.h @@ -41,7 +41,7 @@ typedef struct { lv_txt_flag_t flag; lv_text_decor_t decor; lv_blend_mode_t blend_mode; -}lv_draw_label_dsc_t; +} lv_draw_label_dsc_t; /** Store some info to speed up drawing of very large texts * It takes a lot of time to get the first visible character because @@ -58,7 +58,7 @@ typedef struct { /** The 'y1' coordinate of the label when the hint was saved. * Used to invalidate the hint if the label has moved too much. */ int32_t coord_y; -}lv_draw_label_hint_t; +} lv_draw_label_hint_t; /********************** * GLOBAL PROTOTYPES diff --git a/src/lv_draw/lv_draw_line.c b/src/lv_draw/lv_draw_line.c index 44a20b857..7703c7868 100644 --- a/src/lv_draw/lv_draw_line.c +++ b/src/lv_draw/lv_draw_line.c @@ -24,9 +24,12 @@ /********************** * STATIC PROTOTYPES **********************/ -static void draw_line_skew(const lv_point_t * point1, const lv_point_t * point2, const lv_area_t * clip, lv_draw_line_dsc_t * dsc); -static void draw_line_hor(const lv_point_t * point1, const lv_point_t * point2, const lv_area_t * clip, lv_draw_line_dsc_t * dsc); -static void draw_line_ver(const lv_point_t * point1, const lv_point_t * point2, const lv_area_t * clip, lv_draw_line_dsc_t * dsc); +static void draw_line_skew(const lv_point_t * point1, const lv_point_t * point2, const lv_area_t * clip, + lv_draw_line_dsc_t * dsc); +static void draw_line_hor(const lv_point_t * point1, const lv_point_t * point2, const lv_area_t * clip, + lv_draw_line_dsc_t * dsc); +static void draw_line_ver(const lv_point_t * point1, const lv_point_t * point2, const lv_area_t * clip, + lv_draw_line_dsc_t * dsc); /********************** * STATIC VARIABLES @@ -56,7 +59,8 @@ void lv_draw_line_dsc_init(lv_draw_line_dsc_t * dsc) * @param style pointer to a line's style * @param opa_scale scale down all opacities by the factor */ -void lv_draw_line(const lv_point_t * point1, const lv_point_t * point2, const lv_area_t * clip, lv_draw_line_dsc_t * dsc) +void lv_draw_line(const lv_point_t * point1, const lv_point_t * point2, const lv_area_t * clip, + lv_draw_line_dsc_t * dsc) { if(dsc->width == 0) return; if(dsc->opa <= LV_OPA_MIN) return; @@ -64,10 +68,10 @@ void lv_draw_line(const lv_point_t * point1, const lv_point_t * point2, const lv if(point1->x == point2->x && point1->y == point2->y) return; lv_area_t clip_line; - clip_line.x1 = LV_MATH_MIN(point1->x, point2->x) - dsc->width/2; - clip_line.x2 = LV_MATH_MAX(point1->x, point2->x) + dsc->width/2; - clip_line.y1 = LV_MATH_MIN(point1->y, point2->y) - dsc->width/2; - clip_line.y2 = LV_MATH_MAX(point1->y, point2->y) + dsc->width/2; + clip_line.x1 = LV_MATH_MIN(point1->x, point2->x) - dsc->width / 2; + clip_line.x2 = LV_MATH_MAX(point1->x, point2->x) + dsc->width / 2; + clip_line.y1 = LV_MATH_MIN(point1->y, point2->y) - dsc->width / 2; + clip_line.y2 = LV_MATH_MAX(point1->y, point2->y) + dsc->width / 2; bool is_common; is_common = lv_area_intersect(&clip_line, &clip_line, clip); @@ -111,7 +115,8 @@ void lv_draw_line(const lv_point_t * point1, const lv_point_t * point2, const lv * STATIC FUNCTIONS **********************/ -static void draw_line_hor(const lv_point_t * point1, const lv_point_t * point2, const lv_area_t * clip, lv_draw_line_dsc_t * dsc) +static void draw_line_hor(const lv_point_t * point1, const lv_point_t * point2, const lv_area_t * clip, + lv_draw_line_dsc_t * dsc) { lv_opa_t opa = dsc->opa; @@ -139,8 +144,8 @@ static void draw_line_hor(const lv_point_t * point1, const lv_point_t * point2, /*If there is no mask then simply draw a rectangle*/ if(simple_mode) { lv_blend_fill(clip, &draw_area, - dsc->color, NULL, LV_DRAW_MASK_RES_FULL_COVER,opa, - LV_BLEND_MODE_NORMAL); + dsc->color, NULL, LV_DRAW_MASK_RES_FULL_COVER, opa, + LV_BLEND_MODE_NORMAL); } /*If there other mask apply it*/ else { @@ -170,42 +175,45 @@ static void draw_line_hor(const lv_point_t * point1, const lv_point_t * point2, lv_opa_t * mask_buf = lv_mem_buf_get(draw_area_w); int32_t h; for(h = draw_area.y1; h <= draw_area.y2; h++) { - memset(mask_buf, LV_OPA_COVER, draw_area_w); - lv_draw_mask_res_t mask_res = lv_draw_mask_apply(mask_buf, vdb->area.x1 + draw_area.x1, vdb->area.y1 + h, draw_area_w); + memset(mask_buf, LV_OPA_COVER, draw_area_w); + lv_draw_mask_res_t mask_res = lv_draw_mask_apply(mask_buf, vdb->area.x1 + draw_area.x1, vdb->area.y1 + h, draw_area_w); - if(dashed) { - if(mask_res != LV_DRAW_MASK_RES_FULL_TRANSP) { + if(dashed) { + if(mask_res != LV_DRAW_MASK_RES_FULL_TRANSP) { lv_style_int_t dash_cnt = dash_start; - uint32_t i; - for(i = 0; i < draw_area_w; i++, dash_cnt++) { - if(dash_cnt <= dsc->dash_width) { - int16_t diff = dsc->dash_width - dash_cnt; - i += diff; - dash_cnt += diff; - } else if(dash_cnt >= dsc->dash_gap + dsc->dash_width) { - dash_cnt = 0; - } else { - mask_buf[i] = 0x00; - } - } + uint32_t i; + for(i = 0; i < draw_area_w; i++, dash_cnt++) { + if(dash_cnt <= dsc->dash_width) { + int16_t diff = dsc->dash_width - dash_cnt; + i += diff; + dash_cnt += diff; + } + else if(dash_cnt >= dsc->dash_gap + dsc->dash_width) { + dash_cnt = 0; + } + else { + mask_buf[i] = 0x00; + } + } - mask_res = LV_DRAW_MASK_RES_CHANGED; - } - } + mask_res = LV_DRAW_MASK_RES_CHANGED; + } + } - lv_blend_fill(clip, &fill_area, - dsc->color, mask_buf, mask_res, dsc->opa, - dsc->blend_mode); + lv_blend_fill(clip, &fill_area, + dsc->color, mask_buf, mask_res, dsc->opa, + dsc->blend_mode); - fill_area.y1++; - fill_area.y2++; - } + fill_area.y1++; + fill_area.y2++; + } lv_mem_buf_release(mask_buf); } } -static void draw_line_ver(const lv_point_t * point1, const lv_point_t * point2, const lv_area_t * clip, lv_draw_line_dsc_t * dsc) +static void draw_line_ver(const lv_point_t * point1, const lv_point_t * point2, const lv_area_t * clip, + lv_draw_line_dsc_t * dsc) { lv_opa_t opa = dsc->opa; @@ -233,8 +241,8 @@ static void draw_line_ver(const lv_point_t * point1, const lv_point_t * point2, /*If there is no mask then simply draw a rectangle*/ if(simple_mode) { lv_blend_fill(clip, &draw_area, - dsc->color, NULL, LV_DRAW_MASK_RES_FULL_COVER, opa, - dsc->blend_mode); + dsc->color, NULL, LV_DRAW_MASK_RES_FULL_COVER, opa, + dsc->blend_mode); } /*If there other mask apply it*/ else { @@ -266,35 +274,36 @@ static void draw_line_ver(const lv_point_t * point1, const lv_point_t * point2, int32_t h; for(h = draw_area.y1; h <= draw_area.y2; h++) { - memset(mask_buf, LV_OPA_COVER, draw_area_w); - lv_draw_mask_res_t mask_res = lv_draw_mask_apply(mask_buf, vdb->area.x1 + draw_area.x1, vdb->area.y1 + h, draw_area_w); + memset(mask_buf, LV_OPA_COVER, draw_area_w); + lv_draw_mask_res_t mask_res = lv_draw_mask_apply(mask_buf, vdb->area.x1 + draw_area.x1, vdb->area.y1 + h, draw_area_w); - if(dashed) { - if(mask_res != LV_DRAW_MASK_RES_FULL_TRANSP) { - if(dash_cnt > dsc->dash_width) { - mask_res = LV_DRAW_MASK_RES_FULL_TRANSP; - } + if(dashed) { + if(mask_res != LV_DRAW_MASK_RES_FULL_TRANSP) { + if(dash_cnt > dsc->dash_width) { + mask_res = LV_DRAW_MASK_RES_FULL_TRANSP; + } - if(dash_cnt >= dsc->dash_gap + dsc->dash_width) { - dash_cnt = 0; - } - } - dash_cnt ++; - } + if(dash_cnt >= dsc->dash_gap + dsc->dash_width) { + dash_cnt = 0; + } + } + dash_cnt ++; + } - lv_blend_fill(clip, &fill_area, - dsc->color, mask_buf, mask_res, dsc->opa, - LV_BLEND_MODE_NORMAL); + lv_blend_fill(clip, &fill_area, + dsc->color, mask_buf, mask_res, dsc->opa, + LV_BLEND_MODE_NORMAL); - fill_area.y1++; - fill_area.y2++; - } + fill_area.y1++; + fill_area.y2++; + } lv_mem_buf_release(mask_buf); } } -static void draw_line_skew(const lv_point_t * point1, const lv_point_t * point2, const lv_area_t * clip, lv_draw_line_dsc_t * dsc) +static void draw_line_skew(const lv_point_t * point1, const lv_point_t * point2, const lv_area_t * clip, + lv_draw_line_dsc_t * dsc) { lv_opa_t opa = dsc->opa; @@ -306,7 +315,8 @@ static void draw_line_skew(const lv_point_t * point1, const lv_point_t * point2, p2.y = point2->y; p1.x = point1->x; p2.x = point2->x; - } else { + } + else { p1.y = point2->y; p2.y = point1->y; p1.x = point2->x; @@ -353,20 +363,28 @@ static void draw_line_skew(const lv_point_t * point1, const lv_point_t * point2, if(flat) { if(xdiff > 0) { - lv_draw_mask_line_points_init(&mask_left_param, p1.x, p1.y - w_half0, p2.x, p2.y - w_half0, LV_DRAW_MASK_LINE_SIDE_LEFT); - lv_draw_mask_line_points_init(&mask_right_param, p1.x, p1.y + w_half1, p2.x, p2.y + w_half1, LV_DRAW_MASK_LINE_SIDE_RIGHT); - } else { - lv_draw_mask_line_points_init(&mask_left_param, p1.x, p1.y + w_half1, p2.x, p2.y + w_half1, LV_DRAW_MASK_LINE_SIDE_LEFT); - lv_draw_mask_line_points_init(&mask_right_param, p1.x, p1.y - w_half0, p2.x, p2.y - w_half0, LV_DRAW_MASK_LINE_SIDE_RIGHT); + lv_draw_mask_line_points_init(&mask_left_param, p1.x, p1.y - w_half0, p2.x, p2.y - w_half0, + LV_DRAW_MASK_LINE_SIDE_LEFT); + lv_draw_mask_line_points_init(&mask_right_param, p1.x, p1.y + w_half1, p2.x, p2.y + w_half1, + LV_DRAW_MASK_LINE_SIDE_RIGHT); } - } else { - lv_draw_mask_line_points_init(&mask_left_param, p1.x + w_half1, p1.y, p2.x + w_half1, p2.y, LV_DRAW_MASK_LINE_SIDE_LEFT); - lv_draw_mask_line_points_init(&mask_right_param, p1.x - w_half0, p1.y, p2.x - w_half0, p2.y, LV_DRAW_MASK_LINE_SIDE_RIGHT); + else { + lv_draw_mask_line_points_init(&mask_left_param, p1.x, p1.y + w_half1, p2.x, p2.y + w_half1, + LV_DRAW_MASK_LINE_SIDE_LEFT); + lv_draw_mask_line_points_init(&mask_right_param, p1.x, p1.y - w_half0, p2.x, p2.y - w_half0, + LV_DRAW_MASK_LINE_SIDE_RIGHT); + } + } + else { + lv_draw_mask_line_points_init(&mask_left_param, p1.x + w_half1, p1.y, p2.x + w_half1, p2.y, + LV_DRAW_MASK_LINE_SIDE_LEFT); + lv_draw_mask_line_points_init(&mask_right_param, p1.x - w_half0, p1.y, p2.x - w_half0, p2.y, + LV_DRAW_MASK_LINE_SIDE_RIGHT); } /*Use the normal vector for the endings*/ lv_draw_mask_line_points_init(&mask_top_param, p1.x, p1.y, p1.x - ydiff, p1.y + xdiff, LV_DRAW_MASK_LINE_SIDE_BOTTOM); - lv_draw_mask_line_points_init(&mask_bottom_param, p2.x, p2.y,p2.x - ydiff, p2.y + xdiff, LV_DRAW_MASK_LINE_SIDE_TOP); + lv_draw_mask_line_points_init(&mask_bottom_param, p2.x, p2.y, p2.x - ydiff, p2.y + xdiff, LV_DRAW_MASK_LINE_SIDE_TOP); int16_t mask_left_id = lv_draw_mask_add(&mask_left_param, NULL); int16_t mask_right_id = lv_draw_mask_add(&mask_right_param, NULL); @@ -401,8 +419,8 @@ static void draw_line_skew(const lv_point_t * point1, const lv_point_t * point2, lv_draw_mask_res_t mask_res = lv_draw_mask_apply(mask_buf, vdb->area.x1 + draw_area.x1, vdb->area.y1 + h, draw_area_w); lv_blend_fill(clip, &fill_area, - dsc->color, mask_buf, mask_res, opa, - dsc->blend_mode); + dsc->color, mask_buf, mask_res, opa, + dsc->blend_mode); fill_area.y1++; fill_area.y2++; diff --git a/src/lv_draw/lv_draw_line.h b/src/lv_draw/lv_draw_line.h index fdcb3977d..b8d54ad42 100644 --- a/src/lv_draw/lv_draw_line.h +++ b/src/lv_draw/lv_draw_line.h @@ -28,10 +28,10 @@ typedef struct { lv_style_int_t dash_width; lv_style_int_t dash_gap; lv_opa_t opa; - lv_blend_mode_t blend_mode :2; - uint8_t round_start :1; - uint8_t round_end :1; -}lv_draw_line_dsc_t; + lv_blend_mode_t blend_mode : 2; + uint8_t round_start : 1; + uint8_t round_end : 1; +} lv_draw_line_dsc_t; /********************** * GLOBAL PROTOTYPES @@ -45,7 +45,8 @@ typedef struct { * @param style pointer to a line's style * @param opa_scale scale down all opacities by the factor */ -void lv_draw_line(const lv_point_t * point1, const lv_point_t * point2, const lv_area_t * mask, lv_draw_line_dsc_t * dsc); +void lv_draw_line(const lv_point_t * point1, const lv_point_t * point2, const lv_area_t * mask, + lv_draw_line_dsc_t * dsc); void lv_draw_line_dsc_init(lv_draw_line_dsc_t * dsc); diff --git a/src/lv_draw/lv_draw_mask.c b/src/lv_draw/lv_draw_mask.c index e894ee660..5c3cc4e05 100644 --- a/src/lv_draw/lv_draw_mask.c +++ b/src/lv_draw/lv_draw_mask.c @@ -19,23 +19,29 @@ /********************** * TYPEDEFS **********************/ -typedef struct -{ +typedef struct { void * param; void * custom_id; -}lv_mask_saved_t; +} lv_mask_saved_t; /********************** * STATIC PROTOTYPES **********************/ -static lv_draw_mask_res_t lv_draw_mask_line(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t len, lv_draw_mask_line_param_t * param); -static lv_draw_mask_res_t lv_draw_mask_radius(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t len, lv_draw_mask_radius_param_t * param); -static lv_draw_mask_res_t lv_draw_mask_angle(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t len, lv_draw_mask_angle_param_t * param); -static lv_draw_mask_res_t lv_draw_mask_fade(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t len, lv_draw_mask_fade_param_t * param); -static lv_draw_mask_res_t lv_draw_mask_map(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t len, lv_draw_mask_map_param_t * param); +static lv_draw_mask_res_t lv_draw_mask_line(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t len, + lv_draw_mask_line_param_t * param); +static lv_draw_mask_res_t lv_draw_mask_radius(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t len, + lv_draw_mask_radius_param_t * param); +static lv_draw_mask_res_t lv_draw_mask_angle(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t len, + lv_draw_mask_angle_param_t * param); +static lv_draw_mask_res_t lv_draw_mask_fade(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t len, + lv_draw_mask_fade_param_t * param); +static lv_draw_mask_res_t lv_draw_mask_map(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t len, + lv_draw_mask_map_param_t * param); -static lv_draw_mask_res_t line_mask_flat(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t len, lv_draw_mask_line_param_t * p); -static lv_draw_mask_res_t line_mask_steep(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t len, lv_draw_mask_line_param_t * p); +static lv_draw_mask_res_t line_mask_flat(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t len, + lv_draw_mask_line_param_t * p); +static lv_draw_mask_res_t line_mask_steep(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t len, + lv_draw_mask_line_param_t * p); static inline lv_opa_t mask_mix(lv_opa_t mask_act, lv_opa_t mask_new); @@ -98,7 +104,7 @@ lv_draw_mask_res_t lv_draw_mask_apply(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_ for(i = 0; i < LV_MASK_MAX_NUM; i++) { if(mask_list[i].param) { dsc = mask_list[i].param; - res = dsc->cb(mask_buf, abs_x, abs_y, len, (void*)mask_list[i].param); + res = dsc->cb(mask_buf, abs_x, abs_y, len, (void *)mask_list[i].param); if(res == LV_DRAW_MASK_RES_FULL_TRANSP) return LV_DRAW_MASK_RES_FULL_TRANSP; else if(res == LV_DRAW_MASK_RES_CHANGED) changed = true; } @@ -171,7 +177,8 @@ uint8_t lv_draw_mask_get_cnt(void) * With `LV_DRAW_MASK_LINE_SIDE_LEFT/RIGHT` and horizontal line all pixels are kept * With `LV_DRAW_MASK_LINE_SIDE_TOP/BOTTOM` and vertical line all pixels are kept */ -void lv_draw_mask_line_points_init(lv_draw_mask_line_param_t * param, lv_coord_t p1x, lv_coord_t p1y, lv_coord_t p2x, lv_coord_t p2y, lv_draw_mask_line_side_t side) +void lv_draw_mask_line_points_init(lv_draw_mask_line_param_t * param, lv_coord_t p1x, lv_coord_t p1y, lv_coord_t p2x, + lv_coord_t p2y, lv_draw_mask_line_side_t side) { memset(param, 0x00, sizeof(lv_draw_mask_line_param_t)); @@ -194,14 +201,14 @@ void lv_draw_mask_line_points_init(lv_draw_mask_line_param_t * param, lv_coord_t param->origo.x = p1x; param->origo.y = p1y; - param->flat = (LV_MATH_ABS(p2x-p1x) > LV_MATH_ABS(p2y-p1y)) ? 1 : 0; + param->flat = (LV_MATH_ABS(p2x - p1x) > LV_MATH_ABS(p2y - p1y)) ? 1 : 0; param->yx_steep = 0; param->xy_steep = 0; param->dsc.cb = (lv_draw_mask_cb_t)lv_draw_mask_line; param->dsc.type = LV_DRAW_MASK_TYPE_LINE; - int32_t dx = p2x-p1x; - int32_t dy = p2y-p1y; + int32_t dx = p2x - p1x; + int32_t dy = p2y - p1y; if(param->flat) { /*Normalize the steep. Delta x should be relative to delta x = 1024*/ @@ -217,7 +224,8 @@ void lv_draw_mask_line_points_init(lv_draw_mask_line_param_t * param, lv_coord_t param->xy_steep = (m * dx) >> 10; } param->steep = param->yx_steep; - } else { + } + else { /*Normalize the steep. Delta y should be relative to delta x = 1024*/ int32_t m; @@ -258,7 +266,8 @@ void lv_draw_mask_line_points_init(lv_draw_mask_line_param_t * param, lv_coord_t * With `LV_DRAW_MASK_LINE_SIDE_LEFT/RIGHT` and horizontal line all pixels are kept * With `LV_DRAW_MASK_LINE_SIDE_TOP/BOTTOM` and vertical line all pixels are kept */ -void lv_draw_mask_line_angle_init(lv_draw_mask_line_param_t* param, lv_coord_t p1x, lv_coord_t py, int16_t angle, lv_draw_mask_line_side_t side) +void lv_draw_mask_line_angle_init(lv_draw_mask_line_param_t * param, lv_coord_t p1x, lv_coord_t py, int16_t angle, + lv_draw_mask_line_side_t side) { /* Find an optimal degree. * lv_mask_line_points_init will swap the points to keep the smaller y in p1 @@ -285,7 +294,8 @@ void lv_draw_mask_line_angle_init(lv_draw_mask_line_param_t* param, lv_coord_t p * @param start_angle start angle in degrees. 0 deg on the right, 90 deg, on the bottom * @param end_angle end angle */ -void lv_draw_mask_angle_init(lv_draw_mask_angle_param_t * param, lv_coord_t vertex_x, lv_coord_t vertex_y, lv_coord_t start_angle, lv_coord_t end_angle) +void lv_draw_mask_angle_init(lv_draw_mask_angle_param_t * param, lv_coord_t vertex_x, lv_coord_t vertex_y, + lv_coord_t start_angle, lv_coord_t end_angle) { lv_draw_mask_line_side_t start_side; lv_draw_mask_line_side_t end_side; @@ -295,7 +305,7 @@ void lv_draw_mask_angle_init(lv_draw_mask_angle_param_t * param, lv_coord_t vert start_angle = 0; else if(start_angle > 359) start_angle = 359; - + if(end_angle < 0) end_angle = 0; else if(end_angle > 359) @@ -303,7 +313,8 @@ void lv_draw_mask_angle_init(lv_draw_mask_angle_param_t * param, lv_coord_t vert if(end_angle < start_angle) { param->delta_deg = 360 - start_angle + end_angle; - } else { + } + else { param->delta_deg = LV_MATH_ABS(end_angle - start_angle); } @@ -319,7 +330,8 @@ void lv_draw_mask_angle_init(lv_draw_mask_angle_param_t * param, lv_coord_t vert } else if(start_angle >= 180 && start_angle < 360) { start_side = LV_DRAW_MASK_LINE_SIDE_RIGHT; - } else { + } + else { LV_DEBUG_ASSERT(false, "Unexpected start_angle", start_angle); return; } @@ -329,7 +341,8 @@ void lv_draw_mask_angle_init(lv_draw_mask_angle_param_t * param, lv_coord_t vert } else if(end_angle >= 180 && end_angle < 360) { end_side = LV_DRAW_MASK_LINE_SIDE_LEFT; - } else { + } + else { LV_DEBUG_ASSERT(false, "Unexpected end_angle", end_angle); return; } @@ -369,12 +382,13 @@ void lv_draw_mask_radius_init(lv_draw_mask_radius_param_t * param, const lv_area * @param opa_bottom opacity at the bottom * @param y_bottom at which coordinate reach `opa_bottom`. */ -void lv_draw_mask_fade_init(lv_draw_mask_fade_param_t * param, lv_area_t * coords, lv_opa_t opa_top, lv_coord_t y_top, lv_opa_t opa_bottom, lv_coord_t y_bottom) +void lv_draw_mask_fade_init(lv_draw_mask_fade_param_t * param, lv_area_t * coords, lv_opa_t opa_top, lv_coord_t y_top, + lv_opa_t opa_bottom, lv_coord_t y_bottom) { lv_area_copy(¶m->cfg.coords, coords); - param->cfg.opa_top= opa_top; + param->cfg.opa_top = opa_top; param->cfg.opa_bottom = opa_bottom; - param->cfg.y_top= y_top; + param->cfg.y_top = y_top; param->cfg.y_bottom = y_bottom; param->dsc.cb = (lv_draw_mask_cb_t)lv_draw_mask_fade; param->dsc.type = LV_DRAW_MASK_TYPE_FADE; @@ -400,7 +414,8 @@ void lv_draw_mask_map_init(lv_draw_mask_map_param_t * param, lv_area_t * coords, * STATIC FUNCTIONS **********************/ -static lv_draw_mask_res_t lv_draw_mask_line(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t len, lv_draw_mask_line_param_t * p) +static lv_draw_mask_res_t lv_draw_mask_line(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t len, + lv_draw_mask_line_param_t * p) { /*Make to points relative to the vertex*/ abs_y -= p->origo.y; @@ -411,8 +426,9 @@ static lv_draw_mask_res_t lv_draw_mask_line(lv_opa_t * mask_buf, lv_coord_t abs_ /*Horizontal*/ if(p->flat) { /*Non sense: Can't be on the right/left of a horizontal line*/ - if(p->cfg.side == LV_DRAW_MASK_LINE_SIDE_LEFT || p->cfg.side == LV_DRAW_MASK_LINE_SIDE_RIGHT) return LV_DRAW_MASK_RES_FULL_COVER; - else if(p->cfg.side == LV_DRAW_MASK_LINE_SIDE_TOP && abs_y+1 < 0) return LV_DRAW_MASK_RES_FULL_COVER; + if(p->cfg.side == LV_DRAW_MASK_LINE_SIDE_LEFT || + p->cfg.side == LV_DRAW_MASK_LINE_SIDE_RIGHT) return LV_DRAW_MASK_RES_FULL_COVER; + else if(p->cfg.side == LV_DRAW_MASK_LINE_SIDE_TOP && abs_y + 1 < 0) return LV_DRAW_MASK_RES_FULL_COVER; else if(p->cfg.side == LV_DRAW_MASK_LINE_SIDE_BOTTOM && abs_y > 0) return LV_DRAW_MASK_RES_FULL_COVER; else { return LV_DRAW_MASK_RES_FULL_TRANSP; @@ -421,7 +437,8 @@ static lv_draw_mask_res_t lv_draw_mask_line(lv_opa_t * mask_buf, lv_coord_t abs_ /*Vertical*/ else { /*Non sense: Can't be on the top/bottom of a vertical line*/ - if(p->cfg.side == LV_DRAW_MASK_LINE_SIDE_TOP || p->cfg.side == LV_DRAW_MASK_LINE_SIDE_BOTTOM) return LV_DRAW_MASK_RES_FULL_COVER; + if(p->cfg.side == LV_DRAW_MASK_LINE_SIDE_TOP || + p->cfg.side == LV_DRAW_MASK_LINE_SIDE_BOTTOM) return LV_DRAW_MASK_RES_FULL_COVER; else if(p->cfg.side == LV_DRAW_MASK_LINE_SIDE_RIGHT && abs_x > 0) return LV_DRAW_MASK_RES_FULL_COVER; else if(p->cfg.side == LV_DRAW_MASK_LINE_SIDE_LEFT) { if(abs_x + len < 0) return LV_DRAW_MASK_RES_FULL_COVER; @@ -438,7 +455,7 @@ static lv_draw_mask_res_t lv_draw_mask_line(lv_opa_t * mask_buf, lv_coord_t abs_ int32_t k = - abs_x; if(k < 0) k = 0; if(k >= len) return LV_DRAW_MASK_RES_FULL_TRANSP; - else if(k >= 0 && k < len) memset(&mask_buf[0], 0x00,k); + else if(k >= 0 && k < len) memset(&mask_buf[0], 0x00, k); return LV_DRAW_MASK_RES_CHANGED; } } @@ -448,14 +465,16 @@ static lv_draw_mask_res_t lv_draw_mask_line(lv_opa_t * mask_buf, lv_coord_t abs_ lv_draw_mask_res_t res; if(p->flat) { res = line_mask_flat(mask_buf, abs_x, abs_y, len, p); - } else { + } + else { res = line_mask_steep(mask_buf, abs_x, abs_y, len, p); } return res; } -static lv_draw_mask_res_t line_mask_flat(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t len, lv_draw_mask_line_param_t * p) +static lv_draw_mask_res_t line_mask_flat(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t len, + lv_draw_mask_line_param_t * p) { int32_t y_at_x; y_at_x = (int32_t)((int32_t)p->yx_steep * abs_x) >> 10; @@ -464,15 +483,18 @@ static lv_draw_mask_res_t line_mask_flat(lv_opa_t * mask_buf, lv_coord_t abs_x, if(y_at_x > abs_y) { if(p->inv) { return LV_DRAW_MASK_RES_FULL_COVER; - } else { + } + else { return LV_DRAW_MASK_RES_FULL_TRANSP; } } - } else { + } + else { if(y_at_x < abs_y) { if(p->inv) { return LV_DRAW_MASK_RES_FULL_COVER; - } else { + } + else { return LV_DRAW_MASK_RES_FULL_TRANSP; } } @@ -485,15 +507,18 @@ static lv_draw_mask_res_t line_mask_flat(lv_opa_t * mask_buf, lv_coord_t abs_x, if(y_at_x < abs_y) { if(p->inv) { return LV_DRAW_MASK_RES_FULL_TRANSP; - } else { + } + else { return LV_DRAW_MASK_RES_FULL_COVER; } } - } else { + } + else { if(y_at_x > abs_y) { if(p->inv) { return LV_DRAW_MASK_RES_FULL_TRANSP; - } else { + } + else { return LV_DRAW_MASK_RES_FULL_COVER; } } @@ -514,7 +539,7 @@ static lv_draw_mask_res_t line_mask_flat(lv_opa_t * mask_buf, lv_coord_t abs_x, if(xef) { if(k >= 0 && k < len) { - m = 255 - (((255-xef) * (255 - px_h)) >> 9); + m = 255 - (((255 - xef) * (255 - px_h)) >> 9); if(p->inv) m = 255 - m; mask_buf[k] = mask_mix(mask_buf[k], m); } @@ -547,11 +572,11 @@ static lv_draw_mask_res_t line_mask_flat(lv_opa_t * mask_buf, lv_coord_t abs_x, if(k > len) { return LV_DRAW_MASK_RES_FULL_TRANSP; } - if(k >= 0) - { + if(k >= 0) { memset(&mask_buf[0], 0x00, k); } - } else { + } + else { k++; if(k < 0) { return LV_DRAW_MASK_RES_FULL_TRANSP; @@ -564,7 +589,8 @@ static lv_draw_mask_res_t line_mask_flat(lv_opa_t * mask_buf, lv_coord_t abs_x, return LV_DRAW_MASK_RES_CHANGED; } -static lv_draw_mask_res_t line_mask_steep(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t len, lv_draw_mask_line_param_t * p) +static lv_draw_mask_res_t line_mask_steep(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t len, + lv_draw_mask_line_param_t * p) { int32_t k; int32_t x_at_y; @@ -575,7 +601,8 @@ static lv_draw_mask_res_t line_mask_steep(lv_opa_t * mask_buf, lv_coord_t abs_x, if(x_at_y < abs_x) { if(p->inv) { return LV_DRAW_MASK_RES_FULL_COVER; - } else { + } + else { return LV_DRAW_MASK_RES_FULL_TRANSP; } } @@ -586,7 +613,8 @@ static lv_draw_mask_res_t line_mask_steep(lv_opa_t * mask_buf, lv_coord_t abs_x, if(x_at_y > abs_x + len) { if(p->inv) { return LV_DRAW_MASK_RES_FULL_TRANSP; - } else { + } + else { return LV_DRAW_MASK_RES_FULL_COVER; } } @@ -623,32 +651,34 @@ static lv_draw_mask_res_t line_mask_steep(lv_opa_t * mask_buf, lv_coord_t abs_x, } if(k >= 0) memset(&mask_buf[0], 0x00, k); - } else { + } + else { if(k > len) k = len; if(k == 0) return LV_DRAW_MASK_RES_FULL_TRANSP; - else if(k > 0) memset(&mask_buf[k] ,0x00, len - k); + else if(k > 0) memset(&mask_buf[k], 0x00, len - k); } - } else { + } + else { int32_t y_inters; if(p->xy_steep < 0) { y_inters = (xef * (-p->yx_steep)) >> 10; - if(k >= 0 && k < len ) { + if(k >= 0 && k < len) { m = (y_inters * xef) >> 9; if(p->inv) m = 255 - m; mask_buf[k] = mask_mix(mask_buf[k], m); } k--; - int32_t x_inters = ((255-y_inters) * (-p->xy_steep)) >> 10; + int32_t x_inters = ((255 - y_inters) * (-p->xy_steep)) >> 10; - if(k >= 0 && k < len ) { - m = 255-(((255-y_inters) * x_inters) >> 9); + if(k >= 0 && k < len) { + m = 255 - (((255 - y_inters) * x_inters) >> 9); if(p->inv) m = 255 - m; mask_buf[k] = mask_mix(mask_buf[k], m); } - k+=2; + k += 2; if(p->inv) { k = xei - abs_x - 1; @@ -656,24 +686,26 @@ static lv_draw_mask_res_t line_mask_steep(lv_opa_t * mask_buf, lv_coord_t abs_x, if(k > len) k = len; else if(k > 0) memset(&mask_buf[0], 0x00, k); - } else { + } + else { if(k > len) return LV_DRAW_MASK_RES_FULL_COVER; - if(k >= 0) memset(&mask_buf[k] ,0x00, len - k); + if(k >= 0) memset(&mask_buf[k], 0x00, len - k); } - } else { - y_inters = ((255-xef) * p->yx_steep) >> 10; - if(k >= 0 && k < len ) { - m = 255 - ((y_inters * (255-xef)) >> 9); + } + else { + y_inters = ((255 - xef) * p->yx_steep) >> 10; + if(k >= 0 && k < len) { + m = 255 - ((y_inters * (255 - xef)) >> 9); if(p->inv) m = 255 - m; mask_buf[k] = mask_mix(mask_buf[k], m); } k++; - int32_t x_inters = ((255-y_inters) * p->xy_steep) >> 10; - if(k >= 0 && k < len ) { - m = ((255-y_inters) * x_inters) >> 9; + int32_t x_inters = ((255 - y_inters) * p->xy_steep) >> 10; + if(k >= 0 && k < len) { + m = ((255 - y_inters) * x_inters) >> 9; if(p->inv) m = 255 - m; mask_buf[k] = mask_mix(mask_buf[k], m); } @@ -684,10 +716,11 @@ static lv_draw_mask_res_t line_mask_steep(lv_opa_t * mask_buf, lv_coord_t abs_x, if(k > len) return LV_DRAW_MASK_RES_FULL_TRANSP; if(k >= 0) memset(&mask_buf[0], 0x00, k); - } else { + } + else { if(k > len) k = len; if(k == 0) return LV_DRAW_MASK_RES_FULL_TRANSP; - else if(k > 0) memset(&mask_buf[k] ,0x00, len - k); + else if(k > 0) memset(&mask_buf[k], 0x00, len - k); } } @@ -697,7 +730,8 @@ static lv_draw_mask_res_t line_mask_steep(lv_opa_t * mask_buf, lv_coord_t abs_x, } -static lv_draw_mask_res_t lv_draw_mask_angle(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t len, lv_draw_mask_angle_param_t * p) +static lv_draw_mask_res_t lv_draw_mask_angle(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t len, + lv_draw_mask_angle_param_t * p) { int32_t rel_y = abs_y - p->cfg.vertex_p.y; int32_t rel_x = abs_x - p->cfg.vertex_p.x; @@ -713,7 +747,7 @@ static lv_draw_mask_res_t lv_draw_mask_angle(lv_opa_t * mask_buf, lv_coord_t abs /*Start angle mask can work only from the end of end angle mask */ int32_t end_angle_first = (rel_y * p->end_line.xy_steep) >> 10; - int32_t start_angle_last= ((rel_y+1) * p->start_line.xy_steep) >> 10; + int32_t start_angle_last = ((rel_y + 1) * p->start_line.xy_steep) >> 10; /*Do not let the line end cross the vertex else it will affect the opposite part*/ @@ -742,9 +776,9 @@ static lv_draw_mask_res_t lv_draw_mask_angle(lv_opa_t * mask_buf, lv_coord_t abs if(tmp > len) tmp = len; if(tmp < 0) tmp = 0; - res2 = lv_draw_mask_line(&mask_buf[tmp], abs_x+tmp, abs_y, len-tmp, &p->end_line); + res2 = lv_draw_mask_line(&mask_buf[tmp], abs_x + tmp, abs_y, len - tmp, &p->end_line); if(res2 == LV_DRAW_MASK_RES_FULL_TRANSP) { - memset(&mask_buf[tmp], 0x00, len-tmp); + memset(&mask_buf[tmp], 0x00, len - tmp); } if(res1 == res2) return res1; else return LV_DRAW_MASK_RES_CHANGED; @@ -757,7 +791,7 @@ static lv_draw_mask_res_t lv_draw_mask_angle(lv_opa_t * mask_buf, lv_coord_t abs /*Start angle mask can work only from the end of end angle mask */ int32_t end_angle_first = (rel_y * p->end_line.xy_steep) >> 10; - int32_t start_angle_last= ((rel_y+1) * p->start_line.xy_steep) >> 10; + int32_t start_angle_last = ((rel_y + 1) * p->start_line.xy_steep) >> 10; /*Do not let the line end cross the vertex else it will affect the opposite part*/ if(p->cfg.start_angle > 270 && p->cfg.start_angle <= 359 && start_angle_last < 0) start_angle_last = 0; @@ -776,7 +810,7 @@ static lv_draw_mask_res_t lv_draw_mask_angle(lv_opa_t * mask_buf, lv_coord_t abs int32_t tmp = start_angle_last + dist - rel_x; if(tmp > len) tmp = len; if(tmp > 0) { - res1 = lv_draw_mask_line(&mask_buf[0], abs_x, abs_y, tmp, (lv_draw_mask_line_param_t*)&p->end_line); + res1 = lv_draw_mask_line(&mask_buf[0], abs_x, abs_y, tmp, (lv_draw_mask_line_param_t *)&p->end_line); if(res1 == LV_DRAW_MASK_RES_FULL_TRANSP) { memset(&mask_buf[0], 0x00, tmp); } @@ -784,9 +818,9 @@ static lv_draw_mask_res_t lv_draw_mask_angle(lv_opa_t * mask_buf, lv_coord_t abs if(tmp > len) tmp = len; if(tmp < 0) tmp = 0; - res2 = lv_draw_mask_line(&mask_buf[tmp], abs_x+tmp, abs_y, len-tmp, (lv_draw_mask_line_param_t*)&p->start_line); + res2 = lv_draw_mask_line(&mask_buf[tmp], abs_x + tmp, abs_y, len - tmp, (lv_draw_mask_line_param_t *)&p->start_line); if(res2 == LV_DRAW_MASK_RES_FULL_TRANSP) { - memset(&mask_buf[tmp], 0x00, len-tmp); + memset(&mask_buf[tmp], 0x00, len - tmp); } if(res1 == res2) return res1; else return LV_DRAW_MASK_RES_CHANGED; @@ -835,20 +869,22 @@ static lv_draw_mask_res_t lv_draw_mask_angle(lv_opa_t * mask_buf, lv_coord_t abs } } -static lv_draw_mask_res_t lv_draw_mask_radius(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t len, lv_draw_mask_radius_param_t * p) +static lv_draw_mask_res_t lv_draw_mask_radius(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t len, + lv_draw_mask_radius_param_t * p) { if(p->cfg.outer == 0) { if(abs_y < p->cfg.rect.y1 || abs_y > p->cfg.rect.y2) { return LV_DRAW_MASK_RES_FULL_TRANSP; } - } else { + } + else { if(abs_y < p->cfg.rect.y1 || abs_y > p->cfg.rect.y2) { return LV_DRAW_MASK_RES_FULL_COVER; } } if((abs_x >= p->cfg.rect.x1 + p->cfg.radius && abs_x + len <= p->cfg.rect.x2 - p->cfg.radius) || - (abs_y >= p->cfg.rect.y1 + p->cfg.radius && abs_y <= p->cfg.rect.y2 - p->cfg.radius)) { + (abs_y >= p->cfg.rect.y1 + p->cfg.radius && abs_y <= p->cfg.rect.y2 - p->cfg.radius)) { if(p->cfg.outer == 0) { /*Remove the edges*/ int32_t last = p->cfg.rect.x1 - abs_x; @@ -860,7 +896,7 @@ static lv_draw_mask_res_t lv_draw_mask_radius(lv_opa_t * mask_buf, lv_coord_t ab int32_t first = p->cfg.rect.x2 - abs_x + 1; if(first <= 0) return LV_DRAW_MASK_RES_FULL_TRANSP; else if(first < len) { - memset(&mask_buf[first], 0x00, len-first); + memset(&mask_buf[first], 0x00, len - first); } if(last == 0 && first == len) return LV_DRAW_MASK_RES_FULL_COVER; else return LV_DRAW_MASK_RES_CHANGED; @@ -879,7 +915,7 @@ static lv_draw_mask_res_t lv_draw_mask_radius(lv_opa_t * mask_buf, lv_coord_t ab return LV_DRAW_MASK_RES_CHANGED; } - int32_t k = p->cfg.rect.x1 -abs_x; /*First relevant coordinate on the of the mask*/ + int32_t k = p->cfg.rect.x1 - abs_x; /*First relevant coordinate on the of the mask*/ int32_t w = lv_area_get_width(&p->cfg.rect); int32_t h = lv_area_get_height(&p->cfg.rect); abs_x -= p->cfg.rect.x1; @@ -900,7 +936,7 @@ static lv_draw_mask_res_t lv_draw_mask_radius(lv_opa_t * mask_buf, lv_coord_t ab lv_sqrt(r2 - (y * y), &x0); lv_sqrt_res_t x1; - lv_sqrt(r2 - ((y-1) * (y-1)), &x1); + lv_sqrt(r2 - ((y - 1) * (y - 1)), &x1); /* If x1 is on the next round coordinate (e.g. x0: 3.5, x1:4.0) * then treat x1 as x1: 3.99 to handle them as they were on the same pixel*/ @@ -923,7 +959,7 @@ static lv_draw_mask_res_t lv_draw_mask_radius(lv_opa_t * mask_buf, lv_coord_t ab } /*Right corner*/ - int32_t kr = k+(w-ofs-1); + int32_t kr = k + (w - ofs - 1); if(kr >= 0 && kr < len) { mask_buf[kr] = mask_mix(mask_buf[kr], m); } @@ -941,14 +977,15 @@ static lv_draw_mask_res_t lv_draw_mask_radius(lv_opa_t * mask_buf, lv_coord_t ab return LV_DRAW_MASK_RES_FULL_TRANSP; } if(kr <= len) { - memset(&mask_buf[kr], 0x00, len-kr); + memset(&mask_buf[kr], 0x00, len - kr); } - } else { + } + else { kl++; int32_t first = kl; if(first < 0) first = 0; - int32_t len_tmp = kr-first; + int32_t len_tmp = kr - first; if(len_tmp + first > len) len_tmp = len - first; if(first < len && len_tmp >= 0) { memset(&mask_buf[first], 0x00, len_tmp); @@ -959,13 +996,13 @@ static lv_draw_mask_res_t lv_draw_mask_radius(lv_opa_t * mask_buf, lv_coord_t ab else { int32_t ofs = p->cfg.radius - (x0.i + 1); int32_t kl = k + ofs; - int32_t kr = k + (w - ofs -1); + int32_t kr = k + (w - ofs - 1); if(p->cfg.outer) { int32_t first = kl + 1; if(first < 0) first = 0; - int32_t len_tmp = kr-first; + int32_t len_tmp = kr - first; if(len_tmp + first > len) len_tmp = len - first; if(first < len && len_tmp >= 0) { memset(&mask_buf[first], 0x00, len_tmp); @@ -987,7 +1024,7 @@ static lv_draw_mask_res_t lv_draw_mask_radius(lv_opa_t * mask_buf, lv_coord_t ab /*The first y intersection is special as it might be in the previous line*/ if(y_prev.i >= y) { lv_sqrt(r2 - (i * i), &y_next); - m = 255 - (((255-x0.f) * (255 - y_next.f)) >> 9); + m = 255 - (((255 - x0.f) * (255 - y_next.f)) >> 9); if(p->cfg.outer) m = 255 - m; if(kl >= 0 && kl < len) mask_buf[kl] = mask_mix(mask_buf[kl], m); @@ -1041,7 +1078,8 @@ static lv_draw_mask_res_t lv_draw_mask_radius(lv_opa_t * mask_buf, lv_coord_t ab } -static lv_draw_mask_res_t lv_draw_mask_fade(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t len, lv_draw_mask_fade_param_t * p) +static lv_draw_mask_res_t lv_draw_mask_fade(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t len, + lv_draw_mask_fade_param_t * p) { if(abs_y < p->cfg.coords.y1) return LV_DRAW_MASK_RES_FULL_COVER; if(abs_y > p->cfg.coords.y2) return LV_DRAW_MASK_RES_FULL_COVER; @@ -1064,12 +1102,14 @@ static lv_draw_mask_res_t lv_draw_mask_fade(lv_opa_t * mask_buf, lv_coord_t abs_ mask_buf[i] = mask_mix(mask_buf[i], p->cfg.opa_top); } return LV_DRAW_MASK_RES_CHANGED; - } else if(abs_y >= p->cfg.y_bottom) { + } + else if(abs_y >= p->cfg.y_bottom) { for(i = 0; i < len; i++) { mask_buf[i] = mask_mix(mask_buf[i], p->cfg.opa_bottom); } return LV_DRAW_MASK_RES_CHANGED; - } else { + } + else { /*Calculate the opa proportionally*/ int16_t opa_diff = p->cfg.opa_bottom - p->cfg.opa_top; int32_t y_diff = p->cfg.y_bottom - p->cfg.y_top + 1; @@ -1086,7 +1126,8 @@ static lv_draw_mask_res_t lv_draw_mask_fade(lv_opa_t * mask_buf, lv_coord_t abs_ return LV_DRAW_MASK_RES_FULL_COVER; } -static lv_draw_mask_res_t lv_draw_mask_map(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t len, lv_draw_mask_map_param_t * p) +static lv_draw_mask_res_t lv_draw_mask_map(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t len, + lv_draw_mask_map_param_t * p) { /*Handle out of the mask cases*/ if(abs_y < p->cfg.coords.y1) return LV_DRAW_MASK_RES_FULL_COVER; @@ -1106,7 +1147,8 @@ static lv_draw_mask_res_t lv_draw_mask_map(lv_opa_t * mask_buf, lv_coord_t abs_x x_ofs = p->cfg.coords.x1 - abs_x; len -= x_ofs; mask_buf += x_ofs; - } else { + } + else { map_tmp += (abs_x - p->cfg.coords.x1); } @@ -1124,6 +1166,6 @@ static inline lv_opa_t mask_mix(lv_opa_t mask_act, lv_opa_t mask_new) if(mask_new >= LV_OPA_MAX) return mask_act; if(mask_new <= LV_OPA_MIN) return 0; - return (int32_t)((int32_t) (mask_act * mask_new) >> 8); + return (int32_t)((int32_t)(mask_act * mask_new) >> 8); } diff --git a/src/lv_draw/lv_draw_mask.h b/src/lv_draw/lv_draw_mask.h index a0c48b900..6c36c6480 100644 --- a/src/lv_draw/lv_draw_mask.h +++ b/src/lv_draw/lv_draw_mask.h @@ -53,14 +53,15 @@ enum { LV_DRAW_MASK_LINE_SIDE_BOTTOM, }; -typedef lv_draw_mask_res_t (*lv_draw_mask_cb_t)(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t len, void * p); +typedef lv_draw_mask_res_t (*lv_draw_mask_cb_t)(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t len, + void * p); typedef uint8_t lv_draw_mask_line_side_t; typedef struct { lv_draw_mask_cb_t cb; lv_draw_mask_type_t type; -}lv_draw_mask_common_dsc_t; +} lv_draw_mask_common_dsc_t; typedef struct { /*The first element must be the common descriptor*/ @@ -74,8 +75,8 @@ typedef struct { lv_point_t p2; /*Which side to keep?*/ - lv_draw_mask_line_side_t side :2; - }cfg; + lv_draw_mask_line_side_t side : 2; + } cfg; /*A point of the line*/ lv_point_t origo; @@ -93,13 +94,13 @@ typedef struct { int32_t spx; /*1: It's a flat line? (Near to horizontal)*/ - uint8_t flat :1; + uint8_t flat : 1; /* Invert the mask. The default is: Keep the left part. * It is used to select left/right/top/bottom*/ - uint8_t inv:1; -}lv_draw_mask_line_param_t; + uint8_t inv: 1; +} lv_draw_mask_line_param_t; typedef struct { /*The first element must be the common descriptor*/ @@ -109,12 +110,12 @@ typedef struct { lv_point_t vertex_p; lv_coord_t start_angle; lv_coord_t end_angle; - }cfg; + } cfg; lv_draw_mask_line_param_t start_line; lv_draw_mask_line_param_t end_line; uint16_t delta_deg; -}lv_draw_mask_angle_param_t; +} lv_draw_mask_angle_param_t; typedef struct { /*The first element must be the common descriptor*/ @@ -124,10 +125,10 @@ typedef struct { lv_area_t rect; lv_coord_t radius; /* Invert the mask. 0: Keep the pixels inside.*/ - uint8_t outer:1; - }cfg; + uint8_t outer: 1; + } cfg; -}lv_draw_mask_radius_param_t; +} lv_draw_mask_radius_param_t; typedef struct { /*The first element must be the common descriptor*/ @@ -139,9 +140,9 @@ typedef struct { lv_coord_t y_bottom; lv_opa_t opa_top; lv_opa_t opa_bottom; - }cfg; + } cfg; -}lv_draw_mask_fade_param_t; +} lv_draw_mask_fade_param_t; typedef struct _lv_draw_mask_map_param_t { /*The first element must be the common descriptor*/ @@ -150,8 +151,8 @@ typedef struct _lv_draw_mask_map_param_t { struct { lv_area_t coords; const lv_opa_t * map; - }cfg; -}lv_draw_mask_map_param_t; + } cfg; +} lv_draw_mask_map_param_t; /********************** * GLOBAL PROTOTYPES @@ -211,7 +212,8 @@ uint8_t lv_draw_mask_get_cnt(void); * With `LV_DRAW_MASK_LINE_SIDE_LEFT/RIGHT` and horizontal line all pixels are kept * With `LV_DRAW_MASK_LINE_SIDE_TOP/BOTTOM` and vertical line all pixels are kept */ -void lv_draw_mask_line_points_init(lv_draw_mask_line_param_t * param, lv_coord_t p1x, lv_coord_t p1y, lv_coord_t p2x, lv_coord_t p2y, lv_draw_mask_line_side_t side); +void lv_draw_mask_line_points_init(lv_draw_mask_line_param_t * param, lv_coord_t p1x, lv_coord_t p1y, lv_coord_t p2x, + lv_coord_t p2y, lv_draw_mask_line_side_t side); /** *Initialize a line mask from a point and an angle. @@ -223,7 +225,8 @@ void lv_draw_mask_line_points_init(lv_draw_mask_line_param_t * param, lv_coord_t * With `LV_DRAW_MASK_LINE_SIDE_LEFT/RIGHT` and horizontal line all pixels are kept * With `LV_DRAW_MASK_LINE_SIDE_TOP/BOTTOM` and vertical line all pixels are kept */ -void lv_draw_mask_line_angle_init(lv_draw_mask_line_param_t * param, lv_coord_t p1x, lv_coord_t py, int16_t angle, lv_draw_mask_line_side_t side); +void lv_draw_mask_line_angle_init(lv_draw_mask_line_param_t * param, lv_coord_t p1x, lv_coord_t py, int16_t angle, + lv_draw_mask_line_side_t side); /** * Initialize an angle mask. @@ -233,7 +236,8 @@ void lv_draw_mask_line_angle_init(lv_draw_mask_line_param_t * param, lv_coord_t * @param start_angle start angle in degrees. 0 deg on the right, 90 deg, on the bottom * @param end_angle end angle */ -void lv_draw_mask_angle_init(lv_draw_mask_angle_param_t * param, lv_coord_t vertex_x, lv_coord_t vertex_y, lv_coord_t start_angle, lv_coord_t end_angle); +void lv_draw_mask_angle_init(lv_draw_mask_angle_param_t * param, lv_coord_t vertex_x, lv_coord_t vertex_y, + lv_coord_t start_angle, lv_coord_t end_angle); /** * Initialize a fade mask. @@ -253,7 +257,8 @@ void lv_draw_mask_radius_init(lv_draw_mask_radius_param_t * param, const lv_area * @param opa_bottom opacity at the bottom * @param y_bottom at which coordinate reach `opa_bottom`. */ -void lv_draw_mask_fade_init(lv_draw_mask_fade_param_t * param, lv_area_t * coords, lv_opa_t opa_top, lv_coord_t y_top, lv_opa_t opa_bottom, lv_coord_t y_bottom); +void lv_draw_mask_fade_init(lv_draw_mask_fade_param_t * param, lv_area_t * coords, lv_opa_t opa_top, lv_coord_t y_top, + lv_opa_t opa_bottom, lv_coord_t y_bottom); /** * Initialize a map mask. diff --git a/src/lv_draw/lv_draw_rect.c b/src/lv_draw/lv_draw_rect.c index b3714e508..96636e50e 100644 --- a/src/lv_draw/lv_draw_rect.c +++ b/src/lv_draw/lv_draw_rect.c @@ -100,27 +100,27 @@ void lv_draw_rect(const lv_area_t * coords, const lv_area_t * clip, lv_draw_rect */ void lv_draw_px(const lv_point_t * point, const lv_area_t * clip_area, const lv_style_t * style) { -// lv_opa_t opa = style->body.opa; -// if(opa_scale != LV_OPA_COVER) opa = (opa * opa_scale) >> 8; -// -// if(opa > LV_OPA_MAX) opa = LV_OPA_COVER; -// -// lv_area_t fill_area; -// fill_area.x1 = point->x; -// fill_area.y1 = point->y; -// fill_area.x2 = point->x; -// fill_area.y2 = point->y; -// -// uint8_t mask_cnt = lv_draw_mask_get_cnt(); -// -// if(mask_cnt == 0) { -// lv_blend_fill(clip_area, &fill_area, style->body.main_color, NULL, LV_DRAW_MASK_RES_FULL_COVER, opa, style->body.blend_mode); -// } else { -// uint8_t mask_buf; -// lv_draw_mask_res_t mask_res; -// mask_res = lv_draw_mask_apply(&mask_buf, point->x, point->y, 1); -// lv_blend_fill(clip_area, &fill_area, style->body.main_color, &mask_buf, mask_res, opa, style->body.blend_mode); -// } + // lv_opa_t opa = style->body.opa; + // if(opa_scale != LV_OPA_COVER) opa = (opa * opa_scale) >> 8; + // + // if(opa > LV_OPA_MAX) opa = LV_OPA_COVER; + // + // lv_area_t fill_area; + // fill_area.x1 = point->x; + // fill_area.y1 = point->y; + // fill_area.x2 = point->x; + // fill_area.y2 = point->y; + // + // uint8_t mask_cnt = lv_draw_mask_get_cnt(); + // + // if(mask_cnt == 0) { + // lv_blend_fill(clip_area, &fill_area, style->body.main_color, NULL, LV_DRAW_MASK_RES_FULL_COVER, opa, style->body.blend_mode); + // } else { + // uint8_t mask_buf; + // lv_draw_mask_res_t mask_res; + // mask_res = lv_draw_mask_apply(&mask_buf, point->x, point->y, 1); + // lv_blend_fill(clip_area, &fill_area, style->body.main_color, &mask_buf, mask_res, opa, style->body.blend_mode); + // } } /********************** @@ -188,8 +188,8 @@ static void draw_bg(const lv_area_t * coords, const lv_area_t * clip, lv_draw_re /*Most simple case: just a plain rectangle*/ if(simple_mode && rout == 0 && (dsc->bg_grad_dir == LV_GRAD_DIR_NONE)) { lv_blend_fill(clip, &coords_bg, - dsc->bg_color, NULL, LV_DRAW_MASK_RES_FULL_COVER, opa, - dsc->bg_blend_mode); + dsc->bg_color, NULL, LV_DRAW_MASK_RES_FULL_COVER, opa, + dsc->bg_blend_mode); } /*More complex case: there is a radius, gradient or other mask.*/ else { @@ -226,7 +226,7 @@ static void draw_bg(const lv_area_t * coords, const lv_area_t * clip, lv_draw_re /*In not corner areas apply the mask only if required*/ if(y > coords_bg.y1 + rout + 1 && - y < coords_bg.y2 - rout - 1) { + y < coords_bg.y2 - rout - 1) { mask_res = LV_DRAW_MASK_RES_FULL_COVER; if(simple_mode == false) { memset(mask_buf, LV_OPA_COVER, draw_area_w); @@ -247,8 +247,8 @@ static void draw_bg(const lv_area_t * coords, const lv_area_t * clip, lv_draw_re /* If there is not other mask and drawing the corner area split the drawing to corner and middle areas * because it the middle mask shuldn't be taken into account (therefore its faster)*/ if(simple_mode && - (y < coords_bg.y1 + rout + 1 || - y > coords_bg.y2 - rout - 1)) { + (y < coords_bg.y1 + rout + 1 || + y > coords_bg.y2 - rout - 1)) { /*Left part*/ lv_area_t fill_area2; @@ -258,7 +258,7 @@ static void draw_bg(const lv_area_t * coords, const lv_area_t * clip, lv_draw_re fill_area2.y2 = fill_area.y2; lv_blend_fill(clip, &fill_area2, - grad_color, mask_buf, mask_res, opa, dsc->bg_blend_mode); + grad_color, mask_buf, mask_res, opa, dsc->bg_blend_mode); /*Right part*/ fill_area2.x1 = coords_bg.x2 - rout + 1; @@ -267,16 +267,19 @@ static void draw_bg(const lv_area_t * coords, const lv_area_t * clip, lv_draw_re int32_t mask_ofs = (coords_bg.x2 - rout + 1) - (vdb->area.x1 + draw_area.x1); if(mask_ofs < 0) mask_ofs = 0; lv_blend_fill(clip, &fill_area2, - grad_color, mask_buf + mask_ofs, mask_res, opa, dsc->bg_blend_mode); - } else { + grad_color, mask_buf + mask_ofs, mask_res, opa, dsc->bg_blend_mode); + } + else { if(dsc->bg_grad_dir == LV_GRAD_DIR_HOR) { lv_blend_map(clip, &fill_area, grad_map, mask_buf, mask_res, opa, dsc->bg_blend_mode); - } else if(dsc->bg_grad_dir == LV_GRAD_DIR_VER) { + } + else if(dsc->bg_grad_dir == LV_GRAD_DIR_VER) { lv_blend_fill(clip, &fill_area, - grad_color,mask_buf, mask_res, opa, dsc->bg_blend_mode); - } else if(other_mask_cnt != 0) { + grad_color, mask_buf, mask_res, opa, dsc->bg_blend_mode); + } + else if(other_mask_cnt != 0) { lv_blend_fill(clip, &fill_area, - grad_color,mask_buf, mask_res, opa, dsc->bg_blend_mode); + grad_color, mask_buf, mask_res, opa, dsc->bg_blend_mode); } } fill_area.y1++; @@ -292,13 +295,13 @@ static void draw_bg(const lv_area_t * coords, const lv_area_t * clip, lv_draw_re fill_area.y2 = coords_bg.y1 + rout; lv_blend_fill(clip, &fill_area, - dsc->bg_color, NULL, LV_DRAW_MASK_RES_FULL_COVER, opa, dsc->bg_blend_mode); + dsc->bg_color, NULL, LV_DRAW_MASK_RES_FULL_COVER, opa, dsc->bg_blend_mode); fill_area.y1 = coords_bg.y2 - rout; fill_area.y2 = coords_bg.y2; lv_blend_fill(clip, &fill_area, - dsc->bg_color, NULL, LV_DRAW_MASK_RES_FULL_COVER, opa, dsc->bg_blend_mode); + dsc->bg_color, NULL, LV_DRAW_MASK_RES_FULL_COVER, opa, dsc->bg_blend_mode); fill_area.x1 = coords_bg.x1; fill_area.x2 = coords_bg.x2; @@ -306,7 +309,7 @@ static void draw_bg(const lv_area_t * coords, const lv_area_t * clip, lv_draw_re fill_area.y2 = coords_bg.y2 - rout - 1; lv_blend_fill(clip, &fill_area, - dsc->bg_color, NULL, LV_DRAW_MASK_RES_FULL_COVER, opa, dsc->bg_blend_mode); + dsc->bg_color, NULL, LV_DRAW_MASK_RES_FULL_COVER, opa, dsc->bg_blend_mode); } @@ -448,7 +451,7 @@ static void draw_border(const lv_area_t * coords, const lv_area_t * clip, lv_dra fill_area.y1 = disp_area->y1 + lower_corner_end; fill_area.y2 = fill_area.y1; for(h = lower_corner_end; h <= draw_area.y2; h++) { - memset(mask_buf, LV_OPA_COVER, draw_area_w); + memset(mask_buf, LV_OPA_COVER, draw_area_w); mask_res = lv_draw_mask_apply(mask_buf, vdb->area.x1 + draw_area.x1, vdb->area.y1 + h, draw_area_w); lv_area_t fill_area2; @@ -460,7 +463,7 @@ static void draw_border(const lv_area_t * coords, const lv_area_t * clip, lv_dra lv_blend_fill(clip, &fill_area2, color, mask_buf, mask_res, opa, blend_mode); /*Draw the bottom horizontal line*/ - if(fill_area2.y2 > coords->y2 - dsc->border_width ) { + if(fill_area2.y2 > coords->y2 - dsc->border_width) { fill_area2.x1 = coords->x1 + rout; fill_area2.x2 = coords->x2 - rout; @@ -499,8 +502,8 @@ static void draw_border(const lv_area_t * coords, const lv_area_t * clip, lv_dra fill_area.y1 = disp_area->y1 + draw_area.y1; fill_area.y2 = fill_area.y1; - if(dsc->border_side == LV_BORDER_SIDE_LEFT) fill_area.x2 = coords->x1 + corner_size; - else if(dsc->border_side == LV_BORDER_SIDE_RIGHT) fill_area.x1 = coords->x2 - corner_size; + if(dsc->border_side == LV_BORDER_SIDE_LEFT) fill_area.x2 = coords->x1 + corner_size; + else if(dsc->border_side == LV_BORDER_SIDE_RIGHT) fill_area.x1 = coords->x2 - corner_size; for(h = draw_area.y1; h <= draw_area.y2; h++) { if((dsc->border_side == LV_BORDER_SIDE_BOTTOM && fill_area.y1 < coords->y2 - corner_size - 1) || @@ -513,7 +516,7 @@ static void draw_border(const lv_area_t * coords, const lv_area_t * clip, lv_dra memset(mask_buf, LV_OPA_COVER, draw_area_w); mask_res = lv_draw_mask_apply(mask_buf, vdb->area.x1 + draw_area.x1, vdb->area.y1 + h, draw_area_w); - lv_blend_fill( clip, &fill_area, color, mask_buf, mask_res, opa, blend_mode); + lv_blend_fill(clip, &fill_area, color, mask_buf, mask_res, opa, blend_mode); fill_area.y1++; fill_area.y2++; @@ -546,7 +549,7 @@ static void draw_shadow(const lv_area_t * coords, const lv_area_t * clip, lv_dra if(dsc->shadow_opa <= LV_OPA_MIN) return; if(dsc->shadow_width == 1 && dsc->shadow_ofs_x == 0 && - dsc->shadow_ofs_y == 0 && dsc->shadow_spread <= 0) { + dsc->shadow_ofs_y == 0 && dsc->shadow_spread <= 0) { return; } @@ -659,7 +662,7 @@ static void draw_shadow(const lv_area_t * coords, const lv_area_t * clip, lv_dra if(mask_res == LV_DRAW_MASK_RES_FULL_COVER) mask_res = LV_DRAW_MASK_RES_CHANGED; lv_blend_fill(clip, &a, - dsc->shadow_color, mask_buf + first_px, mask_res, opa, dsc->shadow_blend_mode); + dsc->shadow_color, mask_buf + first_px, mask_res, opa, dsc->shadow_blend_mode); a.y1++; a.y2++; sh_buf_tmp += corner_size; @@ -677,7 +680,7 @@ static void draw_shadow(const lv_area_t * coords, const lv_area_t * clip, lv_dra if(mask_res == LV_DRAW_MASK_RES_FULL_COVER) mask_res = LV_DRAW_MASK_RES_CHANGED; lv_blend_fill(clip, &a, - dsc->shadow_color, mask_buf + first_px, mask_res, opa, dsc->shadow_blend_mode); + dsc->shadow_color, mask_buf + first_px, mask_res, opa, dsc->shadow_blend_mode); a.y1--; a.y2--; sh_buf_tmp += corner_size; @@ -704,7 +707,7 @@ static void draw_shadow(const lv_area_t * coords, const lv_area_t * clip, lv_dra lv_opa_t opa_tmp = sh_buf_tmp[x - a.x1 + first_px]; if(opa_tmp != LV_OPA_COVER || opa != LV_OPA_COVER) opa_tmp = (opa * opa_tmp) >> 8; lv_blend_fill(clip, &va, - dsc->shadow_color, NULL, LV_DRAW_MASK_RES_FULL_COVER, opa_tmp, dsc->shadow_blend_mode); + dsc->shadow_color, NULL, LV_DRAW_MASK_RES_FULL_COVER, opa_tmp, dsc->shadow_blend_mode); } va.x1++; va.x2++; @@ -718,7 +721,7 @@ static void draw_shadow(const lv_area_t * coords, const lv_area_t * clip, lv_dra if(mask_res == LV_DRAW_MASK_RES_FULL_COVER) mask_res = LV_DRAW_MASK_RES_CHANGED; lv_blend_fill(clip, &a, - dsc->shadow_color, mask_buf+first_px, mask_res, opa, dsc->shadow_blend_mode); + dsc->shadow_color, mask_buf + first_px, mask_res, opa, dsc->shadow_blend_mode); a.y1++; a.y2++; } @@ -741,8 +744,8 @@ static void draw_shadow(const lv_area_t * coords, const lv_area_t * clip, lv_dra a.y1 = sh_area.y1; a.y2 = a.y1; - if(a.x2 > sh_area.x1 + lv_area_get_width(&sh_area)/2 - 1) { - a.x2 = sh_area.x1 + lv_area_get_width(&sh_area)/2 -1 ; + if(a.x2 > sh_area.x1 + lv_area_get_width(&sh_area) / 2 - 1) { + a.x2 = sh_area.x1 + lv_area_get_width(&sh_area) / 2 - 1 ; } first_px = 0; @@ -758,7 +761,7 @@ static void draw_shadow(const lv_area_t * coords, const lv_area_t * clip, lv_dra if(mask_res == LV_DRAW_MASK_RES_FULL_COVER) mask_res = LV_DRAW_MASK_RES_CHANGED; lv_blend_fill(clip, &a, - dsc->shadow_color, mask_buf + first_px, mask_res, opa, dsc->shadow_blend_mode); + dsc->shadow_color, mask_buf + first_px, mask_res, opa, dsc->shadow_blend_mode); a.y1++; a.y2++; sh_buf_tmp += corner_size; @@ -776,14 +779,14 @@ static void draw_shadow(const lv_area_t * coords, const lv_area_t * clip, lv_dra if(mask_res == LV_DRAW_MASK_RES_FULL_COVER) mask_res = LV_DRAW_MASK_RES_CHANGED; lv_blend_fill(clip, &a, - dsc->shadow_color, mask_buf + first_px, mask_res, opa, dsc->shadow_blend_mode); + dsc->shadow_color, mask_buf + first_px, mask_res, opa, dsc->shadow_blend_mode); a.y1--; a.y2--; sh_buf_tmp += corner_size; } /*Fill the left side*/ - a.y1 = sh_area.y1+corner_size; + a.y1 = sh_area.y1 + corner_size; a.y2 = a.y1; sh_buf_tmp = sh_buf + corner_size * (corner_size - 1); @@ -801,7 +804,7 @@ static void draw_shadow(const lv_area_t * coords, const lv_area_t * clip, lv_dra lv_opa_t opa_tmp = sh_buf_tmp[x - a.x1 + first_px]; if(opa_tmp != LV_OPA_COVER || opa != LV_OPA_COVER) opa_tmp = (opa * opa_tmp) >> 8; lv_blend_fill(clip, &va, - dsc->shadow_color, NULL, LV_DRAW_MASK_RES_FULL_COVER, opa_tmp, dsc->shadow_blend_mode); + dsc->shadow_color, NULL, LV_DRAW_MASK_RES_FULL_COVER, opa_tmp, dsc->shadow_blend_mode); va.x1++; va.x2++; } @@ -814,7 +817,7 @@ static void draw_shadow(const lv_area_t * coords, const lv_area_t * clip, lv_dra if(mask_res == LV_DRAW_MASK_RES_FULL_COVER) mask_res = LV_DRAW_MASK_RES_CHANGED; lv_blend_fill(clip, &a, - dsc->shadow_color, mask_buf + first_px, mask_res, opa, dsc->shadow_blend_mode); + dsc->shadow_color, mask_buf + first_px, mask_res, opa, dsc->shadow_blend_mode); a.y1++; a.y2++; } @@ -850,13 +853,14 @@ static void draw_shadow(const lv_area_t * coords, const lv_area_t * clip, lv_dra if(mask_res == LV_DRAW_MASK_RES_FULL_COVER) mask_res = LV_DRAW_MASK_RES_CHANGED; lv_blend_fill(clip, &a, - dsc->shadow_color, mask_buf, mask_res, opa, dsc->shadow_blend_mode); - } else { + dsc->shadow_color, mask_buf, mask_res, opa, dsc->shadow_blend_mode); + } + else { lv_opa_t opa_tmp = sh_buf_tmp[0]; if(opa_tmp != LV_OPA_COVER || opa != LV_OPA_COVER) opa_tmp = (opa * opa_tmp) >> 8; lv_blend_fill(clip, &a, - dsc->shadow_color, NULL, LV_DRAW_MASK_RES_FULL_COVER, opa_tmp, dsc->shadow_blend_mode); + dsc->shadow_color, NULL, LV_DRAW_MASK_RES_FULL_COVER, opa_tmp, dsc->shadow_blend_mode); } a.y1++; @@ -867,7 +871,7 @@ static void draw_shadow(const lv_area_t * coords, const lv_area_t * clip, lv_dra /*Fill the bottom side*/ int32_t y_min = simple_mode ? (corner_size - (sh_area.y2 - coords->y2)) : ver_mid_dist; if(y_min < 0) y_min = 0; - sh_buf_tmp = sh_buf + corner_size * (corner_size - y_min - 1 ) + corner_size - 1; + sh_buf_tmp = sh_buf + corner_size * (corner_size - y_min - 1) + corner_size - 1; a.y1 = sh_area.y2 - corner_size + 1 + y_min; a.y2 = a.y1; @@ -878,12 +882,13 @@ static void draw_shadow(const lv_area_t * coords, const lv_area_t * clip, lv_dra mask_res = lv_draw_mask_apply(mask_buf, a.x1, a.y1, lv_area_get_width(&a)); if(mask_res == LV_DRAW_MASK_RES_FULL_COVER) mask_res = LV_DRAW_MASK_RES_CHANGED; lv_blend_fill(clip, &a, - dsc->shadow_color, mask_buf, mask_res, opa, dsc->shadow_blend_mode); - } else { + dsc->shadow_color, mask_buf, mask_res, opa, dsc->shadow_blend_mode); + } + else { lv_opa_t opa_tmp = sh_buf_tmp[0]; if(opa_tmp != LV_OPA_COVER || opa != LV_OPA_COVER) opa_tmp = (opa * opa_tmp) >> 8; lv_blend_fill(clip, &a, - dsc->shadow_color, NULL, LV_DRAW_MASK_RES_FULL_COVER, opa_tmp, dsc->shadow_blend_mode); + dsc->shadow_color, NULL, LV_DRAW_MASK_RES_FULL_COVER, opa_tmp, dsc->shadow_blend_mode); } a.y1++; @@ -901,7 +906,7 @@ static void draw_shadow(const lv_area_t * coords, const lv_area_t * clip, lv_dra memset(mask_buf, 0xFF, lv_area_get_width(&a)); mask_res = lv_draw_mask_apply(mask_buf, a.x1, a.y1, lv_area_get_width(&a)); lv_blend_fill(clip, &a, - dsc->shadow_color, mask_buf, mask_res, opa, dsc->shadow_blend_mode); + dsc->shadow_color, mask_buf, mask_res, opa, dsc->shadow_blend_mode); a.y1++; a.y2++; @@ -921,7 +926,7 @@ static void shadow_draw_corner_buf(const lv_area_t * coords, uint16_t * sh_buf, lv_area_t sh_area; lv_area_copy(&sh_area, coords); - sh_area.x2 = sw / 2 + r -1 - ((sw & 1) ? 0 : 1); + sh_area.x2 = sw / 2 + r - 1 - ((sw & 1) ? 0 : 1); sh_area.y1 = sw / 2 + 1; sh_area.x1 = sh_area.x2 - lv_area_get_width(coords); @@ -944,11 +949,12 @@ static void shadow_draw_corner_buf(const lv_area_t * coords, uint16_t * sh_buf, lv_draw_mask_res_t mask_res = mask_param.dsc.cb(mask_line, 0, y, size, &mask_param); if(mask_res == LV_DRAW_MASK_RES_FULL_TRANSP) { memset(sh_ups_tmp_buf, 0x00, size * sizeof(sh_ups_tmp_buf[0])); - } else { + } + else { int32_t i; sh_ups_tmp_buf[0] = (mask_line[0] << SHADOW_UPSACALE_SHIFT) / sw; for(i = 1; i < size; i++) { - if(mask_line[i] == mask_line[i-1]) sh_ups_tmp_buf[i] = sh_ups_tmp_buf[i-1]; + if(mask_line[i] == mask_line[i - 1]) sh_ups_tmp_buf[i] = sh_ups_tmp_buf[i - 1]; else sh_ups_tmp_buf[i] = (mask_line[i] << SHADOW_UPSACALE_SHIFT) / sw; } } @@ -981,7 +987,7 @@ static void shadow_draw_corner_buf(const lv_area_t * coords, uint16_t * sh_buf, uint32_t i; sh_buf[0] = (sh_buf[0] << SHADOW_UPSACALE_SHIFT) / sw; for(i = 1; i < (uint32_t) size * size; i++) { - if(sh_buf[i] == sh_buf[i-1]) sh_buf[i] = sh_buf[i-1]; + if(sh_buf[i] == sh_buf[i - 1]) sh_buf[i] = sh_buf[i - 1]; else sh_buf[i] = (sh_buf[i] << SHADOW_UPSACALE_SHIFT) / sw; } @@ -1011,8 +1017,8 @@ static void shadow_blur_corner(lv_coord_t size, lv_coord_t sw, uint16_t * sh_ups uint16_t * sh_ups_tmp_buf = sh_ups_buf; for(y = 0; y < size; y++) { - int32_t v = sh_ups_tmp_buf[size-1] * sw; - for(x = size - 1; x >=0; x--) { + int32_t v = sh_ups_tmp_buf[size - 1] * sw; + for(x = size - 1; x >= 0; x--) { sh_ups_blur_buf[x] = v; /*Forget the right pixel*/ @@ -1034,7 +1040,7 @@ static void shadow_blur_corner(lv_coord_t size, lv_coord_t sw, uint16_t * sh_ups uint32_t i; sh_ups_buf[0] = sh_ups_buf[0] / sw; for(i = 1; i < (uint32_t)size * size; i++) { - if(sh_ups_buf[i] == sh_ups_buf[i-1]) sh_ups_buf[i] = sh_ups_buf[i-1]; + if(sh_ups_buf[i] == sh_ups_buf[i - 1]) sh_ups_buf[i] = sh_ups_buf[i - 1]; else sh_ups_buf[i] = sh_ups_buf[i] / sw; } @@ -1213,7 +1219,7 @@ static void draw_outline(const lv_area_t * coords, const lv_area_t * clip, lv_dr lv_blend_fill(clip, &fill_area2, color, mask_buf, mask_res, opa, blend_mode); /*Draw the bottom horizontal line*/ - if(fill_area2.y2 > area_outer.y2 - dsc->outline_width ) { + if(fill_area2.y2 > area_outer.y2 - dsc->outline_width) { fill_area2.x1 = area_outer.x1 + rout; fill_area2.x2 = area_outer.x2 - rout; @@ -1256,7 +1262,7 @@ static void draw_outline(const lv_area_t * coords, const lv_area_t * clip, lv_dr memset(mask_buf, LV_OPA_COVER, draw_area_w); mask_res = lv_draw_mask_apply(mask_buf, vdb->area.x1 + draw_area.x1, vdb->area.y1 + h, draw_area_w); - lv_blend_fill( clip, &fill_area, color, mask_buf, mask_res, opa, blend_mode); + lv_blend_fill(clip, &fill_area, color, mask_buf, mask_res, opa, blend_mode); fill_area.y1++; fill_area.y2++; @@ -1282,7 +1288,7 @@ static void draw_pattern(const lv_area_t * coords, const lv_area_t * clip, lv_dr if(src_type == LV_IMG_SRC_FILE || src_type == LV_IMG_SRC_VARIABLE) { lv_img_header_t header; lv_res_t res = lv_img_decoder_get_info(dsc->pattern_image, &header); - if(res!= LV_RES_OK) { + if(res != LV_RES_OK) { LV_LOG_WARN("draw_img: can't get image info"); return; } @@ -1294,17 +1300,20 @@ static void draw_pattern(const lv_area_t * coords, const lv_area_t * clip, lv_dr img_dsc.opa = dsc->pattern_opa; img_dsc.recolor_opa = dsc->pattern_recolor_opa; img_dsc.recolor = dsc->pattern_recolor; - } else if(src_type == LV_IMG_SRC_SYMBOL) { + } + else if(src_type == LV_IMG_SRC_SYMBOL) { lv_draw_label_dsc_init(&label_dsc); label_dsc.color = dsc->pattern_recolor; label_dsc.font = dsc->pattern_font; label_dsc.opa = dsc->pattern_opa; lv_point_t s; - lv_txt_get_size(&s, dsc->pattern_image, label_dsc.font, label_dsc.letter_space, label_dsc.line_space, LV_COORD_MAX, LV_TXT_FLAG_NONE); + lv_txt_get_size(&s, dsc->pattern_image, label_dsc.font, label_dsc.letter_space, label_dsc.line_space, LV_COORD_MAX, + LV_TXT_FLAG_NONE); img_w = s.x; img_h = s.y; - } else { + } + else { /*Trigger the error handler of image drawer*/ LV_LOG_WARN("lv_img_design: image source type is unknown"); lv_draw_img(coords, clip, NULL, NULL); @@ -1333,7 +1342,8 @@ static void draw_pattern(const lv_area_t * coords, const lv_area_t * clip, lv_dr } } lv_draw_mask_remove_id(radius_mask_id); - } else { + } + else { int32_t obj_w = lv_area_get_width(coords); int32_t obj_h = lv_area_get_height(coords); coords_tmp.x1 = coords->x1 + (obj_w - img_w) / 2; @@ -1371,7 +1381,8 @@ static void draw_value(const lv_area_t * coords, const lv_area_t * clip, lv_draw if(dsc->value_opa <= LV_OPA_MIN) return; lv_point_t s; - lv_txt_get_size(&s, dsc->value_str, dsc->value_font, dsc->value_letter_space, dsc->value_line_space, LV_COORD_MAX, LV_TXT_FLAG_NONE); + lv_txt_get_size(&s, dsc->value_str, dsc->value_font, dsc->value_letter_space, dsc->value_line_space, LV_COORD_MAX, + LV_TXT_FLAG_NONE); lv_area_t value_area; value_area.x1 = 0; diff --git a/src/lv_draw/lv_draw_rect.h b/src/lv_draw/lv_draw_rect.h index e1510c537..f779ae4ed 100644 --- a/src/lv_draw/lv_draw_rect.h +++ b/src/lv_draw/lv_draw_rect.h @@ -64,7 +64,7 @@ typedef struct { lv_color_t pattern_recolor; lv_opa_t pattern_opa; lv_opa_t pattern_recolor_opa; - uint8_t pattern_repeat :1; + uint8_t pattern_repeat : 1; lv_blend_mode_t pattern_blend_mode; /*Value*/ @@ -78,7 +78,7 @@ typedef struct { lv_style_int_t value_line_space; lv_align_t value_align; lv_blend_mode_t value_blend_mode; -}lv_draw_rect_dsc_t; +} lv_draw_rect_dsc_t; /********************** * GLOBAL PROTOTYPES diff --git a/src/lv_draw/lv_draw_triangle.c b/src/lv_draw/lv_draw_triangle.c index 658b0b13a..b3f43106d 100644 --- a/src/lv_draw/lv_draw_triangle.c +++ b/src/lv_draw/lv_draw_triangle.c @@ -52,7 +52,8 @@ void lv_draw_triangle(const lv_point_t * points, const lv_area_t * clip_area, lv * @param clip_area polygon will be drawn only in this area * @param draw_dsc pointer to an initialized `lv_draw_rect_dsc_t` variable */ -void lv_draw_polygon(const lv_point_t * points, uint16_t point_cnt, const lv_area_t * clip_area, lv_draw_rect_dsc_t * draw_dsc) +void lv_draw_polygon(const lv_point_t * points, uint16_t point_cnt, const lv_area_t * clip_area, + lv_draw_rect_dsc_t * draw_dsc) { if(point_cnt < 3) return; if(points == NULL) return; @@ -111,7 +112,8 @@ void lv_draw_polygon(const lv_point_t * points, uint16_t point_cnt, const lv_are i_next_right = i_prev_right + 1; if(i_next_right > point_cnt - 1) i_next_right = 0; - } else { + } + else { i_next_left = i_prev_left + 1; if(i_next_left > point_cnt - 1) i_next_left = 0; @@ -121,10 +123,10 @@ void lv_draw_polygon(const lv_point_t * points, uint16_t point_cnt, const lv_are if(points[i_next_left].y >= points[i_prev_left].y) { if(points[i_next_left].y != points[i_prev_left].y && - points[i_next_left].x != points[i_prev_left].x) { + points[i_next_left].x != points[i_prev_left].x) { lv_draw_mask_line_points_init(mp_next, points[i_prev_left].x, points[i_prev_left].y, - points[i_next_left].x, points[i_next_left].y, - LV_DRAW_MASK_LINE_SIDE_RIGHT); + points[i_next_left].x, points[i_next_left].y, + LV_DRAW_MASK_LINE_SIDE_RIGHT); lv_draw_mask_add(mp_next, mp); mp_next++; } @@ -139,8 +141,8 @@ void lv_draw_polygon(const lv_point_t * points, uint16_t point_cnt, const lv_are points[i_next_right].x != points[i_prev_right].x) { lv_draw_mask_line_points_init(mp_next, points[i_prev_right].x, points[i_prev_right].y, - points[i_next_right].x, points[i_next_right].y, - LV_DRAW_MASK_LINE_SIDE_LEFT); + points[i_next_right].x, points[i_next_right].y, + LV_DRAW_MASK_LINE_SIDE_LEFT); lv_draw_mask_add(mp_next, mp); mp_next++; } @@ -148,7 +150,7 @@ void lv_draw_polygon(const lv_point_t * points, uint16_t point_cnt, const lv_are i_prev_right = i_next_right; } - }while( mask_cnt < point_cnt); + } while(mask_cnt < point_cnt); lv_draw_rect(&poly_coords, clip_area, draw_dsc); diff --git a/src/lv_draw/lv_draw_triangle.h b/src/lv_draw/lv_draw_triangle.h index 888eeed90..4bf7c6e32 100644 --- a/src/lv_draw/lv_draw_triangle.h +++ b/src/lv_draw/lv_draw_triangle.h @@ -42,7 +42,8 @@ void lv_draw_triangle(const lv_point_t * points, const lv_area_t * clip, lv_draw * @param clip_area polygon will be drawn only in this area * @param draw_dsc pointer to an initialized `lv_draw_rect_dsc_t` variable */ -void lv_draw_polygon(const lv_point_t * points, uint16_t point_cnt, const lv_area_t * mask, lv_draw_rect_dsc_t * draw_dsc); +void lv_draw_polygon(const lv_point_t * points, uint16_t point_cnt, const lv_area_t * mask, + lv_draw_rect_dsc_t * draw_dsc); /********************** * MACROS diff --git a/src/lv_draw/lv_img_buf.c b/src/lv_draw/lv_img_buf.c index d740e5e3b..6174c159a 100644 --- a/src/lv_draw/lv_img_buf.c +++ b/src/lv_draw/lv_img_buf.c @@ -56,14 +56,15 @@ lv_color_t lv_img_buf_get_px_color(lv_img_dsc_t * dsc, lv_coord_t x, lv_coord_t uint8_t * buf_u8 = (uint8_t *)dsc->data; if(dsc->header.cf == LV_IMG_CF_TRUE_COLOR || dsc->header.cf == LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED || - dsc->header.cf == LV_IMG_CF_TRUE_COLOR_ALPHA) { + dsc->header.cf == LV_IMG_CF_TRUE_COLOR_ALPHA) { uint8_t px_size = lv_img_cf_get_px_size(dsc->header.cf) >> 3; uint32_t px = dsc->header.w * y * px_size + x * px_size; memcpy(&p_color, &buf_u8[px], sizeof(lv_color_t)); #if LV_COLOR_SIZE == 32 p_color.ch.alpha = 0xFF; /*Only the color should be get so use a deafult alpha value*/ #endif - } else if(dsc->header.cf == LV_IMG_CF_INDEXED_1BIT) { + } + else if(dsc->header.cf == LV_IMG_CF_INDEXED_1BIT) { buf_u8 += 4 * 2; uint8_t bit = x & 0x7; x = x >> 3; @@ -73,7 +74,8 @@ lv_color_t lv_img_buf_get_px_color(lv_img_dsc_t * dsc, lv_coord_t x, lv_coord_t * so the possible real width are 8, 16, 24 ...*/ uint32_t px = ((dsc->header.w + 7) >> 3) * y + x; p_color.full = (buf_u8[px] & (1 << (7 - bit))) >> (7 - bit); - } else if(dsc->header.cf == LV_IMG_CF_INDEXED_2BIT) { + } + else if(dsc->header.cf == LV_IMG_CF_INDEXED_2BIT) { buf_u8 += 4 * 4; uint8_t bit = (x & 0x3) * 2; x = x >> 2; @@ -83,7 +85,8 @@ lv_color_t lv_img_buf_get_px_color(lv_img_dsc_t * dsc, lv_coord_t x, lv_coord_t * so the possible real width are 4, 8, 12 ...*/ uint32_t px = ((dsc->header.w + 3) >> 2) * y + x; p_color.full = (buf_u8[px] & (3 << (6 - bit))) >> (6 - bit); - } else if(dsc->header.cf == LV_IMG_CF_INDEXED_4BIT) { + } + else if(dsc->header.cf == LV_IMG_CF_INDEXED_4BIT) { buf_u8 += 4 * 16; uint8_t bit = (x & 0x1) * 4; x = x >> 1; @@ -93,11 +96,13 @@ lv_color_t lv_img_buf_get_px_color(lv_img_dsc_t * dsc, lv_coord_t x, lv_coord_t * so the possible real width are 2, 4, 6 ...*/ uint32_t px = ((dsc->header.w + 1) >> 1) * y + x; p_color.full = (buf_u8[px] & (0xF << (4 - bit))) >> (4 - bit); - } else if(dsc->header.cf == LV_IMG_CF_INDEXED_8BIT) { + } + else if(dsc->header.cf == LV_IMG_CF_INDEXED_8BIT) { buf_u8 += 4 * 256; uint32_t px = dsc->header.w * y + x; p_color.full = buf_u8[px]; - } else if(dsc->header.cf == LV_IMG_CF_ALPHA_1BIT || dsc->header.cf == LV_IMG_CF_ALPHA_2BIT || + } + else if(dsc->header.cf == LV_IMG_CF_ALPHA_1BIT || dsc->header.cf == LV_IMG_CF_ALPHA_2BIT || dsc->header.cf == LV_IMG_CF_ALPHA_4BIT || dsc->header.cf == LV_IMG_CF_ALPHA_8BIT) { p_color = color; } @@ -119,7 +124,8 @@ lv_opa_t lv_img_buf_get_px_alpha(lv_img_dsc_t * dsc, lv_coord_t x, lv_coord_t y) if(dsc->header.cf == LV_IMG_CF_TRUE_COLOR_ALPHA) { uint32_t px = dsc->header.w * y * LV_IMG_PX_SIZE_ALPHA_BYTE + x * LV_IMG_PX_SIZE_ALPHA_BYTE; return buf_u8[px + LV_IMG_PX_SIZE_ALPHA_BYTE - 1]; - } else if(dsc->header.cf == LV_IMG_CF_ALPHA_1BIT) { + } + else if(dsc->header.cf == LV_IMG_CF_ALPHA_1BIT) { uint8_t bit = x & 0x7; x = x >> 3; @@ -129,7 +135,8 @@ lv_opa_t lv_img_buf_get_px_alpha(lv_img_dsc_t * dsc, lv_coord_t x, lv_coord_t y) uint32_t px = ((dsc->header.w + 7) >> 3) * y + x; uint8_t px_opa = (buf_u8[px] & (1 << (7 - bit))) >> (7 - bit); return px_opa ? LV_OPA_TRANSP : LV_OPA_COVER; - } else if(dsc->header.cf == LV_IMG_CF_ALPHA_2BIT) { + } + else if(dsc->header.cf == LV_IMG_CF_ALPHA_2BIT) { const uint8_t opa_table[4] = {0, 85, 170, 255}; /*Opacity mapping with bpp = 2*/ uint8_t bit = (x & 0x3) * 2; @@ -141,9 +148,11 @@ lv_opa_t lv_img_buf_get_px_alpha(lv_img_dsc_t * dsc, lv_coord_t x, lv_coord_t y) uint32_t px = ((dsc->header.w + 3) >> 2) * y + x; uint8_t px_opa = (buf_u8[px] & (3 << (6 - bit))) >> (6 - bit); return opa_table[px_opa]; - } else if(dsc->header.cf == LV_IMG_CF_ALPHA_4BIT) { + } + else if(dsc->header.cf == LV_IMG_CF_ALPHA_4BIT) { const uint8_t opa_table[16] = {0, 17, 34, 51, /*Opacity mapping with bpp = 4*/ - 68, 85, 102, 119, 136, 153, 170, 187, 204, 221, 238, 255}; + 68, 85, 102, 119, 136, 153, 170, 187, 204, 221, 238, 255 + }; uint8_t bit = (x & 0x1) * 4; x = x >> 1; @@ -154,7 +163,8 @@ lv_opa_t lv_img_buf_get_px_alpha(lv_img_dsc_t * dsc, lv_coord_t x, lv_coord_t y) uint32_t px = ((dsc->header.w + 1) >> 1) * y + x; uint8_t px_opa = (buf_u8[px] & (0xF << (4 - bit))) >> (4 - bit); return opa_table[px_opa]; - } else if(dsc->header.cf == LV_IMG_CF_ALPHA_8BIT) { + } + else if(dsc->header.cf == LV_IMG_CF_ALPHA_8BIT) { uint32_t px = dsc->header.w * y + x; return buf_u8[px]; } @@ -178,7 +188,8 @@ void lv_img_buf_set_px_alpha(lv_img_dsc_t * dsc, lv_coord_t x, lv_coord_t y, lv_ uint8_t px_size = lv_img_cf_get_px_size(dsc->header.cf) >> 3; uint32_t px = dsc->header.w * y * px_size + x * px_size; buf_u8[px + px_size - 1] = opa; - } else if(dsc->header.cf == LV_IMG_CF_ALPHA_1BIT) { + } + else if(dsc->header.cf == LV_IMG_CF_ALPHA_1BIT) { opa = opa >> 7; /*opa -> [0,1]*/ uint8_t bit = x & 0x7; x = x >> 3; @@ -189,7 +200,8 @@ void lv_img_buf_set_px_alpha(lv_img_dsc_t * dsc, lv_coord_t x, lv_coord_t y, lv_ uint32_t px = ((dsc->header.w + 7) >> 3) * y + x; buf_u8[px] = buf_u8[px] & ~(1 << (7 - bit)); buf_u8[px] = buf_u8[px] | ((opa & 0x1) << (7 - bit)); - } else if(dsc->header.cf == LV_IMG_CF_ALPHA_2BIT) { + } + else if(dsc->header.cf == LV_IMG_CF_ALPHA_2BIT) { opa = opa >> 6; /*opa -> [0,3]*/ uint8_t bit = (x & 0x3) * 2; x = x >> 2; @@ -200,7 +212,8 @@ void lv_img_buf_set_px_alpha(lv_img_dsc_t * dsc, lv_coord_t x, lv_coord_t y, lv_ uint32_t px = ((dsc->header.w + 3) >> 2) * y + x; buf_u8[px] = buf_u8[px] & ~(3 << (6 - bit)); buf_u8[px] = buf_u8[px] | ((opa & 0x3) << (6 - bit)); - } else if(dsc->header.cf == LV_IMG_CF_ALPHA_4BIT) { + } + else if(dsc->header.cf == LV_IMG_CF_ALPHA_4BIT) { opa = opa >> 4; /*opa -> [0,15]*/ uint8_t bit = (x & 0x1) * 4; x = x >> 1; @@ -211,7 +224,8 @@ void lv_img_buf_set_px_alpha(lv_img_dsc_t * dsc, lv_coord_t x, lv_coord_t y, lv_ uint32_t px = ((dsc->header.w + 1) >> 1) * y + x; buf_u8[px] = buf_u8[px] & ~(0xF << (4 - bit)); buf_u8[px] = buf_u8[px] | ((opa & 0xF) << (4 - bit)); - } else if(dsc->header.cf == LV_IMG_CF_ALPHA_8BIT) { + } + else if(dsc->header.cf == LV_IMG_CF_ALPHA_8BIT) { uint32_t px = dsc->header.w * y + x; buf_u8[px] = opa; } @@ -233,11 +247,13 @@ void lv_img_buf_set_px_color(lv_img_dsc_t * dsc, lv_coord_t x, lv_coord_t y, lv_ uint8_t px_size = lv_img_cf_get_px_size(dsc->header.cf) >> 3; uint32_t px = dsc->header.w * y * px_size + x * px_size; memcpy(&buf_u8[px], &c, px_size); - } else if(dsc->header.cf == LV_IMG_CF_TRUE_COLOR_ALPHA) { + } + else if(dsc->header.cf == LV_IMG_CF_TRUE_COLOR_ALPHA) { uint8_t px_size = lv_img_cf_get_px_size(dsc->header.cf) >> 3; uint32_t px = dsc->header.w * y * px_size + x * px_size; memcpy(&buf_u8[px], &c, px_size - 1); /*-1 to not overwrite the alpha value*/ - } else if(dsc->header.cf == LV_IMG_CF_INDEXED_1BIT) { + } + else if(dsc->header.cf == LV_IMG_CF_INDEXED_1BIT) { buf_u8 += sizeof(lv_color32_t) * 2; /*Skip the palette*/ uint8_t bit = x & 0x7; @@ -249,7 +265,8 @@ void lv_img_buf_set_px_color(lv_img_dsc_t * dsc, lv_coord_t x, lv_coord_t y, lv_ uint32_t px = ((dsc->header.w + 7) >> 3) * y + x; buf_u8[px] = buf_u8[px] & ~(1 << (7 - bit)); buf_u8[px] = buf_u8[px] | ((c.full & 0x1) << (7 - bit)); - } else if(dsc->header.cf == LV_IMG_CF_INDEXED_2BIT) { + } + else if(dsc->header.cf == LV_IMG_CF_INDEXED_2BIT) { buf_u8 += sizeof(lv_color32_t) * 4; /*Skip the palette*/ uint8_t bit = (x & 0x3) * 2; x = x >> 2; @@ -261,7 +278,8 @@ void lv_img_buf_set_px_color(lv_img_dsc_t * dsc, lv_coord_t x, lv_coord_t y, lv_ buf_u8[px] = buf_u8[px] & ~(3 << (6 - bit)); buf_u8[px] = buf_u8[px] | ((c.full & 0x3) << (6 - bit)); - } else if(dsc->header.cf == LV_IMG_CF_INDEXED_4BIT) { + } + else if(dsc->header.cf == LV_IMG_CF_INDEXED_4BIT) { buf_u8 += sizeof(lv_color32_t) * 16; /*Skip the palette*/ uint8_t bit = (x & 0x1) * 4; x = x >> 1; @@ -272,7 +290,8 @@ void lv_img_buf_set_px_color(lv_img_dsc_t * dsc, lv_coord_t x, lv_coord_t y, lv_ uint32_t px = ((dsc->header.w + 1) >> 1) * y + x; buf_u8[px] = buf_u8[px] & ~(0xF << (4 - bit)); buf_u8[px] = buf_u8[px] | ((c.full & 0xF) << (4 - bit)); - } else if(dsc->header.cf == LV_IMG_CF_INDEXED_8BIT) { + } + else if(dsc->header.cf == LV_IMG_CF_INDEXED_8BIT) { buf_u8 += sizeof(lv_color32_t) * 256; /*Skip the palette*/ uint32_t px = dsc->header.w * y + x; buf_u8[px] = c.full; @@ -292,7 +311,7 @@ void lv_img_buf_set_px_color(lv_img_dsc_t * dsc, lv_coord_t x, lv_coord_t y, lv_ void lv_img_buf_set_palette(lv_img_dsc_t * dsc, uint8_t id, lv_color_t c) { if((dsc->header.cf == LV_IMG_CF_ALPHA_1BIT && id > 1) || (dsc->header.cf == LV_IMG_CF_ALPHA_2BIT && id > 3) || - (dsc->header.cf == LV_IMG_CF_ALPHA_4BIT && id > 15) || (dsc->header.cf == LV_IMG_CF_ALPHA_8BIT)) { + (dsc->header.cf == LV_IMG_CF_ALPHA_4BIT && id > 15) || (dsc->header.cf == LV_IMG_CF_ALPHA_8BIT)) { LV_LOG_WARN("lv_img_buf_set_px_alpha: invalid 'id'"); return; } @@ -310,10 +329,10 @@ void lv_img_buf_set_palette(lv_img_dsc_t * dsc, uint8_t id, lv_color_t c) * @param cf a color format (`LV_IMG_CF_...`) * @return an allocated image, or NULL on failure */ -lv_img_dsc_t *lv_img_buf_alloc(lv_coord_t w, lv_coord_t h, lv_img_cf_t cf) +lv_img_dsc_t * lv_img_buf_alloc(lv_coord_t w, lv_coord_t h, lv_img_cf_t cf) { /* Allocate image descriptor */ - lv_img_dsc_t *dsc = lv_mem_alloc(sizeof(lv_img_dsc_t)); + lv_img_dsc_t * dsc = lv_mem_alloc(sizeof(lv_img_dsc_t)); if(dsc == NULL) return NULL; @@ -346,7 +365,7 @@ lv_img_dsc_t *lv_img_buf_alloc(lv_coord_t w, lv_coord_t h, lv_img_cf_t cf) * Free an allocated image buffer * @param dsc image buffer to free */ -void lv_img_buf_free(lv_img_dsc_t *dsc) +void lv_img_buf_free(lv_img_dsc_t * dsc) { if(dsc != NULL) { if(dsc->data != NULL) @@ -366,18 +385,30 @@ void lv_img_buf_free(lv_img_dsc_t *dsc) uint32_t lv_img_buf_get_img_size(lv_coord_t w, lv_coord_t h, lv_img_cf_t cf) { switch(cf) { - case LV_IMG_CF_TRUE_COLOR: return LV_IMG_BUF_SIZE_TRUE_COLOR(w, h); - case LV_IMG_CF_TRUE_COLOR_ALPHA: return LV_IMG_BUF_SIZE_TRUE_COLOR_ALPHA(w, h); - case LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED: return LV_IMG_BUF_SIZE_TRUE_COLOR_CHROMA_KEYED(w, h); - case LV_IMG_CF_ALPHA_1BIT: return LV_IMG_BUF_SIZE_ALPHA_1BIT(w, h); - case LV_IMG_CF_ALPHA_2BIT: return LV_IMG_BUF_SIZE_ALPHA_2BIT(w, h); - case LV_IMG_CF_ALPHA_4BIT: return LV_IMG_BUF_SIZE_ALPHA_4BIT(w, h); - case LV_IMG_CF_ALPHA_8BIT: return LV_IMG_BUF_SIZE_ALPHA_8BIT(w, h); - case LV_IMG_CF_INDEXED_1BIT: return LV_IMG_BUF_SIZE_INDEXED_1BIT(w, h); - case LV_IMG_CF_INDEXED_2BIT: return LV_IMG_BUF_SIZE_INDEXED_2BIT(w, h); - case LV_IMG_CF_INDEXED_4BIT: return LV_IMG_BUF_SIZE_INDEXED_4BIT(w, h); - case LV_IMG_CF_INDEXED_8BIT: return LV_IMG_BUF_SIZE_INDEXED_8BIT(w, h); - default: return 0; + case LV_IMG_CF_TRUE_COLOR: + return LV_IMG_BUF_SIZE_TRUE_COLOR(w, h); + case LV_IMG_CF_TRUE_COLOR_ALPHA: + return LV_IMG_BUF_SIZE_TRUE_COLOR_ALPHA(w, h); + case LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED: + return LV_IMG_BUF_SIZE_TRUE_COLOR_CHROMA_KEYED(w, h); + case LV_IMG_CF_ALPHA_1BIT: + return LV_IMG_BUF_SIZE_ALPHA_1BIT(w, h); + case LV_IMG_CF_ALPHA_2BIT: + return LV_IMG_BUF_SIZE_ALPHA_2BIT(w, h); + case LV_IMG_CF_ALPHA_4BIT: + return LV_IMG_BUF_SIZE_ALPHA_4BIT(w, h); + case LV_IMG_CF_ALPHA_8BIT: + return LV_IMG_BUF_SIZE_ALPHA_8BIT(w, h); + case LV_IMG_CF_INDEXED_1BIT: + return LV_IMG_BUF_SIZE_INDEXED_1BIT(w, h); + case LV_IMG_CF_INDEXED_2BIT: + return LV_IMG_BUF_SIZE_INDEXED_2BIT(w, h); + case LV_IMG_CF_INDEXED_4BIT: + return LV_IMG_BUF_SIZE_INDEXED_4BIT(w, h); + case LV_IMG_CF_INDEXED_8BIT: + return LV_IMG_BUF_SIZE_INDEXED_8BIT(w, h); + default: + return 0; } } @@ -405,7 +436,8 @@ void lv_img_buf_transform_init(lv_img_transform_dsc_t * dsc) dsc->tmp.chroma_keyed = lv_img_cf_is_chroma_keyed(dsc->cfg.cf) ? 1 : 0; dsc->tmp.has_alpha = lv_img_cf_has_alpha(dsc->cfg.cf) ? 1 : 0; - if(dsc->cfg.cf == LV_IMG_CF_TRUE_COLOR || dsc->cfg.cf == LV_IMG_CF_TRUE_COLOR_ALPHA || dsc->cfg.cf == LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED) { + if(dsc->cfg.cf == LV_IMG_CF_TRUE_COLOR || dsc->cfg.cf == LV_IMG_CF_TRUE_COLOR_ALPHA || + dsc->cfg.cf == LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED) { dsc->tmp.native_color = 1; } @@ -443,7 +475,8 @@ bool lv_img_buf_transform(lv_img_transform_dsc_t * dsc, lv_coord_t x, lv_coord_t /*Get the source pixel from the upscaled image*/ xs = ((dsc->tmp.cosma * xt - dsc->tmp.sinma * yt) >> (LV_TRIGO_SHIFT - 8)) + dsc->tmp.pivot_x_256; ys = ((dsc->tmp.sinma * xt + dsc->tmp.cosma * yt) >> (LV_TRIGO_SHIFT - 8)) + dsc->tmp.pivot_y_256; - } else { + } + else { xt *= dsc->tmp.zoom_inv; yt *= dsc->tmp.zoom_inv; xs = ((dsc->tmp.cosma * xt - dsc->tmp.sinma * yt) >> (LV_TRIGO_SHIFT)) + dsc->tmp.pivot_x_256; @@ -472,13 +505,15 @@ bool lv_img_buf_transform(lv_img_transform_dsc_t * dsc, lv_coord_t x, lv_coord_t pxi = dsc->cfg.src_w * ys_int * px_size + xs_int * px_size; memcpy(&dsc->res.color, &src_u8[pxi], px_size); - } else { + } + else { px_size = LV_IMG_PX_SIZE_ALPHA_BYTE; pxi = dsc->cfg.src_w * ys_int * px_size + xs_int * px_size; memcpy(&dsc->res.color, &src_u8[pxi], px_size - 1); dsc->res.opa = src_u8[pxi + px_size - 1]; } - } else { + } + else { pxi = 0; /*unused*/ px_size = 0; /*unused*/ dsc->res.color = lv_img_buf_get_px_color(&dsc->tmp.img_dsc, xs_int, ys_int, dsc->cfg.color); @@ -516,7 +551,8 @@ bool lv_img_buf_transform(lv_img_transform_dsc_t * dsc, lv_coord_t x, lv_coord_t * @param zoom zoom, (256 no zoom) * @param pivot x,y pivot coordinates of rotation */ -void lv_img_buf_get_transformed_area(lv_area_t * res, lv_coord_t w, lv_coord_t h, int16_t angle, uint16_t zoom, lv_point_t * pivot) +void lv_img_buf_get_transformed_area(lv_area_t * res, lv_coord_t w, lv_coord_t h, int16_t angle, uint16_t zoom, + lv_point_t * pivot) { int32_t angle_low = angle / 10; @@ -543,8 +579,8 @@ void lv_img_buf_get_transformed_area(lv_area_t * res, lv_coord_t w, lv_coord_t h lv_area_t a; a.x1 = ((-pivot->x) * zoom) >> 8; a.y1 = ((-pivot->y) * zoom) >> 8; - a.x2 = ((w -pivot->x) * zoom) >> 8; - a.y2 = ((h -pivot->y) * zoom) >> 8; + a.x2 = ((w - pivot->x) * zoom) >> 8; + a.y2 = ((h - pivot->y) * zoom) >> 8; xt = a.x1; yt = a.y1; @@ -587,14 +623,16 @@ static inline bool transform_anti_alias(lv_img_transform_dsc_t * dsc) lv_opa_t xr; /*x mix ratio*/ if(xs_fract < 0x70) { - xn = - 1; - if(dsc->tmp.xs_int + xn < 0) xn = 0; - xr = xs_fract + 0x80; - } else if(xs_fract > 0x90) { + xn = - 1; + if(dsc->tmp.xs_int + xn < 0) xn = 0; + xr = xs_fract + 0x80; + } + else if(xs_fract > 0x90) { xn = 1; if(dsc->tmp.xs_int + xn >= dsc->cfg.src_w) xn = 0; xr = (0xFF - xs_fract) + 0x80; - } else { + } + else { xn = 0; xr = 0xFF; } @@ -603,16 +641,18 @@ static inline bool transform_anti_alias(lv_img_transform_dsc_t * dsc) lv_opa_t yr; /*x mix ratio*/ if(ys_fract < 0x70) { - yn = - 1; - if(dsc->tmp.ys_int + yn < 0) yn = 0; + yn = - 1; + if(dsc->tmp.ys_int + yn < 0) yn = 0; - yr = ys_fract + 0x80; - } else if(ys_fract > 0x90) { + yr = ys_fract + 0x80; + } + else if(ys_fract > 0x90) { yn = 1; if(dsc->tmp.ys_int + yn >= dsc->cfg.src_h) yn = 0; yr = (0xFF - ys_fract) + 0x80; - } else { + } + else { yn = 0; yr = 0xFF; } @@ -630,13 +670,15 @@ static inline bool transform_anti_alias(lv_img_transform_dsc_t * dsc) if(dsc->tmp.native_color) { memcpy(&c01, &src_u8[dsc->tmp.pxi + dsc->tmp.px_size * xn], sizeof(lv_color_t)); memcpy(&c10, &src_u8[dsc->tmp.pxi + dsc->cfg.src_w * dsc->tmp.px_size * yn], sizeof(lv_color_t)); - memcpy(&c11, &src_u8[dsc->tmp.pxi + dsc->cfg.src_w * dsc->tmp.px_size * yn + dsc->tmp.px_size * xn], sizeof(lv_color_t)); + memcpy(&c11, &src_u8[dsc->tmp.pxi + dsc->cfg.src_w * dsc->tmp.px_size * yn + dsc->tmp.px_size * xn], + 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]; a11 = src_u8[dsc->tmp.pxi + dsc->cfg.src_w * dsc->tmp.px_size * yn + dsc->tmp.px_size * xn + dsc->tmp.px_size - 1]; } - } else { + } + else { c01 = lv_img_buf_get_px_color(&dsc->tmp.img_dsc, dsc->tmp.xs_int + xn, dsc->tmp.ys_int, dsc->cfg.color); c10 = lv_img_buf_get_px_color(&dsc->tmp.img_dsc, dsc->tmp.xs_int, dsc->tmp.ys_int + yn, dsc->cfg.color); c11 = lv_img_buf_get_px_color(&dsc->tmp.img_dsc, dsc->tmp.xs_int + xn, dsc->tmp.ys_int + yn, dsc->cfg.color); @@ -662,7 +704,8 @@ static inline bool transform_anti_alias(lv_img_transform_dsc_t * dsc) if(a10 <= LV_OPA_MIN) xr0 = LV_OPA_COVER; if(a01 <= LV_OPA_MIN) xr1 = LV_OPA_TRANSP; if(a11 <= LV_OPA_MIN) xr1 = LV_OPA_COVER; - } else { + } + else { xr0 = xr; xr1 = xr; dsc->res.opa = LV_OPA_COVER; diff --git a/src/lv_draw/lv_img_buf.h b/src/lv_draw/lv_img_buf.h index d9a8aaf3e..66717e575 100644 --- a/src/lv_draw/lv_img_buf.h +++ b/src/lv_draw/lv_img_buf.h @@ -103,8 +103,7 @@ typedef uint8_t lv_img_cf_t; /** * LittlevGL image header */ -typedef struct -{ +typedef struct { /* The first 8 bit is very important to distinguish the different source types. * For more info see `lv_img_get_src_type()` in lv_img.c */ @@ -121,8 +120,7 @@ typedef struct /** Image header it is compatible with * the result from image converter utility*/ -typedef struct -{ +typedef struct { lv_img_header_t header; uint32_t data_size; const uint8_t * data; @@ -140,12 +138,12 @@ typedef struct { lv_color_t color; /*a color used for `LV_IMG_CF_INDEXED_1/2/4/8BIT` color formats*/ lv_img_cf_t cf; /*color format of the image to rotate*/ bool antialias; - }cfg; + } cfg; struct { lv_color_t color; lv_opa_t opa; - }res; + } res; struct { @@ -155,9 +153,9 @@ typedef struct { int32_t sinma; int32_t cosma; - uint8_t chroma_keyed :1; - uint8_t has_alpha :1; - uint8_t native_color :1; + uint8_t chroma_keyed : 1; + uint8_t has_alpha : 1; + uint8_t native_color : 1; uint16_t zoom_inv; @@ -168,8 +166,8 @@ typedef struct { lv_coord_t ys_int; uint32_t pxi; uint8_t px_size; - }tmp; -}lv_img_transform_dsc_t; + } tmp; +} lv_img_transform_dsc_t; /********************** * GLOBAL PROTOTYPES @@ -182,7 +180,7 @@ typedef struct { * @param cf a color format (`LV_IMG_CF_...`) * @return an allocated image, or NULL on failure */ -lv_img_dsc_t *lv_img_buf_alloc(lv_coord_t w, lv_coord_t h, lv_img_cf_t cf); +lv_img_dsc_t * lv_img_buf_alloc(lv_coord_t w, lv_coord_t h, lv_img_cf_t cf); /** * Get the color of an image's pixel @@ -242,7 +240,7 @@ void lv_img_buf_set_palette(lv_img_dsc_t * dsc, uint8_t id, lv_color_t c); * Free an allocated image buffer * @param dsc image buffer to free */ -void lv_img_buf_free(lv_img_dsc_t *dsc); +void lv_img_buf_free(lv_img_dsc_t * dsc); /** * Get the memory consumption of a raw bitmap, given color format and dimensions. @@ -279,7 +277,8 @@ bool lv_img_buf_transform(lv_img_transform_dsc_t * dsc, lv_coord_t x, lv_coord_t * @param zoom zoom, (256 no zoom) * @param pivot x,y pivot coordinates of rotation */ -void lv_img_buf_get_transformed_area(lv_area_t * res, lv_coord_t w, lv_coord_t h, int16_t angle, uint16_t zoom, lv_point_t * pivot); +void lv_img_buf_get_transformed_area(lv_area_t * res, lv_coord_t w, lv_coord_t h, int16_t angle, uint16_t zoom, + lv_point_t * pivot); /********************** * MACROS diff --git a/src/lv_draw/lv_img_cache.c b/src/lv_draw/lv_img_cache.c index df8b9a7ae..eab868aac 100644 --- a/src/lv_draw/lv_img_cache.c +++ b/src/lv_draw/lv_img_cache.c @@ -14,7 +14,7 @@ #include "../lv_misc/lv_gc.h" #if defined(LV_GC_INCLUDE) -#include LV_GC_INCLUDE + #include LV_GC_INCLUDE #endif /* LV_ENABLE_GC */ /********************* * DEFINES @@ -30,7 +30,7 @@ #define LV_IMG_CACHE_LIFE_LIMIT 1000 #if LV_IMG_CACHE_DEF_SIZE < 1 -#error "LV_IMG_CACHE_DEF_SIZE must be >= 1. See lv_conf.h" + #error "LV_IMG_CACHE_DEF_SIZE must be >= 1. See lv_conf.h" #endif /********************** @@ -86,7 +86,8 @@ lv_img_cache_entry_t * lv_img_cache_open(const void * src, lv_color_t color) lv_img_src_t src_type = lv_img_src_get_type(cache[i].dec_dsc.src); if(src_type == LV_IMG_SRC_VARIABLE) { if(cache[i].dec_dsc.src == src && cache[i].dec_dsc.color.full == color.full) match = true; - } else if(src_type == LV_IMG_SRC_FILE) { + } + else if(src_type == LV_IMG_SRC_FILE) { if(strcmp(cache[i].dec_dsc.src, src) == 0) match = true; } @@ -116,7 +117,8 @@ lv_img_cache_entry_t * lv_img_cache_open(const void * src, lv_color_t color) if(cached_src->dec_dsc.src) { lv_img_decoder_close(&cached_src->dec_dsc); LV_LOG_INFO("image draw: cache miss, close and reuse an entry"); - } else { + } + else { LV_LOG_INFO("image draw: cache miss, cached to an empty entry"); } diff --git a/src/lv_draw/lv_img_cache.h b/src/lv_draw/lv_img_cache.h index ba757b40f..3508bd301 100644 --- a/src/lv_draw/lv_img_cache.h +++ b/src/lv_draw/lv_img_cache.h @@ -25,11 +25,10 @@ extern "C" { /** * When loading images from the network it can take a long time to download and decode the image. - * + * * To avoid repeating this heavy load images can be cached. */ -typedef struct -{ +typedef struct { lv_img_decoder_dsc_t dec_dsc; /**< Image information */ /** Count the cache entries's life. Add `time_tio_open` to `life` when the entry is used. diff --git a/src/lv_draw/lv_img_decoder.c b/src/lv_draw/lv_img_decoder.c index c8121681c..7a8916b27 100644 --- a/src/lv_draw/lv_img_decoder.c +++ b/src/lv_draw/lv_img_decoder.c @@ -14,7 +14,7 @@ #include "../lv_misc/lv_gc.h" #if defined(LV_GC_INCLUDE) -#include LV_GC_INCLUDE + #include LV_GC_INCLUDE #endif /* LV_ENABLE_GC */ /********************* @@ -26,8 +26,7 @@ /********************** * TYPEDEFS **********************/ -typedef struct -{ +typedef struct { #if LV_USE_FILESYSTEM lv_fs_file_t * f; #endif @@ -93,8 +92,7 @@ lv_res_t lv_img_decoder_get_info(const char * src, lv_img_header_t * header) lv_res_t res = LV_RES_INV; lv_img_decoder_t * d; - LV_LL_READ(LV_GC_ROOT(_lv_img_defoder_ll), d) - { + LV_LL_READ(LV_GC_ROOT(_lv_img_defoder_ll), d) { res = LV_RES_INV; if(d->info_cb) { res = d->info_cb(d, src, header); @@ -127,15 +125,15 @@ lv_res_t lv_img_decoder_open(lv_img_decoder_dsc_t * dsc, const void * src, lv_co size_t fnlen = strlen(src); dsc->src = lv_mem_alloc(fnlen + 1); strcpy((char *)dsc->src, src); - } else { + } + else { dsc->src = src; } lv_res_t res = LV_RES_INV; lv_img_decoder_t * d; - LV_LL_READ(LV_GC_ROOT(_lv_img_defoder_ll), d) - { + LV_LL_READ(LV_GC_ROOT(_lv_img_defoder_ll), d) { /*Info an Open callbacks are required*/ if(d->info_cb == NULL || d->open_cb == NULL) continue; @@ -305,7 +303,8 @@ lv_res_t lv_img_decoder_built_in_info(lv_img_decoder_t * decoder, const void * s /* Symbols always have transparent parts. Important because of cover check in the design * function. The actual value doesn't matter because lv_draw_label will draw it*/ header->cf = LV_IMG_CF_ALPHA_1BIT; - } else { + } + else { LV_LOG_WARN("Image get info found unknown src type"); return LV_RES_INV; } @@ -357,10 +356,11 @@ lv_res_t lv_img_decoder_built_in_open(lv_img_decoder_t * decoder, lv_img_decoder LV_LOG_WARN("Image built-in decoder cannot read file because LV_USE_FILESYSTEM = 0"); return LV_RES_INV; #endif - } else if(dsc->src_type == LV_IMG_SRC_VARIABLE) { - /*The variables should have valid data*/ + } + else if(dsc->src_type == LV_IMG_SRC_VARIABLE) { + /*The variables should have valid data*/ if(((lv_img_dsc_t *)dsc->src)->data == NULL) { - return LV_RES_INV; + return LV_RES_INV; } } @@ -372,7 +372,8 @@ lv_res_t lv_img_decoder_built_in_open(lv_img_decoder_t * decoder, lv_img_decoder * So simply give its pointer*/ dsc->img_data = ((lv_img_dsc_t *)dsc->src)->data; return LV_RES_OK; - } else { + } + else { /*If it's a file it need to be read line by line later*/ dsc->img_data = NULL; return LV_RES_OK; @@ -421,7 +422,8 @@ lv_res_t lv_img_decoder_built_in_open(lv_img_decoder_t * decoder, lv_img_decoder LV_LOG_WARN("Image built-in decoder can read the palette because LV_USE_FILESYSTEM = 0"); return LV_RES_INV; #endif - } else { + } + else { /*The palette begins in the beginning of the image data. Just point to it.*/ lv_color32_t * palette_p = (lv_color32_t *)((lv_img_dsc_t *)dsc->src)->data; @@ -473,7 +475,7 @@ lv_res_t lv_img_decoder_built_in_open(lv_img_decoder_t * decoder, lv_img_decoder * @return LV_RES_OK: ok; LV_RES_INV: failed */ lv_res_t lv_img_decoder_built_in_read_line(lv_img_decoder_t * decoder, lv_img_decoder_dsc_t * dsc, lv_coord_t x, - lv_coord_t y, lv_coord_t len, uint8_t * buf) + lv_coord_t y, lv_coord_t len, uint8_t * buf) { (void)decoder; /*Unused*/ @@ -486,14 +488,17 @@ lv_res_t lv_img_decoder_built_in_read_line(lv_img_decoder_t * decoder, lv_img_de if(dsc->src_type == LV_IMG_SRC_FILE) { res = lv_img_decoder_built_in_line_true_color(dsc, x, y, len, buf); } - } else if(dsc->header.cf == LV_IMG_CF_ALPHA_1BIT || dsc->header.cf == LV_IMG_CF_ALPHA_2BIT || - dsc->header.cf == LV_IMG_CF_ALPHA_4BIT || dsc->header.cf == LV_IMG_CF_ALPHA_8BIT) { + } + else if(dsc->header.cf == LV_IMG_CF_ALPHA_1BIT || dsc->header.cf == LV_IMG_CF_ALPHA_2BIT || + dsc->header.cf == LV_IMG_CF_ALPHA_4BIT || dsc->header.cf == LV_IMG_CF_ALPHA_8BIT) { res = lv_img_decoder_built_in_line_alpha(dsc, x, y, len, buf); - } else if(dsc->header.cf == LV_IMG_CF_INDEXED_1BIT || dsc->header.cf == LV_IMG_CF_INDEXED_2BIT || - dsc->header.cf == LV_IMG_CF_INDEXED_4BIT || dsc->header.cf == LV_IMG_CF_INDEXED_8BIT) { + } + else if(dsc->header.cf == LV_IMG_CF_INDEXED_1BIT || dsc->header.cf == LV_IMG_CF_INDEXED_2BIT || + dsc->header.cf == LV_IMG_CF_INDEXED_4BIT || dsc->header.cf == LV_IMG_CF_INDEXED_8BIT) { res = lv_img_decoder_built_in_line_indexed(dsc, x, y, len, buf); - } else { + } + else { LV_LOG_WARN("Built-in image decoder read not supports the color format"); return LV_RES_INV; } @@ -570,7 +575,8 @@ static lv_res_t lv_img_decoder_built_in_line_alpha(lv_img_decoder_dsc_t * dsc, l const lv_opa_t alpha1_opa_table[2] = {0, 255}; /*Opacity mapping with bpp = 1 (Just for compatibility)*/ const lv_opa_t alpha2_opa_table[4] = {0, 85, 170, 255}; /*Opacity mapping with bpp = 2*/ const lv_opa_t alpha4_opa_table[16] = {0, 17, 34, 51, /*Opacity mapping with bpp = 4*/ - 68, 85, 102, 119, 136, 153, 170, 187, 204, 221, 238, 255}; + 68, 85, 102, 119, 136, 153, 170, 187, 204, 221, 238, 255 + }; /*Simply fill the buffer with the color. Later only the alpha value will be modified.*/ lv_color_t bg_color = dsc->color; @@ -635,7 +641,8 @@ static lv_res_t lv_img_decoder_built_in_line_alpha(lv_img_decoder_dsc_t * dsc, l const lv_img_dsc_t * img_dsc = dsc->src; data_tmp = img_dsc->data + ofs; - } else { + } + else { #if LV_USE_FILESYSTEM lv_fs_seek(user_data->f, ofs + 4); /*+4 to skip the header*/ lv_fs_read(user_data->f, fs_buf, w, NULL); @@ -720,7 +727,8 @@ static lv_res_t lv_img_decoder_built_in_line_indexed(lv_img_decoder_dsc_t * dsc, if(dsc->src_type == LV_IMG_SRC_VARIABLE) { const lv_img_dsc_t * img_dsc = dsc->src; data_tmp = img_dsc->data + ofs; - } else { + } + else { #if LV_USE_FILESYSTEM lv_fs_seek(user_data->f, ofs + 4); /*+4 to skip the header*/ lv_fs_read(user_data->f, fs_buf, w, NULL); diff --git a/src/lv_draw/lv_img_decoder.h b/src/lv_draw/lv_img_decoder.h index 611d561ea..5b35f4dd5 100644 --- a/src/lv_draw/lv_img_decoder.h +++ b/src/lv_draw/lv_img_decoder.h @@ -84,8 +84,7 @@ typedef lv_res_t (*lv_img_decoder_read_line_f_t)(struct _lv_img_decoder * decode */ typedef void (*lv_img_decoder_close_f_t)(struct _lv_img_decoder * decoder, struct _lv_img_decoder_dsc * dsc); -typedef struct _lv_img_decoder -{ +typedef struct _lv_img_decoder { lv_img_decoder_info_f_t info_cb; lv_img_decoder_open_f_t open_cb; lv_img_decoder_read_line_f_t read_line_cb; @@ -97,8 +96,7 @@ typedef struct _lv_img_decoder } lv_img_decoder_t; /**Describe an image decoding session. Stores data about the decoding*/ -typedef struct _lv_img_decoder_dsc -{ +typedef struct _lv_img_decoder_dsc { /**The decoder which was able to open the image source*/ lv_img_decoder_t * decoder; @@ -254,7 +252,7 @@ lv_res_t lv_img_decoder_built_in_open(lv_img_decoder_t * decoder, lv_img_decoder * @return LV_RES_OK: ok; LV_RES_INV: failed */ lv_res_t lv_img_decoder_built_in_read_line(lv_img_decoder_t * decoder, lv_img_decoder_dsc_t * dsc, lv_coord_t x, - lv_coord_t y, lv_coord_t len, uint8_t * buf); + lv_coord_t y, lv_coord_t len, uint8_t * buf); /** * Close the pending decoding. Free resources etc. diff --git a/src/lv_font/lv_font.c b/src/lv_font/lv_font.c index c2d6eac82..6e6d0ea36 100644 --- a/src/lv_font/lv_font.c +++ b/src/lv_font/lv_font.c @@ -58,7 +58,8 @@ const uint8_t * lv_font_get_glyph_bitmap(const lv_font_t * font_p, uint32_t lett * @return true: descriptor is successfully loaded into `dsc_out`. * false: the letter was not found, no data is loaded to `dsc_out` */ -bool lv_font_get_glyph_dsc(const lv_font_t * font_p, lv_font_glyph_dsc_t * dsc_out, uint32_t letter, uint32_t letter_next) +bool lv_font_get_glyph_dsc(const lv_font_t * font_p, lv_font_glyph_dsc_t * dsc_out, uint32_t letter, + uint32_t letter_next) { return font_p->get_glyph_dsc(font_p, dsc_out, letter, letter_next); } diff --git a/src/lv_font/lv_font.h b/src/lv_font/lv_font.h index 01ba7c8c9..651314210 100644 --- a/src/lv_font/lv_font.h +++ b/src/lv_font/lv_font.h @@ -39,15 +39,14 @@ extern "C" { *-----------------*/ /** Describes the properties of a glyph. */ -typedef struct -{ +typedef struct { uint16_t adv_w; /**< The glyph needs this space. Draw the next glyph after this width. 8 bit integer, 4 bit fractional */ uint16_t box_w; /**< Width of the glyph's bounding box*/ uint16_t box_h; /**< Height of the glyph's bounding box*/ int16_t ofs_x; /**< x offset of the bounding box*/ int16_t ofs_y; /**< y offset of the bounding box*/ uint8_t bpp; /**< Bit-per-pixel: 1, 2, 4, 8*/ -}lv_font_glyph_dsc_t; +} lv_font_glyph_dsc_t; /** The bitmaps might be upscaled by 3 to achieve subpixel rendering. */ @@ -61,8 +60,7 @@ enum { typedef uint8_t lv_font_subpx_t; /** Describe the properties of a font*/ -typedef struct _lv_font_struct -{ +typedef struct _lv_font_struct { /** Get a glyph's descriptor from a font*/ bool (*get_glyph_dsc)(const struct _lv_font_struct *, lv_font_glyph_dsc_t *, uint32_t letter, uint32_t letter_next); @@ -72,7 +70,7 @@ typedef struct _lv_font_struct /*Pointer to the font in a font pack (must have the same line height)*/ lv_coord_t line_height; /**< The real line height where any text fits*/ lv_coord_t base_line; /**< Base line measured from the top of the line_height*/ - uint8_t subpx :2; /**< An element of `lv_font_subpx_t`*/ + uint8_t subpx : 2; /**< An element of `lv_font_subpx_t`*/ void * dsc; /**< Store implementation specific or run_time data or caching here*/ #if LV_USE_USER_DATA lv_font_user_data_t user_data; /**< Custom user data for font. */ @@ -101,7 +99,8 @@ const uint8_t * lv_font_get_glyph_bitmap(const lv_font_t * font_p, uint32_t lett * @return true: descriptor is successfully loaded into `dsc_out`. * false: the letter was not found, no data is loaded to `dsc_out` */ -bool lv_font_get_glyph_dsc(const lv_font_t * font_p, lv_font_glyph_dsc_t * dsc_out, uint32_t letter, uint32_t letter_next); +bool lv_font_get_glyph_dsc(const lv_font_t * font_p, lv_font_glyph_dsc_t * dsc_out, uint32_t letter, + uint32_t letter_next); /** * Get the width of a glyph with kerning diff --git a/src/lv_font/lv_font_fmt_txt.c b/src/lv_font/lv_font_fmt_txt.c index 04829948c..d7ce7e503 100644 --- a/src/lv_font/lv_font_fmt_txt.c +++ b/src/lv_font/lv_font_fmt_txt.c @@ -26,7 +26,7 @@ typedef enum { RLE_STATE_SINGLE = 0, RLE_STATE_REPEATE, RLE_STATE_COUNTER, -}rle_state_t; +} rle_state_t; /********************** * STATIC PROTOTYPES @@ -76,7 +76,7 @@ static rle_state_t rle_state; */ const uint8_t * lv_font_get_bitmap_fmt_txt(const lv_font_t * font, uint32_t unicode_letter) { - if(unicode_letter == '\t') unicode_letter = ' '; + if(unicode_letter == '\t') unicode_letter = ' '; lv_font_fmt_txt_dsc_t * fdsc = (lv_font_fmt_txt_dsc_t *) font->dsc; uint32_t gid = get_glyph_dsc_id(font, unicode_letter); @@ -88,8 +88,7 @@ const uint8_t * lv_font_get_bitmap_fmt_txt(const lv_font_t * font, uint32_t unic if(gdsc) return &fdsc->glyph_bitmap[gdsc->bitmap_index]; } /*Handle compressed bitmap*/ - else - { + else { static uint8_t * buf = NULL; uint32_t gsize = gdsc->box_w * gdsc->box_h; @@ -97,10 +96,18 @@ const uint8_t * lv_font_get_bitmap_fmt_txt(const lv_font_t * font, uint32_t unic uint32_t buf_size = gsize; switch(fdsc->bpp) { - case 1: buf_size = gsize >> 3; break; - case 2: buf_size = gsize >> 2; break; - case 3: buf_size = gsize >> 1; break; - case 4: buf_size = gsize >> 1; break; + case 1: + buf_size = gsize >> 3; + break; + case 2: + buf_size = gsize >> 2; + break; + case 3: + buf_size = gsize >> 1; + break; + case 4: + buf_size = gsize >> 1; + break; } if(lv_mem_get_size(buf) < buf_size) { @@ -109,7 +116,7 @@ const uint8_t * lv_font_get_bitmap_fmt_txt(const lv_font_t * font, uint32_t unic if(buf == NULL) return NULL; } - decompress(&fdsc->glyph_bitmap[gdsc->bitmap_index], buf, gdsc->box_w , gdsc->box_h, (uint8_t)fdsc->bpp); + decompress(&fdsc->glyph_bitmap[gdsc->bitmap_index], buf, gdsc->box_w, gdsc->box_h, (uint8_t)fdsc->bpp); return buf; } @@ -125,13 +132,14 @@ const uint8_t * lv_font_get_bitmap_fmt_txt(const lv_font_t * font, uint32_t unic * @return true: descriptor is successfully loaded into `dsc_out`. * false: the letter was not found, no data is loaded to `dsc_out` */ -bool lv_font_get_glyph_dsc_fmt_txt(const lv_font_t * font, lv_font_glyph_dsc_t * dsc_out, uint32_t unicode_letter, uint32_t unicode_letter_next) +bool lv_font_get_glyph_dsc_fmt_txt(const lv_font_t * font, lv_font_glyph_dsc_t * dsc_out, uint32_t unicode_letter, + uint32_t unicode_letter_next) { - bool is_tab = false; - if(unicode_letter == '\t') { - unicode_letter = ' '; - is_tab = true; - } + bool is_tab = false; + if(unicode_letter == '\t') { + unicode_letter = ' '; + is_tab = true; + } lv_font_fmt_txt_dsc_t * fdsc = (lv_font_fmt_txt_dsc_t *) font->dsc; uint32_t gid = get_glyph_dsc_id(font, unicode_letter); if(!gid) return false; @@ -195,7 +203,8 @@ static uint32_t get_glyph_dsc_id(const lv_font_t * font, uint32_t letter) glyph_id = fdsc->cmaps[i].glyph_id_start + gid_ofs_8[rcp]; } else if(fdsc->cmaps[i].type == LV_FONT_FMT_TXT_CMAP_SPARSE_TINY) { - uint8_t * p = lv_utils_bsearch(&rcp, fdsc->cmaps[i].unicode_list, fdsc->cmaps[i].list_length, sizeof(fdsc->cmaps[i].unicode_list[0]), unicode_list_compare); + uint8_t * p = lv_utils_bsearch(&rcp, fdsc->cmaps[i].unicode_list, fdsc->cmaps[i].list_length, + sizeof(fdsc->cmaps[i].unicode_list[0]), unicode_list_compare); if(p) { lv_uintptr_t ofs = (lv_uintptr_t)(p - (uint8_t *) fdsc->cmaps[i].unicode_list); @@ -204,10 +213,11 @@ static uint32_t get_glyph_dsc_id(const lv_font_t * font, uint32_t letter) } } else if(fdsc->cmaps[i].type == LV_FONT_FMT_TXT_CMAP_SPARSE_FULL) { - uint8_t * p = lv_utils_bsearch(&rcp, fdsc->cmaps[i].unicode_list, fdsc->cmaps[i].list_length, sizeof(fdsc->cmaps[i].unicode_list[0]), unicode_list_compare); + uint8_t * p = lv_utils_bsearch(&rcp, fdsc->cmaps[i].unicode_list, fdsc->cmaps[i].list_length, + sizeof(fdsc->cmaps[i].unicode_list[0]), unicode_list_compare); if(p) { - lv_uintptr_t ofs = (lv_uintptr_t)(p - (uint8_t*) fdsc->cmaps[i].unicode_list); + lv_uintptr_t ofs = (lv_uintptr_t)(p - (uint8_t *) fdsc->cmaps[i].unicode_list); ofs = ofs >> 1; /*The list stores `uint16_t` so the get the index divide by 2*/ const uint8_t * gid_ofs_16 = fdsc->cmaps[i].glyph_id_ofs_list; glyph_id = fdsc->cmaps[i].glyph_id_start + gid_ofs_16[ofs]; @@ -248,7 +258,8 @@ static int8_t get_kern_value(const lv_font_t * font, uint32_t gid_left, uint32_t ofs = ofs >> 1; /*ofs is for pair, divide by 2 to refer as a single value*/ value = kdsc->values[ofs]; } - } else if(kdsc->glyph_ids_size == 1) { + } + else if(kdsc->glyph_ids_size == 1) { /* Use binary search to find the kern value. * The pairs are ordered left_id first, then right_id secondly. */ const uint16_t * g_ids = kdsc->glyph_ids; @@ -257,15 +268,17 @@ static int8_t get_kern_value(const lv_font_t * font, uint32_t gid_left, uint32_t /*If the `g_id_both` were found get its index from the pointer*/ if(kid_p) { - lv_uintptr_t ofs = (lv_uintptr_t) (kid_p - (const uint8_t *)g_ids); + lv_uintptr_t ofs = (lv_uintptr_t)(kid_p - (const uint8_t *)g_ids); ofs = ofs >> 4; /*ofs is 4 byte pairs, divide by 4 to refer as a single value*/ value = kdsc->values[ofs]; } - } else { + } + else { /*Invalid value*/ } - } else { + } + else { /*Kern classes*/ const lv_font_fmt_txt_kern_classes_t * kdsc = fdsc->kern_dsc; uint8_t left_class = kdsc->left_class_mapping[gid_left]; @@ -274,7 +287,7 @@ static int8_t get_kern_value(const lv_font_t * font, uint32_t gid_left, uint32_t /* If class = 0, kerning not exist for that glyph * else got the value form `class_pair_values` 2D array*/ if(left_class > 0 && right_class > 0) { - value = kdsc->class_pair_values[(left_class-1)* kdsc->right_class_cnt + (right_class-1)]; + value = kdsc->class_pair_values[(left_class - 1) * kdsc->right_class_cnt + (right_class - 1)]; } } @@ -325,7 +338,7 @@ static void decompress(const uint8_t * in, uint8_t * out, lv_coord_t w, lv_coord lv_coord_t y; lv_coord_t x; for(x = 0; x < w; x++) { - bits_write(out,wrp, line_buf1[x], bpp); + bits_write(out, wrp, line_buf1[x], bpp); wrp += wr_size; } @@ -334,7 +347,7 @@ static void decompress(const uint8_t * in, uint8_t * out, lv_coord_t w, lv_coord for(x = 0; x < w; x++) { line_buf1[x] = line_buf2[x] ^ line_buf1[x]; - bits_write(out,wrp, line_buf1[x], bpp); + bits_write(out, wrp, line_buf1[x], bpp); wrp += wr_size; } } @@ -388,14 +401,30 @@ static void bits_write(uint8_t * out, uint32_t bit_pos, uint8_t val, uint8_t len if(len == 3) { len = 4; switch(val) { - case 0: val = 0; break; - case 1: val = 2; break; - case 2: val = 4; break; - case 3: val = 6; break; - case 4: val = 9; break; - case 5: val = 11; break; - case 6: val = 13; break; - case 7: val = 15; break; + case 0: + val = 0; + break; + case 1: + val = 2; + break; + case 2: + val = 4; + break; + case 3: + val = 6; + break; + case 4: + val = 9; + break; + case 5: + val = 11; + break; + case 6: + val = 13; + break; + case 7: + val = 15; + break; } } @@ -444,14 +473,16 @@ static uint8_t rle_next(void) rle_rdp += 6; if(rle_cnt != 0) { rle_state = RLE_STATE_COUNTER; - } else { + } + else { ret = get_bits(rle_in, rle_rdp, rle_bpp); rle_prev_v = ret; rle_rdp += rle_bpp; rle_state = RLE_STATE_SINGLE; } } - } else { + } + else { ret = get_bits(rle_in, rle_rdp, rle_bpp); rle_prev_v = ret; rle_rdp += rle_bpp; diff --git a/src/lv_font/lv_font_fmt_txt.h b/src/lv_font/lv_font_fmt_txt.h index 1bae3f7f6..ad115b04d 100644 --- a/src/lv_font/lv_font_fmt_txt.h +++ b/src/lv_font/lv_font_fmt_txt.h @@ -27,11 +27,10 @@ extern "C" { **********************/ /** This describes a glyph. */ -typedef struct -{ +typedef struct { #if LV_FONT_FMT_TXT_LARGE == 0 uint32_t bitmap_index : 20; /**< Start index of the bitmap. A font can be max 1 MB. */ - uint32_t adv_w :12; /**< Draw the next glyph after this width. 8.4 format (real_value * 16 is stored). */ + uint32_t adv_w : 12; /**< Draw the next glyph after this width. 8.4 format (real_value * 16 is stored). */ uint8_t box_w; /**< Width of the glyph's bounding box*/ uint8_t box_h; /**< Height of the glyph's bounding box*/ int8_t ofs_x; /**< x offset of the bounding box*/ @@ -44,7 +43,7 @@ typedef struct int16_t ofs_x; /**< x offset of the bounding box*/ int16_t ofs_y; /**< y offset of the bounding box. Measured from the top of the line*/ #endif -}lv_font_fmt_txt_glyph_dsc_t; +} lv_font_fmt_txt_glyph_dsc_t; /** Format of font character map. */ @@ -112,7 +111,7 @@ typedef struct { /** Type of this character map*/ lv_font_fmt_txt_cmap_type_t type; -}lv_font_fmt_txt_cmap_t; +} lv_font_fmt_txt_cmap_t; /** A simple mapping of kern values from pairs*/ typedef struct { @@ -125,9 +124,9 @@ typedef struct { */ const void * glyph_ids; const int8_t * values; - uint32_t pair_cnt :24; - uint32_t glyph_ids_size :2; /*0: `glyph_ids` is stored as `uint8_t`; 1: as `uint16_t`*/ -}lv_font_fmt_txt_kern_pair_t; + uint32_t pair_cnt : 24; + uint32_t glyph_ids_size : 2; /*0: `glyph_ids` is stored as `uint8_t`; 1: as `uint16_t`*/ +} lv_font_fmt_txt_kern_pair_t; /** More complex but more optimal class based kern value storage*/ typedef struct { @@ -144,14 +143,14 @@ typedef struct { const uint8_t * right_class_mapping; /*Map the glyph_ids to classes: index -> glyph_id -> class_id*/ uint8_t left_class_cnt; uint8_t right_class_cnt; -}lv_font_fmt_txt_kern_classes_t; +} lv_font_fmt_txt_kern_classes_t; /** Bitmap formats*/ typedef enum { LV_FONT_FMT_TXT_PLAIN = 0, LV_FONT_FMT_TXT_COMPRESSED = 1, -}lv_font_fmt_txt_bitmap_format_t; +} lv_font_fmt_txt_bitmap_format_t; /*Describe store additional data for fonts */ @@ -176,25 +175,25 @@ typedef struct { uint16_t kern_scale; /*Number of cmap tables*/ - uint16_t cmap_num :10; + uint16_t cmap_num : 10; /*Bit per pixel: 1, 2, 3, 4*/ - uint16_t bpp :3; + uint16_t bpp : 3; /*Type of `kern_dsc`*/ - uint16_t kern_classes :1; + uint16_t kern_classes : 1; /* * storage format of the bitmap * from `lv_font_fmt_txt_bitmap_format_t` */ - uint16_t bitmap_format :2; + uint16_t bitmap_format : 2; /*Cache the last letter and is glyph id*/ uint32_t last_letter; uint32_t last_glyph_id; -}lv_font_fmt_txt_dsc_t; +} lv_font_fmt_txt_dsc_t; /********************** * GLOBAL PROTOTYPES @@ -216,7 +215,8 @@ const uint8_t * lv_font_get_bitmap_fmt_txt(const lv_font_t * font, uint32_t lett * @return true: descriptor is successfully loaded into `dsc_out`. * false: the letter was not found, no data is loaded to `dsc_out` */ -bool lv_font_get_glyph_dsc_fmt_txt(const lv_font_t * font, lv_font_glyph_dsc_t * dsc_out, uint32_t unicode_letter, uint32_t unicode_letter_next); +bool lv_font_get_glyph_dsc_fmt_txt(const lv_font_t * font, lv_font_glyph_dsc_t * dsc_out, uint32_t unicode_letter, + uint32_t unicode_letter_next); /********************** * MACROS diff --git a/src/lv_font/lv_font_roboto_12.c b/src/lv_font/lv_font_roboto_12.c index 3da8e899e..19ad2ca19 100644 --- a/src/lv_font/lv_font_roboto_12.c +++ b/src/lv_font/lv_font_roboto_12.c @@ -7,7 +7,7 @@ ******************************************************************************/ #ifndef LV_FONT_ROBOTO_12 -#define LV_FONT_ROBOTO_12 1 + #define LV_FONT_ROBOTO_12 1 #endif #if LV_FONT_ROBOTO_12 @@ -1334,8 +1334,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 @@ -1352,8 +1351,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, 1, 0, 2, 0, 0, 0, 0, 2, 3, 0, 0, 0, 4, 0, 4, 5, 0, 0, 0, 0, 0, 0, 0, @@ -1377,8 +1375,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, 1, 0, 2, 0, 0, 0, 3, 2, 0, 4, 5, 0, 6, 7, 6, 8, 0, 0, 0, 0, 0, 0, 0, @@ -1402,8 +1399,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, 0, -4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -1583,8 +1579,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/lv_font/lv_font_roboto_12_subpx.c b/src/lv_font/lv_font_roboto_12_subpx.c index 4565b99c1..a46a80ab4 100644 --- a/src/lv_font/lv_font_roboto_12_subpx.c +++ b/src/lv_font/lv_font_roboto_12_subpx.c @@ -7,7 +7,7 @@ ******************************************************************************/ #ifndef LV_FONT_ROBOTO_12_SUBPX -#define LV_FONT_ROBOTO_12_SUBPX 1 + #define LV_FONT_ROBOTO_12_SUBPX 1 #endif #if LV_FONT_ROBOTO_12_SUBPX @@ -3125,8 +3125,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 @@ -3143,8 +3142,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, 1, 0, 2, 0, 0, 0, 0, 2, 3, 0, 0, 0, 4, 0, 4, 5, 0, 0, 0, 0, 0, 0, 0, @@ -3168,8 +3166,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, 1, 0, 2, 0, 0, 0, 3, 2, 0, 4, 5, 0, 6, 7, 6, 8, 0, 0, 0, 0, 0, 0, 0, @@ -3193,8 +3190,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, 0, -4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -3374,8 +3370,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/lv_font/lv_font_roboto_16.c b/src/lv_font/lv_font_roboto_16.c index e61c0acf0..70d69b21d 100644 --- a/src/lv_font/lv_font_roboto_16.c +++ b/src/lv_font/lv_font_roboto_16.c @@ -7,7 +7,7 @@ ******************************************************************************/ #ifndef LV_FONT_ROBOTO_16 -#define LV_FONT_ROBOTO_16 1 + #define LV_FONT_ROBOTO_16 1 #endif #if LV_FONT_ROBOTO_16 @@ -1826,8 +1826,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 @@ -1844,8 +1843,7 @@ static const lv_font_fmt_txt_cmap_t cmaps[] = /*Pair left and right glyphs for kerning*/ -static const uint8_t kern_pair_glyph_ids[] = -{ +static const uint8_t kern_pair_glyph_ids[] = { 1, 53, 3, 3, 3, 8, @@ -2285,68 +2283,66 @@ static const uint8_t kern_pair_glyph_ids[] = /* Kerning between the respective left and right glyphs * 4.4 format which needs to scaled with `kern_scale`*/ -static const int8_t kern_pair_values[] = -{ +static const int8_t kern_pair_values[] = { -5, -13, -13, -15, -6, -7, -7, -7, - -7, -2, -2, -8, -2, -7, -10, 1, - -13, -13, -15, -6, -7, -7, -7, -7, - -2, -2, -8, -2, -7, -10, 1, 3, - 2, 3, -21, -21, -21, -21, -28, -15, - -15, -8, -1, -1, -1, -1, -16, -2, - -11, -9, -12, -1, -2, -1, -6, -4, - -6, 2, -3, -3, -7, -3, -4, -1, - -2, -13, -13, -3, -3, -3, -3, -5, - -3, 3, -2, -2, -2, -2, -2, -2, - -2, -2, -3, -3, -3, -29, -29, -21, - -33, 3, -4, -3, -3, -3, -3, -3, - -3, -3, -3, -3, -3, 2, -4, 2, - -3, 2, -4, 2, -3, -3, -8, -4, - -4, -4, -4, -3, -3, -3, -3, -3, - -3, -3, -3, -3, -3, -5, -8, -5, - -42, -42, 2, -8, -8, -8, -8, -34, - -7, -22, -18, -30, -5, -17, -11, -17, - 2, -4, 2, -3, 2, -4, 2, -3, - -13, -13, -3, -3, -3, -3, -5, -3, - -40, -40, -17, -25, -4, -3, -1, -2, - -2, -2, -2, -2, -2, 2, 2, 2, - -5, -3, -2, -4, -10, -2, -6, -5, - -27, -29, -27, -10, -3, -3, -30, -3, - -3, -2, 2, 2, 2, 2, -14, -12, - -12, -12, -12, -14, -14, -12, -14, -12, - -9, -14, -12, -9, -7, -10, -9, -7, - -3, 3, -28, -5, -28, -9, -2, -2, - -2, -2, 2, -6, -5, -5, -5, -5, - -6, -5, -4, -3, -1, -1, 2, 2, - -15, -7, -15, -5, 2, 2, -4, -4, - -4, -4, -4, -4, -4, -3, -2, 2, - -6, -3, -3, -3, -3, 2, -3, -3, - -3, -3, -3, -3, -3, -4, -4, -4, - 3, -6, -26, -6, -26, -12, -4, -4, - -12, -4, -4, -2, 2, -12, 2, 2, - 2, 2, 2, -9, -8, -8, -8, -3, - -8, -5, -5, -8, -5, -8, -5, -7, - -3, -5, -2, -3, -2, -4, 2, -6, - 2, -3, -3, -3, -3, -3, -3, -3, - -3, -3, -3, -2, -3, -3, -3, -2, - -2, -8, -8, -2, -2, -4, -4, -1, - -2, -1, -2, -1, -1, -2, -2, -2, - -2, 2, 2, 3, 2, -3, -3, -3, - -3, -3, 2, -13, -13, -2, -2, -2, - -2, -2, -13, -13, -13, -13, -17, -17, - -2, -3, -2, -2, -4, -4, -1, -2, - -1, -2, 2, 2, -15, -15, -5, -2, - -2, -2, 2, -2, -2, -2, 6, 2, - 2, 2, -2, 2, 2, -13, -13, -2, - -2, -2, -2, 2, -2, -2, -2, -15, - -15, -2, -2, -2, -2, -2, -2, 2, - 2, -13, -13, -2, -2, -2, -2, 2, - -2, -2, -2, -2, -2, -2, -2, -2, - -2, -2, -2 -}; + -7, -2, -2, -8, -2, -7, -10, 1, + -13, -13, -15, -6, -7, -7, -7, -7, + -2, -2, -8, -2, -7, -10, 1, 3, + 2, 3, -21, -21, -21, -21, -28, -15, + -15, -8, -1, -1, -1, -1, -16, -2, + -11, -9, -12, -1, -2, -1, -6, -4, + -6, 2, -3, -3, -7, -3, -4, -1, + -2, -13, -13, -3, -3, -3, -3, -5, + -3, 3, -2, -2, -2, -2, -2, -2, + -2, -2, -3, -3, -3, -29, -29, -21, + -33, 3, -4, -3, -3, -3, -3, -3, + -3, -3, -3, -3, -3, 2, -4, 2, + -3, 2, -4, 2, -3, -3, -8, -4, + -4, -4, -4, -3, -3, -3, -3, -3, + -3, -3, -3, -3, -3, -5, -8, -5, + -42, -42, 2, -8, -8, -8, -8, -34, + -7, -22, -18, -30, -5, -17, -11, -17, + 2, -4, 2, -3, 2, -4, 2, -3, + -13, -13, -3, -3, -3, -3, -5, -3, + -40, -40, -17, -25, -4, -3, -1, -2, + -2, -2, -2, -2, -2, 2, 2, 2, + -5, -3, -2, -4, -10, -2, -6, -5, + -27, -29, -27, -10, -3, -3, -30, -3, + -3, -2, 2, 2, 2, 2, -14, -12, + -12, -12, -12, -14, -14, -12, -14, -12, + -9, -14, -12, -9, -7, -10, -9, -7, + -3, 3, -28, -5, -28, -9, -2, -2, + -2, -2, 2, -6, -5, -5, -5, -5, + -6, -5, -4, -3, -1, -1, 2, 2, + -15, -7, -15, -5, 2, 2, -4, -4, + -4, -4, -4, -4, -4, -3, -2, 2, + -6, -3, -3, -3, -3, 2, -3, -3, + -3, -3, -3, -3, -3, -4, -4, -4, + 3, -6, -26, -6, -26, -12, -4, -4, + -12, -4, -4, -2, 2, -12, 2, 2, + 2, 2, 2, -9, -8, -8, -8, -3, + -8, -5, -5, -8, -5, -8, -5, -7, + -3, -5, -2, -3, -2, -4, 2, -6, + 2, -3, -3, -3, -3, -3, -3, -3, + -3, -3, -3, -2, -3, -3, -3, -2, + -2, -8, -8, -2, -2, -4, -4, -1, + -2, -1, -2, -1, -1, -2, -2, -2, + -2, 2, 2, 3, 2, -3, -3, -3, + -3, -3, 2, -13, -13, -2, -2, -2, + -2, -2, -13, -13, -13, -13, -17, -17, + -2, -3, -2, -2, -4, -4, -1, -2, + -1, -2, 2, 2, -15, -15, -5, -2, + -2, -2, 2, -2, -2, -2, 6, 2, + 2, 2, -2, 2, 2, -13, -13, -2, + -2, -2, -2, 2, -2, -2, -2, -15, + -15, -2, -2, -2, -2, -2, -2, 2, + 2, -13, -13, -2, -2, -2, -2, 2, + -2, -2, -2, -2, -2, -2, -2, -2, + -2, -2, -2 + }; /*Collect the kern pair's data in one place*/ -static const lv_font_fmt_txt_kern_pair_t kern_pairs = -{ +static const lv_font_fmt_txt_kern_pair_t kern_pairs = { .glyph_ids = kern_pair_glyph_ids, .values = kern_pair_values, .pair_cnt = 435, diff --git a/src/lv_font/lv_font_roboto_22.c b/src/lv_font/lv_font_roboto_22.c index f7bdac057..34e2c6d15 100644 --- a/src/lv_font/lv_font_roboto_22.c +++ b/src/lv_font/lv_font_roboto_22.c @@ -7,7 +7,7 @@ ******************************************************************************/ #ifndef LV_FONT_ROBOTO_22 -#define LV_FONT_ROBOTO_22 1 + #define LV_FONT_ROBOTO_22 1 #endif #if LV_FONT_ROBOTO_22 @@ -2930,8 +2930,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 @@ -2948,8 +2947,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, 1, 0, 2, 0, 0, 0, 0, 2, 3, 0, 0, 0, 4, 0, 4, 5, 0, 0, 0, 0, 0, 0, 0, @@ -2973,8 +2971,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, 1, 0, 2, 0, 0, 0, 3, 2, 0, 4, 5, 0, 6, 7, 6, 8, 0, 0, 0, 0, 0, 0, 0, @@ -2998,8 +2995,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, 0, -7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -3179,8 +3175,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/lv_font/lv_font_roboto_28.c b/src/lv_font/lv_font_roboto_28.c index f3e58bb33..8da92024a 100644 --- a/src/lv_font/lv_font_roboto_28.c +++ b/src/lv_font/lv_font_roboto_28.c @@ -7,7 +7,7 @@ ******************************************************************************/ #ifndef LV_FONT_ROBOTO_28 -#define LV_FONT_ROBOTO_28 1 + #define LV_FONT_ROBOTO_28 1 #endif #if LV_FONT_ROBOTO_28 @@ -4315,8 +4315,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 @@ -4333,8 +4332,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, 1, 0, 2, 0, 0, 0, 0, 2, 3, 0, 0, 0, 4, 0, 4, 5, 0, 0, 0, 0, 0, 0, 0, @@ -4358,8 +4356,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, 1, 0, 2, 0, 0, 0, 3, 2, 0, 4, 5, 0, 6, 7, 6, 8, 0, 0, 0, 0, 0, 0, 0, @@ -4383,8 +4380,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, 0, -9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -4564,8 +4560,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/lv_font/lv_font_roboto_28_compressed.c b/src/lv_font/lv_font_roboto_28_compressed.c index 92e714793..834314761 100644 --- a/src/lv_font/lv_font_roboto_28_compressed.c +++ b/src/lv_font/lv_font_roboto_28_compressed.c @@ -7,7 +7,7 @@ ******************************************************************************/ #ifndef LV_FONT_ROBOTO_28_COMPRESSED -#define LV_FONT_ROBOTO_28_COMPRESSED 1 + #define LV_FONT_ROBOTO_28_COMPRESSED 1 #endif #if LV_FONT_ROBOTO_28_COMPRESSED @@ -2157,8 +2157,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 @@ -2175,8 +2174,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, 1, 0, 2, 0, 0, 0, 0, 2, 3, 0, 0, 0, 4, 0, 4, 5, 0, 0, 0, 0, 0, 0, 0, @@ -2200,8 +2198,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, 1, 0, 2, 0, 0, 0, 3, 2, 0, 4, 5, 0, 6, 7, 6, 8, 0, 0, 0, 0, 0, 0, 0, @@ -2225,8 +2222,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, 0, -9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -2406,8 +2402,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/lv_font/lv_font_unscii_8.c b/src/lv_font/lv_font_unscii_8.c index 1b96823e8..949bc2633 100644 --- a/src/lv_font/lv_font_unscii_8.c +++ b/src/lv_font/lv_font_unscii_8.c @@ -3,11 +3,11 @@ /******************************************************************************* * Size: 8 px * Bpp: 1 - * Opts: + * Opts: ******************************************************************************/ #ifndef LV_FONT_UNSCII_8 -#define LV_FONT_UNSCII_8 1 + #define LV_FONT_UNSCII_8 1 #endif #if LV_FONT_UNSCII_8 @@ -418,8 +418,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, .type = LV_FONT_FMT_TXT_CMAP_FORMAT0_TINY, .glyph_id_start = 1, .unicode_list = NULL, .glyph_id_ofs_list = NULL, .list_length = 0 diff --git a/src/lv_hal/lv_hal_disp.c b/src/lv_hal/lv_hal_disp.c index ca3eb8478..581b555ee 100644 --- a/src/lv_hal/lv_hal_disp.c +++ b/src/lv_hal/lv_hal_disp.c @@ -20,7 +20,7 @@ #include "../lv_themes/lv_theme.h" #if defined(LV_GC_INCLUDE) -#include LV_GC_INCLUDE + #include LV_GC_INCLUDE #endif /* LV_ENABLE_GC */ /********************* @@ -139,7 +139,7 @@ lv_disp_t * lv_disp_drv_register(lv_disp_drv_t * driver) disp->refr_task = lv_task_create(lv_disp_refr_task, LV_DISP_DEF_REFR_PERIOD, LV_REFR_TASK_PRIO, disp); LV_ASSERT_MEM(disp->refr_task); if(disp->refr_task == NULL) return NULL; - + disp->inv_p = 0; disp->last_activity_time = 0; @@ -170,8 +170,7 @@ void lv_disp_drv_update(lv_disp_t * disp, lv_disp_drv_t * new_drv) memcpy(&disp->driver, new_drv, sizeof(lv_disp_drv_t)); lv_obj_t * scr; - LV_LL_READ(disp->scr_ll, scr) - { + LV_LL_READ(disp->scr_ll, scr) { lv_obj_set_size(scr, lv_disp_get_hor_res(disp), lv_disp_get_ver_res(disp)); } } @@ -352,7 +351,8 @@ bool lv_disp_is_true_double_buf(lv_disp_t * disp) if(lv_disp_is_double_buf(disp) && disp->driver.buffer->size == scr_size) { return true; - } else { + } + else { return false; } } diff --git a/src/lv_hal/lv_hal_disp.h b/src/lv_hal/lv_hal_disp.h index 8db692a09..01e01c91f 100644 --- a/src/lv_hal/lv_hal_disp.h +++ b/src/lv_hal/lv_hal_disp.h @@ -44,8 +44,7 @@ struct _disp_drv_t; /** * Structure for holding display buffer information. */ -typedef struct -{ +typedef struct { void * buf1; /**< First display buffer. */ void * buf2; /**< Second display buffer. */ @@ -59,8 +58,7 @@ typedef struct /** * Display Driver structure to be registered by HAL */ -typedef struct _disp_drv_t -{ +typedef struct _disp_drv_t { lv_coord_t hor_res; /**< Horizontal resolution. */ lv_coord_t ver_res; /**< Vertical resolution. */ @@ -124,8 +122,7 @@ struct _lv_obj_t; * Display structure. * ::lv_disp_drv_t is the first member of the structure. */ -typedef struct _disp_t -{ +typedef struct _disp_t { /**< Driver to the display*/ lv_disp_drv_t driver; diff --git a/src/lv_hal/lv_hal_indev.c b/src/lv_hal/lv_hal_indev.c index d08484859..ad8c3d275 100644 --- a/src/lv_hal/lv_hal_indev.c +++ b/src/lv_hal/lv_hal_indev.c @@ -16,7 +16,7 @@ #include "lv_hal_disp.h" #if defined(LV_GC_INCLUDE) -#include LV_GC_INCLUDE + #include LV_GC_INCLUDE #endif /* LV_ENABLE_GC */ /********************* @@ -148,7 +148,8 @@ bool lv_indev_read(lv_indev_t * indev, lv_indev_data_t * data) LV_LOG_TRACE("idnev read started"); cont = indev->driver.read_cb(&indev->driver, data); LV_LOG_TRACE("idnev read finished"); - } else { + } + else { LV_LOG_WARN("indev function registered"); } diff --git a/src/lv_hal/lv_hal_indev.h b/src/lv_hal/lv_hal_indev.h index 02e791a11..bd41d9a6b 100644 --- a/src/lv_hal/lv_hal_indev.h +++ b/src/lv_hal/lv_hal_indev.h @@ -61,16 +61,15 @@ enum { typedef uint8_t lv_drag_dir_t; enum { - LV_GESTURE_DIR_TOP, /**< Gesture dir up. */ - LV_GESTURE_DIR_BOTTOM, /**< Gesture dir down. */ - LV_GESTURE_DIR_LEFT, /**< Gesture dir left. */ - LV_GESTURE_DIR_RIGHT, /**< Gesture dir right. */ + LV_GESTURE_DIR_TOP, /**< Gesture dir up. */ + LV_GESTURE_DIR_BOTTOM, /**< Gesture dir down. */ + LV_GESTURE_DIR_LEFT, /**< Gesture dir left. */ + LV_GESTURE_DIR_RIGHT, /**< Gesture dir right. */ }; typedef uint8_t lv_gesture_dir_t; /** Data structure passed to an input driver to fill */ -typedef struct -{ +typedef struct { lv_point_t point; /**< For LV_INDEV_TYPE_POINTER the currently pressed point*/ uint32_t key; /**< For LV_INDEV_TYPE_KEYPAD the currently pressed key*/ uint32_t btn_id; /**< For LV_INDEV_TYPE_BUTTON the currently pressed button*/ @@ -81,8 +80,7 @@ typedef struct /** Initialized by the user and registered by 'lv_indev_add()'*/ -typedef struct _lv_indev_drv_t -{ +typedef struct _lv_indev_drv_t { /**< Input device type*/ lv_indev_type_t type; @@ -128,13 +126,11 @@ typedef struct _lv_indev_drv_t /** Run time data of input devices * Internally used by the library, you should not need to touch it. */ -typedef struct _lv_indev_proc_t -{ +typedef struct _lv_indev_proc_t { lv_indev_state_t state; /**< Current state of the input device. */ - union - { - struct - { /*Pointer and button data*/ + union { + struct { + /*Pointer and button data*/ lv_point_t act_point; /**< Current point of input device. */ lv_point_t last_point; /**< Last point of input device. */ lv_point_t vect; /**< Difference between `act_point` and `last_point`. */ @@ -145,16 +141,16 @@ typedef struct _lv_indev_proc_t other post-release event)*/ struct _lv_obj_t * last_pressed; /*The lastly pressed object*/ - lv_gesture_dir_t gesture_dir; - lv_point_t gesture_sum; /*Count the gesture pixels to check LV_INDEV_DEF_GESTURE_LIMIT*/ + lv_gesture_dir_t gesture_dir; + lv_point_t gesture_sum; /*Count the gesture pixels to check LV_INDEV_DEF_GESTURE_LIMIT*/ /*Flags*/ uint8_t drag_limit_out : 1; uint8_t drag_in_prog : 1; lv_drag_dir_t drag_dir : 3; - uint8_t gesture_sent : 1; + uint8_t gesture_sent : 1; } pointer; - struct - { /*Keypad data*/ + struct { + /*Keypad data*/ lv_indev_state_t last_state; uint32_t last_key; } keypad; @@ -175,8 +171,7 @@ struct _lv_group_t; /** The main input device descriptor with driver, runtime data ('proc') and some additional * information*/ -typedef struct _lv_indev_t -{ +typedef struct _lv_indev_t { lv_indev_drv_t driver; lv_indev_proc_t proc; struct _lv_obj_t * cursor; /**< Cursor for LV_INPUT_TYPE_POINTER*/ diff --git a/src/lv_hal/lv_hal_tick.c b/src/lv_hal/lv_hal_tick.c index 388cdf63c..a62ed7383 100644 --- a/src/lv_hal/lv_hal_tick.c +++ b/src/lv_hal/lv_hal_tick.c @@ -10,7 +10,7 @@ #include #if LV_TICK_CUSTOM == 1 -#include LV_TICK_CUSTOM_INCLUDE + #include LV_TICK_CUSTOM_INCLUDE #endif /********************* @@ -81,7 +81,8 @@ uint32_t lv_tick_elaps(uint32_t prev_tick) /*If there is no overflow in sys_time simple subtract*/ if(act_time >= prev_tick) { prev_tick = act_time - prev_tick; - } else { + } + else { prev_tick = UINT32_MAX - prev_tick + 1; prev_tick += act_time; } diff --git a/src/lv_misc/lv_anim.c b/src/lv_misc/lv_anim.c index 9ff85cf74..13ad39917 100644 --- a/src/lv_misc/lv_anim.c +++ b/src/lv_misc/lv_anim.c @@ -18,7 +18,7 @@ #include "lv_gc.h" #if defined(LV_GC_INCLUDE) -#include LV_GC_INCLUDE + #include LV_GC_INCLUDE #endif /* LV_ENABLE_GC */ /********************* @@ -62,8 +62,8 @@ void lv_anim_core_init(void) lv_ll_init(&LV_GC_ROOT(_lv_anim_ll), sizeof(lv_anim_t)); last_task_run = lv_tick_get(); _lv_anim_task = lv_task_create(anim_task, LV_DISP_DEF_REFR_PERIOD, LV_ANIM_TASK_PRIO, NULL); - anim_mark_list_change(); /*Turn off the animation task*/ - anim_list_changed = false; /*The list has not actaully changed*/ + anim_mark_list_change(); /*Turn off the animation task*/ + anim_list_changed = false; /*The list has not actaully changed*/ } /** @@ -117,7 +117,7 @@ void lv_anim_start(lv_anim_t * a) /* Creating an animation changed the linked list. * It's important if it happens in a ready callback. (see `anim_task`)*/ - anim_mark_list_change(); + anim_mark_list_change(); LV_LOG_TRACE("animation created") } @@ -195,7 +195,7 @@ uint16_t lv_anim_speed_to_time(uint16_t speed, lv_anim_value_t start, lv_anim_va */ void lv_anim_refr_now(void) { - anim_task(NULL); + anim_task(NULL); } /** @@ -209,7 +209,8 @@ lv_anim_value_t lv_anim_path_linear(const lv_anim_t * a) uint32_t step; if(a->time == a->act_time) { step = LV_ANIM_RESOLUTION; /*Use the last value if the time fully elapsed*/ - } else { + } + else { step = ((int32_t)a->act_time * LV_ANIM_RESOLUTION) / a->time; } @@ -344,24 +345,28 @@ lv_anim_value_t lv_anim_path_bounce(const lv_anim_t * a) if(t < 408) { /*Go down*/ t = (t * 2500) >> 10; /*[0..1024] range*/ - } else if(t >= 408 && t < 614) { + } + else if(t >= 408 && t < 614) { /*First bounce back*/ t -= 408; t = t * 5; /*to [0..1024] range*/ t = 1024 - t; diff = diff / 6; - } else if(t >= 614 && t < 819) { + } + else if(t >= 614 && t < 819) { /*Fall back*/ t -= 614; t = t * 5; /*to [0..1024] range*/ diff = diff / 6; - } else if(t >= 819 && t < 921) { + } + else if(t >= 819 && t < 921) { /*Second bounce back*/ t -= 819; t = t * 10; /*to [0..1024] range*/ t = 1024 - t; diff = diff / 16; - } else if(t >= 921 && t <= 1024) { + } + else if(t >= 921 && t <= 1024) { /*Fall back*/ t -= 921; t = t * 10; /*to [0..1024] range*/ @@ -407,8 +412,7 @@ static void anim_task(lv_task_t * param) (void)param; lv_anim_t * a; - LV_LL_READ(LV_GC_ROOT(_lv_anim_ll), a) - { + LV_LL_READ(LV_GC_ROOT(_lv_anim_ll), a) { a->has_run = 0; } @@ -483,8 +487,8 @@ static bool anim_ready_handler(lv_anim_t * a) memcpy(&a_tmp, a, sizeof(lv_anim_t)); lv_ll_remove(&LV_GC_ROOT(_lv_anim_ll), a); lv_mem_free(a); - /*Flag that the list has changed */ - anim_mark_list_change(); + /*Flag that the list has changed */ + anim_mark_list_change(); /* Call the callback function at the end*/ if(a_tmp.ready_cb != NULL) a_tmp.ready_cb(&a_tmp); @@ -513,10 +517,10 @@ static bool anim_ready_handler(lv_anim_t * a) } static void anim_mark_list_change(void) { - anim_list_changed = true; - if(lv_ll_get_head(&LV_GC_ROOT(_lv_anim_ll)) == NULL) - lv_task_set_prio(_lv_anim_task, LV_TASK_PRIO_OFF); - else - lv_task_set_prio(_lv_anim_task, LV_ANIM_TASK_PRIO); + anim_list_changed = true; + if(lv_ll_get_head(&LV_GC_ROOT(_lv_anim_ll)) == NULL) + lv_task_set_prio(_lv_anim_task, LV_TASK_PRIO_OFF); + else + lv_task_set_prio(_lv_anim_task, LV_ANIM_TASK_PRIO); } #endif diff --git a/src/lv_misc/lv_anim.h b/src/lv_misc/lv_anim.h index 6cded7485..6b45652da 100644 --- a/src/lv_misc/lv_anim.h +++ b/src/lv_misc/lv_anim.h @@ -66,8 +66,7 @@ typedef void (*lv_anim_ready_cb_t)(struct _lv_anim_t *); typedef void (*lv_anim_start_cb_t)(struct _lv_anim_t *); /** Describes an animation*/ -typedef struct _lv_anim_t -{ +typedef struct _lv_anim_t { void * var; /**act_time; + return -a->act_time; } /** diff --git a/src/lv_misc/lv_area.c b/src/lv_misc/lv_area.c index bd0016ca4..562124415 100644 --- a/src/lv_misc/lv_area.c +++ b/src/lv_misc/lv_area.c @@ -164,7 +164,7 @@ bool lv_area_is_point_on(const lv_area_t * a_p, const lv_point_t * p_p, lv_coord lv_coord_t max_radius = LV_MATH_MIN(lv_area_get_width(a_p) / 2, lv_area_get_height(a_p) / 2); if(radius > max_radius) radius = max_radius; - + /*Check if it's in one of the corners*/ lv_area_t corner_area; /*Top left*/ @@ -215,7 +215,8 @@ bool lv_area_is_on(const lv_area_t * a1_p, const lv_area_t * a2_p) { if((a1_p->x1 <= a2_p->x2) && (a1_p->x2 >= a2_p->x1) && (a1_p->y1 <= a2_p->y2) && (a1_p->y2 >= a2_p->y1)) { return true; - } else { + } + else { return false; } } @@ -284,108 +285,108 @@ void lv_area_align(const lv_area_t * base, const lv_area_t * to_align, lv_align_ { switch(align) { - case LV_ALIGN_CENTER: - res->x = lv_area_get_width(base) / 2 - lv_area_get_width(to_align) / 2; - res->y = lv_area_get_height(base) / 2 - lv_area_get_height(to_align) / 2; - break; + case LV_ALIGN_CENTER: + res->x = lv_area_get_width(base) / 2 - lv_area_get_width(to_align) / 2; + res->y = lv_area_get_height(base) / 2 - lv_area_get_height(to_align) / 2; + break; - case LV_ALIGN_IN_TOP_LEFT: - res->x = 0; - res->y = 0; - break; - case LV_ALIGN_IN_TOP_MID: - res->x = lv_area_get_width(base) / 2 - lv_area_get_width(to_align) / 2; - res->y = 0; - break; + case LV_ALIGN_IN_TOP_LEFT: + res->x = 0; + res->y = 0; + break; + case LV_ALIGN_IN_TOP_MID: + res->x = lv_area_get_width(base) / 2 - lv_area_get_width(to_align) / 2; + res->y = 0; + break; - case LV_ALIGN_IN_TOP_RIGHT: - res->x = lv_area_get_width(base) - lv_area_get_width(to_align); - res->y = 0; - break; + case LV_ALIGN_IN_TOP_RIGHT: + res->x = lv_area_get_width(base) - lv_area_get_width(to_align); + res->y = 0; + break; - case LV_ALIGN_IN_BOTTOM_LEFT: - res->x = 0; - res->y = lv_area_get_height(base) - lv_area_get_height(to_align); - break; - case LV_ALIGN_IN_BOTTOM_MID: - res->x = lv_area_get_width(base) / 2 - lv_area_get_width(to_align) / 2; - res->y = lv_area_get_height(base) - lv_area_get_height(to_align); - break; + case LV_ALIGN_IN_BOTTOM_LEFT: + res->x = 0; + res->y = lv_area_get_height(base) - lv_area_get_height(to_align); + break; + case LV_ALIGN_IN_BOTTOM_MID: + res->x = lv_area_get_width(base) / 2 - lv_area_get_width(to_align) / 2; + res->y = lv_area_get_height(base) - lv_area_get_height(to_align); + break; - case LV_ALIGN_IN_BOTTOM_RIGHT: - res->x = lv_area_get_width(base) - lv_area_get_width(to_align); - res->y = lv_area_get_height(base) - lv_area_get_height(to_align); - break; + case LV_ALIGN_IN_BOTTOM_RIGHT: + res->x = lv_area_get_width(base) - lv_area_get_width(to_align); + res->y = lv_area_get_height(base) - lv_area_get_height(to_align); + break; - case LV_ALIGN_IN_LEFT_MID: - res->x = 0; - res->y = lv_area_get_height(base) / 2 - lv_area_get_height(to_align) / 2; - break; + case LV_ALIGN_IN_LEFT_MID: + res->x = 0; + res->y = lv_area_get_height(base) / 2 - lv_area_get_height(to_align) / 2; + break; - case LV_ALIGN_IN_RIGHT_MID: - res->x = lv_area_get_width(base) - lv_area_get_width(to_align); - res->y = lv_area_get_height(base) / 2 - lv_area_get_height(to_align) / 2; - break; + case LV_ALIGN_IN_RIGHT_MID: + res->x = lv_area_get_width(base) - lv_area_get_width(to_align); + res->y = lv_area_get_height(base) / 2 - lv_area_get_height(to_align) / 2; + break; - case LV_ALIGN_OUT_TOP_LEFT: - res->x = 0; - res->y = -lv_area_get_height(to_align); - break; + case LV_ALIGN_OUT_TOP_LEFT: + res->x = 0; + res->y = -lv_area_get_height(to_align); + break; - case LV_ALIGN_OUT_TOP_MID: - res->x = lv_area_get_width(base) / 2 - lv_area_get_width(to_align) / 2; - res->y = -lv_area_get_height(to_align); - break; + case LV_ALIGN_OUT_TOP_MID: + res->x = lv_area_get_width(base) / 2 - lv_area_get_width(to_align) / 2; + res->y = -lv_area_get_height(to_align); + break; - case LV_ALIGN_OUT_TOP_RIGHT: - res->x = lv_area_get_width(base) - lv_area_get_width(to_align); - res->y = -lv_area_get_height(to_align); - break; + case LV_ALIGN_OUT_TOP_RIGHT: + res->x = lv_area_get_width(base) - lv_area_get_width(to_align); + res->y = -lv_area_get_height(to_align); + break; - case LV_ALIGN_OUT_BOTTOM_LEFT: - res->x = 0; - res->y = lv_area_get_height(base); - break; + case LV_ALIGN_OUT_BOTTOM_LEFT: + res->x = 0; + res->y = lv_area_get_height(base); + break; - case LV_ALIGN_OUT_BOTTOM_MID: - res->x = lv_area_get_width(base) / 2 - lv_area_get_width(to_align) / 2; - res->y = lv_area_get_height(base); - break; + case LV_ALIGN_OUT_BOTTOM_MID: + res->x = lv_area_get_width(base) / 2 - lv_area_get_width(to_align) / 2; + res->y = lv_area_get_height(base); + break; - case LV_ALIGN_OUT_BOTTOM_RIGHT: - res->x = lv_area_get_width(base) - lv_area_get_width(to_align); - res->y = lv_area_get_height(base); - break; + case LV_ALIGN_OUT_BOTTOM_RIGHT: + res->x = lv_area_get_width(base) - lv_area_get_width(to_align); + res->y = lv_area_get_height(base); + break; - case LV_ALIGN_OUT_LEFT_TOP: - res->x = -lv_area_get_width(to_align); - res->y = 0; - break; + case LV_ALIGN_OUT_LEFT_TOP: + res->x = -lv_area_get_width(to_align); + res->y = 0; + break; - case LV_ALIGN_OUT_LEFT_MID: - res->x = -lv_area_get_width(to_align); - res->y = lv_area_get_height(base) / 2 - lv_area_get_height(to_align) / 2; - break; + case LV_ALIGN_OUT_LEFT_MID: + res->x = -lv_area_get_width(to_align); + res->y = lv_area_get_height(base) / 2 - lv_area_get_height(to_align) / 2; + break; - case LV_ALIGN_OUT_LEFT_BOTTOM: - res->x = -lv_area_get_width(to_align); - res->y = lv_area_get_height(base) - lv_area_get_height(to_align); - break; + case LV_ALIGN_OUT_LEFT_BOTTOM: + res->x = -lv_area_get_width(to_align); + res->y = lv_area_get_height(base) - lv_area_get_height(to_align); + break; - case LV_ALIGN_OUT_RIGHT_TOP: - res->x = lv_area_get_width(base); - res->y = 0; - break; + case LV_ALIGN_OUT_RIGHT_TOP: + res->x = lv_area_get_width(base); + res->y = 0; + break; - case LV_ALIGN_OUT_RIGHT_MID: - res->x = lv_area_get_width(base); - res->y = lv_area_get_height(base) / 2 - lv_area_get_height(to_align) / 2; - break; + case LV_ALIGN_OUT_RIGHT_MID: + res->x = lv_area_get_width(base); + res->y = lv_area_get_height(base) / 2 - lv_area_get_height(to_align) / 2; + break; - case LV_ALIGN_OUT_RIGHT_BOTTOM: - res->x = lv_area_get_width(base); - res->y = lv_area_get_height(base) - lv_area_get_height(to_align); - break; + case LV_ALIGN_OUT_RIGHT_BOTTOM: + res->x = lv_area_get_width(base); + res->y = lv_area_get_height(base) - lv_area_get_height(to_align); + break; } res->x += base->x1; @@ -403,14 +404,14 @@ static bool lv_point_within_circle(const lv_area_t * area, const lv_point_t * p) /* Circle center */ lv_coord_t cx = area->x1 + r; lv_coord_t cy = area->y1 + r; - + /*Simplify the code by moving everything to (0, 0) */ lv_coord_t px = p->x - cx; lv_coord_t py = p->y - cy; - int32_t r_sqrd = r*r; - int32_t dist = (px*px) + (py*py); - + int32_t r_sqrd = r * r; + int32_t dist = (px * px) + (py * py); + if(dist <= r_sqrd) return true; else diff --git a/src/lv_misc/lv_area.h b/src/lv_misc/lv_area.h index cbffed0c7..aa6de6fa6 100644 --- a/src/lv_misc/lv_area.h +++ b/src/lv_misc/lv_area.h @@ -35,15 +35,13 @@ LV_EXPORT_CONST_INT(LV_COORD_MIN); /** * Represents a point on the screen. */ -typedef struct -{ +typedef struct { lv_coord_t x; lv_coord_t y; } lv_point_t; /** Represents an area of the screen. */ -typedef struct -{ +typedef struct { lv_coord_t x1; lv_coord_t y1; lv_coord_t x2; diff --git a/src/lv_misc/lv_async.c b/src/lv_misc/lv_async.c index 2a836432b..4d6e7b095 100644 --- a/src/lv_misc/lv_async.c +++ b/src/lv_misc/lv_async.c @@ -21,7 +21,7 @@ * STATIC PROTOTYPES **********************/ -static void lv_async_task_cb(lv_task_t *task); +static void lv_async_task_cb(lv_task_t * task); /********************** * STATIC VARIABLES @@ -38,20 +38,20 @@ static void lv_async_task_cb(lv_task_t *task); lv_res_t lv_async_call(lv_async_cb_t async_xcb, void * user_data) { /*Allocate an info structure */ - lv_async_info_t *info = lv_mem_alloc(sizeof(lv_async_info_t)); - + lv_async_info_t * info = lv_mem_alloc(sizeof(lv_async_info_t)); + if(info == NULL) return LV_RES_INV; - + /* Create a new task */ /* Use highest priority so that it will run before a refresh */ - lv_task_t *task = lv_task_create(lv_async_task_cb, 0, LV_TASK_PRIO_HIGHEST, info); - + lv_task_t * task = lv_task_create(lv_async_task_cb, 0, LV_TASK_PRIO_HIGHEST, info); + if(task == NULL) { lv_mem_free(info); return LV_RES_INV; } - + info->cb = async_xcb; info->user_data = user_data; @@ -65,11 +65,11 @@ lv_res_t lv_async_call(lv_async_cb_t async_xcb, void * user_data) * STATIC FUNCTIONS **********************/ -static void lv_async_task_cb(lv_task_t *task) +static void lv_async_task_cb(lv_task_t * task) { - lv_async_info_t *info = (lv_async_info_t *)task->user_data; - + lv_async_info_t * info = (lv_async_info_t *)task->user_data; + info->cb(info->user_data); - + lv_mem_free(info); } diff --git a/src/lv_misc/lv_async.h b/src/lv_misc/lv_async.h index 9423cd8ec..10d9610fe 100644 --- a/src/lv_misc/lv_async.h +++ b/src/lv_misc/lv_async.h @@ -32,7 +32,7 @@ typedef void (*lv_async_cb_t)(void *); typedef struct _lv_async_info_t { lv_async_cb_t cb; - void *user_data; + void * user_data; } lv_async_info_t; struct _lv_obj_t; diff --git a/src/lv_misc/lv_bidi.c b/src/lv_misc/lv_bidi.c index 8dbc1c9a8..4b959f8a5 100644 --- a/src/lv_misc/lv_bidi.c +++ b/src/lv_misc/lv_bidi.c @@ -26,19 +26,21 @@ /********************** * TYPEDEFS **********************/ -typedef struct -{ +typedef struct { uint32_t bracklet_pos; lv_bidi_dir_t dir; -}bracket_stack_t; +} bracket_stack_t; /********************** * STATIC PROTOTYPES **********************/ -static lv_bidi_dir_t get_next_run(const char * txt, lv_bidi_dir_t base_dir, uint32_t max_len, uint32_t * len, uint16_t * pos_conv_len); -static void rtl_reverse(char * dest, const char * src, uint32_t len, uint16_t *pos_conv_out, uint16_t pos_conv_rd_base, uint16_t pos_conv_len); +static lv_bidi_dir_t get_next_run(const char * txt, lv_bidi_dir_t base_dir, uint32_t max_len, uint32_t * len, + uint16_t * pos_conv_len); +static void rtl_reverse(char * dest, const char * src, uint32_t len, uint16_t * pos_conv_out, uint16_t pos_conv_rd_base, + uint16_t pos_conv_len); static uint32_t char_change_to_pair(uint32_t letter); -static lv_bidi_dir_t bracket_process(const char * txt, uint32_t next_pos, uint32_t len, uint32_t letter, lv_bidi_dir_t base_dir); +static lv_bidi_dir_t bracket_process(const char * txt, uint32_t next_pos, uint32_t len, uint32_t letter, + lv_bidi_dir_t base_dir); static void fill_pos_conv(uint16_t * out, uint16_t len, uint16_t index); static uint32_t get_txt_len(const char * txt, uint32_t max_len); @@ -151,7 +153,7 @@ bool lv_bidi_letter_is_weak(uint32_t letter) */ bool lv_bidi_letter_is_rtl(uint32_t letter) { - if(letter >= 0x5d0 && letter <= 0x5ea) return true; + if(letter >= 0x5d0 && letter <= 0x5ea) return true; if(letter == 0x202E) return true; /*Unicode of LV_BIDI_RLO*/ return false; @@ -185,23 +187,24 @@ bool lv_bidi_letter_is_neutral(uint32_t letter) * @param is_rtl tell the the char at `viasual_pos` is RTL or LTR context * @return the logical character position */ -uint16_t lv_bidi_get_logical_pos(const char * str_in, char **bidi_txt, uint32_t len, lv_bidi_dir_t base_dir, uint32_t visual_pos, bool *is_rtl) +uint16_t lv_bidi_get_logical_pos(const char * str_in, char ** bidi_txt, uint32_t len, lv_bidi_dir_t base_dir, + uint32_t visual_pos, bool * is_rtl) { uint32_t pos_conv_len = get_txt_len(str_in, len); char * buf = lv_mem_buf_get(len + 1); if(buf == NULL) return (uint16_t) -1; - uint16_t *pos_conv_buf = lv_mem_buf_get(pos_conv_len * sizeof(uint16_t)); + uint16_t * pos_conv_buf = lv_mem_buf_get(pos_conv_len * sizeof(uint16_t)); if(pos_conv_buf == NULL) { lv_mem_buf_release(buf); return (uint16_t) -1; } - if (bidi_txt) *bidi_txt = buf; + if(bidi_txt) *bidi_txt = buf; - lv_bidi_process_paragraph(str_in, bidi_txt? *bidi_txt: NULL, len, base_dir, pos_conv_buf, pos_conv_len); + lv_bidi_process_paragraph(str_in, bidi_txt ? *bidi_txt : NULL, len, base_dir, pos_conv_buf, pos_conv_len); - if (is_rtl) *is_rtl = IS_RTL_POS(pos_conv_buf[visual_pos]); + if(is_rtl) *is_rtl = IS_RTL_POS(pos_conv_buf[visual_pos]); if(bidi_txt == NULL) lv_mem_buf_release(buf); uint16_t res = GET_POS(pos_conv_buf[visual_pos]); @@ -221,26 +224,27 @@ uint16_t lv_bidi_get_logical_pos(const char * str_in, char **bidi_txt, uint32_t * @param is_rtl tell the the char at `logical_pos` is RTL or LTR context * @return the visual character position */ -uint16_t lv_bidi_get_visual_pos(const char * str_in, char **bidi_txt, uint16_t len, lv_bidi_dir_t base_dir, uint32_t logical_pos, bool *is_rtl) +uint16_t lv_bidi_get_visual_pos(const char * str_in, char ** bidi_txt, uint16_t len, lv_bidi_dir_t base_dir, + uint32_t logical_pos, bool * is_rtl) { uint32_t pos_conv_len = get_txt_len(str_in, len); char * buf = lv_mem_buf_get(len + 1); if(buf == NULL) return (uint16_t) -1; - uint16_t *pos_conv_buf = lv_mem_buf_get(pos_conv_len * sizeof(uint16_t)); + uint16_t * pos_conv_buf = lv_mem_buf_get(pos_conv_len * sizeof(uint16_t)); if(pos_conv_buf == NULL) { lv_mem_buf_release(buf); return (uint16_t) -1; } - if (bidi_txt) *bidi_txt = buf; + if(bidi_txt) *bidi_txt = buf; - lv_bidi_process_paragraph(str_in, bidi_txt ? *bidi_txt: NULL, len, base_dir, pos_conv_buf, pos_conv_len); + lv_bidi_process_paragraph(str_in, bidi_txt ? *bidi_txt : NULL, len, base_dir, pos_conv_buf, pos_conv_len); - for (uint16_t i = 0; i < pos_conv_len; i++){ - if (GET_POS(pos_conv_buf[i]) == logical_pos){ + for(uint16_t i = 0; i < pos_conv_len; i++) { + if(GET_POS(pos_conv_buf[i]) == logical_pos) { - if (is_rtl) *is_rtl = IS_RTL_POS(pos_conv_buf[i]); + if(is_rtl) *is_rtl = IS_RTL_POS(pos_conv_buf[i]); lv_mem_buf_release(pos_conv_buf); if(bidi_txt == NULL) lv_mem_buf_release(buf); @@ -262,7 +266,8 @@ uint16_t lv_bidi_get_visual_pos(const char * str_in, char **bidi_txt, uint16_t l * Can be `NULL` is unused * @param pos_conv_len length of `pos_conv_out` in element count */ -void lv_bidi_process_paragraph(const char * str_in, char * str_out, uint32_t len, lv_bidi_dir_t base_dir, uint16_t *pos_conv_out, uint16_t pos_conv_len) +void lv_bidi_process_paragraph(const char * str_in, char * str_out, uint32_t len, lv_bidi_dir_t base_dir, + uint16_t * pos_conv_out, uint16_t pos_conv_len) { uint32_t run_len = 0; lv_bidi_dir_t run_dir; @@ -282,7 +287,7 @@ void lv_bidi_process_paragraph(const char * str_in, char * str_out, uint32_t len pos_conv_wr = 0; } - if (str_out) str_out[len] = '\0'; + if(str_out) str_out[len] = '\0'; lv_bidi_dir_t dir = base_dir; @@ -299,24 +304,26 @@ void lv_bidi_process_paragraph(const char * str_in, char * str_out, uint32_t len } if(rd && str_in[rd] != '\0') { - lv_txt_encoded_prev(str_in, &rd); - pos_conv_rd--; + lv_txt_encoded_prev(str_in, &rd); + pos_conv_rd--; } if(rd) { if(base_dir == LV_BIDI_DIR_LTR) { - if (str_out) { + if(str_out) { memcpy(&str_out[wr], str_in, rd); wr += rd; } - if (pos_conv_out) { + if(pos_conv_out) { fill_pos_conv(&pos_conv_out[pos_conv_wr], pos_conv_rd, 0); pos_conv_wr += pos_conv_rd; } - } else { + } + else { wr -= rd; pos_conv_wr -= pos_conv_rd; - rtl_reverse(str_out? &str_out[wr]: NULL, str_in, rd, pos_conv_out? &pos_conv_out[pos_conv_wr]: NULL, 0, pos_conv_rd); + rtl_reverse(str_out ? &str_out[wr] : NULL, str_in, rd, pos_conv_out ? &pos_conv_out[pos_conv_wr] : NULL, 0, + pos_conv_rd); } } @@ -327,21 +334,24 @@ void lv_bidi_process_paragraph(const char * str_in, char * str_out, uint32_t len if(base_dir == LV_BIDI_DIR_LTR) { if(run_dir == LV_BIDI_DIR_LTR) { - if (str_out) memcpy(&str_out[wr], &str_in[rd], run_len); - if (pos_conv_out) fill_pos_conv(&pos_conv_out[pos_conv_wr], pos_conv_run_len, pos_conv_rd); + if(str_out) memcpy(&str_out[wr], &str_in[rd], run_len); + if(pos_conv_out) fill_pos_conv(&pos_conv_out[pos_conv_wr], pos_conv_run_len, pos_conv_rd); } - else rtl_reverse(str_out? &str_out[wr]: NULL, &str_in[rd], run_len, pos_conv_out? &pos_conv_out[pos_conv_wr] : NULL, pos_conv_rd, pos_conv_run_len); - wr += run_len; - pos_conv_wr += pos_conv_run_len; - } else { - wr -= run_len; - pos_conv_wr -= pos_conv_run_len; - if(run_dir == LV_BIDI_DIR_LTR) { - if (str_out) memcpy(&str_out[wr], &str_in[rd], run_len); - if (pos_conv_out) fill_pos_conv(&pos_conv_out[pos_conv_wr], pos_conv_run_len, pos_conv_rd); - } - else rtl_reverse(str_out? &str_out[wr]: NULL, &str_in[rd], run_len, pos_conv_out? &pos_conv_out[pos_conv_wr] : NULL, pos_conv_rd, pos_conv_run_len); - } + else rtl_reverse(str_out ? &str_out[wr] : NULL, &str_in[rd], run_len, pos_conv_out ? &pos_conv_out[pos_conv_wr] : NULL, + pos_conv_rd, pos_conv_run_len); + wr += run_len; + pos_conv_wr += pos_conv_run_len; + } + else { + wr -= run_len; + pos_conv_wr -= pos_conv_run_len; + if(run_dir == LV_BIDI_DIR_LTR) { + if(str_out) memcpy(&str_out[wr], &str_in[rd], run_len); + if(pos_conv_out) fill_pos_conv(&pos_conv_out[pos_conv_wr], pos_conv_run_len, pos_conv_rd); + } + else rtl_reverse(str_out ? &str_out[wr] : NULL, &str_in[rd], run_len, pos_conv_out ? &pos_conv_out[pos_conv_wr] : NULL, + pos_conv_rd, pos_conv_run_len); + } rd += run_len; pos_conv_rd += pos_conv_run_len; @@ -386,13 +396,14 @@ static uint32_t get_txt_len(const char * txt, uint32_t max_len) static void fill_pos_conv(uint16_t * out, uint16_t len, uint16_t index) { uint16_t i; - for (i = 0; i < len; i++) { + for(i = 0; i < len; i++) { out[i] = SET_RTL_POS(index, false); index++; } -} +} -static lv_bidi_dir_t get_next_run(const char * txt, lv_bidi_dir_t base_dir, uint32_t max_len, uint32_t * len, uint16_t * pos_conv_len) +static lv_bidi_dir_t get_next_run(const char * txt, lv_bidi_dir_t base_dir, uint32_t max_len, uint32_t * len, + uint16_t * pos_conv_len) { uint32_t i = 0; uint32_t letter; @@ -473,7 +484,8 @@ static lv_bidi_dir_t get_next_run(const char * txt, lv_bidi_dir_t base_dir, uint return run_dir; } -static void rtl_reverse(char * dest, const char * src, uint32_t len, uint16_t *pos_conv_out, uint16_t pos_conv_rd_base, uint16_t pos_conv_len) +static void rtl_reverse(char * dest, const char * src, uint32_t len, uint16_t * pos_conv_out, uint16_t pos_conv_rd_base, + uint16_t pos_conv_len) { uint32_t i = len; uint32_t wr = 0; @@ -498,7 +510,7 @@ static void rtl_reverse(char * dest, const char * src, uint32_t len, uint16_t *p /*Finish on non-weak char */ /*but treat number and currency related chars as weak*/ - if (lv_bidi_letter_is_weak(letter) == false && letter != '.' && letter != ',' && letter != '$' && letter != '%') { + if(lv_bidi_letter_is_weak(letter) == false && letter != '.' && letter != ',' && letter != '$' && letter != '%') { lv_txt_encoded_next(src, &i); /*Rewind one letter*/ pos_conv_i++; first_weak = i; @@ -511,8 +523,9 @@ static void rtl_reverse(char * dest, const char * src, uint32_t len, uint16_t *p pos_conv_first_weak = 0; } - if (dest) memcpy(&dest[wr], &src[first_weak], last_weak - first_weak + 1); - if (pos_conv_out) fill_pos_conv(&pos_conv_out[pos_conv_wr], pos_conv_last_weak - pos_conv_first_weak + 1, pos_conv_rd_base + pos_conv_first_weak); + if(dest) memcpy(&dest[wr], &src[first_weak], last_weak - first_weak + 1); + if(pos_conv_out) fill_pos_conv(&pos_conv_out[pos_conv_wr], pos_conv_last_weak - pos_conv_first_weak + 1, + pos_conv_rd_base + pos_conv_first_weak); wr += last_weak - first_weak + 1; pos_conv_wr += pos_conv_last_weak - pos_conv_first_weak + 1; } @@ -523,15 +536,15 @@ static void rtl_reverse(char * dest, const char * src, uint32_t len, uint16_t *p /*Swap arithmetical symbols*/ if(letter_size == 1) { uint32_t new_letter = letter = char_change_to_pair(letter); - if (dest) dest[wr] = (uint8_t)new_letter; - if (pos_conv_out) pos_conv_out[pos_conv_wr] = SET_RTL_POS(pos_conv_rd_base + pos_conv_letter, true); + if(dest) dest[wr] = (uint8_t)new_letter; + if(pos_conv_out) pos_conv_out[pos_conv_wr] = SET_RTL_POS(pos_conv_rd_base + pos_conv_letter, true); wr++; pos_conv_wr++; } /*Just store the letter*/ else { - if (dest) memcpy(&dest[wr], &src[i], letter_size); - if (pos_conv_out) pos_conv_out[pos_conv_wr] = SET_RTL_POS(pos_conv_rd_base + pos_conv_i, true); + if(dest) memcpy(&dest[wr], &src[i], letter_size); + if(pos_conv_out) pos_conv_out[pos_conv_wr] = SET_RTL_POS(pos_conv_rd_base + pos_conv_i, true); wr += letter_size; pos_conv_wr++; } @@ -554,7 +567,8 @@ static uint32_t char_change_to_pair(uint32_t letter) return letter; } -static lv_bidi_dir_t bracket_process(const char * txt, uint32_t next_pos, uint32_t len, uint32_t letter, lv_bidi_dir_t base_dir) +static lv_bidi_dir_t bracket_process(const char * txt, uint32_t next_pos, uint32_t len, uint32_t letter, + lv_bidi_dir_t base_dir) { lv_bidi_dir_t bracket_dir = LV_BIDI_DIR_NEUTRAL; @@ -570,7 +584,8 @@ static lv_bidi_dir_t bracket_process(const char * txt, uint32_t next_pos, uint32 if(letter_next == bracket_right[i]) { /*Closing bracket found*/ break; - } else { + } + else { /*Save the dir*/ lv_bidi_dir_t letter_dir = lv_bidi_get_letter_dir(letter_next); if(letter_dir == base_dir) { @@ -619,7 +634,8 @@ static lv_bidi_dir_t bracket_process(const char * txt, uint32_t next_pos, uint32 br_stack_p++; return bracket_dir; - } else if(br_stack_p > 0) { + } + else if(br_stack_p > 0) { /*Is the letter a closing bracket of the last opening?*/ if(letter == bracket_right[br_stack[br_stack_p - 1].bracklet_pos]) { bracket_dir = br_stack[br_stack_p - 1].dir; diff --git a/src/lv_misc/lv_bidi.h b/src/lv_misc/lv_bidi.h index dd9bd2bb6..c6df56c0a 100644 --- a/src/lv_misc/lv_bidi.h +++ b/src/lv_misc/lv_bidi.h @@ -29,8 +29,7 @@ extern "C" { /********************** * TYPEDEFS **********************/ -enum -{ +enum { /*The first 4 values are stored in `lv_obj_t` on 2 bits*/ LV_BIDI_DIR_LTR = 0x00, LV_BIDI_DIR_RTL = 0x01, @@ -104,7 +103,8 @@ bool lv_bidi_letter_is_neutral(uint32_t letter); * @param is_rtl tell the the char at `viasual_pos` is RTL or LTR context * @return the logical character position */ -uint16_t lv_bidi_get_logical_pos(const char * str_in, char **bidi_txt, uint32_t len, lv_bidi_dir_t base_dir, uint32_t visual_pos, bool *is_rtl); +uint16_t lv_bidi_get_logical_pos(const char * str_in, char ** bidi_txt, uint32_t len, lv_bidi_dir_t base_dir, + uint32_t visual_pos, bool * is_rtl); /** * Get the visual position of a character in a line @@ -118,7 +118,8 @@ uint16_t lv_bidi_get_logical_pos(const char * str_in, char **bidi_txt, uint32_t * @param is_rtl tell the the char at `logical_pos` is RTL or LTR context * @return the visual character position */ -uint16_t lv_bidi_get_visual_pos(const char * str_in, char **bidi_txt, uint16_t len, lv_bidi_dir_t base_dir, uint32_t logical_pos, bool *is_rtl); +uint16_t lv_bidi_get_visual_pos(const char * str_in, char ** bidi_txt, uint16_t len, lv_bidi_dir_t base_dir, + uint32_t logical_pos, bool * is_rtl); /** * Bidi process a paragraph of text @@ -130,7 +131,8 @@ uint16_t lv_bidi_get_visual_pos(const char * str_in, char **bidi_txt, uint16_t l * Can be `NULL` is unused * @param pos_conv_len length of `pos_conv_out` in element count */ -void lv_bidi_process_paragraph(const char * str_in, char * str_out, uint32_t len, lv_bidi_dir_t base_dir, uint16_t *pos_conv_out, uint16_t pos_conv_len); +void lv_bidi_process_paragraph(const char * str_in, char * str_out, uint32_t len, lv_bidi_dir_t base_dir, + uint16_t * pos_conv_out, uint16_t pos_conv_len); /** * Get the next paragraph from a text diff --git a/src/lv_misc/lv_circ.c b/src/lv_misc/lv_circ.c index fc0e3e202..4132a98e6 100644 --- a/src/lv_misc/lv_circ.c +++ b/src/lv_misc/lv_circ.c @@ -68,7 +68,8 @@ void lv_circ_next(lv_point_t * c, lv_coord_t * tmp) if(*tmp <= 0) { (*tmp) += 2 * c->y + 1; /*Change in decision criterion for y -> y+1*/ - } else { + } + else { c->x--; (*tmp) += 2 * (c->y - c->x) + 1; /*Change for y -> y+1, x -> x-1*/ } diff --git a/src/lv_misc/lv_color.c b/src/lv_misc/lv_color.c index dfe711e12..57551c597 100644 --- a/src/lv_misc/lv_color.c +++ b/src/lv_misc/lv_color.c @@ -138,7 +138,7 @@ lv_color_hsv_t lv_color_rgb_to_hsv(uint8_t r8, uint8_t g8, uint8_t b8) hsv.v = (100 * rgbMax) >> 10; int32_t delta = rgbMax - rgbMin; - if (LV_MATH_ABS(delta) < 3) { + if(LV_MATH_ABS(delta) < 3) { hsv.h = 0; hsv.s = 0; return hsv; @@ -163,7 +163,7 @@ lv_color_hsv_t lv_color_rgb_to_hsv(uint8_t r8, uint8_t g8, uint8_t b8) h = 0; h *= 60; h >>= 10; - if (h < 0) h += 360; + if(h < 0) h += 360; hsv.h = h; return hsv; diff --git a/src/lv_misc/lv_color.h b/src/lv_misc/lv_color.h index b045ce568..5a6b1173a 100644 --- a/src/lv_misc/lv_color.h +++ b/src/lv_misc/lv_color.h @@ -194,10 +194,8 @@ enum { * TYPEDEFS **********************/ -typedef union -{ - struct - { +typedef union { + struct { uint8_t blue : 1; uint8_t green : 1; uint8_t red : 1; @@ -205,10 +203,8 @@ typedef union uint8_t full; } lv_color1_t; -typedef union -{ - struct - { +typedef union { + struct { uint8_t blue : 2; uint8_t green : 3; uint8_t red : 3; @@ -216,10 +212,8 @@ typedef union uint8_t full; } lv_color8_t; -typedef union -{ - struct - { +typedef union { + struct { #if LV_COLOR_16_SWAP == 0 uint16_t blue : 5; uint16_t green : 6; @@ -234,10 +228,8 @@ typedef union uint16_t full; } lv_color16_t; -typedef union -{ - struct - { +typedef union { + struct { uint8_t blue; uint8_t green; uint8_t red; @@ -264,8 +256,7 @@ typedef lv_color32_t lv_color_t; typedef uint8_t lv_opa_t; -typedef struct -{ +typedef struct { uint16_t h; uint8_t s; uint8_t v; @@ -296,19 +287,22 @@ static inline uint8_t lv_color_to1(lv_color_t color) #elif LV_COLOR_DEPTH == 8 if((LV_COLOR_GET_R(color) & 0x4) || (LV_COLOR_GET_G(color) & 0x4) || (LV_COLOR_GET_B(color) & 0x2)) { return 1; - } else { + } + else { return 0; } #elif LV_COLOR_DEPTH == 16 if((LV_COLOR_GET_R(color) & 0x10) || (LV_COLOR_GET_G(color) & 0x20) || (LV_COLOR_GET_B(color) & 0x10)) { return 1; - } else { + } + else { return 0; } #elif LV_COLOR_DEPTH == 32 if((LV_COLOR_GET_R(color) & 0x80) || (LV_COLOR_GET_G(color) & 0x80) || (LV_COLOR_GET_B(color) & 0x80)) { return 1; - } else { + } + else { return 0; } #endif @@ -368,7 +362,7 @@ static inline uint16_t lv_color_to16(lv_color_t color) #endif LV_COLOR_SET_B16(ret, LV_COLOR_GET_B(color) >> 3); /* 8 - 5 = 3*/ return ret.full; -#endif +#endif } static inline uint32_t lv_color_to32(lv_color_t color) @@ -392,9 +386,9 @@ static inline uint32_t lv_color_to32(lv_color_t color) * The faster integer math for conversion is: * valueto = ( valuefrom * multiplier + adder ) >> divisor * multiplier = FLOOR( ( (2^bitsto - 1) << divisor ) / (float)(2^bitsfrom - 1) ) - * + * * Find the first divisor where ( adder >> divisor ) <= 0 - * + * * 5-bit to 8-bit: ( 31 * multiplier + adder ) >> divisor = 255 * divisor multiplier adder min (0) max (31) * 0 8 7 7 255 @@ -403,7 +397,7 @@ static inline uint32_t lv_color_to32(lv_color_t color) * 3 65 25 3 255 * 4 131 19 1 255 * 5 263 7 0 255 - * + * * 6-bit to 8-bit: 255 = ( 63 * multiplier + adder ) >> divisor * divisor multiplier adder min (0) max (63) * 0 4 3 3 255 @@ -415,9 +409,9 @@ static inline uint32_t lv_color_to32(lv_color_t color) * 6 259 3 0 255 */ lv_color32_t ret; - LV_COLOR_SET_R32(ret, (LV_COLOR_GET_R(color) * 263 + 7 ) >> 5); - LV_COLOR_SET_G32(ret, (LV_COLOR_GET_G(color) * 259 + 3 ) >> 6); - LV_COLOR_SET_B32(ret, (LV_COLOR_GET_B(color) * 263 + 7 ) >> 5); + LV_COLOR_SET_R32(ret, (LV_COLOR_GET_R(color) * 263 + 7) >> 5); + LV_COLOR_SET_G32(ret, (LV_COLOR_GET_G(color) * 259 + 3) >> 6); + LV_COLOR_SET_B32(ret, (LV_COLOR_GET_B(color) * 263 + 7) >> 5); LV_COLOR_SET_A32(ret, 0xFF); return ret.full; #elif LV_COLOR_DEPTH == 32 @@ -459,7 +453,8 @@ static inline lv_color_t lv_color_mix(lv_color_t c1, lv_color_t c2, uint8_t mix) * @param res_color the result color * @param res_opa the result opacity */ -static inline void lv_color_mix_with_alpha(lv_color_t bg_color, lv_opa_t bg_opa, lv_color_t fg_color, lv_opa_t fg_opa, lv_color_t * res_color, lv_opa_t * res_opa) +static inline void lv_color_mix_with_alpha(lv_color_t bg_color, lv_opa_t bg_opa, lv_color_t fg_color, lv_opa_t fg_opa, + lv_color_t * res_color, lv_opa_t * res_opa) { /* Pick the foreground if it's fully opaque or the Background is fully transparent*/ if(fg_opa > LV_OPA_MAX || bg_opa <= LV_OPA_MIN) { @@ -487,7 +482,7 @@ static inline void lv_color_mix_with_alpha(lv_color_t bg_color, lv_opa_t bg_opa, static lv_opa_t res_opa_saved = 0; if(fg_opa != fg_opa_save || bg_opa != bg_opa_save || fg_color.full != fg_color_save.full || - bg_color.full != bg_color_save.full) { + bg_color.full != bg_color_save.full) { fg_opa_save = fg_opa; bg_opa_save = bg_opa; fg_color_save.full = fg_color.full; diff --git a/src/lv_misc/lv_fs.c b/src/lv_misc/lv_fs.c index dff796a0f..7a156a638 100644 --- a/src/lv_misc/lv_fs.c +++ b/src/lv_misc/lv_fs.c @@ -15,7 +15,7 @@ #include "lv_gc.h" #if defined(LV_GC_INCLUDE) -#include LV_GC_INCLUDE + #include LV_GC_INCLUDE #endif /* LV_ENABLE_GC */ /********************* @@ -27,7 +27,7 @@ * free function, otherwise compilation would fail. */ #ifdef free -#undef free + #undef free #endif /********************** @@ -422,7 +422,8 @@ lv_fs_res_t lv_fs_dir_close(lv_fs_dir_t * rddir_p) if(rddir_p->drv->dir_close_cb == NULL) { res = LV_FS_RES_NOT_IMP; - } else { + } + else { res = rddir_p->drv->dir_close_cb(rddir_p->drv, rddir_p->dir_d); } @@ -453,7 +454,8 @@ lv_fs_res_t lv_fs_free_space(char letter, uint32_t * total_p, uint32_t * free_p) if(drv->free_space_cb == NULL) { res = LV_FS_RES_NOT_IMP; - } else { + } + else { uint32_t total_tmp = 0; uint32_t free_tmp = 0; res = drv->free_space_cb(drv, &total_tmp, &free_tmp); @@ -501,8 +503,7 @@ lv_fs_drv_t * lv_fs_get_drv(char letter) { lv_fs_drv_t * drv; - LV_LL_READ(LV_GC_ROOT(_lv_drv_ll), drv) - { + LV_LL_READ(LV_GC_ROOT(_lv_drv_ll), drv) { if(drv->letter == letter) { return drv; } @@ -520,8 +521,7 @@ char * lv_fs_get_letters(char * buf) lv_fs_drv_t * drv; uint8_t i = 0; - LV_LL_READ(LV_GC_ROOT(_lv_drv_ll), drv) - { + LV_LL_READ(LV_GC_ROOT(_lv_drv_ll), drv) { buf[i] = drv->letter; i++; } @@ -542,7 +542,8 @@ const char * lv_fs_get_ext(const char * fn) for(i = strlen(fn); i > 0; i--) { if(fn[i] == '.') { return &fn[i + 1]; - } else if(fn[i] == '/' || fn[i] == '\\') { + } + else if(fn[i] == '/' || fn[i] == '\\') { return ""; /*No extension if a '\' or '/' found*/ } } @@ -630,7 +631,8 @@ static const char * lv_fs_get_real_path(const char * path) while(*path != '\0') { if(*path == ':' || *path == '\\' || *path == '/') { path++; - } else { + } + else { break; } } diff --git a/src/lv_misc/lv_fs.h b/src/lv_misc/lv_fs.h index 9731458dd..daa7e59c7 100644 --- a/src/lv_misc/lv_fs.h +++ b/src/lv_misc/lv_fs.h @@ -60,8 +60,7 @@ enum { }; typedef uint8_t lv_fs_mode_t; -typedef struct _lv_fs_drv_t -{ +typedef struct _lv_fs_drv_t { char letter; uint16_t file_size; uint16_t rddir_size; @@ -88,14 +87,12 @@ typedef struct _lv_fs_drv_t #endif } lv_fs_drv_t; -typedef struct -{ +typedef struct { void * file_d; lv_fs_drv_t * drv; } lv_fs_file_t; -typedef struct -{ +typedef struct { void * dir_d; lv_fs_drv_t * drv; } lv_fs_dir_t; diff --git a/src/lv_misc/lv_gc.c b/src/lv_misc/lv_gc.c index ed4d0676e..0d568ec4a 100644 --- a/src/lv_misc/lv_gc.c +++ b/src/lv_misc/lv_gc.c @@ -11,7 +11,7 @@ #include "string.h" #if defined(LV_GC_INCLUDE) -#include LV_GC_INCLUDE + #include LV_GC_INCLUDE #endif /* LV_ENABLE_GC */ /********************* @@ -31,7 +31,7 @@ **********************/ #if(!defined(LV_ENABLE_GC)) || LV_ENABLE_GC == 0 -LV_ROOTS + LV_ROOTS #endif /* LV_ENABLE_GC */ /********************** diff --git a/src/lv_misc/lv_ll.c b/src/lv_misc/lv_ll.c index a4f0acba4..c53afe713 100644 --- a/src/lv_misc/lv_ll.c +++ b/src/lv_misc/lv_ll.c @@ -111,7 +111,8 @@ void * lv_ll_ins_prev(lv_ll_t * ll_p, void * n_act) if(lv_ll_get_head(ll_p) == n_act) { n_new = lv_ll_ins_head(ll_p); if(n_new == NULL) return NULL; - } else { + } + else { n_new = lv_mem_alloc(ll_p->n_size + LL_NODE_META_SIZE); if(n_new == NULL) return NULL; @@ -166,18 +167,22 @@ void lv_ll_remove(lv_ll_t * ll_p, void * node_p) ll_p->head = lv_ll_get_next(ll_p, node_p); if(ll_p->head == NULL) { ll_p->tail = NULL; - } else { + } + else { node_set_prev(ll_p, ll_p->head, NULL); } - } else if(lv_ll_get_tail(ll_p) == node_p) { + } + else if(lv_ll_get_tail(ll_p) == node_p) { /*The new tail will be the node before 'n_act'*/ ll_p->tail = lv_ll_get_prev(ll_p, node_p); if(ll_p->tail == NULL) { ll_p->head = NULL; - } else { + } + else { node_set_next(ll_p, ll_p->tail, NULL); } - } else { + } + else { lv_ll_node_t * n_prev = lv_ll_get_prev(ll_p, node_p); lv_ll_node_t * n_next = lv_ll_get_next(ll_p, node_p); @@ -233,7 +238,8 @@ void lv_ll_chg_list(lv_ll_t * ll_ori_p, lv_ll_t * ll_new_p, void * node, bool he if(ll_new_p->tail == NULL) { /*If there is no tail (first node) set the tail too*/ ll_new_p->tail = node; } - } else { + } + else { /*Set node as tail*/ node_set_prev(ll_new_p, node, ll_new_p->tail); node_set_next(ll_new_p, node, NULL); diff --git a/src/lv_misc/lv_ll.h b/src/lv_misc/lv_ll.h index 2ac66a48f..1d03b6ab8 100644 --- a/src/lv_misc/lv_ll.h +++ b/src/lv_misc/lv_ll.h @@ -30,8 +30,7 @@ extern "C" { typedef uint8_t lv_ll_node_t; /** Description of a linked list*/ -typedef struct -{ +typedef struct { uint32_t n_size; lv_ll_node_t * head; lv_ll_node_t * tail; diff --git a/src/lv_misc/lv_log.c b/src/lv_misc/lv_log.c index 2bf18acfd..9fe1fba52 100644 --- a/src/lv_misc/lv_log.c +++ b/src/lv_misc/lv_log.c @@ -13,7 +13,7 @@ #include "lv_printf.h" #if LV_LOG_PRINTF -#include + #include #endif /********************* diff --git a/src/lv_misc/lv_math.c b/src/lv_misc/lv_math.c index 6b97701ea..912aced3c 100644 --- a/src/lv_misc/lv_math.c +++ b/src/lv_misc/lv_math.c @@ -32,7 +32,8 @@ static const int16_t sin0_90_table[] = { 17364, 17846, 18323, 18794, 19260, 19720, 20173, 20621, 21062, 21497, 21925, 22347, 22762, 23170, 23571, 23964, 24351, 24730, 25101, 25465, 25821, 26169, 26509, 26841, 27165, 27481, 27788, 28087, 28377, 28659, 28932, 29196, 29451, 29697, 29934, 30162, 30381, 30591, 30791, 30982, 31163, 31335, 31498, 31650, 31794, 31927, 32051, 32165, - 32269, 32364, 32448, 32523, 32587, 32642, 32687, 32722, 32747, 32762, 32767}; + 32269, 32364, 32448, 32523, 32587, 32642, 32687, 32722, 32747, 32762, 32767 +}; /********************** * MACROS @@ -56,13 +57,16 @@ int16_t lv_trigo_sin(int16_t angle) if(angle < 90) { ret = sin0_90_table[angle]; - } else if(angle >= 90 && angle < 180) { + } + else if(angle >= 90 && angle < 180) { angle = 180 - angle; ret = sin0_90_table[angle]; - } else if(angle >= 180 && angle < 270) { + } + else if(angle >= 180 && angle < 270) { angle = angle - 180; ret = -sin0_90_table[angle]; - } else { /*angle >=270*/ + } + else { /*angle >=270*/ angle = 360 - angle; ret = -sin0_90_table[angle]; } @@ -114,96 +118,96 @@ void lv_sqrt(uint32_t x, lv_sqrt_res_t * q) /*Look up for x=1..1024*/ /*Look up for x=1..1024*/ - static const uint8_t ci[] = { - 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, - 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, - 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, - 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, - 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, - 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, - 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, - 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, - 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, - 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 21, - 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, - 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, - 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, - 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, - 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, - 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, - 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, - 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, - 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, - 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, - 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, - 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, - 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, - 27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, - 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, - 28, 28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, - 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, - 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, - 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, - 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 31, - 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, - 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, - 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 32, - }; + static const uint8_t ci[] = { + 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, + 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, + 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, + 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, + 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, + 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, + 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, + 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, + 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, + 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 21, + 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, + 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, + 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, + 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, + 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, + 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, + 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, + 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, + 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, + 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, + 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, + 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, + 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, + 27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, + 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, + 28, 28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, + 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, + 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, + 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, + 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 31, + 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, + 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, + 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 32, + }; - static const uint8_t cf[] = { - 0, 106, 187, 0, 60, 115, 165, 212, 0, 42, 81, 119, 155, 190, 223, 0, 32, 62, 92, 121, 149, 177, 204, 230, - 0, 25, 50, 75, 99, 122, 145, 168, 191, 213, 235, 0, 21, 42, 63, 83, 103, 123, 143, 162, 181, 200, 219, - 238, 0, 18, 36, 54, 72, 89, 107, 124, 141, 158, 174, 191, 207, 224, 240, 0, 16, 32, 47, 63, 78, 94, 109, - 124, 139, 154, 169, 184, 198, 213, 227, 242, 0, 14, 28, 42, 56, 70, 84, 97, 111, 125, 138, 151, 165, 178, - 191, 204, 217, 230, 243, 0, 13, 25, 38, 51, 63, 76, 88, 100, 113, 125, 137, 149, 161, 173, 185, 197, 209, - 221, 233, 244, 0, 12, 23, 35, 46, 58, 69, 80, 92, 103, 114, 125, 136, 147, 158, 169, 180, 191, 202, 213, - 224, 235, 245, 0, 11, 21, 32, 42, 53, 63, 74, 84, 95, 105, 115, 125, 136, 146, 156, 166, 176, 186, 196, - 206, 216, 226, 236, 246, 0, 10, 20, 29, 39, 49, 59, 68, 78, 87, 97, 107, 116, 126, 135, 145, 154, 163, - 173, 182, 191, 201, 210, 219, 228, 238, 247, 0, 9, 18, 27, 36, 45, 54, 63, 72, 81, 90, 99, 108, 117, 126, - 135, 143, 152, 161, 170, 178, 187, 196, 204, 213, 222, 230, 239, 247, 0, 9, 17, 26, 34, 42, 51, 59, 68, - 76, 84, 93, 101, 109, 118, 126, 134, 142, 151, 159, 167, 175, 183, 191, 200, 208, 216, 224, 232, 240, 248, - 0, 8, 16, 24, 32, 40, 48, 56, 64, 71, 79, 87, 95, 103, 111, 118, 126, 134, 142, 149, 157, 165, 172, 180, - 188, 195, 203, 211, 218, 226, 233, 241, 248, 0, 8, 15, 23, 30, 37, 45, 52, 60, 67, 75, 82, 89, 97, 104, - 112, 119, 126, 133, 141, 148, 155, 163, 170, 177, 184, 192, 199, 206, 213, 220, 227, 235, 242, 249, 0, 7, - 14, 21, 28, 35, 42, 50, 57, 64, 71, 78, 85, 92, 99, 105, 112, 119, 126, 133, 140, 147, 154, 161, 168, 174, - 181, 188, 195, 202, 209, 215, 222, 229, 236, 243, 249, 0, 7, 13, 20, 27, 34, 40, 47, 54, 60, 67, 74, 80, - 87, 93, 100, 107, 113, 120, 126, 133, 139, 146, 153, 159, 166, 172, 179, 185, 192, 198, 205, 211, 217, - 224, 230, 237, 243, 250, 0, 6, 13, 19, 26, 32, 38, 45, 51, 57, 64, 70, 76, 83, 89, 95, 101, 108, 114, 120, - 126, 133, 139, 145, 151, 158, 164, 170, 176, 182, 189, 195, 201, 207, 213, 219, 225, 232, 238, 244, 250, - 0, 6, 12, 18, 24, 30, 36, 42, 49, 55, 61, 67, 73, 79, 85, 91, 97, 103, 109, 115, 121, 127, 132, 138, 144, - 150, 156, 162, 168, 174, 180, 186, 192, 198, 203, 209, 215, 221, 227, 233, 239, 244, 250, 0, 6, 12, 17, - 23, 29, 35, 41, 46, 52, 58, 64, 69, 75, 81, 87, 92, 98, 104, 109, 115, 121, 127, 132, 138, 144, 149, 155, - 161, 166, 172, 178, 183, 189, 194, 200, 206, 211, 217, 223, 228, 234, 239, 245, 250, 0, 6, 11, 17, 22, 28, - 33, 39, 44, 50, 55, 61, 66, 72, 77, 83, 88, 94, 99, 105, 110, 116, 121, 127, 132, 138, 143, 148, 154, 159, - 165, 170, 175, 181, 186, 192, 197, 202, 208, 213, 219, 224, 229, 235, 240, 245, 251, 0, 5, 11, 16, 21, 27, - 32, 37, 43, 48, 53, 58, 64, 69, 74, 79, 85, 90, 95, 101, 106, 111, 116, 121, 127, 132, 137, 142, 148, 153, - 158, 163, 168, 174, 179, 184, 189, 194, 199, 205, 210, 215, 220, 225, 230, 235, 241, 246, 251, 0, 5, 10, - 15, 20, 26, 31, 36, 41, 46, 51, 56, 61, 66, 71, 76, 81, 86, 92, 97, 102, 107, 112, 117, 122, 127, 132, - 137, 142, 147, 152, 157, 162, 167, 172, 177, 182, 187, 192, 197, 202, 207, 212, 216, 221, 226, 231, 236, - 241, 246, 251, 0, 5, 10, 15, 20, 25, 29, 34, 39, 44, 49, 54, 59, 64, 69, 73, 78, 83, 88, 93, 98, 103, 107, - 112, 117, 122, 127, 132, 136, 141, 146, 151, 156, 161, 165, 170, 175, 180, 185, 189, 194, 199, 204, 208, - 213, 218, 223, 227, 232, 237, 242, 247, 251, 0, 5, 9, 14, 19, 24, 28, 33, 38, 43, 47, 52, 57, 61, 66, 71, - 75, 80, 85, 89, 94, 99, 104, 108, 113, 118, 122, 127, 131, 136, 141, 145, 150, 155, 159, 164, 169, 173, - 178, 182, 187, 192, 196, 201, 206, 210, 215, 219, 224, 229, 233, 238, 242, 247, 251, 0, 5, 9, 14, 18, 23, - 27, 32, 36, 41, 46, 50, 55, 59, 64, 68, 73, 77, 82, 86, 91, 95, 100, 104, 109, 113, 118, 122, 127, 131, - 136, 140, 145, 149, 154, 158, 163, 167, 172, 176, 181, 185, 189, 194, 198, 203, 207, 212, 216, 221, 225, - 229, 234, 238, 243, 247, 252, 0, 4, 9, 13, 18, 22, 26, 31, 35, 40, 44, 48, 53, 57, 62, 66, 70, 75, 79, 83, - 88, 92, 96, 101, 105, 110, 114, 118, 123, 127, 131, 136, 140, 144, 149, 153, 157, 162, 166, 170, 175, 179, - 183, 187, 192, 196, 200, 205, 209, 213, 218, 222, 226, 230, 235, 239, 243, 247, 252, 0, 4, 9, 13, 17, 21, - 26, 30, 34, 38, 43, 47, 51, 55, 60, 64, 68, 72, 76, 81, 85, 89, 93, 98, 102, 106, 110, 114, 119, 123, - 127, 131, 135, 140, 144, 148, 152, 156, 160, 165, 169, 173, 177, 181, 185, 190, 194, 198, 202, 206, 210, - 215, 219, 223, 227, 231, 235, 239, 244, 248, 252, 0, 4, 8, 12, 16, 21, 25, 29, 33, 37, 41, 45, 49, 53, 58, - 62, 66, 70, 74, 78, 82, 86, 90, 94, 98, 103, 107, 111, 115, 119, 123, 127, 131, 135, 139, 143, 147, 151, - 155, 159, 163, 168, 172, 176, 180, 184, 188, 192, 196, 200, 204, 208, 212, 216, 220, 224, 228, 232, 236, - 240, 244, 248, 252, 0, + static const uint8_t cf[] = { + 0, 106, 187, 0, 60, 115, 165, 212, 0, 42, 81, 119, 155, 190, 223, 0, 32, 62, 92, 121, 149, 177, 204, 230, + 0, 25, 50, 75, 99, 122, 145, 168, 191, 213, 235, 0, 21, 42, 63, 83, 103, 123, 143, 162, 181, 200, 219, + 238, 0, 18, 36, 54, 72, 89, 107, 124, 141, 158, 174, 191, 207, 224, 240, 0, 16, 32, 47, 63, 78, 94, 109, + 124, 139, 154, 169, 184, 198, 213, 227, 242, 0, 14, 28, 42, 56, 70, 84, 97, 111, 125, 138, 151, 165, 178, + 191, 204, 217, 230, 243, 0, 13, 25, 38, 51, 63, 76, 88, 100, 113, 125, 137, 149, 161, 173, 185, 197, 209, + 221, 233, 244, 0, 12, 23, 35, 46, 58, 69, 80, 92, 103, 114, 125, 136, 147, 158, 169, 180, 191, 202, 213, + 224, 235, 245, 0, 11, 21, 32, 42, 53, 63, 74, 84, 95, 105, 115, 125, 136, 146, 156, 166, 176, 186, 196, + 206, 216, 226, 236, 246, 0, 10, 20, 29, 39, 49, 59, 68, 78, 87, 97, 107, 116, 126, 135, 145, 154, 163, + 173, 182, 191, 201, 210, 219, 228, 238, 247, 0, 9, 18, 27, 36, 45, 54, 63, 72, 81, 90, 99, 108, 117, 126, + 135, 143, 152, 161, 170, 178, 187, 196, 204, 213, 222, 230, 239, 247, 0, 9, 17, 26, 34, 42, 51, 59, 68, + 76, 84, 93, 101, 109, 118, 126, 134, 142, 151, 159, 167, 175, 183, 191, 200, 208, 216, 224, 232, 240, 248, + 0, 8, 16, 24, 32, 40, 48, 56, 64, 71, 79, 87, 95, 103, 111, 118, 126, 134, 142, 149, 157, 165, 172, 180, + 188, 195, 203, 211, 218, 226, 233, 241, 248, 0, 8, 15, 23, 30, 37, 45, 52, 60, 67, 75, 82, 89, 97, 104, + 112, 119, 126, 133, 141, 148, 155, 163, 170, 177, 184, 192, 199, 206, 213, 220, 227, 235, 242, 249, 0, 7, + 14, 21, 28, 35, 42, 50, 57, 64, 71, 78, 85, 92, 99, 105, 112, 119, 126, 133, 140, 147, 154, 161, 168, 174, + 181, 188, 195, 202, 209, 215, 222, 229, 236, 243, 249, 0, 7, 13, 20, 27, 34, 40, 47, 54, 60, 67, 74, 80, + 87, 93, 100, 107, 113, 120, 126, 133, 139, 146, 153, 159, 166, 172, 179, 185, 192, 198, 205, 211, 217, + 224, 230, 237, 243, 250, 0, 6, 13, 19, 26, 32, 38, 45, 51, 57, 64, 70, 76, 83, 89, 95, 101, 108, 114, 120, + 126, 133, 139, 145, 151, 158, 164, 170, 176, 182, 189, 195, 201, 207, 213, 219, 225, 232, 238, 244, 250, + 0, 6, 12, 18, 24, 30, 36, 42, 49, 55, 61, 67, 73, 79, 85, 91, 97, 103, 109, 115, 121, 127, 132, 138, 144, + 150, 156, 162, 168, 174, 180, 186, 192, 198, 203, 209, 215, 221, 227, 233, 239, 244, 250, 0, 6, 12, 17, + 23, 29, 35, 41, 46, 52, 58, 64, 69, 75, 81, 87, 92, 98, 104, 109, 115, 121, 127, 132, 138, 144, 149, 155, + 161, 166, 172, 178, 183, 189, 194, 200, 206, 211, 217, 223, 228, 234, 239, 245, 250, 0, 6, 11, 17, 22, 28, + 33, 39, 44, 50, 55, 61, 66, 72, 77, 83, 88, 94, 99, 105, 110, 116, 121, 127, 132, 138, 143, 148, 154, 159, + 165, 170, 175, 181, 186, 192, 197, 202, 208, 213, 219, 224, 229, 235, 240, 245, 251, 0, 5, 11, 16, 21, 27, + 32, 37, 43, 48, 53, 58, 64, 69, 74, 79, 85, 90, 95, 101, 106, 111, 116, 121, 127, 132, 137, 142, 148, 153, + 158, 163, 168, 174, 179, 184, 189, 194, 199, 205, 210, 215, 220, 225, 230, 235, 241, 246, 251, 0, 5, 10, + 15, 20, 26, 31, 36, 41, 46, 51, 56, 61, 66, 71, 76, 81, 86, 92, 97, 102, 107, 112, 117, 122, 127, 132, + 137, 142, 147, 152, 157, 162, 167, 172, 177, 182, 187, 192, 197, 202, 207, 212, 216, 221, 226, 231, 236, + 241, 246, 251, 0, 5, 10, 15, 20, 25, 29, 34, 39, 44, 49, 54, 59, 64, 69, 73, 78, 83, 88, 93, 98, 103, 107, + 112, 117, 122, 127, 132, 136, 141, 146, 151, 156, 161, 165, 170, 175, 180, 185, 189, 194, 199, 204, 208, + 213, 218, 223, 227, 232, 237, 242, 247, 251, 0, 5, 9, 14, 19, 24, 28, 33, 38, 43, 47, 52, 57, 61, 66, 71, + 75, 80, 85, 89, 94, 99, 104, 108, 113, 118, 122, 127, 131, 136, 141, 145, 150, 155, 159, 164, 169, 173, + 178, 182, 187, 192, 196, 201, 206, 210, 215, 219, 224, 229, 233, 238, 242, 247, 251, 0, 5, 9, 14, 18, 23, + 27, 32, 36, 41, 46, 50, 55, 59, 64, 68, 73, 77, 82, 86, 91, 95, 100, 104, 109, 113, 118, 122, 127, 131, + 136, 140, 145, 149, 154, 158, 163, 167, 172, 176, 181, 185, 189, 194, 198, 203, 207, 212, 216, 221, 225, + 229, 234, 238, 243, 247, 252, 0, 4, 9, 13, 18, 22, 26, 31, 35, 40, 44, 48, 53, 57, 62, 66, 70, 75, 79, 83, + 88, 92, 96, 101, 105, 110, 114, 118, 123, 127, 131, 136, 140, 144, 149, 153, 157, 162, 166, 170, 175, 179, + 183, 187, 192, 196, 200, 205, 209, 213, 218, 222, 226, 230, 235, 239, 243, 247, 252, 0, 4, 9, 13, 17, 21, + 26, 30, 34, 38, 43, 47, 51, 55, 60, 64, 68, 72, 76, 81, 85, 89, 93, 98, 102, 106, 110, 114, 119, 123, + 127, 131, 135, 140, 144, 148, 152, 156, 160, 165, 169, 173, 177, 181, 185, 190, 194, 198, 202, 206, 210, + 215, 219, 223, 227, 231, 235, 239, 244, 248, 252, 0, 4, 8, 12, 16, 21, 25, 29, 33, 37, 41, 45, 49, 53, 58, + 62, 66, 70, 74, 78, 82, 86, 90, 94, 98, 103, 107, 111, 115, 119, 123, 127, 131, 135, 139, 143, 147, 151, + 155, 159, 163, 168, 172, 176, 180, 184, 188, 192, 196, 200, 204, 208, 212, 216, 220, 224, 228, 232, 236, + 240, 244, 248, 252, 0, - }; + }; if(x <= 1024) { x--; q->i = ci[x]; @@ -274,7 +278,8 @@ uint16_t lv_atan2(int x, int y) if(ux > uy) { degree = (uy * 45) / ux; // degree result will be 0-45 range negflag += 0x10; // octant flag bit - } else { + } + else { degree = (ux * 45) / uy; // degree result will be 0-45 range } @@ -286,7 +291,8 @@ uint16_t lv_atan2(int x, int y) if(tempdegree <= 41) comp++; if(tempdegree <= 37) comp++; if(tempdegree <= 32) comp++; // max is 4 degrees compensated - } else { // else is lower half of range + } + else { // else is lower half of range if(tempdegree >= 2) comp++; if(tempdegree >= 6) comp++; if(tempdegree >= 10) comp++; @@ -304,7 +310,8 @@ uint16_t lv_atan2(int x, int y) degree = (180 + degree); else // else is -Y +X degree = (180 - degree); - } else { // else is +Y + } + else { // else is +Y if(negflag & 0x01) // if +Y -X degree = (360 - degree); } diff --git a/src/lv_misc/lv_math.h b/src/lv_misc/lv_math.h index d080f75d4..e12ae26a2 100644 --- a/src/lv_misc/lv_math.h +++ b/src/lv_misc/lv_math.h @@ -44,9 +44,9 @@ extern "C" { **********************/ typedef struct { - uint16_t i; - uint16_t f; - }lv_sqrt_res_t; + uint16_t i; + uint16_t f; +} lv_sqrt_res_t; /********************** diff --git a/src/lv_misc/lv_mem.c b/src/lv_misc/lv_mem.c index 16cb76090..2b8579f1a 100644 --- a/src/lv_misc/lv_mem.c +++ b/src/lv_misc/lv_mem.c @@ -13,11 +13,11 @@ #include #if LV_MEM_CUSTOM != 0 -#include LV_MEM_CUSTOM_INCLUDE + #include LV_MEM_CUSTOM_INCLUDE #endif #if defined(LV_GC_INCLUDE) -#include LV_GC_INCLUDE + #include LV_GC_INCLUDE #endif /* LV_ENABLE_GC */ /********************* @@ -25,13 +25,13 @@ *********************/ /*Add memory junk on alloc (0xaa) and free(0xbb) (just for testing purposes)*/ #ifndef LV_MEM_ADD_JUNK -#define LV_MEM_ADD_JUNK 1 + #define LV_MEM_ADD_JUNK 1 #endif #ifdef LV_ARCH_64 -#define MEM_UNIT uint64_t + #define MEM_UNIT uint64_t #else -#define MEM_UNIT uint32_t + #define MEM_UNIT uint32_t #endif /********************** @@ -41,18 +41,15 @@ #if LV_ENABLE_GC == 0 /*gc custom allocations must not include header*/ /*The size of this union must be 4 bytes (uint32_t)*/ -typedef union -{ - struct - { +typedef union { + struct { MEM_UNIT used : 1; /* 1: if the entry is used*/ MEM_UNIT d_size : 31; /* Size off the data (1 means 4 bytes)*/ } s; MEM_UNIT header; /* The header (used + d_size)*/ } lv_mem_header_t; -typedef struct -{ +typedef struct { lv_mem_header_t header; uint8_t first_data; /*First data byte in the allocated data (Just for easily create a pointer)*/ } lv_mem_ent_t; @@ -63,16 +60,16 @@ typedef struct * STATIC PROTOTYPES **********************/ #if LV_MEM_CUSTOM == 0 -static lv_mem_ent_t * ent_get_next(lv_mem_ent_t * act_e); -static void * ent_alloc(lv_mem_ent_t * e, size_t size); -static void ent_trunc(lv_mem_ent_t * e, size_t size); + static lv_mem_ent_t * ent_get_next(lv_mem_ent_t * act_e); + static void * ent_alloc(lv_mem_ent_t * e, size_t size); + static void ent_trunc(lv_mem_ent_t * e, size_t size); #endif /********************** * STATIC VARIABLES **********************/ #if LV_MEM_CUSTOM == 0 -static uint8_t * work_mem; + static uint8_t * work_mem; #endif static uint32_t zero_mem; /*Give the address of this variable if 0 byte should be allocated*/ @@ -165,7 +162,7 @@ void * lv_mem_alloc(size_t size) } while(e != NULL && alloc == NULL); #else -/*Use custom, user defined malloc function*/ + /*Use custom, user defined malloc function*/ #if LV_ENABLE_GC == 1 /*gc must not include header*/ alloc = LV_MEM_CUSTOM_ALLOC(size); #else /* LV_ENABLE_GC */ @@ -217,7 +214,8 @@ void lv_mem_free(const void * data) while(e_next != NULL) { if(e_next->header.s.used == 0) { e->header.s.d_size += e_next->header.s.d_size + sizeof(e->header); - } else { + } + else { break; } e_next = ent_get_next(e_next); @@ -324,7 +322,8 @@ void lv_mem_defrag(void) while(e_free != NULL) { if(e_free->header.s.used != 0) { e_free = ent_get_next(e_free); - } else { + } + else { break; } } @@ -336,7 +335,8 @@ void lv_mem_defrag(void) while(e_next != NULL) { if(e_next->header.s.used == 0) { e_free->header.s.d_size += e_next->header.s.d_size + sizeof(e_next->header); - } else { + } + else { break; } @@ -358,7 +358,7 @@ lv_res_t lv_mem_test(void) e = ent_get_next(NULL); while(e) { if((e->header.s.used && e->header.s.d_size > LV_MEM_SIZE) || - (e->header.s.used == 0 && e->header.s.d_size > LV_MEM_SIZE)) { + (e->header.s.used == 0 && e->header.s.d_size > LV_MEM_SIZE)) { return LV_RES_INV; } e = ent_get_next(e); @@ -389,7 +389,8 @@ void lv_mem_monitor(lv_mem_monitor_t * mon_p) if(e->header.s.d_size > mon_p->free_biggest_size) { mon_p->free_biggest_size = e->header.s.d_size; } - } else { + } + else { mon_p->used_cnt++; } @@ -514,7 +515,8 @@ static lv_mem_ent_t * ent_get_next(lv_mem_ent_t * act_e) if(act_e == NULL) { /*NULL means: get the first entry*/ next_e = (lv_mem_ent_t *)work_mem; - } else { /*Get the next entry */ + } + else { /*Get the next entry */ uint8_t * data = &act_e->first_data; next_e = (lv_mem_ent_t *)&data[act_e->header.s.d_size]; @@ -539,7 +541,7 @@ static void * ent_alloc(lv_mem_ent_t * e, size_t size) /*Truncate the entry to the desired size */ ent_trunc(e, size), - e->header.s.used = 1; + e->header.s.used = 1; /*Save the allocated data*/ alloc = &e->first_data; diff --git a/src/lv_misc/lv_mem.h b/src/lv_misc/lv_mem.h index 4095f243e..fd0eaa911 100644 --- a/src/lv_misc/lv_mem.h +++ b/src/lv_misc/lv_mem.h @@ -35,8 +35,7 @@ extern "C" { /** * Heap information structure. */ -typedef struct -{ +typedef struct { uint32_t total_size; /**< Total heap size */ uint32_t free_cnt; uint32_t free_size; /**< Size of available memory */ @@ -49,8 +48,8 @@ typedef struct typedef struct { void * p; uint16_t size; - uint8_t used :1; -}lv_mem_buf_t; + uint8_t used : 1; +} lv_mem_buf_t; typedef lv_mem_buf_t lv_mem_buf_arr_t[LV_MEM_BUF_MAX_NUM]; extern lv_mem_buf_arr_t _lv_mem_buf; diff --git a/src/lv_misc/lv_printf.c b/src/lv_misc/lv_printf.c index d5782c910..f007b8a80 100644 --- a/src/lv_misc/lv_printf.c +++ b/src/lv_misc/lv_printf.c @@ -44,51 +44,51 @@ // numeric number including padded zeros (dynamically created on stack) // default: 32 byte #ifndef PRINTF_NTOA_BUFFER_SIZE -#define PRINTF_NTOA_BUFFER_SIZE 32U + #define PRINTF_NTOA_BUFFER_SIZE 32U #endif // 'ftoa' conversion buffer size, this must be big enough to hold one converted // float number including padded zeros (dynamically created on stack) // default: 32 byte #ifndef PRINTF_FTOA_BUFFER_SIZE -#define PRINTF_FTOA_BUFFER_SIZE 32U + #define PRINTF_FTOA_BUFFER_SIZE 32U #endif // support for the floating point type (%f) // default: activated #ifndef PRINTF_DISABLE_SUPPORT_FLOAT -#define PRINTF_SUPPORT_FLOAT + #define PRINTF_SUPPORT_FLOAT #endif // support for exponential floating point notation (%e/%g) // default: activated #ifndef PRINTF_DISABLE_SUPPORT_EXPONENTIAL -#define PRINTF_SUPPORT_EXPONENTIAL + #define PRINTF_SUPPORT_EXPONENTIAL #endif // define the default floating point precision // default: 6 digits #ifndef PRINTF_DEFAULT_FLOAT_PRECISION -#define PRINTF_DEFAULT_FLOAT_PRECISION 6U + #define PRINTF_DEFAULT_FLOAT_PRECISION 6U #endif // define the largest float suitable to print with %f // default: 1e9 #ifndef PRINTF_MAX_FLOAT -#define PRINTF_MAX_FLOAT 1e9 + #define PRINTF_MAX_FLOAT 1e9 #endif // support for the long long types (%llu or %p) // default: activated #ifndef PRINTF_DISABLE_SUPPORT_LONG_LONG -#define PRINTF_SUPPORT_LONG_LONG + #define PRINTF_SUPPORT_LONG_LONG #endif // support for the ptrdiff_t type (%t) // ptrdiff_t is normally defined in as long or long long type // default: activated #ifndef PRINTF_DISABLE_SUPPORT_PTRDIFF_T -#define PRINTF_SUPPORT_PTRDIFF_T + #define PRINTF_SUPPORT_PTRDIFF_T #endif /////////////////////////////////////////////////////////////////////////////// @@ -110,45 +110,48 @@ // import float.h for DBL_MAX #if defined(PRINTF_SUPPORT_FLOAT) -#include + #include #endif // output function type -typedef void (*out_fct_type)(char character, void* buffer, size_t idx, size_t maxlen); +typedef void (*out_fct_type)(char character, void * buffer, size_t idx, size_t maxlen); // wrapper (used as buffer) for output function type typedef struct { - void (*fct)(char character, void* arg); - void* arg; + void (*fct)(char character, void * arg); + void * arg; } out_fct_wrap_type; // internal buffer output -static inline void _out_buffer(char character, void* buffer, size_t idx, size_t maxlen) +static inline void _out_buffer(char character, void * buffer, size_t idx, size_t maxlen) { - if (idx < maxlen) { - ((char*)buffer)[idx] = character; - } + if(idx < maxlen) { + ((char *)buffer)[idx] = character; + } } // internal null output -static inline void _out_null(char character, void* buffer, size_t idx, size_t maxlen) +static inline void _out_null(char character, void * buffer, size_t idx, size_t maxlen) { - (void)character; (void)buffer; (void)idx; (void)maxlen; + (void)character; + (void)buffer; + (void)idx; + (void)maxlen; } // internal secure strlen // \return The length of the string (excluding the terminating 0) limited by 'maxsize' -static inline unsigned int _strnlen_s(const char* str, size_t maxsize) +static inline unsigned int _strnlen_s(const char * str, size_t maxsize) { - const char* s; - for (s = str; *s && maxsize--; ++s); - return (unsigned int)(s - str); + const char * s; + for(s = str; *s && maxsize--; ++s); + return (unsigned int)(s - str); } @@ -156,150 +159,154 @@ static inline unsigned int _strnlen_s(const char* str, size_t maxsize) // \return true if char is a digit static inline bool _is_digit(char ch) { - return (ch >= '0') && (ch <= '9'); + return (ch >= '0') && (ch <= '9'); } // internal ASCII string to unsigned int conversion -static unsigned int _atoi(const char** str) +static unsigned int _atoi(const char ** str) { - unsigned int i = 0U; - while (_is_digit(**str)) { - i = i * 10U + (unsigned int)(*((*str)++) - '0'); - } - return i; + unsigned int i = 0U; + while(_is_digit(**str)) { + i = i * 10U + (unsigned int)(*((*str)++) - '0'); + } + return i; } // output the specified string in reverse, taking care of any zero-padding -static size_t _out_rev(out_fct_type out, char* buffer, size_t idx, size_t maxlen, const char* buf, size_t len, unsigned int width, unsigned int flags) +static size_t _out_rev(out_fct_type out, char * buffer, size_t idx, size_t maxlen, const char * buf, size_t len, + unsigned int width, unsigned int flags) { - const size_t start_idx = idx; + const size_t start_idx = idx; - // pad spaces up to given width - if (!(flags & FLAGS_LEFT) && !(flags & FLAGS_ZEROPAD)) { - size_t i; - for (i = len; i < width; i++) { - out(' ', buffer, idx++, maxlen); + // pad spaces up to given width + if(!(flags & FLAGS_LEFT) && !(flags & FLAGS_ZEROPAD)) { + size_t i; + for(i = len; i < width; i++) { + out(' ', buffer, idx++, maxlen); + } } - } - // reverse string - while (len) { - out(buf[--len], buffer, idx++, maxlen); - } - - // append pad spaces up to given width - if (flags & FLAGS_LEFT) { - while (idx - start_idx < width) { - out(' ', buffer, idx++, maxlen); + // reverse string + while(len) { + out(buf[--len], buffer, idx++, maxlen); } - } - return idx; + // append pad spaces up to given width + if(flags & FLAGS_LEFT) { + while(idx - start_idx < width) { + out(' ', buffer, idx++, maxlen); + } + } + + return idx; } // internal itoa format -static size_t _ntoa_format(out_fct_type out, char* buffer, size_t idx, size_t maxlen, char* buf, size_t len, bool negative, unsigned int base, unsigned int prec, unsigned int width, unsigned int flags) +static size_t _ntoa_format(out_fct_type out, char * buffer, size_t idx, size_t maxlen, char * buf, size_t len, + bool negative, unsigned int base, unsigned int prec, unsigned int width, unsigned int flags) { - // pad leading zeros - if (!(flags & FLAGS_LEFT)) { - if (width && (flags & FLAGS_ZEROPAD) && (negative || (flags & (FLAGS_PLUS | FLAGS_SPACE)))) { - width--; + // pad leading zeros + if(!(flags & FLAGS_LEFT)) { + if(width && (flags & FLAGS_ZEROPAD) && (negative || (flags & (FLAGS_PLUS | FLAGS_SPACE)))) { + width--; + } + while((len < prec) && (len < PRINTF_NTOA_BUFFER_SIZE)) { + buf[len++] = '0'; + } + while((flags & FLAGS_ZEROPAD) && (len < width) && (len < PRINTF_NTOA_BUFFER_SIZE)) { + buf[len++] = '0'; + } } - while ((len < prec) && (len < PRINTF_NTOA_BUFFER_SIZE)) { - buf[len++] = '0'; - } - while ((flags & FLAGS_ZEROPAD) && (len < width) && (len < PRINTF_NTOA_BUFFER_SIZE)) { - buf[len++] = '0'; - } - } - // handle hash - if (flags & FLAGS_HASH) { - if (!(flags & FLAGS_PRECISION) && len && ((len == prec) || (len == width))) { - len--; - if (len && (base == 16U)) { - len--; - } + // handle hash + if(flags & FLAGS_HASH) { + if(!(flags & FLAGS_PRECISION) && len && ((len == prec) || (len == width))) { + len--; + if(len && (base == 16U)) { + len--; + } + } + if((base == 16U) && !(flags & FLAGS_UPPERCASE) && (len < PRINTF_NTOA_BUFFER_SIZE)) { + buf[len++] = 'x'; + } + else if((base == 16U) && (flags & FLAGS_UPPERCASE) && (len < PRINTF_NTOA_BUFFER_SIZE)) { + buf[len++] = 'X'; + } + else if((base == 2U) && (len < PRINTF_NTOA_BUFFER_SIZE)) { + buf[len++] = 'b'; + } + if(len < PRINTF_NTOA_BUFFER_SIZE) { + buf[len++] = '0'; + } } - if ((base == 16U) && !(flags & FLAGS_UPPERCASE) && (len < PRINTF_NTOA_BUFFER_SIZE)) { - buf[len++] = 'x'; - } - else if ((base == 16U) && (flags & FLAGS_UPPERCASE) && (len < PRINTF_NTOA_BUFFER_SIZE)) { - buf[len++] = 'X'; - } - else if ((base == 2U) && (len < PRINTF_NTOA_BUFFER_SIZE)) { - buf[len++] = 'b'; - } - if (len < PRINTF_NTOA_BUFFER_SIZE) { - buf[len++] = '0'; - } - } - if (len < PRINTF_NTOA_BUFFER_SIZE) { - if (negative) { - buf[len++] = '-'; + if(len < PRINTF_NTOA_BUFFER_SIZE) { + if(negative) { + buf[len++] = '-'; + } + else if(flags & FLAGS_PLUS) { + buf[len++] = '+'; // ignore the space if the '+' exists + } + else if(flags & FLAGS_SPACE) { + buf[len++] = ' '; + } } - else if (flags & FLAGS_PLUS) { - buf[len++] = '+'; // ignore the space if the '+' exists - } - else if (flags & FLAGS_SPACE) { - buf[len++] = ' '; - } - } - return _out_rev(out, buffer, idx, maxlen, buf, len, width, flags); + return _out_rev(out, buffer, idx, maxlen, buf, len, width, flags); } // internal itoa for 'long' type -static size_t _ntoa_long(out_fct_type out, char* buffer, size_t idx, size_t maxlen, unsigned long value, bool negative, unsigned long base, unsigned int prec, unsigned int width, unsigned int flags) +static size_t _ntoa_long(out_fct_type out, char * buffer, size_t idx, size_t maxlen, unsigned long value, bool negative, + unsigned long base, unsigned int prec, unsigned int width, unsigned int flags) { - char buf[PRINTF_NTOA_BUFFER_SIZE]; - size_t len = 0U; + char buf[PRINTF_NTOA_BUFFER_SIZE]; + size_t len = 0U; - // no hash for 0 values - if (!value) { - flags &= ~FLAGS_HASH; - } + // no hash for 0 values + if(!value) { + flags &= ~FLAGS_HASH; + } - // write if precision != 0 and value is != 0 - if (!(flags & FLAGS_PRECISION) || value) { - do { - const char digit = (char)(value % base); - buf[len++] = digit < 10 ? '0' + digit : (flags & FLAGS_UPPERCASE ? 'A' : 'a') + digit - 10; - value /= base; - } while (value && (len < PRINTF_NTOA_BUFFER_SIZE)); - } + // write if precision != 0 and value is != 0 + if(!(flags & FLAGS_PRECISION) || value) { + do { + const char digit = (char)(value % base); + buf[len++] = digit < 10 ? '0' + digit : (flags & FLAGS_UPPERCASE ? 'A' : 'a') + digit - 10; + value /= base; + } while(value && (len < PRINTF_NTOA_BUFFER_SIZE)); + } - return _ntoa_format(out, buffer, idx, maxlen, buf, len, negative, (unsigned int)base, prec, width, flags); + return _ntoa_format(out, buffer, idx, maxlen, buf, len, negative, (unsigned int)base, prec, width, flags); } // internal itoa for 'long long' type #if defined(PRINTF_SUPPORT_LONG_LONG) -static size_t _ntoa_long_long(out_fct_type out, char* buffer, size_t idx, size_t maxlen, unsigned long long value, bool negative, unsigned long long base, unsigned int prec, unsigned int width, unsigned int flags) +static size_t _ntoa_long_long(out_fct_type out, char * buffer, size_t idx, size_t maxlen, unsigned long long value, + bool negative, unsigned long long base, unsigned int prec, unsigned int width, unsigned int flags) { - char buf[PRINTF_NTOA_BUFFER_SIZE]; - size_t len = 0U; + char buf[PRINTF_NTOA_BUFFER_SIZE]; + size_t len = 0U; - // no hash for 0 values - if (!value) { - flags &= ~FLAGS_HASH; - } + // no hash for 0 values + if(!value) { + flags &= ~FLAGS_HASH; + } - // write if precision != 0 and value is != 0 - if (!(flags & FLAGS_PRECISION) || value) { - do { - const char digit = (char)(value % base); - buf[len++] = digit < 10 ? '0' + digit : (flags & FLAGS_UPPERCASE ? 'A' : 'a') + digit - 10; - value /= base; - } while (value && (len < PRINTF_NTOA_BUFFER_SIZE)); - } + // write if precision != 0 and value is != 0 + if(!(flags & FLAGS_PRECISION) || value) { + do { + const char digit = (char)(value % base); + buf[len++] = digit < 10 ? '0' + digit : (flags & FLAGS_UPPERCASE ? 'A' : 'a') + digit - 10; + value /= base; + } while(value && (len < PRINTF_NTOA_BUFFER_SIZE)); + } - return _ntoa_format(out, buffer, idx, maxlen, buf, len, negative, (unsigned int)base, prec, width, flags); + return _ntoa_format(out, buffer, idx, maxlen, buf, len, negative, (unsigned int)base, prec, width, flags); } #endif // PRINTF_SUPPORT_LONG_LONG @@ -307,547 +314,580 @@ static size_t _ntoa_long_long(out_fct_type out, char* buffer, size_t idx, size_t #if defined(PRINTF_SUPPORT_FLOAT) #if defined(PRINTF_SUPPORT_EXPONENTIAL) -// forward declaration so that _ftoa can switch to exp notation for values > PRINTF_MAX_FLOAT -static size_t _etoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen, double value, unsigned int prec, unsigned int width, unsigned int flags); + // forward declaration so that _ftoa can switch to exp notation for values > PRINTF_MAX_FLOAT + static size_t _etoa(out_fct_type out, char * buffer, size_t idx, size_t maxlen, double value, unsigned int prec, + unsigned int width, unsigned int flags); #endif // internal ftoa for fixed decimal floating point -static size_t _ftoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen, double value, unsigned int prec, unsigned int width, unsigned int flags) +static size_t _ftoa(out_fct_type out, char * buffer, size_t idx, size_t maxlen, double value, unsigned int prec, + unsigned int width, unsigned int flags) { - char buf[PRINTF_FTOA_BUFFER_SIZE]; - size_t len = 0U; - double diff = 0.0; + char buf[PRINTF_FTOA_BUFFER_SIZE]; + size_t len = 0U; + double diff = 0.0; - // powers of 10 - static const double pow10[] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 }; + // powers of 10 + static const double pow10[] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 }; - // test for special values - if (value != value) - return _out_rev(out, buffer, idx, maxlen, "nan", 3, width, flags); - if (value < -DBL_MAX) - return _out_rev(out, buffer, idx, maxlen, "fni-", 4, width, flags); - if (value > DBL_MAX) - return _out_rev(out, buffer, idx, maxlen, (flags & FLAGS_PLUS) ? "fni+" : "fni", (flags & FLAGS_PLUS) ? 4U : 3U, width, flags); + // test for special values + if(value != value) + return _out_rev(out, buffer, idx, maxlen, "nan", 3, width, flags); + if(value < -DBL_MAX) + return _out_rev(out, buffer, idx, maxlen, "fni-", 4, width, flags); + if(value > DBL_MAX) + return _out_rev(out, buffer, idx, maxlen, (flags & FLAGS_PLUS) ? "fni+" : "fni", (flags & FLAGS_PLUS) ? 4U : 3U, width, + flags); - // test for very large values - // standard printf behavior is to print EVERY whole number digit -- which could be 100s of characters overflowing your buffers == bad - if ((value > PRINTF_MAX_FLOAT) || (value < -PRINTF_MAX_FLOAT)) { + // test for very large values + // standard printf behavior is to print EVERY whole number digit -- which could be 100s of characters overflowing your buffers == bad + if((value > PRINTF_MAX_FLOAT) || (value < -PRINTF_MAX_FLOAT)) { #if defined(PRINTF_SUPPORT_EXPONENTIAL) - return _etoa(out, buffer, idx, maxlen, value, prec, width, flags); + return _etoa(out, buffer, idx, maxlen, value, prec, width, flags); #else - return 0U; + return 0U; #endif - } + } - // test for negative - bool negative = false; - if (value < 0) { - negative = true; - value = 0 - value; - } + // test for negative + bool negative = false; + if(value < 0) { + negative = true; + value = 0 - value; + } - // set default precision, if not set explicitly - if (!(flags & FLAGS_PRECISION)) { - prec = PRINTF_DEFAULT_FLOAT_PRECISION; - } - // limit precision to 9, cause a prec >= 10 can lead to overflow errors - while ((len < PRINTF_FTOA_BUFFER_SIZE) && (prec > 9U)) { - buf[len++] = '0'; - prec--; - } + // set default precision, if not set explicitly + if(!(flags & FLAGS_PRECISION)) { + prec = PRINTF_DEFAULT_FLOAT_PRECISION; + } + // limit precision to 9, cause a prec >= 10 can lead to overflow errors + while((len < PRINTF_FTOA_BUFFER_SIZE) && (prec > 9U)) { + buf[len++] = '0'; + prec--; + } - int whole = (int)value; - double tmp = (value - whole) * pow10[prec]; - unsigned long frac = (unsigned long)tmp; - diff = tmp - frac; + int whole = (int)value; + double tmp = (value - whole) * pow10[prec]; + unsigned long frac = (unsigned long)tmp; + diff = tmp - frac; - if (diff > 0.5) { - ++frac; - // handle rollover, e.g. case 0.99 with prec 1 is 1.0 - if (frac >= pow10[prec]) { - frac = 0; - ++whole; + if(diff > 0.5) { + ++frac; + // handle rollover, e.g. case 0.99 with prec 1 is 1.0 + if(frac >= pow10[prec]) { + frac = 0; + ++whole; + } + } + else if(diff < 0.5) { + } + else if((frac == 0U) || (frac & 1U)) { + // if halfway, round up if odd OR if last digit is 0 + ++frac; } - } - else if (diff < 0.5) { - } - else if ((frac == 0U) || (frac & 1U)) { - // if halfway, round up if odd OR if last digit is 0 - ++frac; - } - if (prec == 0U) { - diff = value - (double)whole; - if ((!(diff < 0.5) || (diff > 0.5)) && (whole & 1)) { - // exactly 0.5 and ODD, then round up - // 1.5 -> 2, but 2.5 -> 2 - ++whole; + if(prec == 0U) { + diff = value - (double)whole; + if((!(diff < 0.5) || (diff > 0.5)) && (whole & 1)) { + // exactly 0.5 and ODD, then round up + // 1.5 -> 2, but 2.5 -> 2 + ++whole; + } } - } - else { - unsigned int count = prec; - // now do fractional part, as an unsigned number - while (len < PRINTF_FTOA_BUFFER_SIZE) { - --count; - buf[len++] = (char)(48U + (frac % 10U)); - if (!(frac /= 10U)) { - break; - } + else { + unsigned int count = prec; + // now do fractional part, as an unsigned number + while(len < PRINTF_FTOA_BUFFER_SIZE) { + --count; + buf[len++] = (char)(48U + (frac % 10U)); + if(!(frac /= 10U)) { + break; + } + } + // add extra 0s + while((len < PRINTF_FTOA_BUFFER_SIZE) && (count-- > 0U)) { + buf[len++] = '0'; + } + if(len < PRINTF_FTOA_BUFFER_SIZE) { + // add decimal + buf[len++] = '.'; + } } - // add extra 0s - while ((len < PRINTF_FTOA_BUFFER_SIZE) && (count-- > 0U)) { - buf[len++] = '0'; - } - if (len < PRINTF_FTOA_BUFFER_SIZE) { - // add decimal - buf[len++] = '.'; - } - } - // do whole part, number is reversed - while (len < PRINTF_FTOA_BUFFER_SIZE) { - buf[len++] = (char)(48 + (whole % 10)); - if (!(whole /= 10)) { - break; + // do whole part, number is reversed + while(len < PRINTF_FTOA_BUFFER_SIZE) { + buf[len++] = (char)(48 + (whole % 10)); + if(!(whole /= 10)) { + break; + } } - } - // pad leading zeros - if (!(flags & FLAGS_LEFT) && (flags & FLAGS_ZEROPAD)) { - if (width && (negative || (flags & (FLAGS_PLUS | FLAGS_SPACE)))) { - width--; + // pad leading zeros + if(!(flags & FLAGS_LEFT) && (flags & FLAGS_ZEROPAD)) { + if(width && (negative || (flags & (FLAGS_PLUS | FLAGS_SPACE)))) { + width--; + } + while((len < width) && (len < PRINTF_FTOA_BUFFER_SIZE)) { + buf[len++] = '0'; + } } - while ((len < width) && (len < PRINTF_FTOA_BUFFER_SIZE)) { - buf[len++] = '0'; - } - } - if (len < PRINTF_FTOA_BUFFER_SIZE) { - if (negative) { - buf[len++] = '-'; + if(len < PRINTF_FTOA_BUFFER_SIZE) { + if(negative) { + buf[len++] = '-'; + } + else if(flags & FLAGS_PLUS) { + buf[len++] = '+'; // ignore the space if the '+' exists + } + else if(flags & FLAGS_SPACE) { + buf[len++] = ' '; + } } - else if (flags & FLAGS_PLUS) { - buf[len++] = '+'; // ignore the space if the '+' exists - } - else if (flags & FLAGS_SPACE) { - buf[len++] = ' '; - } - } - return _out_rev(out, buffer, idx, maxlen, buf, len, width, flags); + return _out_rev(out, buffer, idx, maxlen, buf, len, width, flags); } #if defined(PRINTF_SUPPORT_EXPONENTIAL) // internal ftoa variant for exponential floating-point type, contributed by Martijn Jasperse -static size_t _etoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen, double value, unsigned int prec, unsigned int width, unsigned int flags) +static size_t _etoa(out_fct_type out, char * buffer, size_t idx, size_t maxlen, double value, unsigned int prec, + unsigned int width, unsigned int flags) { - // check for NaN and special values - if ((value != value) || (value > DBL_MAX) || (value < -DBL_MAX)) { - return _ftoa(out, buffer, idx, maxlen, value, prec, width, flags); - } + // check for NaN and special values + if((value != value) || (value > DBL_MAX) || (value < -DBL_MAX)) { + return _ftoa(out, buffer, idx, maxlen, value, prec, width, flags); + } - // determine the sign - const bool negative = value < 0; - if (negative) { - value = -value; - } + // determine the sign + const bool negative = value < 0; + if(negative) { + value = -value; + } - // default precision - if (!(flags & FLAGS_PRECISION)) { - prec = PRINTF_DEFAULT_FLOAT_PRECISION; - } + // default precision + if(!(flags & FLAGS_PRECISION)) { + prec = PRINTF_DEFAULT_FLOAT_PRECISION; + } - // determine the decimal exponent - // based on the algorithm by David Gay (https://www.ampl.com/netlib/fp/dtoa.c) - union { - uint64_t U; - double F; - } conv; + // determine the decimal exponent + // based on the algorithm by David Gay (https://www.ampl.com/netlib/fp/dtoa.c) + union { + uint64_t U; + double F; + } conv; - conv.F = value; - int exp2 = (int)((conv.U >> 52U) & 0x07FFU) - 1023; // effectively log2 - conv.U = (conv.U & ((1ULL << 52U) - 1U)) | (1023ULL << 52U); // drop the exponent so conv.F is now in [1,2) - // now approximate log10 from the log2 integer part and an expansion of ln around 1.5 - int expval = (int)(0.1760912590558 + exp2 * 0.301029995663981 + (conv.F - 1.5) * 0.289529654602168); - // now we want to compute 10^expval but we want to be sure it won't overflow - exp2 = (int)(expval * 3.321928094887362 + 0.5); - const double z = expval * 2.302585092994046 - exp2 * 0.6931471805599453; - const double z2 = z * z; - conv.U = (uint64_t)(exp2 + 1023) << 52U; - // compute exp(z) using continued fractions, see https://en.wikipedia.org/wiki/Exponential_function#Continued_fractions_for_ex - conv.F *= 1 + 2 * z / (2 - z + (z2 / (6 + (z2 / (10 + z2 / 14))))); - // correct for rounding errors - if (value < conv.F) { - expval--; - conv.F /= 10; - } + conv.F = value; + int exp2 = (int)((conv.U >> 52U) & 0x07FFU) - 1023; // effectively log2 + conv.U = (conv.U & ((1ULL << 52U) - 1U)) | (1023ULL << 52U); // drop the exponent so conv.F is now in [1,2) + // now approximate log10 from the log2 integer part and an expansion of ln around 1.5 + int expval = (int)(0.1760912590558 + exp2 * 0.301029995663981 + (conv.F - 1.5) * 0.289529654602168); + // now we want to compute 10^expval but we want to be sure it won't overflow + exp2 = (int)(expval * 3.321928094887362 + 0.5); + const double z = expval * 2.302585092994046 - exp2 * 0.6931471805599453; + const double z2 = z * z; + conv.U = (uint64_t)(exp2 + 1023) << 52U; + // compute exp(z) using continued fractions, see https://en.wikipedia.org/wiki/Exponential_function#Continued_fractions_for_ex + conv.F *= 1 + 2 * z / (2 - z + (z2 / (6 + (z2 / (10 + z2 / 14))))); + // correct for rounding errors + if(value < conv.F) { + expval--; + conv.F /= 10; + } - // the exponent format is "%+03d" and largest value is "307", so set aside 4-5 characters - unsigned int minwidth = ((expval < 100) && (expval > -100)) ? 4U : 5U; + // the exponent format is "%+03d" and largest value is "307", so set aside 4-5 characters + unsigned int minwidth = ((expval < 100) && (expval > -100)) ? 4U : 5U; - // in "%g" mode, "prec" is the number of *significant figures* not decimals - if (flags & FLAGS_ADAPT_EXP) { - // do we want to fall-back to "%f" mode? - if ((value >= 1e-4) && (value < 1e6)) { - if ((int)prec > expval) { - prec = (unsigned)((int)prec - expval - 1); - } - else { - prec = 0; - } - flags |= FLAGS_PRECISION; // make sure _ftoa respects precision - // no characters in exponent - minwidth = 0U; - expval = 0; + // in "%g" mode, "prec" is the number of *significant figures* not decimals + if(flags & FLAGS_ADAPT_EXP) { + // do we want to fall-back to "%f" mode? + if((value >= 1e-4) && (value < 1e6)) { + if((int)prec > expval) { + prec = (unsigned)((int)prec - expval - 1); + } + else { + prec = 0; + } + flags |= FLAGS_PRECISION; // make sure _ftoa respects precision + // no characters in exponent + minwidth = 0U; + expval = 0; + } + else { + // we use one sigfig for the whole part + if((prec > 0) && (flags & FLAGS_PRECISION)) { + --prec; + } + } + } + + // will everything fit? + unsigned int fwidth = width; + if(width > minwidth) { + // we didn't fall-back so subtract the characters required for the exponent + fwidth -= minwidth; } else { - // we use one sigfig for the whole part - if ((prec > 0) && (flags & FLAGS_PRECISION)) { - --prec; - } + // not enough characters, so go back to default sizing + fwidth = 0U; } - } - - // will everything fit? - unsigned int fwidth = width; - if (width > minwidth) { - // we didn't fall-back so subtract the characters required for the exponent - fwidth -= minwidth; - } else { - // not enough characters, so go back to default sizing - fwidth = 0U; - } - if ((flags & FLAGS_LEFT) && minwidth) { - // if we're padding on the right, DON'T pad the floating part - fwidth = 0U; - } - - // rescale the float value - if (expval) { - value /= conv.F; - } - - // output the floating part - const size_t start_idx = idx; - idx = _ftoa(out, buffer, idx, maxlen, negative ? -value : value, prec, fwidth, flags & ~FLAGS_ADAPT_EXP); - - // output the exponent part - if (minwidth) { - // output the exponential symbol - out((flags & FLAGS_UPPERCASE) ? 'E' : 'e', buffer, idx++, maxlen); - // output the exponent value - idx = _ntoa_long(out, buffer, idx, maxlen, (expval < 0) ? -expval : expval, expval < 0, 10, 0, minwidth-1, FLAGS_ZEROPAD | FLAGS_PLUS); - // might need to right-pad spaces - if (flags & FLAGS_LEFT) { - while (idx - start_idx < width) out(' ', buffer, idx++, maxlen); + if((flags & FLAGS_LEFT) && minwidth) { + // if we're padding on the right, DON'T pad the floating part + fwidth = 0U; } - } - return idx; + + // rescale the float value + if(expval) { + value /= conv.F; + } + + // output the floating part + const size_t start_idx = idx; + idx = _ftoa(out, buffer, idx, maxlen, negative ? -value : value, prec, fwidth, flags & ~FLAGS_ADAPT_EXP); + + // output the exponent part + if(minwidth) { + // output the exponential symbol + out((flags & FLAGS_UPPERCASE) ? 'E' : 'e', buffer, idx++, maxlen); + // output the exponent value + idx = _ntoa_long(out, buffer, idx, maxlen, (expval < 0) ? -expval : expval, expval < 0, 10, 0, minwidth - 1, + FLAGS_ZEROPAD | FLAGS_PLUS); + // might need to right-pad spaces + if(flags & FLAGS_LEFT) { + while(idx - start_idx < width) out(' ', buffer, idx++, maxlen); + } + } + return idx; } #endif // PRINTF_SUPPORT_EXPONENTIAL #endif // PRINTF_SUPPORT_FLOAT // internal vsnprintf -static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const char* format, va_list va) +static int _vsnprintf(out_fct_type out, char * buffer, const size_t maxlen, const char * format, va_list va) { - unsigned int flags, width, precision, n; - size_t idx = 0U; + unsigned int flags, width, precision, n; + size_t idx = 0U; - if (!buffer) { - // use null output function - out = _out_null; - } - - while (*format) - { - // format specifier? %[flags][width][.precision][length] - if (*format != '%') { - // no - out(*format, buffer, idx++, maxlen); - format++; - continue; - } - else { - // yes, evaluate it - format++; + if(!buffer) { + // use null output function + out = _out_null; } - // evaluate flags - flags = 0U; - do { - switch (*format) { - case '0': flags |= FLAGS_ZEROPAD; format++; n = 1U; break; - case '-': flags |= FLAGS_LEFT; format++; n = 1U; break; - case '+': flags |= FLAGS_PLUS; format++; n = 1U; break; - case ' ': flags |= FLAGS_SPACE; format++; n = 1U; break; - case '#': flags |= FLAGS_HASH; format++; n = 1U; break; - default : n = 0U; break; - } - } while (n); - - // evaluate width field - width = 0U; - if (_is_digit(*format)) { - width = _atoi(&format); - } - else if (*format == '*') { - const int w = va_arg(va, int); - if (w < 0) { - flags |= FLAGS_LEFT; // reverse padding - width = (unsigned int)-w; - } - else { - width = (unsigned int)w; - } - format++; - } - - // evaluate precision field - precision = 0U; - if (*format == '.') { - flags |= FLAGS_PRECISION; - format++; - if (_is_digit(*format)) { - precision = _atoi(&format); - } - else if (*format == '*') { - const int prec = (int)va_arg(va, int); - precision = prec > 0 ? (unsigned int)prec : 0U; - format++; - } - } - - // evaluate length field - switch (*format) { - case 'l' : - flags |= FLAGS_LONG; - format++; - if (*format == 'l') { - flags |= FLAGS_LONG_LONG; - format++; + while(*format) { + // format specifier? %[flags][width][.precision][length] + if(*format != '%') { + // no + out(*format, buffer, idx++, maxlen); + format++; + continue; } - break; - case 'h' : - flags |= FLAGS_SHORT; - format++; - if (*format == 'h') { - flags |= FLAGS_CHAR; - format++; + else { + // yes, evaluate it + format++; } - break; + + // evaluate flags + flags = 0U; + do { + switch(*format) { + case '0': + flags |= FLAGS_ZEROPAD; + format++; + n = 1U; + break; + case '-': + flags |= FLAGS_LEFT; + format++; + n = 1U; + break; + case '+': + flags |= FLAGS_PLUS; + format++; + n = 1U; + break; + case ' ': + flags |= FLAGS_SPACE; + format++; + n = 1U; + break; + case '#': + flags |= FLAGS_HASH; + format++; + n = 1U; + break; + default : + n = 0U; + break; + } + } while(n); + + // evaluate width field + width = 0U; + if(_is_digit(*format)) { + width = _atoi(&format); + } + else if(*format == '*') { + const int w = va_arg(va, int); + if(w < 0) { + flags |= FLAGS_LEFT; // reverse padding + width = (unsigned int) - w; + } + else { + width = (unsigned int)w; + } + format++; + } + + // evaluate precision field + precision = 0U; + if(*format == '.') { + flags |= FLAGS_PRECISION; + format++; + if(_is_digit(*format)) { + precision = _atoi(&format); + } + else if(*format == '*') { + const int prec = (int)va_arg(va, int); + precision = prec > 0 ? (unsigned int)prec : 0U; + format++; + } + } + + // evaluate length field + switch(*format) { + case 'l' : + flags |= FLAGS_LONG; + format++; + if(*format == 'l') { + flags |= FLAGS_LONG_LONG; + format++; + } + break; + case 'h' : + flags |= FLAGS_SHORT; + format++; + if(*format == 'h') { + flags |= FLAGS_CHAR; + format++; + } + break; #if defined(PRINTF_SUPPORT_PTRDIFF_T) - case 't' : - flags |= (sizeof(ptrdiff_t) == sizeof(long) ? FLAGS_LONG : FLAGS_LONG_LONG); - format++; - break; + case 't' : + flags |= (sizeof(ptrdiff_t) == sizeof(long) ? FLAGS_LONG : FLAGS_LONG_LONG); + format++; + break; #endif - case 'j' : - flags |= (sizeof(intmax_t) == sizeof(long) ? FLAGS_LONG : FLAGS_LONG_LONG); - format++; - break; - case 'z' : - flags |= (sizeof(size_t) == sizeof(long) ? FLAGS_LONG : FLAGS_LONG_LONG); - format++; - break; - default : - break; - } - - // evaluate specifier - switch (*format) { - case 'd' : - case 'i' : - case 'u' : - case 'x' : - case 'X' : - case 'o' : - case 'b' : { - // set the base - unsigned int base; - if (*format == 'x' || *format == 'X') { - base = 16U; - } - else if (*format == 'o') { - base = 8U; - } - else if (*format == 'b') { - base = 2U; - } - else { - base = 10U; - flags &= ~FLAGS_HASH; // no hash for dec format - } - // uppercase - if (*format == 'X') { - flags |= FLAGS_UPPERCASE; + case 'j' : + flags |= (sizeof(intmax_t) == sizeof(long) ? FLAGS_LONG : FLAGS_LONG_LONG); + format++; + break; + case 'z' : + flags |= (sizeof(size_t) == sizeof(long) ? FLAGS_LONG : FLAGS_LONG_LONG); + format++; + break; + default : + break; } - // no plus or space flag for u, x, X, o, b - if ((*format != 'i') && (*format != 'd')) { - flags &= ~(FLAGS_PLUS | FLAGS_SPACE); - } + // evaluate specifier + switch(*format) { + case 'd' : + case 'i' : + case 'u' : + case 'x' : + case 'X' : + case 'o' : + case 'b' : { + // set the base + unsigned int base; + if(*format == 'x' || *format == 'X') { + base = 16U; + } + else if(*format == 'o') { + base = 8U; + } + else if(*format == 'b') { + base = 2U; + } + else { + base = 10U; + flags &= ~FLAGS_HASH; // no hash for dec format + } + // uppercase + if(*format == 'X') { + flags |= FLAGS_UPPERCASE; + } - // ignore '0' flag when precision is given - if (flags & FLAGS_PRECISION) { - flags &= ~FLAGS_ZEROPAD; - } + // no plus or space flag for u, x, X, o, b + if((*format != 'i') && (*format != 'd')) { + flags &= ~(FLAGS_PLUS | FLAGS_SPACE); + } - // convert the integer - if ((*format == 'i') || (*format == 'd')) { - // signed - if (flags & FLAGS_LONG_LONG) { + // ignore '0' flag when precision is given + if(flags & FLAGS_PRECISION) { + flags &= ~FLAGS_ZEROPAD; + } + + // convert the integer + if((*format == 'i') || (*format == 'd')) { + // signed + if(flags & FLAGS_LONG_LONG) { #if defined(PRINTF_SUPPORT_LONG_LONG) - const long long value = va_arg(va, long long); - idx = _ntoa_long_long(out, buffer, idx, maxlen, (unsigned long long)(value > 0 ? value : 0 - value), value < 0, base, precision, width, flags); + const long long value = va_arg(va, long long); + idx = _ntoa_long_long(out, buffer, idx, maxlen, (unsigned long long)(value > 0 ? value : 0 - value), value < 0, base, + precision, width, flags); #endif - } - else if (flags & FLAGS_LONG) { - const long value = va_arg(va, long); - idx = _ntoa_long(out, buffer, idx, maxlen, (unsigned long)(value > 0 ? value : 0 - value), value < 0, base, precision, width, flags); - } - else { - const int value = (flags & FLAGS_CHAR) ? (char)va_arg(va, int) : (flags & FLAGS_SHORT) ? (short int)va_arg(va, int) : va_arg(va, int); - idx = _ntoa_long(out, buffer, idx, maxlen, (unsigned int)(value > 0 ? value : 0 - value), value < 0, base, precision, width, flags); - } - } - else { - // unsigned - if (flags & FLAGS_LONG_LONG) { + } + else if(flags & FLAGS_LONG) { + const long value = va_arg(va, long); + idx = _ntoa_long(out, buffer, idx, maxlen, (unsigned long)(value > 0 ? value : 0 - value), value < 0, base, precision, + width, flags); + } + else { + const int value = (flags & FLAGS_CHAR) ? (char)va_arg(va, int) : (flags & FLAGS_SHORT) ? (short int)va_arg(va, + int) : va_arg(va, int); + idx = _ntoa_long(out, buffer, idx, maxlen, (unsigned int)(value > 0 ? value : 0 - value), value < 0, base, precision, + width, flags); + } + } + else { + // unsigned + if(flags & FLAGS_LONG_LONG) { #if defined(PRINTF_SUPPORT_LONG_LONG) - idx = _ntoa_long_long(out, buffer, idx, maxlen, va_arg(va, unsigned long long), false, base, precision, width, flags); + idx = _ntoa_long_long(out, buffer, idx, maxlen, va_arg(va, unsigned long long), false, base, precision, width, flags); #endif - } - else if (flags & FLAGS_LONG) { - idx = _ntoa_long(out, buffer, idx, maxlen, va_arg(va, unsigned long), false, base, precision, width, flags); - } - else { - const unsigned int value = (flags & FLAGS_CHAR) ? (unsigned char)va_arg(va, unsigned int) : (flags & FLAGS_SHORT) ? (unsigned short int)va_arg(va, unsigned int) : va_arg(va, unsigned int); - idx = _ntoa_long(out, buffer, idx, maxlen, value, false, base, precision, width, flags); - } - } - format++; - break; - } + } + else if(flags & FLAGS_LONG) { + idx = _ntoa_long(out, buffer, idx, maxlen, va_arg(va, unsigned long), false, base, precision, width, flags); + } + else { + const unsigned int value = (flags & FLAGS_CHAR) ? (unsigned char)va_arg(va, + unsigned int) : (flags & FLAGS_SHORT) ? (unsigned short int)va_arg(va, unsigned int) : va_arg(va, unsigned int); + idx = _ntoa_long(out, buffer, idx, maxlen, value, false, base, precision, width, flags); + } + } + format++; + break; + } #if defined(PRINTF_SUPPORT_FLOAT) - case 'f' : - case 'F' : - if (*format == 'F') flags |= FLAGS_UPPERCASE; - idx = _ftoa(out, buffer, idx, maxlen, va_arg(va, double), precision, width, flags); - format++; - break; + case 'f' : + case 'F' : + if(*format == 'F') flags |= FLAGS_UPPERCASE; + idx = _ftoa(out, buffer, idx, maxlen, va_arg(va, double), precision, width, flags); + format++; + break; #if defined(PRINTF_SUPPORT_EXPONENTIAL) - case 'e': - case 'E': - case 'g': - case 'G': - if ((*format == 'g')||(*format == 'G')) flags |= FLAGS_ADAPT_EXP; - if ((*format == 'E')||(*format == 'G')) flags |= FLAGS_UPPERCASE; - idx = _etoa(out, buffer, idx, maxlen, va_arg(va, double), precision, width, flags); - format++; - break; + case 'e': + case 'E': + case 'g': + case 'G': + if((*format == 'g') || (*format == 'G')) flags |= FLAGS_ADAPT_EXP; + if((*format == 'E') || (*format == 'G')) flags |= FLAGS_UPPERCASE; + idx = _etoa(out, buffer, idx, maxlen, va_arg(va, double), precision, width, flags); + format++; + break; #endif // PRINTF_SUPPORT_EXPONENTIAL #endif // PRINTF_SUPPORT_FLOAT - case 'c' : { - unsigned int l = 1U; - // pre padding - if (!(flags & FLAGS_LEFT)) { - while (l++ < width) { - out(' ', buffer, idx++, maxlen); - } - } - // char output - out((char)va_arg(va, int), buffer, idx++, maxlen); - // post padding - if (flags & FLAGS_LEFT) { - while (l++ < width) { - out(' ', buffer, idx++, maxlen); - } - } - format++; - break; - } + case 'c' : { + unsigned int l = 1U; + // pre padding + if(!(flags & FLAGS_LEFT)) { + while(l++ < width) { + out(' ', buffer, idx++, maxlen); + } + } + // char output + out((char)va_arg(va, int), buffer, idx++, maxlen); + // post padding + if(flags & FLAGS_LEFT) { + while(l++ < width) { + out(' ', buffer, idx++, maxlen); + } + } + format++; + break; + } - case 's' : { - const char* p = va_arg(va, char*); - unsigned int l = _strnlen_s(p, precision ? precision : (size_t)-1); - // pre padding - if (flags & FLAGS_PRECISION) { - l = (l < precision ? l : precision); - } - if (!(flags & FLAGS_LEFT)) { - while (l++ < width) { - out(' ', buffer, idx++, maxlen); - } - } - // string output - while ((*p != 0) && (!(flags & FLAGS_PRECISION) || precision--)) { - out(*(p++), buffer, idx++, maxlen); - } - // post padding - if (flags & FLAGS_LEFT) { - while (l++ < width) { - out(' ', buffer, idx++, maxlen); - } - } - format++; - break; - } + case 's' : { + const char * p = va_arg(va, char *); + unsigned int l = _strnlen_s(p, precision ? precision : (size_t) -1); + // pre padding + if(flags & FLAGS_PRECISION) { + l = (l < precision ? l : precision); + } + if(!(flags & FLAGS_LEFT)) { + while(l++ < width) { + out(' ', buffer, idx++, maxlen); + } + } + // string output + while((*p != 0) && (!(flags & FLAGS_PRECISION) || precision--)) { + out(*(p++), buffer, idx++, maxlen); + } + // post padding + if(flags & FLAGS_LEFT) { + while(l++ < width) { + out(' ', buffer, idx++, maxlen); + } + } + format++; + break; + } - case 'p' : { - width = sizeof(void*) * 2U; - flags |= FLAGS_ZEROPAD | FLAGS_UPPERCASE; + case 'p' : { + width = sizeof(void *) * 2U; + flags |= FLAGS_ZEROPAD | FLAGS_UPPERCASE; #if defined(PRINTF_SUPPORT_LONG_LONG) - const bool is_ll = sizeof(uintptr_t) == sizeof(long long); - if (is_ll) { - idx = _ntoa_long_long(out, buffer, idx, maxlen, (uintptr_t)va_arg(va, void*), false, 16U, precision, width, flags); - } - else { + const bool is_ll = sizeof(uintptr_t) == sizeof(long long); + if(is_ll) { + idx = _ntoa_long_long(out, buffer, idx, maxlen, (uintptr_t)va_arg(va, void *), false, 16U, precision, width, flags); + } + else { #endif - idx = _ntoa_long(out, buffer, idx, maxlen, (unsigned long)((uintptr_t)va_arg(va, void*)), false, 16U, precision, width, flags); + idx = _ntoa_long(out, buffer, idx, maxlen, (unsigned long)((uintptr_t)va_arg(va, void *)), false, 16U, precision, width, + flags); #if defined(PRINTF_SUPPORT_LONG_LONG) - } + } #endif - format++; - break; - } + format++; + break; + } - case '%' : - out('%', buffer, idx++, maxlen); - format++; - break; + case '%' : + out('%', buffer, idx++, maxlen); + format++; + break; - default : - out(*format, buffer, idx++, maxlen); - format++; - break; + default : + out(*format, buffer, idx++, maxlen); + format++; + break; + } } - } - // termination - out((char)0, buffer, idx < maxlen ? idx : maxlen - 1U, maxlen); + // termination + out((char)0, buffer, idx < maxlen ? idx : maxlen - 1U, maxlen); - // return written chars without terminating \0 - return (int)idx; + // return written chars without terminating \0 + return (int)idx; } /////////////////////////////////////////////////////////////////////////////// -int lv_snprintf(char* buffer, size_t count, const char* format, ...) +int lv_snprintf(char * buffer, size_t count, const char * format, ...) { - va_list va; - va_start(va, format); - const int ret = _vsnprintf(_out_buffer, buffer, count, format, va); - va_end(va); - return ret; + va_list va; + va_start(va, format); + const int ret = _vsnprintf(_out_buffer, buffer, count, format, va); + va_end(va); + return ret; } -int lv_vsnprintf(char* buffer, size_t count, const char* format, va_list va) +int lv_vsnprintf(char * buffer, size_t count, const char * format, va_list va) { - return _vsnprintf(_out_buffer, buffer, count, format, va); + return _vsnprintf(_out_buffer, buffer, count, format, va); } #endif /*LV_SPRINTF_CUSTOM*/ diff --git a/src/lv_misc/lv_printf.h b/src/lv_misc/lv_printf.h index 4a8bd609b..9aa7073b3 100644 --- a/src/lv_misc/lv_printf.h +++ b/src/lv_misc/lv_printf.h @@ -10,10 +10,10 @@ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: -// +// // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. -// +// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -54,8 +54,8 @@ extern "C" { * null character. A value equal or larger than count indicates truncation. Only when the returned value * is non-negative and less than count, the string has been completely written. */ -int lv_snprintf(char* buffer, size_t count, const char* format, ...); -int lv_vsnprintf(char* buffer, size_t count, const char* format, va_list va); +int lv_snprintf(char * buffer, size_t count, const char * format, ...); +int lv_vsnprintf(char * buffer, size_t count, const char * format, va_list va); #else #include LV_SPRINTF_INCLUDE diff --git a/src/lv_misc/lv_task.c b/src/lv_misc/lv_task.c index eb10e1813..8e97ede22 100644 --- a/src/lv_misc/lv_task.c +++ b/src/lv_misc/lv_task.c @@ -14,7 +14,7 @@ #include "lv_gc.h" #if defined(LV_GC_INCLUDE) -#include LV_GC_INCLUDE + #include LV_GC_INCLUDE #endif /* LV_ENABLE_GC */ /********************* @@ -81,7 +81,7 @@ LV_ATTRIBUTE_TASK_HANDLER uint32_t lv_task_handler(void) static uint32_t idle_period_start = 0; static uint32_t handler_start = 0; static uint32_t busy_time = 0; - static uint32_t time_till_next; + static uint32_t time_till_next; if(lv_task_run == false) { already_running = false; /*Release mutex*/ @@ -174,7 +174,7 @@ LV_ATTRIBUTE_TASK_HANDLER uint32_t lv_task_handler(void) busy_time = 0; idle_period_start = lv_tick_get(); } - + time_till_next = LV_NO_TASK_READY; next = lv_ll_get_head(&LV_GC_ROOT(_lv_task_ll)); while(next) { @@ -183,14 +183,14 @@ LV_ATTRIBUTE_TASK_HANDLER uint32_t lv_task_handler(void) if(delay < time_till_next) time_till_next = delay; } - + next = lv_ll_get_next(&LV_GC_ROOT(_lv_task_ll), next); /*Find the next task*/ } - + already_running = false; /*Release the mutex*/ LV_LOG_TRACE("lv_task_handler ready"); - return time_till_next; + return time_till_next; } /** * Create an "empty" task. It needs to initialzed with at least @@ -305,8 +305,7 @@ void lv_task_set_prio(lv_task_t * task, lv_task_prio_t prio) /*Find the tasks with new priority*/ lv_task_t * i; - LV_LL_READ(LV_GC_ROOT(_lv_task_ll), i) - { + LV_LL_READ(LV_GC_ROOT(_lv_task_ll), i) { if(i->prio <= prio) { if(i != task) lv_ll_move_before(&LV_GC_ROOT(_lv_task_ll), task, i); break; @@ -416,9 +415,9 @@ static bool lv_task_exec(lv_task_t * task) */ static uint32_t lv_task_time_remaining(lv_task_t * task) { - /*Check if at least 'period' time elapsed*/ + /*Check if at least 'period' time elapsed*/ uint32_t elp = lv_tick_elaps(task->last_run); - if(elp >= task->period) - return 0; - return task->period - elp; + if(elp >= task->period) + return 0; + return task->period - elp; } diff --git a/src/lv_misc/lv_task.h b/src/lv_misc/lv_task.h index a7acafdf7..ab7ba3b71 100644 --- a/src/lv_misc/lv_task.h +++ b/src/lv_misc/lv_task.h @@ -57,8 +57,7 @@ typedef uint8_t lv_task_prio_t; /** * Descriptor of a lv_task */ -typedef struct _lv_task_t -{ +typedef struct _lv_task_t { uint32_t period; /**< How often the task should run */ uint32_t last_run; /**< Last time the task ran */ lv_task_cb_t task_cb; /**< Task function */ diff --git a/src/lv_misc/lv_txt.c b/src/lv_misc/lv_txt.c index 944d97c41..30f00b0f5 100644 --- a/src/lv_misc/lv_txt.c +++ b/src/lv_misc/lv_txt.c @@ -25,23 +25,23 @@ static inline bool is_break_char(uint32_t letter); #if LV_TXT_ENC == LV_TXT_ENC_UTF8 -static uint8_t lv_txt_utf8_size(const char * str); -static uint32_t lv_txt_unicode_to_utf8(uint32_t letter_uni); -static uint32_t lv_txt_utf8_conv_wc(uint32_t c); -static uint32_t lv_txt_utf8_next(const char * txt, uint32_t * i); -static uint32_t lv_txt_utf8_prev(const char * txt, uint32_t * i_start); -static uint32_t lv_txt_utf8_get_byte_id(const char * txt, uint32_t utf8_id); -static uint32_t lv_txt_utf8_get_char_id(const char * txt, uint32_t byte_id); -static uint32_t lv_txt_utf8_get_length(const char * txt); + static uint8_t lv_txt_utf8_size(const char * str); + static uint32_t lv_txt_unicode_to_utf8(uint32_t letter_uni); + static uint32_t lv_txt_utf8_conv_wc(uint32_t c); + static uint32_t lv_txt_utf8_next(const char * txt, uint32_t * i); + static uint32_t lv_txt_utf8_prev(const char * txt, uint32_t * i_start); + static uint32_t lv_txt_utf8_get_byte_id(const char * txt, uint32_t utf8_id); + static uint32_t lv_txt_utf8_get_char_id(const char * txt, uint32_t byte_id); + static uint32_t lv_txt_utf8_get_length(const char * txt); #elif LV_TXT_ENC == LV_TXT_ENC_ASCII -static uint8_t lv_txt_iso8859_1_size(const char * str); -static uint32_t lv_txt_unicode_to_iso8859_1(uint32_t letter_uni); -static uint32_t lv_txt_iso8859_1_conv_wc(uint32_t c); -static uint32_t lv_txt_iso8859_1_next(const char * txt, uint32_t * i); -static uint32_t lv_txt_iso8859_1_prev(const char * txt, uint32_t * i_start); -static uint32_t lv_txt_iso8859_1_get_byte_id(const char * txt, uint32_t utf8_id); -static uint32_t lv_txt_iso8859_1_get_char_id(const char * txt, uint32_t byte_id); -static uint32_t lv_txt_iso8859_1_get_length(const char * txt); + static uint8_t lv_txt_iso8859_1_size(const char * str); + static uint32_t lv_txt_unicode_to_iso8859_1(uint32_t letter_uni); + static uint32_t lv_txt_iso8859_1_conv_wc(uint32_t c); + static uint32_t lv_txt_iso8859_1_next(const char * txt, uint32_t * i); + static uint32_t lv_txt_iso8859_1_prev(const char * txt, uint32_t * i_start); + static uint32_t lv_txt_iso8859_1_get_byte_id(const char * txt, uint32_t utf8_id); + static uint32_t lv_txt_iso8859_1_get_char_id(const char * txt, uint32_t byte_id); + static uint32_t lv_txt_iso8859_1_get_length(const char * txt); #endif /********************** * STATIC VARIABLES @@ -51,23 +51,23 @@ static uint32_t lv_txt_iso8859_1_get_length(const char * txt); * GLOBAL VARIABLES **********************/ #if LV_TXT_ENC == LV_TXT_ENC_UTF8 -uint8_t (*lv_txt_encoded_size)(const char *) = lv_txt_utf8_size; -uint32_t (*lv_txt_unicode_to_encoded)(uint32_t) = lv_txt_unicode_to_utf8; -uint32_t (*lv_txt_encoded_conv_wc)(uint32_t) = lv_txt_utf8_conv_wc; -uint32_t (*lv_txt_encoded_next)(const char *, uint32_t *) = lv_txt_utf8_next; -uint32_t (*lv_txt_encoded_prev)(const char *, uint32_t *) = lv_txt_utf8_prev; -uint32_t (*lv_txt_encoded_get_byte_id)(const char *, uint32_t) = lv_txt_utf8_get_byte_id; -uint32_t (*lv_txt_encoded_get_char_id)(const char *, uint32_t) = lv_txt_utf8_get_char_id; -uint32_t (*lv_txt_get_encoded_length)(const char *) = lv_txt_utf8_get_length; + uint8_t (*lv_txt_encoded_size)(const char *) = lv_txt_utf8_size; + uint32_t (*lv_txt_unicode_to_encoded)(uint32_t) = lv_txt_unicode_to_utf8; + uint32_t (*lv_txt_encoded_conv_wc)(uint32_t) = lv_txt_utf8_conv_wc; + uint32_t (*lv_txt_encoded_next)(const char *, uint32_t *) = lv_txt_utf8_next; + uint32_t (*lv_txt_encoded_prev)(const char *, uint32_t *) = lv_txt_utf8_prev; + uint32_t (*lv_txt_encoded_get_byte_id)(const char *, uint32_t) = lv_txt_utf8_get_byte_id; + uint32_t (*lv_txt_encoded_get_char_id)(const char *, uint32_t) = lv_txt_utf8_get_char_id; + uint32_t (*lv_txt_get_encoded_length)(const char *) = lv_txt_utf8_get_length; #elif LV_TXT_ENC == LV_TXT_ENC_ASCII -uint8_t (*lv_txt_encoded_size)(const char *) = lv_txt_iso8859_1_size; -uint32_t (*lv_txt_unicode_to_encoded)(uint32_t) = lv_txt_unicode_to_iso8859_1; -uint32_t (*lv_txt_encoded_conv_wc)(uint32_t) = lv_txt_iso8859_1_conv_wc; -uint32_t (*lv_txt_encoded_next)(const char *, uint32_t *) = lv_txt_iso8859_1_next; -uint32_t (*lv_txt_encoded_prev)(const char *, uint32_t *) = lv_txt_iso8859_1_prev; -uint32_t (*lv_txt_encoded_get_byte_id)(const char *, uint32_t) = lv_txt_iso8859_1_get_byte_id; -uint32_t (*lv_txt_encoded_get_char_id)(const char *, uint32_t) = lv_txt_iso8859_1_get_char_id; -uint32_t (*lv_txt_get_encoded_length)(const char *) = lv_txt_iso8859_1_get_length; + uint8_t (*lv_txt_encoded_size)(const char *) = lv_txt_iso8859_1_size; + uint32_t (*lv_txt_unicode_to_encoded)(uint32_t) = lv_txt_unicode_to_iso8859_1; + uint32_t (*lv_txt_encoded_conv_wc)(uint32_t) = lv_txt_iso8859_1_conv_wc; + uint32_t (*lv_txt_encoded_next)(const char *, uint32_t *) = lv_txt_iso8859_1_next; + uint32_t (*lv_txt_encoded_prev)(const char *, uint32_t *) = lv_txt_iso8859_1_prev; + uint32_t (*lv_txt_encoded_get_byte_id)(const char *, uint32_t) = lv_txt_iso8859_1_get_byte_id; + uint32_t (*lv_txt_encoded_get_char_id)(const char *, uint32_t) = lv_txt_iso8859_1_get_char_id; + uint32_t (*lv_txt_get_encoded_length)(const char *) = lv_txt_iso8859_1_get_length; #endif @@ -109,10 +109,11 @@ void lv_txt_get_size(lv_point_t * size_res, const char * text, const lv_font_t * while(text[line_start] != '\0') { new_line_start += lv_txt_get_next_line(&text[line_start], font, letter_space, max_width, flag); - if ((unsigned long)size_res->y + (unsigned long)letter_height + (unsigned long)line_space > LV_MAX_OF(lv_coord_t)) { + if((unsigned long)size_res->y + (unsigned long)letter_height + (unsigned long)line_space > LV_MAX_OF(lv_coord_t)) { LV_LOG_WARN("lv_txt_get_size: integer overflow while calculating text height"); return; - } else { + } + else { size_res->y += letter_height; size_res->y += line_space; } @@ -155,7 +156,7 @@ void lv_txt_get_size(lv_point_t * size_res, const char * text, const lv_font_t * * 3. Return i=9, pointing at breakchar '\n' * 4. Parenting lv_txt_get_next_line() would detect subsequent '\0' * - * TODO: Returned word_w_ptr may overestimate the returned word's width when + * TODO: Returned word_w_ptr may overestimate the returned word's width when * max_width is reached. In current usage, this has no impact. * * @param txt a '\0' terminated string @@ -168,8 +169,8 @@ void lv_txt_get_size(lv_point_t * size_res, const char * text, const lv_font_t * * @return the index of the first char of the next word (in byte index not letter index. With UTF-8 they are different) */ static uint16_t lv_txt_get_next_word(const char * txt, const lv_font_t * font, - lv_coord_t letter_space, lv_coord_t max_width, - lv_txt_flag_t flag, uint32_t *word_w_ptr, lv_txt_cmd_state_t * cmd_state, bool force) + lv_coord_t letter_space, lv_coord_t max_width, + lv_txt_flag_t flag, uint32_t * word_w_ptr, lv_txt_cmd_state_t * cmd_state, bool force) { if(txt == NULL || txt[0] == '\0') return 0; if(font == NULL) return 0; @@ -212,7 +213,7 @@ static uint16_t lv_txt_get_next_word(const char * txt, const lv_font_t * font, /* Test if this character fits within max_width */ if(break_index == NO_BREAK_FOUND && (cur_w - letter_space) > max_width) { - break_index = i; + break_index = i; break_letter_count = word_len - 1; /* break_index is now pointing at the character that doesn't fit */ } @@ -227,7 +228,7 @@ static uint16_t lv_txt_get_next_word(const char * txt, const lv_font_t * font, } /* Update the output width */ - if( word_w_ptr != NULL && break_index == NO_BREAK_FOUND ) *word_w_ptr = cur_w; + if(word_w_ptr != NULL && break_index == NO_BREAK_FOUND) *word_w_ptr = cur_w; i = i_next; @@ -236,22 +237,22 @@ static uint16_t lv_txt_get_next_word(const char * txt, const lv_font_t * font, } /* Entire Word fits in the provided space */ - if( break_index == NO_BREAK_FOUND ) { - if( word_len == 0 || (letter == '\r' && letter_next == '\n') ) i = i_next; + if(break_index == NO_BREAK_FOUND) { + if(word_len == 0 || (letter == '\r' && letter_next == '\n')) i = i_next; return i; } #if LV_TXT_LINE_BREAK_LONG_LEN > 0 /* Word doesn't fit in provided space, but isn't "long" */ if(word_len < LV_TXT_LINE_BREAK_LONG_LEN) { - if( force ) return break_index; + if(force) return break_index; if(word_w_ptr != NULL) *word_w_ptr = 0; /* Return no word */ return 0; } /* Word is "long," but insufficient amounts can fit in provided space */ if(break_letter_count < LV_TXT_LINE_BREAK_LONG_PRE_MIN_LEN) { - if( force ) return break_index; + if(force) return break_index; if(word_w_ptr != NULL) *word_w_ptr = 0; return 0; } @@ -261,7 +262,7 @@ static uint16_t lv_txt_get_next_word(const char * txt, const lv_font_t * font, i = break_index; int32_t n_move = LV_TXT_LINE_BREAK_LONG_POST_MIN_LEN - (word_len - break_letter_count); /* Move pointer "i" backwards */ - for(;n_move>0; n_move--){ + for(; n_move > 0; n_move--) { lv_txt_encoded_prev(txt, &i); // TODO: it would be appropriate to update the returned word width here // However, in current usage, this doesn't impact anything. @@ -269,7 +270,7 @@ static uint16_t lv_txt_get_next_word(const char * txt, const lv_font_t * font, } return i; #else - if( force ) return break_index; + if(force) return break_index; if(word_w_ptr != NULL) *word_w_ptr = 0; /* Return no word */ (void) break_letter_count; return 0; @@ -300,10 +301,10 @@ uint16_t lv_txt_get_next_line(const char * txt, const lv_font_t * font, while(txt[i] != '\0' && max_width > 0) { uint32_t word_w = 0; - uint32_t advance = lv_txt_get_next_word(&txt[i], font, letter_space, max_width, flag, &word_w, &cmd_state, i==0); + uint32_t advance = lv_txt_get_next_word(&txt[i], font, letter_space, max_width, flag, &word_w, &cmd_state, i == 0); max_width -= word_w; - if( advance == 0 ){ + if(advance == 0) { if(i == 0) lv_txt_encoded_next(txt, &i); // prevent inf loops break; } @@ -312,7 +313,7 @@ uint16_t lv_txt_get_next_line(const char * txt, const lv_font_t * font, if(txt[0] == '\n' || txt[0] == '\r') break; - if(txt[i] == '\n' || txt[i] == '\r'){ + if(txt[i] == '\n' || txt[i] == '\r') { i++; /* Include the following newline in the current line */ break; } @@ -496,12 +497,14 @@ static uint32_t lv_txt_unicode_to_utf8(uint32_t letter_uni) bytes[1] = ((letter_uni >> 0) & 0x3F) | 0x80; bytes[2] = 0; bytes[3] = 0; - } else if(letter_uni < 0x010000) { + } + else if(letter_uni < 0x010000) { bytes[0] = ((letter_uni >> 12) & 0x0F) | 0xE0; bytes[1] = ((letter_uni >> 6) & 0x3F) | 0x80; bytes[2] = ((letter_uni >> 0) & 0x3F) | 0x80; bytes[3] = 0; - } else if(letter_uni < 0x110000) { + } + else if(letter_uni < 0x110000) { bytes[0] = ((letter_uni >> 18) & 0x07) | 0xF0; bytes[1] = ((letter_uni >> 12) & 0x3F) | 0x80; bytes[2] = ((letter_uni >> 6) & 0x3F) | 0x80; @@ -603,7 +606,8 @@ static uint32_t lv_txt_utf8_next(const char * txt, uint32_t * i) if((txt[*i] & 0xC0) != 0x80) return 0; /*Invalid UTF-8 code*/ result += txt[*i] & 0x3F; (*i)++; - } else { + } + else { (*i)++; /*Not UTF-8 char. Go the next.*/ } } diff --git a/src/lv_misc/lv_utils.c b/src/lv_misc/lv_utils.c index 3f1895605..1939af6f9 100644 --- a/src/lv_misc/lv_utils.c +++ b/src/lv_misc/lv_utils.c @@ -100,10 +100,12 @@ void * lv_utils_bsearch(const void * key, const void * base, uint32_t n, uint32_ if((c = (*cmp)(key, middle)) > 0) { n = (n / 2) - ((n & 1) == 0); base = (middle += size); - } else if(c < 0) { + } + else if(c < 0) { n /= 2; middle = base; - } else { + } + else { return (char *)middle; } } diff --git a/src/lv_themes/lv_theme.h b/src/lv_themes/lv_theme.h index 000c50905..1963f0ae7 100644 --- a/src/lv_themes/lv_theme.h +++ b/src/lv_themes/lv_theme.h @@ -29,7 +29,7 @@ extern "C" { /** * A theme in LittlevGL consists of many styles bound together. - * + * * There is a style for each object type, as well as a generic style for * backgrounds and panels. */ @@ -76,11 +76,11 @@ typedef enum { LV_THEME_TILEVIEW, LV_THEME_WIN, LV_THEME_WIN_BTN, /*The buttons are initialized separately*/ -}lv_theme_style_t; +} lv_theme_style_t; typedef struct { - void (*apply_cb)(lv_obj_t *,lv_theme_style_t); -}lv_theme_t; + void (*apply_cb)(lv_obj_t *, lv_theme_style_t); +} lv_theme_t; /********************** * GLOBAL PROTOTYPES diff --git a/src/lv_themes/lv_theme_material.c b/src/lv_themes/lv_theme_material.c index 69eb1ca5a..639135ed6 100644 --- a/src/lv_themes/lv_theme_material.c +++ b/src/lv_themes/lv_theme_material.c @@ -60,94 +60,94 @@ static lv_style_t pad; #if LV_USE_ARC -static lv_style_t arc; -static lv_style_t arc_bg; + static lv_style_t arc; + static lv_style_t arc_bg; #endif #if LV_USE_BAR -static lv_style_t bar_bg; -static lv_style_t bar_indic; + static lv_style_t bar_bg; + static lv_style_t bar_indic; #endif #if LV_USE_BTNMATRIX -static lv_style_t btnm_bg, btnm_btn; + static lv_style_t btnm_bg, btnm_btn; #endif #if LV_USE_CALENDAR -static lv_style_t calendar_date_nums, calendar_header, calendar_daynames; + static lv_style_t calendar_date_nums, calendar_header, calendar_daynames; #endif #if LV_USE_CPICKER -static lv_style_t cpicker_bg, cpicker_indic; + static lv_style_t cpicker_bg, cpicker_indic; #endif #if LV_USE_CHART -static lv_style_t chart_series_bg, chart_series; + static lv_style_t chart_series_bg, chart_series; #endif #if LV_USE_CHECKBOX -static lv_style_t cb_bg, cb_bullet; + static lv_style_t cb_bg, cb_bullet; #endif #if LV_USE_DROPDOWN -static lv_style_t ddlist_btn, ddlist_page, ddlist_sel; + static lv_style_t ddlist_btn, ddlist_page, ddlist_sel; #endif #if LV_USE_GAUGE -static lv_style_t gauge_main, gauge_strong, gauge_needle; + static lv_style_t gauge_main, gauge_strong, gauge_needle; #endif #if LV_USE_KEYBOARD -static lv_style_t kb_bg, kb_btn; + static lv_style_t kb_bg, kb_btn; #endif #if LV_USE_LED -static lv_style_t led; + static lv_style_t led; #endif #if LV_USE_LINEMETER -static lv_style_t lmeter; + static lv_style_t lmeter; #endif #if LV_USE_LIST -static lv_style_t list_bg, list_btn; + static lv_style_t list_bg, list_btn; #endif #if LV_USE_MSGBOX -static lv_style_t mbox_btn_bg; + static lv_style_t mbox_btn_bg; #endif #if LV_USE_PAGE -static lv_style_t sb; + static lv_style_t sb; #endif #if LV_USE_ROLLER -static lv_style_t roller_bg, roller_sel; + static lv_style_t roller_bg, roller_sel; #endif #if LV_USE_SLIDER -static lv_style_t slider_knob; + static lv_style_t slider_knob; #endif #if LV_USE_SPINBOX -static lv_style_t spinbox_btn, spinbox_cursor; + static lv_style_t spinbox_btn, spinbox_cursor; #endif #if LV_USE_SWITCH -static lv_style_t sw_knob; + static lv_style_t sw_knob; #endif #if LV_USE_TABLE -static lv_style_t table_cell; + static lv_style_t table_cell; #endif #if LV_USE_TABVIEW -static lv_style_t tabview_btns, tabview_btns_bg, tabview_indic, tabview_page_scrl; + static lv_style_t tabview_btns, tabview_btns_bg, tabview_indic, tabview_page_scrl; #endif #if LV_USE_TEXTAREA -static lv_style_t ta_bg, ta_cursor, ta_oneline, ta_placeholder; + static lv_style_t ta_bg, ta_cursor, ta_oneline, ta_placeholder; #endif /********************** @@ -177,7 +177,7 @@ static void basic_init(void) lv_style_set_border_color(&panel, LV_STATE_DEFAULT, color_panel_border(LV_STATE_DEFAULT)); lv_style_set_border_color(&panel, LV_STATE_FOCUSED, color_panel_border(LV_STATE_FOCUSED)); lv_style_set_border_width(&panel, LV_STATE_DEFAULT, BORDER_WIDTH); - lv_style_set_border_side(&panel, LV_STATE_DEFAULT , LV_BORDER_SIDE_TOP); + lv_style_set_border_side(&panel, LV_STATE_DEFAULT, LV_BORDER_SIDE_TOP); lv_style_set_text_font(&panel, LV_STATE_DEFAULT, _font_normal); lv_style_set_text_color(&panel, LV_STATE_DEFAULT, color_panel_txt(LV_STATE_DEFAULT)); lv_style_set_value_color(&panel, LV_STATE_DEFAULT, color_panel_txt(LV_STATE_DEFAULT)); @@ -228,12 +228,13 @@ static void basic_init(void) lv_style_set_text_color(&btn, LV_STATE_PRESSED, color_btn_txt(LV_STATE_PRESSED)); lv_style_set_text_color(&btn, LV_STATE_PRESSED, color_btn_txt(LV_STATE_CHECKED)); lv_style_set_text_color(&btn, LV_STATE_CHECKED | LV_STATE_PRESSED, color_btn_txt(LV_STATE_CHECKED | LV_STATE_PRESSED)); - lv_style_set_text_color(&btn, LV_STATE_DISABLED,color_btn_txt(LV_STATE_DISABLED)); + lv_style_set_text_color(&btn, LV_STATE_DISABLED, color_btn_txt(LV_STATE_DISABLED)); lv_style_set_image_recolor(&btn, LV_STATE_DEFAULT, color_btn_txt(LV_STATE_DEFAULT)); lv_style_set_image_recolor(&btn, LV_STATE_PRESSED, color_btn_txt(LV_STATE_PRESSED)); lv_style_set_image_recolor(&btn, LV_STATE_PRESSED, color_btn_txt(LV_STATE_CHECKED)); - lv_style_set_image_recolor(&btn, LV_STATE_CHECKED | LV_STATE_PRESSED, color_btn_txt(LV_STATE_CHECKED | LV_STATE_PRESSED)); - lv_style_set_image_recolor(&btn, LV_STATE_DISABLED,color_btn_txt(LV_STATE_DISABLED)); + lv_style_set_image_recolor(&btn, LV_STATE_CHECKED | LV_STATE_PRESSED, + color_btn_txt(LV_STATE_CHECKED | LV_STATE_PRESSED)); + lv_style_set_image_recolor(&btn, LV_STATE_DISABLED, color_btn_txt(LV_STATE_DISABLED)); lv_style_set_value_color(&btn, LV_STATE_DEFAULT, color_btn_txt(LV_STATE_DEFAULT)); lv_style_set_pad_left(&btn, LV_STATE_DEFAULT, LV_DPI / 5); @@ -338,10 +339,10 @@ static void slider_init(void) lv_style_set_bg_color(&slider_knob, LV_STATE_DEFAULT, LV_COLOR_WHITE); lv_style_set_value_color(&slider_knob, LV_STATE_DEFAULT, LV_COLOR_WHITE); lv_style_set_radius(&slider_knob, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE); - lv_style_set_pad_left(&slider_knob, LV_STATE_DEFAULT, LV_DPI/20); - lv_style_set_pad_right(&slider_knob, LV_STATE_DEFAULT, LV_DPI/20); - lv_style_set_pad_top(&slider_knob, LV_STATE_DEFAULT, LV_DPI/20); - lv_style_set_pad_bottom(&slider_knob, LV_STATE_DEFAULT, LV_DPI/20); + lv_style_set_pad_left(&slider_knob, LV_STATE_DEFAULT, LV_DPI / 20); + lv_style_set_pad_right(&slider_knob, LV_STATE_DEFAULT, LV_DPI / 20); + lv_style_set_pad_top(&slider_knob, LV_STATE_DEFAULT, LV_DPI / 20); + lv_style_set_pad_bottom(&slider_knob, LV_STATE_DEFAULT, LV_DPI / 20); #endif } @@ -353,10 +354,10 @@ static void switch_init(void) lv_style_set_bg_opa(&sw_knob, LV_STATE_DEFAULT, LV_OPA_COVER); lv_style_set_bg_color(&sw_knob, LV_STATE_DEFAULT, LV_COLOR_WHITE); lv_style_set_radius(&sw_knob, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE); - lv_style_set_pad_top(&sw_knob, LV_STATE_DEFAULT, - LV_DPI/20); - lv_style_set_pad_bottom(&sw_knob, LV_STATE_DEFAULT, - LV_DPI/20); - lv_style_set_pad_left(&sw_knob, LV_STATE_DEFAULT, - LV_DPI/20); - lv_style_set_pad_right(&sw_knob, LV_STATE_DEFAULT, - LV_DPI/20); + lv_style_set_pad_top(&sw_knob, LV_STATE_DEFAULT, - LV_DPI / 20); + lv_style_set_pad_bottom(&sw_knob, LV_STATE_DEFAULT, - LV_DPI / 20); + lv_style_set_pad_left(&sw_knob, LV_STATE_DEFAULT, - LV_DPI / 20); + lv_style_set_pad_right(&sw_knob, LV_STATE_DEFAULT, - LV_DPI / 20); #endif } @@ -372,7 +373,7 @@ static void linemeter_init(void) lv_style_set_pad_right(&lmeter, LV_STATE_DEFAULT, LV_DPI / 10); lv_style_set_pad_top(&lmeter, LV_STATE_DEFAULT, LV_DPI / 10); lv_style_set_pad_inner(&lmeter, LV_STATE_DEFAULT, LV_DPI / 6); - lv_style_set_scale_width(&lmeter, LV_STATE_DEFAULT, LV_DPI/12); + lv_style_set_scale_width(&lmeter, LV_STATE_DEFAULT, LV_DPI / 12); lv_style_set_line_color(&lmeter, LV_STATE_DEFAULT, _color_primary); lv_style_set_scale_grad_color(&lmeter, LV_STATE_DEFAULT, _color_primary); @@ -401,7 +402,7 @@ static void gauge_init(void) lv_style_set_pad_right(&gauge_main, LV_STATE_DEFAULT, LV_DPI / 10); lv_style_set_pad_top(&gauge_main, LV_STATE_DEFAULT, LV_DPI / 10); lv_style_set_pad_inner(&gauge_main, LV_STATE_DEFAULT, LV_DPI / 6); - lv_style_set_scale_width(&gauge_main, LV_STATE_DEFAULT, LV_DPI/12); + lv_style_set_scale_width(&gauge_main, LV_STATE_DEFAULT, LV_DPI / 12); lv_style_init(&gauge_strong); lv_style_set_line_color(&gauge_strong, LV_STATE_DEFAULT, lv_color_hex3(0x888)); @@ -409,7 +410,7 @@ static void gauge_init(void) lv_style_set_scale_end_color(&gauge_strong, LV_STATE_DEFAULT, _color_primary); lv_style_set_line_width(&gauge_strong, LV_STATE_DEFAULT, LV_DPI / 25); lv_style_set_scale_end_line_width(&gauge_strong, LV_STATE_DEFAULT, LV_DPI / 25); - lv_style_set_scale_width(&gauge_strong, LV_STATE_DEFAULT, LV_DPI/7); + lv_style_set_scale_width(&gauge_strong, LV_STATE_DEFAULT, LV_DPI / 7); lv_style_init(&gauge_needle); lv_style_set_line_color(&gauge_needle, LV_STATE_DEFAULT, LV_COLOR_WHITE); @@ -448,7 +449,7 @@ static void chart_init(void) { #if LV_USE_CHART lv_style_init(&chart_series_bg); - lv_style_set_line_width(&chart_series_bg, LV_STATE_DEFAULT , 1); + lv_style_set_line_width(&chart_series_bg, LV_STATE_DEFAULT, 1); lv_style_set_line_dash_width(&chart_series_bg, LV_STATE_DEFAULT, 4); lv_style_set_line_dash_gap(&chart_series_bg, LV_STATE_DEFAULT, 4); lv_style_set_pad_bottom(&chart_series_bg, LV_STATE_DEFAULT, LV_DPI / 10); @@ -475,33 +476,33 @@ static void calendar_init(void) lv_style_init(&calendar_header); lv_style_set_pad_top(&calendar_header, LV_STATE_DEFAULT, LV_DPI / 7); - lv_style_set_pad_left(&calendar_header, LV_STATE_DEFAULT , LV_DPI / 7); - lv_style_set_pad_right(&calendar_header, LV_STATE_DEFAULT , LV_DPI / 7); - lv_style_set_pad_bottom(&calendar_header, LV_STATE_DEFAULT , LV_DPI / 7); + lv_style_set_pad_left(&calendar_header, LV_STATE_DEFAULT, LV_DPI / 7); + lv_style_set_pad_right(&calendar_header, LV_STATE_DEFAULT, LV_DPI / 7); + lv_style_set_pad_bottom(&calendar_header, LV_STATE_DEFAULT, LV_DPI / 7); lv_style_set_text_color(&calendar_header, LV_STATE_PRESSED, LV_COLOR_WHITE); lv_style_init(&calendar_daynames); lv_style_set_text_color(&calendar_daynames, LV_STATE_DEFAULT, lv_color_hex3(0xeee)); - lv_style_set_pad_left(&calendar_daynames, LV_STATE_DEFAULT , LV_DPI / 7); - lv_style_set_pad_right(&calendar_daynames, LV_STATE_DEFAULT , LV_DPI / 7); - lv_style_set_pad_bottom(&calendar_daynames, LV_STATE_DEFAULT , LV_DPI / 7); + lv_style_set_pad_left(&calendar_daynames, LV_STATE_DEFAULT, LV_DPI / 7); + lv_style_set_pad_right(&calendar_daynames, LV_STATE_DEFAULT, LV_DPI / 7); + lv_style_set_pad_bottom(&calendar_daynames, LV_STATE_DEFAULT, LV_DPI / 7); lv_style_init(&calendar_date_nums); lv_style_set_radius(&calendar_date_nums, LV_STATE_DEFAULT, LV_DPI / 50); lv_style_set_text_color(&calendar_date_nums, LV_STATE_CHECKED, LV_COLOR_WHITE); lv_style_set_text_color(&calendar_date_nums, LV_STATE_FOCUSED, _color_primary); - lv_style_set_bg_opa(&calendar_date_nums, LV_STATE_CHECKED , LV_OPA_20); - lv_style_set_bg_opa(&calendar_date_nums, LV_STATE_PRESSED , LV_OPA_20); - lv_style_set_bg_opa(&calendar_date_nums, LV_STATE_PRESSED | LV_STATE_CHECKED , LV_OPA_40); + lv_style_set_bg_opa(&calendar_date_nums, LV_STATE_CHECKED, LV_OPA_20); + lv_style_set_bg_opa(&calendar_date_nums, LV_STATE_PRESSED, LV_OPA_20); + lv_style_set_bg_opa(&calendar_date_nums, LV_STATE_PRESSED | LV_STATE_CHECKED, LV_OPA_40); lv_style_set_bg_color(&calendar_date_nums, LV_STATE_CHECKED, LV_COLOR_WHITE); - lv_style_set_border_width(&calendar_date_nums, LV_STATE_CHECKED , 2); - lv_style_set_border_side(&calendar_date_nums, LV_STATE_CHECKED , LV_BORDER_SIDE_LEFT); - lv_style_set_border_color(&calendar_date_nums,LV_STATE_CHECKED, _color_primary); + lv_style_set_border_width(&calendar_date_nums, LV_STATE_CHECKED, 2); + lv_style_set_border_side(&calendar_date_nums, LV_STATE_CHECKED, LV_BORDER_SIDE_LEFT); + lv_style_set_border_color(&calendar_date_nums, LV_STATE_CHECKED, _color_primary); lv_style_set_pad_inner(&calendar_date_nums, LV_STATE_DEFAULT, LV_DPI / 30); - lv_style_set_pad_left(&calendar_date_nums, LV_STATE_DEFAULT , LV_DPI / 7); - lv_style_set_pad_right(&calendar_date_nums, LV_STATE_DEFAULT , LV_DPI / 7); - lv_style_set_pad_bottom(&calendar_date_nums, LV_STATE_DEFAULT , LV_DPI / 7); + lv_style_set_pad_left(&calendar_date_nums, LV_STATE_DEFAULT, LV_DPI / 7); + lv_style_set_pad_right(&calendar_date_nums, LV_STATE_DEFAULT, LV_DPI / 7); + lv_style_set_pad_bottom(&calendar_date_nums, LV_STATE_DEFAULT, LV_DPI / 7); #endif } @@ -534,12 +535,12 @@ static void checkbox_init(void) #if LV_USE_CHECKBOX != 0 lv_style_init(&cb_bg); lv_style_set_radius(&cb_bg, LV_STATE_DEFAULT, LV_DPI / 50); - lv_style_set_pad_inner(&cb_bg, LV_STATE_DEFAULT , LV_DPI / 20); + lv_style_set_pad_inner(&cb_bg, LV_STATE_DEFAULT, LV_DPI / 20); lv_style_set_outline_color(&cb_bg, LV_STATE_DEFAULT, _color_primary); lv_style_set_outline_opa(&cb_bg, LV_STATE_DEFAULT, LV_OPA_TRANSP); lv_style_set_outline_opa(&cb_bg, LV_STATE_FOCUSED, LV_OPA_50); lv_style_set_outline_width(&cb_bg, LV_STATE_DEFAULT, 3); - lv_style_set_outline_pad(&cb_bg, LV_STATE_DEFAULT, LV_DPI/20); + lv_style_set_outline_pad(&cb_bg, LV_STATE_DEFAULT, LV_DPI / 20); lv_style_set_transition_time(&cb_bg, LV_STATE_DEFAULT, TRANSITION_TIME); lv_style_set_transition_prop_6(&cb_bg, LV_STATE_DEFAULT, LV_STYLE_OUTLINE_OPA); @@ -554,7 +555,7 @@ static void checkbox_init(void) lv_style_set_pattern_image(&cb_bullet, LV_STATE_CHECKED, LV_SYMBOL_OK); lv_style_set_pattern_recolor(&cb_bullet, LV_STATE_CHECKED, LV_COLOR_WHITE); lv_style_set_text_font(&cb_bullet, LV_STATE_CHECKED, _font_small); - lv_style_set_transition_time(&cb_bullet, LV_STATE_DEFAULT , TRANSITION_TIME); + lv_style_set_transition_time(&cb_bullet, LV_STATE_DEFAULT, TRANSITION_TIME); lv_style_set_transition_prop_5(&cb_bullet, LV_STATE_DEFAULT, LV_STYLE_BG_OPA); lv_style_set_transition_prop_6(&cb_bullet, LV_STATE_DEFAULT, LV_STYLE_BORDER_COLOR); #endif @@ -587,11 +588,11 @@ static void keyboard_init(void) lv_style_init(&kb_bg); lv_style_copy(&kb_bg, &panel); - lv_style_set_pad_inner(&kb_bg, LV_STATE_DEFAULT, LV_DPI/20); - lv_style_set_pad_left(&kb_bg, LV_STATE_DEFAULT, LV_DPI/20); - lv_style_set_pad_right(&kb_bg, LV_STATE_DEFAULT, LV_DPI/20); - lv_style_set_pad_top(&kb_bg, LV_STATE_DEFAULT, LV_DPI/20); - lv_style_set_pad_bottom(&kb_bg, LV_STATE_DEFAULT, LV_DPI/20); + lv_style_set_pad_inner(&kb_bg, LV_STATE_DEFAULT, LV_DPI / 20); + lv_style_set_pad_left(&kb_bg, LV_STATE_DEFAULT, LV_DPI / 20); + lv_style_set_pad_right(&kb_bg, LV_STATE_DEFAULT, LV_DPI / 20); + lv_style_set_pad_top(&kb_bg, LV_STATE_DEFAULT, LV_DPI / 20); + lv_style_set_pad_bottom(&kb_bg, LV_STATE_DEFAULT, LV_DPI / 20); #endif } @@ -611,9 +612,9 @@ static void page_init(void) lv_style_set_bg_opa(&sb, LV_STATE_DEFAULT, LV_OPA_COVER); lv_style_set_bg_color(&sb, LV_STATE_DEFAULT, lv_color_hex(0x3a3d42)); lv_style_set_radius(&sb, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE); - lv_style_set_size(&sb,LV_STATE_DEFAULT, LV_DPI / 30); - lv_style_set_pad_right(&sb,LV_STATE_DEFAULT, LV_DPI / 20); - lv_style_set_pad_bottom(&sb,LV_STATE_DEFAULT, LV_DPI / 20); + lv_style_set_size(&sb, LV_STATE_DEFAULT, LV_DPI / 30); + lv_style_set_pad_right(&sb, LV_STATE_DEFAULT, LV_DPI / 20); + lv_style_set_pad_bottom(&sb, LV_STATE_DEFAULT, LV_DPI / 20); #endif } @@ -686,7 +687,7 @@ static void list_init(void) lv_style_set_radius(&list_btn, LV_STATE_PRESSED, 0); lv_style_set_radius(&list_btn, LV_STATE_CHECKED, 0); lv_style_set_bg_opa(&list_btn, LV_STATE_PRESSED, LV_OPA_COVER); - lv_style_set_bg_opa(&list_btn, LV_STATE_CHECKED , LV_OPA_COVER); + lv_style_set_bg_opa(&list_btn, LV_STATE_CHECKED, LV_OPA_COVER); lv_style_set_bg_color(&list_btn, LV_STATE_DEFAULT, color_btn(LV_STATE_DEFAULT)); lv_style_set_bg_color(&list_btn, LV_STATE_PRESSED, color_btn(LV_STATE_PRESSED)); lv_style_set_bg_color(&list_btn, LV_STATE_DISABLED, color_btn(LV_STATE_DISABLED)); @@ -768,7 +769,7 @@ static void tabview_init(void) lv_style_set_bg_color(&tabview_btns_bg, LV_STATE_DEFAULT, color_panel(LV_STATE_DEFAULT)); lv_style_set_border_color(&tabview_btns_bg, LV_STATE_DEFAULT, color_panel_border(LV_STATE_DEFAULT)); lv_style_set_border_width(&tabview_btns_bg, LV_STATE_DEFAULT, LV_DPI / 30 > 0 ? LV_DPI / 30 : 1); - lv_style_set_border_side(&tabview_btns_bg, LV_STATE_DEFAULT , LV_BORDER_SIDE_BOTTOM); + lv_style_set_border_side(&tabview_btns_bg, LV_STATE_DEFAULT, LV_BORDER_SIDE_BOTTOM); lv_style_set_text_color(&tabview_btns_bg, LV_STATE_DEFAULT, lv_color_hex(0x979a9f)); lv_style_set_text_font(&tabview_btns_bg, LV_STATE_DEFAULT, _font_normal); lv_style_set_image_recolor(&tabview_btns_bg, LV_STATE_DEFAULT, lv_color_hex(0x979a9f)); @@ -810,10 +811,10 @@ static void table_init(void) lv_style_set_border_color(&table_cell, LV_STATE_DEFAULT, lv_color_hex(0x303338)); lv_style_set_border_width(&table_cell, LV_STATE_DEFAULT, 1); lv_style_set_border_side(&table_cell, LV_STATE_DEFAULT, LV_BORDER_SIDE_TOP | LV_BORDER_SIDE_BOTTOM); - lv_style_set_pad_left(&table_cell, LV_STATE_DEFAULT, LV_DPI/7); - lv_style_set_pad_right(&table_cell, LV_STATE_DEFAULT, LV_DPI/7); - lv_style_set_pad_top(&table_cell, LV_STATE_DEFAULT, LV_DPI/7); - lv_style_set_pad_bottom(&table_cell, LV_STATE_DEFAULT, LV_DPI/7); + lv_style_set_pad_left(&table_cell, LV_STATE_DEFAULT, LV_DPI / 7); + lv_style_set_pad_right(&table_cell, LV_STATE_DEFAULT, LV_DPI / 7); + lv_style_set_pad_top(&table_cell, LV_STATE_DEFAULT, LV_DPI / 7); + lv_style_set_pad_bottom(&table_cell, LV_STATE_DEFAULT, LV_DPI / 7); #endif } @@ -842,7 +843,7 @@ static void win_init(void) * @return a pointer to reference this theme later */ lv_theme_t * lv_theme_material_init(lv_color_t color_primary, lv_color_t color_secondary, uint32_t flags, - lv_font_t * font_small, lv_font_t * font_normal, lv_font_t * font_subtitle, lv_font_t * font_title) + lv_font_t * font_small, lv_font_t * font_normal, lv_font_t * font_subtitle, lv_font_t * font_title) { _color_primary = color_primary; @@ -895,500 +896,500 @@ void lv_theme_material_apply(lv_obj_t * obj, lv_theme_style_t name) lv_style_list_t * list; switch(name) { - case LV_THEME_NONE: - break; + case LV_THEME_NONE: + break; - case LV_THEME_SCR: - lv_obj_clean_style_list(obj, LV_OBJ_PART_MAIN); - list = lv_obj_get_style_list(obj, LV_OBJ_PART_MAIN); -lv_style_list_add_style(list, &scr); - break; - case LV_THEME_OBJ: - lv_obj_clean_style_list(obj, LV_OBJ_PART_MAIN); - list = lv_obj_get_style_list(obj, LV_OBJ_PART_MAIN); -lv_style_list_add_style(list, &panel); - break; + case LV_THEME_SCR: + lv_obj_clean_style_list(obj, LV_OBJ_PART_MAIN); + list = lv_obj_get_style_list(obj, LV_OBJ_PART_MAIN); + lv_style_list_add_style(list, &scr); + break; + case LV_THEME_OBJ: + lv_obj_clean_style_list(obj, LV_OBJ_PART_MAIN); + list = lv_obj_get_style_list(obj, LV_OBJ_PART_MAIN); + lv_style_list_add_style(list, &panel); + break; #if LV_USE_CONT - case LV_THEME_CONT: - lv_obj_clean_style_list(obj, LV_OBJ_PART_MAIN); - list = lv_obj_get_style_list(obj, LV_CONT_PART_MAIN); -lv_style_list_add_style(list, &panel); - break; + case LV_THEME_CONT: + lv_obj_clean_style_list(obj, LV_OBJ_PART_MAIN); + list = lv_obj_get_style_list(obj, LV_CONT_PART_MAIN); + lv_style_list_add_style(list, &panel); + break; #endif #if LV_USE_BTN - case LV_THEME_BTN: - lv_obj_clean_style_list(obj, LV_BTN_PART_MAIN); - list = lv_obj_get_style_list(obj, LV_BTN_PART_MAIN); -lv_style_list_add_style(list, &btn); - break; + case LV_THEME_BTN: + lv_obj_clean_style_list(obj, LV_BTN_PART_MAIN); + list = lv_obj_get_style_list(obj, LV_BTN_PART_MAIN); + lv_style_list_add_style(list, &btn); + break; #endif #if LV_USE_BTNMATRIX - case LV_THEME_BTNMATRIX: - lv_obj_clean_style_list(obj, LV_BTNMATRIX_PART_BG); - list = lv_obj_get_style_list(obj, LV_BTNMATRIX_PART_BG); + case LV_THEME_BTNMATRIX: + lv_obj_clean_style_list(obj, LV_BTNMATRIX_PART_BG); + list = lv_obj_get_style_list(obj, LV_BTNMATRIX_PART_BG); - lv_obj_clean_style_list(obj, LV_BTNMATRIX_PART_BTN); - list = lv_obj_get_style_list(obj, LV_BTNMATRIX_PART_BTN); -lv_style_list_add_style(list, &btn); -lv_style_list_add_style(list, &btnm_btn); - break; + lv_obj_clean_style_list(obj, LV_BTNMATRIX_PART_BTN); + list = lv_obj_get_style_list(obj, LV_BTNMATRIX_PART_BTN); + lv_style_list_add_style(list, &btn); + lv_style_list_add_style(list, &btnm_btn); + break; #endif #if LV_USE_KEYBOARD - case LV_THEME_KEYBOARD: - lv_obj_clean_style_list(obj, LV_KEYBOARD_PART_BG); - list = lv_obj_get_style_list(obj, LV_KEYBOARD_PART_BG); -lv_style_list_add_style(list, &kb_bg); + case LV_THEME_KEYBOARD: + lv_obj_clean_style_list(obj, LV_KEYBOARD_PART_BG); + list = lv_obj_get_style_list(obj, LV_KEYBOARD_PART_BG); + lv_style_list_add_style(list, &kb_bg); - lv_obj_clean_style_list(obj, LV_KEYBOARD_PART_BTN); - list = lv_obj_get_style_list(obj, LV_KEYBOARD_PART_BTN); -lv_style_list_add_style(list, &btn); -lv_style_list_add_style(list, &kb_btn); - break; + lv_obj_clean_style_list(obj, LV_KEYBOARD_PART_BTN); + list = lv_obj_get_style_list(obj, LV_KEYBOARD_PART_BTN); + lv_style_list_add_style(list, &btn); + lv_style_list_add_style(list, &kb_btn); + break; #endif #if LV_USE_BAR - case LV_THEME_BAR: - lv_obj_clean_style_list(obj, LV_BAR_PART_BG); - list = lv_obj_get_style_list(obj, LV_BAR_PART_BG); + case LV_THEME_BAR: + lv_obj_clean_style_list(obj, LV_BAR_PART_BG); + list = lv_obj_get_style_list(obj, LV_BAR_PART_BG); -lv_style_list_add_style(list, &bar_bg); + lv_style_list_add_style(list, &bar_bg); - lv_obj_clean_style_list(obj, LV_BAR_PART_INDIC); - list = lv_obj_get_style_list(obj, LV_BAR_PART_INDIC); - lv_style_list_add_style(list, &bar_indic); - break; + lv_obj_clean_style_list(obj, LV_BAR_PART_INDIC); + list = lv_obj_get_style_list(obj, LV_BAR_PART_INDIC); + lv_style_list_add_style(list, &bar_indic); + break; #endif #if LV_USE_SWITCH - case LV_THEME_SWITCH: - lv_obj_clean_style_list(obj, LV_SWITCH_PART_BG); - list = lv_obj_get_style_list(obj, LV_SWITCH_PART_BG); - lv_style_list_add_style(list, &bar_bg); + case LV_THEME_SWITCH: + lv_obj_clean_style_list(obj, LV_SWITCH_PART_BG); + list = lv_obj_get_style_list(obj, LV_SWITCH_PART_BG); + lv_style_list_add_style(list, &bar_bg); - lv_obj_clean_style_list(obj, LV_SWITCH_PART_INDIC); - list = lv_obj_get_style_list(obj, LV_SWITCH_PART_INDIC); - lv_style_list_add_style(list, &bar_indic); + lv_obj_clean_style_list(obj, LV_SWITCH_PART_INDIC); + list = lv_obj_get_style_list(obj, LV_SWITCH_PART_INDIC); + lv_style_list_add_style(list, &bar_indic); - lv_obj_clean_style_list(obj, LV_SWITCH_PART_KNOB); - list = lv_obj_get_style_list(obj, LV_SWITCH_PART_KNOB); - lv_style_list_add_style(list, &sw_knob); - break; + lv_obj_clean_style_list(obj, LV_SWITCH_PART_KNOB); + list = lv_obj_get_style_list(obj, LV_SWITCH_PART_KNOB); + lv_style_list_add_style(list, &sw_knob); + break; #endif #if LV_USE_CANVAS - case LV_THEME_CANVAS: - lv_obj_clean_style_list(obj, LV_CANVAS_PART_MAIN); - list = lv_obj_get_style_list(obj, LV_CANVAS_PART_MAIN); - break; + case LV_THEME_CANVAS: + lv_obj_clean_style_list(obj, LV_CANVAS_PART_MAIN); + list = lv_obj_get_style_list(obj, LV_CANVAS_PART_MAIN); + break; #endif #if LV_USE_IMG - case LV_THEME_IMAGE: - lv_obj_clean_style_list(obj, LV_IMG_PART_MAIN); - list = lv_obj_get_style_list(obj, LV_IMG_PART_MAIN); - break; + case LV_THEME_IMAGE: + lv_obj_clean_style_list(obj, LV_IMG_PART_MAIN); + list = lv_obj_get_style_list(obj, LV_IMG_PART_MAIN); + break; #endif #if LV_USE_IMGBTN - case LV_THEME_IMGBTN: - lv_obj_clean_style_list(obj, LV_IMG_PART_MAIN); - list = lv_obj_get_style_list(obj, LV_IMG_PART_MAIN); - break; + case LV_THEME_IMGBTN: + lv_obj_clean_style_list(obj, LV_IMG_PART_MAIN); + list = lv_obj_get_style_list(obj, LV_IMG_PART_MAIN); + break; #endif #if LV_USE_LABEL - case LV_THEME_LABEL: - lv_obj_clean_style_list(obj, LV_LABEL_PART_MAIN); - list = lv_obj_get_style_list(obj, LV_LABEL_PART_MAIN); - break; + case LV_THEME_LABEL: + lv_obj_clean_style_list(obj, LV_LABEL_PART_MAIN); + list = lv_obj_get_style_list(obj, LV_LABEL_PART_MAIN); + break; #endif #if LV_USE_LINE - case LV_THEME_LINE: - lv_obj_clean_style_list(obj, LV_LABEL_PART_MAIN); - list = lv_obj_get_style_list(obj, LV_LABEL_PART_MAIN); - break; + case LV_THEME_LINE: + lv_obj_clean_style_list(obj, LV_LABEL_PART_MAIN); + list = lv_obj_get_style_list(obj, LV_LABEL_PART_MAIN); + break; #endif #if LV_USE_ARC - case LV_THEME_ARC: - lv_obj_clean_style_list(obj, LV_ARC_PART_BG); - list = lv_obj_get_style_list(obj, LV_ARC_PART_BG); - lv_style_list_add_style(list, &arc_bg); + case LV_THEME_ARC: + lv_obj_clean_style_list(obj, LV_ARC_PART_BG); + list = lv_obj_get_style_list(obj, LV_ARC_PART_BG); + lv_style_list_add_style(list, &arc_bg); - lv_obj_clean_style_list(obj, LV_ARC_PART_ARC); - list = lv_obj_get_style_list(obj, LV_ARC_PART_ARC); - lv_style_list_add_style(list, &arc); - break; + lv_obj_clean_style_list(obj, LV_ARC_PART_ARC); + list = lv_obj_get_style_list(obj, LV_ARC_PART_ARC); + lv_style_list_add_style(list, &arc); + break; #endif #if LV_USE_SPINNER - case LV_THEME_SPINNER: - lv_obj_clean_style_list(obj, LV_SPINNER_PART_BG); - list = lv_obj_get_style_list(obj, LV_SPINNER_PART_BG); - lv_style_list_add_style(list, &arc_bg); + case LV_THEME_SPINNER: + lv_obj_clean_style_list(obj, LV_SPINNER_PART_BG); + list = lv_obj_get_style_list(obj, LV_SPINNER_PART_BG); + lv_style_list_add_style(list, &arc_bg); - lv_obj_clean_style_list(obj, LV_SPINNER_PART_ARC); - list = lv_obj_get_style_list(obj, LV_SPINNER_PART_ARC); - lv_style_list_add_style(list, &arc); - break; + lv_obj_clean_style_list(obj, LV_SPINNER_PART_ARC); + list = lv_obj_get_style_list(obj, LV_SPINNER_PART_ARC); + lv_style_list_add_style(list, &arc); + break; #endif #if LV_USE_SLIDER - case LV_THEME_SLIDER: - lv_obj_clean_style_list(obj, LV_SLIDER_PART_BG); - list = lv_obj_get_style_list(obj, LV_SLIDER_PART_BG); - lv_style_list_add_style(list, &bar_bg); + case LV_THEME_SLIDER: + lv_obj_clean_style_list(obj, LV_SLIDER_PART_BG); + list = lv_obj_get_style_list(obj, LV_SLIDER_PART_BG); + lv_style_list_add_style(list, &bar_bg); - lv_obj_clean_style_list(obj, LV_SLIDER_PART_INDIC); - list = lv_obj_get_style_list(obj, LV_SLIDER_PART_INDIC); - lv_style_list_add_style(list, &bar_indic); + lv_obj_clean_style_list(obj, LV_SLIDER_PART_INDIC); + list = lv_obj_get_style_list(obj, LV_SLIDER_PART_INDIC); + lv_style_list_add_style(list, &bar_indic); - lv_obj_clean_style_list(obj, LV_SLIDER_PART_KNOB); - list = lv_obj_get_style_list(obj, LV_SLIDER_PART_KNOB); - lv_style_list_add_style(list, &slider_knob); - break; + lv_obj_clean_style_list(obj, LV_SLIDER_PART_KNOB); + list = lv_obj_get_style_list(obj, LV_SLIDER_PART_KNOB); + lv_style_list_add_style(list, &slider_knob); + break; #endif #if LV_USE_CHECKBOX - case LV_THEME_CHECKBOX: - lv_obj_clean_style_list(obj, LV_CHECKBOX_PART_BG); - list = lv_obj_get_style_list(obj, LV_CHECKBOX_PART_BG); - lv_style_list_add_style(list, &cb_bg); + case LV_THEME_CHECKBOX: + lv_obj_clean_style_list(obj, LV_CHECKBOX_PART_BG); + list = lv_obj_get_style_list(obj, LV_CHECKBOX_PART_BG); + lv_style_list_add_style(list, &cb_bg); - lv_obj_clean_style_list(obj, LV_CHECKBOX_PART_BULLET); - list = lv_obj_get_style_list(obj, LV_CHECKBOX_PART_BULLET); - lv_style_list_add_style(list, &cb_bullet); - break; + lv_obj_clean_style_list(obj, LV_CHECKBOX_PART_BULLET); + list = lv_obj_get_style_list(obj, LV_CHECKBOX_PART_BULLET); + lv_style_list_add_style(list, &cb_bullet); + break; #endif #if LV_USE_MSGBOX - case LV_THEME_MSGBOX: - lv_obj_clean_style_list(obj, LV_MSGBOX_PART_BG); - list = lv_obj_get_style_list(obj, LV_MSGBOX_PART_BG); - lv_style_list_add_style(list, &bg); - break; + case LV_THEME_MSGBOX: + lv_obj_clean_style_list(obj, LV_MSGBOX_PART_BG); + list = lv_obj_get_style_list(obj, LV_MSGBOX_PART_BG); + lv_style_list_add_style(list, &bg); + break; - case LV_THEME_MSGBOX_BTNS: - lv_obj_clean_style_list(obj, LV_MSGBOX_PART_BTN_BG); - list = lv_obj_get_style_list(obj, LV_MSGBOX_PART_BTN_BG); - lv_style_list_add_style(list, &mbox_btn_bg); + case LV_THEME_MSGBOX_BTNS: + lv_obj_clean_style_list(obj, LV_MSGBOX_PART_BTN_BG); + list = lv_obj_get_style_list(obj, LV_MSGBOX_PART_BTN_BG); + lv_style_list_add_style(list, &mbox_btn_bg); - lv_obj_clean_style_list(obj, LV_MSGBOX_PART_BTN); - list = lv_obj_get_style_list(obj, LV_MSGBOX_PART_BTN); - lv_style_list_add_style(list, &btn); - break; + lv_obj_clean_style_list(obj, LV_MSGBOX_PART_BTN); + list = lv_obj_get_style_list(obj, LV_MSGBOX_PART_BTN); + lv_style_list_add_style(list, &btn); + break; #endif #if LV_USE_LED - case LV_THEME_LED: - lv_obj_clean_style_list(obj, LV_LED_PART_MAIN); - list = lv_obj_get_style_list(obj, LV_LED_PART_MAIN); - lv_style_list_add_style(list, &led); - break; + case LV_THEME_LED: + lv_obj_clean_style_list(obj, LV_LED_PART_MAIN); + list = lv_obj_get_style_list(obj, LV_LED_PART_MAIN); + lv_style_list_add_style(list, &led); + break; #endif #if LV_USE_PAGE - case LV_THEME_PAGE: - lv_obj_clean_style_list(obj, LV_PAGE_PART_BG); - list = lv_obj_get_style_list(obj, LV_PAGE_PART_BG); - lv_style_list_add_style(list, &panel); + case LV_THEME_PAGE: + lv_obj_clean_style_list(obj, LV_PAGE_PART_BG); + list = lv_obj_get_style_list(obj, LV_PAGE_PART_BG); + lv_style_list_add_style(list, &panel); - lv_obj_clean_style_list(obj, LV_PAGE_PART_SCRL); - list = lv_obj_get_style_list(obj, LV_PAGE_PART_SCRL); - lv_style_list_add_style(list, &pad); + lv_obj_clean_style_list(obj, LV_PAGE_PART_SCRL); + list = lv_obj_get_style_list(obj, LV_PAGE_PART_SCRL); + lv_style_list_add_style(list, &pad); - lv_obj_clean_style_list(obj, LV_PAGE_PART_SCRLBAR); - list = lv_obj_get_style_list(obj, LV_PAGE_PART_SCRLBAR); - lv_style_list_add_style(list, &sb); - break; + lv_obj_clean_style_list(obj, LV_PAGE_PART_SCRLBAR); + list = lv_obj_get_style_list(obj, LV_PAGE_PART_SCRLBAR); + lv_style_list_add_style(list, &sb); + break; #endif #if LV_USE_TABVIEW - case LV_THEME_TABVIEW: - lv_obj_clean_style_list(obj, LV_TABVIEW_PART_BG); - list = lv_obj_get_style_list(obj, LV_TABVIEW_PART_BG); - lv_style_list_add_style(list, &scr); + case LV_THEME_TABVIEW: + lv_obj_clean_style_list(obj, LV_TABVIEW_PART_BG); + list = lv_obj_get_style_list(obj, LV_TABVIEW_PART_BG); + lv_style_list_add_style(list, &scr); - lv_obj_clean_style_list(obj, LV_TABVIEW_PART_BG_SCRL); - list = lv_obj_get_style_list(obj, LV_TABVIEW_PART_BG_SCRL); + lv_obj_clean_style_list(obj, LV_TABVIEW_PART_BG_SCRL); + list = lv_obj_get_style_list(obj, LV_TABVIEW_PART_BG_SCRL); - lv_obj_clean_style_list(obj, LV_TABVIEW_PART_TAB_BG); - list = lv_obj_get_style_list(obj, LV_TABVIEW_PART_TAB_BG); - lv_style_list_add_style(list, &tabview_btns_bg); + lv_obj_clean_style_list(obj, LV_TABVIEW_PART_TAB_BG); + list = lv_obj_get_style_list(obj, LV_TABVIEW_PART_TAB_BG); + lv_style_list_add_style(list, &tabview_btns_bg); - lv_obj_clean_style_list(obj, LV_TABVIEW_PART_INDIC); - list = lv_obj_get_style_list(obj, LV_TABVIEW_PART_INDIC); - lv_style_list_add_style(list, &tabview_indic); + lv_obj_clean_style_list(obj, LV_TABVIEW_PART_INDIC); + list = lv_obj_get_style_list(obj, LV_TABVIEW_PART_INDIC); + lv_style_list_add_style(list, &tabview_indic); - lv_obj_clean_style_list(obj, LV_TABVIEW_PART_TAB); - list = lv_obj_get_style_list(obj, LV_TABVIEW_PART_TAB); - lv_style_list_add_style(list, &tabview_btns); - break; + lv_obj_clean_style_list(obj, LV_TABVIEW_PART_TAB); + list = lv_obj_get_style_list(obj, LV_TABVIEW_PART_TAB); + lv_style_list_add_style(list, &tabview_btns); + break; - case LV_THEME_TABVIEW_PAGE: - lv_obj_clean_style_list(obj, LV_PAGE_PART_BG); - list = lv_obj_get_style_list(obj, LV_PAGE_PART_BG); + case LV_THEME_TABVIEW_PAGE: + lv_obj_clean_style_list(obj, LV_PAGE_PART_BG); + list = lv_obj_get_style_list(obj, LV_PAGE_PART_BG); - lv_obj_clean_style_list(obj, LV_PAGE_PART_SCRL); - list = lv_obj_get_style_list(obj, LV_PAGE_PART_SCRL); - lv_style_list_add_style(list, &tabview_page_scrl); + lv_obj_clean_style_list(obj, LV_PAGE_PART_SCRL); + list = lv_obj_get_style_list(obj, LV_PAGE_PART_SCRL); + lv_style_list_add_style(list, &tabview_page_scrl); - break; + break; #endif #if LV_USE_TILEVIEW - case LV_THEME_TILEVIEW: - lv_obj_clean_style_list(obj, LV_TILEVIEW_PART_BG); - list = lv_obj_get_style_list(obj, LV_TILEVIEW_PART_BG); - lv_style_list_add_style(list, &scr); + case LV_THEME_TILEVIEW: + lv_obj_clean_style_list(obj, LV_TILEVIEW_PART_BG); + list = lv_obj_get_style_list(obj, LV_TILEVIEW_PART_BG); + lv_style_list_add_style(list, &scr); - lv_obj_clean_style_list(obj, LV_TILEVIEW_PART_SCRLBAR); - list = lv_obj_get_style_list(obj, LV_TILEVIEW_PART_SCRLBAR); - lv_style_list_add_style(list, &sb); + lv_obj_clean_style_list(obj, LV_TILEVIEW_PART_SCRLBAR); + list = lv_obj_get_style_list(obj, LV_TILEVIEW_PART_SCRLBAR); + lv_style_list_add_style(list, &sb); - lv_obj_clean_style_list(obj, LV_TILEVIEW_PART_EDGE_FLASH); - list = lv_obj_get_style_list(obj, LV_TILEVIEW_PART_EDGE_FLASH); - lv_style_list_add_style(list, &btn); - break; + lv_obj_clean_style_list(obj, LV_TILEVIEW_PART_EDGE_FLASH); + list = lv_obj_get_style_list(obj, LV_TILEVIEW_PART_EDGE_FLASH); + lv_style_list_add_style(list, &btn); + break; #endif #if LV_USE_ROLLER - case LV_THEME_ROLLER: - lv_obj_clean_style_list(obj, LV_ROLLER_PART_BG); - list = lv_obj_get_style_list(obj, LV_ROLLER_PART_BG); - lv_style_list_add_style(list, &roller_bg); + case LV_THEME_ROLLER: + lv_obj_clean_style_list(obj, LV_ROLLER_PART_BG); + list = lv_obj_get_style_list(obj, LV_ROLLER_PART_BG); + lv_style_list_add_style(list, &roller_bg); - lv_obj_clean_style_list(obj, LV_ROLLER_PART_SEL); - list = lv_obj_get_style_list(obj, LV_ROLLER_PART_SEL); - lv_style_list_add_style(list, &roller_sel); - break; + lv_obj_clean_style_list(obj, LV_ROLLER_PART_SEL); + list = lv_obj_get_style_list(obj, LV_ROLLER_PART_SEL); + lv_style_list_add_style(list, &roller_sel); + break; #endif #if LV_USE_OBJMASK - case LV_THEME_OBJMASK: - lv_obj_clean_style_list(obj, LV_OBJMASK_PART_MAIN); - list = lv_obj_get_style_list(obj, LV_OBJMASK_PART_MAIN); - break; + case LV_THEME_OBJMASK: + lv_obj_clean_style_list(obj, LV_OBJMASK_PART_MAIN); + list = lv_obj_get_style_list(obj, LV_OBJMASK_PART_MAIN); + break; #endif #if LV_USE_LIST - case LV_THEME_LIST: - lv_obj_clean_style_list(obj, LV_LIST_PART_BG); - list = lv_obj_get_style_list(obj, LV_LIST_PART_BG); - lv_style_list_add_style(list, &list_bg); + case LV_THEME_LIST: + lv_obj_clean_style_list(obj, LV_LIST_PART_BG); + list = lv_obj_get_style_list(obj, LV_LIST_PART_BG); + lv_style_list_add_style(list, &list_bg); - lv_obj_clean_style_list(obj, LV_LIST_PART_SCRL); - list = lv_obj_get_style_list(obj, LV_LIST_PART_SCRL); + lv_obj_clean_style_list(obj, LV_LIST_PART_SCRL); + list = lv_obj_get_style_list(obj, LV_LIST_PART_SCRL); - lv_obj_clean_style_list(obj, LV_LIST_PART_SCRLBAR); - list = lv_obj_get_style_list(obj, LV_LIST_PART_SCRLBAR); - lv_style_list_add_style(list, &sb); - break; + lv_obj_clean_style_list(obj, LV_LIST_PART_SCRLBAR); + list = lv_obj_get_style_list(obj, LV_LIST_PART_SCRLBAR); + lv_style_list_add_style(list, &sb); + break; - case LV_THEME_LIST_BTN: - lv_obj_clean_style_list(obj, LV_BTN_PART_MAIN); - list = lv_obj_get_style_list(obj, LV_BTN_PART_MAIN); - lv_style_list_add_style(list, &list_btn); - break; + case LV_THEME_LIST_BTN: + lv_obj_clean_style_list(obj, LV_BTN_PART_MAIN); + list = lv_obj_get_style_list(obj, LV_BTN_PART_MAIN); + lv_style_list_add_style(list, &list_btn); + break; #endif #if LV_USE_DROPDOWN - case LV_THEME_DROPDOWN: - lv_obj_clean_style_list(obj, LV_DROPDOWN_PART_BTN); - list = lv_obj_get_style_list(obj, LV_DROPDOWN_PART_BTN); - lv_style_list_add_style(list, &ddlist_btn); + case LV_THEME_DROPDOWN: + lv_obj_clean_style_list(obj, LV_DROPDOWN_PART_BTN); + list = lv_obj_get_style_list(obj, LV_DROPDOWN_PART_BTN); + lv_style_list_add_style(list, &ddlist_btn); - lv_obj_clean_style_list(obj, LV_DROPDOWN_PART_LIST); - list = lv_obj_get_style_list(obj, LV_DROPDOWN_PART_LIST); - lv_style_list_add_style(list, &ddlist_page); + lv_obj_clean_style_list(obj, LV_DROPDOWN_PART_LIST); + list = lv_obj_get_style_list(obj, LV_DROPDOWN_PART_LIST); + lv_style_list_add_style(list, &ddlist_page); - lv_obj_clean_style_list(obj, LV_DROPDOWN_PART_SCRLBAR); - list = lv_obj_get_style_list(obj, LV_DROPDOWN_PART_SCRLBAR); - lv_style_list_add_style(list, &sb); + lv_obj_clean_style_list(obj, LV_DROPDOWN_PART_SCRLBAR); + list = lv_obj_get_style_list(obj, LV_DROPDOWN_PART_SCRLBAR); + lv_style_list_add_style(list, &sb); - lv_obj_clean_style_list(obj, LV_DROPDOWN_PART_SELECTED); - list = lv_obj_get_style_list(obj, LV_DROPDOWN_PART_SELECTED); - lv_style_list_add_style(list, &ddlist_sel); - break; + lv_obj_clean_style_list(obj, LV_DROPDOWN_PART_SELECTED); + list = lv_obj_get_style_list(obj, LV_DROPDOWN_PART_SELECTED); + lv_style_list_add_style(list, &ddlist_sel); + break; #endif #if LV_USE_CHART - case LV_THEME_CHART: - lv_obj_clean_style_list(obj, LV_CHART_PART_BG); - list = lv_obj_get_style_list(obj, LV_CHART_PART_BG); - lv_style_list_add_style(list, &panel); + case LV_THEME_CHART: + lv_obj_clean_style_list(obj, LV_CHART_PART_BG); + list = lv_obj_get_style_list(obj, LV_CHART_PART_BG); + lv_style_list_add_style(list, &panel); - lv_obj_clean_style_list(obj, LV_CHART_PART_SERIES_BG); - list = lv_obj_get_style_list(obj, LV_CHART_PART_SERIES_BG); - lv_style_list_add_style(list, &chart_series_bg); + lv_obj_clean_style_list(obj, LV_CHART_PART_SERIES_BG); + list = lv_obj_get_style_list(obj, LV_CHART_PART_SERIES_BG); + lv_style_list_add_style(list, &chart_series_bg); - lv_obj_clean_style_list(obj, LV_CHART_PART_SERIES); - list = lv_obj_get_style_list(obj, LV_CHART_PART_SERIES); - lv_style_list_add_style(list, &chart_series); - break; + lv_obj_clean_style_list(obj, LV_CHART_PART_SERIES); + list = lv_obj_get_style_list(obj, LV_CHART_PART_SERIES); + lv_style_list_add_style(list, &chart_series); + break; #endif #if LV_USE_TABLE - case LV_THEME_TABLE: - lv_obj_clean_style_list(obj, LV_TABLE_PART_BG); - list = lv_obj_get_style_list(obj, LV_TABLE_PART_BG); + case LV_THEME_TABLE: + lv_obj_clean_style_list(obj, LV_TABLE_PART_BG); + list = lv_obj_get_style_list(obj, LV_TABLE_PART_BG); - lv_obj_clean_style_list(obj, LV_TABLE_PART_CELL1); - list = lv_obj_get_style_list(obj, LV_TABLE_PART_CELL1); - lv_style_list_add_style(list, &table_cell); + lv_obj_clean_style_list(obj, LV_TABLE_PART_CELL1); + list = lv_obj_get_style_list(obj, LV_TABLE_PART_CELL1); + lv_style_list_add_style(list, &table_cell); - lv_obj_clean_style_list(obj, LV_TABLE_PART_CELL2); - list = lv_obj_get_style_list(obj, LV_TABLE_PART_CELL2); - lv_style_list_add_style(list, &table_cell); + lv_obj_clean_style_list(obj, LV_TABLE_PART_CELL2); + list = lv_obj_get_style_list(obj, LV_TABLE_PART_CELL2); + lv_style_list_add_style(list, &table_cell); - lv_obj_clean_style_list(obj, LV_TABLE_PART_CELL3); - list = lv_obj_get_style_list(obj, LV_TABLE_PART_CELL3); - lv_style_list_add_style(list, &table_cell); + lv_obj_clean_style_list(obj, LV_TABLE_PART_CELL3); + list = lv_obj_get_style_list(obj, LV_TABLE_PART_CELL3); + lv_style_list_add_style(list, &table_cell); - lv_obj_clean_style_list(obj, LV_TABLE_PART_CELL4); - list = lv_obj_get_style_list(obj, LV_TABLE_PART_CELL4); - lv_style_list_add_style(list, &table_cell); - break; + lv_obj_clean_style_list(obj, LV_TABLE_PART_CELL4); + list = lv_obj_get_style_list(obj, LV_TABLE_PART_CELL4); + lv_style_list_add_style(list, &table_cell); + break; #endif #if LV_USE_WIN - case LV_THEME_WIN: - lv_obj_clean_style_list(obj, LV_WIN_PART_BG); - list = lv_obj_get_style_list(obj, LV_WIN_PART_BG); - lv_style_list_add_style(list, &scr); + case LV_THEME_WIN: + lv_obj_clean_style_list(obj, LV_WIN_PART_BG); + list = lv_obj_get_style_list(obj, LV_WIN_PART_BG); + lv_style_list_add_style(list, &scr); - lv_obj_clean_style_list(obj, LV_WIN_PART_SCRLBAR); - list = lv_obj_get_style_list(obj, LV_WIN_PART_SCRLBAR); - lv_style_list_add_style(list, &sb); + lv_obj_clean_style_list(obj, LV_WIN_PART_SCRLBAR); + list = lv_obj_get_style_list(obj, LV_WIN_PART_SCRLBAR); + lv_style_list_add_style(list, &sb); - lv_obj_clean_style_list(obj, LV_WIN_PART_CONTENT_SCRL); - list = lv_obj_get_style_list(obj, LV_WIN_PART_CONTENT_SCRL); - lv_style_list_add_style(list, &tabview_page_scrl); + lv_obj_clean_style_list(obj, LV_WIN_PART_CONTENT_SCRL); + list = lv_obj_get_style_list(obj, LV_WIN_PART_CONTENT_SCRL); + lv_style_list_add_style(list, &tabview_page_scrl); - lv_obj_clean_style_list(obj, LV_WIN_PART_HEADER); - list = lv_obj_get_style_list(obj, LV_WIN_PART_HEADER); - lv_style_list_add_style(list, &tabview_btns_bg); - break; + lv_obj_clean_style_list(obj, LV_WIN_PART_HEADER); + list = lv_obj_get_style_list(obj, LV_WIN_PART_HEADER); + lv_style_list_add_style(list, &tabview_btns_bg); + break; - case LV_THEME_WIN_BTN: - lv_obj_clean_style_list(obj, LV_BTN_PART_MAIN); - list = lv_obj_get_style_list(obj, LV_BTN_PART_MAIN); - lv_style_list_add_style(list, &tabview_btns); - break; + case LV_THEME_WIN_BTN: + lv_obj_clean_style_list(obj, LV_BTN_PART_MAIN); + list = lv_obj_get_style_list(obj, LV_BTN_PART_MAIN); + lv_style_list_add_style(list, &tabview_btns); + break; #endif #if LV_USE_TEXTAREA - case LV_THEME_TEXTAREA: - lv_obj_clean_style_list(obj, LV_TEXTAREA_PART_BG); - list = lv_obj_get_style_list(obj, LV_TEXTAREA_PART_BG); - lv_style_list_add_style(list, &ta_bg); + case LV_THEME_TEXTAREA: + lv_obj_clean_style_list(obj, LV_TEXTAREA_PART_BG); + list = lv_obj_get_style_list(obj, LV_TEXTAREA_PART_BG); + lv_style_list_add_style(list, &ta_bg); - lv_obj_clean_style_list(obj, LV_TEXTAREA_PART_PLACEHOLDER); - list = lv_obj_get_style_list(obj, LV_TEXTAREA_PART_PLACEHOLDER); - lv_style_list_add_style(list, &ta_placeholder); + lv_obj_clean_style_list(obj, LV_TEXTAREA_PART_PLACEHOLDER); + list = lv_obj_get_style_list(obj, LV_TEXTAREA_PART_PLACEHOLDER); + lv_style_list_add_style(list, &ta_placeholder); - lv_obj_clean_style_list(obj, LV_TEXTAREA_PART_CURSOR); - list = lv_obj_get_style_list(obj, LV_TEXTAREA_PART_CURSOR); - lv_style_list_add_style(list, &ta_cursor); + lv_obj_clean_style_list(obj, LV_TEXTAREA_PART_CURSOR); + list = lv_obj_get_style_list(obj, LV_TEXTAREA_PART_CURSOR); + lv_style_list_add_style(list, &ta_cursor); - lv_obj_clean_style_list(obj, LV_TEXTAREA_PART_SCRLBAR); - list = lv_obj_get_style_list(obj, LV_TEXTAREA_PART_SCRLBAR); - lv_style_list_add_style(list, &sb); - break; + lv_obj_clean_style_list(obj, LV_TEXTAREA_PART_SCRLBAR); + list = lv_obj_get_style_list(obj, LV_TEXTAREA_PART_SCRLBAR); + lv_style_list_add_style(list, &sb); + break; - case LV_THEME_TEXTAREA_ONELINE: - lv_obj_clean_style_list(obj, LV_TEXTAREA_PART_BG); - list = lv_obj_get_style_list(obj, LV_TEXTAREA_PART_BG); - lv_style_list_add_style(list, &ta_oneline); + case LV_THEME_TEXTAREA_ONELINE: + lv_obj_clean_style_list(obj, LV_TEXTAREA_PART_BG); + list = lv_obj_get_style_list(obj, LV_TEXTAREA_PART_BG); + lv_style_list_add_style(list, &ta_oneline); - lv_obj_clean_style_list(obj, LV_TEXTAREA_PART_PLACEHOLDER); - list = lv_obj_get_style_list(obj, LV_TEXTAREA_PART_PLACEHOLDER); - lv_style_list_add_style(list, &ta_placeholder); + lv_obj_clean_style_list(obj, LV_TEXTAREA_PART_PLACEHOLDER); + list = lv_obj_get_style_list(obj, LV_TEXTAREA_PART_PLACEHOLDER); + lv_style_list_add_style(list, &ta_placeholder); - lv_obj_clean_style_list(obj, LV_TEXTAREA_PART_CURSOR); - list = lv_obj_get_style_list(obj, LV_TEXTAREA_PART_CURSOR); - lv_style_list_add_style(list, &ta_cursor); + lv_obj_clean_style_list(obj, LV_TEXTAREA_PART_CURSOR); + list = lv_obj_get_style_list(obj, LV_TEXTAREA_PART_CURSOR); + lv_style_list_add_style(list, &ta_cursor); - lv_obj_clean_style_list(obj, LV_TEXTAREA_PART_SCRLBAR); - list = lv_obj_get_style_list(obj, LV_TEXTAREA_PART_SCRLBAR); - lv_style_list_add_style(list, &sb); - break; + lv_obj_clean_style_list(obj, LV_TEXTAREA_PART_SCRLBAR); + list = lv_obj_get_style_list(obj, LV_TEXTAREA_PART_SCRLBAR); + lv_style_list_add_style(list, &sb); + break; #endif #if LV_USE_SPINBOX - case LV_THEME_SPINBOX: - lv_obj_clean_style_list(obj, LV_SPINBOX_PART_BG); - list = lv_obj_get_style_list(obj, LV_SPINBOX_PART_BG); - lv_style_list_add_style(list, &ta_bg); + case LV_THEME_SPINBOX: + lv_obj_clean_style_list(obj, LV_SPINBOX_PART_BG); + list = lv_obj_get_style_list(obj, LV_SPINBOX_PART_BG); + lv_style_list_add_style(list, &ta_bg); - lv_obj_clean_style_list(obj, LV_SPINBOX_PART_CURSOR); - list = lv_obj_get_style_list(obj, LV_SPINBOX_PART_CURSOR); - lv_style_list_add_style(list, &spinbox_cursor); - break; + lv_obj_clean_style_list(obj, LV_SPINBOX_PART_CURSOR); + list = lv_obj_get_style_list(obj, LV_SPINBOX_PART_CURSOR); + lv_style_list_add_style(list, &spinbox_cursor); + break; - case LV_THEME_SPINBOX_BTN: - lv_obj_clean_style_list(obj, LV_BTN_PART_MAIN); - list = lv_obj_get_style_list(obj, LV_BTN_PART_MAIN); - lv_style_list_add_style(list, &spinbox_btn); - break; + case LV_THEME_SPINBOX_BTN: + lv_obj_clean_style_list(obj, LV_BTN_PART_MAIN); + list = lv_obj_get_style_list(obj, LV_BTN_PART_MAIN); + lv_style_list_add_style(list, &spinbox_btn); + break; #endif #if LV_USE_CALENDAR - case LV_THEME_CALENDAR: - lv_obj_clean_style_list(obj, LV_CALENDAR_PART_BG); - list = lv_obj_get_style_list(obj, LV_CALENDAR_PART_BG); - lv_style_list_add_style(list, &panel); + case LV_THEME_CALENDAR: + lv_obj_clean_style_list(obj, LV_CALENDAR_PART_BG); + list = lv_obj_get_style_list(obj, LV_CALENDAR_PART_BG); + lv_style_list_add_style(list, &panel); - lv_obj_clean_style_list(obj, LV_CALENDAR_PART_DATE); - list = lv_obj_get_style_list(obj, LV_CALENDAR_PART_DATE); - lv_style_list_add_style(list, &calendar_date_nums); + lv_obj_clean_style_list(obj, LV_CALENDAR_PART_DATE); + list = lv_obj_get_style_list(obj, LV_CALENDAR_PART_DATE); + lv_style_list_add_style(list, &calendar_date_nums); - lv_obj_clean_style_list(obj, LV_CALENDAR_PART_HEADER); - list = lv_obj_get_style_list(obj, LV_CALENDAR_PART_HEADER); - lv_style_list_add_style(list, &calendar_header); + lv_obj_clean_style_list(obj, LV_CALENDAR_PART_HEADER); + list = lv_obj_get_style_list(obj, LV_CALENDAR_PART_HEADER); + lv_style_list_add_style(list, &calendar_header); - lv_obj_clean_style_list(obj, LV_CALENDAR_PART_DAY_NAMES); - list = lv_obj_get_style_list(obj, LV_CALENDAR_PART_DAY_NAMES); - lv_style_list_add_style(list, &calendar_daynames); - break; + lv_obj_clean_style_list(obj, LV_CALENDAR_PART_DAY_NAMES); + list = lv_obj_get_style_list(obj, LV_CALENDAR_PART_DAY_NAMES); + lv_style_list_add_style(list, &calendar_daynames); + break; #endif #if LV_USE_CPICKER - case LV_THEME_CPICKER: - lv_obj_clean_style_list(obj, LV_CPICKER_PART_MAIN); - list = lv_obj_get_style_list(obj, LV_CPICKER_PART_MAIN); - lv_style_list_add_style(list, &cpicker_bg); + case LV_THEME_CPICKER: + lv_obj_clean_style_list(obj, LV_CPICKER_PART_MAIN); + list = lv_obj_get_style_list(obj, LV_CPICKER_PART_MAIN); + lv_style_list_add_style(list, &cpicker_bg); - lv_obj_clean_style_list(obj, LV_CPICKER_PART_INDIC); - list = lv_obj_get_style_list(obj, LV_CPICKER_PART_INDIC); - lv_style_list_add_style(list, &cpicker_indic); - break; + lv_obj_clean_style_list(obj, LV_CPICKER_PART_INDIC); + list = lv_obj_get_style_list(obj, LV_CPICKER_PART_INDIC); + lv_style_list_add_style(list, &cpicker_indic); + break; #endif #if LV_USE_LINEMETER - case LV_THEME_LINEMETER: - lv_obj_clean_style_list(obj, LV_LINEMETER_PART_MAIN); - list = lv_obj_get_style_list(obj, LV_LINEMETER_PART_MAIN); - lv_style_list_add_style(list, &lmeter); - break; + case LV_THEME_LINEMETER: + lv_obj_clean_style_list(obj, LV_LINEMETER_PART_MAIN); + list = lv_obj_get_style_list(obj, LV_LINEMETER_PART_MAIN); + lv_style_list_add_style(list, &lmeter); + break; #endif #if LV_USE_GAUGE - case LV_THEME_GAUGE: - lv_obj_clean_style_list(obj, LV_GAUGE_PART_MAIN); - list = lv_obj_get_style_list(obj, LV_GAUGE_PART_MAIN); - lv_style_list_add_style(list, &gauge_main); + case LV_THEME_GAUGE: + lv_obj_clean_style_list(obj, LV_GAUGE_PART_MAIN); + list = lv_obj_get_style_list(obj, LV_GAUGE_PART_MAIN); + lv_style_list_add_style(list, &gauge_main); - lv_obj_clean_style_list(obj, LV_GAUGE_PART_STRONG); - list = lv_obj_get_style_list(obj, LV_GAUGE_PART_STRONG); - lv_style_list_add_style(list, &gauge_strong); + lv_obj_clean_style_list(obj, LV_GAUGE_PART_STRONG); + list = lv_obj_get_style_list(obj, LV_GAUGE_PART_STRONG); + lv_style_list_add_style(list, &gauge_strong); - lv_obj_clean_style_list(obj, LV_GAUGE_PART_NEEDLE); - list = lv_obj_get_style_list(obj, LV_GAUGE_PART_NEEDLE); - lv_style_list_add_style(list, &gauge_needle); - break; + lv_obj_clean_style_list(obj, LV_GAUGE_PART_NEEDLE); + list = lv_obj_get_style_list(obj, LV_GAUGE_PART_NEEDLE); + lv_style_list_add_style(list, &gauge_needle); + break; #endif default: break; @@ -1407,96 +1408,96 @@ lv_style_list_add_style(list, &bar_bg); static inline lv_color_t color_scr(lv_state_t state) { switch(state) { - case LV_STATE_DEFAULT: - case LV_STATE_PRESSED: - case LV_STATE_CHECKED: - case LV_STATE_FOCUSED: - case LV_STATE_EDITED: - case LV_STATE_HOVERED: - case LV_STATE_DISABLED: - default: - return lv_color_hex(0x22252a); + case LV_STATE_DEFAULT: + case LV_STATE_PRESSED: + case LV_STATE_CHECKED: + case LV_STATE_FOCUSED: + case LV_STATE_EDITED: + case LV_STATE_HOVERED: + case LV_STATE_DISABLED: + default: + return lv_color_hex(0x22252a); } } static inline lv_color_t color_panel(lv_state_t state) { switch(state) { - case LV_STATE_DEFAULT: - case LV_STATE_PRESSED: - case LV_STATE_CHECKED: - case LV_STATE_FOCUSED: - case LV_STATE_EDITED: - case LV_STATE_HOVERED: - case LV_STATE_DISABLED: - default: - return lv_color_hex(0x282b30); + case LV_STATE_DEFAULT: + case LV_STATE_PRESSED: + case LV_STATE_CHECKED: + case LV_STATE_FOCUSED: + case LV_STATE_EDITED: + case LV_STATE_HOVERED: + case LV_STATE_DISABLED: + default: + return lv_color_hex(0x282b30); } } static inline lv_color_t color_bg(lv_state_t state) { switch(state) { - case LV_STATE_DEFAULT: - case LV_STATE_PRESSED: - case LV_STATE_CHECKED: - case LV_STATE_FOCUSED: - case LV_STATE_EDITED: - case LV_STATE_HOVERED: - case LV_STATE_DISABLED: - default: - return lv_color_hex(0x2f3237); + case LV_STATE_DEFAULT: + case LV_STATE_PRESSED: + case LV_STATE_CHECKED: + case LV_STATE_FOCUSED: + case LV_STATE_EDITED: + case LV_STATE_HOVERED: + case LV_STATE_DISABLED: + default: + return lv_color_hex(0x2f3237); } } static inline lv_color_t color_btn(lv_state_t state) { switch(state) { - case LV_STATE_DEFAULT: - return lv_color_hex(0x303439); - case LV_STATE_PRESSED: - return lv_color_hex(0x43484f); - case LV_STATE_CHECKED: - return _color_primary; - case LV_STATE_CHECKED | LV_STATE_PRESSED: - return lv_color_lighten(_color_primary, LV_OPA_20); - case LV_STATE_FOCUSED: - case LV_STATE_EDITED: - case LV_STATE_HOVERED: - case LV_STATE_DISABLED: - default: - return _color_primary; + case LV_STATE_DEFAULT: + return lv_color_hex(0x303439); + case LV_STATE_PRESSED: + return lv_color_hex(0x43484f); + case LV_STATE_CHECKED: + return _color_primary; + case LV_STATE_CHECKED | LV_STATE_PRESSED: + return lv_color_lighten(_color_primary, LV_OPA_20); + case LV_STATE_FOCUSED: + case LV_STATE_EDITED: + case LV_STATE_HOVERED: + case LV_STATE_DISABLED: + default: + return _color_primary; } } static inline lv_color_t color_scr_border(lv_state_t state) { switch(state) { - case LV_STATE_DEFAULT: - case LV_STATE_PRESSED: - case LV_STATE_CHECKED: - case LV_STATE_FOCUSED: - case LV_STATE_EDITED: - case LV_STATE_HOVERED: - case LV_STATE_DISABLED: - default: - return lv_color_hex(0x555555); + case LV_STATE_DEFAULT: + case LV_STATE_PRESSED: + case LV_STATE_CHECKED: + case LV_STATE_FOCUSED: + case LV_STATE_EDITED: + case LV_STATE_HOVERED: + case LV_STATE_DISABLED: + default: + return lv_color_hex(0x555555); } } static inline lv_color_t color_panel_border(lv_state_t state) { switch(state) { - case LV_STATE_DEFAULT: - case LV_STATE_PRESSED: - case LV_STATE_CHECKED: - case LV_STATE_EDITED: - case LV_STATE_HOVERED: - case LV_STATE_DISABLED: - default: - return lv_color_hex(0x3b3e42); - case LV_STATE_FOCUSED: - return _color_primary; + case LV_STATE_DEFAULT: + case LV_STATE_PRESSED: + case LV_STATE_CHECKED: + case LV_STATE_EDITED: + case LV_STATE_HOVERED: + case LV_STATE_DISABLED: + default: + return lv_color_hex(0x3b3e42); + case LV_STATE_FOCUSED: + return _color_primary; } } @@ -1504,33 +1505,33 @@ static inline lv_color_t color_panel_border(lv_state_t state) static inline lv_color_t color_bg_border(lv_state_t state) { switch(state) { - case LV_STATE_DEFAULT: - return lv_color_hex(0x606060); - case LV_STATE_PRESSED: - return lv_color_hex(0x404040); - case LV_STATE_CHECKED: - case LV_STATE_FOCUSED: - case LV_STATE_EDITED: - case LV_STATE_HOVERED: - case LV_STATE_DISABLED: - default: - return lv_color_hex(0x606060); + case LV_STATE_DEFAULT: + return lv_color_hex(0x606060); + case LV_STATE_PRESSED: + return lv_color_hex(0x404040); + case LV_STATE_CHECKED: + case LV_STATE_FOCUSED: + case LV_STATE_EDITED: + case LV_STATE_HOVERED: + case LV_STATE_DISABLED: + default: + return lv_color_hex(0x606060); } } static inline lv_color_t color_btn_border(lv_state_t state) { switch(state) { - case LV_STATE_DEFAULT: - case LV_STATE_PRESSED: - return lv_color_hex(0x606060); - case LV_STATE_CHECKED: - case LV_STATE_FOCUSED: - case LV_STATE_EDITED: - case LV_STATE_HOVERED: - case LV_STATE_DISABLED: - default: - return LV_COLOR_RED; + case LV_STATE_DEFAULT: + case LV_STATE_PRESSED: + return lv_color_hex(0x606060); + case LV_STATE_CHECKED: + case LV_STATE_FOCUSED: + case LV_STATE_EDITED: + case LV_STATE_HOVERED: + case LV_STATE_DISABLED: + default: + return LV_COLOR_RED; } } @@ -1538,30 +1539,30 @@ static inline lv_color_t color_btn_border(lv_state_t state) static inline lv_color_t color_scr_txt(lv_state_t state) { switch(state) { - case LV_STATE_DEFAULT: - case LV_STATE_PRESSED: - case LV_STATE_CHECKED: - case LV_STATE_FOCUSED: - case LV_STATE_EDITED: - case LV_STATE_HOVERED: - case LV_STATE_DISABLED: - default: - return lv_color_hex(0xbababa); + case LV_STATE_DEFAULT: + case LV_STATE_PRESSED: + case LV_STATE_CHECKED: + case LV_STATE_FOCUSED: + case LV_STATE_EDITED: + case LV_STATE_HOVERED: + case LV_STATE_DISABLED: + default: + return lv_color_hex(0xbababa); } } static inline lv_color_t color_panel_txt(lv_state_t state) { switch(state) { - case LV_STATE_DEFAULT: - case LV_STATE_PRESSED: - case LV_STATE_CHECKED: - case LV_STATE_FOCUSED: - case LV_STATE_EDITED: - case LV_STATE_HOVERED: - case LV_STATE_DISABLED: - default: - return lv_color_hex(0xa5a8ad); + case LV_STATE_DEFAULT: + case LV_STATE_PRESSED: + case LV_STATE_CHECKED: + case LV_STATE_FOCUSED: + case LV_STATE_EDITED: + case LV_STATE_HOVERED: + case LV_STATE_DISABLED: + default: + return lv_color_hex(0xa5a8ad); } } @@ -1569,32 +1570,32 @@ static inline lv_color_t color_panel_txt(lv_state_t state) static inline lv_color_t color_bg_txt(lv_state_t state) { switch(state) { - case LV_STATE_DEFAULT: - case LV_STATE_PRESSED: - case LV_STATE_CHECKED: - case LV_STATE_FOCUSED: - case LV_STATE_EDITED: - case LV_STATE_HOVERED: - case LV_STATE_DISABLED: - default: - return lv_color_hex(0xa5a8ad); + case LV_STATE_DEFAULT: + case LV_STATE_PRESSED: + case LV_STATE_CHECKED: + case LV_STATE_FOCUSED: + case LV_STATE_EDITED: + case LV_STATE_HOVERED: + case LV_STATE_DISABLED: + default: + return lv_color_hex(0xa5a8ad); } } static inline lv_color_t color_btn_txt(lv_state_t state) { switch(state) { - case LV_STATE_DEFAULT: - case LV_STATE_PRESSED: - case LV_STATE_CHECKED: - case LV_STATE_FOCUSED: - case LV_STATE_EDITED: - case LV_STATE_HOVERED: - return lv_color_hex(0xffffff); - case LV_STATE_DISABLED: - return lv_color_hex(0x888888); - default: - return lv_color_hex(0xffffff); + case LV_STATE_DEFAULT: + case LV_STATE_PRESSED: + case LV_STATE_CHECKED: + case LV_STATE_FOCUSED: + case LV_STATE_EDITED: + case LV_STATE_HOVERED: + return lv_color_hex(0xffffff); + case LV_STATE_DISABLED: + return lv_color_hex(0x888888); + default: + return lv_color_hex(0xffffff); } } diff --git a/src/lv_themes/lv_theme_material.h b/src/lv_themes/lv_theme_material.h index cc9cb9727..b242cf6d5 100644 --- a/src/lv_themes/lv_theme_material.h +++ b/src/lv_themes/lv_theme_material.h @@ -43,7 +43,7 @@ extern "C" { * @return a pointer to reference this theme later */ lv_theme_t * lv_theme_material_init(lv_color_t color_primary, lv_color_t color_secondary, uint32_t flags, - lv_font_t * font_small, lv_font_t * font_normal, lv_font_t * font_subtitle, lv_font_t * font_title); + lv_font_t * font_small, lv_font_t * font_normal, lv_font_t * font_subtitle, lv_font_t * font_title); /********************** * MACROS **********************/ diff --git a/src/lv_widgets/lv_arc.c b/src/lv_widgets/lv_arc.c index bd91f0437..e4b72e265 100644 --- a/src/lv_widgets/lv_arc.c +++ b/src/lv_widgets/lv_arc.c @@ -169,11 +169,11 @@ void lv_arc_set_end_angle(lv_obj_t * arc, int16_t end) lv_obj_invalidate(arc); } /*Only a smaller incremental move*/ - else if(ext->arc_angle_end > ext->arc_angle_start && end > ext->arc_angle_start ) { + else if(ext->arc_angle_end > ext->arc_angle_start && end > ext->arc_angle_start) { inv_arc_area(arc, LV_MATH_MIN(ext->arc_angle_end, end), LV_MATH_MAX(ext->arc_angle_end, end)); } /*Only a smaller incremental move*/ - else if(ext->arc_angle_end < ext->arc_angle_start && end < ext->arc_angle_start ) { + else if(ext->arc_angle_end < ext->arc_angle_start && end < ext->arc_angle_start) { inv_arc_area(arc, LV_MATH_MIN(ext->arc_angle_end, end), LV_MATH_MAX(ext->arc_angle_end, end)); } /*Crossing the end angle makes the whole arc change*/ @@ -181,7 +181,7 @@ void lv_arc_set_end_angle(lv_obj_t * arc, int16_t end) lv_obj_invalidate(arc); } - ext->arc_angle_end= end; + ext->arc_angle_end = end; } @@ -259,11 +259,11 @@ void lv_arc_set_bg_end_angle(lv_obj_t * arc, int16_t end) lv_obj_invalidate(arc); } /*Only a smaller incremental move*/ - else if(ext->bg_angle_end > ext->bg_angle_start && end > ext->bg_angle_start ) { + else if(ext->bg_angle_end > ext->bg_angle_start && end > ext->bg_angle_start) { inv_arc_area(arc, LV_MATH_MIN(ext->bg_angle_end, end), LV_MATH_MAX(ext->bg_angle_end, end)); } /*Only a smaller incremental move*/ - else if(ext->bg_angle_end < ext->bg_angle_start && end < ext->bg_angle_start ) { + else if(ext->bg_angle_end < ext->bg_angle_start && end < ext->bg_angle_start) { inv_arc_area(arc, LV_MATH_MIN(ext->bg_angle_end, end), LV_MATH_MAX(ext->bg_angle_end, end)); } /*Crossing the end angle makes the whole arc change*/ @@ -271,7 +271,7 @@ void lv_arc_set_bg_end_angle(lv_obj_t * arc, int16_t end) lv_obj_invalidate(arc); } - ext->bg_angle_end= end; + ext->bg_angle_end = end; } /** @@ -439,14 +439,14 @@ static lv_style_list_t * lv_arc_get_style(lv_obj_t * arc, uint8_t part) lv_style_list_t * style_dsc_p; switch(part) { - case LV_ARC_PART_BG: - style_dsc_p = &arc->style_list; - break; - case LV_ARC_PART_ARC: - style_dsc_p = &ext->style_arc; - break; - default: - style_dsc_p = NULL; + case LV_ARC_PART_BG: + style_dsc_p = &arc->style_list; + break; + case LV_ARC_PART_ARC: + style_dsc_p = &ext->style_arc; + break; + default: + style_dsc_p = NULL; } return style_dsc_p; @@ -513,32 +513,41 @@ static void inv_arc_area(lv_obj_t * arc, uint16_t start_angle, uint16_t end_angl lv_obj_invalidate_area(arc, &inv_area); } - } else if(start_quarter == 0 && end_quarter == 1) { + } + else if(start_quarter == 0 && end_quarter == 1) { inv_area.x1 = x + ((lv_trigo_sin(end_angle + 90) * rout) >> LV_TRIGO_SHIFT) - extra_area; - inv_area.y1 = y + ((LV_MATH_MIN(lv_trigo_sin(end_angle), lv_trigo_sin(start_angle)) * rin) >> LV_TRIGO_SHIFT) - extra_area; + inv_area.y1 = y + ((LV_MATH_MIN(lv_trigo_sin(end_angle), + lv_trigo_sin(start_angle)) * rin) >> LV_TRIGO_SHIFT) - extra_area; inv_area.x2 = x + ((lv_trigo_sin(start_angle + 90) * rout) >> LV_TRIGO_SHIFT) + extra_area; inv_area.y2 = y + rout + extra_area; lv_obj_invalidate_area(arc, &inv_area); - } else if(start_quarter == 1 && end_quarter == 2) { + } + else if(start_quarter == 1 && end_quarter == 2) { inv_area.x1 = x - rout - extra_area; inv_area.y1 = y + ((lv_trigo_sin(end_angle) * rout) >> LV_TRIGO_SHIFT) - extra_area; - inv_area.x2 = x + ((LV_MATH_MAX(lv_trigo_sin(start_angle + 90) , lv_trigo_sin(end_angle + 90)) * rin) >> LV_TRIGO_SHIFT) + extra_area; + inv_area.x2 = x + ((LV_MATH_MAX(lv_trigo_sin(start_angle + 90), + lv_trigo_sin(end_angle + 90)) * rin) >> LV_TRIGO_SHIFT) + extra_area; inv_area.y2 = y + ((lv_trigo_sin(start_angle) * rout) >> LV_TRIGO_SHIFT) + extra_area; lv_obj_invalidate_area(arc, &inv_area); - } else if(start_quarter == 2 && end_quarter == 3) { + } + else if(start_quarter == 2 && end_quarter == 3) { inv_area.x1 = x + ((lv_trigo_sin(start_angle + 90) * rout) >> LV_TRIGO_SHIFT) - extra_area; inv_area.y1 = y - rout - extra_area; inv_area.x2 = x + ((lv_trigo_sin(end_angle + 90) * rout) >> LV_TRIGO_SHIFT) + extra_area; - inv_area.y2 = y + (LV_MATH_MAX(lv_trigo_sin(end_angle) * rin, lv_trigo_sin(start_angle) * rin) >> LV_TRIGO_SHIFT) + extra_area; + inv_area.y2 = y + (LV_MATH_MAX(lv_trigo_sin(end_angle) * rin, + lv_trigo_sin(start_angle) * rin) >> LV_TRIGO_SHIFT) + extra_area; lv_obj_invalidate_area(arc, &inv_area); - } else if(start_quarter == 3 && end_quarter == 0) { - inv_area.x1 = x + ((LV_MATH_MIN(lv_trigo_sin(end_angle + 90), lv_trigo_sin(start_angle + 90)) * rin) >> LV_TRIGO_SHIFT) - extra_area; + } + else if(start_quarter == 3 && end_quarter == 0) { + inv_area.x1 = x + ((LV_MATH_MIN(lv_trigo_sin(end_angle + 90), + lv_trigo_sin(start_angle + 90)) * rin) >> LV_TRIGO_SHIFT) - extra_area; inv_area.y1 = y + ((lv_trigo_sin(start_angle) * rout) >> LV_TRIGO_SHIFT) - extra_area; inv_area.x2 = x + rout + extra_area; inv_area.y2 = y + ((lv_trigo_sin(end_angle) * rout) >> LV_TRIGO_SHIFT) + extra_area; lv_obj_invalidate_area(arc, &inv_area); - } else { + } + else { lv_obj_invalidate(arc); } } diff --git a/src/lv_widgets/lv_arc.h b/src/lv_widgets/lv_arc.h index 91d0d3130..2bae946e2 100644 --- a/src/lv_widgets/lv_arc.h +++ b/src/lv_widgets/lv_arc.h @@ -27,8 +27,7 @@ extern "C" { * TYPEDEFS **********************/ /*Data of arc*/ -typedef struct -{ +typedef struct { /*New data for this type */ lv_coord_t arc_angle_start; lv_coord_t arc_angle_end; diff --git a/src/lv_widgets/lv_bar.c b/src/lv_widgets/lv_bar.c index cbb2b8eeb..927915e30 100644 --- a/src/lv_widgets/lv_bar.c +++ b/src/lv_widgets/lv_bar.c @@ -26,10 +26,10 @@ #define LV_BAR_SIZE_MIN 4 /*hor. pad and ver. pad cannot make the indicator smaller then this [px]*/ #if LV_USE_ANIMATION -#define LV_BAR_IS_ANIMATING(anim_struct) (((anim_struct).anim_state) != LV_BAR_ANIM_STATE_INV) -#define LV_BAR_GET_ANIM_VALUE(orig_value, anim_struct) (LV_BAR_IS_ANIMATING(anim_struct) ? ((anim_struct).anim_end) : (orig_value)) + #define LV_BAR_IS_ANIMATING(anim_struct) (((anim_struct).anim_state) != LV_BAR_ANIM_STATE_INV) + #define LV_BAR_GET_ANIM_VALUE(orig_value, anim_struct) (LV_BAR_IS_ANIMATING(anim_struct) ? ((anim_struct).anim_end) : (orig_value)) #else -#define LV_BAR_GET_ANIM_VALUE(orig_value, anim_struct) (orig_value) + #define LV_BAR_GET_ANIM_VALUE(orig_value, anim_struct) (orig_value) #endif /********************** * TYPEDEFS @@ -46,10 +46,11 @@ static void draw_bg(lv_obj_t * bar, const lv_area_t * clip_area); static void draw_indic(lv_obj_t * bar, const lv_area_t * clip_area); #if LV_USE_ANIMATION -static void lv_bar_set_value_with_anim(lv_obj_t * bar, int16_t new_value, int16_t *value_ptr, lv_bar_anim_t *anim_info, lv_anim_enable_t en); -static void lv_bar_init_anim(lv_obj_t * bar, lv_bar_anim_t * bar_anim); -static void lv_bar_anim(lv_bar_anim_t * bar, lv_anim_value_t value); -static void lv_bar_anim_ready(lv_anim_t * a); + static void lv_bar_set_value_with_anim(lv_obj_t * bar, int16_t new_value, int16_t * value_ptr, + lv_bar_anim_t * anim_info, lv_anim_enable_t en); + static void lv_bar_init_anim(lv_obj_t * bar, lv_bar_anim_t * bar_anim); + static void lv_bar_anim(lv_bar_anim_t * bar, lv_anim_value_t value); + static void lv_bar_anim_ready(lv_anim_t * a); #endif /********************** @@ -93,13 +94,13 @@ lv_obj_t * lv_bar_create(lv_obj_t * par, const lv_obj_t * copy) } ext->min_value = 0; - ext->start_value = 0; + ext->start_value = 0; ext->max_value = 100; ext->cur_value = 0; #if LV_USE_ANIMATION ext->anim_time = 200; - lv_bar_init_anim(bar, &ext->cur_value_anim); - lv_bar_init_anim(bar, &ext->start_value_anim); + lv_bar_init_anim(bar, &ext->cur_value_anim); + lv_bar_init_anim(bar, &ext->start_value_anim); #endif ext->type = LV_BAR_TYPE_NORMAL; @@ -117,10 +118,11 @@ lv_obj_t * lv_bar_create(lv_obj_t * par, const lv_obj_t * copy) lv_bar_set_value(bar, ext->cur_value, false); lv_theme_apply(bar, LV_THEME_BAR); - } else { + } + else { lv_bar_ext_t * ext_copy = lv_obj_get_ext_attr(copy); ext->min_value = ext_copy->min_value; - ext->start_value = ext_copy->start_value; + ext->start_value = ext_copy->start_value; ext->max_value = ext_copy->max_value; ext->cur_value = ext_copy->cur_value; ext->type = ext_copy->type; @@ -164,7 +166,7 @@ void lv_bar_set_value(lv_obj_t * bar, int16_t value, lv_anim_enable_t anim) ext->cur_value = new_value; lv_obj_invalidate(bar); #else - lv_bar_set_value_with_anim(bar, new_value, &ext->cur_value, &ext->cur_value_anim, anim); + lv_bar_set_value_with_anim(bar, new_value, &ext->cur_value, &ext->cur_value_anim, anim); #endif } @@ -189,7 +191,7 @@ void lv_bar_set_start_value(lv_obj_t * bar, int16_t start_value, lv_anim_enable_ #if LV_USE_ANIMATION == 0 ext->start_value = new_value; #else - lv_bar_set_value_with_anim(bar, new_value, &ext->start_value, &ext->start_value_anim, anim); + lv_bar_set_value_with_anim(bar, new_value, &ext->start_value, &ext->start_value_anim, anim); #endif } @@ -230,14 +232,14 @@ void lv_bar_set_range(lv_obj_t * bar, int16_t min, int16_t max) */ void lv_bar_set_type(lv_obj_t * bar, lv_bar_type_t type) { - LV_ASSERT_OBJ(bar, LV_OBJX_NAME); + LV_ASSERT_OBJ(bar, LV_OBJX_NAME); lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar); - ext->type = type; - if(ext->type != LV_BAR_TYPE_CUSTOM) - ext->start_value = ext->min_value; + ext->type = type; + if(ext->type != LV_BAR_TYPE_CUSTOM) + ext->start_value = ext->min_value; - lv_obj_invalidate(bar); + lv_obj_invalidate(bar); } /** @@ -286,7 +288,7 @@ int16_t lv_bar_get_start_value(const lv_obj_t * bar) lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar); - if(ext->type != LV_BAR_TYPE_CUSTOM) return ext->min_value; + if(ext->type != LV_BAR_TYPE_CUSTOM) return ext->min_value; return LV_BAR_GET_ANIM_VALUE(ext->start_value, ext->start_value_anim); } @@ -322,11 +324,12 @@ int16_t lv_bar_get_max_value(const lv_obj_t * bar) * @param bar pointer to bar object * @return bar type */ -lv_bar_type_t lv_bar_get_type(lv_obj_t * bar) { - LV_ASSERT_OBJ(bar, LV_OBJX_NAME); +lv_bar_type_t lv_bar_get_type(lv_obj_t * bar) +{ + LV_ASSERT_OBJ(bar, LV_OBJX_NAME); lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar); - return ext->type; + return ext->type; } /** @@ -367,7 +370,8 @@ static lv_design_res_t lv_bar_design(lv_obj_t * bar, const lv_area_t * clip_area if(mode == LV_DESIGN_COVER_CHK) { /*Return false if the object is not covers the mask area*/ return ancestor_design_f(bar, clip_area, mode); - } else if(mode == LV_DESIGN_DRAW_MAIN) { + } + else if(mode == LV_DESIGN_DRAW_MAIN) { draw_bg(bar, clip_area); draw_indic(bar, clip_area); @@ -382,7 +386,8 @@ static lv_design_res_t lv_bar_design(lv_obj_t * bar, const lv_area_t * clip_area lv_obj_init_draw_rect_dsc(bar, LV_BAR_PART_BG, &draw_dsc); lv_draw_rect(&bar->coords, clip_area, &draw_dsc); - } else if(mode == LV_DESIGN_DRAW_POST) { + } + else if(mode == LV_DESIGN_DRAW_POST) { } return LV_DESIGN_RES_OK; @@ -407,7 +412,8 @@ static void draw_indic(lv_obj_t * bar, const lv_area_t * clip_area) int32_t range = ext->max_value - ext->min_value; bool hor = objw >= objh ? true : false; bool sym = false; - if(ext->type == LV_BAR_TYPE_SYM && ext->min_value < 0 && ext->max_value > 0 && ext->start_value == ext->min_value) sym = true; + if(ext->type == LV_BAR_TYPE_SYM && ext->min_value < 0 && ext->max_value > 0 && + ext->start_value == ext->min_value) sym = true; /*Calculate the indicator area*/ lv_style_int_t bg_left = lv_obj_get_style_pad_left(bar, LV_BAR_PART_BG); @@ -425,7 +431,8 @@ static void draw_indic(lv_obj_t * bar, const lv_area_t * clip_area) if(hor && lv_area_get_height(&ext->indic_area) < LV_BAR_SIZE_MIN) { ext->indic_area.y1 = bar->coords.y1 + (objh / 2) - (LV_BAR_SIZE_MIN / 2); ext->indic_area.y2 = ext->indic_area.y1 + LV_BAR_SIZE_MIN; - } else if(!hor && lv_area_get_width(&ext->indic_area) < LV_BAR_SIZE_MIN) { + } + else if(!hor && lv_area_get_width(&ext->indic_area) < LV_BAR_SIZE_MIN) { ext->indic_area.x1 = bar->coords.x1 + (objw / 2) - (LV_BAR_SIZE_MIN / 2); ext->indic_area.x2 = ext->indic_area.x1 + LV_BAR_SIZE_MIN; } @@ -439,13 +446,14 @@ static void draw_indic(lv_obj_t * bar, const lv_area_t * clip_area) lv_coord_t anim_cur_value_x, anim_start_value_x; lv_coord_t * axis1, * axis2; - lv_coord_t (*indic_length_calc)(const lv_area_t *area); + lv_coord_t (*indic_length_calc)(const lv_area_t * area); if(hor) { axis1 = &ext->indic_area.x1; axis2 = &ext->indic_area.x2; indic_length_calc = lv_area_get_width; - } else { + } + else { axis1 = &ext->indic_area.y1; axis2 = &ext->indic_area.y2; indic_length_calc = lv_area_get_height; @@ -457,12 +465,14 @@ static void draw_indic(lv_obj_t * bar, const lv_area_t * clip_area) (int32_t)((int32_t)anim_length * (ext->start_value_anim.anim_start - ext->min_value)) / range; lv_coord_t anim_start_value_end_x = (int32_t)((int32_t)anim_length * (ext->start_value_anim.anim_end - ext->min_value)) / range; - - anim_start_value_x = (((anim_start_value_end_x - anim_start_value_start_x) * ext->start_value_anim.anim_state) / LV_BAR_ANIM_STATE_END); + + anim_start_value_x = (((anim_start_value_end_x - anim_start_value_start_x) * ext->start_value_anim.anim_state) / + LV_BAR_ANIM_STATE_END); if(anim_start_value_end_x < anim_start_value_start_x) anim_start_value_x += anim_start_value_start_x; - } else + } + else #endif { anim_start_value_x = (int32_t)((int32_t)anim_length * (ext->start_value - ext->min_value)) / range; @@ -474,12 +484,14 @@ static void draw_indic(lv_obj_t * bar, const lv_area_t * clip_area) (int32_t)((int32_t)anim_length * (ext->cur_value_anim.anim_start - ext->min_value)) / range; lv_coord_t anim_cur_value_end_x = (int32_t)((int32_t)anim_length * (ext->cur_value_anim.anim_end - ext->min_value)) / range; - - anim_cur_value_x = (((anim_cur_value_end_x - anim_cur_value_start_x) * ext->cur_value_anim.anim_state) / LV_BAR_ANIM_STATE_END); + + anim_cur_value_x = (((anim_cur_value_end_x - anim_cur_value_start_x) * ext->cur_value_anim.anim_state) / + LV_BAR_ANIM_STATE_END); if(anim_cur_value_end_x < anim_cur_value_start_x) anim_cur_value_x += anim_cur_value_start_x; - } else + } + else #endif { anim_cur_value_x = (int32_t)((int32_t)anim_length * (ext->cur_value - ext->min_value)) / range; @@ -489,7 +501,8 @@ static void draw_indic(lv_obj_t * bar, const lv_area_t * clip_area) if(hor) { *axis2 = *axis1 + anim_cur_value_x; *axis1 += anim_start_value_x; - } else { + } + else { *axis2 -= anim_start_value_x; *axis1 = *axis2 - anim_cur_value_x; } @@ -521,7 +534,7 @@ static void draw_indic(lv_obj_t * bar, const lv_area_t * clip_area) * The radius of the bg and the indicator can make a strange shape where * it'd be very difficult to draw shadow. */ if((hor && lv_area_get_width(&ext->indic_area) > bg_radius * 2) || - (!hor && lv_area_get_height(&ext->indic_area) > bg_radius * 2)) { + (!hor && lv_area_get_height(&ext->indic_area) > bg_radius * 2)) { lv_opa_t bg_opa = draw_indic_dsc.bg_opa; lv_opa_t border_opa = draw_indic_dsc.border_opa; lv_opa_t value_opa = draw_indic_dsc.border_opa; @@ -560,7 +573,8 @@ static void draw_indic(lv_obj_t * bar, const lv_area_t * clip_area) if(hor && lv_area_get_height(&mask_indic_max_area) < LV_BAR_SIZE_MIN) { mask_indic_max_area.y1 = bar->coords.y1 + (objh / 2) - (LV_BAR_SIZE_MIN / 2); mask_indic_max_area.y2 = mask_indic_max_area.y1 + LV_BAR_SIZE_MIN; - } else if(!hor && lv_area_get_width(&mask_indic_max_area) < LV_BAR_SIZE_MIN) { + } + else if(!hor && lv_area_get_width(&mask_indic_max_area) < LV_BAR_SIZE_MIN) { mask_indic_max_area.x1 = bar->coords.x1 + (objw / 2) - (LV_BAR_SIZE_MIN / 2); mask_indic_max_area.x2 = mask_indic_max_area.x1 + LV_BAR_SIZE_MIN; } @@ -623,14 +637,14 @@ static lv_res_t lv_bar_signal(lv_obj_t * bar, lv_signal_t sign, void * param) bar->ext_draw_pad = LV_MATH_MAX(bar->ext_draw_pad, indic_size); } - if(sign == LV_SIGNAL_CLEANUP) { + if(sign == LV_SIGNAL_CLEANUP) { lv_obj_clean_style_list(bar, LV_BAR_PART_INDIC); #if LV_USE_ANIMATION - lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar); - lv_anim_del(&ext->cur_value_anim, NULL); - lv_anim_del(&ext->start_value_anim, NULL); + lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar); + lv_anim_del(&ext->cur_value_anim, NULL); + lv_anim_del(&ext->start_value_anim, NULL); #endif - } + } return res; } @@ -643,14 +657,14 @@ static lv_style_list_t * lv_bar_get_style(lv_obj_t * bar, uint8_t part) lv_style_list_t * style_dsc_p; switch(part) { - case LV_BAR_PART_BG: - style_dsc_p = &bar->style_list; - break; - case LV_BAR_PART_INDIC: - style_dsc_p = &ext->style_indic; - break; - default: - style_dsc_p = NULL; + case LV_BAR_PART_BG: + style_dsc_p = &bar->style_list; + break; + case LV_BAR_PART_INDIC: + style_dsc_p = &ext->style_indic; + break; + default: + style_dsc_p = NULL; } return style_dsc_p; @@ -665,22 +679,25 @@ static void lv_bar_anim(lv_bar_anim_t * var, lv_anim_value_t value) static void lv_bar_anim_ready(lv_anim_t * a) { - lv_bar_anim_t * var = a->var; - lv_bar_ext_t * ext = lv_obj_get_ext_attr(var->bar); + lv_bar_anim_t * var = a->var; + lv_bar_ext_t * ext = lv_obj_get_ext_attr(var->bar); var->anim_state = LV_BAR_ANIM_STATE_INV; - if(var == &ext->cur_value_anim) - ext->cur_value = var->anim_end; - else if(var == &ext->start_value_anim) - ext->start_value = var->anim_end; - lv_obj_invalidate(var->bar); + if(var == &ext->cur_value_anim) + ext->cur_value = var->anim_end; + else if(var == &ext->start_value_anim) + ext->start_value = var->anim_end; + lv_obj_invalidate(var->bar); } -static void lv_bar_set_value_with_anim(lv_obj_t * bar, int16_t new_value, int16_t *value_ptr, lv_bar_anim_t *anim_info, lv_anim_enable_t en) { +static void lv_bar_set_value_with_anim(lv_obj_t * bar, int16_t new_value, int16_t * value_ptr, + lv_bar_anim_t * anim_info, lv_anim_enable_t en) +{ if(en == LV_ANIM_OFF) { *value_ptr = new_value; lv_obj_invalidate(bar); - } else { - lv_bar_ext_t *ext = lv_obj_get_ext_attr(bar); + } + else { + lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar); /*No animation in progress -> simply set the values*/ if(anim_info->anim_state == LV_BAR_ANIM_STATE_INV) { anim_info->anim_start = *value_ptr; @@ -691,8 +708,8 @@ static void lv_bar_set_value_with_anim(lv_obj_t * bar, int16_t new_value, int16_ anim_info->anim_start = anim_info->anim_end; anim_info->anim_end = new_value; } - /* Stop the previous animation if it exists */ - lv_anim_del(anim_info, NULL); + /* Stop the previous animation if it exists */ + lv_anim_del(anim_info, NULL); lv_anim_t a; lv_anim_init(&a); @@ -709,10 +726,10 @@ static void lv_bar_set_value_with_anim(lv_obj_t * bar, int16_t new_value, int16_ static void lv_bar_init_anim(lv_obj_t * bar, lv_bar_anim_t * bar_anim) { - bar_anim->bar = bar; - bar_anim->anim_start = 0; - bar_anim->anim_end = 0; - bar_anim->anim_state = LV_BAR_ANIM_STATE_INV; + bar_anim->bar = bar; + bar_anim->anim_start = 0; + bar_anim->anim_end = 0; + bar_anim->anim_state = LV_BAR_ANIM_STATE_INV; } #endif diff --git a/src/lv_widgets/lv_bar.h b/src/lv_widgets/lv_bar.h index 248ef6572..286311e69 100644 --- a/src/lv_widgets/lv_bar.h +++ b/src/lv_widgets/lv_bar.h @@ -44,24 +44,23 @@ extern "C" { **********************/ enum { - LV_BAR_TYPE_NORMAL, - LV_BAR_TYPE_SYM, - LV_BAR_TYPE_CUSTOM + LV_BAR_TYPE_NORMAL, + LV_BAR_TYPE_SYM, + LV_BAR_TYPE_CUSTOM }; typedef uint8_t lv_bar_type_t; #if LV_USE_ANIMATION typedef struct { lv_obj_t * bar; - lv_anim_value_t anim_start; + lv_anim_value_t anim_start; lv_anim_value_t anim_end; - lv_anim_value_t anim_state; + lv_anim_value_t anim_state; } lv_bar_anim_t; #endif /** Data of bar*/ -typedef struct -{ +typedef struct { /*No inherited ext, derived from the base object */ /*New data for this type */ @@ -73,9 +72,9 @@ typedef struct #if LV_USE_ANIMATION lv_anim_value_t anim_time; lv_bar_anim_t cur_value_anim; - lv_bar_anim_t start_value_anim; + lv_bar_anim_t start_value_anim; #endif - uint8_t type : 2; /*Type of bar*/ + uint8_t type : 2; /*Type of bar*/ lv_style_list_t style_indic; /*Style of the indicator*/ } lv_bar_ext_t; diff --git a/src/lv_widgets/lv_btn.c b/src/lv_widgets/lv_btn.c index 8fb8ff425..da66f5fcd 100644 --- a/src/lv_widgets/lv_btn.c +++ b/src/lv_widgets/lv_btn.c @@ -152,8 +152,8 @@ void lv_btn_set_state(lv_obj_t * btn, lv_btn_state_t state) break; } -// /*Make the state change happen immediately, without transition*/ -// btn->prev_state = btn->state; + // /*Make the state change happen immediately, without transition*/ + // btn->prev_state = btn->state; } /** @@ -168,7 +168,8 @@ void lv_btn_toggle(lv_obj_t * btn) if(lv_obj_get_state(btn, LV_BTN_PART_MAIN) & LV_STATE_CHECKED) { lv_obj_clear_state(btn, LV_STATE_CHECKED); - } else { + } + else { lv_obj_add_state(btn, LV_STATE_CHECKED); } } @@ -190,10 +191,12 @@ lv_btn_state_t lv_btn_get_state(const lv_obj_t * btn) if(state & LV_STATE_DISABLED) { return LV_BTN_STATE_DISABLED; - } else if(state & LV_STATE_CHECKED) { + } + else if(state & LV_STATE_CHECKED) { if(state & LV_STATE_PRESSED) return LV_BTN_STATE_CHECKED_PRESSED; else return LV_BTN_STATE_CHECKED_RELEASED; - } else { + } + else { if(state & LV_STATE_PRESSED) return LV_BTN_STATE_PRESSED; else return LV_BTN_STATE_RELEASED; } @@ -232,9 +235,11 @@ static lv_design_res_t lv_btn_design(lv_obj_t * btn, const lv_area_t * clip_area { if(mode == LV_DESIGN_COVER_CHK) { return ancestor_design(btn, clip_area, mode); - } else if(mode == LV_DESIGN_DRAW_MAIN) { + } + else if(mode == LV_DESIGN_DRAW_MAIN) { ancestor_design(btn, clip_area, mode); - } else if(mode == LV_DESIGN_DRAW_POST) { + } + else if(mode == LV_DESIGN_DRAW_POST) { ancestor_design(btn, clip_area, mode); } @@ -267,7 +272,8 @@ static lv_res_t lv_btn_signal(lv_obj_t * btn, lv_signal_t sign, void * param) if(lv_obj_get_state(btn, LV_BTN_PART_MAIN) & LV_STATE_CHECKED) { lv_btn_set_state(btn, LV_BTN_STATE_RELEASED); toggled = 0; - } else { + } + else { lv_btn_set_state(btn, LV_BTN_STATE_CHECKED_RELEASED); toggled = 1; } @@ -275,7 +281,8 @@ static lv_res_t lv_btn_signal(lv_obj_t * btn, lv_signal_t sign, void * param) res = lv_event_send(btn, LV_EVENT_VALUE_CHANGED, &toggled); if(res != LV_RES_OK) return res; } - } else if(sign == LV_SIGNAL_CONTROL) { + } + else if(sign == LV_SIGNAL_CONTROL) { char c = *((char *)param); if(c == LV_KEY_RIGHT || c == LV_KEY_UP) { if(lv_btn_get_checkable(btn)) { @@ -286,7 +293,8 @@ static lv_res_t lv_btn_signal(lv_obj_t * btn, lv_signal_t sign, void * param) if(res != LV_RES_OK) return res; } - } else if(c == LV_KEY_LEFT || c == LV_KEY_DOWN) { + } + else if(c == LV_KEY_LEFT || c == LV_KEY_DOWN) { if(lv_btn_get_checkable(btn)) { lv_btn_set_state(btn, LV_BTN_STATE_RELEASED); diff --git a/src/lv_widgets/lv_btn.h b/src/lv_widgets/lv_btn.h index fe02342b4..3c3f9ede9 100644 --- a/src/lv_widgets/lv_btn.h +++ b/src/lv_widgets/lv_btn.h @@ -46,8 +46,7 @@ enum { typedef uint8_t lv_btn_state_t; /** Extended data of button*/ -typedef struct -{ +typedef struct { /** Ext. of ancestor*/ lv_cont_ext_t cont; @@ -57,7 +56,7 @@ typedef struct /**Styles*/ enum { - LV_BTN_PART_MAIN = LV_OBJ_PART_MAIN , + LV_BTN_PART_MAIN = LV_OBJ_PART_MAIN, _LV_BTN_PART_VIRTUAL_LAST, _LV_BTN_PART_REAL_LAST = _LV_OBJ_PART_REAL_LAST, }; diff --git a/src/lv_widgets/lv_btnmatrix.c b/src/lv_widgets/lv_btnmatrix.c index 6dbc7a0b7..b4ec09e52 100644 --- a/src/lv_widgets/lv_btnmatrix.c +++ b/src/lv_widgets/lv_btnmatrix.c @@ -112,9 +112,9 @@ lv_obj_t * lv_btnmatrix_create(lv_obj_t * par, const lv_obj_t * copy) } /*Copy an existing object*/ else { -// lv_btnmatrix_ext_t * copy_ext = lv_obj_get_ext_attr(copy); -// memcpy((void*)ext->styles_btn, copy_ext->styles_btn, sizeof(ext->styles_btn)); -// lv_btnmatrix_set_map(new_btnm, lv_btnmatrix_get_map_array(copy)); + // lv_btnmatrix_ext_t * copy_ext = lv_obj_get_ext_attr(copy); + // memcpy((void*)ext->styles_btn, copy_ext->styles_btn, sizeof(ext->styles_btn)); + // lv_btnmatrix_set_map(new_btnm, lv_btnmatrix_get_map_array(copy)); } LV_LOG_INFO("button matrix created"); @@ -199,7 +199,7 @@ void lv_btnmatrix_set_map(lv_obj_t * btnm, const char * map[]) /*Make sure the last row is at the bottom of 'btnm'*/ if(map_p_tmp[btn_cnt][0] == '\0') { /*Last row?*/ - btn_h = lv_obj_get_height(btnm)- act_y - bottom - 1; + btn_h = lv_obj_get_height(btnm) - act_y - bottom - 1; } lv_bidi_dir_t base_dir = lv_obj_get_base_dir(btnm); @@ -225,7 +225,8 @@ void lv_btnmatrix_set_map(lv_obj_t * btnm, const char * map[]) if(base_dir == LV_BIDI_DIR_RTL) { act_x = (unit_act_cnt * all_unit_w) / unit_cnt + i * inner; act_x = lv_obj_get_width(btnm) - right - act_x - act_unit_w - 1; - } else { + } + else { act_x = (unit_act_cnt * all_unit_w) / unit_cnt + i * inner + left; } @@ -235,7 +236,8 @@ void lv_btnmatrix_set_map(lv_obj_t * btnm, const char * map[]) if(inner == 0 && act_x != left) { lv_area_set(&ext->button_areas[btn_i], ext->button_areas[btn_i - 1].x2, act_y, act_x + act_unit_w, act_y + btn_h); - } else { + } + else { lv_area_set(&ext->button_areas[btn_i], act_x, act_y, act_x + act_unit_w, act_y + btn_h); } @@ -480,7 +482,8 @@ const char * lv_btnmatrix_get_active_btn_text(const lv_obj_t * btnm) lv_btnmatrix_ext_t * ext = lv_obj_get_ext_attr(btnm); if(ext->btn_id_act != LV_BTNMATRIX_BTN_NONE) { return lv_btnmatrix_get_btn_text(btnm, ext->btn_id_act); - } else { + } + else { return NULL; } } @@ -652,29 +655,29 @@ static lv_design_res_t lv_btnmatrix_design(lv_obj_t * btnm, const lv_area_t * cl bool tgl_state = button_get_tgl_state(ext->ctrl_bits[btn_i]); if(tgl_state) { - if(!chk_inited) { - btnm->state = LV_STATE_CHECKED; - lv_draw_rect_dsc_init(&draw_rect_chk_dsc); - lv_draw_label_dsc_init(&draw_label_chk_dsc); - lv_obj_init_draw_rect_dsc(btnm, LV_BTNMATRIX_PART_BTN, &draw_rect_chk_dsc); - lv_obj_init_draw_label_dsc(btnm, LV_BTNMATRIX_PART_BTN, &draw_label_chk_dsc); - draw_label_chk_dsc.flag = txt_flag; - btnm->state = state_ori; - chk_inited = true; - } + if(!chk_inited) { + btnm->state = LV_STATE_CHECKED; + lv_draw_rect_dsc_init(&draw_rect_chk_dsc); + lv_draw_label_dsc_init(&draw_label_chk_dsc); + lv_obj_init_draw_rect_dsc(btnm, LV_BTNMATRIX_PART_BTN, &draw_rect_chk_dsc); + lv_obj_init_draw_label_dsc(btnm, LV_BTNMATRIX_PART_BTN, &draw_label_chk_dsc); + draw_label_chk_dsc.flag = txt_flag; + btnm->state = state_ori; + chk_inited = true; + } } if(button_is_inactive(ext->ctrl_bits[btn_i])) { - if(!disabled_inited) { - btnm->state = LV_STATE_DISABLED; - lv_draw_rect_dsc_init(&draw_rect_ina_dsc); - lv_draw_label_dsc_init(&draw_label_ina_dsc); - lv_obj_init_draw_rect_dsc(btnm, LV_BTNMATRIX_PART_BTN, &draw_rect_ina_dsc); - lv_obj_init_draw_label_dsc(btnm, LV_BTNMATRIX_PART_BTN, &draw_label_ina_dsc); - draw_label_ina_dsc.flag = txt_flag; - btnm->state = state_ori; - disabled_inited = true; - } + if(!disabled_inited) { + btnm->state = LV_STATE_DISABLED; + lv_draw_rect_dsc_init(&draw_rect_ina_dsc); + lv_draw_label_dsc_init(&draw_label_ina_dsc); + lv_obj_init_draw_rect_dsc(btnm, LV_BTNMATRIX_PART_BTN, &draw_rect_ina_dsc); + lv_obj_init_draw_label_dsc(btnm, LV_BTNMATRIX_PART_BTN, &draw_label_ina_dsc); + draw_label_ina_dsc.flag = txt_flag; + btnm->state = state_ori; + disabled_inited = true; + } draw_rect_dsc_act = &draw_rect_ina_dsc; draw_label_dsc_act = &draw_label_ina_dsc; } @@ -716,7 +719,8 @@ static lv_design_res_t lv_btnmatrix_design(lv_obj_t * btnm, const lv_area_t * cl /*Left/right columns*/ if(txt_i == 0) { /*First button*/ draw_rect_dsc_act->border_side &= ~LV_BORDER_SIDE_LEFT; - } else if(strcmp(ext->map_p[txt_i - 1], "\n") == 0) { + } + else if(strcmp(ext->map_p[txt_i - 1], "\n") == 0) { draw_rect_dsc_act->border_side &= ~LV_BORDER_SIDE_LEFT; } @@ -745,7 +749,8 @@ static lv_design_res_t lv_btnmatrix_design(lv_obj_t * btnm, const lv_area_t * cl lv_draw_label(&area_tmp, clip_area, draw_label_dsc_act, txt, NULL); } - } else if(mode == LV_DESIGN_DRAW_POST) { + } + else if(mode == LV_DESIGN_DRAW_POST) { ancestor_design_f(btnm, clip_area, mode); } return LV_DESIGN_RES_OK; @@ -779,13 +784,16 @@ static lv_res_t lv_btnmatrix_signal(lv_obj_t * btnm, lv_signal_t sign, void * pa lv_obj_clean_style_list(btnm, LV_BTNMATRIX_PART_BTN); lv_mem_free(ext->button_areas); lv_mem_free(ext->ctrl_bits); - } else if(sign == LV_SIGNAL_STYLE_CHG) { + } + else if(sign == LV_SIGNAL_STYLE_CHG) { lv_btnmatrix_set_map(btnm, ext->map_p); - } else if(sign == LV_SIGNAL_COORD_CHG) { + } + else if(sign == LV_SIGNAL_COORD_CHG) { if(lv_obj_get_width(btnm) != lv_area_get_width(param) || lv_obj_get_height(btnm) != lv_area_get_height(param)) { lv_btnmatrix_set_map(btnm, ext->map_p); } - } else if(sign == LV_SIGNAL_PRESSED) { + } + else if(sign == LV_SIGNAL_PRESSED) { invalidate_button_area(btnm, ext->btn_id_pr); lv_indev_type_t indev_type = lv_indev_get_type(lv_indev_get_act()); @@ -797,7 +805,7 @@ static lv_res_t lv_btnmatrix_signal(lv_obj_t * btnm, lv_signal_t sign, void * pa /*Handle the case where there is no button there*/ if(btn_pr != LV_BTNMATRIX_BTN_NONE) { if(button_is_inactive(ext->ctrl_bits[btn_pr]) == false && - button_is_hidden(ext->ctrl_bits[btn_pr]) == false) { + button_is_hidden(ext->ctrl_bits[btn_pr]) == false) { invalidate_button_area(btnm, ext->btn_id_pr) /*Invalidate the old area*/; ext->btn_id_pr = btn_pr; ext->btn_id_act = btn_pr; @@ -806,7 +814,8 @@ static lv_res_t lv_btnmatrix_signal(lv_obj_t * btnm, lv_signal_t sign, void * pa } } #if LV_USE_GROUP - else if(indev_type == LV_INDEV_TYPE_KEYPAD || (indev_type == LV_INDEV_TYPE_ENCODER && lv_group_get_editing(lv_obj_get_group(btnm)))) { + else if(indev_type == LV_INDEV_TYPE_KEYPAD || (indev_type == LV_INDEV_TYPE_ENCODER && + lv_group_get_editing(lv_obj_get_group(btnm)))) { ext->btn_id_pr = ext->btn_id_focused; invalidate_button_area(btnm, ext->btn_id_focused); } @@ -820,7 +829,8 @@ static lv_res_t lv_btnmatrix_signal(lv_obj_t * btnm, lv_signal_t sign, void * pa res = lv_event_send(btnm, LV_EVENT_VALUE_CHANGED, &b); } } - } else if(sign == LV_SIGNAL_PRESSING) { + } + else if(sign == LV_SIGNAL_PRESSING) { uint16_t btn_pr; /*Search the pressed area*/ lv_indev_get_point(param, &p); @@ -845,14 +855,16 @@ static lv_res_t lv_btnmatrix_signal(lv_obj_t * btnm, lv_signal_t sign, void * pa ext->btn_id_pr = btn_pr; ext->btn_id_act = btn_pr; - } else if(sign == LV_SIGNAL_RELEASED) { + } + else if(sign == LV_SIGNAL_RELEASED) { if(ext->btn_id_pr != LV_BTNMATRIX_BTN_NONE) { /*Toggle the button if enabled*/ if(button_is_tgl_enabled(ext->ctrl_bits[ext->btn_id_pr]) && - !button_is_inactive(ext->ctrl_bits[ext->btn_id_pr])) { + !button_is_inactive(ext->ctrl_bits[ext->btn_id_pr])) { if(button_get_tgl_state(ext->ctrl_bits[ext->btn_id_pr])) { ext->ctrl_bits[ext->btn_id_pr] &= (~LV_BTNMATRIX_CTRL_CHECK_STATE); - } else { + } + else { ext->ctrl_bits[ext->btn_id_pr] |= LV_BTNMATRIX_CTRL_CHECK_STATE; } if(ext->one_toggle) make_one_button_toggled(btnm, ext->btn_id_pr); @@ -877,7 +889,8 @@ static lv_res_t lv_btnmatrix_signal(lv_obj_t * btnm, lv_signal_t sign, void * pa res = lv_event_send(btnm, LV_EVENT_VALUE_CHANGED, &b); } } - } else if(sign == LV_SIGNAL_LONG_PRESS_REP) { + } + else if(sign == LV_SIGNAL_LONG_PRESS_REP) { if(ext->btn_id_act != LV_BTNMATRIX_BTN_NONE) { if(button_is_repeat_disabled(ext->ctrl_bits[ext->btn_id_act]) == false && button_is_inactive(ext->ctrl_bits[ext->btn_id_act]) == false && @@ -886,11 +899,13 @@ static lv_res_t lv_btnmatrix_signal(lv_obj_t * btnm, lv_signal_t sign, void * pa res = lv_event_send(btnm, LV_EVENT_VALUE_CHANGED, &b); } } - } else if(sign == LV_SIGNAL_PRESS_LOST) { + } + else if(sign == LV_SIGNAL_PRESS_LOST) { ext->btn_id_pr = LV_BTNMATRIX_BTN_NONE; ext->btn_id_act = LV_BTNMATRIX_BTN_NONE; lv_obj_invalidate(btnm); - } else if(sign == LV_SIGNAL_FOCUS) { + } + else if(sign == LV_SIGNAL_FOCUS) { #if LV_USE_GROUP lv_indev_t * indev = lv_indev_get_act(); lv_indev_type_t indev_type = lv_indev_get_type(indev); @@ -901,14 +916,16 @@ static lv_res_t lv_btnmatrix_signal(lv_obj_t * btnm, lv_signal_t sign, void * pa indev_type = lv_indev_get_type(indev); } - if(indev_type == LV_INDEV_TYPE_ENCODER) { + if(indev_type == LV_INDEV_TYPE_ENCODER) { /*In navigation mode don't select any button but in edit mode select the fist*/ if(lv_group_get_editing(lv_obj_get_group(btnm))) { ext->btn_id_focused = 0; - } else { + } + else { ext->btn_id_focused = LV_BTNMATRIX_BTN_NONE; } - } else if (indev_type == LV_INDEV_TYPE_KEYPAD) { + } + else if(indev_type == LV_INDEV_TYPE_KEYPAD) { ext->btn_id_focused = 0; } @@ -921,7 +938,8 @@ static lv_res_t lv_btnmatrix_signal(lv_obj_t * btnm, lv_signal_t sign, void * pa ext->btn_id_focused = LV_BTNMATRIX_BTN_NONE; ext->btn_id_pr = LV_BTNMATRIX_BTN_NONE; ext->btn_id_act = LV_BTNMATRIX_BTN_NONE; - } else if(sign == LV_SIGNAL_CONTROL) { + } + else if(sign == LV_SIGNAL_CONTROL) { char c = *((char *)param); if(c == LV_KEY_RIGHT) { if(ext->btn_id_focused == LV_BTNMATRIX_BTN_NONE) @@ -931,17 +949,20 @@ static lv_res_t lv_btnmatrix_signal(lv_obj_t * btnm, lv_signal_t sign, void * pa if(ext->btn_id_focused >= ext->btn_cnt - 1) ext->btn_id_focused = ext->btn_cnt - 1; ext->btn_id_act = ext->btn_id_focused; lv_obj_invalidate(btnm); - } else if(c == LV_KEY_LEFT) { + } + else if(c == LV_KEY_LEFT) { if(ext->btn_id_focused == LV_BTNMATRIX_BTN_NONE) ext->btn_id_focused = 0; if(ext->btn_id_focused > 0) ext->btn_id_focused--; ext->btn_id_act = ext->btn_id_focused; lv_obj_invalidate(btnm); - } else if(c == LV_KEY_DOWN) { + } + else if(c == LV_KEY_DOWN) { lv_style_int_t pad_inner = lv_obj_get_style_pad_inner(btnm, LV_BTNMATRIX_PART_BG); /*Find the area below the the current*/ if(ext->btn_id_focused == LV_BTNMATRIX_BTN_NONE) { ext->btn_id_focused = 0; - } else { + } + else { uint16_t area_below; lv_coord_t pr_center = ext->button_areas[ext->btn_id_focused].x1 + (lv_area_get_width(&ext->button_areas[ext->btn_id_focused]) >> 1); @@ -960,12 +981,14 @@ static lv_res_t lv_btnmatrix_signal(lv_obj_t * btnm, lv_signal_t sign, void * pa } ext->btn_id_act = ext->btn_id_focused; lv_obj_invalidate(btnm); - } else if(c == LV_KEY_UP) { + } + else if(c == LV_KEY_UP) { lv_style_int_t pad_inner = lv_obj_get_style_pad_inner(btnm, LV_BTNMATRIX_PART_BG); /*Find the area below the the current*/ if(ext->btn_id_focused == LV_BTNMATRIX_BTN_NONE) { ext->btn_id_focused = 0; - } else { + } + else { int16_t area_above; lv_coord_t pr_center = ext->button_areas[ext->btn_id_focused].x1 + (lv_area_get_width(&ext->button_areas[ext->btn_id_focused]) >> 1); @@ -984,7 +1007,8 @@ static lv_res_t lv_btnmatrix_signal(lv_obj_t * btnm, lv_signal_t sign, void * pa ext->btn_id_act = ext->btn_id_focused; lv_obj_invalidate(btnm); } - } else if(sign == LV_SIGNAL_GET_EDITABLE) { + } + else if(sign == LV_SIGNAL_GET_EDITABLE) { bool * editable = (bool *)param; *editable = true; } @@ -1006,14 +1030,14 @@ static lv_style_list_t * lv_btnmatrix_get_style(lv_obj_t * btnm, uint8_t part) lv_style_list_t * style_dsc_p; switch(part) { - case LV_BTNMATRIX_PART_BG: - style_dsc_p = &btnm->style_list; - break; - case LV_BTNMATRIX_PART_BTN: - style_dsc_p = &ext->style_btn; - break; - default: - style_dsc_p = NULL; + case LV_BTNMATRIX_PART_BG: + style_dsc_p = &btnm->style_list; + break; + case LV_BTNMATRIX_PART_BTN: + style_dsc_p = &ext->style_btn; + break; + default: + style_dsc_p = NULL; } return style_dsc_p; diff --git a/src/lv_widgets/lv_btnmatrix.h b/src/lv_widgets/lv_btnmatrix.h index 73b034a8b..3369f47ac 100644 --- a/src/lv_widgets/lv_btnmatrix.h +++ b/src/lv_widgets/lv_btnmatrix.h @@ -46,8 +46,7 @@ enum { typedef uint16_t lv_btnmatrix_ctrl_t; /*Data of button matrix*/ -typedef struct -{ +typedef struct { /*No inherited ext.*/ /*Ext. of ancestor*/ /*New data for this type */ const char ** map_p; /*Pointer to the current map*/ diff --git a/src/lv_widgets/lv_calendar.c b/src/lv_widgets/lv_calendar.c index 858aa3cdf..20a07791d 100644 --- a/src/lv_widgets/lv_calendar.c +++ b/src/lv_widgets/lv_calendar.c @@ -59,7 +59,8 @@ static lv_signal_cb_t ancestor_signal; static lv_design_cb_t ancestor_design; static const char * day_name[7] = {"Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"}; static const char * month_name[12] = {"January", "February", "March", "April", "May", "June", - "July", "August", "September", "October", "November", "December"}; + "July", "August", "September", "October", "November", "December" + }; /********************** * MACROS @@ -131,7 +132,7 @@ lv_obj_t * lv_calendar_create(lv_obj_t * par, const lv_obj_t * copy) if(copy == NULL) { lv_theme_apply(calendar, LV_THEME_CALENDAR); - lv_obj_set_size(calendar, 5*LV_DPI/2, 5*LV_DPI/2); + lv_obj_set_size(calendar, 5 * LV_DPI / 2, 5 * LV_DPI / 2); } /*Copy an existing calendar*/ @@ -153,7 +154,7 @@ lv_obj_t * lv_calendar_create(lv_obj_t * par, const lv_obj_t * copy) ext->style_header = copy_ext->style_header; ext->style_day_names = copy_ext->style_day_names; /*Refresh the style with new signal function*/ -// lv_obj_refresh_style(new_calendar); + // lv_obj_refresh_style(new_calendar); } LV_LOG_INFO("calendar created"); @@ -432,7 +433,8 @@ static lv_res_t lv_calendar_signal(lv_obj_t * calendar, lv_signal_t sign, void * lv_obj_clean_style_list(calendar, LV_CALENDAR_PART_HEADER); lv_obj_clean_style_list(calendar, LV_CALENDAR_PART_DAY_NAMES); lv_obj_clean_style_list(calendar, LV_CALENDAR_PART_DATE); - } else if(sign == LV_SIGNAL_PRESSING) { + } + else if(sign == LV_SIGNAL_PRESSING) { lv_calendar_ext_t * ext = lv_obj_get_ext_attr(calendar); lv_area_t header_area; lv_area_copy(&header_area, &calendar->coords); @@ -447,7 +449,8 @@ static lv_res_t lv_calendar_signal(lv_obj_t * calendar, lv_signal_t sign, void * if(p.x < header_area.x1 + lv_area_get_width(&header_area) / 2) { if(ext->btn_pressing != -1) lv_obj_invalidate(calendar); ext->btn_pressing = -1; - } else { + } + else { if(ext->btn_pressing != 1) lv_obj_invalidate(calendar); ext->btn_pressing = 1; } @@ -469,7 +472,8 @@ static lv_res_t lv_calendar_signal(lv_obj_t * calendar, lv_signal_t sign, void * ext->pressed_date.month = 0; ext->pressed_date.day = 0; } - } else if(sign == LV_SIGNAL_PRESS_LOST) { + } + else if(sign == LV_SIGNAL_PRESS_LOST) { lv_calendar_ext_t * ext = lv_obj_get_ext_attr(calendar); ext->btn_pressing = 0; ext->pressed_date.year = 0; @@ -477,23 +481,28 @@ static lv_res_t lv_calendar_signal(lv_obj_t * calendar, lv_signal_t sign, void * ext->pressed_date.day = 0; lv_obj_invalidate(calendar); - } else if(sign == LV_SIGNAL_RELEASED) { + } + else if(sign == LV_SIGNAL_RELEASED) { lv_calendar_ext_t * ext = lv_obj_get_ext_attr(calendar); if(ext->btn_pressing < 0) { if(ext->showed_date.month <= 1) { ext->showed_date.month = 12; ext->showed_date.year--; - } else { + } + else { ext->showed_date.month--; } - } else if(ext->btn_pressing > 0) { + } + else if(ext->btn_pressing > 0) { if(ext->showed_date.month >= 12) { ext->showed_date.month = 1; ext->showed_date.year++; - } else { + } + else { ext->showed_date.month++; } - } else if(ext->pressed_date.year != 0) { + } + else if(ext->pressed_date.year != 0) { res = lv_event_send(calendar, LV_EVENT_VALUE_CHANGED, NULL); if(res != LV_RES_OK) return res; @@ -504,22 +513,26 @@ static lv_res_t lv_calendar_signal(lv_obj_t * calendar, lv_signal_t sign, void * ext->pressed_date.month = 0; ext->pressed_date.day = 0; lv_obj_invalidate(calendar); - } else if(sign == LV_SIGNAL_CONTROL) { + } + else if(sign == LV_SIGNAL_CONTROL) { uint8_t c = *((uint8_t *)param); lv_calendar_ext_t * ext = lv_obj_get_ext_attr(calendar); if(c == LV_KEY_RIGHT || c == LV_KEY_UP) { if(ext->showed_date.month >= 12) { ext->showed_date.month = 1; ext->showed_date.year++; - } else { + } + else { ext->showed_date.month++; } lv_obj_invalidate(calendar); - } else if(c == LV_KEY_LEFT || c == LV_KEY_DOWN) { + } + else if(c == LV_KEY_LEFT || c == LV_KEY_DOWN) { if(ext->showed_date.month <= 1) { ext->showed_date.month = 12; ext->showed_date.year--; - } else { + } + else { ext->showed_date.month--; } lv_obj_invalidate(calendar); @@ -544,20 +557,20 @@ static lv_style_list_t * lv_calendar_get_style(lv_obj_t * calendar, uint8_t part switch(part) { - case LV_CALENDAR_PART_BG: - style_dsc_p = &calendar->style_list; - break; - case LV_CALENDAR_PART_HEADER: - style_dsc_p = &ext->style_header; - break; - case LV_CALENDAR_PART_DAY_NAMES: - style_dsc_p = &ext->style_day_names; - break; - case LV_CALENDAR_PART_DATE: - style_dsc_p = &ext->style_date_nums; - break; - default: - style_dsc_p = NULL; + case LV_CALENDAR_PART_BG: + style_dsc_p = &calendar->style_list; + break; + case LV_CALENDAR_PART_HEADER: + style_dsc_p = &ext->style_header; + break; + case LV_CALENDAR_PART_DAY_NAMES: + style_dsc_p = &ext->style_day_names; + break; + case LV_CALENDAR_PART_DATE: + style_dsc_p = &ext->style_date_nums; + break; + default: + style_dsc_p = NULL; } return style_dsc_p; @@ -602,20 +615,23 @@ static bool calculate_touched_day(lv_obj_t * calendar, const lv_point_t * touche ext->pressed_date.year = ext->showed_date.year - (ext->showed_date.month == 1 ? 1 : 0); ext->pressed_date.month = ext->showed_date.month == 1 ? 12 : (ext->showed_date.month - 1); ext->pressed_date.day = get_month_length(ext->pressed_date.year, ext->pressed_date.month) - - get_day_of_week(ext->showed_date.year, ext->showed_date.month, 1) + 1 + i_pos; - } else if(i_pos < (get_day_of_week(ext->showed_date.year, ext->showed_date.month, 1) + - get_month_length(ext->showed_date.year, ext->showed_date.month))) { + get_day_of_week(ext->showed_date.year, ext->showed_date.month, 1) + 1 + i_pos; + } + else if(i_pos < (get_day_of_week(ext->showed_date.year, ext->showed_date.month, 1) + + get_month_length(ext->showed_date.year, ext->showed_date.month))) { ext->pressed_date.year = ext->showed_date.year; ext->pressed_date.month = ext->showed_date.month; ext->pressed_date.day = i_pos + 1 - get_day_of_week(ext->showed_date.year, ext->showed_date.month, 1); - } else if(i_pos < 42) { + } + else if(i_pos < 42) { ext->pressed_date.year = ext->showed_date.year + (ext->showed_date.month == 12 ? 1 : 0); ext->pressed_date.month = ext->showed_date.month == 12 ? 1 : (ext->showed_date.month + 1); ext->pressed_date.day = i_pos + 1 - get_day_of_week(ext->showed_date.year, ext->showed_date.month, 1) - - get_month_length(ext->showed_date.year, ext->showed_date.month); + get_month_length(ext->showed_date.year, ext->showed_date.month); } return true; - } else { + } + else { return false; } } @@ -688,7 +704,7 @@ static void draw_header(lv_obj_t * calendar, const lv_area_t * mask) lv_draw_label_dsc_init(&label_dsc); lv_obj_init_draw_label_dsc(calendar, LV_CALENDAR_PART_HEADER, &label_dsc); label_dsc.flag = LV_TXT_FLAG_CENTER; - lv_draw_label(&header_area, mask, &label_dsc,txt_buf, NULL); + lv_draw_label(&header_area, mask, &label_dsc, txt_buf, NULL); calendar->state = state_ori; /*Restore the state*/ @@ -708,7 +724,8 @@ static void draw_header(lv_obj_t * calendar, const lv_area_t * mask) if(ext->btn_pressing > 0) calendar->state |= LV_STATE_PRESSED; else calendar->state &= ~(LV_STATE_PRESSED); - header_area.x1 = header_area.x2 - header_right - lv_txt_get_width(LV_SYMBOL_RIGHT, (uint16_t)strlen(LV_SYMBOL_RIGHT), font, 0, LV_TXT_FLAG_NONE); + header_area.x1 = header_area.x2 - header_right - lv_txt_get_width(LV_SYMBOL_RIGHT, (uint16_t)strlen(LV_SYMBOL_RIGHT), + font, 0, LV_TXT_FLAG_NONE); lv_draw_label_dsc_init(&label_dsc); lv_obj_init_draw_label_dsc(calendar, LV_CALENDAR_PART_HEADER, &label_dsc); @@ -805,7 +822,8 @@ static void draw_dates(lv_obj_t * calendar, const lv_area_t * clip_area) day_cnt = 1; draw_state = DAY_DRAW_ACT_MONTH; month_state = 0; - } else { + } + else { draw_state = DAY_DRAW_PREV_MONTH; day_cnt = get_month_length(ext->showed_date.year, ext->showed_date.month - 1); /*Length of the previous month*/ day_cnt -= month_start_day - 1; /*First visible number of the previous month*/ @@ -850,7 +868,7 @@ static void draw_dates(lv_obj_t * calendar, const lv_area_t * clip_area) } /*The current month is over*/ else if(draw_state == DAY_DRAW_ACT_MONTH && - day_cnt > get_month_length(ext->showed_date.year, ext->showed_date.month)) { + day_cnt > get_month_length(ext->showed_date.year, ext->showed_date.month)) { draw_state = DAY_DRAW_NEXT_MONTH; day_cnt = 1; month_state = LV_STATE_DISABLED; @@ -923,7 +941,8 @@ static bool is_highlighted(lv_obj_t * calendar, day_draw_state_t draw_state, int if(draw_state == DAY_DRAW_PREV_MONTH) { year -= month == 1 ? 1 : 0; month = month == 1 ? 12 : month - 1; - } else if(draw_state == DAY_DRAW_NEXT_MONTH) { + } + else if(draw_state == DAY_DRAW_NEXT_MONTH) { year += month == 12 ? 1 : 0; month = month == 12 ? 1 : month + 1; } @@ -956,7 +975,8 @@ static bool is_pressed(lv_obj_t * calendar, day_draw_state_t draw_state, int32_t if(draw_state == DAY_DRAW_PREV_MONTH) { year -= month == 1 ? 1 : 0; month = month == 1 ? 12 : month - 1; - } else if(draw_state == DAY_DRAW_NEXT_MONTH) { + } + else if(draw_state == DAY_DRAW_NEXT_MONTH) { year += month == 12 ? 1 : 0; month = month == 12 ? 1 : month + 1; } diff --git a/src/lv_widgets/lv_calendar.h b/src/lv_widgets/lv_calendar.h index d0b4f8330..1e0f88cdc 100644 --- a/src/lv_widgets/lv_calendar.h +++ b/src/lv_widgets/lv_calendar.h @@ -30,16 +30,14 @@ extern "C" { /** * Represents a date on the calendar object (platform-agnostic). */ -typedef struct -{ +typedef struct { uint16_t year; int8_t month; int8_t day; } lv_calendar_date_t; /*Data of calendar*/ -typedef struct -{ +typedef struct { /*None*/ /*Ext. of ancestor*/ /*New data for this type */ lv_calendar_date_t today; /*Date of today*/ diff --git a/src/lv_widgets/lv_canvas.c b/src/lv_widgets/lv_canvas.c index e2c17736e..085c9556a 100644 --- a/src/lv_widgets/lv_canvas.c +++ b/src/lv_widgets/lv_canvas.c @@ -31,21 +31,22 @@ static lv_res_t lv_canvas_signal(lv_obj_t * canvas, lv_signal_t sign, void * param); static void set_set_px_cb(lv_disp_drv_t * disp_drv, lv_img_cf_t cf); -static void set_px_true_color_alpha(lv_disp_drv_t * disp_drv, uint8_t * buf, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y, - lv_color_t color, lv_opa_t opa); +static void set_px_true_color_alpha(lv_disp_drv_t * disp_drv, uint8_t * buf, lv_coord_t buf_w, lv_coord_t x, + lv_coord_t y, + lv_color_t color, lv_opa_t opa); static void set_px_cb_alpha1(lv_disp_drv_t * disp_drv, uint8_t * buf, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y, - lv_color_t color, lv_opa_t opa); + lv_color_t color, lv_opa_t opa); static void set_px_cb_alpha2(lv_disp_drv_t * disp_drv, uint8_t * buf, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y, - lv_color_t color, lv_opa_t opa); + lv_color_t color, lv_opa_t opa); static void set_px_cb_alpha4(lv_disp_drv_t * disp_drv, uint8_t * buf, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y, - lv_color_t color, lv_opa_t opa); + lv_color_t color, lv_opa_t opa); static void set_px_cb_alpha8(lv_disp_drv_t * disp_drv, uint8_t * buf, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y, - lv_color_t color, lv_opa_t opa); + lv_color_t color, lv_opa_t opa); static void set_px_alpha_generic(lv_img_dsc_t * d, lv_coord_t x, lv_coord_t y, lv_color_t color, lv_opa_t opa); @@ -274,8 +275,9 @@ void lv_canvas_copy_buf(lv_obj_t * canvas, const void * to_copy, lv_coord_t x, l * Set to `source height / 2` to rotate around the center * @param antialias apply anti-aliasing during the transformation. Looks better but slower. */ -void lv_canvas_transform(lv_obj_t * canvas, lv_img_dsc_t * img, int16_t angle, uint16_t zoom, lv_coord_t offset_x, lv_coord_t offset_y, - int32_t pivot_x, int32_t pivot_y, bool antialias) +void lv_canvas_transform(lv_obj_t * canvas, lv_img_dsc_t * img, int16_t angle, uint16_t zoom, lv_coord_t offset_x, + lv_coord_t offset_y, + int32_t pivot_x, int32_t pivot_y, bool antialias) { LV_ASSERT_OBJ(canvas, LV_OBJX_NAME); LV_ASSERT_NULL(img); @@ -314,7 +316,8 @@ void lv_canvas_transform(lv_obj_t * canvas, lv_img_dsc_t * img, int16_t angle, u /*If the image has no alpha channel just simple set the result color on the canvas*/ if(lv_img_cf_has_alpha(img->header.cf) == false) { lv_img_buf_set_px_color(&ext_dst->dsc, x + offset_x, y + offset_y, dsc.res.color); - } else { + } + else { lv_color_t bg_color = lv_img_buf_get_px_color(&ext_dst->dsc, x + offset_x, y + offset_y, dsc.cfg.color); /*If the canvas has no alpha but the image has mix the image's color with @@ -384,7 +387,8 @@ void lv_canvas_blur_hor(lv_obj_t * canvas, const lv_area_t * area, uint16_t r) if(a.y1 < 0) a.y1 = 0; if(a.x2 > ext->dsc.header.w - 1) a.x2 = ext->dsc.header.w - 1; if(a.y2 > ext->dsc.header.h - 1) a.y2 = ext->dsc.header.h - 1; - } else { + } + else { a.x1 = 0; a.y1 = 0; a.x2 = ext->dsc.header.w - 1; @@ -425,7 +429,7 @@ void lv_canvas_blur_hor(lv_obj_t * canvas, const lv_area_t * area, uint16_t r) memcpy(line_buf, &ext->dsc.data[y * line_w], line_w); - for(x = a.x1 -r_back; x <= a.x1 + r_front; x++) { + for(x = a.x1 - r_back; x <= a.x1 + r_front; x++) { x_safe = x < 0 ? 0 : x; x_safe = x_safe > ext->dsc.header.w - 1 ? ext->dsc.header.w - 1 : x_safe; @@ -447,8 +451,8 @@ void lv_canvas_blur_hor(lv_obj_t * canvas, const lv_area_t * area, uint16_t r) for(x = a.x1; x <= a.x2; x++) { - if(asum) { - c.ch.red = rsum / r; + if(asum) { + c.ch.red = rsum / r; #if LV_COLOR_DEPTH == 16 && LV_COLOR_16_SWAP uint8_t gtmp = gsum / r; c.ch.green_h = gtmp >> 3; @@ -456,12 +460,12 @@ void lv_canvas_blur_hor(lv_obj_t * canvas, const lv_area_t * area, uint16_t r) #else c.ch.green = gsum / r; #endif - c.ch.blue = bsum / r; - if(has_alpha) opa = asum / r; + c.ch.blue = bsum / r; + if(has_alpha) opa = asum / r; - lv_img_buf_set_px_color(&ext->dsc, x, y, c); - } - if(has_alpha) lv_img_buf_set_px_alpha(&ext->dsc, x, y, opa); + lv_img_buf_set_px_color(&ext->dsc, x, y, c); + } + if(has_alpha) lv_img_buf_set_px_alpha(&ext->dsc, x, y, opa); x_safe = x - r_back; x_safe = x_safe < 0 ? 0 : x_safe; @@ -519,7 +523,8 @@ void lv_canvas_blur_ver(lv_obj_t * canvas, const lv_area_t * area, uint16_t r) if(a.y1 < 0) a.y1 = 0; if(a.x2 > ext->dsc.header.w - 1) a.x2 = ext->dsc.header.w - 1; if(a.y2 > ext->dsc.header.h - 1) a.y2 = ext->dsc.header.h - 1; - } else { + } + else { a.x1 = 0; a.y1 = 0; a.x2 = ext->dsc.header.w - 1; @@ -557,7 +562,7 @@ void lv_canvas_blur_ver(lv_obj_t * canvas, const lv_area_t * area, uint16_t r) lv_color_t c; lv_opa_t opa = LV_OPA_COVER; - for(y = a.y1 -r_back; y <= a.y1 + r_front; y++) { + for(y = a.y1 - r_back; y <= a.y1 + r_front; y++) { y_safe = y < 0 ? 0 : y; y_safe = y_safe > ext->dsc.header.h - 1 ? ext->dsc.header.h - 1 : y_safe; @@ -581,21 +586,21 @@ void lv_canvas_blur_ver(lv_obj_t * canvas, const lv_area_t * area, uint16_t r) if(has_alpha == false) asum = LV_OPA_COVER; for(y = a.y1; y <= a.y2; y++) { - if(asum) { - c.ch.red = rsum / r; + if(asum) { + c.ch.red = rsum / r; #if LV_COLOR_DEPTH == 16 && LV_COLOR_16_SWAP - uint8_t gtmp = gsum / r; + uint8_t gtmp = gsum / r; c.ch.green_h = gtmp >> 3; c.ch.green_l = gtmp & 0x7; #else c.ch.green = gsum / r; #endif - c.ch.blue = bsum / r; - if(has_alpha) opa = asum / r; + c.ch.blue = bsum / r; + if(has_alpha) opa = asum / r; - lv_img_buf_set_px_color(&ext->dsc, x, y, c); - } - if(has_alpha) lv_img_buf_set_px_alpha(&ext->dsc, x, y, opa); + lv_img_buf_set_px_color(&ext->dsc, x, y, c); + } + if(has_alpha) lv_img_buf_set_px_alpha(&ext->dsc, x, y, opa); y_safe = y - r_back; y_safe = y_safe < 0 ? 0 : y_safe; @@ -714,8 +719,7 @@ void lv_canvas_draw_rect(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_coord /*Disable anti-aliasing if drawing with transparent color to chroma keyed canvas*/ lv_color_t ctransp = LV_COLOR_TRANSP; if(dsc->header.cf == LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED && - rect_dsc->bg_color.full == ctransp.full) - { + rect_dsc->bg_color.full == ctransp.full) { disp.driver.antialiasing = 0; } #endif @@ -740,7 +744,8 @@ void lv_canvas_draw_rect(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_coord * @param txt text to display * @param align align of the text (`LV_LABEL_ALIGN_LEFT/RIGHT/CENTER`) */ -void lv_canvas_draw_text(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_coord_t max_w, lv_draw_label_dsc_t * label_draw_dsc, +void lv_canvas_draw_text(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_coord_t max_w, + lv_draw_label_dsc_t * label_draw_dsc, const char * txt, lv_label_align_t align) { LV_ASSERT_OBJ(canvas, LV_OBJX_NAME); @@ -786,10 +791,18 @@ void lv_canvas_draw_text(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_coord lv_txt_flag_t flag; switch(align) { - case LV_LABEL_ALIGN_LEFT: flag = LV_TXT_FLAG_NONE; break; - case LV_LABEL_ALIGN_RIGHT: flag = LV_TXT_FLAG_RIGHT; break; - case LV_LABEL_ALIGN_CENTER: flag = LV_TXT_FLAG_CENTER; break; - default: flag = LV_TXT_FLAG_NONE; break; + case LV_LABEL_ALIGN_LEFT: + flag = LV_TXT_FLAG_NONE; + break; + case LV_LABEL_ALIGN_RIGHT: + flag = LV_TXT_FLAG_RIGHT; + break; + case LV_LABEL_ALIGN_CENTER: + flag = LV_TXT_FLAG_CENTER; + break; + default: + flag = LV_TXT_FLAG_NONE; + break; } label_draw_dsc->flag = flag; @@ -807,7 +820,8 @@ void lv_canvas_draw_text(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_coord * @param src image source. Can be a pointer an `lv_img_dsc_t` variable or a path an image. * @param style style of the image (`image` properties are used) */ -void lv_canvas_draw_img(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, const void * src, lv_draw_img_dsc_t * img_draw_dsc) +void lv_canvas_draw_img(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, const void * src, + lv_draw_img_dsc_t * img_draw_dsc) { LV_ASSERT_OBJ(canvas, LV_OBJX_NAME); @@ -871,7 +885,8 @@ void lv_canvas_draw_img(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, const voi * @param point_cnt number of points * @param style style of the line (`line` properties are used) */ -void lv_canvas_draw_line(lv_obj_t * canvas, const lv_point_t * points, uint32_t point_cnt, lv_draw_line_dsc_t * line_draw_dsc) +void lv_canvas_draw_line(lv_obj_t * canvas, const lv_point_t * points, uint32_t point_cnt, + lv_draw_line_dsc_t * line_draw_dsc) { LV_ASSERT_OBJ(canvas, LV_OBJX_NAME); @@ -908,8 +923,7 @@ void lv_canvas_draw_line(lv_obj_t * canvas, const lv_point_t * points, uint32_t /*Disable anti-aliasing if drawing with transparent color to chroma keyed canvas*/ lv_color_t ctransp = LV_COLOR_TRANSP; if(dsc->header.cf == LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED && - line_draw_dsc->color.full == ctransp.full) - { + line_draw_dsc->color.full == ctransp.full) { disp.driver.antialiasing = 0; } #endif @@ -921,7 +935,7 @@ void lv_canvas_draw_line(lv_obj_t * canvas, const lv_point_t * points, uint32_t for(i = 0; i < point_cnt - 1; i++) { lv_draw_line(&points[i], &points[i + 1], &mask, line_draw_dsc); } - + lv_refr_set_disp_refreshing(refr_ori); lv_obj_invalidate(canvas); @@ -934,7 +948,8 @@ void lv_canvas_draw_line(lv_obj_t * canvas, const lv_point_t * points, uint32_t * @param point_cnt number of points * @param style style of the polygon (`body.main_color` and `body.opa` is used) */ -void lv_canvas_draw_polygon(lv_obj_t * canvas, const lv_point_t * points, uint32_t point_cnt, lv_draw_rect_dsc_t * poly_draw_dsc) +void lv_canvas_draw_polygon(lv_obj_t * canvas, const lv_point_t * points, uint32_t point_cnt, + lv_draw_rect_dsc_t * poly_draw_dsc) { LV_ASSERT_OBJ(canvas, LV_OBJX_NAME); @@ -972,8 +987,7 @@ void lv_canvas_draw_polygon(lv_obj_t * canvas, const lv_point_t * points, uint32 /*Disable anti-aliasing if drawing with transparent color to chroma keyed canvas*/ lv_color_t ctransp = LV_COLOR_TRANSP; if(dsc->header.cf == LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED && - poly_draw_dsc->bg_color.full == ctransp.full) - { + poly_draw_dsc->bg_color.full == ctransp.full) { disp.driver.antialiasing = 0; } #endif @@ -981,7 +995,7 @@ void lv_canvas_draw_polygon(lv_obj_t * canvas, const lv_point_t * points, uint32 lv_disp_t * refr_ori = lv_refr_get_disp_refreshing(); lv_refr_set_disp_refreshing(&disp); -// lv_draw_polygon(points, point_cnt, &mask, poly_draw_dsc); + // lv_draw_polygon(points, point_cnt, &mask, poly_draw_dsc); lv_refr_set_disp_refreshing(refr_ori); @@ -1037,8 +1051,7 @@ void lv_canvas_draw_arc(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_coord_ /*Disable anti-aliasing if drawing with transparent color to chroma keyed canvas*/ lv_color_t ctransp = LV_COLOR_TRANSP; if(dsc->header.cf == LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED && - arc_draw_dsc->color.full == ctransp.full) - { + arc_draw_dsc->color.full == ctransp.full) { disp.driver.antialiasing = 0; } #endif @@ -1083,17 +1096,28 @@ static lv_res_t lv_canvas_signal(lv_obj_t * canvas, lv_signal_t sign, void * par static void set_set_px_cb(lv_disp_drv_t * disp_drv, lv_img_cf_t cf) { switch(cf) { - case LV_IMG_CF_TRUE_COLOR_ALPHA: disp_drv->set_px_cb = set_px_true_color_alpha; break; - case LV_IMG_CF_ALPHA_1BIT: disp_drv->set_px_cb = set_px_cb_alpha1; break; - case LV_IMG_CF_ALPHA_2BIT: disp_drv->set_px_cb = set_px_cb_alpha2; break; - case LV_IMG_CF_ALPHA_4BIT: disp_drv->set_px_cb = set_px_cb_alpha4; break; - case LV_IMG_CF_ALPHA_8BIT: disp_drv->set_px_cb = set_px_cb_alpha8; break; - default: disp_drv->set_px_cb = NULL; + case LV_IMG_CF_TRUE_COLOR_ALPHA: + disp_drv->set_px_cb = set_px_true_color_alpha; + break; + case LV_IMG_CF_ALPHA_1BIT: + disp_drv->set_px_cb = set_px_cb_alpha1; + break; + case LV_IMG_CF_ALPHA_2BIT: + disp_drv->set_px_cb = set_px_cb_alpha2; + break; + case LV_IMG_CF_ALPHA_4BIT: + disp_drv->set_px_cb = set_px_cb_alpha4; + break; + case LV_IMG_CF_ALPHA_8BIT: + disp_drv->set_px_cb = set_px_cb_alpha8; + break; + default: + disp_drv->set_px_cb = NULL; } } static void set_px_cb_alpha1(lv_disp_drv_t * disp_drv, uint8_t * buf, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y, - lv_color_t color, lv_opa_t opa) + lv_color_t color, lv_opa_t opa) { (void) disp_drv; /*Unused*/ @@ -1107,7 +1131,7 @@ static void set_px_cb_alpha1(lv_disp_drv_t * disp_drv, uint8_t * buf, lv_coord_t } static void set_px_cb_alpha2(lv_disp_drv_t * disp_drv, uint8_t * buf, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y, - lv_color_t color, lv_opa_t opa) + lv_color_t color, lv_opa_t opa) { (void) disp_drv; /*Unused*/ @@ -1121,7 +1145,7 @@ static void set_px_cb_alpha2(lv_disp_drv_t * disp_drv, uint8_t * buf, lv_coord_t } static void set_px_cb_alpha4(lv_disp_drv_t * disp_drv, uint8_t * buf, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y, - lv_color_t color, lv_opa_t opa) + lv_color_t color, lv_opa_t opa) { (void) disp_drv; /*Unused*/ @@ -1135,7 +1159,7 @@ static void set_px_cb_alpha4(lv_disp_drv_t * disp_drv, uint8_t * buf, lv_coord_t } static void set_px_cb_alpha8(lv_disp_drv_t * disp_drv, uint8_t * buf, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y, - lv_color_t color, lv_opa_t opa) + lv_color_t color, lv_opa_t opa) { (void) disp_drv; /*Unused*/ @@ -1163,8 +1187,9 @@ static void set_px_alpha_generic(lv_img_dsc_t * d, lv_coord_t x, lv_coord_t y, l } -static void set_px_true_color_alpha(lv_disp_drv_t * disp_drv, uint8_t * buf, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y, - lv_color_t color, lv_opa_t opa) +static void set_px_true_color_alpha(lv_disp_drv_t * disp_drv, uint8_t * buf, lv_coord_t buf_w, lv_coord_t x, + lv_coord_t y, + lv_color_t color, lv_opa_t opa) { (void) disp_drv; /*Unused*/ diff --git a/src/lv_widgets/lv_canvas.h b/src/lv_widgets/lv_canvas.h index 5d0288067..ba45016ee 100644 --- a/src/lv_widgets/lv_canvas.h +++ b/src/lv_widgets/lv_canvas.h @@ -29,8 +29,7 @@ extern "C" { * TYPEDEFS **********************/ /*Data of canvas*/ -typedef struct -{ +typedef struct { lv_img_ext_t img; /*Ext. of ancestor*/ /*New data for this type */ lv_img_dsc_t dsc; @@ -145,8 +144,9 @@ void lv_canvas_copy_buf(lv_obj_t * canvas, const void * to_copy, lv_coord_t x, l * Set to `source height / 2` to rotate around the center * @param antialias apply anti-aliasing during the transformation. Looks better but slower. */ -void lv_canvas_transform(lv_obj_t * canvas, lv_img_dsc_t * img, int16_t angle, uint16_t zoom, lv_coord_t offset_x, lv_coord_t offset_y, - int32_t pivot_x, int32_t pivot_y, bool antialias); +void lv_canvas_transform(lv_obj_t * canvas, lv_img_dsc_t * img, int16_t angle, uint16_t zoom, lv_coord_t offset_x, + lv_coord_t offset_y, + int32_t pivot_x, int32_t pivot_y, bool antialias); @@ -194,7 +194,8 @@ void lv_canvas_draw_rect(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_coord * @param txt text to display * @param align align of the text (`LV_LABEL_ALIGN_LEFT/RIGHT/CENTER`) */ -void lv_canvas_draw_text(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_coord_t max_w, lv_draw_label_dsc_t * label_draw_dsc, +void lv_canvas_draw_text(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_coord_t max_w, + lv_draw_label_dsc_t * label_draw_dsc, const char * txt, lv_label_align_t align); /** @@ -203,7 +204,8 @@ void lv_canvas_draw_text(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_coord * @param src image source. Can be a pointer an `lv_img_dsc_t` variable or a path an image. * @param style style of the image (`image` properties are used) */ -void lv_canvas_draw_img(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, const void * src, lv_draw_img_dsc_t * img_draw_dsc); +void lv_canvas_draw_img(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, const void * src, + lv_draw_img_dsc_t * img_draw_dsc); /** * Draw a line on the canvas @@ -212,7 +214,8 @@ void lv_canvas_draw_img(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, const voi * @param point_cnt number of points * @param style style of the line (`line` properties are used) */ -void lv_canvas_draw_line(lv_obj_t * canvas, const lv_point_t * points, uint32_t point_cnt, lv_draw_line_dsc_t * line_draw_dsc); +void lv_canvas_draw_line(lv_obj_t * canvas, const lv_point_t * points, uint32_t point_cnt, + lv_draw_line_dsc_t * line_draw_dsc); /** * Draw a polygon on the canvas @@ -221,7 +224,8 @@ void lv_canvas_draw_line(lv_obj_t * canvas, const lv_point_t * points, uint32_t * @param point_cnt number of points * @param style style of the polygon (`body.main_color` and `body.opa` is used) */ -void lv_canvas_draw_polygon(lv_obj_t * canvas, const lv_point_t * points, uint32_t point_cnt, lv_draw_rect_dsc_t * poly_draw_dsc); +void lv_canvas_draw_polygon(lv_obj_t * canvas, const lv_point_t * points, uint32_t point_cnt, + lv_draw_rect_dsc_t * poly_draw_dsc); /** * Draw an arc on the canvas diff --git a/src/lv_widgets/lv_chart.c b/src/lv_widgets/lv_chart.c index 8e593b638..447815ad4 100644 --- a/src/lv_widgets/lv_chart.c +++ b/src/lv_widgets/lv_chart.c @@ -134,7 +134,8 @@ lv_obj_t * lv_chart_create(lv_obj_t * par, const lv_obj_t * copy) lv_theme_apply(chart, LV_THEME_CHART); - } else { + } + else { lv_chart_ext_t * ext_copy = lv_obj_get_ext_attr(copy); lv_style_list_copy(&ext->style_series, &ext_copy->style_series); @@ -301,8 +302,7 @@ void lv_chart_set_point_count(lv_obj_t * chart, uint16_t point_cnt) if(point_cnt < 1) point_cnt = 1; - LV_LL_READ_BACK(ext->series_ll, ser) - { + LV_LL_READ_BACK(ext->series_ll, ser) { if(ser->start_point != 0) { lv_coord_t * new_points = lv_mem_alloc(sizeof(lv_coord_t) * point_cnt); LV_ASSERT_MEM(new_points); @@ -316,7 +316,8 @@ void lv_chart_set_point_count(lv_obj_t * chart, uint16_t point_cnt) for(i = point_cnt_old; i < point_cnt; i++) { new_points[i] = def; /*Fill up the rest with default value*/ } - } else { + } + else { for(i = 0; i < point_cnt; i++) { new_points[i] = ser->points[(i + ser->start_point) % point_cnt_old]; /*Copy old contents to new array*/ @@ -326,7 +327,8 @@ void lv_chart_set_point_count(lv_obj_t * chart, uint16_t point_cnt) /*Switch over pointer from old to new*/ lv_mem_free(ser->points); ser->points = new_points; - } else { + } + else { ser->points = lv_mem_realloc(ser->points, sizeof(lv_coord_t) * point_cnt); LV_ASSERT_MEM(ser->points); if(ser->points == NULL) return; @@ -400,7 +402,8 @@ void lv_chart_set_next(lv_obj_t * chart, lv_chart_series_t * ser, lv_coord_t y) y; /*This was the place of the former left most value, after shifting it is the rightmost*/ ser->start_point = (ser->start_point + 1) % ext->point_cnt; lv_chart_refresh(chart); - } else if(ext->update_mode == LV_CHART_UPDATE_MODE_CIRCULAR) { + } + else if(ext->update_mode == LV_CHART_UPDATE_MODE_CIRCULAR) { ser->points[ser->start_point] = y; if(ext->type & LV_CHART_TYPE_LINE) invalidate_lines(chart, ser->start_point); @@ -479,11 +482,11 @@ void lv_chart_set_secondary_y_tick_length(lv_obj_t * chart, uint8_t major_tick_l /** * Set the x-axis tick count and labels of a chart - * @param chart pointer to a chart object - * @param list_of_values list of string values, terminated with \n, except the last - * @param num_tick_marks if list_of_values is NULL: total number of ticks per axis - * else number of ticks between two value labels - * @param options extra options + * @param chart pointer to a chart object + * @param list_of_values list of string values, terminated with \n, except the last + * @param num_tick_marks if list_of_values is NULL: total number of ticks per axis + * else number of ticks between two value labels + * @param options extra options */ void lv_chart_set_x_tick_texts(lv_obj_t * chart, const char * list_of_values, uint8_t num_tick_marks, lv_chart_axis_options_t options) @@ -526,7 +529,7 @@ void lv_chart_set_y_tick_texts(lv_obj_t * chart, const char * list_of_values, ui * @param options extra options */ void lv_chart_set_secondary_y_tick_texts(lv_obj_t * chart, const char * list_of_values, uint8_t num_tick_marks, - lv_chart_axis_options_t options) + lv_chart_axis_options_t options) { LV_ASSERT_OBJ(chart, LV_OBJX_NAME); LV_ASSERT_NULL(list_of_values); @@ -600,7 +603,8 @@ static lv_design_res_t lv_chart_design(lv_obj_t * chart, const lv_area_t * clip_ { if(mode == LV_DESIGN_COVER_CHK) { return ancestor_design(chart, clip_area, mode); - } else if(mode == LV_DESIGN_DRAW_MAIN) { + } + else if(mode == LV_DESIGN_DRAW_MAIN) { /*Draw the background*/ lv_draw_rect_dsc_t bg_dsc; lv_draw_rect_dsc_init(&bg_dsc); @@ -647,8 +651,7 @@ static lv_res_t lv_chart_signal(lv_obj_t * chart, lv_signal_t sign, void * param if(sign == LV_SIGNAL_CLEANUP) { lv_coord_t ** datal; - LV_LL_READ(ext->series_ll, datal) - { + LV_LL_READ(ext->series_ll, datal) { lv_mem_free(*datal); } lv_ll_clear(&ext->series_ll); @@ -675,17 +678,17 @@ static lv_style_list_t * lv_chart_get_style(lv_obj_t * chart, uint8_t part) lv_style_list_t * style_dsc_p; switch(part) { - case LV_CHART_PART_BG: - style_dsc_p = &chart->style_list; - break; - case LV_CHART_PART_SERIES_BG: - style_dsc_p = &ext->style_series_bg; - break; - case LV_CHART_PART_SERIES: - style_dsc_p = &ext->style_series; - break; - default: - style_dsc_p = NULL; + case LV_CHART_PART_BG: + style_dsc_p = &chart->style_list; + break; + case LV_CHART_PART_SERIES_BG: + style_dsc_p = &ext->style_series_bg; + break; + case LV_CHART_PART_SERIES: + style_dsc_p = &ext->style_series; + break; + default: + style_dsc_p = NULL; } return style_dsc_p; @@ -725,7 +728,8 @@ static void draw_series_bg(lv_obj_t * chart, const lv_area_t * series_area, cons if(bg_dsc.border_width != 0) { div_i_start = 1; div_i_end = ext->hdiv_cnt; - } else { + } + else { div_i_start = 0; div_i_end = ext->hdiv_cnt + 1; } @@ -745,7 +749,8 @@ static void draw_series_bg(lv_obj_t * chart, const lv_area_t * series_area, cons if(bg_dsc.border_width != 0) { div_i_start = 1; div_i_end = ext->vdiv_cnt; - } else { + } + else { div_i_start = 0; div_i_end = ext->vdiv_cnt + 1; } @@ -797,7 +802,8 @@ static void draw_series_line(lv_obj_t * chart, const lv_area_t * series_area, co has_fade = area_dsc.bg_grad_dir == LV_GRAD_DIR_VER ? true : false; if(has_fade) { - lv_draw_mask_fade_init(&mask_fade_p, &chart->coords, area_dsc.bg_main_color_stop, chart->coords.y1, area_dsc.bg_grad_color_stop, chart->coords.y2); + lv_draw_mask_fade_init(&mask_fade_p, &chart->coords, area_dsc.bg_main_color_stop, chart->coords.y1, + area_dsc.bg_grad_color_stop, chart->coords.y2); } } @@ -809,8 +815,7 @@ static void draw_series_line(lv_obj_t * chart, const lv_area_t * series_area, co lv_coord_t point_radius = lv_obj_get_style_size(chart, LV_CHART_PART_SERIES); /*Go through all data lines*/ - LV_LL_READ_BACK(ext->series_ll, ser) - { + LV_LL_READ_BACK(ext->series_ll, ser) { line_dsc.color = ser->color; point_dsc.bg_color = ser->color; area_dsc.bg_color = ser->color; @@ -942,8 +947,7 @@ static void draw_series_column(lv_obj_t * chart, const lv_area_t * series_area, x_act += series_area->x1 + x_ofs; /*Draw the current point of all data line*/ - LV_LL_READ_BACK(ext->series_ll, ser) - { + LV_LL_READ_BACK(ext->series_ll, ser) { lv_coord_t start_point = ext->update_mode == LV_CHART_UPDATE_MODE_SHIFT ? ser->start_point : 0; col_a.x1 = x_act; @@ -1047,14 +1051,15 @@ static lv_chart_label_iterator_t create_axis_label_iter(const char * list, uint8 /* count number of list items */ for(j = 0; list[j] != '\0'; j++) { - if(list[j] == '\n') - iterator.items_left++; + if(list[j] == '\n') + iterator.items_left++; } if(iterator_dir == LV_CHART_LABEL_ITERATOR_FORWARD) { iterator.is_reverse_iter = 0; iterator.current_pos = list; - } else { + } + else { iterator.is_reverse_iter = 1; // -1 to skip '\0' at the end of the string iterator.current_pos = list + j - 1; @@ -1071,42 +1076,45 @@ static lv_chart_label_iterator_t create_axis_label_iter(const char * list, uint8 static void get_next_axis_label(lv_chart_label_iterator_t * iterator, char * buf) { uint8_t label_len = 0; - if (iterator->is_reverse_iter) { + if(iterator->is_reverse_iter) { const char * label_start; /* count the length of the current label*/ - while ((*iterator->current_pos != '\n') && - (iterator->current_pos != iterator->list_start)) { + while((*iterator->current_pos != '\n') && + (iterator->current_pos != iterator->list_start)) { iterator->current_pos--; label_len++; } label_start = iterator->current_pos; - if (*iterator->current_pos == '\n') { + if(*iterator->current_pos == '\n') { /* do not copy \n symbol, +1 to skip it*/ label_start++; /* skip newline*/ iterator->current_pos--; - } else { + } + else { /* it is last label in list (first one from the beginning )*/ label_len++; } /* do not allow output buffer overflow */ - if (label_len > LV_CHART_AXIS_TICK_LABEL_MAX_LEN) { + if(label_len > LV_CHART_AXIS_TICK_LABEL_MAX_LEN) { label_len = LV_CHART_AXIS_TICK_LABEL_MAX_LEN; } strncpy(buf, label_start, label_len); - } else { + } + else { /* search for tick string */ while(iterator->current_pos[label_len] != '\n' && - iterator->current_pos[label_len] != '\0') { + iterator->current_pos[label_len] != '\0') { /* do not overflow the buffer, but move to the end of the current label */ if(label_len < LV_CHART_AXIS_TICK_LABEL_MAX_LEN) { buf[label_len] = iterator->current_pos[label_len]; label_len++; - } else { + } + else { label_len++; } } @@ -1114,7 +1122,7 @@ static void get_next_axis_label(lv_chart_label_iterator_t * iterator, char * buf iterator->current_pos += label_len; /* do not allow output buffer overflow */ - if (label_len > LV_CHART_AXIS_TICK_LABEL_MAX_LEN) { + if(label_len > LV_CHART_AXIS_TICK_LABEL_MAX_LEN) { label_len = LV_CHART_AXIS_TICK_LABEL_MAX_LEN; } @@ -1141,7 +1149,7 @@ static void draw_y_ticks(lv_obj_t * chart, const lv_area_t * series_area, const { lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart); lv_chart_axis_cfg_t * y_axis = (which_axis == LV_CHART_AXIS_PRIMARY_Y) ? - &ext->y_axis : &ext->secondary_y_axis; + &ext->y_axis : &ext->secondary_y_axis; if(y_axis->list_of_values == NULL && y_axis->num_tick_marks == 0) return; @@ -1183,7 +1191,8 @@ static void draw_y_ticks(lv_obj_t * chart, const lv_area_t * series_area, const minor_tick_len *= -1; } - iter_dir = (y_axis->options & LV_CHART_AXIS_INVERSE_LABELS_ORDER) ? LV_CHART_LABEL_ITERATOR_REVERSE : LV_CHART_LABEL_ITERATOR_FORWARD; + iter_dir = (y_axis->options & LV_CHART_AXIS_INVERSE_LABELS_ORDER) ? LV_CHART_LABEL_ITERATOR_REVERSE : + LV_CHART_LABEL_ITERATOR_FORWARD; iter = create_axis_label_iter(y_axis->list_of_values, iter_dir); /*determine the number of options */ @@ -1199,7 +1208,7 @@ static void draw_y_ticks(lv_obj_t * chart, const lv_area_t * series_area, const num_scale_ticks = (y_axis->num_tick_marks * (num_of_labels - 1)); lv_style_int_t label_dist = which_axis == LV_CHART_AXIS_PRIMARY_Y ? - lv_obj_get_style_pad_left(chart, LV_CHART_PART_SERIES_BG) : lv_obj_get_style_pad_right(chart, LV_CHART_PART_SERIES_BG); + lv_obj_get_style_pad_left(chart, LV_CHART_PART_SERIES_BG) : lv_obj_get_style_pad_right(chart, LV_CHART_PART_SERIES_BG); lv_draw_line_dsc_t line_dsc; lv_draw_line_dsc_init(&line_dsc); @@ -1210,11 +1219,11 @@ static void draw_y_ticks(lv_obj_t * chart, const lv_area_t * series_area, const lv_obj_init_draw_label_dsc(chart, LV_CHART_PART_BG, &label_dsc); for(i = 0; i < (num_scale_ticks + 1); i++) { /* one extra loop - it may not exist in the list, empty label */ - /* first point of the tick */ + /* first point of the tick */ p1.x = x_ofs; /* move extra pixel out of chart boundary */ - if (which_axis == LV_CHART_AXIS_PRIMARY_Y) + if(which_axis == LV_CHART_AXIS_PRIMARY_Y) p1.x--; else p1.x++; @@ -1227,7 +1236,7 @@ static void draw_y_ticks(lv_obj_t * chart, const lv_area_t * series_area, const /* draw a line at moving y position */ p2.y = p1.y = - y_ofs + (int32_t)((int32_t)(h - line_dsc.width) * i) / num_scale_ticks; + y_ofs + (int32_t)((int32_t)(h - line_dsc.width) * i) / num_scale_ticks; if(y_axis->options & LV_CHART_AXIS_INVERSE_LABELS_ORDER) { /*if label order is inversed last tick have number 0*/ @@ -1235,7 +1244,8 @@ static void draw_y_ticks(lv_obj_t * chart, const lv_area_t * series_area, const lv_draw_line(&p1, &p2, mask, &line_dsc); else if((y_axis->options & LV_CHART_AXIS_DRAW_LAST_TICK) != 0) lv_draw_line(&p1, &p2, mask, &line_dsc); - } else { + } + else { if(i != num_scale_ticks) lv_draw_line(&p1, &p2, mask, &line_dsc); else if((y_axis->options & LV_CHART_AXIS_DRAW_LAST_TICK) != 0) @@ -1260,7 +1270,8 @@ static void draw_y_ticks(lv_obj_t * chart, const lv_area_t * series_area, const if(which_axis == LV_CHART_AXIS_PRIMARY_Y) { a.x1 = p2.x - size.x - label_dist; a.x2 = p2.x - label_dist; - } else { + } + else { a.x1 = p2.x + label_dist; a.x2 = p2.x + size.x + label_dist; } @@ -1352,11 +1363,12 @@ static void draw_x_ticks(lv_obj_t * chart, const lv_area_t * series_area, const /* reserve appropriate area */ lv_point_t size; lv_txt_get_size(&size, buf, label_dsc.font, label_dsc.letter_space, label_dsc.line_space, - LV_COORD_MAX, LV_TXT_FLAG_CENTER); + LV_COORD_MAX, LV_TXT_FLAG_CENTER); /* set the area at some distance of the major tick len under of the tick */ lv_area_t a = {(p2.x - size.x / 2), (p2.y + label_dist), (p2.x + size.x / 2), - (p2.y + size.y + label_dist)}; + (p2.y + size.y + label_dist) + }; lv_draw_label(&a, mask, &label_dsc, buf, NULL); } } diff --git a/src/lv_widgets/lv_chart.h b/src/lv_widgets/lv_chart.h index 2bce2ab4f..77534cc8c 100644 --- a/src/lv_widgets/lv_chart.h +++ b/src/lv_widgets/lv_chart.h @@ -52,8 +52,7 @@ enum { }; typedef uint8_t lv_chart_update_mode_t; -typedef struct -{ +typedef struct { lv_coord_t * points; lv_color_t color; uint16_t start_point; @@ -67,8 +66,7 @@ enum { }; typedef uint8_t lv_chart_axis_options_t; -typedef struct -{ +typedef struct { const char * list_of_values; lv_chart_axis_options_t options; uint8_t num_tick_marks; @@ -77,8 +75,7 @@ typedef struct } lv_chart_axis_cfg_t; /*Data of chart */ -typedef struct -{ +typedef struct { /*No inherited ext*/ /*Ext. of ancestor*/ /*New data for this type */ lv_ll_t series_ll; /*Linked list for the data line pointers (stores lv_chart_dl_t)*/ @@ -250,7 +247,7 @@ void lv_chart_set_x_tick_texts(lv_obj_t * chart, const char * list_of_values, ui * @param options extra options */ void lv_chart_set_secondary_y_tick_texts(lv_obj_t * chart, const char * list_of_values, uint8_t num_tick_marks, - lv_chart_axis_options_t options); + lv_chart_axis_options_t options); /** * Set the y-axis tick count and labels of a chart diff --git a/src/lv_widgets/lv_checkbox.c b/src/lv_widgets/lv_checkbox.c index e26da1a07..ab11a4e8a 100644 --- a/src/lv_widgets/lv_checkbox.c +++ b/src/lv_widgets/lv_checkbox.c @@ -85,13 +85,14 @@ lv_obj_t * lv_checkbox_create(lv_obj_t * par, const lv_obj_t * copy) lv_theme_apply(cb, LV_THEME_CHECKBOX); - } else { + } + else { lv_checkbox_ext_t * copy_ext = lv_obj_get_ext_attr(copy); ext->bullet = lv_obj_create(cb, copy_ext->bullet); ext->label = lv_label_create(cb, copy_ext->label); /*Refresh the style with new signal function*/ -// lv_obj_refresh_style(cb); + // lv_obj_refresh_style(cb); } LV_LOG_INFO("check box created"); @@ -181,10 +182,12 @@ static lv_res_t lv_checkbox_signal(lv_obj_t * cb, lv_signal_t sign, void * param lv_coord_t line_height = lv_font_get_line_height(font); lv_obj_set_size(ext->bullet, line_height, line_height); lv_obj_set_state(ext->bullet, lv_obj_get_state(cb, LV_CHECKBOX_PART_BG)); - } else if(sign == LV_SIGNAL_PRESSED || sign == LV_SIGNAL_RELEASED || sign == LV_SIGNAL_PRESS_LOST || + } + else if(sign == LV_SIGNAL_PRESSED || sign == LV_SIGNAL_RELEASED || sign == LV_SIGNAL_PRESS_LOST || sign == LV_SIGNAL_FOCUS || sign == LV_SIGNAL_DEFOCUS) { lv_obj_set_state(ext->bullet, lv_obj_get_state(cb, LV_CHECKBOX_PART_BG)); - } else if(sign == LV_SIGNAL_CONTROL) { + } + else if(sign == LV_SIGNAL_CONTROL) { char c = *((char *)param); if(c == LV_KEY_RIGHT || c == LV_KEY_DOWN || c == LV_KEY_LEFT || c == LV_KEY_UP) { /*Follow the backgrounds state with the bullet*/ @@ -202,14 +205,14 @@ static lv_style_list_t * lv_checkbox_get_style(lv_obj_t * cb, uint8_t type) lv_checkbox_ext_t * ext = lv_obj_get_ext_attr(cb); switch(type) { - case LV_CHECKBOX_PART_BG: - style_dsc_p = &cb->style_list; - break; - case LV_CHECKBOX_PART_BULLET: - style_dsc_p = lv_obj_get_style_list(ext->bullet, LV_BTN_PART_MAIN); - break; - default: - style_dsc_p = NULL; + case LV_CHECKBOX_PART_BG: + style_dsc_p = &cb->style_list; + break; + case LV_CHECKBOX_PART_BULLET: + style_dsc_p = lv_obj_get_style_list(ext->bullet, LV_BTN_PART_MAIN); + break; + default: + style_dsc_p = NULL; } return style_dsc_p; diff --git a/src/lv_widgets/lv_checkbox.h b/src/lv_widgets/lv_checkbox.h index c6fe7b3b3..db17e617b 100644 --- a/src/lv_widgets/lv_checkbox.h +++ b/src/lv_widgets/lv_checkbox.h @@ -39,8 +39,7 @@ extern "C" { **********************/ /*Data of check box*/ -typedef struct -{ +typedef struct { lv_btn_ext_t bg_btn; /*Ext. of ancestor*/ /*New data for this type */ lv_obj_t * bullet; /*Pointer to button*/ @@ -93,7 +92,7 @@ void lv_checkbox_set_static_text(lv_obj_t * cb, const char * txt); */ static inline void lv_checkbox_set_checked(lv_obj_t * cb, bool checked) { - lv_btn_set_state(cb, checked ? LV_BTN_STATE_CHECKED_RELEASED: LV_BTN_STATE_RELEASED); + lv_btn_set_state(cb, checked ? LV_BTN_STATE_CHECKED_RELEASED : LV_BTN_STATE_RELEASED); } /** @@ -141,7 +140,7 @@ static inline bool lv_checkbox_is_checked(const lv_obj_t * cb) */ static inline bool lv_checkbox_is_inactive(const lv_obj_t * cb) { - return lv_btn_get_state(cb) == LV_BTN_STATE_DISABLED ? true :false; + return lv_btn_get_state(cb) == LV_BTN_STATE_DISABLED ? true : false; } diff --git a/src/lv_widgets/lv_cont.c b/src/lv_widgets/lv_cont.c index 58c3ed907..6ef1f41e6 100644 --- a/src/lv_widgets/lv_cont.c +++ b/src/lv_widgets/lv_cont.c @@ -76,7 +76,7 @@ lv_obj_t * lv_cont_create(lv_obj_t * par, const lv_obj_t * copy) if(cont == NULL) return NULL; if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_cb(cont); - if(ancestor_design == NULL) ancestor_design= lv_obj_get_design_cb(cont); + if(ancestor_design == NULL) ancestor_design = lv_obj_get_design_cb(cont); lv_obj_allocate_ext_attr(cont, sizeof(lv_cont_ext_t)); lv_cont_ext_t * ext = lv_obj_get_ext_attr(cont); @@ -270,15 +270,18 @@ static lv_res_t lv_cont_signal(lv_obj_t * cont, lv_signal_t sign, void * param) if(sign == LV_SIGNAL_STYLE_CHG) { /*Recalculate the padding if the style changed*/ lv_cont_refr_layout(cont); lv_cont_refr_autofit(cont); - } else if(sign == LV_SIGNAL_CHILD_CHG) { + } + else if(sign == LV_SIGNAL_CHILD_CHG) { lv_cont_refr_layout(cont); lv_cont_refr_autofit(cont); - } else if(sign == LV_SIGNAL_COORD_CHG) { + } + else if(sign == LV_SIGNAL_COORD_CHG) { if(lv_obj_get_width(cont) != lv_area_get_width(param) || lv_obj_get_height(cont) != lv_area_get_height(param)) { lv_cont_refr_layout(cont); lv_cont_refr_autofit(cont); } - } else if(sign == LV_SIGNAL_PARENT_SIZE_CHG) { + } + else if(sign == LV_SIGNAL_PARENT_SIZE_CHG) { /*FLOOD and FILL fit needs to be refreshed if the parent's size has changed*/ lv_cont_refr_autofit(cont); } @@ -291,11 +294,11 @@ static lv_style_list_t * lv_cont_get_style(lv_obj_t * cont, uint8_t type) { lv_style_list_t * style_dsc_p; switch(type) { - case LV_CONT_PART_MAIN: - style_dsc_p = &cont->style_list; - break; - default: - style_dsc_p = NULL; + case LV_CONT_PART_MAIN: + style_dsc_p = &cont->style_list; + break; + default: + style_dsc_p = NULL; } return style_dsc_p; @@ -316,13 +319,17 @@ static void lv_cont_refr_layout(lv_obj_t * cont) if(type == LV_LAYOUT_CENTER) { lv_cont_layout_center(cont); - } else if(type == LV_LAYOUT_COLUMN_LEFT || type == LV_LAYOUT_COLUMN_MID || type == LV_LAYOUT_COLUMN_RIGHT) { + } + else if(type == LV_LAYOUT_COLUMN_LEFT || type == LV_LAYOUT_COLUMN_MID || type == LV_LAYOUT_COLUMN_RIGHT) { lv_cont_layout_col(cont); - } else if(type == LV_LAYOUT_ROW_TOP || type == LV_LAYOUT_ROW_MID || type == LV_LAYOUT_ROW_BOTTOM) { + } + else if(type == LV_LAYOUT_ROW_TOP || type == LV_LAYOUT_ROW_MID || type == LV_LAYOUT_ROW_BOTTOM) { lv_cont_layout_row(cont); - } else if(type == LV_LAYOUT_PRETTY_MID || type == LV_LAYOUT_PRETTY_TOP || type == LV_LAYOUT_PRETTY_BOTTOM) { + } + else if(type == LV_LAYOUT_PRETTY_MID || type == LV_LAYOUT_PRETTY_TOP || type == LV_LAYOUT_PRETTY_BOTTOM) { lv_cont_layout_pretty(cont); - } else if(type == LV_LAYOUT_GRID) { + } + else if(type == LV_LAYOUT_GRID) { lv_cont_layout_grid(cont); } } @@ -369,8 +376,7 @@ static void lv_cont_layout_col(lv_obj_t * cont) lv_obj_add_protect(cont, LV_PROTECT_CHILD_CHG); /* Align the children */ lv_coord_t last_cord = top; - LV_LL_READ_BACK(cont->child_ll, child) - { + LV_LL_READ_BACK(cont->child_ll, child) { if(lv_obj_get_hidden(child) != false || lv_obj_is_protected(child, LV_PROTECT_POS) != false) continue; lv_obj_align(child, cont, align, hpad_corr, last_cord); @@ -401,11 +407,11 @@ static void lv_cont_layout_row(lv_obj_t * cont) break; case LV_LAYOUT_ROW_MID: vpad_corr = 0; - align = base_dir == LV_BIDI_DIR_RTL ? LV_ALIGN_IN_RIGHT_MID: LV_ALIGN_IN_LEFT_MID; + align = base_dir == LV_BIDI_DIR_RTL ? LV_ALIGN_IN_RIGHT_MID : LV_ALIGN_IN_LEFT_MID; break; case LV_LAYOUT_ROW_BOTTOM: vpad_corr = -lv_obj_get_style_pad_bottom(cont, LV_CONT_PART_MAIN); - align = base_dir == LV_BIDI_DIR_RTL ? LV_ALIGN_IN_BOTTOM_RIGHT: LV_ALIGN_IN_BOTTOM_LEFT; + align = base_dir == LV_BIDI_DIR_RTL ? LV_ALIGN_IN_BOTTOM_RIGHT : LV_ALIGN_IN_BOTTOM_LEFT; break; default: vpad_corr = 0; @@ -424,8 +430,7 @@ static void lv_cont_layout_row(lv_obj_t * cont) lv_coord_t inner = lv_obj_get_style_pad_inner(cont, LV_CONT_PART_MAIN); - LV_LL_READ_BACK(cont->child_ll, child) - { + LV_LL_READ_BACK(cont->child_ll, child) { if(lv_obj_get_hidden(child) != false || lv_obj_is_protected(child, LV_PROTECT_POS) != false) continue; if(base_dir == LV_BIDI_DIR_RTL) lv_obj_align(child, cont, align, -last_cord, vpad_corr); @@ -448,8 +453,7 @@ static void lv_cont_layout_center(lv_obj_t * cont) lv_coord_t h_tot = 0; lv_coord_t inner = lv_obj_get_style_pad_inner(cont, LV_CONT_PART_MAIN); - LV_LL_READ(cont->child_ll, child) - { + LV_LL_READ(cont->child_ll, child) { if(lv_obj_get_hidden(child) != false || lv_obj_is_protected(child, LV_PROTECT_POS) != false) continue; h_tot += lv_obj_get_height(child) + inner; obj_num++; @@ -465,8 +469,7 @@ static void lv_cont_layout_center(lv_obj_t * cont) /* Align the children */ lv_coord_t last_cord = -(h_tot / 2); - LV_LL_READ_BACK(cont->child_ll, child) - { + LV_LL_READ_BACK(cont->child_ll, child) { if(lv_obj_get_hidden(child) != false || lv_obj_is_protected(child, LV_PROTECT_POS) != false) continue; lv_obj_align(child, cont, LV_ALIGN_CENTER, 0, last_cord + lv_obj_get_height(child) / 2); @@ -549,20 +552,20 @@ static void lv_cont_layout_pretty(lv_obj_t * cont) w_row = lv_obj_get_width(obj1) + lv_obj_get_width(obj2); lv_coord_t pad = (w_obj - w_row) / 3; switch(type) { - case LV_LAYOUT_PRETTY_TOP: - lv_obj_align(obj1, cont, LV_ALIGN_IN_TOP_LEFT, pad, act_y); - lv_obj_align(obj2, cont, LV_ALIGN_IN_TOP_RIGHT, -pad, act_y); - break; - case LV_LAYOUT_PRETTY_MID: - lv_obj_align(obj1, cont, LV_ALIGN_IN_TOP_LEFT, pad, act_y + (h_row - lv_obj_get_height(obj1)) / 2); - lv_obj_align(obj2, cont, LV_ALIGN_IN_TOP_RIGHT, -pad, act_y + (h_row - lv_obj_get_height(obj2)) / 2); - break; - case LV_LAYOUT_PRETTY_BOTTOM: - lv_obj_align(obj1, cont, LV_ALIGN_IN_TOP_LEFT, pad, act_y + h_row - lv_obj_get_height(obj1)); - lv_obj_align(obj2, cont, LV_ALIGN_IN_TOP_RIGHT, -pad, act_y + h_row - lv_obj_get_height(obj2)); - break; - default: - break; + case LV_LAYOUT_PRETTY_TOP: + lv_obj_align(obj1, cont, LV_ALIGN_IN_TOP_LEFT, pad, act_y); + lv_obj_align(obj2, cont, LV_ALIGN_IN_TOP_RIGHT, -pad, act_y); + break; + case LV_LAYOUT_PRETTY_MID: + lv_obj_align(obj1, cont, LV_ALIGN_IN_TOP_LEFT, pad, act_y + (h_row - lv_obj_get_height(obj1)) / 2); + lv_obj_align(obj2, cont, LV_ALIGN_IN_TOP_RIGHT, -pad, act_y + (h_row - lv_obj_get_height(obj2)) / 2); + break; + case LV_LAYOUT_PRETTY_BOTTOM: + lv_obj_align(obj1, cont, LV_ALIGN_IN_TOP_LEFT, pad, act_y + h_row - lv_obj_get_height(obj1)); + lv_obj_align(obj2, cont, LV_ALIGN_IN_TOP_RIGHT, -pad, act_y + h_row - lv_obj_get_height(obj2)); + break; + default: + break; } } /* Align the children (from child_rs to child_rc)*/ @@ -574,21 +577,21 @@ static void lv_cont_layout_pretty(lv_obj_t * cont) while(child_tmp != NULL) { if(lv_obj_get_hidden(child_tmp) == false && lv_obj_is_protected(child_tmp, LV_PROTECT_POS) == false) { switch(type) { - case LV_LAYOUT_PRETTY_TOP: - lv_obj_align(child_tmp, cont, LV_ALIGN_IN_TOP_LEFT, act_x, - act_y); - break; - case LV_LAYOUT_PRETTY_MID: - lv_obj_align(child_tmp, cont, LV_ALIGN_IN_TOP_LEFT, act_x, - act_y + (h_row - lv_obj_get_height(child_tmp)) / 2); + case LV_LAYOUT_PRETTY_TOP: + lv_obj_align(child_tmp, cont, LV_ALIGN_IN_TOP_LEFT, act_x, + act_y); + break; + case LV_LAYOUT_PRETTY_MID: + lv_obj_align(child_tmp, cont, LV_ALIGN_IN_TOP_LEFT, act_x, + act_y + (h_row - lv_obj_get_height(child_tmp)) / 2); - break; - case LV_LAYOUT_PRETTY_BOTTOM: - lv_obj_align(child_tmp, cont, LV_ALIGN_IN_TOP_LEFT, act_x, - act_y + h_row - lv_obj_get_height(child_tmp)); - break; - default: - break; + break; + case LV_LAYOUT_PRETTY_BOTTOM: + lv_obj_align(child_tmp, cont, LV_ALIGN_IN_TOP_LEFT, act_x, + act_y + h_row - lv_obj_get_height(child_tmp)); + break; + default: + break; } act_x += lv_obj_get_width(child_tmp) + new_opad; @@ -622,7 +625,8 @@ static void lv_cont_layout_grid(lv_obj_t * cont) lv_coord_t x_ofs; if(obj_row > 1) { x_ofs = w_obj + (w_fit - (obj_row * w_obj)) / (obj_row - 1); - } else { + } + else { x_ofs = w_tot / 2 - w_obj / 2; } lv_coord_t y_ofs = h_obj + inner; @@ -636,14 +640,14 @@ static void lv_cont_layout_grid(lv_obj_t * cont) lv_coord_t act_x = left; lv_coord_t act_y = lv_obj_get_style_pad_top(cont, LV_CONT_PART_MAIN); uint16_t obj_cnt = 0; - LV_LL_READ_BACK(cont->child_ll, child) - { + LV_LL_READ_BACK(cont->child_ll, child) { if(lv_obj_get_hidden(child) != false || lv_obj_is_protected(child, LV_PROTECT_POS) != false) continue; if(obj_row > 1) { lv_obj_set_pos(child, act_x, act_y); act_x += x_ofs; - } else { + } + else { lv_obj_set_pos(child, x_ofs, act_y); } obj_cnt++; @@ -695,8 +699,7 @@ static void lv_cont_refr_autofit(lv_obj_t * cont) tight_area.x2 = LV_COORD_MIN; tight_area.y2 = LV_COORD_MIN; - LV_LL_READ(cont->child_ll, child_i) - { + LV_LL_READ(cont->child_ll, child_i) { if(lv_obj_get_hidden(child_i) != false) continue; tight_area.x1 = LV_MATH_MIN(tight_area.x1, child_i->coords.x1); tight_area.y1 = LV_MATH_MIN(tight_area.y1, child_i->coords.y1); @@ -714,31 +717,59 @@ static void lv_cont_refr_autofit(lv_obj_t * cont) lv_area_copy(&new_area, &ori); switch(ext->fit_left) { - case LV_FIT_TIGHT: new_area.x1 = tight_area.x1; break; - case LV_FIT_PARENT: new_area.x1 = flood_area.x1; break; - case LV_FIT_MAX: new_area.x1 = has_children ? LV_MATH_MIN(tight_area.x1, flood_area.x1) : flood_area.x1; break; - default: break; + case LV_FIT_TIGHT: + new_area.x1 = tight_area.x1; + break; + case LV_FIT_PARENT: + new_area.x1 = flood_area.x1; + break; + case LV_FIT_MAX: + new_area.x1 = has_children ? LV_MATH_MIN(tight_area.x1, flood_area.x1) : flood_area.x1; + break; + default: + break; } switch(ext->fit_right) { - case LV_FIT_TIGHT: new_area.x2 = tight_area.x2; break; - case LV_FIT_PARENT: new_area.x2 = flood_area.x2; break; - case LV_FIT_MAX: new_area.x2 = has_children ? LV_MATH_MAX(tight_area.x2, flood_area.x2) : flood_area.x2; break; - default: break; + case LV_FIT_TIGHT: + new_area.x2 = tight_area.x2; + break; + case LV_FIT_PARENT: + new_area.x2 = flood_area.x2; + break; + case LV_FIT_MAX: + new_area.x2 = has_children ? LV_MATH_MAX(tight_area.x2, flood_area.x2) : flood_area.x2; + break; + default: + break; } switch(ext->fit_top) { - case LV_FIT_TIGHT: new_area.y1 = tight_area.y1; break; - case LV_FIT_PARENT: new_area.y1 = flood_area.y1; break; - case LV_FIT_MAX: new_area.y1 = has_children ? LV_MATH_MIN(tight_area.y1, flood_area.y1) : flood_area.y1; break; - default: break; + case LV_FIT_TIGHT: + new_area.y1 = tight_area.y1; + break; + case LV_FIT_PARENT: + new_area.y1 = flood_area.y1; + break; + case LV_FIT_MAX: + new_area.y1 = has_children ? LV_MATH_MIN(tight_area.y1, flood_area.y1) : flood_area.y1; + break; + default: + break; } switch(ext->fit_bottom) { - case LV_FIT_TIGHT: new_area.y2 = tight_area.y2; break; - case LV_FIT_PARENT: new_area.y2 = flood_area.y2; break; - case LV_FIT_MAX: new_area.y2 = has_children ? LV_MATH_MAX(tight_area.y2, flood_area.y2) : flood_area.y2; break; - default: break; + case LV_FIT_TIGHT: + new_area.y2 = tight_area.y2; + break; + case LV_FIT_PARENT: + new_area.y2 = flood_area.y2; + break; + case LV_FIT_MAX: + new_area.y2 = has_children ? LV_MATH_MAX(tight_area.y2, flood_area.y2) : flood_area.y2; + break; + default: + break; } /*Do nothing if the coordinates are not changed*/ diff --git a/src/lv_widgets/lv_cont.h b/src/lv_widgets/lv_cont.h index c26ed8f41..837559a3d 100644 --- a/src/lv_widgets/lv_cont.h +++ b/src/lv_widgets/lv_cont.h @@ -97,8 +97,7 @@ enum { }; typedef uint8_t lv_fit_t; -typedef struct -{ +typedef struct { /*Inherited from 'base_obj' so no inherited ext. */ /*Ext. of ancestor*/ /*New data for this type */ lv_layout_t layout : 4; /*A layout from 'lv_layout_t' enum*/ diff --git a/src/lv_widgets/lv_cpicker.c b/src/lv_widgets/lv_cpicker.c index d3a3e49c2..25fcf9a79 100644 --- a/src/lv_widgets/lv_cpicker.c +++ b/src/lv_widgets/lv_cpicker.c @@ -23,27 +23,27 @@ #define LV_OBJX_NAME "lv_cpicker" #ifndef LV_CPICKER_DEF_TYPE -#define LV_CPICKER_DEF_TYPE LV_CPICKER_TYPE_DISC + #define LV_CPICKER_DEF_TYPE LV_CPICKER_TYPE_DISC #endif #ifndef LV_CPICKER_DEF_HUE -#define LV_CPICKER_DEF_HUE 0 + #define LV_CPICKER_DEF_HUE 0 #endif #ifndef LV_CPICKER_DEF_SATURATION -#define LV_CPICKER_DEF_SATURATION 100 + #define LV_CPICKER_DEF_SATURATION 100 #endif #ifndef LV_CPICKER_DEF_VALUE -#define LV_CPICKER_DEF_VALUE 100 + #define LV_CPICKER_DEF_VALUE 100 #endif #ifndef LV_CPICKER_DEF_HSV -#define LV_CPICKER_DEF_HSV ((lv_color_hsv_t){LV_CPICKER_DEF_HUE, LV_CPICKER_DEF_SATURATION, LV_CPICKER_DEF_VALUE}) + #define LV_CPICKER_DEF_HSV ((lv_color_hsv_t){LV_CPICKER_DEF_HUE, LV_CPICKER_DEF_SATURATION, LV_CPICKER_DEF_VALUE}) #endif #ifndef LV_CPICKER_DEF_QF /*quantization factor*/ -#define LV_CPICKER_DEF_QF 3 + #define LV_CPICKER_DEF_QF 3 #endif #define TRI_OFFSET 2 @@ -225,19 +225,19 @@ bool lv_cpicker_set_hsv(lv_obj_t * cpicker, lv_color_hsv_t hsv) { LV_ASSERT_OBJ(cpicker, LV_OBJX_NAME); - if (hsv.h > 360) hsv.h %= 360; - if (hsv.s > 100) hsv.s = 100; - if (hsv.v > 100) hsv.v = 100; + if(hsv.h > 360) hsv.h %= 360; + if(hsv.s > 100) hsv.s = 100; + if(hsv.v > 100) hsv.v = 100; lv_cpicker_ext_t * ext = lv_obj_get_ext_attr(cpicker); - if (ext->hsv.h == hsv.h && ext->hsv.s == hsv.s && ext->hsv.v == hsv.v) return false; + if(ext->hsv.h == hsv.h && ext->hsv.s == hsv.s && ext->hsv.v == hsv.v) return false; ext->hsv = hsv; refr_indic_pos(cpicker); - if (ext->type == LV_CPICKER_TYPE_DISC) { + if(ext->type == LV_CPICKER_TYPE_DISC) { lv_obj_invalidate(cpicker); } @@ -258,7 +258,7 @@ bool lv_cpicker_set_color(lv_obj_t * cpicker, lv_color_t color) c32.full = lv_color_to32(color); return lv_cpicker_set_hsv(cpicker, - lv_color_rgb_to_hsv(c32.ch.red, c32.ch.green, c32.ch.blue)); + lv_color_rgb_to_hsv(c32.ch.red, c32.ch.green, c32.ch.blue)); } /** @@ -309,7 +309,7 @@ void lv_cpicker_set_indic_colored(lv_obj_t * cpicker, bool en) * Getter functions *====================*/ -/** +/** * Get the current color mode. * @param cpicker pointer to colorpicker object * @return color mode (hue/sat/val) @@ -452,7 +452,8 @@ static lv_design_res_t lv_cpicker_design(lv_obj_t * cpicker, const lv_area_t * c if(ext->type == LV_CPICKER_TYPE_DISC) { draw_disc_grad(cpicker, clip_area); - } else if(ext->type == LV_CPICKER_TYPE_RECT) { + } + else if(ext->type == LV_CPICKER_TYPE_RECT) { draw_rect_grad(cpicker, clip_area); } @@ -482,14 +483,14 @@ static void draw_disc_grad(lv_obj_t * cpicker, const lv_area_t * mask) uint16_t i; lv_coord_t cir_w = lv_obj_get_style_scale_width(cpicker, LV_CPICKER_PART_MAIN); - for(i = 0; i <= 360; i+= LV_CPICKER_DEF_QF) { + for(i = 0; i <= 360; i += LV_CPICKER_DEF_QF) { line_dsc.color = angle_to_mode_color(cpicker, i); lv_point_t p[2]; p[0].x = cx + (r * lv_trigo_sin(i) >> LV_TRIGO_SHIFT); - p[0].y = cy + (r * lv_trigo_sin(i+ 90) >> LV_TRIGO_SHIFT); - p[1].x = cx + ((r-cir_w) * lv_trigo_sin(i) >> LV_TRIGO_SHIFT); - p[1].y = cy + ((r-cir_w) * lv_trigo_sin(i+ 90) >> LV_TRIGO_SHIFT); + p[0].y = cy + (r * lv_trigo_sin(i + 90) >> LV_TRIGO_SHIFT); + p[1].x = cx + ((r - cir_w) * lv_trigo_sin(i) >> LV_TRIGO_SHIFT); + p[1].y = cy + ((r - cir_w) * lv_trigo_sin(i + 90) >> LV_TRIGO_SHIFT); lv_draw_line(&p[0], &p[1], mask, &line_dsc); } @@ -564,7 +565,7 @@ static void draw_rect_grad(lv_obj_t * cpicker, const lv_area_t * mask) uint16_t i; for(i = 0; i < 360; i += i_step) { - bg_dsc.bg_color = angle_to_mode_color(cpicker, i); + bg_dsc.bg_color = angle_to_mode_color(cpicker, i); /*the following attribute might need changing between index to add border, shadow, radius etc*/ lv_area_t rect_area; @@ -592,7 +593,7 @@ static void draw_indic(lv_obj_t * cpicker, const lv_area_t * mask) cir_dsc.radius = LV_RADIUS_CIRCLE; if(ext->indic.colored) { - cir_dsc.bg_color = lv_cpicker_get_color(cpicker); + cir_dsc.bg_color = lv_cpicker_get_color(cpicker); } lv_area_t indic_area = get_indic_area(cpicker); @@ -614,7 +615,7 @@ static lv_area_t get_indic_area(lv_obj_t * cpicker) /*Get indicator's radius*/ uint16_t r = 0; if(ext->type == LV_CPICKER_TYPE_DISC) { - r = lv_obj_get_style_scale_width(cpicker, LV_CPICKER_PART_MAIN) / 2; + r = lv_obj_get_style_scale_width(cpicker, LV_CPICKER_PART_MAIN) / 2; } else if(ext->type == LV_CPICKER_TYPE_RECT) { lv_coord_t h = lv_obj_get_height(cpicker); @@ -648,10 +649,10 @@ static lv_res_t lv_cpicker_signal(lv_obj_t * cpicker, lv_signal_t sign, void * p lv_res_t res; if(sign == LV_SIGNAL_GET_STYLE) { - lv_get_style_info_t * info = param; - info->result = lv_cpicker_get_style(cpicker, info->part); - if(info->result != NULL) return LV_RES_OK; - else return ancestor_signal(cpicker, sign, param); + lv_get_style_info_t * info = param; + info->result = lv_cpicker_get_style(cpicker, info->part); + if(info->result != NULL) return LV_RES_OK; + else return ancestor_signal(cpicker, sign, param); } res = ancestor_signal(cpicker, sign, param); @@ -662,7 +663,8 @@ static lv_res_t lv_cpicker_signal(lv_obj_t * cpicker, lv_signal_t sign, void * p if(sign == LV_SIGNAL_CLEANUP) { lv_obj_clean_style_list(cpicker, LV_CPICKER_PART_INDIC); - } else if(sign == LV_SIGNAL_REFR_EXT_DRAW_PAD) { + } + else if(sign == LV_SIGNAL_REFR_EXT_DRAW_PAD) { lv_style_int_t left = lv_obj_get_style_pad_left(cpicker, LV_CPICKER_PART_INDIC); lv_style_int_t right = lv_obj_get_style_pad_right(cpicker, LV_CPICKER_PART_INDIC); lv_style_int_t top = lv_obj_get_style_pad_top(cpicker, LV_CPICKER_PART_INDIC); @@ -672,11 +674,13 @@ static lv_res_t lv_cpicker_signal(lv_obj_t * cpicker, lv_signal_t sign, void * p if(ext->type == LV_CPICKER_TYPE_DISC) { cpicker->ext_draw_pad = LV_MATH_MAX(cpicker->ext_draw_pad, indic_pad); - } else { + } + else { indic_pad += lv_obj_get_height(cpicker) / 2; cpicker->ext_draw_pad = LV_MATH_MAX(cpicker->ext_draw_pad, indic_pad); } - } else if(sign == LV_SIGNAL_COORD_CHG) { + } + else if(sign == LV_SIGNAL_COORD_CHG) { /*Refresh extended draw area to make knob visible*/ if(lv_obj_get_width(cpicker) != lv_area_get_width(param) || lv_obj_get_height(cpicker) != lv_area_get_height(param)) { @@ -684,7 +688,8 @@ static lv_res_t lv_cpicker_signal(lv_obj_t * cpicker, lv_signal_t sign, void * p refr_indic_pos(cpicker); lv_obj_invalidate(cpicker); } - } else if(sign == LV_SIGNAL_STYLE_CHG) { + } + else if(sign == LV_SIGNAL_STYLE_CHG) { /*Refresh extended draw area to make knob visible*/ lv_obj_refresh_ext_draw_pad(cpicker); refr_indic_pos(cpicker); @@ -697,18 +702,18 @@ static lv_res_t lv_cpicker_signal(lv_obj_t * cpicker, lv_signal_t sign, void * p hsv_cur = ext->hsv; switch(ext->color_mode) { - case LV_CPICKER_COLOR_MODE_HUE: - hsv_cur.h = (ext->hsv.h + 1) % 360; - break; - case LV_CPICKER_COLOR_MODE_SATURATION: - hsv_cur.s = (ext->hsv.s + 1) % 100; - break; - case LV_CPICKER_COLOR_MODE_VALUE: - hsv_cur.v = (ext->hsv.v + 1) % 100; - break; + case LV_CPICKER_COLOR_MODE_HUE: + hsv_cur.h = (ext->hsv.h + 1) % 360; + break; + case LV_CPICKER_COLOR_MODE_SATURATION: + hsv_cur.s = (ext->hsv.s + 1) % 100; + break; + case LV_CPICKER_COLOR_MODE_VALUE: + hsv_cur.v = (ext->hsv.v + 1) % 100; + break; } - if (lv_cpicker_set_hsv(cpicker, hsv_cur)) { + if(lv_cpicker_set_hsv(cpicker, hsv_cur)) { res = lv_event_send(cpicker, LV_EVENT_VALUE_CHANGED, NULL); if(res != LV_RES_OK) return res; } @@ -718,18 +723,18 @@ static lv_res_t lv_cpicker_signal(lv_obj_t * cpicker, lv_signal_t sign, void * p hsv_cur = ext->hsv; switch(ext->color_mode) { - case LV_CPICKER_COLOR_MODE_HUE: - hsv_cur.h = ext->hsv.h > 0?(ext->hsv.h - 1) : 360; - break; - case LV_CPICKER_COLOR_MODE_SATURATION: - hsv_cur.s = ext->hsv.s > 0?(ext->hsv.s - 1) : 100; - break; - case LV_CPICKER_COLOR_MODE_VALUE: - hsv_cur.v = ext->hsv.v > 0?(ext->hsv.v - 1) : 100; - break; + case LV_CPICKER_COLOR_MODE_HUE: + hsv_cur.h = ext->hsv.h > 0 ? (ext->hsv.h - 1) : 360; + break; + case LV_CPICKER_COLOR_MODE_SATURATION: + hsv_cur.s = ext->hsv.s > 0 ? (ext->hsv.s - 1) : 100; + break; + case LV_CPICKER_COLOR_MODE_VALUE: + hsv_cur.v = ext->hsv.v > 0 ? (ext->hsv.v - 1) : 100; + break; } - if (lv_cpicker_set_hsv(cpicker, hsv_cur)) { + if(lv_cpicker_set_hsv(cpicker, hsv_cur)) { res = lv_event_send(cpicker, LV_EVENT_VALUE_CHANGED, NULL); if(res != LV_RES_OK) return res; } @@ -740,7 +745,8 @@ static lv_res_t lv_cpicker_signal(lv_obj_t * cpicker, lv_signal_t sign, void * p lv_indev_get_point(lv_indev_get_act(), &ext->last_press_point); res = double_click_reset(cpicker); if(res != LV_RES_OK) return res; - } else if(sign == LV_SIGNAL_PRESSING) { + } + else if(sign == LV_SIGNAL_PRESSING) { lv_indev_t * indev = lv_indev_get_act(); if(indev == NULL) return res; @@ -748,7 +754,7 @@ static lv_res_t lv_cpicker_signal(lv_obj_t * cpicker, lv_signal_t sign, void * p lv_indev_get_point(indev, &p); if((LV_MATH_ABS(p.x - ext->last_press_point.x) > indev->driver.drag_limit / 2) || - (LV_MATH_ABS(p.y - ext->last_press_point.y) > indev->driver.drag_limit / 2)) { + (LV_MATH_ABS(p.y - ext->last_press_point.y) > indev->driver.drag_limit / 2)) { ext->last_change_time = lv_tick_get(); ext->last_press_point.x = p.x; ext->last_press_point.y = p.y; @@ -775,7 +781,8 @@ static lv_res_t lv_cpicker_signal(lv_obj_t * cpicker, lv_signal_t sign, void * p if(angle < 0) angle = 0; if(angle >= 360) angle = 359; - } else if(ext->type == LV_CPICKER_TYPE_DISC) { + } + else if(ext->type == LV_CPICKER_TYPE_DISC) { lv_style_int_t scale_w = lv_obj_get_style_scale_width(cpicker, LV_CPICKER_PART_MAIN); lv_coord_t r_in = w / 2; @@ -812,23 +819,24 @@ static lv_res_t lv_cpicker_signal(lv_obj_t * cpicker, lv_signal_t sign, void * p hsv_cur = ext->hsv; switch(ext->color_mode) { - case LV_CPICKER_COLOR_MODE_HUE: - hsv_cur.h = angle; - break; - case LV_CPICKER_COLOR_MODE_SATURATION: - hsv_cur.s = (angle * 100) / 360; - break; - case LV_CPICKER_COLOR_MODE_VALUE: - hsv_cur.v = (angle * 100) / 360; - break; + case LV_CPICKER_COLOR_MODE_HUE: + hsv_cur.h = angle; + break; + case LV_CPICKER_COLOR_MODE_SATURATION: + hsv_cur.s = (angle * 100) / 360; + break; + case LV_CPICKER_COLOR_MODE_VALUE: + hsv_cur.v = (angle * 100) / 360; + break; } - if (lv_cpicker_set_hsv(cpicker, hsv_cur)) { + if(lv_cpicker_set_hsv(cpicker, hsv_cur)) { res = lv_event_send(cpicker, LV_EVENT_VALUE_CHANGED, NULL); if(res != LV_RES_OK) return res; } - } else if(sign == LV_SIGNAL_HIT_TEST) { - lv_hit_test_info_t *info = param; + } + else if(sign == LV_SIGNAL_HIT_TEST) { + lv_hit_test_info_t * info = param; info->result = lv_cpicker_hit(cpicker, info->point); } @@ -850,14 +858,14 @@ static lv_style_list_t * lv_cpicker_get_style(lv_obj_t * cpicker, uint8_t part) lv_style_list_t * style_dsc_p; switch(part) { - case LV_CPICKER_PART_MAIN : - style_dsc_p = &cpicker->style_list; - break; - case LV_CPICKER_PART_INDIC: - style_dsc_p = &ext->indic.style_list; - break; - default: - style_dsc_p = NULL; + case LV_CPICKER_PART_MAIN : + style_dsc_p = &cpicker->style_list; + break; + case LV_CPICKER_PART_INDIC: + style_dsc_p = &ext->indic.style_list; + break; + default: + style_dsc_p = NULL; } return style_dsc_p; @@ -868,12 +876,12 @@ static bool lv_cpicker_hit(lv_obj_t * cpicker, const lv_point_t * p) bool is_point_on_coords = lv_obj_is_point_on_coords(cpicker, p); if(!is_point_on_coords) return false; - + lv_cpicker_ext_t * ext = (lv_cpicker_ext_t *)lv_obj_get_ext_attr(cpicker); if(ext->type == LV_CPICKER_TYPE_RECT) return true; - + /*Valid clicks can be only in the circle*/ if(lv_area_is_point_on(&cpicker->coords, p, LV_RADIUS_CIRCLE)) return true; else return false; @@ -898,20 +906,21 @@ static void refr_indic_pos(lv_obj_t * cpicker) if(ext->type == LV_CPICKER_TYPE_RECT) { lv_coord_t ind_pos = 0; switch(ext->color_mode) { - case LV_CPICKER_COLOR_MODE_HUE: - ind_pos += (ext->hsv.h * w) / 360; - break; - case LV_CPICKER_COLOR_MODE_SATURATION: - ind_pos += (ext->hsv.s * w) / 100; - break; - case LV_CPICKER_COLOR_MODE_VALUE: - ind_pos += (ext->hsv.v * w) / 100; - break; + case LV_CPICKER_COLOR_MODE_HUE: + ind_pos += (ext->hsv.h * w) / 360; + break; + case LV_CPICKER_COLOR_MODE_SATURATION: + ind_pos += (ext->hsv.s * w) / 100; + break; + case LV_CPICKER_COLOR_MODE_VALUE: + ind_pos += (ext->hsv.v * w) / 100; + break; } ext->indic.pos.x = ind_pos; ext->indic.pos.y = h / 2; - } else if(ext->type == LV_CPICKER_TYPE_DISC) { + } + else if(ext->type == LV_CPICKER_TYPE_DISC) { lv_style_int_t scale_w = lv_obj_get_style_scale_width(cpicker, LV_CPICKER_PART_MAIN); lv_coord_t r = (w - scale_w) / 2; uint16_t angle = get_angle(cpicker); @@ -934,20 +943,20 @@ static lv_res_t double_click_reset(lv_obj_t * cpicker) hsv_cur = ext->hsv; switch(ext->color_mode) { - case LV_CPICKER_COLOR_MODE_HUE: - hsv_cur.h = LV_CPICKER_DEF_HUE; - break; - case LV_CPICKER_COLOR_MODE_SATURATION: - hsv_cur.s = LV_CPICKER_DEF_SATURATION; - break; - case LV_CPICKER_COLOR_MODE_VALUE: - hsv_cur.v = LV_CPICKER_DEF_VALUE; - break; + case LV_CPICKER_COLOR_MODE_HUE: + hsv_cur.h = LV_CPICKER_DEF_HUE; + break; + case LV_CPICKER_COLOR_MODE_SATURATION: + hsv_cur.s = LV_CPICKER_DEF_SATURATION; + break; + case LV_CPICKER_COLOR_MODE_VALUE: + hsv_cur.v = LV_CPICKER_DEF_VALUE; + break; } lv_indev_wait_release(indev); - if (lv_cpicker_set_hsv(cpicker, hsv_cur)) { + if(lv_cpicker_set_hsv(cpicker, hsv_cur)) { lv_res_t res = lv_event_send(cpicker, LV_EVENT_VALUE_CHANGED, NULL); if(res != LV_RES_OK) return res; } @@ -961,18 +970,17 @@ static lv_color_t angle_to_mode_color(lv_obj_t * cpicker, uint16_t angle) { lv_cpicker_ext_t * ext = lv_obj_get_ext_attr(cpicker); lv_color_t color; - switch(ext->color_mode) - { - default: - case LV_CPICKER_COLOR_MODE_HUE: - color = lv_color_hsv_to_rgb(angle % 360, ext->hsv.s, ext->hsv.v); - break; - case LV_CPICKER_COLOR_MODE_SATURATION: - color = lv_color_hsv_to_rgb(ext->hsv.h, ((angle % 360) * 100) / 360, ext->hsv.v); - break; - case LV_CPICKER_COLOR_MODE_VALUE: - color = lv_color_hsv_to_rgb(ext->hsv.h, ext->hsv.s, ((angle % 360) * 100) / 360); - break; + switch(ext->color_mode) { + default: + case LV_CPICKER_COLOR_MODE_HUE: + color = lv_color_hsv_to_rgb(angle % 360, ext->hsv.s, ext->hsv.v); + break; + case LV_CPICKER_COLOR_MODE_SATURATION: + color = lv_color_hsv_to_rgb(ext->hsv.h, ((angle % 360) * 100) / 360, ext->hsv.v); + break; + case LV_CPICKER_COLOR_MODE_VALUE: + color = lv_color_hsv_to_rgb(ext->hsv.h, ext->hsv.s, ((angle % 360) * 100) / 360); + break; } return color; } @@ -981,18 +989,17 @@ static uint16_t get_angle(lv_obj_t * cpicker) { lv_cpicker_ext_t * ext = lv_obj_get_ext_attr(cpicker); uint16_t angle; - switch(ext->color_mode) - { - default: - case LV_CPICKER_COLOR_MODE_HUE: - angle = ext->hsv.h; - break; - case LV_CPICKER_COLOR_MODE_SATURATION: - angle = (ext->hsv.s * 360) / 100; - break; - case LV_CPICKER_COLOR_MODE_VALUE: - angle = (ext->hsv.v * 360) / 100 ; - break; + switch(ext->color_mode) { + default: + case LV_CPICKER_COLOR_MODE_HUE: + angle = ext->hsv.h; + break; + case LV_CPICKER_COLOR_MODE_SATURATION: + angle = (ext->hsv.s * 360) / 100; + break; + case LV_CPICKER_COLOR_MODE_VALUE: + angle = (ext->hsv.v * 360) / 100 ; + break; } return angle; } diff --git a/src/lv_widgets/lv_cpicker.h b/src/lv_widgets/lv_cpicker.h index 942deabec..1fe8d77b9 100644 --- a/src/lv_widgets/lv_cpicker.h +++ b/src/lv_widgets/lv_cpicker.h @@ -48,15 +48,15 @@ typedef struct { struct { lv_style_list_t style_list; lv_point_t pos; - uint8_t colored :1; + uint8_t colored : 1; } indic; uint32_t last_click_time; uint32_t last_change_time; lv_point_t last_press_point; - lv_cpicker_color_mode_t color_mode :2; - uint8_t color_mode_fixed :1; - lv_cpicker_type_t type :1; + lv_cpicker_color_mode_t color_mode : 2; + uint8_t color_mode_fixed : 1; + lv_cpicker_type_t type : 1; } lv_cpicker_ext_t; /*Parts*/ diff --git a/src/lv_widgets/lv_dropdown.c b/src/lv_widgets/lv_dropdown.c index 0f5199d2d..6b0d0f627 100644 --- a/src/lv_widgets/lv_dropdown.c +++ b/src/lv_widgets/lv_dropdown.c @@ -25,8 +25,8 @@ #define LV_OBJX_NAME "lv_dropdown" #if LV_USE_ANIMATION == 0 -#undef LV_DROPDOWN_DEF_ANIM_TIME -#define LV_DROPDOWN_DEF_ANIM_TIME 0 /*No animation*/ + #undef LV_DROPDOWN_DEF_ANIM_TIME + #define LV_DROPDOWN_DEF_ANIM_TIME 0 /*No animation*/ #endif #define LV_DROPDOWN_PR_NONE 0xFFFF @@ -34,11 +34,10 @@ /********************** * TYPEDEFS **********************/ -typedef struct -{ +typedef struct { lv_page_ext_t page; lv_obj_t * ddlist; /*Pointer to the ddlist where the page belongs*/ -}lv_dropdown_page_ext_t; +} lv_dropdown_page_ext_t; /********************** * STATIC PROTOTYPES @@ -57,8 +56,8 @@ static uint16_t get_id_on_point(lv_obj_t * ddlist, lv_coord_t x, lv_coord_t y); static void pos_selected(lv_obj_t * ddlist); static lv_obj_t * get_label(const lv_obj_t * ddlist); #if LV_USE_ANIMATION -static void list_anim(void * p, lv_anim_value_t v); -static void close_anim_ready(lv_anim_t * a); + static void list_anim(void * p, lv_anim_value_t v); + static void close_anim_ready(lv_anim_t * a); #endif /********************** @@ -237,7 +236,8 @@ void lv_dropdown_set_max_height(lv_obj_t * ddlist, lv_coord_t h) if(ext->page) { if(h == 0) { lv_cont_set_fit(ext->page, LV_FIT_TIGHT); - } else { + } + else { lv_cont_set_fit2(ext->page, LV_FIT_TIGHT, LV_FIT_NONE); lv_obj_set_height(ext->page, h); } @@ -539,7 +539,8 @@ void lv_dropdown_close(lv_obj_t * ddlist, lv_anim_enable_t anim) #endif lv_obj_del(ext->page); ext->page = NULL; - } else { + } + else { #if LV_USE_ANIMATION if(ext->dir != LV_DROPDOWN_DIR_UP) { lv_anim_t a; @@ -550,7 +551,8 @@ void lv_dropdown_close(lv_obj_t * ddlist, lv_anim_enable_t anim) lv_anim_set_time(&a, ext->anim_time); lv_anim_set_ready_cb(&a, close_anim_ready); lv_anim_start(&a); - } else { + } + else { lv_anim_del(ddlist, list_anim); lv_obj_del(ext->page); ext->page = NULL; @@ -608,7 +610,8 @@ static lv_design_res_t lv_dropdown_design(lv_obj_t * ddlist, const lv_area_t * c txt = ext->dir != LV_DROPDOWN_DIR_LEFT ? opt_txt : ext->symbol; if(txt) { - lv_txt_get_size(&txt_size, txt, label_dsc.font, label_dsc.letter_space, label_dsc.line_space, LV_COORD_MAX, label_dsc.flag); + lv_txt_get_size(&txt_size, txt, label_dsc.font, label_dsc.letter_space, label_dsc.line_space, LV_COORD_MAX, + label_dsc.flag); txt_area.y1 = ddlist->coords.y1 + top; txt_area.y2 = txt_area.y1 + txt_size.y; @@ -617,7 +620,8 @@ static lv_design_res_t lv_dropdown_design(lv_obj_t * ddlist, const lv_area_t * c if(ext->symbol == NULL && txt == opt_txt) { txt_area.x1 = ddlist->coords.x1 + (lv_obj_get_width(ddlist) - txt_size.x) / 2; txt_area.x2 = txt_area.x1 + txt_size.x; - } else { + } + else { txt_area.x1 = ddlist->coords.x1 + left; txt_area.x2 = txt_area.x1 + txt_size.x; } @@ -626,7 +630,8 @@ static lv_design_res_t lv_dropdown_design(lv_obj_t * ddlist, const lv_area_t * c txt = ext->dir != LV_DROPDOWN_DIR_LEFT ? ext->symbol : opt_txt; if(txt) { - lv_txt_get_size(&txt_size, txt, label_dsc.font, label_dsc.letter_space, label_dsc.line_space, LV_COORD_MAX, label_dsc.flag); + lv_txt_get_size(&txt_size, txt, label_dsc.font, label_dsc.letter_space, label_dsc.line_space, LV_COORD_MAX, + label_dsc.flag); txt_area.y1 = ddlist->coords.y1 + top; txt_area.y2 = txt_area.y1 + txt_size.y; @@ -634,7 +639,8 @@ static lv_design_res_t lv_dropdown_design(lv_obj_t * ddlist, const lv_area_t * c if(ext->symbol == NULL && txt == opt_txt) { txt_area.x1 = ddlist->coords.x1 + (lv_obj_get_width(ddlist) - txt_size.x) / 2; txt_area.x2 = txt_area.x1 + txt_size.x; - } else { + } + else { txt_area.x1 = ddlist->coords.x2 - right - txt_size.x; txt_area.x2 = txt_area.x1 + txt_size.x; } @@ -646,7 +652,8 @@ static lv_design_res_t lv_dropdown_design(lv_obj_t * ddlist, const lv_area_t * c lv_mem_buf_release((char *)opt_txt); } - } else if(mode == LV_DESIGN_DRAW_POST) { + } + else if(mode == LV_DESIGN_DRAW_POST) { ancestor_design(ddlist, clip_area, mode); } @@ -741,9 +748,9 @@ static lv_res_t lv_dropdown_signal(lv_obj_t * ddlist, lv_signal_t sign, void * p lv_dropdown_ext_t * ext = lv_obj_get_ext_attr(ddlist); lv_get_state_info_t * info = param; if(info->part == LV_DROPDOWN_PART_LIST || - info->part == LV_DROPDOWN_PART_SCRLBAR || - info->part == LV_DROPDOWN_PART_SELECTED) { - info->result = lv_obj_get_state(ext->page, LV_PAGE_PART_BG); + info->part == LV_DROPDOWN_PART_SCRLBAR || + info->part == LV_DROPDOWN_PART_SELECTED) { + info->result = lv_obj_get_state(ext->page, LV_PAGE_PART_BG); } } else if(sign == LV_SIGNAL_CLEANUP) { @@ -771,7 +778,8 @@ static lv_res_t lv_dropdown_signal(lv_obj_t * ddlist, lv_signal_t sign, void * p lv_dropdown_close(ddlist, LV_ANIM_ON); } #endif - } else if(sign == LV_SIGNAL_DEFOCUS || sign == LV_SIGNAL_LEAVE) { + } + else if(sign == LV_SIGNAL_DEFOCUS || sign == LV_SIGNAL_LEAVE) { lv_dropdown_close(ddlist, LV_ANIM_ON); } else if(sign == LV_SIGNAL_RELEASED) { @@ -782,7 +790,8 @@ static lv_res_t lv_dropdown_signal(lv_obj_t * ddlist, lv_signal_t sign, void * p ext->sel_opt_id_orig = ext->sel_opt_id; lv_obj_invalidate(ddlist); } - } else { + } + else { lv_dropdown_open(ddlist, LV_ANIM_ON); } } @@ -807,24 +816,28 @@ static lv_res_t lv_dropdown_signal(lv_obj_t * ddlist, lv_signal_t sign, void * p if(c == LV_KEY_RIGHT || c == LV_KEY_DOWN) { if(ext->page == NULL) { lv_dropdown_open(ddlist, LV_ANIM_ON); - } else if(ext->sel_opt_id + 1 < ext->option_cnt) { + } + else if(ext->sel_opt_id + 1 < ext->option_cnt) { ext->sel_opt_id++; pos_selected(ddlist); } - } else if(c == LV_KEY_LEFT || c == LV_KEY_UP) { + } + else if(c == LV_KEY_LEFT || c == LV_KEY_UP) { if(ext->page == NULL) { lv_dropdown_open(ddlist, LV_ANIM_ON); - } else if(ext->sel_opt_id > 0) { + } + else if(ext->sel_opt_id > 0) { ext->sel_opt_id--; pos_selected(ddlist); } - } else if(c == LV_KEY_ESC) { - ext->sel_opt_id = ext->sel_opt_id_orig; - lv_dropdown_close(ddlist, LV_ANIM_ON); + } + else if(c == LV_KEY_ESC) { + ext->sel_opt_id = ext->sel_opt_id_orig; + lv_dropdown_close(ddlist, LV_ANIM_ON); } } -else if(sign == LV_SIGNAL_GET_EDITABLE) { + else if(sign == LV_SIGNAL_GET_EDITABLE) { bool * editable = (bool *)param; *editable = true; } @@ -859,13 +872,16 @@ static lv_res_t lv_dropdown_page_signal(lv_obj_t * page, lv_signal_t sign, void lv_style_int_t right = lv_obj_get_style_pad_right(ddlist, LV_DROPDOWN_PART_LIST); lv_obj_t * scrl = lv_page_get_scrl(page); scrl->ext_draw_pad = LV_MATH_MAX(scrl->ext_draw_pad, LV_MATH_MAX(left, right)); - } else if(sign == LV_SIGNAL_RELEASED) { + } + else if(sign == LV_SIGNAL_RELEASED) { if(lv_indev_is_dragging(lv_indev_get_act()) == false) { page_release_handler(page); } - } else if(sign == LV_SIGNAL_PRESSED) { - page_press_handler(page); - } else if(sign == LV_SIGNAL_CLEANUP) { + } + else if(sign == LV_SIGNAL_PRESSED) { + page_press_handler(page); + } + else if(sign == LV_SIGNAL_CLEANUP) { lv_dropdown_ext_t * ext = lv_obj_get_ext_attr(ddlist); ext->page = NULL; /*The page is just being deleted*/ } @@ -894,24 +910,26 @@ static lv_res_t lv_dropdown_page_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, lv_obj_t * ddlist = page_ext->ddlist; lv_dropdown_ext_t * ext = lv_obj_get_ext_attr(ddlist); - if(sign == LV_SIGNAL_RELEASED) { + if(sign == LV_SIGNAL_RELEASED) { if(lv_indev_is_dragging(lv_indev_get_act()) == false) { page_release_handler(page); } - } else if(sign == LV_SIGNAL_PRESSED) { - page_press_handler(page); - } else if(sign == LV_SIGNAL_DRAG_BEGIN) { - ext->pr_opt_id = LV_DROPDOWN_PR_NONE; - lv_obj_invalidate(page); - } - else if(sign == LV_SIGNAL_REFR_EXT_DRAW_PAD) { - /* Make possible to draw on the full width of the background to redraw the selected rectangle - * when the ddlist is scrolled in fix height mode. - * (The scrollabel is scrolled the "select rectangle" is drawn on the bg too)*/ - lv_style_int_t left = lv_obj_get_style_pad_left(ddlist, LV_DROPDOWN_PART_LIST); - lv_style_int_t right = lv_obj_get_style_pad_right(ddlist, LV_DROPDOWN_PART_LIST); - scrl->ext_draw_pad = LV_MATH_MAX(scrl->ext_draw_pad, LV_MATH_MAX(left, right)); - } + } + else if(sign == LV_SIGNAL_PRESSED) { + page_press_handler(page); + } + else if(sign == LV_SIGNAL_DRAG_BEGIN) { + ext->pr_opt_id = LV_DROPDOWN_PR_NONE; + lv_obj_invalidate(page); + } + else if(sign == LV_SIGNAL_REFR_EXT_DRAW_PAD) { + /* Make possible to draw on the full width of the background to redraw the selected rectangle + * when the ddlist is scrolled in fix height mode. + * (The scrollabel is scrolled the "select rectangle" is drawn on the bg too)*/ + lv_style_int_t left = lv_obj_get_style_pad_left(ddlist, LV_DROPDOWN_PART_LIST); + lv_style_int_t right = lv_obj_get_style_pad_right(ddlist, LV_DROPDOWN_PART_LIST); + scrl->ext_draw_pad = LV_MATH_MAX(scrl->ext_draw_pad, LV_MATH_MAX(left, right)); + } return res; } @@ -931,20 +949,20 @@ static lv_style_list_t * lv_dropdown_get_style(lv_obj_t * ddlist, uint8_t part) lv_style_list_t * style_dsc_p; switch(part) { - case LV_DROPDOWN_PART_BTN: - style_dsc_p = &ddlist->style_list; - break; - case LV_DROPDOWN_PART_LIST: - style_dsc_p = &ext->style_page; - break; - case LV_DROPDOWN_PART_SCRLBAR: - style_dsc_p = &ext->style_scrlbar; - break; - case LV_DROPDOWN_PART_SELECTED: - style_dsc_p = &ext->style_selected; - break; - default: - style_dsc_p = NULL; + case LV_DROPDOWN_PART_BTN: + style_dsc_p = &ddlist->style_list; + break; + case LV_DROPDOWN_PART_LIST: + style_dsc_p = &ext->style_page; + break; + case LV_DROPDOWN_PART_SCRLBAR: + style_dsc_p = &ext->style_scrlbar; + break; + case LV_DROPDOWN_PART_SELECTED: + style_dsc_p = &ext->style_selected; + break; + default: + style_dsc_p = NULL; } return style_dsc_p; @@ -997,7 +1015,8 @@ static void draw_box_label(lv_obj_t * ddlist, const lv_area_t * clip_area, uint1 lv_draw_label_dsc_t label_dsc; lv_draw_label_dsc_init(&label_dsc); lv_obj_init_draw_label_dsc(ddlist, LV_DROPDOWN_PART_SELECTED, &label_dsc); - label_dsc.line_space = lv_obj_get_style_text_line_space(ddlist, LV_DROPDOWN_PART_LIST); /*Line space should come from the page*/ + label_dsc.line_space = lv_obj_get_style_text_line_space(ddlist, + LV_DROPDOWN_PART_LIST); /*Line space should come from the page*/ lv_coord_t font_h = lv_font_get_line_height(label_dsc.font); lv_obj_t * label = get_label(ddlist); diff --git a/src/lv_widgets/lv_dropdown.h b/src/lv_widgets/lv_dropdown.h index 8781e3a88..0495f0070 100644 --- a/src/lv_widgets/lv_dropdown.h +++ b/src/lv_widgets/lv_dropdown.h @@ -48,8 +48,7 @@ enum { typedef uint8_t lv_dropdown_dir_t; /*Data of drop down list*/ -typedef struct -{ +typedef struct { lv_btn_ext_t btn; /*Ext. of ancestor*/ /*New data for this type */ lv_obj_t * page; /*The dropped down list*/ @@ -65,8 +64,8 @@ typedef struct uint16_t sel_opt_id_orig; /*Store the original index on focus*/ uint16_t pr_opt_id; /*Index of the currently pressed option*/ uint16_t anim_time; - lv_dropdown_dir_t dir :2; - uint8_t show_selected :1; + lv_dropdown_dir_t dir : 2; + uint8_t show_selected : 1; } lv_dropdown_ext_t; enum { diff --git a/src/lv_widgets/lv_gauge.c b/src/lv_widgets/lv_gauge.c index 97125d7e0..70c547d6c 100644 --- a/src/lv_widgets/lv_gauge.c +++ b/src/lv_widgets/lv_gauge.c @@ -119,7 +119,7 @@ lv_obj_t * lv_gauge_create(lv_obj_t * par, const lv_obj_t * copy) } ext->label_count = copy_ext->label_count; /*Refresh the style with new signal function*/ -// lv_obj_refresh_style(new_gauge); + // lv_obj_refresh_style(new_gauge); } LV_LOG_INFO("gauge created"); @@ -417,17 +417,17 @@ static lv_style_list_t * lv_gauge_get_style(lv_obj_t * gauge, uint8_t part) lv_style_list_t * style_dsc_p; switch(part) { - case LV_GAUGE_PART_MAIN: - style_dsc_p = &gauge->style_list; - break; - case LV_GAUGE_PART_STRONG: - style_dsc_p = &ext->style_strong; - break; - case LV_GAUGE_PART_NEEDLE: - style_dsc_p = &ext->style_needle; - break; - default: - style_dsc_p = NULL; + case LV_GAUGE_PART_MAIN: + style_dsc_p = &gauge->style_list; + break; + case LV_GAUGE_PART_STRONG: + style_dsc_p = &ext->style_strong; + break; + case LV_GAUGE_PART_NEEDLE: + style_dsc_p = &ext->style_needle; + break; + default: + style_dsc_p = NULL; } return style_dsc_p; diff --git a/src/lv_widgets/lv_gauge.h b/src/lv_widgets/lv_gauge.h index 8dd49eba2..d7c940799 100644 --- a/src/lv_widgets/lv_gauge.h +++ b/src/lv_widgets/lv_gauge.h @@ -36,8 +36,7 @@ extern "C" { **********************/ /*Data of gauge*/ -typedef struct -{ +typedef struct { lv_linemeter_ext_t lmeter; /*Ext. of ancestor*/ /*New data for this type */ int16_t * values; /*Array of the set values (for needles) */ diff --git a/src/lv_widgets/lv_img.c b/src/lv_widgets/lv_img.c index c7b636d33..e38bd376b 100644 --- a/src/lv_widgets/lv_img.c +++ b/src/lv_widgets/lv_img.c @@ -11,7 +11,7 @@ /*Testing of dependencies*/ #if LV_USE_LABEL == 0 -#error "lv_img: lv_label is required. Enable it in lv_conf.h (LV_USE_LABEL 1) " + #error "lv_img: lv_label is required. Enable it in lv_conf.h (LV_USE_LABEL 1) " #endif #include "../lv_core/lv_debug.h" @@ -103,15 +103,17 @@ lv_obj_t * lv_img_create(lv_obj_t * par, const lv_obj_t * copy) * and must be screen sized*/ if(par != NULL) { ext->auto_size = 1; - } else { + } + else { ext->auto_size = 0; } - } else { + } + else { lv_img_ext_t * copy_ext = lv_obj_get_ext_attr(copy); ext->auto_size = copy_ext->auto_size; lv_img_set_src(img, copy_ext->src); -// /*Refresh the style with new signal function*/ + // /*Refresh the style with new signal function*/ lv_obj_refresh_style(img); } @@ -138,10 +140,17 @@ void lv_img_set_src(lv_obj_t * img, const void * src_img) #if LV_USE_LOG && LV_LOG_LEVEL >= LV_LOG_LEVEL_INFO switch(src_type) { - case LV_IMG_SRC_FILE: LV_LOG_TRACE("lv_img_set_src: `LV_IMG_SRC_FILE` type found"); break; - case LV_IMG_SRC_VARIABLE: LV_LOG_TRACE("lv_img_set_src: `LV_IMG_SRC_VARIABLE` type found"); break; - case LV_IMG_SRC_SYMBOL: LV_LOG_TRACE("lv_img_set_src: `LV_IMG_SRC_SYMBOL` type found"); break; - default: LV_LOG_WARN("lv_img_set_src: unknown type"); + case LV_IMG_SRC_FILE: + LV_LOG_TRACE("lv_img_set_src: `LV_IMG_SRC_FILE` type found"); + break; + case LV_IMG_SRC_VARIABLE: + LV_LOG_TRACE("lv_img_set_src: `LV_IMG_SRC_VARIABLE` type found"); + break; + case LV_IMG_SRC_SYMBOL: + LV_LOG_TRACE("lv_img_set_src: `LV_IMG_SRC_SYMBOL` type found"); + break; + default: + LV_LOG_WARN("lv_img_set_src: unknown type"); } #endif @@ -168,7 +177,8 @@ void lv_img_set_src(lv_obj_t * img, const void * src_img) lv_mem_free(ext->src); } ext->src = src_img; - } else if(src_type == LV_IMG_SRC_FILE || src_type == LV_IMG_SRC_SYMBOL) { + } + else if(src_type == LV_IMG_SRC_FILE || src_type == LV_IMG_SRC_SYMBOL) { /* If the new and the old src are the same then it was only a refresh.*/ if(ext->src != src_img) { const void * old_src = NULL; @@ -278,7 +288,7 @@ void lv_img_set_offset_y(lv_obj_t * img, lv_coord_t y) void lv_img_set_pivot(lv_obj_t * img, lv_coord_t pivot_x, lv_coord_t pivot_y) { lv_img_ext_t * ext = lv_obj_get_ext_attr(img); - if (ext->pivot.x == pivot_x && ext->pivot.y == pivot_y) return; + if(ext->pivot.x == pivot_x && ext->pivot.y == pivot_y) return; lv_area_t a; lv_img_buf_get_transformed_area(&a, ext->w, ext->h, ext->angle, ext->zoom, &ext->pivot); @@ -464,7 +474,7 @@ lv_coord_t lv_img_get_offset_y(lv_obj_t * img) * @param img pointer to an image object * @param center rotation center of the image */ -void lv_img_get_pivot(lv_obj_t * img, lv_point_t *pivot) +void lv_img_get_pivot(lv_obj_t * img, lv_point_t * pivot) { LV_ASSERT_OBJ(img, LV_OBJX_NAME); @@ -535,7 +545,8 @@ static lv_design_res_t lv_img_design(lv_obj_t * img, const lv_area_t * clip_area if(mode == LV_DESIGN_COVER_CHK) { lv_design_res_t cover = LV_DESIGN_RES_NOT_COVER; - if(ext->src_type == LV_IMG_SRC_UNKNOWN || ext->src_type == LV_IMG_SRC_SYMBOL || ext->angle != 0) return LV_DESIGN_RES_NOT_COVER; + if(ext->src_type == LV_IMG_SRC_UNKNOWN || ext->src_type == LV_IMG_SRC_SYMBOL || + ext->angle != 0) return LV_DESIGN_RES_NOT_COVER; if(ext->cf == LV_IMG_CF_TRUE_COLOR || ext->cf == LV_IMG_CF_RAW) { cover = lv_area_is_in(clip_area, &img->coords, 0) ? LV_DESIGN_RES_COVER : LV_DESIGN_RES_NOT_COVER; @@ -544,7 +555,8 @@ static lv_design_res_t lv_img_design(lv_obj_t * img, const lv_area_t * clip_area if(lv_obj_get_style_image_opa(img, LV_IMG_PART_MAIN) < LV_OPA_MAX) return false; return cover; - } else if(mode == LV_DESIGN_DRAW_MAIN) { + } + else if(mode == LV_DESIGN_DRAW_MAIN) { if(ext->h == 0 || ext->w == 0) return true; lv_area_t img_coords; @@ -605,7 +617,8 @@ static lv_design_res_t lv_img_design(lv_obj_t * img, const lv_area_t * clip_area lv_draw_img(&cords_tmp, clip_area, ext->src, &img_dsc); } } - } else if(ext->src_type == LV_IMG_SRC_SYMBOL) { + } + else if(ext->src_type == LV_IMG_SRC_SYMBOL) { LV_LOG_TRACE("lv_img_design: start to draw symbol"); lv_draw_label_dsc_t label_dsc; lv_draw_label_dsc_init(&label_dsc); @@ -613,12 +626,14 @@ static lv_design_res_t lv_img_design(lv_obj_t * img, const lv_area_t * clip_area label_dsc.color = lv_obj_get_style_image_recolor(img, LV_IMG_PART_MAIN); lv_draw_label(&img_coords, clip_area, &label_dsc, ext->src, NULL); - } else { + } + else { /*Trigger the error handler of image drawer*/ LV_LOG_WARN("lv_img_design: image source type is unknown"); lv_draw_img(&img->coords, clip_area, NULL, NULL); } - } else if(mode == LV_DESIGN_DRAW_POST) { + } + else if(mode == LV_DESIGN_DRAW_POST) { if(lv_obj_get_style_clip_corner(img, LV_OBJ_PART_MAIN)) { lv_draw_mask_radius_param_t * param = lv_draw_mask_remove_custom(img + 8); lv_mem_buf_release(param); @@ -671,12 +686,14 @@ static lv_res_t lv_img_signal(lv_obj_t * img, lv_signal_t sign, void * param) ext->src = NULL; ext->src_type = LV_IMG_SRC_UNKNOWN; } - } else if(sign == LV_SIGNAL_STYLE_CHG) { + } + else if(sign == LV_SIGNAL_STYLE_CHG) { /*Refresh the file name to refresh the symbol text size*/ if(ext->src_type == LV_IMG_SRC_SYMBOL) { lv_img_set_src(img, ext->src); } - } else if(sign == LV_SIGNAL_REFR_EXT_DRAW_PAD) { + } + else if(sign == LV_SIGNAL_REFR_EXT_DRAW_PAD) { /*If the image has angle provide enough room for the rotated corners */ if(ext->angle || ext->zoom != LV_IMG_ZOOM_NONE) { lv_area_t a; @@ -699,8 +716,9 @@ static lv_res_t lv_img_signal(lv_obj_t * img, lv_signal_t sign, void * param) img->ext_draw_pad = LV_MATH_MAX(img->ext_draw_pad, bottom); - } else if(sign == LV_SIGNAL_HIT_TEST) { - lv_hit_test_info_t *info = param; + } + else if(sign == LV_SIGNAL_HIT_TEST) { + lv_hit_test_info_t * info = param; if(ext->zoom != 256 && ext->angle == 0) { lv_coord_t origin_width = lv_area_get_width(&img->coords); lv_coord_t origin_height = lv_area_get_height(&img->coords); @@ -717,7 +735,8 @@ static lv_res_t lv_img_signal(lv_obj_t * img, lv_signal_t sign, void * param) coords.y1 += height_offset; coords.y2 -= height_offset; info->result = lv_area_is_point_on(&coords, info->point, 0); - } else + } + else info->result = lv_obj_is_point_on_coords(img, info->point); } @@ -729,11 +748,11 @@ static lv_style_list_t * lv_img_get_style(lv_obj_t * img, uint8_t type) { lv_style_list_t * style_dsc_p; switch(type) { - case LV_IMG_PART_MAIN: - style_dsc_p = &img->style_list; - break; - default: - style_dsc_p = NULL; + case LV_IMG_PART_MAIN: + style_dsc_p = &img->style_list; + break; + default: + style_dsc_p = NULL; } return style_dsc_p; diff --git a/src/lv_widgets/lv_img.h b/src/lv_widgets/lv_img.h index 9a1071c4f..a5c29a6ae 100644 --- a/src/lv_widgets/lv_img.h +++ b/src/lv_widgets/lv_img.h @@ -30,21 +30,20 @@ extern "C" { * TYPEDEFS **********************/ /*Data of image*/ -typedef struct -{ +typedef struct { /*No inherited ext. because inherited from the base object*/ /*Ext. of ancestor*/ /*New data for this type */ const void * src; /*Image source: Pointer to an array or a file or a symbol*/ lv_point_t offset; lv_coord_t w; /*Width of the image (Handled by the library)*/ lv_coord_t h; /*Height of the image (Handled by the library)*/ - uint16_t angle; /*rotation angle of the image*/ + uint16_t angle; /*rotation angle of the image*/ lv_point_t pivot; /*rotation center of the image*/ uint16_t zoom; /*256 means no zoom, 512 double size, 128 hasl size*/ uint8_t src_type : 2; /*See: lv_img_src_t*/ uint8_t auto_size : 1; /*1: automatically set the object size to the image size*/ uint8_t cf : 5; /*Color format from `lv_img_color_format_t`*/ - uint8_t antialias :1; /*Apply anti-aliasing in transformations (rotate, zoom)*/ + uint8_t antialias : 1; /*Apply anti-aliasing in transformations (rotate, zoom)*/ } lv_img_ext_t; /*Image parts*/ @@ -187,7 +186,7 @@ uint16_t lv_img_get_angle(lv_obj_t * img); * @param img pointer to an image object * @param center rotation center of the image */ -void lv_img_get_pivot(lv_obj_t * img, lv_point_t *center); +void lv_img_get_pivot(lv_obj_t * img, lv_point_t * center); /** * Get the zoom factor of the image. diff --git a/src/lv_widgets/lv_imgbtn.c b/src/lv_widgets/lv_imgbtn.c index 25695f26b..d979e9825 100644 --- a/src/lv_widgets/lv_imgbtn.c +++ b/src/lv_widgets/lv_imgbtn.c @@ -72,9 +72,9 @@ lv_obj_t * lv_imgbtn_create(lv_obj_t * par, const lv_obj_t * copy) if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_cb(imgbtn); if(ancestor_design == NULL) ancestor_design = lv_obj_get_design_cb(imgbtn); - /*Initialize the allocated 'ext' */ + /*Initialize the allocated 'ext' */ #if LV_IMGBTN_TILED == 0 - memset((void*)ext->img_src, 0, sizeof(ext->img_src)); + memset((void *)ext->img_src, 0, sizeof(ext->img_src)); #else memset(ext->img_src_left, 0, sizeof(ext->img_src_left)); memset(ext->img_src_mid, 0, sizeof(ext->img_src_mid)); @@ -95,11 +95,11 @@ lv_obj_t * lv_imgbtn_create(lv_obj_t * par, const lv_obj_t * copy) else { lv_imgbtn_ext_t * copy_ext = lv_obj_get_ext_attr(copy); #if LV_IMGBTN_TILED == 0 - memcpy((void*)ext->img_src, copy_ext->img_src, sizeof(ext->img_src)); + memcpy((void *)ext->img_src, copy_ext->img_src, sizeof(ext->img_src)); #else - memcpy((void*)ext->img_src_left, copy_ext->img_src_left, sizeof(ext->img_src_left)); - memcpy((void*)ext->img_src_mid, copy_ext->img_src_mid, sizeof(ext->img_src_mid)); - memcpy((void*)ext->img_src_right, copy_ext->img_src_right, sizeof(ext->img_src_right)); + memcpy((void *)ext->img_src_left, copy_ext->img_src_left, sizeof(ext->img_src_left)); + memcpy((void *)ext->img_src_mid, copy_ext->img_src_mid, sizeof(ext->img_src_mid)); + memcpy((void *)ext->img_src_right, copy_ext->img_src_right, sizeof(ext->img_src_right)); #endif /*Refresh the style with new signal function*/ lv_obj_refresh_style(imgbtn); @@ -151,9 +151,8 @@ void lv_imgbtn_set_src(lv_obj_t * imgbtn, lv_btn_state_t state, const void * src if(lv_img_src_get_type(src_left) == LV_IMG_SRC_SYMBOL || - lv_img_src_get_type(src_mid) == LV_IMG_SRC_SYMBOL || - lv_img_src_get_type(src_right) == LV_IMG_SRC_SYMBOL ) - { + lv_img_src_get_type(src_mid) == LV_IMG_SRC_SYMBOL || + lv_img_src_get_type(src_right) == LV_IMG_SRC_SYMBOL) { LV_LOG_WARN("lv_imgbtn_set_src: symbols are not supported in tiled mode"); return; } @@ -283,7 +282,8 @@ static lv_design_res_t lv_imgbtn_design(lv_obj_t * imgbtn, const lv_area_t * cli lv_draw_label_dsc_init(&label_dsc); lv_obj_init_draw_label_dsc(imgbtn, LV_IMGBTN_PART_MAIN, &label_dsc); lv_draw_label(&imgbtn->coords, clip_area, &label_dsc, src, NULL); - } else { + } + else { lv_draw_img_dsc_t img_dsc; lv_draw_img_dsc_init(&img_dsc); lv_obj_init_draw_img_dsc(imgbtn, LV_IMGBTN_PART_MAIN, &img_dsc); @@ -328,31 +328,31 @@ static lv_design_res_t lv_imgbtn_design(lv_obj_t * imgbtn, const lv_area_t * cli src = ext->img_src_mid[state]; if(src) { - lv_area_t clip_center_area; - clip_center_area.x1 = imgbtn->coords.x1 + left_w; - clip_center_area.x2 = imgbtn->coords.x2 - right_w; - clip_center_area.y1 = imgbtn->coords.y1; - clip_center_area.y2 = imgbtn->coords.y2; + lv_area_t clip_center_area; + clip_center_area.x1 = imgbtn->coords.x1 + left_w; + clip_center_area.x2 = imgbtn->coords.x2 - right_w; + clip_center_area.y1 = imgbtn->coords.y1; + clip_center_area.y2 = imgbtn->coords.y2; - bool comm_res; - comm_res = lv_area_intersect(&clip_center_area, &clip_center_area, clip_area); - if(comm_res) { + bool comm_res; + comm_res = lv_area_intersect(&clip_center_area, &clip_center_area, clip_area); + if(comm_res) { - lv_coord_t obj_w = lv_obj_get_width(imgbtn); - lv_coord_t i; - lv_img_decoder_get_info(src, &header); + lv_coord_t obj_w = lv_obj_get_width(imgbtn); + lv_coord_t i; + lv_img_decoder_get_info(src, &header); - coords.x1 = imgbtn->coords.x1 + left_w; - coords.y1 = imgbtn->coords.y1; - coords.x2 = coords.x1 + header.w - 1; - coords.y2 = imgbtn->coords.y1 + header.h - 1; + coords.x1 = imgbtn->coords.x1 + left_w; + coords.y1 = imgbtn->coords.y1; + coords.x2 = coords.x1 + header.w - 1; + coords.y2 = imgbtn->coords.y1 + header.h - 1; - for(i = 0; i < obj_w - right_w - left_w; i += header.w) { - lv_draw_img(&coords, clip_area, src, &img_dsc); - coords.x1 = coords.x2 + 1; - coords.x2 += header.w; - } - } + for(i = 0; i < obj_w - right_w - left_w; i += header.w) { + lv_draw_img(&coords, clip_area, src, &img_dsc); + coords.x1 = coords.x2 + 1; + coords.x2 += header.w; + } + } } #endif @@ -385,7 +385,8 @@ static lv_res_t lv_imgbtn_signal(lv_obj_t * imgbtn, lv_signal_t sign, void * par /* If the style changed then the button was clicked, released etc. so probably the state was * changed as well Set the new image for the new state.*/ refr_img(imgbtn); - } else if(sign == LV_SIGNAL_CLEANUP) { + } + else if(sign == LV_SIGNAL_CLEANUP) { /*Nothing to cleanup. (No dynamically allocated memory in 'ext')*/ } @@ -411,7 +412,8 @@ static void refr_img(lv_obj_t * imgbtn) header.w = lv_txt_get_width(src, (uint16_t)strlen(src), font, 0, LV_TXT_FLAG_NONE); header.always_zero = 0; header.cf = LV_IMG_CF_ALPHA_1BIT; - } else { + } + else { info_res = lv_img_decoder_get_info(src, &header); } @@ -422,7 +424,8 @@ static void refr_img(lv_obj_t * imgbtn) #else lv_obj_set_height(imgbtn, header.h); #endif - } else { + } + else { ext->act_cf = LV_IMG_CF_UNKNOWN; } diff --git a/src/lv_widgets/lv_imgbtn.h b/src/lv_widgets/lv_imgbtn.h index 87ac781dd..150bd2a15 100644 --- a/src/lv_widgets/lv_imgbtn.h +++ b/src/lv_widgets/lv_imgbtn.h @@ -34,8 +34,7 @@ extern "C" { * TYPEDEFS **********************/ /*Data of image button*/ -typedef struct -{ +typedef struct { lv_btn_ext_t btn; /*Ext. of ancestor*/ /*New data for this type */ #if LV_IMGBTN_TILED == 0 diff --git a/src/lv_widgets/lv_keyboard.c b/src/lv_widgets/lv_keyboard.c index 11e73ea04..ad5d1a683 100644 --- a/src/lv_widgets/lv_keyboard.c +++ b/src/lv_widgets/lv_keyboard.c @@ -37,59 +37,67 @@ static void lv_keyboard_update_map(lv_obj_t * kb); static lv_signal_cb_t ancestor_signal; /* clang-format off */ static const char * const default_kb_map_lc[] = {"1#", "q", "w", "e", "r", "t", "y", "u", "i", "o", "p", LV_SYMBOL_BACKSPACE, "\n", - "ABC", "a", "s", "d", "f", "g", "h", "j", "k", "l", LV_SYMBOL_NEW_LINE, "\n", - "_", "-", "z", "x", "c", "v", "b", "n", "m", ".", ",", ":", "\n", - LV_SYMBOL_CLOSE, LV_SYMBOL_LEFT, " ", LV_SYMBOL_RIGHT, LV_SYMBOL_OK, ""}; + "ABC", "a", "s", "d", "f", "g", "h", "j", "k", "l", LV_SYMBOL_NEW_LINE, "\n", + "_", "-", "z", "x", "c", "v", "b", "n", "m", ".", ",", ":", "\n", + LV_SYMBOL_CLOSE, LV_SYMBOL_LEFT, " ", LV_SYMBOL_RIGHT, LV_SYMBOL_OK, "" + }; static const lv_btnmatrix_ctrl_t default_kb_ctrl_lc_map[] = { LV_KEYBOARD_CTRL_BTN_FLAGS | 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 7, LV_KEYBOARD_CTRL_BTN_FLAGS | 6, 3, 3, 3, 3, 3, 3, 3, 3, 3, 7, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - LV_KEYBOARD_CTRL_BTN_FLAGS | 2, 2, 6, 2, LV_KEYBOARD_CTRL_BTN_FLAGS | 2}; + LV_KEYBOARD_CTRL_BTN_FLAGS | 2, 2, 6, 2, LV_KEYBOARD_CTRL_BTN_FLAGS | 2 +}; static const char * const default_kb_map_uc[] = {"1#", "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", LV_SYMBOL_BACKSPACE, "\n", - "abc", "A", "S", "D", "F", "G", "H", "J", "K", "L", LV_SYMBOL_NEW_LINE, "\n", - "_", "-", "Z", "X", "C", "V", "B", "N", "M", ".", ",", ":", "\n", - LV_SYMBOL_CLOSE, LV_SYMBOL_LEFT, " ", LV_SYMBOL_RIGHT, LV_SYMBOL_OK, ""}; + "abc", "A", "S", "D", "F", "G", "H", "J", "K", "L", LV_SYMBOL_NEW_LINE, "\n", + "_", "-", "Z", "X", "C", "V", "B", "N", "M", ".", ",", ":", "\n", + LV_SYMBOL_CLOSE, LV_SYMBOL_LEFT, " ", LV_SYMBOL_RIGHT, LV_SYMBOL_OK, "" + }; static const lv_btnmatrix_ctrl_t default_kb_ctrl_uc_map[] = { LV_KEYBOARD_CTRL_BTN_FLAGS | 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 7, LV_KEYBOARD_CTRL_BTN_FLAGS | 6, 3, 3, 3, 3, 3, 3, 3, 3, 3, 7, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - LV_KEYBOARD_CTRL_BTN_FLAGS | 2, 2, 6, 2, LV_KEYBOARD_CTRL_BTN_FLAGS | 2}; + LV_KEYBOARD_CTRL_BTN_FLAGS | 2, 2, 6, 2, LV_KEYBOARD_CTRL_BTN_FLAGS | 2 +}; -static const char * const default_kb_map_spec[] = {"0", "1", "2", "3", "4" ,"5", "6", "7", "8", "9", LV_SYMBOL_BACKSPACE, "\n", - "abc", "+", "-", "/", "*", "=", "%", "!", "?", "#", "<", ">", "\n", - "\\", "@", "$", "(", ")", "{", "}", "[", "]", ";", "\"", "'", "\n", - LV_SYMBOL_CLOSE, LV_SYMBOL_LEFT, " ", LV_SYMBOL_RIGHT, LV_SYMBOL_OK, ""}; +static const char * const default_kb_map_spec[] = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", LV_SYMBOL_BACKSPACE, "\n", + "abc", "+", "-", "/", "*", "=", "%", "!", "?", "#", "<", ">", "\n", + "\\", "@", "$", "(", ")", "{", "}", "[", "]", ";", "\"", "'", "\n", + LV_SYMBOL_CLOSE, LV_SYMBOL_LEFT, " ", LV_SYMBOL_RIGHT, LV_SYMBOL_OK, "" + }; static const lv_btnmatrix_ctrl_t default_kb_ctrl_spec_map[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, LV_KEYBOARD_CTRL_BTN_FLAGS | 2, LV_KEYBOARD_CTRL_BTN_FLAGS | 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - LV_KEYBOARD_CTRL_BTN_FLAGS | 2, 2, 6, 2, LV_KEYBOARD_CTRL_BTN_FLAGS | 2}; + LV_KEYBOARD_CTRL_BTN_FLAGS | 2, 2, 6, 2, LV_KEYBOARD_CTRL_BTN_FLAGS | 2 +}; static const char * const default_kb_map_num[] = {"1", "2", "3", LV_SYMBOL_CLOSE, "\n", - "4", "5", "6", LV_SYMBOL_OK, "\n", - "7", "8", "9", LV_SYMBOL_BACKSPACE, "\n", - "+/-", "0", ".", LV_SYMBOL_LEFT, LV_SYMBOL_RIGHT, ""}; + "4", "5", "6", LV_SYMBOL_OK, "\n", + "7", "8", "9", LV_SYMBOL_BACKSPACE, "\n", + "+/-", "0", ".", LV_SYMBOL_LEFT, LV_SYMBOL_RIGHT, "" + }; static const lv_btnmatrix_ctrl_t default_kb_ctrl_num_map[] = { - 1, 1, 1, LV_KEYBOARD_CTRL_BTN_FLAGS | 2, - 1, 1, 1, LV_KEYBOARD_CTRL_BTN_FLAGS | 2, - 1, 1, 1, 2, - 1, 1, 1, 1, 1}; + 1, 1, 1, LV_KEYBOARD_CTRL_BTN_FLAGS | 2, + 1, 1, 1, LV_KEYBOARD_CTRL_BTN_FLAGS | 2, + 1, 1, 1, 2, + 1, 1, 1, 1, 1 +}; /* clang-format on */ -static const char * * kb_map[4] = { - (const char * *)default_kb_map_lc, - (const char * *)default_kb_map_uc, +static const char * * kb_map[4] = { + (const char * *)default_kb_map_lc, + (const char * *)default_kb_map_uc, (const char * *)default_kb_map_spec, (const char * *)default_kb_map_num }; -static const lv_btnmatrix_ctrl_t * kb_ctrl[4] = { - default_kb_ctrl_lc_map, - default_kb_ctrl_uc_map, +static const lv_btnmatrix_ctrl_t * kb_ctrl[4] = { + default_kb_ctrl_lc_map, + default_kb_ctrl_uc_map, default_kb_ctrl_spec_map, default_kb_ctrl_num_map }; @@ -142,7 +150,7 @@ lv_obj_t * lv_keyboard_create(lv_obj_t * par, const lv_obj_t * copy) * Don't use `par` directly because if the window is created on a page it is moved to the * scrollable so the parent has changed */ lv_obj_set_size(kb, lv_obj_get_width_fit(lv_obj_get_parent(kb)), - lv_obj_get_height_fit(lv_obj_get_parent(kb)) / 2); + lv_obj_get_height_fit(lv_obj_get_parent(kb)) / 2); lv_obj_align(kb, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, 0); lv_obj_set_event_cb(kb, lv_keyboard_def_event_cb); lv_obj_set_base_dir(kb, LV_BIDI_DIR_LTR); @@ -164,7 +172,7 @@ lv_obj_t * lv_keyboard_create(lv_obj_t * par, const lv_obj_t * copy) lv_btnmatrix_set_ctrl_map(kb, kb_ctrl[ext->mode]); /*Refresh the style with new signal function*/ -// lv_obj_refresh_style(new_kb); + // lv_obj_refresh_style(new_kb); } LV_LOG_INFO("keyboard created"); @@ -236,7 +244,8 @@ void lv_keyboard_set_cursor_manage(lv_obj_t * kb, bool en) if(ext->cursor_mng) { lv_textarea_set_cursor_hidden(ext->ta, false); - } else { + } + else { lv_textarea_set_cursor_hidden(ext->ta, true); } } @@ -341,35 +350,41 @@ void lv_keyboard_def_event_cb(lv_obj_t * kb, lv_event_t event) /*Do the corresponding action according to the text of the button*/ if(strcmp(txt, "abc") == 0) { - ext->mode = LV_KEYBOARD_MODE_TEXT_LOWER; - lv_btnmatrix_set_map(kb, kb_map[LV_KEYBOARD_MODE_TEXT_LOWER]); - lv_btnmatrix_set_ctrl_map(kb, kb_ctrl[LV_KEYBOARD_MODE_TEXT_LOWER]); + ext->mode = LV_KEYBOARD_MODE_TEXT_LOWER; + lv_btnmatrix_set_map(kb, kb_map[LV_KEYBOARD_MODE_TEXT_LOWER]); + lv_btnmatrix_set_ctrl_map(kb, kb_ctrl[LV_KEYBOARD_MODE_TEXT_LOWER]); return; - } else if(strcmp(txt, "ABC") == 0) { - ext->mode = LV_KEYBOARD_MODE_TEXT_UPPER; - lv_btnmatrix_set_map(kb, kb_map[LV_KEYBOARD_MODE_TEXT_UPPER]); - lv_btnmatrix_set_ctrl_map(kb, kb_ctrl[LV_KEYBOARD_MODE_TEXT_UPPER]); + } + else if(strcmp(txt, "ABC") == 0) { + ext->mode = LV_KEYBOARD_MODE_TEXT_UPPER; + lv_btnmatrix_set_map(kb, kb_map[LV_KEYBOARD_MODE_TEXT_UPPER]); + lv_btnmatrix_set_ctrl_map(kb, kb_ctrl[LV_KEYBOARD_MODE_TEXT_UPPER]); return; - } else if(strcmp(txt, "1#") == 0) { - ext->mode = LV_KEYBOARD_MODE_SPECIAL; - lv_btnmatrix_set_map(kb, kb_map[LV_KEYBOARD_MODE_SPECIAL]); - lv_btnmatrix_set_ctrl_map(kb, kb_ctrl[LV_KEYBOARD_MODE_SPECIAL]); + } + else if(strcmp(txt, "1#") == 0) { + ext->mode = LV_KEYBOARD_MODE_SPECIAL; + lv_btnmatrix_set_map(kb, kb_map[LV_KEYBOARD_MODE_SPECIAL]); + lv_btnmatrix_set_ctrl_map(kb, kb_ctrl[LV_KEYBOARD_MODE_SPECIAL]); return; - } else if(strcmp(txt, LV_SYMBOL_CLOSE) == 0) { + } + else if(strcmp(txt, LV_SYMBOL_CLOSE) == 0) { if(kb->event_cb != lv_keyboard_def_event_cb) { lv_res_t res = lv_event_send(kb, LV_EVENT_CANCEL, NULL); if(res != LV_RES_OK) return; - } else { + } + else { lv_keyboard_set_ta(kb, NULL); /*De-assign the text area to hide it cursor if needed*/ lv_obj_del(kb); return; } return; - } else if(strcmp(txt, LV_SYMBOL_OK) == 0) { + } + else if(strcmp(txt, LV_SYMBOL_OK) == 0) { if(kb->event_cb != lv_keyboard_def_event_cb) { lv_res_t res = lv_event_send(kb, LV_EVENT_APPLY, NULL); if(res != LV_RES_OK) return; - } else { + } + else { lv_keyboard_set_ta(kb, NULL); /*De-assign the text area to hide it cursor if needed*/ } return; @@ -394,17 +409,20 @@ void lv_keyboard_def_event_cb(lv_obj_t * kb, lv_event_t event) lv_textarea_del_char(ext->ta); lv_textarea_add_char(ext->ta, '+'); lv_textarea_set_cursor_pos(ext->ta, cur); - } else if(ta_txt[0] == '+') { + } + else if(ta_txt[0] == '+') { lv_textarea_set_cursor_pos(ext->ta, 1); lv_textarea_del_char(ext->ta); lv_textarea_add_char(ext->ta, '-'); lv_textarea_set_cursor_pos(ext->ta, cur); - } else { + } + else { lv_textarea_set_cursor_pos(ext->ta, 0); lv_textarea_add_char(ext->ta, '-'); lv_textarea_set_cursor_pos(ext->ta, cur + 1); } - } else { + } + else { lv_textarea_add_text(ext->ta, txt); } } @@ -431,13 +449,15 @@ static lv_res_t lv_keyboard_signal(lv_obj_t * kb, lv_signal_t sign, void * param if(sign == LV_SIGNAL_CLEANUP) { /*Nothing to cleanup. (No dynamically allocated memory in 'ext')*/ - } else if(sign == LV_SIGNAL_FOCUS) { + } + else if(sign == LV_SIGNAL_FOCUS) { lv_keyboard_ext_t * ext = lv_obj_get_ext_attr(kb); /*Show the cursor of the Text area if cursor management is enabled*/ if(ext->ta && ext->cursor_mng) { lv_textarea_set_cursor_hidden(ext->ta, false); } - } else if(sign == LV_SIGNAL_DEFOCUS) { + } + else if(sign == LV_SIGNAL_DEFOCUS) { lv_keyboard_ext_t * ext = lv_obj_get_ext_attr(kb); /*Show the cursor of the Text area if cursor management is enabled*/ if(ext->ta && ext->cursor_mng) { @@ -454,9 +474,9 @@ static lv_res_t lv_keyboard_signal(lv_obj_t * kb, lv_signal_t sign, void * param */ static void lv_keyboard_update_map(lv_obj_t * kb) { - lv_keyboard_ext_t * ext = lv_obj_get_ext_attr(kb); - lv_btnmatrix_set_map(kb, kb_map[ext->mode]); - lv_btnmatrix_set_ctrl_map(kb, kb_ctrl[ext->mode]); + lv_keyboard_ext_t * ext = lv_obj_get_ext_attr(kb); + lv_btnmatrix_set_map(kb, kb_map[ext->mode]); + lv_btnmatrix_set_ctrl_map(kb, kb_ctrl[ext->mode]); } #endif diff --git a/src/lv_widgets/lv_keyboard.h b/src/lv_widgets/lv_keyboard.h index 789c46ad6..7e18ae03c 100644 --- a/src/lv_widgets/lv_keyboard.h +++ b/src/lv_widgets/lv_keyboard.h @@ -45,10 +45,9 @@ enum { LV_KEYBOARD_MODE_NUM, }; typedef uint8_t lv_keyboard_mode_t; - + /*Data of keyboard*/ -typedef struct -{ +typedef struct { lv_btnmatrix_ext_t btnm; /*Ext. of ancestor*/ /*New data for this type */ lv_obj_t * ta; /*Pointer to the assigned text area*/ diff --git a/src/lv_widgets/lv_label.c b/src/lv_widgets/lv_label.c index 2c86831c9..98ae3c6da 100644 --- a/src/lv_widgets/lv_label.c +++ b/src/lv_widgets/lv_label.c @@ -26,7 +26,7 @@ /*Test configurations*/ #ifndef LV_LABEL_DEF_SCROLL_SPEED -#define LV_LABEL_DEF_SCROLL_SPEED (25) + #define LV_LABEL_DEF_SCROLL_SPEED (25) #endif #define LV_LABEL_DOT_END_INV 0xFFFF @@ -46,8 +46,8 @@ static void lv_label_refr_text(lv_obj_t * label); static void lv_label_revert_dots(lv_obj_t * label); #if LV_USE_ANIMATION -static void lv_label_set_offset_x(lv_obj_t * label, lv_coord_t x); -static void lv_label_set_offset_y(lv_obj_t * label, lv_coord_t y); + static void lv_label_set_offset_x(lv_obj_t * label, lv_coord_t x); + static void lv_label_set_offset_y(lv_obj_t * label, lv_coord_t y); #endif static bool lv_label_set_dot_tmp(lv_obj_t * label, char * data, uint16_t len); @@ -151,9 +151,10 @@ lv_obj_t * lv_label_create(lv_obj_t * par, const lv_obj_t * copy) } if(copy_ext->dot_tmp_alloc && copy_ext->dot.tmp_ptr) { - uint16_t len = (uint16_t )strlen(copy_ext->dot.tmp_ptr); + uint16_t len = (uint16_t)strlen(copy_ext->dot.tmp_ptr); lv_label_set_dot_tmp(new_label, ext->dot.tmp_ptr, len); - } else { + } + else { memcpy(ext->dot.tmp, copy_ext->dot.tmp, sizeof(ext->dot.tmp)); } ext->dot_tmp_alloc = copy_ext->dot_tmp_alloc; @@ -199,7 +200,8 @@ void lv_label_set_text(lv_obj_t * label, const char * text) LV_ASSERT_MEM(ext->text); if(ext->text == NULL) return; - } else { + } + else { /*Allocate space for the new text*/ size_t len = strlen(text) + 1; if(ext->text != NULL && ext->static_txt == 0) { @@ -242,8 +244,8 @@ void lv_label_set_text_fmt(lv_obj_t * label, const char * fmt, ...) } if(ext->text != NULL && ext->static_txt == 0) { - lv_mem_free(ext->text); - ext->text = NULL; + lv_mem_free(ext->text); + ext->text = NULL; } va_list ap, ap2; @@ -255,15 +257,15 @@ void lv_label_set_text_fmt(lv_obj_t * label, const char * fmt, ...) va_end(ap); - ext->text = lv_mem_alloc(len+1); + ext->text = lv_mem_alloc(len + 1); LV_ASSERT_MEM(ext->text); if(ext->text == NULL) { va_end(ap2); return; } - ext->text[len-1] = 0; /* Ensure NULL termination */ + ext->text[len - 1] = 0; /* Ensure NULL termination */ - lv_vsnprintf(ext->text, len+1, fmt, ap2); + lv_vsnprintf(ext->text, len + 1, fmt, ap2); va_end(ap2); ext->static_txt = 0; /*Now the text is dynamically allocated*/ @@ -507,7 +509,7 @@ lv_label_align_t lv_label_get_align(const lv_obj_t * label) if(base_dir == LV_BIDI_DIR_AUTO) base_dir = lv_bidi_detect_base_dir(ext->text); if(base_dir == LV_BIDI_DIR_LTR) align = LV_LABEL_ALIGN_LEFT; - else if (base_dir == LV_BIDI_DIR_RTL) align = LV_LABEL_ALIGN_RIGHT; + else if(base_dir == LV_BIDI_DIR_RTL) align = LV_LABEL_ALIGN_RIGHT; #else align = LV_LABEL_ALIGN_LEFT; #endif @@ -606,10 +608,10 @@ void lv_label_get_letter_pos(const lv_obj_t * label, uint16_t char_id, lv_point_ } } - const char *bidi_txt; + const char * bidi_txt; uint16_t visual_byte_pos; #if LV_USE_BIDI - char *mutable_bidi_txt = NULL; + char * mutable_bidi_txt = NULL; /*Handle Bidi*/ if(new_line_start == byte_id) { visual_byte_pos = byte_id - line_start; @@ -619,9 +621,10 @@ void lv_label_get_letter_pos(const lv_obj_t * label, uint16_t char_id, lv_point_ uint16_t line_char_id = lv_txt_encoded_get_char_id(&txt[line_start], byte_id - line_start); bool is_rtl; - uint16_t visual_char_pos = lv_bidi_get_visual_pos(&txt[line_start], &mutable_bidi_txt, new_line_start - line_start, lv_obj_get_base_dir(label), line_char_id, &is_rtl); + uint16_t visual_char_pos = lv_bidi_get_visual_pos(&txt[line_start], &mutable_bidi_txt, new_line_start - line_start, + lv_obj_get_base_dir(label), line_char_id, &is_rtl); bidi_txt = mutable_bidi_txt; - if (is_rtl) visual_char_pos++; + if(is_rtl) visual_char_pos++; visual_byte_pos = lv_txt_encoded_get_byte_id(bidi_txt, visual_char_pos); } @@ -640,7 +643,8 @@ void lv_label_get_letter_pos(const lv_obj_t * label, uint16_t char_id, lv_point_ line_w = lv_txt_get_width(bidi_txt, new_line_start - line_start, font, letter_space, flag); x += lv_area_get_width(&txt_coords) / 2 - line_w / 2; - } else if(align == LV_LABEL_ALIGN_RIGHT) { + } + else if(align == LV_LABEL_ALIGN_RIGHT) { lv_coord_t line_w; line_w = lv_txt_get_width(bidi_txt, new_line_start - line_start, font, letter_space, flag); @@ -680,7 +684,7 @@ uint16_t lv_label_get_letter_on(const lv_obj_t * label, lv_point_t * pos) lv_coord_t y = 0; lv_txt_flag_t flag = LV_TXT_FLAG_NONE; uint16_t logical_pos; - char *bidi_txt; + char * bidi_txt; if(ext->recolor != 0) flag |= LV_TXT_FLAG_RECOLOR; if(ext->expand != 0) flag |= LV_TXT_FLAG_EXPAND; @@ -704,7 +708,7 @@ uint16_t lv_label_get_letter_on(const lv_obj_t * label, lv_point_t * pos) uint32_t tmp = new_line_start; uint32_t letter; letter = lv_txt_encoded_prev(txt, &tmp); - if(letter != '\n' && txt[new_line_start] == '\0' ) new_line_start++; + if(letter != '\n' && txt[new_line_start] == '\0') new_line_start++; break; } y += letter_height + line_space; @@ -718,7 +722,7 @@ uint16_t lv_label_get_letter_on(const lv_obj_t * label, lv_point_t * pos) if(new_line_start > 0 && txt[new_line_start - 1] == '\0' && txt_len > 0) txt_len--; lv_bidi_process_paragraph(txt + line_start, bidi_txt, txt_len, lv_obj_get_base_dir(label), NULL, 0); #else - bidi_txt = (char*)txt + line_start; + bidi_txt = (char *)txt + line_start; #endif /*Calculate the x coordinate*/ @@ -769,8 +773,9 @@ uint16_t lv_label_get_letter_on(const lv_obj_t * label, lv_point_t * pos) #if LV_USE_BIDI /*Handle Bidi*/ bool is_rtl; - logical_pos = lv_bidi_get_logical_pos(&txt[line_start], NULL, txt_len, lv_obj_get_base_dir(label), lv_txt_encoded_get_char_id(bidi_txt, i), &is_rtl); - if (is_rtl) logical_pos++; + logical_pos = lv_bidi_get_logical_pos(&txt[line_start], NULL, txt_len, lv_obj_get_base_dir(label), + lv_txt_encoded_get_char_id(bidi_txt, i), &is_rtl); + if(is_rtl) logical_pos++; lv_mem_buf_release(bidi_txt); #else logical_pos = lv_txt_encoded_get_char_id(bidi_txt, i); @@ -916,11 +921,11 @@ lv_style_list_t * lv_label_get_style(lv_obj_t * label, uint8_t type) { lv_style_list_t * style_dsc_p; switch(type) { - case LV_LABEL_PART_MAIN: - style_dsc_p = &label->style_list; - break; - default: - style_dsc_p = NULL; + case LV_LABEL_PART_MAIN: + style_dsc_p = &label->style_list; + break; + default: + style_dsc_p = NULL; } return style_dsc_p; @@ -1095,7 +1100,7 @@ static lv_design_res_t lv_label_design(lv_obj_t * label, const lv_area_t * clip_ /*Draw the text again next to the original to make an circular effect */ if(size.x > lv_area_get_width(&txt_coords)) { label_draw_dsc.ofs_x = ext->offset.x + size.x + - lv_font_get_glyph_width(label_draw_dsc.font, ' ', ' ') * LV_LABEL_WAIT_CHAR_COUNT; + lv_font_get_glyph_width(label_draw_dsc.font, ' ', ' ') * LV_LABEL_WAIT_CHAR_COUNT; label_draw_dsc.ofs_y = ext->offset.y; lv_draw_label(&txt_coords, &txt_clip, &label_draw_dsc, ext->text, hint); @@ -1144,22 +1149,26 @@ static lv_res_t lv_label_signal(lv_obj_t * label, lv_signal_t sign, void * param ext->text = NULL; } lv_label_dot_tmp_free(label); - } else if(sign == LV_SIGNAL_STYLE_CHG) { + } + else if(sign == LV_SIGNAL_STYLE_CHG) { /*Revert dots for proper refresh*/ lv_label_revert_dots(label); lv_label_refr_text(label); - } else if(sign == LV_SIGNAL_COORD_CHG) { + } + else if(sign == LV_SIGNAL_COORD_CHG) { if(lv_area_get_width(&label->coords) != lv_area_get_width(param) || lv_area_get_height(&label->coords) != lv_area_get_height(param)) { lv_label_revert_dots(label); lv_label_refr_text(label); } - } else if(sign == LV_SIGNAL_BASE_DIR_CHG) { + } + else if(sign == LV_SIGNAL_BASE_DIR_CHG) { #if LV_USE_BIDI if(ext->static_txt == 0) lv_label_set_text(label, NULL); #endif - } else if(sign == LV_SIGNAL_GET_TYPE) { + } + else if(sign == LV_SIGNAL_GET_TYPE) { lv_obj_type_t * buf = param; uint8_t i; for(i = 0; i < LV_MAX_ANCESTOR_NUM - 1; i++) { /*Find the last set data*/ @@ -1217,8 +1226,8 @@ static void lv_label_refr_text(lv_obj_t * label) lv_anim_set_var(&a, label); lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINIT); lv_anim_set_playback_delay(&a, (((lv_font_get_glyph_width(font, ' ', ' ') + letter_space) * 1000) / - ext->anim_speed) * - LV_LABEL_WAIT_CHAR_COUNT); + ext->anim_speed) * + LV_LABEL_WAIT_CHAR_COUNT); lv_anim_set_repeat_delay(&a, a.playback_delay); bool hor_anim = false; @@ -1229,7 +1238,8 @@ static void lv_label_refr_text(lv_obj_t * label) lv_anim_set_playback_time(&a, a.time); lv_anim_start(&a); hor_anim = true; - } else { + } + else { /*Delete the offset animation if not required*/ lv_anim_del(label, (lv_anim_exec_xcb_t)lv_label_set_offset_x); ext->offset.x = 0; @@ -1241,7 +1251,8 @@ static void lv_label_refr_text(lv_obj_t * label) lv_anim_set_time(&a, lv_anim_speed_to_time(ext->anim_speed, a.start, a.end)); lv_anim_set_playback_time(&a, a.time); lv_anim_start(&a); - } else { + } + else { /*Delete the offset animation if not required*/ lv_anim_del(label, (lv_anim_exec_xcb_t)lv_label_set_offset_y); ext->offset.y = 0; @@ -1257,7 +1268,7 @@ static void lv_label_refr_text(lv_obj_t * label) lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINIT); uint32_t delay = (((lv_font_get_glyph_width(font, ' ', ' ') + letter_space) * 1000) / ext->anim_speed) * - LV_LABEL_WAIT_CHAR_COUNT; + LV_LABEL_WAIT_CHAR_COUNT; lv_anim_set_delay(&a, delay); bool hor_anim = false; @@ -1267,7 +1278,8 @@ static void lv_label_refr_text(lv_obj_t * label) lv_anim_set_time(&a, lv_anim_speed_to_time(ext->anim_speed, a.start, a.end)); lv_anim_start(&a); hor_anim = true; - } else { + } + else { /*Delete the offset animation if not required*/ lv_anim_del(label, (lv_anim_exec_xcb_t)lv_label_set_offset_x); ext->offset.x = 0; @@ -1278,22 +1290,26 @@ static void lv_label_refr_text(lv_obj_t * label) lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)lv_label_set_offset_y); lv_anim_set_time(&a, lv_anim_speed_to_time(ext->anim_speed, a.start, a.end)); lv_anim_start(&a); - } else { + } + else { /*Delete the offset animation if not required*/ lv_anim_del(label, (lv_anim_exec_xcb_t)lv_label_set_offset_y); ext->offset.y = 0; } #endif - } else if(ext->long_mode == LV_LABEL_LONG_DOT) { + } + else if(ext->long_mode == LV_LABEL_LONG_DOT) { if(size.y <= lv_area_get_height(&txt_coords)) { /*No dots are required, the text is short enough*/ ext->dot_end = LV_LABEL_DOT_END_INV; - } else if(lv_txt_get_encoded_length(ext->text) <= LV_LABEL_DOT_NUM) { /*Don't turn to dots all the characters*/ + } + else if(lv_txt_get_encoded_length(ext->text) <= LV_LABEL_DOT_NUM) { /*Don't turn to dots all the characters*/ ext->dot_end = LV_LABEL_DOT_END_INV; - } else { + } + else { lv_point_t p; p.x = lv_area_get_width(&txt_coords) - (lv_font_get_glyph_width(font, '.', '.') + letter_space) * - LV_LABEL_DOT_NUM; /*Shrink with dots*/ + LV_LABEL_DOT_NUM; /*Shrink with dots*/ p.y = lv_area_get_height(&txt_coords); p.y -= p.y % (lv_font_get_line_height(font) + line_space); /*Round down to the last line*/ @@ -1399,7 +1415,8 @@ static bool lv_label_set_dot_tmp(lv_obj_t * label, char * data, uint16_t len) memcpy(ext->dot.tmp_ptr, data, len); ext->dot.tmp_ptr[len] = '\0'; ext->dot_tmp_alloc = true; - } else { + } + else { /* Characters can be directly stored in object */ ext->dot_tmp_alloc = false; memcpy(ext->dot.tmp, data, len); @@ -1417,7 +1434,8 @@ static char * lv_label_get_dot_tmp(lv_obj_t * label) lv_label_ext_t * ext = lv_obj_get_ext_attr(label); if(ext->dot_tmp_alloc) { return ext->dot.tmp_ptr; - } else { + } + else { return ext->dot.tmp; } } diff --git a/src/lv_widgets/lv_label.h b/src/lv_widgets/lv_label.h index a96b0072a..0b676eb4d 100644 --- a/src/lv_widgets/lv_label.h +++ b/src/lv_widgets/lv_label.h @@ -61,14 +61,12 @@ enum { typedef uint8_t lv_label_align_t; /** Data of label*/ -typedef struct -{ +typedef struct { /*Inherited from 'base_obj' so no inherited ext.*/ /*Ext. of ancestor*/ /*New data for this type */ char * text; /*Text of the label*/ - union - { + union { char * tmp_ptr; /* Pointer to the allocated memory containing the character which are replaced by dots (Handled by the library)*/ char tmp[LV_LABEL_DOT_NUM + 1]; /* Directly store the characters if <=4 characters */ diff --git a/src/lv_widgets/lv_led.c b/src/lv_widgets/lv_led.c index 236203475..c98ac8743 100644 --- a/src/lv_widgets/lv_led.c +++ b/src/lv_widgets/lv_led.c @@ -82,7 +82,7 @@ lv_obj_t * lv_led_create(lv_obj_t * par, const lv_obj_t * copy) if(copy == NULL) { lv_obj_set_size(led, LV_LED_WIDTH_DEF, LV_LED_HEIGHT_DEF); - lv_theme_apply(led,LV_THEME_LED); + lv_theme_apply(led, LV_THEME_LED); } /*Copy an existing object*/ else { @@ -194,7 +194,8 @@ static lv_design_res_t lv_led_design(lv_obj_t * led, const lv_area_t * clip_area if(mode == LV_DESIGN_COVER_CHK) { /*Return false if the object is not covers the clip_area area*/ return ancestor_design(led, clip_area, mode); - } else if(mode == LV_DESIGN_DRAW_MAIN) { + } + else if(mode == LV_DESIGN_DRAW_MAIN) { /*Make darker colors in a temporary style according to the brightness*/ lv_led_ext_t * ext = lv_obj_get_ext_attr(led); @@ -210,7 +211,8 @@ static lv_design_res_t lv_led_design(lv_obj_t * led, const lv_area_t * clip_area /*Set the current shadow width according to brightness proportionally between LV_LED_BRIGHT_OFF * and LV_LED_BRIGHT_ON*/ - rect_dsc.shadow_width = ((ext->bright - LV_LED_BRIGHT_OFF) * rect_dsc.shadow_width) / (LV_LED_BRIGHT_ON - LV_LED_BRIGHT_OFF); + rect_dsc.shadow_width = ((ext->bright - LV_LED_BRIGHT_OFF) * rect_dsc.shadow_width) / + (LV_LED_BRIGHT_ON - LV_LED_BRIGHT_OFF); lv_draw_rect(&led->coords, clip_area, &rect_dsc); } diff --git a/src/lv_widgets/lv_led.h b/src/lv_widgets/lv_led.h index 92a2b916a..2ef640954 100644 --- a/src/lv_widgets/lv_led.h +++ b/src/lv_widgets/lv_led.h @@ -28,8 +28,7 @@ extern "C" { **********************/ /*Data of led*/ -typedef struct -{ +typedef struct { /*No inherited ext.*/ /*New data for this type */ uint8_t bright; /*Current brightness of the LED (0..255)*/ diff --git a/src/lv_widgets/lv_line.c b/src/lv_widgets/lv_line.c index 4365b4bac..7a5694078 100644 --- a/src/lv_widgets/lv_line.c +++ b/src/lv_widgets/lv_line.c @@ -254,7 +254,8 @@ static lv_design_res_t lv_line_design(lv_obj_t * line, const lv_area_t * clip_ar if(ext->y_inv == 0) { p1.y = ext->point_array[i].y + y_ofs; p2.y = ext->point_array[i + 1].y + y_ofs; - } else { + } + else { p1.y = h - ext->point_array[i].y + y_ofs; p2.y = h - ext->point_array[i + 1].y + y_ofs; } @@ -281,9 +282,9 @@ static lv_res_t lv_line_signal(lv_obj_t * line, lv_signal_t sign, void * param) if(res != LV_RES_OK) return res; if(sign == LV_SIGNAL_GET_TYPE) return lv_obj_handle_get_type_signal(param, LV_OBJX_NAME); - if(sign == LV_SIGNAL_REFR_EXT_DRAW_PAD) { - /*The corner of the skew lines is out of the intended area*/ - lv_style_int_t line_width = lv_obj_get_style_line_width(line, LV_LINE_PART_MAIN); + if(sign == LV_SIGNAL_REFR_EXT_DRAW_PAD) { + /*The corner of the skew lines is out of the intended area*/ + lv_style_int_t line_width = lv_obj_get_style_line_width(line, LV_LINE_PART_MAIN); if(line->ext_draw_pad < line_width) line->ext_draw_pad = line_width; } diff --git a/src/lv_widgets/lv_line.h b/src/lv_widgets/lv_line.h index 9851b31ff..430a9da01 100644 --- a/src/lv_widgets/lv_line.h +++ b/src/lv_widgets/lv_line.h @@ -28,8 +28,7 @@ extern "C" { **********************/ /*Data of line*/ -typedef struct -{ +typedef struct { /*Inherited from 'base_obj' so no inherited ext.*/ /*Ext. of ancestor*/ const lv_point_t * point_array; /*Pointer to an array with the points of the line*/ uint16_t point_num; /*Number of points in 'point_array' */ @@ -86,7 +85,7 @@ void lv_line_set_y_invert(lv_obj_t * line, bool en); #define lv_line_set_y_inv \ lv_line_set_y_invert /*The name was inconsistent. In v.6.0 only `lv_line_set_y_invert`will \ - work */ +work */ /*===================== diff --git a/src/lv_widgets/lv_linemeter.c b/src/lv_widgets/lv_linemeter.c index e42f2f48c..a4e550734 100644 --- a/src/lv_widgets/lv_linemeter.c +++ b/src/lv_widgets/lv_linemeter.c @@ -95,8 +95,8 @@ lv_obj_t * lv_linemeter_create(lv_obj_t * par, const lv_obj_t * copy) ext->max_value = copy_ext->max_value; ext->cur_value = copy_ext->cur_value; -// /*Refresh the style with new signal function*/ -// lv_obj_refresh_style(new_lmeter); + // /*Refresh the style with new signal function*/ + // lv_obj_refresh_style(new_lmeter); } LV_LOG_INFO("line meter created"); @@ -340,8 +340,7 @@ void lv_linemeter_draw_scale(lv_obj_t * lmeter, const lv_area_t * clip_area, uin lv_style_int_t border_width = lv_obj_get_style_scale_border_width(lmeter, part); lv_style_int_t end_border_width = lv_obj_get_style_scale_end_border_width(lmeter, part); - if(border_width || end_border_width) - { + if(border_width || end_border_width) { int16_t end_angle = (level * ext->scale_angle) / (ext->line_cnt - 1) + angle_ofs - 1; lv_draw_line_dsc_t arc_dsc; lv_draw_line_dsc_init(&arc_dsc); @@ -355,8 +354,8 @@ void lv_linemeter_draw_scale(lv_obj_t * lmeter, const lv_area_t * clip_area, uin if(end_border_width) { arc_dsc.width = end_border_width; - arc_dsc.color = end_color; - lv_draw_arc(x_ofs, y_ofs, r_out, end_angle, (angle_ofs + ext->scale_angle) % 360, clip_area, &arc_dsc); + arc_dsc.color = end_color; + lv_draw_arc(x_ofs, y_ofs, r_out, end_angle, (angle_ofs + ext->scale_angle) % 360, clip_area, &arc_dsc); } @@ -420,7 +419,8 @@ static lv_res_t lv_linemeter_signal(lv_obj_t * lmeter, lv_signal_t sign, void * if(sign == LV_SIGNAL_CLEANUP) { /*Nothing to cleanup. (No dynamically allocated memory in 'ext')*/ - } else if(sign == LV_SIGNAL_STYLE_CHG) { + } + else if(sign == LV_SIGNAL_STYLE_CHG) { lv_obj_refresh_ext_draw_pad(lmeter); lv_obj_invalidate(lmeter); } diff --git a/src/lv_widgets/lv_linemeter.h b/src/lv_widgets/lv_linemeter.h index d78fcc691..8564602e1 100644 --- a/src/lv_widgets/lv_linemeter.h +++ b/src/lv_widgets/lv_linemeter.h @@ -27,8 +27,7 @@ extern "C" { * TYPEDEFS **********************/ /*Data of line meter*/ -typedef struct -{ +typedef struct { /*No inherited ext.*/ /*Ext. of ancestor*/ /*New data for this type */ uint16_t scale_angle; /*Angle of the scale in deg. (0..360)*/ diff --git a/src/lv_widgets/lv_list.c b/src/lv_widgets/lv_list.c index c9deae0f8..7b74d6c4a 100644 --- a/src/lv_widgets/lv_list.c +++ b/src/lv_widgets/lv_list.c @@ -23,8 +23,8 @@ #define LV_LIST_LAYOUT_DEF LV_LAYOUT_COLUMN_MID #if LV_USE_ANIMATION == 0 -#undef LV_LIST_DEF_ANIM_TIME -#define LV_LIST_DEF_ANIM_TIME 0 + #undef LV_LIST_DEF_ANIM_TIME + #define LV_LIST_DEF_ANIM_TIME 0 #endif /********************** @@ -45,7 +45,7 @@ static bool lv_list_is_list_label(lv_obj_t * list_btn); * STATIC VARIABLES **********************/ #if LV_USE_IMG -static lv_signal_cb_t img_signal; + static lv_signal_cb_t img_signal; #endif static lv_signal_cb_t label_signal; static lv_signal_cb_t ancestor_page_signal; @@ -101,7 +101,8 @@ lv_obj_t * lv_list_create(lv_obj_t * par, const lv_obj_t * copy) lv_theme_apply(list, LV_THEME_LIST); - } else { + } + else { lv_obj_t * copy_btn = lv_list_get_next_btn(copy, NULL); while(copy_btn) { const void * img_src = NULL; @@ -170,13 +171,15 @@ lv_obj_t * lv_list_add_btn(lv_obj_t * list, const void * img_src, const char * t lv_layout_t list_layout = lv_list_get_layout(list); bool layout_ver = false; - if(list_layout == LV_LAYOUT_COLUMN_MID || list_layout == LV_LAYOUT_COLUMN_LEFT || list_layout == LV_LAYOUT_COLUMN_RIGHT) { - layout_ver = true; + if(list_layout == LV_LAYOUT_COLUMN_MID || list_layout == LV_LAYOUT_COLUMN_LEFT || + list_layout == LV_LAYOUT_COLUMN_RIGHT) { + layout_ver = true; } if(layout_ver) { lv_btn_set_fit2(btn, LV_FIT_PARENT, LV_FIT_TIGHT); - } else { + } + else { lv_coord_t w = last_btn ? lv_obj_get_width(last_btn) : (LV_DPI * 3) / 2; lv_btn_set_fit2(btn, LV_FIT_NONE, LV_FIT_TIGHT); lv_obj_set_width(btn, w); @@ -291,12 +294,12 @@ void lv_list_focus_btn(lv_obj_t * list, lv_obj_t * btn) * @param list pointer to a list object * @param layout which layout should be used */ - void lv_list_set_layout(lv_obj_t * list, lv_layout_t layout) - { - LV_ASSERT_OBJ(list, LV_OBJX_NAME); +void lv_list_set_layout(lv_obj_t * list, lv_layout_t layout) +{ + LV_ASSERT_OBJ(list, LV_OBJX_NAME); - /* Update list layout if necessary */ - if (layout == lv_list_get_layout(list)) return; + /* Update list layout if necessary */ + if(layout == lv_list_get_layout(list)) return; /* Get the first button on the list */ lv_obj_t * btn = lv_list_get_prev_btn(list, NULL); @@ -308,7 +311,7 @@ void lv_list_focus_btn(lv_obj_t * list, lv_obj_t * btn) lv_btn_set_fit2(btn, LV_FIT_PARENT, LV_FIT_TIGHT); } /*If a row layout set the buttons' width according to the content*/ - else if (layout == LV_LAYOUT_ROW_MID || layout == LV_LAYOUT_ROW_TOP || layout == LV_LAYOUT_ROW_BOTTOM) { + else if(layout == LV_LAYOUT_ROW_MID || layout == LV_LAYOUT_ROW_TOP || layout == LV_LAYOUT_ROW_BOTTOM) { lv_btn_set_fit(btn, LV_FIT_TIGHT); } @@ -317,13 +320,14 @@ void lv_list_focus_btn(lv_obj_t * list, lv_obj_t * btn) if(layout == LV_LAYOUT_COLUMN_MID || layout == LV_LAYOUT_COLUMN_LEFT || layout == LV_LAYOUT_COLUMN_RIGHT) { lv_page_set_scrl_fit2(list, LV_FIT_PARENT, LV_FIT_TIGHT); - } else if (layout == LV_LAYOUT_ROW_MID || layout == LV_LAYOUT_ROW_TOP || layout == LV_LAYOUT_ROW_BOTTOM) { + } + else if(layout == LV_LAYOUT_ROW_MID || layout == LV_LAYOUT_ROW_TOP || layout == LV_LAYOUT_ROW_BOTTOM) { lv_page_set_scrl_fit2(list, LV_FIT_TIGHT, LV_FIT_TIGHT); lv_cont_set_fit2(list, LV_FIT_NONE, LV_FIT_TIGHT); } lv_page_set_scrl_layout(list, layout); - } +} /*===================== * Getter functions @@ -538,7 +542,8 @@ void lv_list_up(const lv_obj_t * list) lv_coord_t new_y = lv_obj_get_height(list) - (lv_obj_get_y(e_prev) + lv_obj_get_height(e_prev)); if(lv_list_get_anim_time(list) == 0) { lv_obj_set_y(scrl, new_y); - } else { + } + else { #if LV_USE_ANIMATION lv_anim_t a; lv_anim_init(&a); @@ -575,7 +580,8 @@ void lv_list_down(const lv_obj_t * list) lv_coord_t new_y = -lv_obj_get_y(e); if(lv_list_get_anim_time(list) == 0) { lv_obj_set_y(scrl, new_y); - } else { + } + else { #if LV_USE_ANIMATION lv_anim_t a; lv_anim_init(&a); @@ -654,16 +660,20 @@ static lv_res_t lv_list_signal(lv_obj_t * list, lv_signal_t sign, void * param) if(sign == LV_SIGNAL_PRESSED) { res = lv_event_send(ext->act_sel_btn, LV_EVENT_PRESSED, NULL); if(res != LV_RES_OK) return res; - } else if(sign == LV_SIGNAL_PRESSING) { + } + else if(sign == LV_SIGNAL_PRESSING) { res = lv_event_send(ext->act_sel_btn, LV_EVENT_PRESSING, NULL); if(res != LV_RES_OK) return res; - } else if(sign == LV_SIGNAL_LONG_PRESS) { + } + else if(sign == LV_SIGNAL_LONG_PRESS) { res = lv_event_send(ext->act_sel_btn, LV_EVENT_LONG_PRESSED, NULL); if(res != LV_RES_OK) return res; - } else if(sign == LV_SIGNAL_LONG_PRESS_REP) { + } + else if(sign == LV_SIGNAL_LONG_PRESS_REP) { res = lv_event_send(ext->act_sel_btn, LV_EVENT_LONG_PRESSED_REPEAT, NULL); if(res != LV_RES_OK) return res; - } else if(sign == LV_SIGNAL_RELEASED) { + } + else if(sign == LV_SIGNAL_RELEASED) { if(indev->proc.long_pr_sent == 0) { res = lv_event_send(ext->act_sel_btn, LV_EVENT_SHORT_CLICKED, NULL); if(res != LV_RES_OK) return res; @@ -679,21 +689,23 @@ static lv_res_t lv_list_signal(lv_obj_t * list, lv_signal_t sign, void * param) } } #endif - } else if(sign == LV_SIGNAL_FOCUS) { + } + else if(sign == LV_SIGNAL_FOCUS) { #if LV_USE_GROUP lv_indev_type_t indev_type = lv_indev_get_type(lv_indev_get_act()); /*With ENCODER focus the button only in edit mode*/ lv_group_t * g = lv_obj_get_group(list); if((indev_type == LV_INDEV_TYPE_KEYPAD) || - (indev_type == LV_INDEV_TYPE_ENCODER && lv_group_get_editing(g))) { + (indev_type == LV_INDEV_TYPE_ENCODER && lv_group_get_editing(g))) { lv_list_ext_t * ext = lv_obj_get_ext_attr(list); /* Select the last used button, or use the first no last button */ if(ext->last_sel_btn) lv_list_focus_btn(list, ext->last_sel_btn); else lv_list_focus_btn(list, lv_list_get_next_btn(list, NULL)); } #endif - } else if(sign == LV_SIGNAL_DEFOCUS) { + } + else if(sign == LV_SIGNAL_DEFOCUS) { #if LV_USE_GROUP /*De-select the selected btn*/ @@ -701,10 +713,12 @@ static lv_res_t lv_list_signal(lv_obj_t * list, lv_signal_t sign, void * param) lv_list_ext_t * ext = lv_obj_get_ext_attr(list); ext->act_sel_btn = NULL; #endif - } else if(sign == LV_SIGNAL_GET_EDITABLE) { + } + else if(sign == LV_SIGNAL_GET_EDITABLE) { bool * editable = (bool *)param; *editable = true; - } else if(sign == LV_SIGNAL_CONTROL) { + } + else if(sign == LV_SIGNAL_CONTROL) { #if LV_USE_GROUP char c = *((char *)param); @@ -720,9 +734,10 @@ static lv_res_t lv_list_signal(lv_obj_t * list, lv_signal_t sign, void * param) lv_obj_t * btn = lv_list_get_next_btn(list, NULL); if(btn) lv_list_focus_btn(list, - btn); /*If there are no buttons on the list then there is no first button*/ + btn); /*If there are no buttons on the list then there is no first button*/ } - } else if(c == LV_KEY_LEFT || c == LV_KEY_UP) { + } + else if(c == LV_KEY_LEFT || c == LV_KEY_UP) { lv_list_ext_t * ext = lv_obj_get_ext_attr(list); /*If there is a valid selected button the make the next selected*/ if(ext->act_sel_btn != NULL) { @@ -756,8 +771,9 @@ static lv_res_t lv_list_btn_signal(lv_obj_t * btn, lv_signal_t sign, void * para if(res != LV_RES_OK) return res; if(sign == LV_SIGNAL_GET_TYPE) return lv_obj_handle_get_type_signal(param, ""); - if((sign == LV_SIGNAL_COORD_CHG && (lv_obj_get_width(btn) != lv_area_get_width(param) || lv_obj_get_height(btn) != lv_area_get_height(param))) || - sign == LV_SIGNAL_STYLE_CHG) { + if((sign == LV_SIGNAL_COORD_CHG && (lv_obj_get_width(btn) != lv_area_get_width(param) || + lv_obj_get_height(btn) != lv_area_get_height(param))) || + sign == LV_SIGNAL_STYLE_CHG) { lv_obj_t * label = lv_list_get_btn_label(btn); if(label) { const lv_font_t * font = lv_obj_get_style_text_font(label, LV_LABEL_PART_MAIN); @@ -776,11 +792,11 @@ static lv_res_t lv_list_btn_signal(lv_obj_t * btn, lv_signal_t sign, void * para if(lv_indev_is_dragging(lv_indev_get_act()) == false) { lv_obj_t * list = lv_obj_get_parent(lv_obj_get_parent(btn)); lv_list_focus_btn(list, btn); - #if LV_USE_GROUP +#if LV_USE_GROUP if(lv_obj_get_group(list)) { lv_group_focus_obj(list); } - #endif +#endif } } else if(sign == LV_SIGNAL_CLEANUP) { @@ -808,22 +824,22 @@ static lv_style_list_t * lv_list_get_style(lv_obj_t * list, uint8_t part) lv_style_list_t * style_dsc_p; switch(part) { - case LV_LIST_PART_BG: - style_dsc_p = &list->style_list; - break; - case LV_LIST_PART_SCRL: - style_dsc_p = &ext->page.scrl->style_list; - break; - case LV_LIST_PART_SCRLBAR: - style_dsc_p = &ext->page.scrlbar.style; - break; + case LV_LIST_PART_BG: + style_dsc_p = &list->style_list; + break; + case LV_LIST_PART_SCRL: + style_dsc_p = &ext->page.scrl->style_list; + break; + case LV_LIST_PART_SCRLBAR: + style_dsc_p = &ext->page.scrlbar.style; + break; #if LV_USE_ANIMATION - case LV_LIST_PART_EDGE_FLASH: - style_dsc_p = &ext->page.edge_flash.style; - break; + case LV_LIST_PART_EDGE_FLASH: + style_dsc_p = &ext->page.edge_flash.style; + break; #endif - default: - style_dsc_p = NULL; + default: + style_dsc_p = NULL; } return style_dsc_p; diff --git a/src/lv_widgets/lv_list.h b/src/lv_widgets/lv_list.h index c7d5b9620..1c9efb4d6 100644 --- a/src/lv_widgets/lv_list.h +++ b/src/lv_widgets/lv_list.h @@ -44,8 +44,7 @@ extern "C" { * TYPEDEFS **********************/ /*Data of list*/ -typedef struct -{ +typedef struct { lv_page_ext_t page; /*Ext. of ancestor*/ /*New data for this type */ diff --git a/src/lv_widgets/lv_msgbox.c b/src/lv_widgets/lv_msgbox.c index 94efa6c2c..3cf6a0905 100644 --- a/src/lv_widgets/lv_msgbox.c +++ b/src/lv_widgets/lv_msgbox.c @@ -21,12 +21,12 @@ #define LV_OBJX_NAME "lv_msgbox" #if LV_USE_ANIMATION -#ifndef LV_MSGBOX_CLOSE_ANIM_TIME -#define LV_MSGBOX_CLOSE_ANIM_TIME 200 /*List close animation time) */ -#endif + #ifndef LV_MSGBOX_CLOSE_ANIM_TIME + #define LV_MSGBOX_CLOSE_ANIM_TIME 200 /*List close animation time) */ + #endif #else -#undef LV_MSGBOX_CLOSE_ANIM_TIME -#define LV_MSGBOX_CLOSE_ANIM_TIME 0 /*No animations*/ + #undef LV_MSGBOX_CLOSE_ANIM_TIME + #define LV_MSGBOX_CLOSE_ANIM_TIME 0 /*No animations*/ #endif /********************** @@ -40,7 +40,7 @@ static lv_res_t lv_msgbox_signal(lv_obj_t * mbox, lv_signal_t sign, void * param static void mbox_realign(lv_obj_t * mbox); static lv_style_list_t * lv_msgbox_get_style(lv_obj_t * mbox, uint8_t part); #if LV_USE_ANIMATION -static void lv_msgbox_close_ready_cb(lv_anim_t * a); + static void lv_msgbox_close_ready_cb(lv_anim_t * a); #endif static void lv_msgbox_default_event_cb(lv_obj_t * mbox, lv_event_t event); static void lv_msgbox_btnm_event_cb(lv_obj_t * btnm, lv_event_t event); @@ -219,14 +219,15 @@ void lv_msgbox_start_auto_close(lv_obj_t * mbox, uint16_t delay) lv_anim_set_delay(&a, delay); lv_anim_start(&a); - lv_anim_set_exec_cb(&a,(lv_anim_exec_xcb_t)lv_obj_set_width); + lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)lv_obj_set_width); lv_anim_set_values(&a, lv_obj_get_width(mbox), 0); lv_anim_set_ready_cb(&a, lv_msgbox_close_ready_cb); lv_anim_start(&a); /*Disable fit to let shrinking work*/ lv_cont_set_fit(mbox, LV_FIT_NONE); - } else { + } + else { /*Create an animation to delete the mbox `delay` ms later*/ lv_anim_t a; lv_anim_init(&a); @@ -399,15 +400,17 @@ static lv_res_t lv_msgbox_signal(lv_obj_t * mbox, lv_signal_t sign, void * param } if(sign == LV_SIGNAL_GET_STYLE) { - lv_get_style_info_t * info = param; - info->result = lv_msgbox_get_style(mbox, info->part); - if(info->result != NULL) return LV_RES_OK; - else return ancestor_signal(mbox, sign, param); - } else if(sign == LV_SIGNAL_GET_STATE_DSC) { + lv_get_style_info_t * info = param; + info->result = lv_msgbox_get_style(mbox, info->part); + if(info->result != NULL) return LV_RES_OK; + else return ancestor_signal(mbox, sign, param); + } + else if(sign == LV_SIGNAL_GET_STATE_DSC) { lv_get_state_info_t * info = param; lv_msgbox_ext_t * ext = lv_obj_get_ext_attr(mbox); if(ext->btnm && info->part == LV_MSGBOX_PART_BTN_BG) info->result = lv_obj_get_state(ext->btnm, LV_BTNMATRIX_PART_BG); - else if(ext->btnm && info->part == LV_MSGBOX_PART_BTN) info->result = lv_obj_get_state(ext->btnm, LV_BTNMATRIX_PART_BTN); + else if(ext->btnm && + info->part == LV_MSGBOX_PART_BTN) info->result = lv_obj_get_state(ext->btnm, LV_BTNMATRIX_PART_BTN); return LV_RES_OK; } @@ -421,15 +424,18 @@ static lv_res_t lv_msgbox_signal(lv_obj_t * mbox, lv_signal_t sign, void * param if(lv_obj_get_width(mbox) != lv_area_get_width(param)) { mbox_realign(mbox); } - } else if(sign == LV_SIGNAL_STYLE_CHG) { + } + else if(sign == LV_SIGNAL_STYLE_CHG) { mbox_realign(mbox); - } else if(sign == LV_SIGNAL_RELEASED) { + } + else if(sign == LV_SIGNAL_RELEASED) { if(ext->btnm) { uint32_t btn_id = lv_btnmatrix_get_active_btn(ext->btnm); if(btn_id != LV_BTNMATRIX_BTN_NONE) lv_event_send(mbox, LV_EVENT_VALUE_CHANGED, &btn_id); } - } else if(sign == LV_SIGNAL_FOCUS || sign == LV_SIGNAL_DEFOCUS || sign == LV_SIGNAL_CONTROL || - sign == LV_SIGNAL_GET_EDITABLE) { + } + else if(sign == LV_SIGNAL_FOCUS || sign == LV_SIGNAL_DEFOCUS || sign == LV_SIGNAL_CONTROL || + sign == LV_SIGNAL_GET_EDITABLE) { if(ext->btnm) { ext->btnm->signal_cb(ext->btnm, sign, param); } @@ -469,17 +475,17 @@ static lv_style_list_t * lv_msgbox_get_style(lv_obj_t * mbox, uint8_t part) lv_style_list_t * style_dsc_p; switch(part) { - case LV_MSGBOX_PART_BG: - style_dsc_p = &mbox->style_list; - break; - case LV_MSGBOX_PART_BTN_BG: - style_dsc_p = ext->btnm ? lv_obj_get_style_list(ext->btnm, LV_BTNMATRIX_PART_BG) : NULL; - break; - case LV_MSGBOX_PART_BTN: - style_dsc_p = ext->btnm ? lv_obj_get_style_list(ext->btnm, LV_BTNMATRIX_PART_BTN) : NULL; - break; - default: - style_dsc_p = NULL; + case LV_MSGBOX_PART_BG: + style_dsc_p = &mbox->style_list; + break; + case LV_MSGBOX_PART_BTN_BG: + style_dsc_p = ext->btnm ? lv_obj_get_style_list(ext->btnm, LV_BTNMATRIX_PART_BG) : NULL; + break; + case LV_MSGBOX_PART_BTN: + style_dsc_p = ext->btnm ? lv_obj_get_style_list(ext->btnm, LV_BTNMATRIX_PART_BTN) : NULL; + break; + default: + style_dsc_p = NULL; } return style_dsc_p; diff --git a/src/lv_widgets/lv_msgbox.h b/src/lv_widgets/lv_msgbox.h index d1b9940ee..e7e261d17 100644 --- a/src/lv_widgets/lv_msgbox.h +++ b/src/lv_widgets/lv_msgbox.h @@ -44,8 +44,7 @@ extern "C" { **********************/ /*Data of message box*/ -typedef struct -{ +typedef struct { lv_cont_ext_t bg; /*Ext. of ancestor*/ /*New data for this type */ lv_obj_t * text; /*Text of the message box*/ diff --git a/src/lv_widgets/lv_objmask.c b/src/lv_widgets/lv_objmask.c index a1eaeee65..7a3f85c52 100644 --- a/src/lv_widgets/lv_objmask.c +++ b/src/lv_widgets/lv_objmask.c @@ -231,8 +231,8 @@ static lv_design_res_t lv_objmask_design(lv_obj_t * objmask, const lv_area_t * c lv_draw_mask_line_param_t * p_new = lv_mem_buf_get(sizeof(lv_draw_mask_line_param_t)); lv_draw_mask_line_points_init(p_new, p_ori->cfg.p1.x + xofs, p_ori->cfg.p1.y + yofs, - p_ori->cfg.p2.x + xofs, p_ori->cfg.p2.y + yofs, - p_ori->cfg.side); + p_ori->cfg.p2.x + xofs, p_ori->cfg.p2.y + yofs, + p_ori->cfg.side); lv_draw_mask_add(p_new, m->param); } else if(dsc->type == LV_DRAW_MASK_TYPE_ANGLE) { @@ -240,7 +240,7 @@ static lv_design_res_t lv_objmask_design(lv_obj_t * objmask, const lv_area_t * c lv_draw_mask_angle_param_t * p_new = lv_mem_buf_get(sizeof(lv_draw_mask_angle_param_t)); lv_draw_mask_angle_init(p_new, p_ori->cfg.vertex_p.x + xofs, p_ori->cfg.vertex_p.y + yofs, - p_ori->cfg.start_angle, p_ori->cfg.end_angle); + p_ori->cfg.start_angle, p_ori->cfg.end_angle); lv_draw_mask_add(p_new, m->param); } else if(dsc->type == LV_DRAW_MASK_TYPE_RADIUS) { @@ -267,7 +267,7 @@ static lv_design_res_t lv_objmask_design(lv_obj_t * objmask, const lv_area_t * c rect.y2 = p_ori->cfg.coords.y2 + yofs; lv_draw_mask_fade_init(p_new, &rect, p_ori->cfg.opa_top, p_ori->cfg.y_top + yofs, - p_ori->cfg.opa_bottom, p_ori->cfg.y_bottom + yofs); + p_ori->cfg.opa_bottom, p_ori->cfg.y_bottom + yofs); lv_draw_mask_add(p_new, m->param); } else if(dsc->type == LV_DRAW_MASK_TYPE_MAP) { @@ -341,12 +341,23 @@ static uint16_t get_param_size(lv_draw_mask_type_t type) { uint16_t param_size; switch(type) { - case LV_DRAW_MASK_TYPE_LINE: param_size = sizeof(lv_draw_mask_line_param_t); break; - case LV_DRAW_MASK_TYPE_ANGLE: param_size = sizeof(lv_draw_mask_angle_param_t); break; - case LV_DRAW_MASK_TYPE_RADIUS: param_size = sizeof(lv_draw_mask_radius_param_t); break; - case LV_DRAW_MASK_TYPE_FADE: param_size = sizeof(lv_draw_mask_fade_param_t); break; - case LV_DRAW_MASK_TYPE_MAP: param_size = sizeof(lv_draw_mask_map_param_t); break; - default: param_size = 0; + case LV_DRAW_MASK_TYPE_LINE: + param_size = sizeof(lv_draw_mask_line_param_t); + break; + case LV_DRAW_MASK_TYPE_ANGLE: + param_size = sizeof(lv_draw_mask_angle_param_t); + break; + case LV_DRAW_MASK_TYPE_RADIUS: + param_size = sizeof(lv_draw_mask_radius_param_t); + break; + case LV_DRAW_MASK_TYPE_FADE: + param_size = sizeof(lv_draw_mask_fade_param_t); + break; + case LV_DRAW_MASK_TYPE_MAP: + param_size = sizeof(lv_draw_mask_map_param_t); + break; + default: + param_size = 0; } return param_size; diff --git a/src/lv_widgets/lv_objmask.h b/src/lv_widgets/lv_objmask.h index 39736bdd2..0c568f989 100644 --- a/src/lv_widgets/lv_objmask.h +++ b/src/lv_widgets/lv_objmask.h @@ -30,11 +30,10 @@ extern "C" { typedef struct { void * param; -}lv_objmask_mask_t; +} lv_objmask_mask_t; /*Data of object mask*/ -typedef struct -{ +typedef struct { lv_cont_ext_t cont; /*Ext. of ancestor*/ /*New data for this type */ lv_ll_t mask_ll; /*Store the created masks*/ diff --git a/src/lv_widgets/lv_objx_templ.c b/src/lv_widgets/lv_objx_templ.c index aebefb4b9..d0c28984f 100644 --- a/src/lv_widgets/lv_objx_templ.c +++ b/src/lv_widgets/lv_objx_templ.c @@ -129,8 +129,10 @@ void lv_templ_set_style(lv_obj_t * templ, lv_templ_style_t type, const lv_style_ lv_templ_ext_t * ext = lv_obj_get_ext_attr(templ); switch(type) { - case LV_TEMPL_STYLE_X: break; - case LV_TEMPL_STYLE_Y: break; + case LV_TEMPL_STYLE_X: + break; + case LV_TEMPL_STYLE_Y: + break; } } @@ -156,9 +158,12 @@ lv_style_t * lv_templ_get_style(const lv_obj_t * templ, lv_templ_style_t type) lv_style_t * style = NULL; switch(type) { - case LV_TEMPL_STYLE_X: style = NULL; /*Replace NULL with a pointer to the style*/ - case LV_TEMPL_STYLE_Y: style = NULL; /*Replace NULL with a pointer to the style*/ - default: style = NULL; + case LV_TEMPL_STYLE_X: + style = NULL; /*Replace NULL with a pointer to the style*/ + case LV_TEMPL_STYLE_Y: + style = NULL; /*Replace NULL with a pointer to the style*/ + default: + style = NULL; } return style; diff --git a/src/lv_widgets/lv_objx_templ.h b/src/lv_widgets/lv_objx_templ.h index fa5a32cf1..7079291c8 100644 --- a/src/lv_widgets/lv_objx_templ.h +++ b/src/lv_widgets/lv_objx_templ.h @@ -34,8 +34,7 @@ extern "C" { * TYPEDEFS **********************/ /*Data of template*/ -typedef struct -{ +typedef struct { lv_ANCESTOR_ext_t ANCESTOR; /*Ext. of ancestor*/ /*New data for this type */ } lv_templ_ext_t; diff --git a/src/lv_widgets/lv_page.c b/src/lv_widgets/lv_page.c index fe7f24ec7..e0140bb48 100644 --- a/src/lv_widgets/lv_page.c +++ b/src/lv_widgets/lv_page.c @@ -32,8 +32,8 @@ #define LV_PAGE_END_ANIM_WAIT_TIME 300 #if LV_USE_ANIMATION == 0 -#undef LV_PAGE_DEF_ANIM_TIME -#define LV_PAGE_DEF_ANIM_TIME 0 /*No animation*/ + #undef LV_PAGE_DEF_ANIM_TIME + #define LV_PAGE_DEF_ANIM_TIME 0 /*No animation*/ #endif /********************** @@ -51,8 +51,8 @@ static lv_res_t lv_page_scrollable_signal(lv_obj_t * scrl, lv_signal_t sign, voi static void scrl_def_event_cb(lv_obj_t * scrl, lv_event_t event); static void refr_ext_draw_pad(lv_obj_t * page); #if LV_USE_ANIMATION -static void edge_flash_anim(void * page, lv_anim_value_t v); -static void edge_flash_anim_end(lv_anim_t * a); + static void edge_flash_anim(void * page, lv_anim_value_t v); + static void edge_flash_anim_end(lv_anim_t * a); #endif /********************** @@ -125,7 +125,7 @@ lv_obj_t * lv_page_create(lv_obj_t * par, const lv_obj_t * copy) lv_obj_set_signal_cb(ext->scrl, lv_page_scrollable_signal); /* Add the signal function only if 'scrolling' is created -+ * because everything has to be ready before any signal is received*/ + + * because everything has to be ready before any signal is received*/ lv_obj_set_signal_cb(page, lv_page_signal); lv_obj_set_design_cb(page, lv_page_design); @@ -133,7 +133,8 @@ lv_obj_t * lv_page_create(lv_obj_t * par, const lv_obj_t * copy) lv_theme_apply(page, LV_THEME_PAGE); - } else { + } + else { lv_page_ext_t * copy_ext = lv_obj_get_ext_attr(copy); ext->scrl = lv_cont_create(page, copy_ext->scrl); lv_obj_set_signal_cb(ext->scrl, lv_page_scrollable_signal); @@ -143,9 +144,9 @@ lv_obj_t * lv_page_create(lv_obj_t * par, const lv_obj_t * copy) lv_obj_set_signal_cb(page, lv_page_signal); lv_obj_set_design_cb(page, lv_page_design); -// lv_page_set_style(new_page, LV_PAGE_STYLE_BG, lv_page_get_style(copy, LV_PAGE_STYLE_BG)); -// lv_page_set_style(new_page, LV_PAGE_STYLE_SCRL, lv_page_get_style(copy, LV_PAGE_STYLE_SCRL)); -// lv_page_set_style(new_page, LV_PAGE_STYLE_SCRLBAR, lv_page_get_style(copy, LV_PAGE_STYLE_SCRLBAR)); + // lv_page_set_style(new_page, LV_PAGE_STYLE_BG, lv_page_get_style(copy, LV_PAGE_STYLE_BG)); + // lv_page_set_style(new_page, LV_PAGE_STYLE_SCRL, lv_page_get_style(copy, LV_PAGE_STYLE_SCRL)); + // lv_page_set_style(new_page, LV_PAGE_STYLE_SCRLBAR, lv_page_get_style(copy, LV_PAGE_STYLE_SCRLBAR)); lv_page_set_sb_mode(page, copy_ext->scrlbar.mode); } @@ -497,7 +498,8 @@ void lv_page_focus(lv_obj_t * page, const lv_obj_t * obj, lv_anim_enable_t anim_ if(anim_en == LV_ANIM_OFF || lv_page_get_anim_time(page) == 0) { lv_obj_set_y(ext->scrl, scrlable_y); lv_obj_set_x(ext->scrl, scrlable_x); - } else { + } + else { #if LV_USE_ANIMATION lv_anim_t a; lv_anim_init(&a); @@ -589,10 +591,18 @@ void lv_page_start_edge_flash(lv_obj_t * page, lv_page_edge_t edge) lv_anim_start(&a); switch(edge) { - case LV_PAGE_EDGE_BOTTOM: ext->edge_flash.bottom_ip = 1; break; - case LV_PAGE_EDGE_TOP: ext->edge_flash.top_ip = 1; break; - case LV_PAGE_EDGE_LEFT: ext->edge_flash.left_ip = 1; break; - case LV_PAGE_EDGE_RIGHT: ext->edge_flash.right_ip = 1; break; + case LV_PAGE_EDGE_BOTTOM: + ext->edge_flash.bottom_ip = 1; + break; + case LV_PAGE_EDGE_TOP: + ext->edge_flash.top_ip = 1; + break; + case LV_PAGE_EDGE_LEFT: + ext->edge_flash.left_ip = 1; + break; + case LV_PAGE_EDGE_RIGHT: + ext->edge_flash.right_ip = 1; + break; } #else @@ -622,7 +632,8 @@ static lv_design_res_t lv_page_design(lv_obj_t * page, const lv_area_t * clip_ar if(mode == LV_DESIGN_DRAW_MAIN) { return ancestor_design(page, clip_area, mode); - } else if(mode == LV_DESIGN_DRAW_POST) { + } + else if(mode == LV_DESIGN_DRAW_POST) { ancestor_design(page, clip_area, mode); lv_page_ext_t * ext = lv_obj_get_ext_attr(page); @@ -630,75 +641,78 @@ static lv_design_res_t lv_page_design(lv_obj_t * page, const lv_area_t * clip_ar lv_area_t sb_ver_area; /*Convert the relative coordinates to absolute*/ lv_area_copy(&sb_hor_area, &ext->scrlbar.hor_area); - sb_hor_area.x1 += page->coords.x1; - sb_hor_area.y1 += page->coords.y1; - sb_hor_area.x2 += page->coords.x1; - sb_hor_area.y2 += page->coords.y1; + sb_hor_area.x1 += page->coords.x1; + sb_hor_area.y1 += page->coords.y1; + sb_hor_area.x2 += page->coords.x1; + sb_hor_area.y2 += page->coords.y1; /*Convert the relative coordinates to absolute*/ lv_area_copy(&sb_ver_area, &ext->scrlbar.ver_area); - sb_ver_area.x1 += page->coords.x1; - sb_ver_area.y1 += page->coords.y1; - sb_ver_area.x2 += page->coords.x1; - sb_ver_area.y2 += page->coords.y1; + sb_ver_area.x1 += page->coords.x1; + sb_ver_area.y1 += page->coords.y1; + sb_ver_area.x2 += page->coords.x1; + sb_ver_area.y2 += page->coords.y1; - if((ext->scrlbar.hor_draw && lv_area_is_on(&sb_hor_area, clip_area)) || - (ext->scrlbar.ver_draw && lv_area_is_on(&sb_ver_area, clip_area))) { - /*Draw the scrollbars*/ - lv_draw_rect_dsc_t rect_dsc; - lv_draw_rect_dsc_init(&rect_dsc); - lv_obj_init_draw_rect_dsc(page, LV_PAGE_PART_SCRLBAR, &rect_dsc); - if(ext->scrlbar.hor_draw && (ext->scrlbar.mode & LV_SB_MODE_HIDE) == 0) { - lv_draw_rect(&sb_hor_area, clip_area, &rect_dsc); - } + if((ext->scrlbar.hor_draw && lv_area_is_on(&sb_hor_area, clip_area)) || + (ext->scrlbar.ver_draw && lv_area_is_on(&sb_ver_area, clip_area))) { + /*Draw the scrollbars*/ + lv_draw_rect_dsc_t rect_dsc; + lv_draw_rect_dsc_init(&rect_dsc); + lv_obj_init_draw_rect_dsc(page, LV_PAGE_PART_SCRLBAR, &rect_dsc); + if(ext->scrlbar.hor_draw && (ext->scrlbar.mode & LV_SB_MODE_HIDE) == 0) { + lv_draw_rect(&sb_hor_area, clip_area, &rect_dsc); + } - if(ext->scrlbar.ver_draw && (ext->scrlbar.mode & LV_SB_MODE_HIDE) == 0) { - lv_draw_rect(&sb_ver_area, clip_area, &rect_dsc); - } - } + if(ext->scrlbar.ver_draw && (ext->scrlbar.mode & LV_SB_MODE_HIDE) == 0) { + lv_draw_rect(&sb_ver_area, clip_area, &rect_dsc); + } + } #if LV_USE_ANIMATION - { - lv_coord_t page_w = lv_obj_get_width(page); - lv_coord_t page_h = lv_obj_get_height(page); + { + lv_coord_t page_w = lv_obj_get_width(page); + lv_coord_t page_h = lv_obj_get_height(page); - lv_area_t flash_area; + lv_area_t flash_area; - if(ext->edge_flash.top_ip) { - flash_area.x1 = page->coords.x1 - page_w; - flash_area.x2 = page->coords.x2 + page_w; - flash_area.y1 = page->coords.y1 - 3 * page_w + ext->edge_flash.state; - flash_area.y2 = page->coords.y1 + ext->edge_flash.state; - } else if(ext->edge_flash.bottom_ip) { - flash_area.x1 = page->coords.x1 - page_w; - flash_area.x2 = page->coords.x2 + page_w; - flash_area.y1 = page->coords.y2 - ext->edge_flash.state; - flash_area.y2 = page->coords.y2 + 3 * page_w - ext->edge_flash.state; - } else if(ext->edge_flash.right_ip) { - flash_area.x1 = page->coords.x2 - ext->edge_flash.state; - flash_area.x2 = page->coords.x2 + 3 * page_h - ext->edge_flash.state; - flash_area.y1 = page->coords.y1 - page_h; - flash_area.y2 = page->coords.y2 + page_h; - } else if(ext->edge_flash.left_ip) { - flash_area.x1 = page->coords.x1 - 3 * page_h + ext->edge_flash.state; - flash_area.x2 = page->coords.x1 + ext->edge_flash.state; - flash_area.y1 = page->coords.y1 - page_h; - flash_area.y2 = page->coords.y2 + page_h; - } + if(ext->edge_flash.top_ip) { + flash_area.x1 = page->coords.x1 - page_w; + flash_area.x2 = page->coords.x2 + page_w; + flash_area.y1 = page->coords.y1 - 3 * page_w + ext->edge_flash.state; + flash_area.y2 = page->coords.y1 + ext->edge_flash.state; + } + else if(ext->edge_flash.bottom_ip) { + flash_area.x1 = page->coords.x1 - page_w; + flash_area.x2 = page->coords.x2 + page_w; + flash_area.y1 = page->coords.y2 - ext->edge_flash.state; + flash_area.y2 = page->coords.y2 + 3 * page_w - ext->edge_flash.state; + } + else if(ext->edge_flash.right_ip) { + flash_area.x1 = page->coords.x2 - ext->edge_flash.state; + flash_area.x2 = page->coords.x2 + 3 * page_h - ext->edge_flash.state; + flash_area.y1 = page->coords.y1 - page_h; + flash_area.y2 = page->coords.y2 + page_h; + } + else if(ext->edge_flash.left_ip) { + flash_area.x1 = page->coords.x1 - 3 * page_h + ext->edge_flash.state; + flash_area.x2 = page->coords.x1 + ext->edge_flash.state; + flash_area.y1 = page->coords.y1 - page_h; + flash_area.y2 = page->coords.y2 + page_h; + } - if(ext->edge_flash.left_ip || ext->edge_flash.right_ip || ext->edge_flash.top_ip || - ext->edge_flash.bottom_ip) { - lv_draw_rect_dsc_t edge_draw_dsc; - lv_draw_rect_dsc_init(&edge_draw_dsc); - lv_obj_init_draw_rect_dsc(page, LV_PAGE_PART_EDGE_FLASH, &edge_draw_dsc); - edge_draw_dsc.radius = LV_RADIUS_CIRCLE; - uint32_t opa = (edge_draw_dsc.bg_opa * ext->edge_flash.state) / LV_PAGE_END_FLASH_SIZE; - edge_draw_dsc.bg_opa = opa; - lv_draw_rect(&flash_area, clip_area, &edge_draw_dsc); - } - } + if(ext->edge_flash.left_ip || ext->edge_flash.right_ip || ext->edge_flash.top_ip || + ext->edge_flash.bottom_ip) { + lv_draw_rect_dsc_t edge_draw_dsc; + lv_draw_rect_dsc_init(&edge_draw_dsc); + lv_obj_init_draw_rect_dsc(page, LV_PAGE_PART_EDGE_FLASH, &edge_draw_dsc); + edge_draw_dsc.radius = LV_RADIUS_CIRCLE; + uint32_t opa = (edge_draw_dsc.bg_opa * ext->edge_flash.state) / LV_PAGE_END_FLASH_SIZE; + edge_draw_dsc.bg_opa = opa; + lv_draw_rect(&flash_area, clip_area, &edge_draw_dsc); + } + } #endif - } + } return LV_DESIGN_RES_OK; } @@ -718,7 +732,8 @@ static lv_res_t lv_page_signal(lv_obj_t * page, lv_signal_t sign, void * param) info->result = lv_page_get_style(page, info->part); if(info->result != NULL) return LV_RES_OK; else return ancestor_signal(page, sign, param); - } else if(sign == LV_SIGNAL_GET_STATE_DSC) { + } + else if(sign == LV_SIGNAL_GET_STATE_DSC) { lv_get_state_info_t * info = param; if(info->part == LV_PAGE_PART_SCRL) info->result = lv_obj_get_state(lv_page_get_scrl(page), LV_CONT_PART_MAIN); else info->result = lv_obj_get_state(page, info->part); @@ -769,8 +784,8 @@ static lv_res_t lv_page_signal(lv_obj_t * page, lv_signal_t sign, void * param) /* Reposition the child to take padding into account (Only if it's on (0;0) or (widht;height) coordinates now) * It's required to keep new the object on the same coordinate if FIT is enabled.*/ if((tmp->coords.x1 == page->coords.x1) && - (fit_left == LV_FIT_TIGHT || fit_left == LV_FIT_MAX) && - base_dir != LV_BIDI_DIR_RTL) { + (fit_left == LV_FIT_TIGHT || fit_left == LV_FIT_MAX) && + base_dir != LV_BIDI_DIR_RTL) { tmp->coords.x1 += scrl_left; tmp->coords.x2 += scrl_left; } @@ -785,11 +800,13 @@ static lv_res_t lv_page_signal(lv_obj_t * page, lv_signal_t sign, void * param) tmp->coords.y2 += scrl_top; } lv_obj_set_parent(tmp, ext->scrl); - } else { + } + else { child = lv_obj_get_child(page, child); } } - } else if(sign == LV_SIGNAL_STYLE_CHG) { + } + else if(sign == LV_SIGNAL_STYLE_CHG) { ext->scrl->signal_cb(ext->scrl, LV_SIGNAL_COORD_CHG, &ext->scrl->coords); lv_style_int_t sb_width = lv_obj_get_style_size(page, LV_PAGE_PART_SCRLBAR); @@ -801,7 +818,8 @@ static lv_res_t lv_page_signal(lv_obj_t * page, lv_signal_t sign, void * param) /*Refresh the ext. size because the scrollbars might be positioned out of the page*/ refr_ext_draw_pad(page); - } else if(sign == LV_SIGNAL_COORD_CHG) { + } + else if(sign == LV_SIGNAL_COORD_CHG) { /*Refresh the scrollbar and notify the scrl if the size is changed*/ if(ext->scrl != NULL && (lv_obj_get_width(page) != lv_area_get_width(param) || lv_obj_get_height(page) != lv_area_get_height(param))) { @@ -811,23 +829,28 @@ static lv_res_t lv_page_signal(lv_obj_t * page, lv_signal_t sign, void * param) /*The scrollbars are important only if they are visible now*/ if(ext->scrlbar.hor_draw || ext->scrlbar.ver_draw) lv_page_sb_refresh(page); } - } else if(sign == LV_SIGNAL_REFR_EXT_DRAW_PAD) { + } + else if(sign == LV_SIGNAL_REFR_EXT_DRAW_PAD) { refr_ext_draw_pad(page); - } else if(sign == LV_SIGNAL_CONTROL) { + } + else if(sign == LV_SIGNAL_CONTROL) { uint32_t c = *((uint32_t *)param); if(c == LV_KEY_DOWN) { lv_page_scroll_ver(page, -lv_obj_get_height(page) / 4); - } else if(c == LV_KEY_UP) { + } + else if(c == LV_KEY_UP) { lv_page_scroll_ver(page, lv_obj_get_height(page) / 4); - } else if(c == LV_KEY_RIGHT) { + } + else if(c == LV_KEY_RIGHT) { /*If the page can't be scrolled horizontally because it's not wide enough then scroll it * vertically*/ if(lv_page_get_scrl_width(page) <= lv_obj_get_width(page)) lv_page_scroll_ver(page, -lv_obj_get_height(page) / 4); else lv_page_scroll_hor(page, -lv_obj_get_width(page) / 4); - } else if(c == LV_KEY_LEFT) { + } + else if(c == LV_KEY_LEFT) { /*If the page can't be scrolled horizontally because it's not wide enough then scroll it * vertically*/ if(lv_page_get_scrl_width(page) <= lv_obj_get_width(page)) @@ -835,7 +858,8 @@ static lv_res_t lv_page_signal(lv_obj_t * page, lv_signal_t sign, void * param) else lv_page_scroll_hor(page, lv_obj_get_width(page) / 4); } - } else if(sign == LV_SIGNAL_GET_EDITABLE) { + } + else if(sign == LV_SIGNAL_GET_EDITABLE) { bool * editable = (bool *)param; *editable = true; } @@ -893,14 +917,14 @@ static lv_res_t lv_page_scrollable_signal(lv_obj_t * scrl, lv_signal_t sign, voi if((lv_indev_is_dragging(indev) == false || page_ext->scroll_prop_obj) && (drag_sum->y || drag_sum->x)) { /*Propagate vertically?*/ if((drag_sum->y > 0 && lv_page_on_edge(page, LV_PAGE_EDGE_TOP)) || - (drag_sum->y < 0 && lv_page_on_edge(page, LV_PAGE_EDGE_BOTTOM))) { + (drag_sum->y < 0 && lv_page_on_edge(page, LV_PAGE_EDGE_BOTTOM))) { lv_obj_set_drag_parent(page, true); lv_obj_set_drag_parent(scrl, true); parent_ext->scroll_prop_obj = page; } /*Propagate horizontally?*/ if((drag_sum->x > 0 && lv_page_on_edge(page, LV_PAGE_EDGE_LEFT)) || - (drag_sum->x < 0 && lv_page_on_edge(page, LV_PAGE_EDGE_RIGHT))) { + (drag_sum->x < 0 && lv_page_on_edge(page, LV_PAGE_EDGE_RIGHT))) { lv_obj_set_drag_parent(page, true); lv_obj_set_drag_parent(scrl, true); parent_ext->scroll_prop_obj = page; @@ -915,18 +939,20 @@ static lv_res_t lv_page_scrollable_signal(lv_obj_t * scrl, lv_signal_t sign, voi lv_style_int_t bottom = lv_obj_get_style_pad_bottom(page, LV_PAGE_PART_BG); /*scrollable width smaller then page width? -> align to left*/ - if(lv_area_get_width(&scrl_coords) + left +right <= lv_area_get_width(&page_coords)) { + if(lv_area_get_width(&scrl_coords) + left + right <= lv_area_get_width(&page_coords)) { if(scrl_coords.x1 != page_coords.x1 + left) { new_x = left; refr_x = true; } - } else { + } + else { /*The edges of the scrollable can not be in the page (minus hpad) */ if(scrl_coords.x2 < page_coords.x2 - right) { new_x = lv_area_get_width(&page_coords) - lv_area_get_width(&scrl_coords) - right; /* Right align */ refr_x = true; lv_page_start_edge_flash(page, LV_PAGE_EDGE_RIGHT); - } else if(scrl_coords.x1 > page_coords.x1 + left) { + } + else if(scrl_coords.x1 > page_coords.x1 + left) { new_x = left; /*Left align*/ refr_x = true; lv_page_start_edge_flash(page, LV_PAGE_EDGE_LEFT); @@ -939,13 +965,15 @@ static lv_res_t lv_page_scrollable_signal(lv_obj_t * scrl, lv_signal_t sign, voi new_y = top; refr_y = true; } - } else { + } + else { /*The edges of the scrollable can not be in the page (minus vpad) */ if(scrl_coords.y2 < page_coords.y2 - bottom) { new_y = lv_area_get_height(&page_coords) - lv_area_get_height(&scrl_coords) - bottom; /* Bottom align */ refr_y = true; lv_page_start_edge_flash(page, LV_PAGE_EDGE_BOTTOM); - } else if(scrl_coords.y1 > page_coords.y1 + top) { + } + else if(scrl_coords.y1 > page_coords.y1 + top) { new_y = top; /*Top align*/ refr_y = true; lv_page_start_edge_flash(page, LV_PAGE_EDGE_TOP); @@ -957,7 +985,8 @@ static lv_res_t lv_page_scrollable_signal(lv_obj_t * scrl, lv_signal_t sign, voi } lv_page_sb_refresh(page); - } else if(sign == LV_SIGNAL_DRAG_END) { + } + else if(sign == LV_SIGNAL_DRAG_END) { /*Scroll propagation is finished on drag end*/ if(page_ext->scroll_prop_obj) { @@ -1000,12 +1029,14 @@ static lv_res_t lv_page_scrollable_signal(lv_obj_t * scrl, lv_signal_t sign, voi page_ext->scrlbar.ver_draw = 0; } } - } else if(sign == LV_SIGNAL_FOCUS) { + } + else if(sign == LV_SIGNAL_FOCUS) { res = lv_signal_send(page, LV_SIGNAL_FOCUS, NULL); if(res != LV_RES_OK) return res; res = lv_event_send(page, LV_EVENT_FOCUSED, NULL); if(res != LV_RES_OK) return res; - } else if(sign == LV_SIGNAL_DEFOCUS) { + } + else if(sign == LV_SIGNAL_DEFOCUS) { res = lv_signal_send(page, LV_SIGNAL_DEFOCUS, NULL); if(res != LV_RES_OK) return res; res = lv_event_send(page, LV_EVENT_DEFOCUSED, NULL); @@ -1053,22 +1084,22 @@ static lv_style_list_t * lv_page_get_style(lv_obj_t * page, uint8_t part) lv_style_list_t * style_dsc_p; switch(part) { - case LV_PAGE_PART_BG: - style_dsc_p = &page->style_list; - break; - case LV_PAGE_PART_SCRL: - style_dsc_p = lv_obj_get_style_list(ext->scrl, LV_CONT_PART_MAIN); - break; - case LV_PAGE_PART_SCRLBAR: - style_dsc_p = &ext->scrlbar.style; - break; + case LV_PAGE_PART_BG: + style_dsc_p = &page->style_list; + break; + case LV_PAGE_PART_SCRL: + style_dsc_p = lv_obj_get_style_list(ext->scrl, LV_CONT_PART_MAIN); + break; + case LV_PAGE_PART_SCRLBAR: + style_dsc_p = &ext->scrlbar.style; + break; #if LV_USE_ANIMATION - case LV_PAGE_PART_EDGE_FLASH: - style_dsc_p = &ext->edge_flash.style; - break; + case LV_PAGE_PART_EDGE_FLASH: + style_dsc_p = &ext->edge_flash.style; + break; #endif - default: - style_dsc_p = NULL; + default: + style_dsc_p = NULL; } return style_dsc_p; @@ -1153,8 +1184,8 @@ static void lv_page_sb_refresh(lv_obj_t * page) lv_area_set_pos(&ext->scrlbar.hor_area, sb_hor_pad + - (-(lv_obj_get_x(scrl) -bg_left) * (obj_w - size_tmp - 2 * sb_hor_pad)) / - (scrl_w + bg_left + bg_right - obj_w), + (-(lv_obj_get_x(scrl) - bg_left) * (obj_w - size_tmp - 2 * sb_hor_pad)) / + (scrl_w + bg_left + bg_right - obj_w), obj_h - sb_width - sb_bottom); if(ext->scrlbar.mode == LV_SB_MODE_AUTO || ext->scrlbar.mode == LV_SB_MODE_DRAG) ext->scrlbar.hor_draw = 1; @@ -1178,7 +1209,7 @@ static void lv_page_sb_refresh(lv_obj_t * page) obj_w - sb_width - sb_right, sb_ver_pad + (-(lv_obj_get_y(scrl) - bg_left) * (obj_h - size_tmp - 2 * sb_ver_pad)) / - (scrl_h + bg_top + bg_bottom - obj_h)); + (scrl_h + bg_top + bg_bottom - obj_h)); if(ext->scrlbar.mode == LV_SB_MODE_AUTO || ext->scrlbar.mode == LV_SB_MODE_DRAG) ext->scrlbar.ver_draw = 1; } diff --git a/src/lv_widgets/lv_page.h b/src/lv_widgets/lv_page.h index 8dbbe159b..04f2ca2f2 100644 --- a/src/lv_widgets/lv_page.h +++ b/src/lv_widgets/lv_page.h @@ -50,13 +50,11 @@ enum { LV_PAGE_EDGE_LEFT = 0x1, LV_PAGE_EDGE_TOP = 0x2, LV_PAGE_EDGE_RIGHT = 0x4 typedef uint8_t lv_page_edge_t; /*Data of page*/ -typedef struct -{ +typedef struct { lv_cont_ext_t bg; /*Ext. of ancestor*/ /*New data for this type */ lv_obj_t * scrl; /*The scrollable object on the background*/ - struct - { + struct { lv_style_list_t style; /*Style of scrollbars*/ lv_area_t hor_area; /*Horizontal scrollbar area relative to the page. (Handled by the library) */ lv_area_t ver_area; /*Vertical scrollbar area relative to the page (Handled by the library)*/ @@ -65,8 +63,7 @@ typedef struct lv_sb_mode_t mode : 3; /*Scrollbar visibility from 'lv_page_sb_mode_t'*/ } scrlbar; #if LV_USE_ANIMATION - struct - { + struct { lv_anim_value_t state; /*Store the current size of the edge flash effect*/ lv_style_list_t style; /*Style of edge flash effect (usually homogeneous circle)*/ uint8_t enabled : 1; /*1: Show a flash animation on the edge*/ @@ -83,7 +80,7 @@ typedef struct uint16_t anim_time; /*Scroll animation time*/ #endif lv_obj_t * scroll_prop_obj; /*Pointer to child page from where the scroll is being propagated */ - uint8_t scroll_prop :1; /*The direction of the scroll propagation*/ + uint8_t scroll_prop : 1; /*The direction of the scroll propagation*/ } lv_page_ext_t; enum { diff --git a/src/lv_widgets/lv_roller.c b/src/lv_widgets/lv_roller.c index 717d0029d..8612bc123 100644 --- a/src/lv_widgets/lv_roller.c +++ b/src/lv_widgets/lv_roller.c @@ -20,8 +20,8 @@ #define LV_OBJX_NAME "lv_roller" #if LV_USE_ANIMATION == 0 -#undef LV_ROLLER_DEF_ANIM_TIME -#define LV_ROLLER_DEF_ANIM_TIME 0 /*No animation*/ + #undef LV_ROLLER_DEF_ANIM_TIME + #define LV_ROLLER_DEF_ANIM_TIME 0 /*No animation*/ #endif /********************** @@ -42,7 +42,7 @@ static lv_res_t release_handler(lv_obj_t * roller); static void inf_normalize(void * roller_scrl); static lv_obj_t * get_label(const lv_obj_t * roller); #if LV_USE_ANIMATION -static void scroll_anim_ready_cb(lv_anim_t * a); + static void scroll_anim_ready_cb(lv_anim_t * a); #endif static void draw_bg(lv_obj_t * roller, const lv_area_t * clip_area); @@ -163,7 +163,8 @@ void lv_roller_set_options(lv_obj_t * roller, const char * options, lv_roller_mo if(mode == LV_ROLLER_MODE_NORMAL) { ext->mode = LV_ROLLER_MODE_NORMAL; lv_label_set_text(label, options); - } else { + } + else { ext->mode = LV_ROLLER_MODE_INIFINITE; size_t opt_len = strlen(options) + 1; /*+1 to add '\n' after option lists*/ @@ -264,7 +265,8 @@ uint16_t lv_roller_get_selected(const lv_obj_t * roller) if(ext->mode == LV_ROLLER_MODE_INIFINITE) { uint16_t real_id_cnt = ext->option_cnt / LV_ROLLER_INF_PAGES; return ext->sel_opt_id % real_id_cnt; - } else { + } + else { return ext->sel_opt_id; } } @@ -315,7 +317,8 @@ uint16_t lv_roller_get_option_cnt(const lv_obj_t * roller) lv_roller_ext_t * ext = lv_obj_get_ext_attr(roller); if(ext->mode == LV_ROLLER_MODE_INIFINITE) { return ext->option_cnt / LV_ROLLER_INF_PAGES; - } else { + } + else { return ext->option_cnt; } } @@ -413,7 +416,8 @@ static lv_design_res_t lv_roller_design(lv_obj_t * roller, const lv_area_t * cli if(LV_LABEL_ALIGN_CENTER == label_align) { label_dsc.flag |= LV_TXT_FLAG_CENTER; - } else if(LV_LABEL_ALIGN_RIGHT == label_align) { + } + else if(LV_LABEL_ALIGN_RIGHT == label_align) { label_dsc.flag |= LV_TXT_FLAG_RIGHT; } @@ -456,7 +460,8 @@ static lv_res_t lv_roller_signal(lv_obj_t * roller, lv_signal_t sign, void * par refr_height(roller); refr_width(roller); refr_position(roller, false); - } else if(sign == LV_SIGNAL_COORD_CHG) { + } + else if(sign == LV_SIGNAL_COORD_CHG) { if(lv_obj_get_width(roller) != lv_area_get_width(param) || lv_obj_get_height(roller) != lv_area_get_height(param)) { @@ -465,9 +470,11 @@ static lv_res_t lv_roller_signal(lv_obj_t * roller, lv_signal_t sign, void * par #endif refr_position(roller, false); } - } else if(sign == LV_SIGNAL_RELEASED) { + } + else if(sign == LV_SIGNAL_RELEASED) { release_handler(roller); - } else if(sign == LV_SIGNAL_FOCUS) { + } + else if(sign == LV_SIGNAL_FOCUS) { #if LV_USE_GROUP lv_group_t * g = lv_obj_get_group(roller); bool editing = lv_group_get_editing(g); @@ -486,12 +493,14 @@ static lv_res_t lv_roller_signal(lv_obj_t * roller, lv_signal_t sign, void * par else { ext->sel_opt_id_ori = ext->sel_opt_id; } - } else { + } + else { ext->sel_opt_id_ori = ext->sel_opt_id; /*Save the current value. Used to revert this state if ENER wont't be pressed*/ } #endif - } else if(sign == LV_SIGNAL_DEFOCUS) { + } + else if(sign == LV_SIGNAL_DEFOCUS) { #if LV_USE_GROUP /*Revert the original state*/ if(ext->sel_opt_id != ext->sel_opt_id_ori) { @@ -499,7 +508,8 @@ static lv_res_t lv_roller_signal(lv_obj_t * roller, lv_signal_t sign, void * par refr_position(roller, true); } #endif - } else if(sign == LV_SIGNAL_CONTROL) { + } + else if(sign == LV_SIGNAL_CONTROL) { char c = *((char *)param); if(c == LV_KEY_RIGHT || c == LV_KEY_DOWN) { if(ext->sel_opt_id + 1 < ext->option_cnt) { @@ -507,7 +517,8 @@ static lv_res_t lv_roller_signal(lv_obj_t * roller, lv_signal_t sign, void * par lv_roller_set_selected(roller, ext->sel_opt_id + 1, true); ext->sel_opt_id_ori = ori_id; } - } else if(c == LV_KEY_LEFT || c == LV_KEY_UP) { + } + else if(c == LV_KEY_LEFT || c == LV_KEY_UP) { if(ext->sel_opt_id > 0) { uint16_t ori_id = ext->sel_opt_id_ori; /*lv_roller_set_selceted will overwrite this*/ lv_roller_set_selected(roller, ext->sel_opt_id - 1, true); @@ -516,7 +527,7 @@ static lv_res_t lv_roller_signal(lv_obj_t * roller, lv_signal_t sign, void * par } } else if(sign == LV_SIGNAL_CLEANUP) { - lv_obj_clean_style_list(roller, LV_ROLLER_PART_SEL); + lv_obj_clean_style_list(roller, LV_ROLLER_PART_SEL); } return res; } @@ -535,14 +546,14 @@ static lv_style_list_t * lv_roller_get_style(lv_obj_t * roller, uint8_t part) lv_style_list_t * style_dsc_p; switch(part) { - case LV_ROLLER_PART_BG: - style_dsc_p = &roller->style_list; - break; - case LV_ROLLER_PART_SEL: - style_dsc_p = &ext->style_sel; - break; - default: - style_dsc_p = NULL; + case LV_ROLLER_PART_BG: + style_dsc_p = &roller->style_list; + break; + case LV_ROLLER_PART_SEL: + style_dsc_p = &ext->style_sel; + break; + default: + style_dsc_p = NULL; } return style_dsc_p; @@ -595,8 +606,9 @@ static lv_res_t lv_roller_scrl_signal(lv_obj_t * roller_scrl, lv_signal_t sign, } /*If picked an option by clicking then set it*/ else if(sign == LV_SIGNAL_RELEASED) { - release_handler(roller); - } else if(sign == LV_SIGNAL_PRESSED) { + release_handler(roller); + } + else if(sign == LV_SIGNAL_PRESSED) { #if LV_USE_ANIMATION lv_anim_del(roller_scrl, (lv_anim_exec_xcb_t)lv_obj_set_y); #endif @@ -701,7 +713,8 @@ static void refr_position(lv_obj_t * roller, lv_anim_enable_t anim_en) lv_anim_del(roller_scrl, (lv_anim_exec_xcb_t)lv_obj_set_y); #endif lv_obj_set_y(roller_scrl, new_y); - } else { + } + else { #if LV_USE_ANIMATION lv_anim_t a; lv_anim_init(&a); diff --git a/src/lv_widgets/lv_roller.h b/src/lv_widgets/lv_roller.h index c7760bbf9..f9da7e431 100644 --- a/src/lv_widgets/lv_roller.h +++ b/src/lv_widgets/lv_roller.h @@ -45,8 +45,7 @@ typedef uint8_t lv_roller_mode_t; /*Data of roller*/ -typedef struct -{ +typedef struct { lv_page_ext_t page; /*Ext. of ancestor*/ /*New data for this type */ diff --git a/src/lv_widgets/lv_slider.c b/src/lv_widgets/lv_slider.c index a44cd3b97..58a8db97b 100644 --- a/src/lv_widgets/lv_slider.c +++ b/src/lv_widgets/lv_slider.c @@ -181,42 +181,47 @@ static lv_design_res_t lv_slider_design(lv_obj_t * slider, const lv_area_t * cli if(hor) { if(!sym) { knob_area.x1 = ext->bar.indic_area.x2; - } else { + } + else { if(ext->bar.cur_value >= 0) { knob_area.x1 = ext->bar.indic_area.x2; - } else { + } + else { knob_area.x1 = ext->bar.indic_area.x1; } } } /*Vertical*/ else { - if(!sym) { - knob_area.y1 = ext->bar.indic_area.y1; - } else { - if(ext->bar.cur_value >= 0) { - knob_area.y1 = ext->bar.indic_area.y1; - } else { - knob_area.y1 = ext->bar.indic_area.y2; - } - } + if(!sym) { + knob_area.y1 = ext->bar.indic_area.y1; + } + else { + if(ext->bar.cur_value >= 0) { + knob_area.y1 = ext->bar.indic_area.y1; + } + else { + knob_area.y1 = ext->bar.indic_area.y2; + } + } } - lv_slider_position_knob(slider, &knob_area, knob_size, hor); + lv_slider_position_knob(slider, &knob_area, knob_size, hor); - lv_area_copy(&ext->right_knob_area, &knob_area); + lv_area_copy(&ext->right_knob_area, &knob_area); lv_slider_draw_knob(slider, &knob_area, clip_area); if(lv_slider_get_type(slider) == LV_SLIDER_TYPE_RANGE) { - /* Draw a second knob for the start_value side */ - if(hor) { + /* Draw a second knob for the start_value side */ + if(hor) { knob_area.x1 = ext->bar.indic_area.x1; - } else { - knob_area.y1 = ext->bar.indic_area.y1; - } - lv_slider_position_knob(slider, &knob_area, knob_size, hor); + } + else { + knob_area.y1 = ext->bar.indic_area.y1; + } + lv_slider_position_knob(slider, &knob_area, knob_size, hor); - lv_area_copy(&ext->left_knob_area, &knob_area); - lv_slider_draw_knob(slider, &knob_area, clip_area); + lv_area_copy(&ext->left_knob_area, &knob_area); + lv_slider_draw_knob(slider, &knob_area, clip_area); } } /*Post draw when the children are drawn*/ @@ -257,7 +262,8 @@ static lv_res_t lv_slider_signal(lv_obj_t * slider, lv_signal_t sign, void * par ext->dragging = true; if(lv_slider_get_type(slider) == LV_SLIDER_TYPE_NORMAL) { ext->value_to_set = &ext->bar.cur_value; - } else if(lv_slider_get_type(slider) == LV_SLIDER_TYPE_RANGE) { + } + else if(lv_slider_get_type(slider) == LV_SLIDER_TYPE_RANGE) { lv_indev_get_point(param, &p); bool hor = lv_obj_get_width(slider) >= lv_obj_get_height(slider); @@ -268,25 +274,28 @@ static lv_res_t lv_slider_signal(lv_obj_t * slider, lv_signal_t sign, void * par } else if(p.x < ext->left_knob_area.x1) { ext->value_to_set = &ext->bar.start_value; - } else { + } + else { /* Calculate the distance from each knob */ - dist_left = LV_MATH_ABS((ext->left_knob_area.x1+(ext->left_knob_area.x2 - ext->left_knob_area.x1)/2) - p.x); - dist_right = LV_MATH_ABS((ext->right_knob_area.x1+(ext->right_knob_area.x2 - ext->right_knob_area.x1)/2) - p.x); + dist_left = LV_MATH_ABS((ext->left_knob_area.x1 + (ext->left_knob_area.x2 - ext->left_knob_area.x1) / 2) - p.x); + dist_right = LV_MATH_ABS((ext->right_knob_area.x1 + (ext->right_knob_area.x2 - ext->right_knob_area.x1) / 2) - p.x); /* Use whichever one is closer */ if(dist_right < dist_left)ext->value_to_set = &ext->bar.cur_value; else ext->value_to_set = &ext->bar.start_value; } - } else { + } + else { if(p.y < ext->right_knob_area.y1) { ext->value_to_set = &ext->bar.cur_value; } else if(p.y > ext->left_knob_area.y2) { ext->value_to_set = &ext->bar.start_value; - } else { + } + else { /* Calculate the distance from each knob */ - dist_left = LV_MATH_ABS((ext->left_knob_area.y1+(ext->left_knob_area.y2 - ext->left_knob_area.y1)/2) - p.y); - dist_right = LV_MATH_ABS((ext->right_knob_area.y1+(ext->right_knob_area.y2 - ext->right_knob_area.y1)/2) - p.y); + dist_left = LV_MATH_ABS((ext->left_knob_area.y1 + (ext->left_knob_area.y2 - ext->left_knob_area.y1) / 2) - p.y); + dist_right = LV_MATH_ABS((ext->right_knob_area.y1 + (ext->right_knob_area.y2 - ext->right_knob_area.y1) / 2) - p.y); /* Use whichever one is closer */ if(dist_right < dist_left)ext->value_to_set = &ext->bar.cur_value; @@ -294,7 +303,8 @@ static lv_res_t lv_slider_signal(lv_obj_t * slider, lv_signal_t sign, void * par } } } - } else if(sign == LV_SIGNAL_PRESSING && ext->value_to_set != NULL) { + } + else if(sign == LV_SIGNAL_PRESSING && ext->value_to_set != NULL) { lv_indev_get_point(param, &p); lv_coord_t w = lv_obj_get_width(slider); @@ -315,33 +325,36 @@ static lv_res_t lv_slider_signal(lv_obj_t * slider, lv_signal_t sign, void * par new_value = p.x - (slider->coords.x1 + bg_left); /*Make the point relative to the indicator*/ new_value = (new_value * range) / indic_w; new_value += ext->bar.min_value; - } else { - lv_coord_t indic_h = h - bg_bottom - bg_top; - new_value = p.y - (slider->coords.y2 + bg_bottom); /*Make the point relative to the indicator*/ - new_value = (-new_value * range) / indic_h; - new_value += ext->bar.min_value; + } + else { + lv_coord_t indic_h = h - bg_bottom - bg_top; + new_value = p.y - (slider->coords.y2 + bg_bottom); /*Make the point relative to the indicator*/ + new_value = (-new_value * range) / indic_h; + new_value += ext->bar.min_value; - } + } - /* Figure out the min. and max. for this mode */ - if(ext->value_to_set == &ext->bar.start_value) { - real_max_value = ext->bar.cur_value; - } else { - real_min_value = ext->bar.start_value; - } + /* Figure out the min. and max. for this mode */ + if(ext->value_to_set == &ext->bar.start_value) { + real_max_value = ext->bar.cur_value; + } + else { + real_min_value = ext->bar.start_value; + } - if(new_value < real_min_value) new_value = real_min_value; - else if(new_value > real_max_value) new_value = real_max_value; - if(*ext->value_to_set != new_value) { - *ext->value_to_set = new_value; - lv_obj_invalidate(slider); - res = lv_event_send(slider, LV_EVENT_VALUE_CHANGED, NULL); - if(res != LV_RES_OK) return res; - } + if(new_value < real_min_value) new_value = real_min_value; + else if(new_value > real_max_value) new_value = real_max_value; + if(*ext->value_to_set != new_value) { + *ext->value_to_set = new_value; + lv_obj_invalidate(slider); + res = lv_event_send(slider, LV_EVENT_VALUE_CHANGED, NULL); + if(res != LV_RES_OK) return res; + } - } else if(sign == LV_SIGNAL_RELEASED || sign == LV_SIGNAL_PRESS_LOST) { + } + else if(sign == LV_SIGNAL_RELEASED || sign == LV_SIGNAL_PRESS_LOST) { ext->dragging = false; - ext->value_to_set = NULL; + ext->value_to_set = NULL; #if LV_USE_GROUP /*Leave edit mode if released. (No need to wait for LONG_PRESS) */ @@ -353,14 +366,16 @@ static lv_res_t lv_slider_signal(lv_obj_t * slider, lv_signal_t sign, void * par } #endif - } else if(sign == LV_SIGNAL_COORD_CHG) { + } + else if(sign == LV_SIGNAL_COORD_CHG) { /* The knob size depends on slider size. * During the drawing method the ext. size is used by the knob so refresh the ext. size.*/ if(lv_obj_get_width(slider) != lv_area_get_width(param) || lv_obj_get_height(slider) != lv_area_get_height(param)) { slider->signal_cb(slider, LV_SIGNAL_REFR_EXT_DRAW_PAD, NULL); } - } else if(sign == LV_SIGNAL_REFR_EXT_DRAW_PAD) { + } + else if(sign == LV_SIGNAL_REFR_EXT_DRAW_PAD) { lv_style_int_t knob_left = lv_obj_get_style_pad_left(slider, LV_SLIDER_PART_KNOB); lv_style_int_t knob_right = lv_obj_get_style_pad_right(slider, LV_SLIDER_PART_KNOB); lv_style_int_t knob_top = lv_obj_get_style_pad_top(slider, LV_SLIDER_PART_KNOB); @@ -368,7 +383,7 @@ static lv_res_t lv_slider_signal(lv_obj_t * slider, lv_signal_t sign, void * par /* The smaller size is the knob diameter*/ lv_coord_t knob_size = LV_MATH_MIN(lv_obj_get_width(slider), lv_obj_get_height(slider)) >> 1; - knob_size += LV_MATH_MAX(LV_MATH_MAX(knob_left, knob_right), LV_MATH_MAX(knob_bottom,knob_top)); + knob_size += LV_MATH_MAX(LV_MATH_MAX(knob_left, knob_right), LV_MATH_MAX(knob_bottom, knob_top)); knob_size += 2; /*For rounding error*/ knob_size += lv_obj_get_draw_rect_ext_pad_size(slider, LV_SLIDER_PART_KNOB); @@ -376,21 +391,25 @@ static lv_res_t lv_slider_signal(lv_obj_t * slider, lv_signal_t sign, void * par /*Indic. size is handled by bar*/ slider->ext_draw_pad = LV_MATH_MAX(slider->ext_draw_pad, knob_size); - } else if(sign == LV_SIGNAL_CONTROL) { + } + else if(sign == LV_SIGNAL_CONTROL) { char c = *((char *)param); if(c == LV_KEY_RIGHT || c == LV_KEY_UP) { lv_slider_set_value(slider, lv_slider_get_value(slider) + 1, true); res = lv_event_send(slider, LV_EVENT_VALUE_CHANGED, NULL); if(res != LV_RES_OK) return res; - } else if(c == LV_KEY_LEFT || c == LV_KEY_DOWN) { + } + else if(c == LV_KEY_LEFT || c == LV_KEY_DOWN) { lv_slider_set_value(slider, lv_slider_get_value(slider) - 1, true); res = lv_event_send(slider, LV_EVENT_VALUE_CHANGED, NULL); if(res != LV_RES_OK) return res; } - } else if(sign == LV_SIGNAL_CLEANUP) { + } + else if(sign == LV_SIGNAL_CLEANUP) { lv_obj_clean_style_list(slider, LV_SLIDER_PART_KNOB); - } else if(sign == LV_SIGNAL_GET_EDITABLE) { + } + else if(sign == LV_SIGNAL_GET_EDITABLE) { bool * editable = (bool *)param; *editable = true; } @@ -407,17 +426,17 @@ static lv_style_list_t * lv_slider_get_style(lv_obj_t * slider, uint8_t part) lv_style_list_t * style_dsc_p; switch(part) { - case LV_SLIDER_PART_BG: - style_dsc_p = &slider->style_list; - break; - case LV_SLIDER_PART_INDIC: - style_dsc_p = &ext->bar.style_indic; - break; - case LV_SLIDER_PART_KNOB: - style_dsc_p = &ext->style_knob; - break; - default: - style_dsc_p = NULL; + case LV_SLIDER_PART_BG: + style_dsc_p = &slider->style_list; + break; + case LV_SLIDER_PART_INDIC: + style_dsc_p = &ext->bar.style_indic; + break; + case LV_SLIDER_PART_KNOB: + style_dsc_p = &ext->style_knob; + break; + default: + style_dsc_p = NULL; } return style_dsc_p; @@ -426,24 +445,25 @@ static lv_style_list_t * lv_slider_get_style(lv_obj_t * slider, uint8_t part) static void lv_slider_position_knob(lv_obj_t * slider, lv_area_t * knob_area, lv_coord_t knob_size, bool hor) { - if(hor) { - knob_area->x1 -= (knob_size >> 1); + if(hor) { + knob_area->x1 -= (knob_size >> 1); knob_area->x2 = knob_area->x1 + knob_size; knob_area->y1 = slider->coords.y1; knob_area->y2 = slider->coords.y2; - } else { - knob_area->y1 -= (knob_size >> 1); - knob_area->y2 = knob_area->y1 + knob_size; - knob_area->x1 = slider->coords.x1; - knob_area->x2 = slider->coords.x2; - } + } + else { + knob_area->y1 -= (knob_size >> 1); + knob_area->y2 = knob_area->y1 + knob_size; + knob_area->x1 = slider->coords.x1; + knob_area->x2 = slider->coords.x2; + } lv_style_int_t knob_left = lv_obj_get_style_pad_left(slider, LV_SLIDER_PART_KNOB); lv_style_int_t knob_right = lv_obj_get_style_pad_right(slider, LV_SLIDER_PART_KNOB); lv_style_int_t knob_top = lv_obj_get_style_pad_top(slider, LV_SLIDER_PART_KNOB); lv_style_int_t knob_bottom = lv_obj_get_style_pad_bottom(slider, LV_SLIDER_PART_KNOB); - /*Apply the paddings on the knob area*/ + /*Apply the paddings on the knob area*/ knob_area->x1 -= knob_left; knob_area->x2 += knob_right; knob_area->y1 -= knob_top; diff --git a/src/lv_widgets/lv_slider.h b/src/lv_widgets/lv_slider.h index d39784956..1a49c1f94 100644 --- a/src/lv_widgets/lv_slider.h +++ b/src/lv_widgets/lv_slider.h @@ -34,21 +34,20 @@ extern "C" { **********************/ enum { - LV_SLIDER_TYPE_NORMAL, - LV_SLIDER_TYPE_SYM, - LV_SLIDER_TYPE_RANGE + LV_SLIDER_TYPE_NORMAL, + LV_SLIDER_TYPE_SYM, + LV_SLIDER_TYPE_RANGE }; typedef uint8_t lv_slider_type_t; /*Data of slider*/ -typedef struct -{ +typedef struct { lv_bar_ext_t bar; /*Ext. of ancestor*/ /*New data for this type */ lv_style_list_t style_knob; /*Style of the knob*/ - lv_area_t left_knob_area; - lv_area_t right_knob_area; - int16_t *value_to_set; /* Which bar value to set */ - uint8_t dragging :1; /*1: the slider is being dragged*/ + lv_area_t left_knob_area; + lv_area_t right_knob_area; + int16_t * value_to_set; /* Which bar value to set */ + uint8_t dragging : 1; /*1: the slider is being dragged*/ } lv_slider_ext_t; /** Built-in styles of slider*/ @@ -126,12 +125,12 @@ static inline void lv_slider_set_anim_time(lv_obj_t * slider, uint16_t anim_time */ static inline void lv_slider_set_type(lv_obj_t * slider, lv_slider_type_t type) { - if(type == LV_SLIDER_TYPE_NORMAL) - lv_bar_set_type(slider, LV_BAR_TYPE_NORMAL); - else if(type == LV_SLIDER_TYPE_SYM) - lv_bar_set_type(slider, LV_BAR_TYPE_SYM); - else if(type == LV_SLIDER_TYPE_RANGE) - lv_bar_set_type(slider, LV_BAR_TYPE_CUSTOM); + if(type == LV_SLIDER_TYPE_NORMAL) + lv_bar_set_type(slider, LV_BAR_TYPE_NORMAL); + else if(type == LV_SLIDER_TYPE_SYM) + lv_bar_set_type(slider, LV_BAR_TYPE_SYM); + else if(type == LV_SLIDER_TYPE_RANGE) + lv_bar_set_type(slider, LV_BAR_TYPE_CUSTOM); } /*===================== @@ -206,13 +205,13 @@ static inline uint16_t lv_slider_get_anim_time(lv_obj_t * slider) */ static inline lv_slider_type_t lv_slider_get_type(lv_obj_t * slider) { - lv_bar_type_t type = lv_bar_get_type(slider); - if(type == LV_BAR_TYPE_SYM) - return LV_SLIDER_TYPE_SYM; - else if(type == LV_BAR_TYPE_CUSTOM) - return LV_SLIDER_TYPE_RANGE; - else - return LV_SLIDER_TYPE_NORMAL; + lv_bar_type_t type = lv_bar_get_type(slider); + if(type == LV_BAR_TYPE_SYM) + return LV_SLIDER_TYPE_SYM; + else if(type == LV_BAR_TYPE_CUSTOM) + return LV_SLIDER_TYPE_RANGE; + else + return LV_SLIDER_TYPE_NORMAL; } /********************** diff --git a/src/lv_widgets/lv_spinbox.c b/src/lv_widgets/lv_spinbox.c index d5003f4bd..93ca77f24 100644 --- a/src/lv_widgets/lv_spinbox.c +++ b/src/lv_widgets/lv_spinbox.c @@ -292,7 +292,8 @@ void lv_spinbox_increment(lv_obj_t * spinbox) if((ext->value + ext->step) > 0 && ext->value < 0) ext->value = -ext->value; ext->value += ext->step; - } else { + } + else { ext->value = ext->range_max; } @@ -313,7 +314,8 @@ void lv_spinbox_decrement(lv_obj_t * spinbox) /*Special mode when zero crossing*/ if((ext->value - ext->step) < 0 && ext->value > 0) ext->value = -ext->value; ext->value -= ext->step; - } else { + } + else { ext->value = ext->range_min; } @@ -352,14 +354,16 @@ static lv_res_t lv_spinbox_signal(lv_obj_t * spinbox, lv_signal_t sign, void * p if(sign == LV_SIGNAL_CLEANUP) { /*Nothing to cleanup. (No dynamically allocated memory in 'ext')*/ - } else if(sign == LV_SIGNAL_GET_TYPE) { + } + else if(sign == LV_SIGNAL_GET_TYPE) { lv_obj_type_t * buf = param; uint8_t i; for(i = 0; i < LV_MAX_ANCESTOR_NUM - 1; i++) { /*Find the last set data*/ if(buf->type[i] == NULL) break; } buf->type[i] = "lv_spinbox"; - } else if(sign == LV_SIGNAL_RELEASED) { + } + else if(sign == LV_SIGNAL_RELEASED) { /*If released with an ENCODER then move to the next digit*/ lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox); lv_indev_t * indev = lv_indev_get_act(); @@ -368,7 +372,8 @@ static lv_res_t lv_spinbox_signal(lv_obj_t * spinbox, lv_signal_t sign, void * p if(lv_group_get_editing(lv_obj_get_group(spinbox))) { if(ext->step > 1) { lv_spinbox_step_next(spinbox); - } else { + } + else { /*Restart from the MSB*/ ext->step = 1; uint32_t i; @@ -381,7 +386,8 @@ static lv_res_t lv_spinbox_signal(lv_obj_t * spinbox, lv_signal_t sign, void * p } } #endif - }else { + } + else { /*The cursor has been positioned to a digit. * Set `step` accordingly*/ const char * txt = lv_textarea_get_text(spinbox); @@ -389,9 +395,11 @@ static lv_res_t lv_spinbox_signal(lv_obj_t * spinbox, lv_signal_t sign, void * p if(txt[ext->ta.cursor.pos] == '.') { lv_textarea_cursor_left(spinbox); - } else if(ext->ta.cursor.pos == txt_len) { + } + else if(ext->ta.cursor.pos == txt_len) { lv_textarea_set_cursor_pos(spinbox, txt_len - 1); - } else if(ext->ta.cursor.pos == 0 && ext->range_min < 0) { + } + else if(ext->ta.cursor.pos == 0 && ext->range_min < 0) { lv_textarea_set_cursor_pos(spinbox, 1); } @@ -410,7 +418,8 @@ static lv_res_t lv_spinbox_signal(lv_obj_t * spinbox, lv_signal_t sign, void * p } - } else if(sign == LV_SIGNAL_CONTROL) { + } + else if(sign == LV_SIGNAL_CONTROL) { lv_indev_type_t indev_type = lv_indev_get_type(lv_indev_get_act()); uint32_t c = *((uint32_t *)param); /*uint32_t because can be UTF-8*/ @@ -419,16 +428,20 @@ static lv_res_t lv_spinbox_signal(lv_obj_t * spinbox, lv_signal_t sign, void * p lv_spinbox_increment(spinbox); else lv_spinbox_step_next(spinbox); - } else if(c == LV_KEY_LEFT) { + } + else if(c == LV_KEY_LEFT) { if(indev_type == LV_INDEV_TYPE_ENCODER) lv_spinbox_decrement(spinbox); else lv_spinbox_step_prev(spinbox); - } else if(c == LV_KEY_UP) { + } + else if(c == LV_KEY_UP) { lv_spinbox_increment(spinbox); - } else if(c == LV_KEY_DOWN) { + } + else if(c == LV_KEY_DOWN) { lv_spinbox_decrement(spinbox); - } else { + } + else { lv_textarea_add_char(spinbox, c); } } @@ -450,14 +463,14 @@ static lv_style_list_t * lv_spinbox_get_style(lv_obj_t * ta, uint8_t part) lv_style_list_t * style_dsc_p; switch(part) { - case LV_SPINBOX_PART_BG: - style_dsc_p = &ta->style_list; - break; - case LV_SPINBOX_PART_CURSOR: - style_dsc_p = &ext->ta.cursor.style; - break; - default: - style_dsc_p = NULL; + case LV_SPINBOX_PART_BG: + style_dsc_p = &ta->style_list; + break; + case LV_SPINBOX_PART_CURSOR: + style_dsc_p = &ext->ta.cursor.style; + break; + default: + style_dsc_p = NULL; } return style_dsc_p; @@ -471,13 +484,14 @@ static void lv_spinbox_updatevalue(lv_obj_t * spinbox) char * buf_p = buf; uint8_t cur_shift_left = 0; - if (ext->range_min < 0) { // hide sign if there are only positive values + if(ext->range_min < 0) { // hide sign if there are only positive values /*Add the sign*/ (*buf_p) = ext->value >= 0 ? '+' : '-'; buf_p++; - } else { - /*Cursor need shift to left*/ - cur_shift_left++; + } + else { + /*Cursor need shift to left*/ + cur_shift_left++; } int32_t i; diff --git a/src/lv_widgets/lv_spinbox.h b/src/lv_widgets/lv_spinbox.h index 9f76cf09e..49818882c 100644 --- a/src/lv_widgets/lv_spinbox.h +++ b/src/lv_widgets/lv_spinbox.h @@ -35,8 +35,7 @@ extern "C" { **********************/ /*Data of spinbox*/ -typedef struct -{ +typedef struct { lv_textarea_ext_t ta; /*Ext. of ancestor*/ /*New data for this type */ int32_t value; diff --git a/src/lv_widgets/lv_spinner.c b/src/lv_widgets/lv_spinner.c index 921c97f2f..60df1768d 100644 --- a/src/lv_widgets/lv_spinner.c +++ b/src/lv_widgets/lv_spinner.c @@ -21,15 +21,15 @@ #define LV_OBJX_NAME "lv_spinner" #ifndef LV_SPINNER_DEF_ARC_LENGTH -#define LV_SPINNER_DEF_ARC_LENGTH 60 /*[deg]*/ + #define LV_SPINNER_DEF_ARC_LENGTH 60 /*[deg]*/ #endif #ifndef LV_SPINNER_DEF_SPIN_TIME -#define LV_SPINNER_DEF_SPIN_TIME 1000 /*[ms]*/ + #define LV_SPINNER_DEF_SPIN_TIME 1000 /*[ms]*/ #endif #ifndef LV_SPINNER_DEF_ANIM -#define LV_SPINNER_DEF_ANIM LV_SPINNER_TYPE_SPINNING_ARC /*animation type*/ + #define LV_SPINNER_DEF_ANIM LV_SPINNER_TYPE_SPINNING_ARC /*animation type*/ #endif /********************** @@ -167,42 +167,42 @@ void lv_spinner_set_type(lv_obj_t * preload, lv_spinner_type_t type) lv_anim_del(preload, NULL); switch(type) { case LV_SPINNER_TYPE_FILLSPIN_ARC: { - ext->anim_type = LV_SPINNER_TYPE_FILLSPIN_ARC; - lv_anim_t a; - lv_anim_init(&a); - lv_anim_set_var(&a, preload); - lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)lv_spinner_anim_cb); - lv_anim_set_path_cb(&a, lv_anim_path_ease_in_out); - lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINIT); - lv_anim_set_time(&a, ext->time); - if(ext->anim_dir == LV_SPINNER_DIR_FORWARD) lv_anim_set_values(&a, 0, 360); - else lv_anim_set_values(&a, 360, 0); - lv_anim_start(&a); + ext->anim_type = LV_SPINNER_TYPE_FILLSPIN_ARC; + lv_anim_t a; + lv_anim_init(&a); + lv_anim_set_var(&a, preload); + lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)lv_spinner_anim_cb); + lv_anim_set_path_cb(&a, lv_anim_path_ease_in_out); + lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINIT); + lv_anim_set_time(&a, ext->time); + if(ext->anim_dir == LV_SPINNER_DIR_FORWARD) lv_anim_set_values(&a, 0, 360); + else lv_anim_set_values(&a, 360, 0); + lv_anim_start(&a); - lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)lv_spinner_set_arc_length); - if(ext->anim_dir == LV_SPINNER_DIR_FORWARD) lv_anim_set_values(&a, ext->arc_length, 360 - ext->arc_length); - else lv_anim_set_values(&a, 360 - ext->arc_length, ext->arc_length); + lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)lv_spinner_set_arc_length); + if(ext->anim_dir == LV_SPINNER_DIR_FORWARD) lv_anim_set_values(&a, ext->arc_length, 360 - ext->arc_length); + else lv_anim_set_values(&a, 360 - ext->arc_length, ext->arc_length); - lv_anim_set_playback_time(&a, ext->time); - lv_anim_start(&a); - break; - } + lv_anim_set_playback_time(&a, ext->time); + lv_anim_start(&a); + break; + } case LV_SPINNER_TYPE_CONSTANT_ARC: case LV_SPINNER_TYPE_SPINNING_ARC: default: { - ext->anim_type = type; - lv_anim_t a; - lv_anim_init(&a); - lv_anim_set_var(&a, preload); - lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)lv_spinner_anim_cb); - lv_anim_set_time(&a, ext->time); - lv_anim_set_path_cb(&a, (LV_SPINNER_TYPE_CONSTANT_ARC == type ? lv_anim_path_linear : lv_anim_path_ease_in_out)); - lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINIT); - if(ext->anim_dir == LV_SPINNER_DIR_FORWARD) lv_anim_set_values(&a, 0, 360); - else lv_anim_set_values(&a, 360, 0); - lv_anim_start(&a); - break; - } + ext->anim_type = type; + lv_anim_t a; + lv_anim_init(&a); + lv_anim_set_var(&a, preload); + lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)lv_spinner_anim_cb); + lv_anim_set_time(&a, ext->time); + lv_anim_set_path_cb(&a, (LV_SPINNER_TYPE_CONSTANT_ARC == type ? lv_anim_path_linear : lv_anim_path_ease_in_out)); + lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINIT); + if(ext->anim_dir == LV_SPINNER_DIR_FORWARD) lv_anim_set_values(&a, 0, 360); + else lv_anim_set_values(&a, 360, 0); + lv_anim_start(&a); + break; + } } } diff --git a/src/lv_widgets/lv_spinner.h b/src/lv_widgets/lv_spinner.h index 1aa07a559..99d6ede56 100644 --- a/src/lv_widgets/lv_spinner.h +++ b/src/lv_widgets/lv_spinner.h @@ -58,8 +58,7 @@ enum { typedef uint8_t lv_spinner_dir_t; /*Data of pre loader*/ -typedef struct -{ +typedef struct { lv_arc_ext_t arc; /*Ext. of ancestor*/ /*New data for this type */ lv_anim_value_t arc_length; /*Length of the spinning indicator in degree*/ diff --git a/src/lv_widgets/lv_switch.c b/src/lv_widgets/lv_switch.c index 1faf1481c..50fdfa61d 100644 --- a/src/lv_widgets/lv_switch.c +++ b/src/lv_widgets/lv_switch.c @@ -12,7 +12,7 @@ /*Testing of dependencies*/ #if LV_USE_SLIDER == 0 -#error "lv_sw: lv_slider is required. Enable it in lv_conf.h (LV_USE_SLIDER 1) " + #error "lv_sw: lv_slider is required. Enable it in lv_conf.h (LV_USE_SLIDER 1) " #endif #include "../lv_core/lv_debug.h" @@ -279,21 +279,24 @@ static lv_res_t lv_switch_signal(lv_obj_t * sw, lv_signal_t sign, void * param) if(sign == LV_SIGNAL_CLEANUP) { lv_obj_clean_style_list(sw, LV_SWITCH_PART_KNOB); - } else if(sign == LV_SIGNAL_RELEASED) { - if(lv_switch_get_state(sw)) lv_switch_off(sw, LV_ANIM_ON); + } + else if(sign == LV_SIGNAL_RELEASED) { + if(lv_switch_get_state(sw)) lv_switch_off(sw, LV_ANIM_ON); else lv_switch_on(sw, LV_ANIM_ON); res = lv_event_send(sw, LV_EVENT_VALUE_CHANGED, NULL); if(res != LV_RES_OK) return res; - } else if(sign == LV_SIGNAL_CONTROL) { + } + else if(sign == LV_SIGNAL_CONTROL) { char c = *((char *)param); if(c == LV_KEY_RIGHT || c == LV_KEY_UP) lv_switch_on(sw, LV_ANIM_ON); else if(c == LV_KEY_LEFT || c == LV_KEY_DOWN) lv_switch_off(sw, LV_ANIM_ON); res = lv_event_send(sw, LV_EVENT_VALUE_CHANGED, NULL); if(res != LV_RES_OK) return res; - }else if(sign == LV_SIGNAL_REFR_EXT_DRAW_PAD) { + } + else if(sign == LV_SIGNAL_REFR_EXT_DRAW_PAD) { lv_style_int_t knob_left = lv_obj_get_style_pad_left(sw, LV_SLIDER_PART_KNOB); lv_style_int_t knob_right = lv_obj_get_style_pad_right(sw, LV_SLIDER_PART_KNOB); lv_style_int_t knob_top = lv_obj_get_style_pad_top(sw, LV_SLIDER_PART_KNOB); @@ -301,7 +304,7 @@ static lv_res_t lv_switch_signal(lv_obj_t * sw, lv_signal_t sign, void * param) /* The smaller size is the knob diameter*/ lv_coord_t knob_size = LV_MATH_MIN(lv_obj_get_width(sw), lv_obj_get_height(sw)) >> 1; - knob_size += LV_MATH_MAX(LV_MATH_MAX(knob_left, knob_right), LV_MATH_MAX(knob_bottom,knob_top)); + knob_size += LV_MATH_MAX(LV_MATH_MAX(knob_left, knob_right), LV_MATH_MAX(knob_bottom, knob_top)); knob_size += 2; /*For rounding error*/ knob_size += lv_obj_get_draw_rect_ext_pad_size(sw, LV_SLIDER_PART_KNOB); @@ -325,17 +328,17 @@ static lv_style_list_t * lv_switch_get_style(lv_obj_t * sw, uint8_t part) lv_style_list_t * style_dsc_p; switch(part) { - case LV_SWITCH_PART_BG: - style_dsc_p = &sw->style_list; - break; - case LV_SWITCH_PART_INDIC: - style_dsc_p = &ext->bar.style_indic; - break; - case LV_SWITCH_PART_KNOB: - style_dsc_p = &ext->style_knob; - break; - default: - style_dsc_p = NULL; + case LV_SWITCH_PART_BG: + style_dsc_p = &sw->style_list; + break; + case LV_SWITCH_PART_INDIC: + style_dsc_p = &ext->bar.style_indic; + break; + case LV_SWITCH_PART_KNOB: + style_dsc_p = &ext->style_knob; + break; + default: + style_dsc_p = NULL; } return style_dsc_p; diff --git a/src/lv_widgets/lv_switch.h b/src/lv_widgets/lv_switch.h index 37f780424..35b7b0abb 100644 --- a/src/lv_widgets/lv_switch.h +++ b/src/lv_widgets/lv_switch.h @@ -33,12 +33,11 @@ extern "C" { * TYPEDEFS **********************/ /*Data of switch*/ -typedef struct -{ +typedef struct { lv_bar_ext_t bar; /*Ext. of ancestor*/ /*New data for this type */ lv_style_list_t style_knob; /*Style of the knob*/ - uint8_t state :1; /*The current state*/ + uint8_t state : 1; /*The current state*/ } lv_switch_ext_t; /** diff --git a/src/lv_widgets/lv_table.c b/src/lv_widgets/lv_table.c index 553cbca94..133595b6b 100644 --- a/src/lv_widgets/lv_table.c +++ b/src/lv_widgets/lv_table.c @@ -30,8 +30,9 @@ static lv_design_res_t lv_table_design(lv_obj_t * table, const lv_area_t * clip_area, lv_design_mode_t mode); static lv_res_t lv_table_signal(lv_obj_t * table, lv_signal_t sign, void * param); static lv_style_list_t * lv_table_get_style(lv_obj_t * table, uint8_t part); -static lv_coord_t get_row_height(lv_obj_t * table, uint16_t row_id, const lv_font_t ** font, lv_style_int_t * letter_space, lv_style_int_t * line_space, - lv_style_int_t * cell_left, lv_style_int_t * cell_right, lv_style_int_t * cell_top, lv_style_int_t * cell_bottom); +static lv_coord_t get_row_height(lv_obj_t * table, uint16_t row_id, const lv_font_t ** font, + lv_style_int_t * letter_space, lv_style_int_t * line_space, + lv_style_int_t * cell_left, lv_style_int_t * cell_right, lv_style_int_t * cell_top, lv_style_int_t * cell_bottom); static void refr_size(lv_obj_t * table); /********************** @@ -150,9 +151,9 @@ void lv_table_set_cell_value(lv_obj_t * table, uint16_t row, uint16_t col, const else if(base_dir == LV_BIDI_DIR_RTL) format.s.align = LV_LABEL_ALIGN_RIGHT; else if(base_dir == LV_BIDI_DIR_AUTO) #if LV_USE_BIDI - format.s.align = lv_bidi_detect_base_dir(txt); + format.s.align = lv_bidi_detect_base_dir(txt); #else - format.s.align = LV_LABEL_ALIGN_LEFT; + format.s.align = LV_LABEL_ALIGN_LEFT; #endif format.s.right_merge = 0; format.s.type = 0; @@ -188,7 +189,8 @@ void lv_table_set_row_cnt(lv_obj_t * table, uint16_t row_cnt) uint32_t new_cell_cnt = ext->col_cnt * ext->row_cnt; memset(&ext->cell_data[old_cell_cnt], 0, (new_cell_cnt - old_cell_cnt) * sizeof(ext->cell_data[0])); } - } else { + } + else { lv_mem_free(ext->cell_data); ext->cell_data = NULL; } @@ -223,7 +225,8 @@ void lv_table_set_col_cnt(lv_obj_t * table, uint16_t col_cnt) memset(&ext->cell_data[old_cell_cnt], 0, (new_cell_cnt - old_cell_cnt) * sizeof(ext->cell_data[0])); } - } else { + } + else { lv_mem_free(ext->cell_data); ext->cell_data = NULL; } @@ -590,7 +593,7 @@ static lv_design_res_t lv_table_design(lv_obj_t * table, const lv_area_t * clip_ lv_txt_flag_t txt_flags; lv_style_int_t bg_top = lv_obj_get_style_pad_top(table, LV_TABLE_PART_BG); - lv_style_int_t bg_left= lv_obj_get_style_pad_left(table, LV_TABLE_PART_BG); + lv_style_int_t bg_left = lv_obj_get_style_pad_left(table, LV_TABLE_PART_BG); lv_draw_rect_dsc_t rect_dsc[LV_TABLE_CELL_STYLE_CNT]; lv_draw_label_dsc_t label_dsc[LV_TABLE_CELL_STYLE_CNT]; @@ -630,7 +633,7 @@ static lv_design_res_t lv_table_design(lv_obj_t * table, const lv_area_t * clip_ cell_area.y2 = table->coords.y1 + bg_top; for(row = 0; row < ext->row_cnt; row++) { lv_coord_t h_row = get_row_height(table, row, font, letter_space, line_space, - cell_left, cell_right, cell_top, cell_bottom); + cell_left, cell_right, cell_top, cell_bottom); cell_area.y1 = cell_area.y2 + 1; cell_area.y2 = cell_area.y1 + h_row - 1; @@ -644,7 +647,8 @@ static lv_design_res_t lv_table_design(lv_obj_t * table, const lv_area_t * clip_ lv_table_cell_format_t format; if(ext->cell_data[cell]) { format.format_byte = ext->cell_data[cell][0]; - } else { + } + else { format.s.right_merge = 0; format.s.align = LV_LABEL_ALIGN_LEFT; format.s.type = 0; @@ -662,7 +666,8 @@ static lv_design_res_t lv_table_design(lv_obj_t * table, const lv_area_t * clip_ cell_area.x2 += ext->col_w[col + col_merge + 1]; else break; - } else { + } + else { break; } } @@ -692,7 +697,8 @@ static lv_design_res_t lv_table_design(lv_obj_t * table, const lv_area_t * clip_ /*Align the content to the middle if not cropped*/ if(format.s.crop == 0) { txt_flags = LV_TXT_FLAG_NONE; - } else { + } + else { txt_flags = LV_TXT_FLAG_EXPAND; } @@ -709,9 +715,15 @@ static lv_design_res_t lv_table_design(lv_obj_t * table, const lv_area_t * clip_ label_dsc[cell_type].flag = 0; switch(format.s.align) { default: - case LV_LABEL_ALIGN_LEFT: label_dsc[cell_type].flag |= LV_TXT_FLAG_NONE; break; - case LV_LABEL_ALIGN_RIGHT: label_dsc[cell_type].flag |= LV_TXT_FLAG_RIGHT; break; - case LV_LABEL_ALIGN_CENTER: label_dsc[cell_type].flag |= LV_TXT_FLAG_CENTER; break; + case LV_LABEL_ALIGN_LEFT: + label_dsc[cell_type].flag |= LV_TXT_FLAG_NONE; + break; + case LV_LABEL_ALIGN_RIGHT: + label_dsc[cell_type].flag |= LV_TXT_FLAG_RIGHT; + break; + case LV_LABEL_ALIGN_CENTER: + label_dsc[cell_type].flag |= LV_TXT_FLAG_CENTER; + break; } lv_area_t label_mask; @@ -817,23 +829,23 @@ static lv_style_list_t * lv_table_get_style(lv_obj_t * table, uint8_t part) lv_style_list_t * style_dsc_p; switch(part) { - case LV_TABLE_PART_BG: - style_dsc_p = &table->style_list; - break; - case LV_TABLE_PART_CELL1: - style_dsc_p = &ext->cell_style[0]; - break; - case LV_TABLE_PART_CELL2: - style_dsc_p = &ext->cell_style[1]; - break; - case LV_TABLE_PART_CELL3: - style_dsc_p = &ext->cell_style[2]; - break; - case LV_TABLE_PART_CELL4: - style_dsc_p = &ext->cell_style[3]; - break; - default: - style_dsc_p = NULL; + case LV_TABLE_PART_BG: + style_dsc_p = &table->style_list; + break; + case LV_TABLE_PART_CELL1: + style_dsc_p = &ext->cell_style[0]; + break; + case LV_TABLE_PART_CELL2: + style_dsc_p = &ext->cell_style[1]; + break; + case LV_TABLE_PART_CELL3: + style_dsc_p = &ext->cell_style[2]; + break; + case LV_TABLE_PART_CELL4: + style_dsc_p = &ext->cell_style[3]; + break; + default: + style_dsc_p = NULL; } return style_dsc_p; @@ -871,22 +883,23 @@ static void refr_size(lv_obj_t * table) for(i = 0; i < ext->row_cnt; i++) { - h += get_row_height(table, i, font, letter_space, line_space, - cell_left, cell_right, cell_top, cell_bottom); + h += get_row_height(table, i, font, letter_space, line_space, + cell_left, cell_right, cell_top, cell_bottom); } lv_style_int_t bg_top = lv_obj_get_style_pad_top(table, LV_TABLE_PART_BG); - lv_style_int_t bg_bottom= lv_obj_get_style_pad_bottom(table, LV_TABLE_PART_BG); + lv_style_int_t bg_bottom = lv_obj_get_style_pad_bottom(table, LV_TABLE_PART_BG); lv_style_int_t bg_left = lv_obj_get_style_pad_left(table, LV_TABLE_PART_BG); - lv_style_int_t bg_right= lv_obj_get_style_pad_right(table, LV_TABLE_PART_BG); + lv_style_int_t bg_right = lv_obj_get_style_pad_right(table, LV_TABLE_PART_BG); w += bg_left + bg_right; h += bg_top + bg_bottom; lv_obj_set_size(table, w + 1, h + 1); } -static lv_coord_t get_row_height(lv_obj_t * table, uint16_t row_id, const lv_font_t ** font, lv_style_int_t * letter_space, lv_style_int_t * line_space, - lv_style_int_t * cell_left, lv_style_int_t * cell_right, lv_style_int_t * cell_top, lv_style_int_t * cell_bottom) +static lv_coord_t get_row_height(lv_obj_t * table, uint16_t row_id, const lv_font_t ** font, + lv_style_int_t * letter_space, lv_style_int_t * line_space, + lv_style_int_t * cell_left, lv_style_int_t * cell_right, lv_style_int_t * cell_top, lv_style_int_t * cell_bottom) { lv_table_ext_t * ext = lv_obj_get_ext_attr(table); lv_point_t txt_size; @@ -910,7 +923,8 @@ static lv_coord_t get_row_height(lv_obj_t * table, uint16_t row_id, const lv_fon txt_w += ext->col_w[col + col_merge + 1]; else break; - } else { + } + else { break; } } diff --git a/src/lv_widgets/lv_table.h b/src/lv_widgets/lv_table.h index eac35556c..08071531f 100644 --- a/src/lv_widgets/lv_table.h +++ b/src/lv_widgets/lv_table.h @@ -39,13 +39,11 @@ extern "C" { /** * Internal table cell format structure. - * + * * Use the `lv_table` APIs instead. */ -typedef union -{ - struct - { +typedef union { + struct { uint8_t align : 2; uint8_t right_merge : 1; uint8_t type : 2; @@ -55,8 +53,7 @@ typedef union } lv_table_cell_format_t; /*Data of table*/ -typedef struct -{ +typedef struct { /*New data for this type */ uint16_t col_cnt; uint16_t row_cnt; diff --git a/src/lv_widgets/lv_tabview.c b/src/lv_widgets/lv_tabview.c index 173d08adf..1156196aa 100644 --- a/src/lv_widgets/lv_tabview.c +++ b/src/lv_widgets/lv_tabview.c @@ -21,12 +21,12 @@ #define LV_OBJX_NAME "lv_tabview" #if LV_USE_ANIMATION -#ifndef LV_TABVIEW_DEF_ANIM_TIME -#define LV_TABVIEW_DEF_ANIM_TIME 300 /*Animation time of focusing to the a list element [ms] (0: no animation) */ -#endif + #ifndef LV_TABVIEW_DEF_ANIM_TIME + #define LV_TABVIEW_DEF_ANIM_TIME 300 /*Animation time of focusing to the a list element [ms] (0: no animation) */ + #endif #else -#undef LV_TABVIEW_DEF_ANIM_TIME -#define LV_TABVIEW_DEF_ANIM_TIME 0 /*No animations*/ + #undef LV_TABVIEW_DEF_ANIM_TIME + #define LV_TABVIEW_DEF_ANIM_TIME 0 /*No animations*/ #endif /********************** @@ -117,7 +117,8 @@ lv_obj_t * lv_tabview_create(lv_obj_t * par, const lv_obj_t * copy) if(par) { w = lv_obj_get_width_fit(lv_obj_get_parent(tabview)); h = lv_obj_get_height_fit(lv_obj_get_parent(tabview)); - } else { + } + else { w = lv_disp_get_hor_res(NULL); h = lv_disp_get_ver_res(NULL); } @@ -164,16 +165,21 @@ lv_obj_t * lv_tabview_create(lv_obj_t * par, const lv_obj_t * copy) ext->tab_name_ptr[0] = ""; lv_btnmatrix_set_map(ext->btns, ext->tab_name_ptr); - lv_style_list_copy(lv_obj_get_style_list(tabview, LV_TABVIEW_PART_BG_SCRL), lv_obj_get_style_list(copy, LV_TABVIEW_PART_BG_SCRL)); - lv_style_list_copy(lv_obj_get_style_list(tabview, LV_TABVIEW_PART_TAB_BG), lv_obj_get_style_list(copy, LV_TABVIEW_PART_TAB_BG)); - lv_style_list_copy(lv_obj_get_style_list(tabview, LV_TABVIEW_PART_TAB), lv_obj_get_style_list(copy, LV_TABVIEW_PART_TAB)); + lv_style_list_copy(lv_obj_get_style_list(tabview, LV_TABVIEW_PART_BG_SCRL), lv_obj_get_style_list(copy, + LV_TABVIEW_PART_BG_SCRL)); + lv_style_list_copy(lv_obj_get_style_list(tabview, LV_TABVIEW_PART_TAB_BG), lv_obj_get_style_list(copy, + LV_TABVIEW_PART_TAB_BG)); + lv_style_list_copy(lv_obj_get_style_list(tabview, LV_TABVIEW_PART_TAB), lv_obj_get_style_list(copy, + LV_TABVIEW_PART_TAB)); uint16_t i; for(i = 0; i < copy_ext->tab_cnt; i++) { lv_obj_t * new_tab = lv_tabview_add_tab(tabview, copy_ext->tab_name_ptr[i]); lv_obj_t * copy_tab = lv_tabview_get_tab(copy, i); - lv_style_list_copy(lv_obj_get_style_list(new_tab, LV_PAGE_PART_SCRL), lv_obj_get_style_list(copy_tab, LV_PAGE_PART_SCRL)); - lv_style_list_copy(lv_obj_get_style_list(new_tab, LV_PAGE_PART_SCRLBAR), lv_obj_get_style_list(copy_tab, LV_PAGE_PART_SCRLBAR)); + lv_style_list_copy(lv_obj_get_style_list(new_tab, LV_PAGE_PART_SCRL), lv_obj_get_style_list(copy_tab, + LV_PAGE_PART_SCRL)); + lv_style_list_copy(lv_obj_get_style_list(new_tab, LV_PAGE_PART_SCRLBAR), lv_obj_get_style_list(copy_tab, + LV_PAGE_PART_SCRLBAR)); lv_obj_refresh_style(new_tab); } @@ -238,11 +244,11 @@ lv_obj_t * lv_tabview_add_tab(lv_obj_t * tabview, const char * name) switch(ext->btns_pos) { case LV_TABVIEW_BTNS_POS_TOP: case LV_TABVIEW_BTNS_POS_BOTTOM: - ext->tab_name_ptr = lv_mem_realloc((void*)ext->tab_name_ptr, sizeof(char *) * (ext->tab_cnt + 1)); + ext->tab_name_ptr = lv_mem_realloc((void *)ext->tab_name_ptr, sizeof(char *) * (ext->tab_cnt + 1)); break; case LV_TABVIEW_BTNS_POS_LEFT: case LV_TABVIEW_BTNS_POS_RIGHT: - ext->tab_name_ptr = lv_mem_realloc((void*)ext->tab_name_ptr, sizeof(char *) * (ext->tab_cnt * 2)); + ext->tab_name_ptr = lv_mem_realloc((void *)ext->tab_name_ptr, sizeof(char *) * (ext->tab_cnt * 2)); break; } @@ -254,35 +260,36 @@ lv_obj_t * lv_tabview_add_tab(lv_obj_t * tabview, const char * name) * to LV_TABVIEW_BTNS_POS_TOP or LV_TABVIEW_BTNS_POS_BOTTOM. */ switch(ext->btns_pos) { - default: /*default case is prevented in lv_tabview_set_btns_pos(), but here for safety*/ - case LV_TABVIEW_BTNS_POS_NONE: - case LV_TABVIEW_BTNS_POS_TOP: - case LV_TABVIEW_BTNS_POS_BOTTOM: - ext->tab_name_ptr = lv_mem_realloc(ext->tab_name_ptr, sizeof(char *) * (ext->tab_cnt + 1)); + default: /*default case is prevented in lv_tabview_set_btns_pos(), but here for safety*/ + case LV_TABVIEW_BTNS_POS_NONE: + case LV_TABVIEW_BTNS_POS_TOP: + case LV_TABVIEW_BTNS_POS_BOTTOM: + ext->tab_name_ptr = lv_mem_realloc(ext->tab_name_ptr, sizeof(char *) * (ext->tab_cnt + 1)); - LV_ASSERT_MEM(ext->tab_name_ptr); - if(ext->tab_name_ptr == NULL) return NULL; + LV_ASSERT_MEM(ext->tab_name_ptr); + if(ext->tab_name_ptr == NULL) return NULL; - ext->tab_name_ptr[ext->tab_cnt - 1] = name_dm; - ext->tab_name_ptr[ext->tab_cnt] = ""; + ext->tab_name_ptr[ext->tab_cnt - 1] = name_dm; + ext->tab_name_ptr[ext->tab_cnt] = ""; - break; - case LV_TABVIEW_BTNS_POS_LEFT: - case LV_TABVIEW_BTNS_POS_RIGHT: - ext->tab_name_ptr = lv_mem_realloc(ext->tab_name_ptr, sizeof(char *) * (ext->tab_cnt * 2)); + break; + case LV_TABVIEW_BTNS_POS_LEFT: + case LV_TABVIEW_BTNS_POS_RIGHT: + ext->tab_name_ptr = lv_mem_realloc(ext->tab_name_ptr, sizeof(char *) * (ext->tab_cnt * 2)); - LV_ASSERT_MEM(ext->tab_name_ptr); - if(ext->tab_name_ptr == NULL) return NULL; + LV_ASSERT_MEM(ext->tab_name_ptr); + if(ext->tab_name_ptr == NULL) return NULL; - if(ext->tab_cnt == 1) { - ext->tab_name_ptr[0] = name_dm; - ext->tab_name_ptr[1] = ""; - } else { - ext->tab_name_ptr[ext->tab_cnt * 2 - 3] = "\n"; - ext->tab_name_ptr[ext->tab_cnt * 2 - 2] = name_dm; - ext->tab_name_ptr[ext->tab_cnt * 2 - 1] = ""; - } - break; + if(ext->tab_cnt == 1) { + ext->tab_name_ptr[0] = name_dm; + ext->tab_name_ptr[1] = ""; + } + else { + ext->tab_name_ptr[ext->tab_cnt * 2 - 3] = "\n"; + ext->tab_name_ptr[ext->tab_cnt * 2 - 2] = name_dm; + ext->tab_name_ptr[ext->tab_cnt * 2 - 1] = ""; + } + break; } /* The button matrix's map still points to the old `tab_name_ptr` which might be freed by @@ -337,16 +344,16 @@ void lv_tabview_set_tab_act(lv_obj_t * tabview, uint16_t id, lv_anim_enable_t an lv_style_int_t scrl_left = lv_obj_get_style_pad_left(ext->content, LV_PAGE_PART_SCRL); switch(ext->btns_pos) { - default: /*default case is prevented in lv_tabview_set_btns_pos(), but here for safety*/ - case LV_TABVIEW_BTNS_POS_NONE: - case LV_TABVIEW_BTNS_POS_TOP: - case LV_TABVIEW_BTNS_POS_BOTTOM: - cont_x = -(lv_obj_get_width(tabview) * id + scrl_inner * id + scrl_left); - break; - case LV_TABVIEW_BTNS_POS_LEFT: - case LV_TABVIEW_BTNS_POS_RIGHT: - cont_x = -((lv_obj_get_width(tabview) - lv_obj_get_width(ext->btns)) * id + scrl_inner * id + scrl_left); - break; + default: /*default case is prevented in lv_tabview_set_btns_pos(), but here for safety*/ + case LV_TABVIEW_BTNS_POS_NONE: + case LV_TABVIEW_BTNS_POS_TOP: + case LV_TABVIEW_BTNS_POS_BOTTOM: + cont_x = -(lv_obj_get_width(tabview) * id + scrl_inner * id + scrl_left); + break; + case LV_TABVIEW_BTNS_POS_LEFT: + case LV_TABVIEW_BTNS_POS_RIGHT: + cont_x = -((lv_obj_get_width(tabview) - lv_obj_get_width(ext->btns)) * id + scrl_inner * id + scrl_left); + break; } if(anim == LV_ANIM_OFF || lv_tabview_get_anim_time(tabview) == 0) { @@ -373,19 +380,19 @@ void lv_tabview_set_tab_act(lv_obj_t * tabview, uint16_t id, lv_anim_enable_t an lv_style_int_t btns_bg_top = lv_obj_get_style_pad_top(tabview, LV_TABVIEW_PART_TAB_BG); switch(ext->btns_pos) { - default: /*default case is prevented in lv_tabview_set_btns_pos(), but here for safety*/ - case LV_TABVIEW_BTNS_POS_NONE: - break; - case LV_TABVIEW_BTNS_POS_TOP: - case LV_TABVIEW_BTNS_POS_BOTTOM: - indic_size = lv_obj_get_width(ext->indic); - indic_pos = indic_size * id + btns_bg_inner* id + btns_bg_left; - break; - case LV_TABVIEW_BTNS_POS_LEFT: - case LV_TABVIEW_BTNS_POS_RIGHT: - indic_size = lv_obj_get_height(ext->indic); - indic_pos = btns_bg_top + id * (indic_size + btns_bg_inner); - break; + default: /*default case is prevented in lv_tabview_set_btns_pos(), but here for safety*/ + case LV_TABVIEW_BTNS_POS_NONE: + break; + case LV_TABVIEW_BTNS_POS_TOP: + case LV_TABVIEW_BTNS_POS_BOTTOM: + indic_size = lv_obj_get_width(ext->indic); + indic_pos = indic_size * id + btns_bg_inner * id + btns_bg_left; + break; + case LV_TABVIEW_BTNS_POS_LEFT: + case LV_TABVIEW_BTNS_POS_RIGHT: + indic_size = lv_obj_get_height(ext->indic); + indic_pos = btns_bg_top + id * (indic_size + btns_bg_inner); + break; } #if LV_USE_ANIMATION @@ -393,12 +400,17 @@ void lv_tabview_set_tab_act(lv_obj_t * tabview, uint16_t id, lv_anim_enable_t an #endif { switch(ext->btns_pos) { - default: /*default case is prevented in lv_tabview_set_btns_pos(), but here for safety*/ - case LV_TABVIEW_BTNS_POS_NONE: break; - case LV_TABVIEW_BTNS_POS_TOP: - case LV_TABVIEW_BTNS_POS_BOTTOM: lv_obj_set_x(ext->indic, indic_pos); break; - case LV_TABVIEW_BTNS_POS_LEFT: - case LV_TABVIEW_BTNS_POS_RIGHT: lv_obj_set_y(ext->indic, indic_pos); break; + default: /*default case is prevented in lv_tabview_set_btns_pos(), but here for safety*/ + case LV_TABVIEW_BTNS_POS_NONE: + break; + case LV_TABVIEW_BTNS_POS_TOP: + case LV_TABVIEW_BTNS_POS_BOTTOM: + lv_obj_set_x(ext->indic, indic_pos); + break; + case LV_TABVIEW_BTNS_POS_LEFT: + case LV_TABVIEW_BTNS_POS_RIGHT: + lv_obj_set_y(ext->indic, indic_pos); + break; } } #if LV_USE_ANIMATION @@ -409,19 +421,19 @@ void lv_tabview_set_tab_act(lv_obj_t * tabview, uint16_t id, lv_anim_enable_t an lv_anim_set_time(&a, ext->anim_time); switch(ext->btns_pos) { - default: /*default case is prevented in lv_tabview_set_btns_pos(), but here for safety*/ - case LV_TABVIEW_BTNS_POS_NONE: - break; - case LV_TABVIEW_BTNS_POS_TOP: - case LV_TABVIEW_BTNS_POS_BOTTOM: - lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)lv_obj_set_x); - lv_anim_set_values(&a, lv_obj_get_x(ext->indic), indic_pos); - break; - case LV_TABVIEW_BTNS_POS_LEFT: - case LV_TABVIEW_BTNS_POS_RIGHT: - lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)lv_obj_set_y); - lv_anim_set_values(&a, lv_obj_get_y(ext->indic), indic_pos); - break; + default: /*default case is prevented in lv_tabview_set_btns_pos(), but here for safety*/ + case LV_TABVIEW_BTNS_POS_NONE: + break; + case LV_TABVIEW_BTNS_POS_TOP: + case LV_TABVIEW_BTNS_POS_BOTTOM: + lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)lv_obj_set_x); + lv_anim_set_values(&a, lv_obj_get_x(ext->indic), indic_pos); + break; + case LV_TABVIEW_BTNS_POS_LEFT: + case LV_TABVIEW_BTNS_POS_RIGHT: + lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)lv_obj_set_y); + lv_anim_set_values(&a, lv_obj_get_y(ext->indic), indic_pos); + break; } lv_anim_start(&a); @@ -571,19 +583,20 @@ lv_tabview_btns_pos_t lv_tabview_get_btns_pos(const lv_obj_t * tabview) static lv_res_t lv_tabview_signal(lv_obj_t * tabview, lv_signal_t sign, void * param) { lv_res_t res; - if(sign == LV_SIGNAL_GET_STYLE) { - lv_get_style_info_t * info = param; - info->result = lv_tabview_get_style(tabview, info->part); - if(info->result != NULL) return LV_RES_OK; - else return ancestor_signal(tabview, sign, param); - } else if(sign == LV_SIGNAL_GET_STATE_DSC) { + if(sign == LV_SIGNAL_GET_STYLE) { + lv_get_style_info_t * info = param; + info->result = lv_tabview_get_style(tabview, info->part); + if(info->result != NULL) return LV_RES_OK; + else return ancestor_signal(tabview, sign, param); + } + else if(sign == LV_SIGNAL_GET_STATE_DSC) { lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview); - lv_get_state_info_t * info = param; - if(info->part == LV_TABVIEW_PART_TAB_BG) info->result = lv_obj_get_state(ext->btns, LV_BTNMATRIX_PART_BG); - else if(info->part == LV_TABVIEW_PART_TAB) info->result = lv_obj_get_state(ext->btns, LV_BTNMATRIX_PART_BTN); - else if(info->part == LV_TABVIEW_PART_INDIC) info->result = lv_obj_get_state(ext->indic, LV_OBJ_PART_MAIN); - else if(info->part == LV_TABVIEW_PART_BG_SCRL) info->result = lv_obj_get_state(ext->content, LV_PAGE_PART_SCRL); - return LV_RES_OK; + lv_get_state_info_t * info = param; + if(info->part == LV_TABVIEW_PART_TAB_BG) info->result = lv_obj_get_state(ext->btns, LV_BTNMATRIX_PART_BG); + else if(info->part == LV_TABVIEW_PART_TAB) info->result = lv_obj_get_state(ext->btns, LV_BTNMATRIX_PART_BTN); + else if(info->part == LV_TABVIEW_PART_INDIC) info->result = lv_obj_get_state(ext->indic, LV_OBJ_PART_MAIN); + else if(info->part == LV_TABVIEW_PART_BG_SCRL) info->result = lv_obj_get_state(ext->content, LV_PAGE_PART_SCRL); + return LV_RES_OK; } /* Include the ancient signal function */ @@ -600,33 +613,38 @@ static lv_res_t lv_tabview_signal(lv_obj_t * tabview, lv_signal_t sign, void * p ext->tab_name_ptr = NULL; ext->btns = NULL; /*These objects were children so they are already invalid*/ ext->content = NULL; - } else if(sign == LV_SIGNAL_STYLE_CHG) { + } + else if(sign == LV_SIGNAL_STYLE_CHG) { /*Be sure the buttons are updated because correct button size is required in `tabview_realign`*/ lv_signal_send(ext->btns, LV_SIGNAL_STYLE_CHG, NULL); tabview_realign(tabview); - } else if(sign == LV_SIGNAL_COORD_CHG) { + } + else if(sign == LV_SIGNAL_COORD_CHG) { if(ext->content != NULL && (lv_obj_get_width(tabview) != lv_area_get_width(param) || - lv_obj_get_height(tabview) != lv_area_get_height(param))) { + lv_obj_get_height(tabview) != lv_area_get_height(param))) { tabview_realign(tabview); } - } else if(sign == LV_SIGNAL_RELEASED) { + } + else if(sign == LV_SIGNAL_RELEASED) { #if LV_USE_GROUP /*If released by a KEYPAD or ENCODER then really the tab buttons should be released. * So simulate a CLICK on the tab buttons*/ lv_indev_t * indev = lv_indev_get_act(); lv_indev_type_t indev_type = lv_indev_get_type(indev); if(indev_type == LV_INDEV_TYPE_KEYPAD || - (indev_type == LV_INDEV_TYPE_ENCODER && lv_group_get_editing(lv_obj_get_group(tabview)))) { + (indev_type == LV_INDEV_TYPE_ENCODER && lv_group_get_editing(lv_obj_get_group(tabview)))) { lv_event_send(ext->btns, LV_EVENT_CLICKED, lv_event_get_data()); } #endif - } else if(sign == LV_SIGNAL_GET_EDITABLE) { + } + else if(sign == LV_SIGNAL_GET_EDITABLE) { bool * editable = (bool *)param; *editable = true; } - if(sign == LV_SIGNAL_FOCUS || sign == LV_SIGNAL_DEFOCUS || sign == LV_SIGNAL_CONTROL || sign == LV_SIGNAL_PRESSED || sign == LV_SIGNAL_RELEASED) { + if(sign == LV_SIGNAL_FOCUS || sign == LV_SIGNAL_DEFOCUS || sign == LV_SIGNAL_CONTROL || sign == LV_SIGNAL_PRESSED || + sign == LV_SIGNAL_RELEASED) { /* The button matrix is not in a group (the tab view is in it) but it should handle the * group signals. So propagate the related signals to the button matrix manually*/ if(ext->btns) { @@ -684,7 +702,8 @@ static lv_res_t tabview_scrl_signal(lv_obj_t * tabview_scrl, lv_signal_t sign, v if(page_x1 > treshold) { if(base_dir != LV_BIDI_DIR_RTL) tab_cur--; else tab_cur ++; - } else if(page_x2 < treshold) { + } + else if(page_x2 < treshold) { if(base_dir != LV_BIDI_DIR_RTL) tab_cur++; else tab_cur --; } @@ -717,23 +736,23 @@ static lv_style_list_t * lv_tabview_get_style(lv_obj_t * tabview, uint8_t part) lv_style_list_t * style_dsc_p; switch(part) { - case LV_TABVIEW_PART_BG: - style_dsc_p = &tabview->style_list; - break; - case LV_TABVIEW_PART_BG_SCRL: - style_dsc_p = lv_obj_get_style_list(ext->content, LV_PAGE_PART_SCRL); - break; - case LV_TABVIEW_PART_TAB_BG: - style_dsc_p = lv_obj_get_style_list(ext->btns, LV_BTNMATRIX_PART_BG); - break; - case LV_TABVIEW_PART_TAB: - style_dsc_p = lv_obj_get_style_list(ext->btns, LV_BTNMATRIX_PART_BTN); - break; - case LV_TABVIEW_PART_INDIC: - style_dsc_p = lv_obj_get_style_list(ext->indic, LV_OBJ_PART_MAIN); - break; - default: - style_dsc_p = NULL; + case LV_TABVIEW_PART_BG: + style_dsc_p = &tabview->style_list; + break; + case LV_TABVIEW_PART_BG_SCRL: + style_dsc_p = lv_obj_get_style_list(ext->content, LV_PAGE_PART_SCRL); + break; + case LV_TABVIEW_PART_TAB_BG: + style_dsc_p = lv_obj_get_style_list(ext->btns, LV_BTNMATRIX_PART_BG); + break; + case LV_TABVIEW_PART_TAB: + style_dsc_p = lv_obj_get_style_list(ext->btns, LV_BTNMATRIX_PART_BTN); + break; + case LV_TABVIEW_PART_INDIC: + style_dsc_p = lv_obj_get_style_list(ext->indic, LV_OBJ_PART_MAIN); + break; + default: + style_dsc_p = NULL; } return style_dsc_p; @@ -798,34 +817,36 @@ static void refr_indic_size(lv_obj_t * tabview) lv_coord_t indic_h; switch(ext->btns_pos) { - default: /*default case is prevented in lv_tabview_set_btns_pos(), but here for safety*/ - case LV_TABVIEW_BTNS_POS_NONE: - lv_obj_set_hidden(ext->indic, true); - indic_w = 0; - indic_h = 0; - break; - case LV_TABVIEW_BTNS_POS_TOP: - case LV_TABVIEW_BTNS_POS_BOTTOM: - lv_obj_set_hidden(ext->indic, false); - if(ext->tab_cnt) { - indic_h = indic_size; - indic_w = lv_area_get_width(&btnm_ext->button_areas[0]); - } else { + default: /*default case is prevented in lv_tabview_set_btns_pos(), but here for safety*/ + case LV_TABVIEW_BTNS_POS_NONE: + lv_obj_set_hidden(ext->indic, true); indic_w = 0; indic_h = 0; - } - break; - case LV_TABVIEW_BTNS_POS_LEFT: - case LV_TABVIEW_BTNS_POS_RIGHT: - lv_obj_set_hidden(ext->indic, false); - if(ext->tab_cnt) { - indic_w = indic_size; - indic_h = lv_area_get_height(&btnm_ext->button_areas[0]); - } else { - indic_w = 0; - indic_h = 0; - } - break; + break; + case LV_TABVIEW_BTNS_POS_TOP: + case LV_TABVIEW_BTNS_POS_BOTTOM: + lv_obj_set_hidden(ext->indic, false); + if(ext->tab_cnt) { + indic_h = indic_size; + indic_w = lv_area_get_width(&btnm_ext->button_areas[0]); + } + else { + indic_w = 0; + indic_h = 0; + } + break; + case LV_TABVIEW_BTNS_POS_LEFT: + case LV_TABVIEW_BTNS_POS_RIGHT: + lv_obj_set_hidden(ext->indic, false); + if(ext->tab_cnt) { + indic_w = indic_size; + indic_h = lv_area_get_height(&btnm_ext->button_areas[0]); + } + else { + indic_w = 0; + indic_h = 0; + } + break; } lv_obj_set_width(ext->indic, indic_w); @@ -854,26 +875,26 @@ static void refr_btns_size(lv_obj_t * tabview) lv_coord_t btns_h; switch(ext->btns_pos) { - default: /*default case is prevented in lv_tabview_set_btns_pos(), but here for safety*/ - case LV_TABVIEW_BTNS_POS_NONE: - btns_w = 0; - btns_h = 0; - lv_obj_set_hidden(ext->btns, true); - break; - case LV_TABVIEW_BTNS_POS_TOP: - case LV_TABVIEW_BTNS_POS_BOTTOM: - lv_obj_set_hidden(ext->btns, false); - btns_h = lv_font_get_line_height(font) + tab_top + tab_bottom + tab_bg_top + tab_bg_bottom; - btns_w = lv_obj_get_width(tabview); + default: /*default case is prevented in lv_tabview_set_btns_pos(), but here for safety*/ + case LV_TABVIEW_BTNS_POS_NONE: + btns_w = 0; + btns_h = 0; + lv_obj_set_hidden(ext->btns, true); + break; + case LV_TABVIEW_BTNS_POS_TOP: + case LV_TABVIEW_BTNS_POS_BOTTOM: + lv_obj_set_hidden(ext->btns, false); + btns_h = lv_font_get_line_height(font) + tab_top + tab_bottom + tab_bg_top + tab_bg_bottom; + btns_w = lv_obj_get_width(tabview); - break; - case LV_TABVIEW_BTNS_POS_LEFT: - case LV_TABVIEW_BTNS_POS_RIGHT: - lv_obj_set_hidden(ext->btns, false); - btns_w = lv_font_get_glyph_width(font, 'A', '\0') + - tab_left + tab_right + tab_bg_left + tab_bg_right; - btns_h = lv_obj_get_height(tabview); - break; + break; + case LV_TABVIEW_BTNS_POS_LEFT: + case LV_TABVIEW_BTNS_POS_RIGHT: + lv_obj_set_hidden(ext->btns, false); + btns_w = lv_font_get_glyph_width(font, 'A', '\0') + + tab_left + tab_right + tab_bg_left + tab_bg_right; + btns_h = lv_obj_get_height(tabview); + break; } lv_obj_set_size(ext->btns, btns_w, btns_h); @@ -886,21 +907,21 @@ static void refr_content_size(lv_obj_t * tabview) lv_coord_t cont_h; switch(ext->btns_pos) { - default: /*default case is prevented in lv_tabview_set_btns_pos(), but here for safety*/ - case LV_TABVIEW_BTNS_POS_NONE: - cont_w = lv_obj_get_width(tabview); - cont_h = lv_obj_get_height(tabview); - break; - case LV_TABVIEW_BTNS_POS_TOP: - case LV_TABVIEW_BTNS_POS_BOTTOM: - cont_w = lv_obj_get_width(tabview); - cont_h = lv_obj_get_height(tabview) - lv_obj_get_height(ext->btns); - break; - case LV_TABVIEW_BTNS_POS_LEFT: - case LV_TABVIEW_BTNS_POS_RIGHT: - cont_w = lv_obj_get_width(tabview) - lv_obj_get_width(ext->btns); - cont_h = lv_obj_get_height(tabview); - break; + default: /*default case is prevented in lv_tabview_set_btns_pos(), but here for safety*/ + case LV_TABVIEW_BTNS_POS_NONE: + cont_w = lv_obj_get_width(tabview); + cont_h = lv_obj_get_height(tabview); + break; + case LV_TABVIEW_BTNS_POS_TOP: + case LV_TABVIEW_BTNS_POS_BOTTOM: + cont_w = lv_obj_get_width(tabview); + cont_h = lv_obj_get_height(tabview) - lv_obj_get_height(ext->btns); + break; + case LV_TABVIEW_BTNS_POS_LEFT: + case LV_TABVIEW_BTNS_POS_RIGHT: + cont_w = lv_obj_get_width(tabview) - lv_obj_get_width(ext->btns); + cont_h = lv_obj_get_height(tabview); + break; } lv_obj_set_size(ext->content, cont_w, cont_h); @@ -925,30 +946,30 @@ static void refr_align(lv_obj_t * tabview) lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tabview); switch(ext->btns_pos) { - default: /*default case is prevented in lv_tabview_set_btns_pos(), but here for safety*/ - case LV_TABVIEW_BTNS_POS_NONE: - lv_obj_align(ext->content, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 0); - break; - case LV_TABVIEW_BTNS_POS_TOP: - lv_obj_align(ext->btns, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 0); - lv_obj_align(ext->content, ext->btns, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 0); - lv_obj_align(ext->indic, ext->btns, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0); - break; - case LV_TABVIEW_BTNS_POS_BOTTOM: - lv_obj_align(ext->content, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 0); - lv_obj_align(ext->btns, ext->content, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 0); - lv_obj_align(ext->indic, ext->btns, LV_ALIGN_IN_TOP_LEFT, 0, 0); - break; - case LV_TABVIEW_BTNS_POS_LEFT: - lv_obj_align(ext->btns, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 0); - lv_obj_align(ext->content, tabview, LV_ALIGN_IN_TOP_LEFT, lv_obj_get_width(ext->btns), 0); - lv_obj_align(ext->indic, ext->btns, LV_ALIGN_IN_TOP_RIGHT, 0, 0); - break; - case LV_TABVIEW_BTNS_POS_RIGHT: - lv_obj_align(ext->btns, NULL, LV_ALIGN_IN_TOP_RIGHT, 0, 0); - lv_obj_align(ext->content, tabview, LV_ALIGN_IN_TOP_LEFT, 0, 0); - lv_obj_align(ext->indic, ext->btns, LV_ALIGN_IN_TOP_LEFT, 0, 0); - break; + default: /*default case is prevented in lv_tabview_set_btns_pos(), but here for safety*/ + case LV_TABVIEW_BTNS_POS_NONE: + lv_obj_align(ext->content, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 0); + break; + case LV_TABVIEW_BTNS_POS_TOP: + lv_obj_align(ext->btns, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 0); + lv_obj_align(ext->content, ext->btns, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 0); + lv_obj_align(ext->indic, ext->btns, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0); + break; + case LV_TABVIEW_BTNS_POS_BOTTOM: + lv_obj_align(ext->content, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 0); + lv_obj_align(ext->btns, ext->content, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 0); + lv_obj_align(ext->indic, ext->btns, LV_ALIGN_IN_TOP_LEFT, 0, 0); + break; + case LV_TABVIEW_BTNS_POS_LEFT: + lv_obj_align(ext->btns, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 0); + lv_obj_align(ext->content, tabview, LV_ALIGN_IN_TOP_LEFT, lv_obj_get_width(ext->btns), 0); + lv_obj_align(ext->indic, ext->btns, LV_ALIGN_IN_TOP_RIGHT, 0, 0); + break; + case LV_TABVIEW_BTNS_POS_RIGHT: + lv_obj_align(ext->btns, NULL, LV_ALIGN_IN_TOP_RIGHT, 0, 0); + lv_obj_align(ext->content, tabview, LV_ALIGN_IN_TOP_LEFT, 0, 0); + lv_obj_align(ext->indic, ext->btns, LV_ALIGN_IN_TOP_LEFT, 0, 0); + break; } } #endif diff --git a/src/lv_widgets/lv_tabview.h b/src/lv_widgets/lv_tabview.h index 54649c26a..0d0ecb179 100644 --- a/src/lv_widgets/lv_tabview.h +++ b/src/lv_widgets/lv_tabview.h @@ -49,8 +49,7 @@ enum { typedef uint8_t lv_tabview_btns_pos_t; /*Data of tab*/ -typedef struct -{ +typedef struct { /*Ext. of ancestor*/ /*New data for this type */ lv_obj_t * btns; diff --git a/src/lv_widgets/lv_textarea.c b/src/lv_widgets/lv_textarea.c index 1a4c3f6c0..3ca34b073 100644 --- a/src/lv_widgets/lv_textarea.c +++ b/src/lv_widgets/lv_textarea.c @@ -26,11 +26,11 @@ /*Test configuration*/ #ifndef LV_TEXTAREA_DEF_CURSOR_BLINK_TIME -#define LV_TEXTAREA_DEF_CURSOR_BLINK_TIME 400 /*ms*/ + #define LV_TEXTAREA_DEF_CURSOR_BLINK_TIME 400 /*ms*/ #endif #ifndef LV_TEXTAREA_DEF_PWD_SHOW_TIME -#define LV_TEXTAREA_DEF_PWD_SHOW_TIME 1500 /*ms*/ + #define LV_TEXTAREA_DEF_PWD_SHOW_TIME 1500 /*ms*/ #endif #define LV_TEXTAREA_DEF_WIDTH (2 * LV_DPI) @@ -47,14 +47,15 @@ * STATIC PROTOTYPES **********************/ static lv_design_res_t lv_textarea_design(lv_obj_t * ta, const lv_area_t * clip_area, lv_design_mode_t mode); -static lv_design_res_t lv_textarea_scrollable_design(lv_obj_t * scrl, const lv_area_t * clip_area, lv_design_mode_t mode); +static lv_design_res_t lv_textarea_scrollable_design(lv_obj_t * scrl, const lv_area_t * clip_area, + lv_design_mode_t mode); static lv_res_t lv_textarea_signal(lv_obj_t * ta, lv_signal_t sign, void * param); static lv_res_t lv_textarea_scrollable_signal(lv_obj_t * scrl, lv_signal_t sign, void * param); static lv_style_list_t * lv_textarea_get_style(lv_obj_t * ta, uint8_t part); #if LV_USE_ANIMATION -static void cursor_blink_anim(lv_obj_t * ta, lv_anim_value_t show); -static void pwd_char_hider_anim(lv_obj_t * ta, lv_anim_value_t x); -static void pwd_char_hider_anim_ready(lv_anim_t * a); + static void cursor_blink_anim(lv_obj_t * ta, lv_anim_value_t show); + static void pwd_char_hider_anim(lv_obj_t * ta, lv_anim_value_t x); + static void pwd_char_hider_anim_ready(lv_anim_t * a); #endif static void pwd_char_hider(lv_obj_t * ta); static bool char_is_accepted(lv_obj_t * ta, uint32_t c); @@ -169,7 +170,7 @@ lv_obj_t * lv_textarea_create(lv_obj_t * par, const lv_obj_t * copy) lv_style_list_copy(&ext->cursor.style, ©_ext->cursor.style); lv_style_list_copy(&ext->style_placeholder, ©_ext->style_placeholder); - if(ext->pwd_mode != 0) pwd_char_hider( ta); + if(ext->pwd_mode != 0) pwd_char_hider(ta); if(copy_ext->placeholder_txt) { lv_textarea_set_placeholder_text(ta, copy_ext->placeholder_txt); @@ -494,7 +495,8 @@ void lv_textarea_set_text(lv_obj_t * ta, const char * txt) uint32_t c = lv_txt_encoded_next(txt, &i); lv_textarea_add_char(ta, lv_txt_unicode_to_encoded(c)); } - } else { + } + else { lv_label_set_text(ext->label, txt); lv_textarea_set_cursor_pos(ta, LV_TEXTAREA_CURSOR_LAST); } @@ -556,12 +558,14 @@ void lv_textarea_set_placeholder_text(lv_obj_t * ta, const char * txt) lv_mem_free(ext->placeholder_txt); ext->placeholder_txt = NULL; } - } else { + } + else { /*Allocate memory for the placeholder_txt text*/ if(ext->placeholder_txt == NULL) { ext->placeholder_txt = lv_mem_alloc(txt_len + 1); - } else { + } + else { ext->placeholder_txt = lv_mem_realloc(ext->placeholder_txt, txt_len + 1); } @@ -746,7 +750,8 @@ void lv_textarea_set_one_line(lv_obj_t * ta, bool en) lv_obj_set_height(ta, font_h + top + bottom); lv_label_set_long_mode(ext->label, LV_LABEL_LONG_EXPAND); lv_obj_set_pos(lv_page_get_scrl(ta), left, top); - } else { + } + else { lv_style_int_t top = lv_obj_get_style_pad_top(ta, LV_TEXTAREA_PART_BG); lv_style_int_t left = lv_obj_get_style_pad_left(ta, LV_TEXTAREA_PART_BG); ext->one_line = 0; @@ -776,7 +781,8 @@ void lv_textarea_set_text_align(lv_obj_t * ta, lv_label_align_t align) lv_obj_t * label = lv_textarea_get_label(ta); if(!ext->one_line) { lv_label_set_align(label, align); - } else { + } + else { /*Normal left align. Just let the text expand*/ if(align == LV_LABEL_ALIGN_LEFT) { lv_label_set_long_mode(label, LV_LABEL_LONG_EXPAND); @@ -905,7 +911,8 @@ void lv_textarea_set_cursor_blink_time(lv_obj_t * ta, uint16_t time) lv_anim_set_values(&a, 1, 0); lv_anim_set_path_cb(&a, lv_anim_path_step); lv_anim_start(&a); - } else { + } + else { lv_anim_del(ta, (lv_anim_exec_xcb_t)cursor_blink_anim); ext->cursor.state = 1; } @@ -932,7 +939,8 @@ const char * lv_textarea_get_text(const lv_obj_t * ta) const char * txt; if(ext->pwd_mode == 0) { txt = lv_label_get_text(ext->label); - } else { + } + else { txt = ext->pwd_tmp; } @@ -1073,7 +1081,8 @@ bool lv_textarea_text_is_selected(const lv_obj_t * ta) if((lv_label_get_text_sel_start(ext->label) == LV_DRAW_LABEL_NO_TXT_SEL || lv_label_get_text_sel_end(ext->label) == LV_DRAW_LABEL_NO_TXT_SEL)) { return true; - } else { + } + else { return false; } #else @@ -1260,11 +1269,13 @@ static lv_design_res_t lv_textarea_design(lv_obj_t * ta, const lv_area_t * clip_ if(mode == LV_DESIGN_COVER_CHK) { /*Return false if the object is not covers the mask_p area*/ return ancestor_design(ta, clip_area, mode); - } else if(mode == LV_DESIGN_DRAW_MAIN) { + } + else if(mode == LV_DESIGN_DRAW_MAIN) { /*Draw the object*/ ancestor_design(ta, clip_area, mode); - } else if(mode == LV_DESIGN_DRAW_POST) { + } + else if(mode == LV_DESIGN_DRAW_POST) { ancestor_design(ta, clip_area, mode); } return LV_DESIGN_RES_OK; @@ -1280,15 +1291,18 @@ static lv_design_res_t lv_textarea_design(lv_obj_t * ta, const lv_area_t * clip_ * LV_DESIGN_DRAW_POST: drawing after every children are drawn * @return return true/false, depends on 'mode' */ -static lv_design_res_t lv_textarea_scrollable_design(lv_obj_t * scrl, const lv_area_t * clip_area, lv_design_mode_t mode) +static lv_design_res_t lv_textarea_scrollable_design(lv_obj_t * scrl, const lv_area_t * clip_area, + lv_design_mode_t mode) { if(mode == LV_DESIGN_COVER_CHK) { /*Return false if the object is not covers the mask_p area*/ return scrl_design(scrl, clip_area, mode); - } else if(mode == LV_DESIGN_DRAW_MAIN) { + } + else if(mode == LV_DESIGN_DRAW_MAIN) { /*Draw the object*/ scrl_design(scrl, clip_area, mode); - } else if(mode == LV_DESIGN_DRAW_POST) { + } + else if(mode == LV_DESIGN_DRAW_POST) { scrl_design(scrl, clip_area, mode); lv_obj_t * ta = lv_obj_get_parent(scrl); @@ -1301,14 +1315,14 @@ static lv_design_res_t lv_textarea_scrollable_design(lv_obj_t * scrl, const lv_a lv_draw_label_dsc_init(&ph_dsc); lv_obj_init_draw_label_dsc(ta, LV_TEXTAREA_PART_PLACEHOLDER, &ph_dsc); switch(lv_label_get_align(ext->label)) { - case LV_LABEL_ALIGN_CENTER: - ph_dsc.flag |= LV_TXT_FLAG_CENTER; - break; - case LV_LABEL_ALIGN_RIGHT: - ph_dsc.flag |= LV_TXT_FLAG_RIGHT; - break; - default: - break; + case LV_LABEL_ALIGN_CENTER: + ph_dsc.flag |= LV_TXT_FLAG_CENTER; + break; + case LV_LABEL_ALIGN_RIGHT: + ph_dsc.flag |= LV_TXT_FLAG_RIGHT; + break; + default: + break; } lv_draw_label(&scrl->coords, clip_area, &ph_dsc, ext->placeholder_txt, NULL); @@ -1316,7 +1330,7 @@ static lv_design_res_t lv_textarea_scrollable_design(lv_obj_t * scrl, const lv_a /*Draw the cursor*/ - if(ext->cursor.hidden|| ext->cursor.state == 0) { + if(ext->cursor.hidden || ext->cursor.state == 0) { return LV_DESIGN_RES_OK; /*The cursor is not visible now*/ } @@ -1369,7 +1383,8 @@ static lv_res_t lv_textarea_signal(lv_obj_t * ta, lv_signal_t sign, void * param info->result = lv_textarea_get_style(ta, info->part); if(info->result != NULL) return LV_RES_OK; else return ancestor_signal(ta, sign, param); - } else if(sign == LV_SIGNAL_GET_STATE_DSC) { + } + else if(sign == LV_SIGNAL_GET_STATE_DSC) { return ancestor_signal(ta, sign, param); } @@ -1391,7 +1406,8 @@ static lv_res_t lv_textarea_signal(lv_obj_t * ta, lv_signal_t sign, void * param /* (The created label will be deleted automatically) */ - } else if(sign == LV_SIGNAL_STYLE_CHG) { + } + else if(sign == LV_SIGNAL_STYLE_CHG) { if(ext->label) { if(ext->one_line) { lv_style_int_t top = lv_obj_get_style_pad_top(ta, LV_TEXTAREA_PART_BG); @@ -1402,7 +1418,8 @@ static lv_res_t lv_textarea_signal(lv_obj_t * ta, lv_signal_t sign, void * param lv_coord_t font_h = lv_font_get_line_height(font); lv_obj_set_height(ext->label, font_h); lv_obj_set_height(ta, font_h + top + bottom); - } else { + } + else { /*In not one line mode refresh the Label width because 'hpad' can modify it*/ lv_obj_set_width(ext->label, lv_page_get_fit_width(ta)); lv_obj_set_pos(ext->label, 0, 0); /*Be sure the Label is in the correct position*/ @@ -1411,7 +1428,8 @@ static lv_res_t lv_textarea_signal(lv_obj_t * ta, lv_signal_t sign, void * param lv_label_set_text(ext->label, NULL); refr_cursor_area(ta); } - } else if(sign == LV_SIGNAL_COORD_CHG) { + } + else if(sign == LV_SIGNAL_COORD_CHG) { /*Set the label width according to the text area width*/ if(ext->label) { if(lv_obj_get_width(ta) != lv_area_get_width(param) || lv_obj_get_height(ta) != lv_area_get_height(param)) { @@ -1422,7 +1440,8 @@ static lv_res_t lv_textarea_signal(lv_obj_t * ta, lv_signal_t sign, void * param refr_cursor_area(ta); } } - } else if(sign == LV_SIGNAL_CONTROL) { + } + else if(sign == LV_SIGNAL_CONTROL) { uint32_t c = *((uint32_t *)param); /*uint32_t because can be UTF-8*/ if(c == LV_KEY_RIGHT) lv_textarea_cursor_right(ta); @@ -1443,16 +1462,19 @@ static lv_res_t lv_textarea_signal(lv_obj_t * ta, lv_signal_t sign, void * param else { lv_textarea_add_char(ta, c); } - } else if(sign == LV_SIGNAL_GET_EDITABLE) { + } + else if(sign == LV_SIGNAL_GET_EDITABLE) { bool * editable = (bool *)param; *editable = true; - } else if(sign == LV_SIGNAL_DEFOCUS) { + } + else if(sign == LV_SIGNAL_DEFOCUS) { #if LV_USE_GROUP if(lv_obj_get_group(ta)) { lv_textarea_set_cursor_hidden(ta, true); } #endif - } else if(sign == LV_SIGNAL_FOCUS) { + } + else if(sign == LV_SIGNAL_FOCUS) { #if LV_USE_GROUP lv_group_t * g = lv_obj_get_group(ta); bool editing = lv_group_get_editing(g); @@ -1462,12 +1484,14 @@ static lv_res_t lv_textarea_signal(lv_obj_t * ta, lv_signal_t sign, void * param if(indev_type == LV_INDEV_TYPE_ENCODER) { if(editing) lv_textarea_set_cursor_hidden(ta, false); else lv_textarea_set_cursor_hidden(ta, true); - } else { + } + else { lv_textarea_set_cursor_hidden(ta, false); } #endif - } else if(sign == LV_SIGNAL_PRESSED || sign == LV_SIGNAL_PRESSING || sign == LV_SIGNAL_PRESS_LOST || - sign == LV_SIGNAL_RELEASED) { + } + else if(sign == LV_SIGNAL_PRESSED || sign == LV_SIGNAL_PRESSING || sign == LV_SIGNAL_PRESS_LOST || + sign == LV_SIGNAL_RELEASED) { update_cursor_position_on_click(ta, sign, (lv_indev_t *)param); } return res; @@ -1499,7 +1523,8 @@ static lv_res_t lv_textarea_scrollable_signal(lv_obj_t * scrl, lv_signal_t sign, const lv_font_t * font = lv_obj_get_style_text_font(ta, LV_TEXTAREA_PART_BG); lv_coord_t font_h = lv_font_get_line_height(font); scrl->ext_draw_pad = LV_MATH_MAX(scrl->ext_draw_pad, line_space + font_h); - } else if(sign == LV_SIGNAL_COORD_CHG) { + } + else if(sign == LV_SIGNAL_COORD_CHG) { /*Set the label width according to the text area width*/ if(ext->label) { if(lv_obj_get_width(scrl) != lv_area_get_width(param) || @@ -1514,8 +1539,9 @@ static lv_res_t lv_textarea_scrollable_signal(lv_obj_t * scrl, lv_signal_t sign, } - } else if(sign == LV_SIGNAL_PRESSING || sign == LV_SIGNAL_PRESSED || sign == LV_SIGNAL_PRESS_LOST || - sign == LV_SIGNAL_RELEASED) { + } + else if(sign == LV_SIGNAL_PRESSING || sign == LV_SIGNAL_PRESSED || sign == LV_SIGNAL_PRESS_LOST || + sign == LV_SIGNAL_RELEASED) { update_cursor_position_on_click(ta, sign, (lv_indev_t *)param); } @@ -1536,25 +1562,25 @@ static lv_style_list_t * lv_textarea_get_style(lv_obj_t * ta, uint8_t part) lv_style_list_t * style_dsc_p; switch(part) { - case LV_TEXTAREA_PART_BG: - style_dsc_p = &ta->style_list; - break; - case LV_TEXTAREA_PART_SCRLBAR: - style_dsc_p = &ext->page.scrlbar.style; - break; - case LV_TEXTAREA_PART_CURSOR: - style_dsc_p = &ext->cursor.style; - break; + case LV_TEXTAREA_PART_BG: + style_dsc_p = &ta->style_list; + break; + case LV_TEXTAREA_PART_SCRLBAR: + style_dsc_p = &ext->page.scrlbar.style; + break; + case LV_TEXTAREA_PART_CURSOR: + style_dsc_p = &ext->cursor.style; + break; #if LV_USE_ANIMATION - case LV_TEXTAREA_PART_EDGE_FLASH: - style_dsc_p = &ext->page.edge_flash.style; - break; + case LV_TEXTAREA_PART_EDGE_FLASH: + style_dsc_p = &ext->page.edge_flash.style; + break; #endif - case LV_TEXTAREA_PART_PLACEHOLDER: - style_dsc_p = &ext->style_placeholder; - break; - default: - style_dsc_p = NULL; + case LV_TEXTAREA_PART_PLACEHOLDER: + style_dsc_p = &ext->style_placeholder; + break; + default: + style_dsc_p = NULL; } return style_dsc_p; @@ -1671,7 +1697,8 @@ static bool char_is_accepted(lv_obj_t * ta, uint32_t c) } return false; /*The character wasn't in the list*/ - } else { + } + else { return true; /*If the accepted char list in not specified the accept the character*/ } } @@ -1698,7 +1725,8 @@ static void refr_cursor_area(lv_obj_t * ta) lv_coord_t letter_w; if(letter == '\0' || letter == '\n' || letter == '\r') { letter_w = lv_font_get_glyph_width(font, ' ', '\0'); - } else { + } + else { /*`letter_next` parameter is '\0' to ignore kerning*/ letter_w = lv_font_get_glyph_width(font, letter, '\0'); } @@ -1719,7 +1747,8 @@ static void refr_cursor_area(lv_obj_t * ta) if(letter == '\0' || letter == '\n' || letter == '\r') { letter_w = lv_font_get_glyph_width(font, ' ', '\0'); - } else { + } + else { letter_w = lv_font_get_glyph_width(font, letter, '\0'); } } @@ -1800,7 +1829,8 @@ static void update_cursor_position_on_click(lv_obj_t * ta, lv_signal_t sign, lv_ else if(rel_pos.x >= label_width) { char_id_at_click = LV_TEXTAREA_CURSOR_LAST; click_outside_label = true; - } else { + } + else { char_id_at_click = lv_label_get_letter_on(ext->label, &rel_pos); click_outside_label = !lv_label_is_char_under_pos(ext->label, &rel_pos); } @@ -1812,10 +1842,12 @@ static void update_cursor_position_on_click(lv_obj_t * ta, lv_signal_t sign, lv_ ext->sel_end = LV_LABEL_TEXT_SEL_OFF; ext->text_sel_in_prog = 1; lv_obj_set_drag(lv_page_get_scrl(ta), false); - } else if(ext->text_sel_in_prog && sign == LV_SIGNAL_PRESSING) { + } + else if(ext->text_sel_in_prog && sign == LV_SIGNAL_PRESSING) { /*Input device may be moving. Store the end position */ ext->sel_end = char_id_at_click; - } else if(ext->text_sel_in_prog && (sign == LV_SIGNAL_PRESS_LOST || sign == LV_SIGNAL_RELEASED)) { + } + else if(ext->text_sel_in_prog && (sign == LV_SIGNAL_PRESS_LOST || sign == LV_SIGNAL_RELEASED)) { /*Input device is released. Check if anything was selected.*/ lv_obj_set_drag(lv_page_get_scrl(ta), true); } @@ -1833,13 +1865,15 @@ static void update_cursor_position_on_click(lv_obj_t * ta, lv_signal_t sign, lv_ ext_label->sel_end = ext->sel_start; lv_obj_invalidate(ta); } - } else if(ext->sel_start < ext->sel_end) { + } + else if(ext->sel_start < ext->sel_end) { if(ext_label->sel_start != ext->sel_start || ext_label->sel_end != ext->sel_end) { ext_label->sel_start = ext->sel_start; ext_label->sel_end = ext->sel_end; lv_obj_invalidate(ta); } - } else { + } + else { if(ext_label->sel_start != LV_DRAW_LABEL_NO_TXT_SEL || ext_label->sel_end != LV_DRAW_LABEL_NO_TXT_SEL) { ext_label->sel_start = LV_DRAW_LABEL_NO_TXT_SEL; ext_label->sel_end = LV_DRAW_LABEL_NO_TXT_SEL; @@ -1859,7 +1893,8 @@ static void update_cursor_position_on_click(lv_obj_t * ta, lv_signal_t sign, lv_ /*Check if the click happened on the right side of the area outside the label*/ else if(rel_pos.x >= label_width) { char_id_at_click = LV_TEXTAREA_CURSOR_LAST; - } else { + } + else { char_id_at_click = lv_label_get_letter_on(ext->label, &rel_pos); } diff --git a/src/lv_widgets/lv_textarea.h b/src/lv_widgets/lv_textarea.h index 24fa58f1a..0febaa444 100644 --- a/src/lv_widgets/lv_textarea.h +++ b/src/lv_widgets/lv_textarea.h @@ -42,8 +42,7 @@ LV_EXPORT_CONST_INT(LV_TEXTAREA_CURSOR_LAST); **********************/ /*Data of text area*/ -typedef struct -{ +typedef struct { lv_page_ext_t page; /*Ext. of ancestor*/ /*New data for this type */ lv_obj_t * label; /*Label of the text area*/ @@ -53,8 +52,7 @@ typedef struct const char * accapted_chars; /*Only these characters will be accepted. NULL: accept all*/ uint16_t max_length; /*The max. number of characters. 0: no limit*/ uint16_t pwd_show_time; /*Time to show characters in password mode before change them to '*' */ - struct - { + struct { lv_style_list_t style; /* Style of the cursor (NULL to use label's style)*/ lv_coord_t valid_x; /* Used when stepping up/down to a shorter line. * (Used by the library)*/ diff --git a/src/lv_widgets/lv_tileview.c b/src/lv_widgets/lv_tileview.c index b25f0108c..2365550bf 100644 --- a/src/lv_widgets/lv_tileview.c +++ b/src/lv_widgets/lv_tileview.c @@ -21,12 +21,12 @@ #define LV_OBJX_NAME "lv_tileview" #if LV_USE_ANIMATION -#ifndef LV_TILEVIEW_DEF_ANIM_TIME -#define LV_TILEVIEW_DEF_ANIM_TIME 300 /*Animation time loading a tile [ms] (0: no animation) */ -#endif + #ifndef LV_TILEVIEW_DEF_ANIM_TIME + #define LV_TILEVIEW_DEF_ANIM_TIME 300 /*Animation time loading a tile [ms] (0: no animation) */ + #endif #else -#undef LV_TILEVIEW_DEF_ANIM_TIME -#define LV_TILEVIEW_DEF_ANIM_TIME 0 /*No animations*/ + #undef LV_TILEVIEW_DEF_ANIM_TIME + #define LV_TILEVIEW_DEF_ANIM_TIME 0 /*No animations*/ #endif /********************** @@ -106,7 +106,8 @@ lv_obj_t * lv_tileview_create(lv_obj_t * par, const lv_obj_t * copy) if(par) { w = lv_obj_get_width_fit(lv_obj_get_parent(new_tileview)); h = lv_obj_get_height_fit(lv_obj_get_parent(new_tileview)); - } else { + } + else { w = lv_disp_get_hor_res(NULL); h = lv_disp_get_ver_res(NULL); } @@ -247,12 +248,13 @@ void lv_tileview_set_tile_act(lv_obj_t * tileview, lv_coord_t x, lv_coord_t y, l } if(y_coord != y_act) { - lv_anim_set_exec_cb(&a,(lv_anim_exec_xcb_t)lv_obj_set_y); + lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)lv_obj_set_y); lv_anim_set_values(&a, y_act, y_coord); lv_anim_start(&a); } #endif - } else { + } + else { lv_obj_set_pos(scrl, x_coord, y_coord); } @@ -276,7 +278,7 @@ void lv_tileview_set_tile_act(lv_obj_t * tileview, lv_coord_t x, lv_coord_t y, l * @param x column id (0, 1, 2...) * @param y line id (0, 1, 2...) */ -void lv_tileview_get_tile_act(lv_obj_t * tileview, lv_coord_t *x, lv_coord_t *y) +void lv_tileview_get_tile_act(lv_obj_t * tileview, lv_coord_t * x, lv_coord_t * y) { lv_tileview_ext_t * ext = lv_obj_get_ext_attr(tileview); @@ -419,7 +421,8 @@ static void drag_end_handler(lv_obj_t * tileview) p.x -= predict; - } else if(drag_dir & LV_DRAG_DIR_VER) { + } + else if(drag_dir & LV_DRAG_DIR_VER) { lv_point_t vect; lv_indev_get_vect(indev, &vect); lv_coord_t predict = 0; diff --git a/src/lv_widgets/lv_tileview.h b/src/lv_widgets/lv_tileview.h index a3218947e..5b0b3e619 100644 --- a/src/lv_widgets/lv_tileview.h +++ b/src/lv_widgets/lv_tileview.h @@ -28,8 +28,7 @@ extern "C" { **********************/ /*Data of tileview*/ -typedef struct -{ +typedef struct { lv_page_ext_t page; /*New data for this type */ const lv_point_t * valid_pos; @@ -127,7 +126,7 @@ static inline void lv_tileview_set_anim_time(lv_obj_t * tileview, uint16_t anim_ * @param x column id (0, 1, 2...) * @param y line id (0, 1, 2...) */ -void lv_tileview_get_tile_act(lv_obj_t * tileview, lv_coord_t *x, lv_coord_t *y); +void lv_tileview_get_tile_act(lv_obj_t * tileview, lv_coord_t * x, lv_coord_t * y); /** * Get the scroll propagation property * @param tileview pointer to a Tileview diff --git a/src/lv_widgets/lv_win.c b/src/lv_widgets/lv_win.c index 13480c83c..81a018499 100644 --- a/src/lv_widgets/lv_win.c +++ b/src/lv_widgets/lv_win.c @@ -85,7 +85,8 @@ lv_obj_t * lv_win_create(lv_obj_t * par, const lv_obj_t * copy) if(par) { w = lv_obj_get_width_fit(lv_obj_get_parent(new_win)); h = lv_obj_get_height_fit(lv_obj_get_parent(new_win)); - } else { + } + else { w = lv_disp_get_hor_res(NULL); h = lv_disp_get_ver_res(NULL); } @@ -102,7 +103,7 @@ lv_obj_t * lv_win_create(lv_obj_t * par, const lv_obj_t * copy) /*Move back to window background because it's automatically moved to the content page*/ lv_obj_add_protect(ext->header, LV_PROTECT_PARENT); lv_obj_set_parent(ext->header, new_win); - if(ancestor_header_design == NULL) ancestor_header_design= lv_obj_get_design_cb(ext->header); + if(ancestor_header_design == NULL) ancestor_header_design = lv_obj_get_design_cb(ext->header); lv_obj_set_height(ext->header, LV_DPI / 2); lv_obj_set_design_cb(ext->header, lv_win_header_design); @@ -475,7 +476,8 @@ static lv_design_res_t lv_win_header_design(lv_obj_t * header, const lv_area_t * lv_point_t txt_size; - lv_txt_get_size(&txt_size, ext->title_txt, label_dsc.font, label_dsc.letter_space, label_dsc.line_space, LV_COORD_MAX, label_dsc.flag); + lv_txt_get_size(&txt_size, ext->title_txt, label_dsc.font, label_dsc.letter_space, label_dsc.line_space, LV_COORD_MAX, + label_dsc.flag); txt_area.x1 = header->coords.x1 + left; txt_area.y1 = header->coords.y1 + (lv_obj_get_height(header) - txt_size.y) / 2; @@ -483,7 +485,8 @@ static lv_design_res_t lv_win_header_design(lv_obj_t * header, const lv_area_t * txt_area.y2 = txt_area.y1 + txt_size.y; lv_draw_label(&txt_area, clip_area, &label_dsc, ext->title_txt, NULL); - } else if(mode == LV_DESIGN_DRAW_POST) { + } + else if(mode == LV_DESIGN_DRAW_POST) { ancestor_header_design(header, clip_area, mode); } @@ -505,10 +508,12 @@ static lv_res_t lv_win_signal(lv_obj_t * win, lv_signal_t sign, void * param) info->result = lv_win_get_style(win, info->part); if(info->result != NULL) return LV_RES_OK; else return ancestor_signal(win, sign, param); - } else if(sign == LV_SIGNAL_GET_STATE_DSC) { + } + else if(sign == LV_SIGNAL_GET_STATE_DSC) { lv_win_ext_t * ext = lv_obj_get_ext_attr(win); lv_get_state_info_t * info = param; - if(info->part == LV_WIN_PART_CONTENT_SCRL) info->result = lv_obj_get_state(lv_page_get_scrl(ext->page), LV_CONT_PART_MAIN); + if(info->part == LV_WIN_PART_CONTENT_SCRL) info->result = lv_obj_get_state(lv_page_get_scrl(ext->page), + LV_CONT_PART_MAIN); else if(info->part == LV_WIN_PART_SCRLBAR) info->result = lv_obj_get_state(ext->page, LV_PAGE_PART_SCRLBAR); else if(info->part == LV_WIN_PART_HEADER) info->result = lv_obj_get_state(ext->header, LV_OBJ_PART_MAIN); return LV_RES_OK; @@ -530,24 +535,29 @@ static lv_res_t lv_win_signal(lv_obj_t * win, lv_signal_t sign, void * param) lv_obj_t * tmp = child; child = lv_obj_get_child(win, child); /*Get the next child before move this*/ lv_obj_set_parent(tmp, page); - } else { + } + else { child = lv_obj_get_child(win, child); } } } - } else if(sign == LV_SIGNAL_STYLE_CHG) { + } + else if(sign == LV_SIGNAL_STYLE_CHG) { lv_win_realign(win); - } else if(sign == LV_SIGNAL_COORD_CHG) { + } + else if(sign == LV_SIGNAL_COORD_CHG) { /*If the size is changed refresh the window*/ if(lv_area_get_width(param) != lv_obj_get_width(win) || lv_area_get_height(param) != lv_obj_get_height(win)) { lv_win_realign(win); } - } else if(sign == LV_SIGNAL_CLEANUP) { + } + else if(sign == LV_SIGNAL_CLEANUP) { ext->header = NULL; /*These objects were children so they are already invalid*/ ext->page = NULL; lv_mem_free(ext->title_txt); ext->title_txt = NULL; - } else if(sign == LV_SIGNAL_CONTROL) { + } + else if(sign == LV_SIGNAL_CONTROL) { /*Forward all the control signals to the page*/ ext->page->signal_cb(ext->page, sign, param); } @@ -568,20 +578,20 @@ static lv_style_list_t * lv_win_get_style(lv_obj_t * win, uint8_t part) lv_style_list_t * style_dsc_p; switch(part) { - case LV_WIN_PART_BG: - style_dsc_p = &win->style_list; - break; - case LV_WIN_PART_HEADER: - style_dsc_p = lv_obj_get_style_list(ext->header, LV_OBJ_PART_MAIN); - break; - case LV_WIN_PART_SCRLBAR: - style_dsc_p = lv_obj_get_style_list(ext->page, LV_PAGE_PART_SCRLBAR); - break; - case LV_WIN_PART_CONTENT_SCRL: - style_dsc_p = lv_obj_get_style_list(ext->page, LV_PAGE_PART_SCRL); - break; - default: - style_dsc_p = NULL; + case LV_WIN_PART_BG: + style_dsc_p = &win->style_list; + break; + case LV_WIN_PART_HEADER: + style_dsc_p = lv_obj_get_style_list(ext->header, LV_OBJ_PART_MAIN); + break; + case LV_WIN_PART_SCRLBAR: + style_dsc_p = lv_obj_get_style_list(ext->page, LV_PAGE_PART_SCRLBAR); + break; + case LV_WIN_PART_CONTENT_SCRL: + style_dsc_p = lv_obj_get_style_list(ext->page, LV_PAGE_PART_SCRL); + break; + default: + style_dsc_p = NULL; } return style_dsc_p; @@ -609,7 +619,8 @@ static void lv_win_realign(lv_obj_t * win) lv_obj_set_size(btn, btn_size, btn_size); if(btn_prev == NULL) { lv_obj_align(btn, ext->header, LV_ALIGN_IN_RIGHT_MID, -header_right, 0); - } else { + } + else { lv_obj_align(btn, btn_prev, LV_ALIGN_OUT_LEFT_MID, - header_inner, 0); } btn_prev = btn; diff --git a/src/lv_widgets/lv_win.h b/src/lv_widgets/lv_win.h index edfba1ce9..124f2b1f6 100644 --- a/src/lv_widgets/lv_win.h +++ b/src/lv_widgets/lv_win.h @@ -50,8 +50,7 @@ extern "C" { **********************/ /*Data of window*/ -typedef struct -{ +typedef struct { /*Ext. of ancestor*/ /*New data for this type */ lv_obj_t * page; /*Pointer to a page which holds the content*/ @@ -62,11 +61,11 @@ typedef struct /** Window parts. */ enum { LV_WIN_PART_BG = LV_OBJ_PART_MAIN, /**< Window object background style. */ - _LV_WIN_PART_VIRTUAL_LAST, + _LV_WIN_PART_VIRTUAL_LAST, LV_WIN_PART_HEADER = _LV_OBJ_PART_REAL_LAST, /**< Window titlebar background style. */ LV_WIN_PART_CONTENT_SCRL, /**< Window content style. */ LV_WIN_PART_SCRLBAR, /**< Window scrollbar style. */ - _LV_WIN_PART_REAL_LAST + _LV_WIN_PART_REAL_LAST }; /**********************