diff --git a/src/lv_core/lv_obj.c b/src/lv_core/lv_obj.c index 0b0f40944..4496d0d0b 100644 --- a/src/lv_core/lv_obj.c +++ b/src/lv_core/lv_obj.c @@ -180,9 +180,12 @@ void lv_deinit(void) * Create a basic object * @param parent pointer to a parent object. * If NULL then a screen will be created + * + * @param copy DEPRECATED, will be removed in v9. + * Pointer to an other base object to copy. * @return pointer to the new object */ -lv_obj_t * lv_obj_create(lv_obj_t * parent) +lv_obj_t * lv_obj_create(lv_obj_t * parent, lv_obj_t * copy) { lv_obj_t * new_obj = NULL; @@ -290,9 +293,47 @@ lv_obj_t * lv_obj_create(lv_obj_t * parent) new_obj->ext_attr = NULL; lv_style_list_init(&new_obj->style_list); - if(parent != NULL) lv_theme_apply(new_obj, LV_THEME_OBJ); - else lv_theme_apply(new_obj, LV_THEME_SCR); + lv_style_list_init(&new_obj->style_list); + if(copy == NULL) { + if(parent != NULL) lv_theme_apply(new_obj, LV_THEME_OBJ); + else lv_theme_apply(new_obj, LV_THEME_SCR); + } + else { + lv_style_list_copy(&new_obj->style_list, ©->style_list); + } + /*Copy the attributes if required*/ + if(copy != NULL) { + lv_area_copy(&new_obj->coords, ©->coords); + new_obj->ext_draw_pad = copy->ext_draw_pad; + #if LV_USE_EXT_CLICK_AREA == LV_EXT_CLICK_AREA_FULL + lv_area_copy(&new_obj->ext_click_pad, ©->ext_click_pad); + #elif LV_USE_EXT_CLICK_AREA == LV_EXT_CLICK_AREA_TINY + new_obj->ext_click_pad = copy->ext_click_pad; + #endif + + /*Set user data*/ + #if LV_USE_USER_DATA + _lv_memcpy(&new_obj->user_data, ©->user_data, sizeof(lv_obj_user_data_t)); + #endif + /*Only copy the `event_cb`. `signal_cb` and `design_cb` will be copied in the derived + * object type (e.g. `lv_btn`)*/ + new_obj->event_cb = copy->event_cb; + + new_obj->flags = copy->flags; + + #if LV_USE_GROUP + /*Add to the same group*/ + if(copy->group_p != NULL) { + lv_group_add_obj(copy->group_p, new_obj); + } + #endif + + /*Set the same coordinates for non screen objects*/ + if(lv_obj_get_parent(copy) != NULL && parent != NULL) { + lv_obj_set_pos(new_obj, lv_obj_get_x(copy), lv_obj_get_y(copy)); + } + } lv_obj_set_pos(new_obj, 0, 0); /*Send a signal to the parent to notify it about the new child*/ diff --git a/src/lv_core/lv_obj.h b/src/lv_core/lv_obj.h index 3f5477379..c663a0b3a 100644 --- a/src/lv_core/lv_obj.h +++ b/src/lv_core/lv_obj.h @@ -308,9 +308,12 @@ void lv_deinit(void); * Create a basic object * @param parent pointer to a parent object. * If NULL then a screen will be created + * + * @param copy DEPRECATED, will be removed in v9. + * Pointer to an other base object to copy. * @return pointer to the new object */ -lv_obj_t * lv_obj_create(lv_obj_t * parent); +lv_obj_t * lv_obj_create(lv_obj_t * parent, lv_obj_t * copy); /** * Delete 'obj' and all of its children diff --git a/src/lv_hal/lv_hal_disp.c b/src/lv_hal/lv_hal_disp.c index fac9f1a0b..3e7a33c67 100644 --- a/src/lv_hal/lv_hal_disp.c +++ b/src/lv_hal/lv_hal_disp.c @@ -153,9 +153,9 @@ lv_disp_t * lv_disp_drv_register(lv_disp_drv_t * driver) #endif disp->prev_scr = NULL; - disp->act_scr = lv_obj_create(NULL); /*Create a default screen on the display*/ - disp->top_layer = lv_obj_create(NULL); /*Create top layer on the display*/ - disp->sys_layer = lv_obj_create(NULL); /*Create sys layer on the display*/ + disp->act_scr = lv_obj_create(NULL, NULL); /*Create a default screen on the display*/ + disp->top_layer = lv_obj_create(NULL, NULL); /*Create top layer on the display*/ + disp->sys_layer = lv_obj_create(NULL, NULL); /*Create sys layer on the display*/ lv_obj_reset_style_list(disp->top_layer, LV_OBJ_PART_MAIN); lv_obj_reset_style_list(disp->sys_layer, LV_OBJ_PART_MAIN); lv_obj_clear_flag(disp->top_layer, LV_OBJ_FLAG_CLICKABLE); diff --git a/src/lv_themes/lv_theme.c b/src/lv_themes/lv_theme.c index e5db6d723..08b7fc8d8 100644 --- a/src/lv_themes/lv_theme.c +++ b/src/lv_themes/lv_theme.c @@ -239,14 +239,14 @@ static void clear_styles(lv_obj_t * obj, lv_theme_style_t name) #if LV_USE_BAR case LV_THEME_BAR: - _lv_obj_reset_style_list_no_refr(obj, LV_BAR_PART_BG); + _lv_obj_reset_style_list_no_refr(obj, LV_BAR_PART_MAIN); _lv_obj_reset_style_list_no_refr(obj, LV_BAR_PART_INDIC); break; #endif #if LV_USE_SWITCH case LV_THEME_SWITCH: - _lv_obj_reset_style_list_no_refr(obj, LV_SWITCH_PART_BG); + _lv_obj_reset_style_list_no_refr(obj, LV_SWITCH_PART_MAIN); _lv_obj_reset_style_list_no_refr(obj, LV_SWITCH_PART_INDIC); _lv_obj_reset_style_list_no_refr(obj, LV_SWITCH_PART_KNOB); break; @@ -298,7 +298,7 @@ static void clear_styles(lv_obj_t * obj, lv_theme_style_t name) #if LV_USE_SLIDER case LV_THEME_SLIDER: - _lv_obj_reset_style_list_no_refr(obj, LV_SLIDER_PART_BG); + _lv_obj_reset_style_list_no_refr(obj, LV_SLIDER_PART_MAIN); _lv_obj_reset_style_list_no_refr(obj, LV_SLIDER_PART_INDIC); _lv_obj_reset_style_list_no_refr(obj, LV_SLIDER_PART_KNOB); break; diff --git a/src/lv_themes/lv_theme_material.c b/src/lv_themes/lv_theme_material.c index 09e4ba037..ca6b3e460 100644 --- a/src/lv_themes/lv_theme_material.c +++ b/src/lv_themes/lv_theme_material.c @@ -1019,7 +1019,7 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj, lv_theme_style_t name) #if LV_USE_BAR case LV_THEME_BAR: - list = _lv_obj_get_style_list(obj, LV_BAR_PART_BG); + list = _lv_obj_get_style_list(obj, LV_BAR_PART_MAIN); _lv_style_list_add_style(list, &styles->bar_bg); list = _lv_obj_get_style_list(obj, LV_BAR_PART_INDIC); @@ -1029,7 +1029,7 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj, lv_theme_style_t name) #if LV_USE_SWITCH case LV_THEME_SWITCH: - list = _lv_obj_get_style_list(obj, LV_SWITCH_PART_BG); + list = _lv_obj_get_style_list(obj, LV_SWITCH_PART_MAIN); _lv_style_list_add_style(list, &styles->bar_bg); list = _lv_obj_get_style_list(obj, LV_SWITCH_PART_INDIC); @@ -1093,7 +1093,7 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj, lv_theme_style_t name) #if LV_USE_SLIDER case LV_THEME_SLIDER: - list = _lv_obj_get_style_list(obj, LV_SLIDER_PART_BG); + list = _lv_obj_get_style_list(obj, LV_SLIDER_PART_MAIN); _lv_style_list_add_style(list, &styles->bar_bg); _lv_style_list_add_style(list, &styles->slider_bg); diff --git a/src/lv_themes/lv_theme_mono.c b/src/lv_themes/lv_theme_mono.c index 42e5b0ed5..bf934c9f1 100644 --- a/src/lv_themes/lv_theme_mono.c +++ b/src/lv_themes/lv_theme_mono.c @@ -381,13 +381,7 @@ static void slider_init(void) static void switch_init(void) { #if LV_USE_SWITCH != 0 - style_init_reset(&styles->sb); - lv_style_set_bg_opa(&styles->sb, LV_STATE_DEFAULT, LV_OPA_COVER); - lv_style_set_bg_color(&styles->sb, LV_STATE_DEFAULT, FG_COLOR); - lv_style_set_radius(&styles->sb, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE); - lv_style_set_pad_right(&styles->sb, LV_STATE_DEFAULT, LV_DPI / 30); - lv_style_set_pad_bottom(&styles->sb, LV_STATE_DEFAULT, LV_DPI / 30); - lv_style_set_size(&styles->sb, LV_STATE_DEFAULT, LV_MATH_MAX(LV_DPI / 25, 3)); + #endif } @@ -620,7 +614,7 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj, lv_theme_style_t name) #if LV_USE_BAR case LV_THEME_BAR: - list = _lv_obj_get_style_list(obj, LV_BAR_PART_BG); + list = _lv_obj_get_style_list(obj, LV_BAR_PART_MAIN); _lv_style_list_add_style(list, &styles->bg); _lv_style_list_add_style(list, &styles->pad_none); _lv_style_list_add_style(list, &styles->round); @@ -634,7 +628,7 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj, lv_theme_style_t name) #if LV_USE_SWITCH case LV_THEME_SWITCH: - list = _lv_obj_get_style_list(obj, LV_SWITCH_PART_BG); + list = _lv_obj_get_style_list(obj, LV_SWITCH_PART_MAIN); _lv_style_list_add_style(list, &styles->bg); _lv_style_list_add_style(list, &styles->pad_none); _lv_style_list_add_style(list, &styles->round); @@ -705,7 +699,7 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj, lv_theme_style_t name) #if LV_USE_SLIDER case LV_THEME_SLIDER: - list = _lv_obj_get_style_list(obj, LV_SLIDER_PART_BG); + list = _lv_obj_get_style_list(obj, LV_SLIDER_PART_MAIN); _lv_style_list_add_style(list, &styles->bg); _lv_style_list_add_style(list, &styles->pad_none); diff --git a/src/lv_themes/lv_theme_template.c b/src/lv_themes/lv_theme_template.c index 63bccb2c5..8d3e87508 100644 --- a/src/lv_themes/lv_theme_template.c +++ b/src/lv_themes/lv_theme_template.c @@ -461,7 +461,7 @@ void theme_apply(lv_theme_t * th, lv_obj_t * obj, lv_theme_style_t name) #if LV_USE_BAR case LV_THEME_BAR: - list = _lv_obj_get_style_list(obj, LV_BAR_PART_BG); + list = _lv_obj_get_style_list(obj, LV_BAR_PART_MAIN); _lv_style_list_add_style(list, &styles->bg); _lv_style_list_add_style(list, &styles->tight); @@ -473,7 +473,7 @@ void theme_apply(lv_theme_t * th, lv_obj_t * obj, lv_theme_style_t name) #if LV_USE_SWITCH case LV_THEME_SWITCH: - list = _lv_obj_get_style_list(obj, LV_SWITCH_PART_BG); + list = _lv_obj_get_style_list(obj, LV_SWITCH_PART_MAIN); _lv_style_list_add_style(list, &styles->bg); _lv_style_list_add_style(list, &styles->tight); _lv_style_list_add_style(list, &styles->round); @@ -548,7 +548,7 @@ void theme_apply(lv_theme_t * th, lv_obj_t * obj, lv_theme_style_t name) #if LV_USE_SLIDER case LV_THEME_SLIDER: - list = _lv_obj_get_style_list(obj, LV_SLIDER_PART_BG); + list = _lv_obj_get_style_list(obj, LV_SLIDER_PART_MAIN); _lv_style_list_add_style(list, &styles->bg); list = _lv_obj_get_style_list(obj, LV_SLIDER_PART_INDIC); diff --git a/src/lv_widgets/lv_bar.c b/src/lv_widgets/lv_bar.c index acd90fdb2..b08e409b1 100644 --- a/src/lv_widgets/lv_bar.c +++ b/src/lv_widgets/lv_bar.c @@ -56,7 +56,7 @@ static void lv_bar_anim_ready(lv_anim_t * a); /********************** * STATIC VARIABLES **********************/ -static lv_design_cb_t ancestor_design_f; +static lv_design_cb_t ancestor_design; static lv_signal_cb_t ancestor_signal; /********************** @@ -70,20 +70,21 @@ static lv_signal_cb_t ancestor_signal; /** * Create a bar objects * @param par pointer to an object, it will be the parent of the new bar - * @param copy pointer to a bar object, if not NULL then the new object will be copied from it + * @param copy DEPRECATED, will be removed in v9. + * Pointer to an other bar to copy. * @return pointer to the created bar */ -lv_obj_t * lv_bar_create(lv_obj_t * par, const lv_obj_t * copy) +lv_obj_t * lv_bar_create(lv_obj_t * parent, lv_obj_t * copy) { LV_LOG_TRACE("lv_bar create started"); /*Create the ancestor basic object*/ - lv_obj_t * bar = lv_obj_create(par, copy); + lv_obj_t * bar = lv_obj_create(parent, copy); LV_ASSERT_MEM(bar); if(bar == NULL) return NULL; if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_cb(bar); - if(ancestor_design_f == NULL) ancestor_design_f = lv_obj_get_design_cb(bar); + if(ancestor_design == NULL) ancestor_design = lv_obj_get_design_cb(bar); /*Allocate the object type specific extended data*/ lv_bar_ext_t * ext = lv_obj_allocate_ext_attr(bar, sizeof(lv_bar_ext_t)); @@ -109,32 +110,27 @@ lv_obj_t * lv_bar_create(lv_obj_t * par, const lv_obj_t * copy) lv_obj_set_signal_cb(bar, lv_bar_signal); lv_obj_set_design_cb(bar, lv_bar_design); - - /*Init the new bar object*/ if(copy == NULL) { - - lv_obj_set_click(bar, false); + lv_obj_clear_flag(bar, LV_OBJ_FLAG_CHECKABLE); lv_obj_set_size(bar, LV_DPI * 2, LV_DPI / 10); lv_bar_set_value(bar, ext->cur_value, false); lv_theme_apply(bar, LV_THEME_BAR); + } 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->max_value = ext_copy->max_value; + ext->cur_value = ext_copy->cur_value; + ext->type = ext_copy->type; + + lv_style_list_copy(&ext->style_indic, &ext_copy->style_indic); + + /*Refresh the style with new signal function*/ + _lv_obj_refresh_style(bar, LV_OBJ_PART_ALL, LV_STYLE_PROP_ALL); + + lv_bar_set_value(bar, ext->cur_value, LV_ANIM_OFF); } - 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->max_value = ext_copy->max_value; - ext->cur_value = ext_copy->cur_value; - ext->type = ext_copy->type; - - lv_style_list_copy(&ext->style_indic, &ext_copy->style_indic); - - /*Refresh the style with new signal function*/ - lv_obj_refresh_style(bar, LV_OBJ_PART_ALL, LV_STYLE_PROP_ALL); - - lv_bar_set_value(bar, ext->cur_value, LV_ANIM_OFF); - } - LV_LOG_INFO("bar created"); return bar; @@ -371,7 +367,7 @@ 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); + return ancestor_design(bar, clip_area, mode); } else if(mode == LV_DESIGN_DRAW_MAIN) { draw_bg(bar, clip_area); @@ -385,7 +381,7 @@ static lv_design_res_t lv_bar_design(lv_obj_t * bar, const lv_area_t * clip_area draw_dsc.shadow_opa = LV_OPA_TRANSP; draw_dsc.pattern_opa = LV_OPA_TRANSP; draw_dsc.outline_opa = LV_OPA_TRANSP; - lv_obj_init_draw_rect_dsc(bar, LV_BAR_PART_BG, &draw_dsc); + lv_obj_init_draw_rect_dsc(bar, LV_BAR_PART_MAIN, &draw_dsc); lv_draw_rect(&bar->coords, clip_area, &draw_dsc); } else if(mode == LV_DESIGN_DRAW_POST) { @@ -412,13 +408,13 @@ static void draw_bg(lv_obj_t * bar, const lv_area_t * clip_area) lv_draw_rect_dsc_t draw_dsc; lv_draw_rect_dsc_init(&draw_dsc); /*If the border is drawn later disable loading its properties*/ - if(lv_obj_get_style_border_post(bar, LV_BAR_PART_BG)) { + if(lv_obj_get_style_border_post(bar, LV_BAR_PART_MAIN)) { draw_dsc.border_opa = LV_OPA_TRANSP; } /*value will be drawn later*/ draw_dsc.value_opa = LV_OPA_TRANSP; - lv_obj_init_draw_rect_dsc(bar, LV_BAR_PART_BG, &draw_dsc); + lv_obj_init_draw_rect_dsc(bar, LV_BAR_PART_MAIN, &draw_dsc); lv_draw_rect(&bar->coords, clip_area, &draw_dsc); } @@ -437,10 +433,10 @@ static void draw_indic(lv_obj_t * bar, const lv_area_t * clip_area) 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); - lv_style_int_t bg_right = lv_obj_get_style_pad_right(bar, LV_BAR_PART_BG); - lv_style_int_t bg_top = lv_obj_get_style_pad_top(bar, LV_BAR_PART_BG); - lv_style_int_t bg_bottom = lv_obj_get_style_pad_bottom(bar, LV_BAR_PART_BG); + lv_style_int_t bg_left = lv_obj_get_style_pad_left(bar, LV_BAR_PART_MAIN); + lv_style_int_t bg_right = lv_obj_get_style_pad_right(bar, LV_BAR_PART_MAIN); + lv_style_int_t bg_top = lv_obj_get_style_pad_top(bar, LV_BAR_PART_MAIN); + lv_style_int_t bg_bottom = lv_obj_get_style_pad_bottom(bar, LV_BAR_PART_MAIN); /*Respect padding and minimum width/height too*/ lv_area_copy(&ext->indic_area, &bar->coords); @@ -550,7 +546,7 @@ static void draw_indic(lv_obj_t * bar, const lv_area_t * clip_area) /*Do not draw a zero length indicator*/ if(!sym && indic_length_calc(&ext->indic_area) <= 1) return; - uint16_t bg_radius = lv_obj_get_style_radius(bar, LV_BAR_PART_BG); + uint16_t bg_radius = lv_obj_get_style_radius(bar, LV_BAR_PART_MAIN); lv_coord_t short_side = LV_MATH_MIN(objw, objh); if(bg_radius > short_side >> 1) bg_radius = short_side >> 1; @@ -645,29 +641,29 @@ static lv_res_t lv_bar_signal(lv_obj_t * bar, lv_signal_t sign, void * param) { lv_res_t res; + /* Include the ancient signal function */ + res = ancestor_signal(bar, sign, param); + if(res != LV_RES_OK) return res; + if(sign == LV_SIGNAL_GET_STYLE) { lv_get_style_info_t * info = param; info->result = lv_bar_get_style(bar, info->part); if(info->result != NULL) return LV_RES_OK; else return ancestor_signal(bar, sign, param); } - - /* Include the ancient signal function */ - res = ancestor_signal(bar, sign, param); - if(res != LV_RES_OK) return res; - if(sign == LV_SIGNAL_GET_TYPE) return lv_obj_handle_get_type_signal(param, LV_OBJX_NAME); - - if(sign == LV_SIGNAL_REFR_EXT_DRAW_PAD) { - + else if(sign == LV_SIGNAL_GET_TYPE) { + return _lv_obj_handle_get_type_signal(param, LV_OBJX_NAME); + } + else if(sign == LV_SIGNAL_REFR_EXT_DRAW_PAD) { lv_coord_t indic_size; - indic_size = lv_obj_get_draw_rect_ext_pad_size(bar, LV_BAR_PART_INDIC); + indic_size = _lv_obj_get_draw_rect_ext_pad_size(bar, LV_BAR_PART_INDIC); /*Bg size is handled by lv_obj*/ bar->ext_draw_pad = LV_MATH_MAX(bar->ext_draw_pad, indic_size); } if(sign == LV_SIGNAL_CLEANUP) { - lv_obj_clean_style_list(bar, LV_BAR_PART_INDIC); + _lv_obj_reset_style_list_no_refr(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); @@ -683,20 +679,20 @@ static lv_style_list_t * lv_bar_get_style(lv_obj_t * bar, uint8_t part) LV_ASSERT_OBJ(bar, LV_OBJX_NAME); lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar); - lv_style_list_t * style_dsc_p; + lv_style_list_t * list; switch(part) { - case LV_BAR_PART_BG: - style_dsc_p = &bar->style_list; + case LV_BAR_PART_MAIN: + list = &bar->style_list; break; case LV_BAR_PART_INDIC: - style_dsc_p = &ext->style_indic; + list = &ext->style_indic; break; default: - style_dsc_p = NULL; + list = NULL; } - return style_dsc_p; + return list; } #if LV_USE_ANIMATION diff --git a/src/lv_widgets/lv_bar.h b/src/lv_widgets/lv_bar.h index 3c8de853b..6a761921f 100644 --- a/src/lv_widgets/lv_bar.h +++ b/src/lv_widgets/lv_bar.h @@ -19,7 +19,6 @@ extern "C" { #include "../lv_core/lv_obj.h" #include "../lv_misc/lv_anim.h" -#include "lv_cont.h" #include "lv_btn.h" #include "lv_label.h" @@ -80,7 +79,7 @@ typedef struct { /** Bar parts */ enum { - LV_BAR_PART_BG, /** Bar background style. */ + LV_BAR_PART_MAIN, /** Bar background style. */ LV_BAR_PART_INDIC, /** Bar fill area style. */ _LV_BAR_PART_VIRTUAL_LAST }; @@ -93,10 +92,11 @@ typedef uint8_t lv_bar_part_t; /** * Create a bar objects * @param par pointer to an object, it will be the parent of the new bar - * @param copy pointer to a bar object, if not NULL then the new object will be copied from it + * @param copy DEPRECATED, will be removed in v9. + * Pointer to an other bar to copy. * @return pointer to the created bar */ -lv_obj_t * lv_bar_create(lv_obj_t * par, const lv_obj_t * copy); +lv_obj_t * lv_bar_create(lv_obj_t * parent, lv_obj_t * copy); /*===================== * Setter functions diff --git a/src/lv_widgets/lv_btn.c b/src/lv_widgets/lv_btn.c index 1003d84b1..376999675 100644 --- a/src/lv_widgets/lv_btn.c +++ b/src/lv_widgets/lv_btn.c @@ -49,15 +49,17 @@ static lv_signal_cb_t ancestor_signal; /** * Create a button object * @param parent pointer to an object, it will be the parent of the new button + * @param copy DEPRECATED, will be removed in v9. + * Pointer to an other button to copy. * @return pointer to the created button */ -lv_obj_t * lv_btn_create(lv_obj_t * parent) +lv_obj_t * lv_btn_create(lv_obj_t * parent, const lv_obj_t * copy) { LV_LOG_TRACE("button create started"); lv_obj_t * btn; - btn = lv_obj_create(parent); + btn = lv_obj_create(parent, copy); LV_ASSERT_MEM(btn); if(btn == NULL) return NULL; @@ -65,13 +67,15 @@ lv_obj_t * lv_btn_create(lv_obj_t * parent) lv_obj_set_signal_cb(btn, lv_btn_signal); - /*Set layout if the button is not a screen*/ - if(parent) { - lv_obj_set_size(btn, LV_DPI, LV_DPI / 3); - lv_obj_set_grid(btn, &lv_grid_center); - } + if(copy == NULL) { + /*Set layout if the button is not a screen*/ + if(parent) { + lv_obj_set_size(btn, LV_DPI, LV_DPI / 3); + lv_obj_set_grid(btn, &lv_grid_center); + } - lv_theme_apply(btn, LV_THEME_BTN); + lv_theme_apply(btn, LV_THEME_BTN); + } LV_LOG_INFO("button created"); diff --git a/src/lv_widgets/lv_btn.h b/src/lv_widgets/lv_btn.h index 721d2b5a1..4421933f5 100644 --- a/src/lv_widgets/lv_btn.h +++ b/src/lv_widgets/lv_btn.h @@ -40,9 +40,11 @@ typedef uint8_t lv_btn_part_t; /** * Create a button object * @param parent pointer to an object, it will be the parent of the new button + * @param copy DEPRECATED, will be removed in v9. + * Pointer to an other button to copy. * @return pointer to the created button */ -lv_obj_t * lv_btn_create(lv_obj_t * parent); +lv_obj_t * lv_btn_create(lv_obj_t * parent, const lv_obj_t * copy); /*===================== * Setter functions diff --git a/src/lv_widgets/lv_checkbox.h b/src/lv_widgets/lv_checkbox.h index 96bb0f1e2..7576a76d9 100644 --- a/src/lv_widgets/lv_checkbox.h +++ b/src/lv_widgets/lv_checkbox.h @@ -40,18 +40,17 @@ extern "C" { /*Data of check box*/ typedef struct { - lv_btn_ext_t bg_btn; /*Ext. of ancestor*/ - /*New data for this type */ - lv_obj_t * bullet; /*Pointer to button*/ + /*No inherited ext, derived from the base object */ + + /*New data for this widget */ + lv_obj_t * text; /*Pointer to button*/ lv_obj_t * label; /*Pointer to label*/ } lv_checkbox_ext_t; /** Checkbox styles. */ enum { - LV_CHECKBOX_PART_BG = LV_BTN_PART_MAIN, /**< Style of object background. */ + LV_CHECKBOX_PART_MAIN = LV_OBJ_PART_MAIN, /**< Style of object background. */ _LV_CHECKBOX_PART_VIRTUAL_LAST, - LV_CHECKBOX_PART_BULLET = _LV_BTN_PART_REAL_LAST, /**< Style of box (released). */ - _LV_CHECKBOX_PART_REAL_LAST }; typedef uint8_t lv_checkbox_style_t; diff --git a/src/lv_widgets/lv_label.c b/src/lv_widgets/lv_label.c index bef0ec357..52ae3bc5b 100644 --- a/src/lv_widgets/lv_label.c +++ b/src/lv_widgets/lv_label.c @@ -71,14 +71,16 @@ static lv_signal_cb_t ancestor_signal; /** * Create a label objects * @param parent pointer to an object, it will be the parent of the new label + * @param copy DEPRECATED, will be removed in v9. + * Pointer to an other label to copy. * @return pointer to the created button */ -lv_obj_t * lv_label_create(lv_obj_t * parent) +lv_obj_t * lv_label_create(lv_obj_t * parent, const lv_obj_t * copy) { LV_LOG_TRACE("label create started"); /*Create a basic object*/ - lv_obj_t * new_label = lv_obj_create(parent); + lv_obj_t * new_label = lv_obj_create(parent, copy); LV_ASSERT_MEM(new_label); if(new_label == NULL) return NULL; diff --git a/src/lv_widgets/lv_label.h b/src/lv_widgets/lv_label.h index 99e517e31..63da6d028 100644 --- a/src/lv_widgets/lv_label.h +++ b/src/lv_widgets/lv_label.h @@ -112,9 +112,11 @@ typedef uint8_t lv_label_part_t; /** * Create a label objects * @param parent pointer to an object, it will be the parent of the new label + * @param copy DEPRECATED, will be removed in v9. + * Pointer to an other label to copy. * @return pointer to the created button */ -lv_obj_t * lv_label_create(lv_obj_t * parent); +lv_obj_t * lv_label_create(lv_obj_t * parent, const lv_obj_t * copy); /*===================== * Setter functions diff --git a/src/lv_widgets/lv_slider.c b/src/lv_widgets/lv_slider.c index 7e658226d..de18041d4 100644 --- a/src/lv_widgets/lv_slider.c +++ b/src/lv_widgets/lv_slider.c @@ -41,7 +41,7 @@ static void lv_slider_draw_knob(lv_obj_t * slider, const lv_area_t * knob_area, /********************** * STATIC VARIABLES **********************/ -static lv_design_cb_t ancestor_design_f; +static lv_design_cb_t ancestor_design; static lv_signal_cb_t ancestor_signal; /********************** @@ -54,20 +54,21 @@ static lv_signal_cb_t ancestor_signal; /** * Create a slider objects - * @param par pointer to an object, it will be the parent of the new slider - * @param copy pointer to a slider object, if not NULL then the new object will be copied from it + * @param parent pointer to an object, it will be the parent of the new slider + * @param copy DEPRECATED, will be removed in v9. + * Pointer to an other slider to copy. * @return pointer to the created slider */ -lv_obj_t * lv_slider_create(lv_obj_t * par, const lv_obj_t * copy) +lv_obj_t * lv_slider_create(lv_obj_t * parent, lv_obj_t * copy) { LV_LOG_TRACE("slider create started"); /*Create the ancestor slider*/ - lv_obj_t * slider = lv_bar_create(par, copy); + lv_obj_t * slider = lv_bar_create(parent, copy); LV_ASSERT_MEM(slider); if(slider == NULL) return NULL; - if(ancestor_design_f == NULL) ancestor_design_f = lv_obj_get_design_cb(slider); + if(ancestor_design == NULL) ancestor_design = lv_obj_get_design_cb(slider); if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_cb(slider); /*Allocate the slider type specific extended data*/ @@ -89,23 +90,20 @@ lv_obj_t * lv_slider_create(lv_obj_t * par, const lv_obj_t * copy) /*Init the new slider slider*/ if(copy == NULL) { - lv_obj_set_click(slider, true); - lv_obj_add_protect(slider, LV_PROTECT_PRESS_LOST); - lv_obj_set_ext_click_area(slider, 0, 0, LV_DPI / 10, LV_DPI / 10); - lv_theme_apply(slider, LV_THEME_SLIDER); + lv_obj_add_flag(slider, LV_OBJ_FLAG_CHECKABLE); + lv_obj_set_ext_click_area(slider, 0, 0, LV_DPI / 10, LV_DPI / 10); lv_obj_set_height(slider, LV_DPI / 15); - } - /*Copy an existing slider*/ - else { + } else { lv_slider_ext_t * copy_ext = lv_obj_get_ext_attr(copy); lv_style_list_copy(&ext->style_knob, ©_ext->style_knob); lv_area_copy(&ext->left_knob_area, ©_ext->left_knob_area); lv_area_copy(&ext->right_knob_area, ©_ext->right_knob_area); - lv_obj_refresh_style(slider, LV_OBJ_PART_ALL, LV_STYLE_PROP_ALL); + _lv_obj_refresh_style(slider, LV_OBJ_PART_ALL, LV_STYLE_PROP_ALL); } + LV_LOG_INFO("slider created"); return slider; @@ -119,17 +117,6 @@ lv_obj_t * lv_slider_create(lv_obj_t * par, const lv_obj_t * copy) * Getter functions *====================*/ -/** - * Get the value of a slider - * @param slider pointer to a slider object - * @return the value of the slider - */ -int16_t lv_slider_get_value(const lv_obj_t * slider) -{ - LV_ASSERT_OBJ(slider, LV_OBJX_NAME); - return lv_bar_get_value(slider); -} - /** * Give the slider is being dragged or not * @param slider pointer to a slider object @@ -168,7 +155,7 @@ static lv_design_res_t lv_slider_design(lv_obj_t * slider, const lv_area_t * cli /*The ancestor design function will draw the background and the indicator. * It also sets ext->bar.indic_area*/ - ancestor_design_f(slider, clip_area, mode); + ancestor_design(slider, clip_area, mode); lv_slider_ext_t * ext = lv_obj_get_ext_attr(slider); lv_bidi_dir_t base_dir = lv_obj_get_base_dir(slider); @@ -231,7 +218,7 @@ static lv_design_res_t lv_slider_design(lv_obj_t * slider, const lv_area_t * cli } /*Post draw when the children are drawn*/ else if(mode == LV_DESIGN_DRAW_POST) { - return ancestor_design_f(slider, clip_area, mode); + return ancestor_design(slider, clip_area, mode); } return LV_DESIGN_RES_OK; @@ -258,7 +245,7 @@ static lv_res_t lv_slider_signal(lv_obj_t * slider, lv_signal_t sign, void * par /* Include the ancient signal function */ res = ancestor_signal(slider, sign, param); if(res != LV_RES_OK) return res; - if(sign == LV_SIGNAL_GET_TYPE) return lv_obj_handle_get_type_signal(param, LV_OBJX_NAME); + if(sign == LV_SIGNAL_GET_TYPE) return _lv_obj_handle_get_type_signal(param, LV_OBJX_NAME); lv_slider_type_t type = lv_slider_get_type(slider); lv_slider_ext_t * ext = lv_obj_get_ext_attr(slider); @@ -334,10 +321,10 @@ static lv_res_t lv_slider_signal(lv_obj_t * slider, lv_signal_t sign, void * par lv_coord_t w = lv_obj_get_width(slider); lv_coord_t h = lv_obj_get_height(slider); - lv_style_int_t bg_left = lv_obj_get_style_pad_left(slider, LV_SLIDER_PART_BG); - lv_style_int_t bg_right = lv_obj_get_style_pad_right(slider, LV_SLIDER_PART_BG); - lv_style_int_t bg_top = lv_obj_get_style_pad_top(slider, LV_SLIDER_PART_BG); - lv_style_int_t bg_bottom = lv_obj_get_style_pad_bottom(slider, LV_SLIDER_PART_BG); + lv_style_int_t bg_left = lv_obj_get_style_pad_left(slider, LV_SLIDER_PART_MAIN); + lv_style_int_t bg_right = lv_obj_get_style_pad_right(slider, LV_SLIDER_PART_MAIN); + lv_style_int_t bg_top = lv_obj_get_style_pad_top(slider, LV_SLIDER_PART_MAIN); + lv_style_int_t bg_bottom = lv_obj_get_style_pad_bottom(slider, LV_SLIDER_PART_MAIN); int32_t range = ext->bar.max_value - ext->bar.min_value; int16_t new_value = 0; @@ -415,7 +402,7 @@ static lv_res_t lv_slider_signal(lv_obj_t * slider, lv_signal_t sign, void * par 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); + knob_size += _lv_obj_get_draw_rect_ext_pad_size(slider, LV_SLIDER_PART_KNOB); /*Indic. size is handled by bar*/ slider->ext_draw_pad = LV_MATH_MAX(slider->ext_draw_pad, knob_size); @@ -438,7 +425,7 @@ static lv_res_t lv_slider_signal(lv_obj_t * slider, lv_signal_t sign, void * par #endif } else if(sign == LV_SIGNAL_CLEANUP) { - lv_obj_clean_style_list(slider, LV_SLIDER_PART_KNOB); + _lv_obj_reset_style_list_no_refr(slider, LV_SLIDER_PART_KNOB); } else if(sign == LV_SIGNAL_GET_EDITABLE) { #if LV_USE_GROUP @@ -459,7 +446,7 @@ 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: + case LV_SLIDER_PART_MAIN: style_dsc_p = &slider->style_list; break; case LV_SLIDER_PART_INDIC: diff --git a/src/lv_widgets/lv_slider.h b/src/lv_widgets/lv_slider.h index 9012bb4a5..07aa657d2 100644 --- a/src/lv_widgets/lv_slider.h +++ b/src/lv_widgets/lv_slider.h @@ -53,9 +53,10 @@ typedef struct { /** Built-in styles of slider*/ enum { - LV_SLIDER_PART_BG, /** Slider background style. */ - LV_SLIDER_PART_INDIC, /** Slider indicator (filled area) style. */ - LV_SLIDER_PART_KNOB, /** Slider knob style. */ + LV_SLIDER_PART_MAIN = LV_BAR_PART_MAIN, /** Slider background style. */ + LV_SLIDER_PART_INDIC = LV_BAR_PART_INDIC, /** Slider indicator (filled area) style. */ + LV_SLIDER_PART_KNOB = _LV_BAR_PART_VIRTUAL_LAST, /** Slider knob style. */ + _LV_SLIDER_PART_VIRTUAL_LAST }; /********************** @@ -64,11 +65,12 @@ enum { /** * Create a slider objects - * @param par pointer to an object, it will be the parent of the new slider - * @param copy pointer to a slider object, if not NULL then the new object will be copied from it + * @param parent pointer to an object, it will be the parent of the new slider + * @param copy DEPRECATED, will be removed in v9. + * Pointer to an other slider to copy. * @return pointer to the created slider */ -lv_obj_t * lv_slider_create(lv_obj_t * par, const lv_obj_t * copy); +lv_obj_t * lv_slider_create(lv_obj_t * parent, lv_obj_t * copy); /*===================== * Setter functions @@ -142,7 +144,10 @@ static inline void lv_slider_set_type(lv_obj_t * slider, lv_slider_type_t type) * @param slider pointer to a slider object * @return the value of the main knob of the slider */ -int16_t lv_slider_get_value(const lv_obj_t * slider); +static inline int16_t lv_slider_get_value(const lv_obj_t * slider) +{ + return lv_bar_get_value(slider); +} /** * Get the value of the left knob of a slider diff --git a/src/lv_widgets/lv_switch.c b/src/lv_widgets/lv_switch.c index 9340f1efa..ec38c0ea6 100644 --- a/src/lv_widgets/lv_switch.c +++ b/src/lv_widgets/lv_switch.c @@ -55,16 +55,17 @@ static lv_design_cb_t ancestor_design; /** * Create a switch objects - * @param par pointer to an object, it will be the parent of the new switch - * @param copy pointer to a switch object, if not NULL then the new object will be copied from it + * @param parent pointer to an object, it will be the parent of the new switch + * @param copy DEPRECATED, will be removed in v9. + * Pointer to an other switch to copy. * @return pointer to the created switch */ -lv_obj_t * lv_switch_create(lv_obj_t * par, const lv_obj_t * copy) +lv_obj_t * lv_switch_create(lv_obj_t * parent, const lv_obj_t * copy) { LV_LOG_TRACE("switch create started"); /*Create the ancestor of switch*/ - lv_obj_t * sw = lv_bar_create(par, copy); + lv_obj_t * sw = lv_bar_create(parent, copy); LV_ASSERT_MEM(sw); if(sw == NULL) return NULL; @@ -88,21 +89,17 @@ lv_obj_t * lv_switch_create(lv_obj_t * par, const lv_obj_t * copy) /*Init the new switch switch*/ if(copy == NULL) { - lv_obj_set_click(sw, true); - lv_obj_add_protect(sw, LV_PROTECT_PRESS_LOST); + lv_obj_add_flag(sw, LV_OBJ_FLAG_CLICKABLE); lv_obj_set_size(sw, LV_DPX(60), LV_DPX(35)); lv_bar_set_range(sw, 0, 1); lv_theme_apply(sw, LV_THEME_SWITCH); - } - /*Copy an existing switch*/ - else { + } else { lv_switch_ext_t * copy_ext = lv_obj_get_ext_attr(copy); lv_style_list_copy(&ext->style_knob, ©_ext->style_knob); - lv_obj_refresh_style(sw, LV_OBJ_PART_ALL, LV_STYLE_PROP_ALL); + _lv_obj_refresh_style(sw, LV_OBJ_PART_ALL, LV_STYLE_PROP_ALL); } - /*Refresh the style with new signal function*/ LV_LOG_INFO("switch created"); @@ -212,8 +209,8 @@ static lv_design_res_t lv_switch_design(lv_obj_t * sw, const lv_area_t * clip_ar lv_coord_t knob_size = objh; lv_area_t knob_area; - lv_style_int_t bg_left = lv_obj_get_style_pad_left(sw, LV_SWITCH_PART_BG); - lv_style_int_t bg_right = lv_obj_get_style_pad_right(sw, LV_SWITCH_PART_BG); + lv_style_int_t bg_left = lv_obj_get_style_pad_left(sw, LV_SWITCH_PART_MAIN); + lv_style_int_t bg_right = lv_obj_get_style_pad_right(sw, LV_SWITCH_PART_MAIN); lv_coord_t max_indic_w = objw - bg_left - bg_right; lv_coord_t act_indic_w = lv_area_get_width(&ext->bar.indic_area); @@ -267,25 +264,23 @@ static lv_res_t lv_switch_signal(lv_obj_t * sw, lv_signal_t sign, void * param) { lv_res_t res; + /* Include the ancient signal function */ + res = ancestor_signal(sw, sign, param); + if(res != LV_RES_OK) return res; + if(sign == LV_SIGNAL_GET_STYLE) { lv_get_style_info_t * info = param; info->result = lv_switch_get_style(sw, info->part); if(info->result != NULL) return LV_RES_OK; else return ancestor_signal(sw, sign, param); } - - if(sign == LV_SIGNAL_GET_TYPE) { + else if(sign == LV_SIGNAL_GET_TYPE) { res = ancestor_signal(sw, sign, param); if(res != LV_RES_OK) return res; - return lv_obj_handle_get_type_signal(param, LV_OBJX_NAME); + return _lv_obj_handle_get_type_signal(param, LV_OBJX_NAME); } - - /* Include the ancient signal function */ - res = ancestor_signal(sw, sign, param); - if(res != LV_RES_OK) return res; - - if(sign == LV_SIGNAL_CLEANUP) { - lv_obj_clean_style_list(sw, LV_SWITCH_PART_KNOB); + else if(sign == LV_SIGNAL_CLEANUP) { + _lv_obj_reset_style_list_no_refr(sw, LV_SWITCH_PART_KNOB); } else if(sign == LV_SIGNAL_RELEASED) { if(lv_switch_get_state(sw)) lv_switch_off(sw, LV_ANIM_ON); @@ -316,7 +311,7 @@ static lv_res_t lv_switch_signal(lv_obj_t * sw, lv_signal_t sign, void * param) 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_SWITCH_PART_KNOB); + knob_size += _lv_obj_get_draw_rect_ext_pad_size(sw, LV_SWITCH_PART_KNOB); /*Indic. size is handled by bar*/ sw->ext_draw_pad = LV_MATH_MAX(sw->ext_draw_pad, knob_size); @@ -339,7 +334,7 @@ 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: + case LV_SWITCH_PART_MAIN: style_dsc_p = &sw->style_list; break; case LV_SWITCH_PART_INDIC: diff --git a/src/lv_widgets/lv_switch.h b/src/lv_widgets/lv_switch.h index 609e44fcc..8079b0fc3 100644 --- a/src/lv_widgets/lv_switch.h +++ b/src/lv_widgets/lv_switch.h @@ -19,10 +19,9 @@ extern "C" { /*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_switch: lv_slider is required. Enable it in lv_conf.h (LV_USE_SLIDER 1)" #endif -#include "../lv_core/lv_obj.h" #include "lv_bar.h" /********************* @@ -44,7 +43,7 @@ typedef struct { * Switch parts. */ enum { - LV_SWITCH_PART_BG = LV_BAR_PART_BG, /**< Switch background. */ + LV_SWITCH_PART_MAIN = LV_BAR_PART_MAIN, /**< Switch background. */ LV_SWITCH_PART_INDIC = LV_BAR_PART_INDIC, /**< Switch fill area. */ LV_SWITCH_PART_KNOB = _LV_BAR_PART_VIRTUAL_LAST, /**< Switch knob. */ _LV_SWITCH_PART_VIRTUAL_LAST @@ -58,11 +57,12 @@ typedef uint8_t lv_switch_part_t; /** * Create a switch objects - * @param par pointer to an object, it will be the parent of the new switch - * @param copy pointer to a switch object, if not NULL then the new object will be copied from it + * @param parent pointer to an object, it will be the parent of the new switch + * @param copy DEPRECATED, will be removed in v9. + * Pointer to an other switch to copy. * @return pointer to the created switch */ -lv_obj_t * lv_switch_create(lv_obj_t * par, const lv_obj_t * copy); +lv_obj_t * lv_switch_create(lv_obj_t * parent, const lv_obj_t * copy); /*===================== * Setter functions