1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-28 07:03:00 +08:00

start to rework widgets

This commit is contained in:
Gabor Kiss-Vamosi 2020-09-15 10:16:15 +02:00
parent 877b30017d
commit fceb1177cd
18 changed files with 201 additions and 171 deletions

View File

@ -180,9 +180,12 @@ void lv_deinit(void)
* Create a basic object * Create a basic object
* @param parent pointer to a parent object. * @param parent pointer to a parent object.
* If NULL then a screen will be created * 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 * @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; 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; new_obj->ext_attr = NULL;
lv_style_list_init(&new_obj->style_list); lv_style_list_init(&new_obj->style_list);
lv_style_list_init(&new_obj->style_list);
if(copy == NULL) {
if(parent != NULL) lv_theme_apply(new_obj, LV_THEME_OBJ); if(parent != NULL) lv_theme_apply(new_obj, LV_THEME_OBJ);
else lv_theme_apply(new_obj, LV_THEME_SCR); else lv_theme_apply(new_obj, LV_THEME_SCR);
}
else {
lv_style_list_copy(&new_obj->style_list, &copy->style_list);
}
/*Copy the attributes if required*/
if(copy != NULL) {
lv_area_copy(&new_obj->coords, &copy->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, &copy->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, &copy->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); lv_obj_set_pos(new_obj, 0, 0);
/*Send a signal to the parent to notify it about the new child*/ /*Send a signal to the parent to notify it about the new child*/

View File

@ -308,9 +308,12 @@ void lv_deinit(void);
* Create a basic object * Create a basic object
* @param parent pointer to a parent object. * @param parent pointer to a parent object.
* If NULL then a screen will be created * 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 * @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 * Delete 'obj' and all of its children

View File

@ -153,9 +153,9 @@ lv_disp_t * lv_disp_drv_register(lv_disp_drv_t * driver)
#endif #endif
disp->prev_scr = NULL; disp->prev_scr = NULL;
disp->act_scr = lv_obj_create(NULL); /*Create a default screen 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); /*Create top layer on the display*/ disp->top_layer = lv_obj_create(NULL, NULL); /*Create top layer on the display*/
disp->sys_layer = lv_obj_create(NULL); /*Create sys 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->top_layer, LV_OBJ_PART_MAIN);
lv_obj_reset_style_list(disp->sys_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); lv_obj_clear_flag(disp->top_layer, LV_OBJ_FLAG_CLICKABLE);

View File

@ -239,14 +239,14 @@ static void clear_styles(lv_obj_t * obj, lv_theme_style_t name)
#if LV_USE_BAR #if LV_USE_BAR
case LV_THEME_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); _lv_obj_reset_style_list_no_refr(obj, LV_BAR_PART_INDIC);
break; break;
#endif #endif
#if LV_USE_SWITCH #if LV_USE_SWITCH
case LV_THEME_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_INDIC);
_lv_obj_reset_style_list_no_refr(obj, LV_SWITCH_PART_KNOB); _lv_obj_reset_style_list_no_refr(obj, LV_SWITCH_PART_KNOB);
break; break;
@ -298,7 +298,7 @@ static void clear_styles(lv_obj_t * obj, lv_theme_style_t name)
#if LV_USE_SLIDER #if LV_USE_SLIDER
case LV_THEME_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_INDIC);
_lv_obj_reset_style_list_no_refr(obj, LV_SLIDER_PART_KNOB); _lv_obj_reset_style_list_no_refr(obj, LV_SLIDER_PART_KNOB);
break; break;

View File

@ -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 #if LV_USE_BAR
case LV_THEME_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); _lv_style_list_add_style(list, &styles->bar_bg);
list = _lv_obj_get_style_list(obj, LV_BAR_PART_INDIC); 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 #if LV_USE_SWITCH
case LV_THEME_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); _lv_style_list_add_style(list, &styles->bar_bg);
list = _lv_obj_get_style_list(obj, LV_SWITCH_PART_INDIC); 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 #if LV_USE_SLIDER
case LV_THEME_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->bar_bg);
_lv_style_list_add_style(list, &styles->slider_bg); _lv_style_list_add_style(list, &styles->slider_bg);

View File

@ -381,13 +381,7 @@ static void slider_init(void)
static void switch_init(void) static void switch_init(void)
{ {
#if LV_USE_SWITCH != 0 #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 #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 #if LV_USE_BAR
case LV_THEME_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->bg);
_lv_style_list_add_style(list, &styles->pad_none); _lv_style_list_add_style(list, &styles->pad_none);
_lv_style_list_add_style(list, &styles->round); _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 #if LV_USE_SWITCH
case LV_THEME_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->bg);
_lv_style_list_add_style(list, &styles->pad_none); _lv_style_list_add_style(list, &styles->pad_none);
_lv_style_list_add_style(list, &styles->round); _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 #if LV_USE_SLIDER
case LV_THEME_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->bg);
_lv_style_list_add_style(list, &styles->pad_none); _lv_style_list_add_style(list, &styles->pad_none);

View File

@ -461,7 +461,7 @@ void theme_apply(lv_theme_t * th, lv_obj_t * obj, lv_theme_style_t name)
#if LV_USE_BAR #if LV_USE_BAR
case LV_THEME_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->bg);
_lv_style_list_add_style(list, &styles->tight); _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 #if LV_USE_SWITCH
case LV_THEME_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->bg);
_lv_style_list_add_style(list, &styles->tight); _lv_style_list_add_style(list, &styles->tight);
_lv_style_list_add_style(list, &styles->round); _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 #if LV_USE_SLIDER
case LV_THEME_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->bg);
list = _lv_obj_get_style_list(obj, LV_SLIDER_PART_INDIC); list = _lv_obj_get_style_list(obj, LV_SLIDER_PART_INDIC);

View File

@ -56,7 +56,7 @@ static void lv_bar_anim_ready(lv_anim_t * a);
/********************** /**********************
* STATIC VARIABLES * STATIC VARIABLES
**********************/ **********************/
static lv_design_cb_t ancestor_design_f; static lv_design_cb_t ancestor_design;
static lv_signal_cb_t ancestor_signal; static lv_signal_cb_t ancestor_signal;
/********************** /**********************
@ -70,20 +70,21 @@ static lv_signal_cb_t ancestor_signal;
/** /**
* Create a bar objects * Create a bar objects
* @param par pointer to an object, it will be the parent of the new bar * @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 * @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"); LV_LOG_TRACE("lv_bar create started");
/*Create the ancestor basic object*/ /*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); LV_ASSERT_MEM(bar);
if(bar == NULL) return NULL; if(bar == NULL) return NULL;
if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_cb(bar); 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*/ /*Allocate the object type specific extended data*/
lv_bar_ext_t * ext = lv_obj_allocate_ext_attr(bar, sizeof(lv_bar_ext_t)); lv_bar_ext_t * ext = lv_obj_allocate_ext_attr(bar, sizeof(lv_bar_ext_t));
@ -109,17 +110,13 @@ 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_signal_cb(bar, lv_bar_signal);
lv_obj_set_design_cb(bar, lv_bar_design); lv_obj_set_design_cb(bar, lv_bar_design);
/*Init the new bar object*/
if(copy == NULL) { if(copy == NULL) {
lv_obj_clear_flag(bar, LV_OBJ_FLAG_CHECKABLE);
lv_obj_set_click(bar, false);
lv_obj_set_size(bar, LV_DPI * 2, LV_DPI / 10); lv_obj_set_size(bar, LV_DPI * 2, LV_DPI / 10);
lv_bar_set_value(bar, ext->cur_value, false); lv_bar_set_value(bar, ext->cur_value, false);
lv_theme_apply(bar, LV_THEME_BAR); lv_theme_apply(bar, LV_THEME_BAR);
} } else {
else {
lv_bar_ext_t * ext_copy = lv_obj_get_ext_attr(copy); lv_bar_ext_t * ext_copy = lv_obj_get_ext_attr(copy);
ext->min_value = ext_copy->min_value; ext->min_value = ext_copy->min_value;
ext->start_value = ext_copy->start_value; ext->start_value = ext_copy->start_value;
@ -130,11 +127,10 @@ lv_obj_t * lv_bar_create(lv_obj_t * par, const lv_obj_t * copy)
lv_style_list_copy(&ext->style_indic, &ext_copy->style_indic); lv_style_list_copy(&ext->style_indic, &ext_copy->style_indic);
/*Refresh the style with new signal function*/ /*Refresh the style with new signal function*/
lv_obj_refresh_style(bar, LV_OBJ_PART_ALL, LV_STYLE_PROP_ALL); _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_bar_set_value(bar, ext->cur_value, LV_ANIM_OFF);
} }
LV_LOG_INFO("bar created"); LV_LOG_INFO("bar created");
return bar; 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) { if(mode == LV_DESIGN_COVER_CHK) {
/*Return false if the object is not covers the mask area*/ /*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) { else if(mode == LV_DESIGN_DRAW_MAIN) {
draw_bg(bar, clip_area); 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.shadow_opa = LV_OPA_TRANSP;
draw_dsc.pattern_opa = LV_OPA_TRANSP; draw_dsc.pattern_opa = LV_OPA_TRANSP;
draw_dsc.outline_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); lv_draw_rect(&bar->coords, clip_area, &draw_dsc);
} }
else if(mode == LV_DESIGN_DRAW_POST) { 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_t draw_dsc;
lv_draw_rect_dsc_init(&draw_dsc); lv_draw_rect_dsc_init(&draw_dsc);
/*If the border is drawn later disable loading its properties*/ /*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; draw_dsc.border_opa = LV_OPA_TRANSP;
} }
/*value will be drawn later*/ /*value will be drawn later*/
draw_dsc.value_opa = LV_OPA_TRANSP; 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); 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; ext->start_value == ext->min_value) sym = true;
/*Calculate the indicator area*/ /*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_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_BG); 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_BG); 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_BG); lv_style_int_t bg_bottom = lv_obj_get_style_pad_bottom(bar, LV_BAR_PART_MAIN);
/*Respect padding and minimum width/height too*/ /*Respect padding and minimum width/height too*/
lv_area_copy(&ext->indic_area, &bar->coords); 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*/ /*Do not draw a zero length indicator*/
if(!sym && indic_length_calc(&ext->indic_area) <= 1) return; 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); lv_coord_t short_side = LV_MATH_MIN(objw, objh);
if(bg_radius > short_side >> 1) bg_radius = short_side >> 1; 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; 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) { if(sign == LV_SIGNAL_GET_STYLE) {
lv_get_style_info_t * info = param; lv_get_style_info_t * info = param;
info->result = lv_bar_get_style(bar, info->part); info->result = lv_bar_get_style(bar, info->part);
if(info->result != NULL) return LV_RES_OK; if(info->result != NULL) return LV_RES_OK;
else return ancestor_signal(bar, sign, param); else return ancestor_signal(bar, sign, param);
} }
else if(sign == LV_SIGNAL_GET_TYPE) {
/* Include the ancient signal function */ return _lv_obj_handle_get_type_signal(param, LV_OBJX_NAME);
res = ancestor_signal(bar, sign, param); }
if(res != LV_RES_OK) return res; else if(sign == LV_SIGNAL_REFR_EXT_DRAW_PAD) {
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) {
lv_coord_t indic_size; 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*/ /*Bg size is handled by lv_obj*/
bar->ext_draw_pad = LV_MATH_MAX(bar->ext_draw_pad, indic_size); 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); _lv_obj_reset_style_list_no_refr(bar, LV_BAR_PART_INDIC);
#if LV_USE_ANIMATION #if LV_USE_ANIMATION
lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar); lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar);
lv_anim_del(&ext->cur_value_anim, NULL); 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_ASSERT_OBJ(bar, LV_OBJX_NAME);
lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar); 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) { switch(part) {
case LV_BAR_PART_BG: case LV_BAR_PART_MAIN:
style_dsc_p = &bar->style_list; list = &bar->style_list;
break; break;
case LV_BAR_PART_INDIC: case LV_BAR_PART_INDIC:
style_dsc_p = &ext->style_indic; list = &ext->style_indic;
break; break;
default: default:
style_dsc_p = NULL; list = NULL;
} }
return style_dsc_p; return list;
} }
#if LV_USE_ANIMATION #if LV_USE_ANIMATION

View File

@ -19,7 +19,6 @@ extern "C" {
#include "../lv_core/lv_obj.h" #include "../lv_core/lv_obj.h"
#include "../lv_misc/lv_anim.h" #include "../lv_misc/lv_anim.h"
#include "lv_cont.h"
#include "lv_btn.h" #include "lv_btn.h"
#include "lv_label.h" #include "lv_label.h"
@ -80,7 +79,7 @@ typedef struct {
/** Bar parts */ /** Bar parts */
enum { 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_INDIC, /** Bar fill area style. */
_LV_BAR_PART_VIRTUAL_LAST _LV_BAR_PART_VIRTUAL_LAST
}; };
@ -93,10 +92,11 @@ typedef uint8_t lv_bar_part_t;
/** /**
* Create a bar objects * Create a bar objects
* @param par pointer to an object, it will be the parent of the new bar * @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 * @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 * Setter functions

View File

@ -49,15 +49,17 @@ static lv_signal_cb_t ancestor_signal;
/** /**
* Create a button object * Create a button object
* @param parent pointer to an object, it will be the parent of the new button * @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 * @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_LOG_TRACE("button create started");
lv_obj_t * btn; lv_obj_t * btn;
btn = lv_obj_create(parent); btn = lv_obj_create(parent, copy);
LV_ASSERT_MEM(btn); LV_ASSERT_MEM(btn);
if(btn == NULL) return NULL; if(btn == NULL) return NULL;
@ -65,6 +67,7 @@ lv_obj_t * lv_btn_create(lv_obj_t * parent)
lv_obj_set_signal_cb(btn, lv_btn_signal); lv_obj_set_signal_cb(btn, lv_btn_signal);
if(copy == NULL) {
/*Set layout if the button is not a screen*/ /*Set layout if the button is not a screen*/
if(parent) { if(parent) {
lv_obj_set_size(btn, LV_DPI, LV_DPI / 3); lv_obj_set_size(btn, LV_DPI, LV_DPI / 3);
@ -72,6 +75,7 @@ lv_obj_t * lv_btn_create(lv_obj_t * parent)
} }
lv_theme_apply(btn, LV_THEME_BTN); lv_theme_apply(btn, LV_THEME_BTN);
}
LV_LOG_INFO("button created"); LV_LOG_INFO("button created");

View File

@ -40,9 +40,11 @@ typedef uint8_t lv_btn_part_t;
/** /**
* Create a button object * Create a button object
* @param parent pointer to an object, it will be the parent of the new button * @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 * @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 * Setter functions

View File

@ -40,18 +40,17 @@ extern "C" {
/*Data of check box*/ /*Data of check box*/
typedef struct { typedef struct {
lv_btn_ext_t bg_btn; /*Ext. of ancestor*/ /*No inherited ext, derived from the base object */
/*New data for this type */
lv_obj_t * bullet; /*Pointer to button*/ /*New data for this widget */
lv_obj_t * text; /*Pointer to button*/
lv_obj_t * label; /*Pointer to label*/ lv_obj_t * label; /*Pointer to label*/
} lv_checkbox_ext_t; } lv_checkbox_ext_t;
/** Checkbox styles. */ /** Checkbox styles. */
enum { 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_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; typedef uint8_t lv_checkbox_style_t;

View File

@ -71,14 +71,16 @@ static lv_signal_cb_t ancestor_signal;
/** /**
* Create a label objects * Create a label objects
* @param parent pointer to an object, it will be the parent of the new label * @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 * @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"); LV_LOG_TRACE("label create started");
/*Create a basic object*/ /*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); LV_ASSERT_MEM(new_label);
if(new_label == NULL) return NULL; if(new_label == NULL) return NULL;

View File

@ -112,9 +112,11 @@ typedef uint8_t lv_label_part_t;
/** /**
* Create a label objects * Create a label objects
* @param parent pointer to an object, it will be the parent of the new label * @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 * @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 * Setter functions

View File

@ -41,7 +41,7 @@ static void lv_slider_draw_knob(lv_obj_t * slider, const lv_area_t * knob_area,
/********************** /**********************
* STATIC VARIABLES * STATIC VARIABLES
**********************/ **********************/
static lv_design_cb_t ancestor_design_f; static lv_design_cb_t ancestor_design;
static lv_signal_cb_t ancestor_signal; static lv_signal_cb_t ancestor_signal;
/********************** /**********************
@ -54,20 +54,21 @@ static lv_signal_cb_t ancestor_signal;
/** /**
* Create a slider objects * Create a slider objects
* @param par pointer to an object, it will be the parent of the new slider * @param parent 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 copy DEPRECATED, will be removed in v9.
* Pointer to an other slider to copy.
* @return pointer to the created slider * @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"); LV_LOG_TRACE("slider create started");
/*Create the ancestor slider*/ /*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); LV_ASSERT_MEM(slider);
if(slider == NULL) return NULL; 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); if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_cb(slider);
/*Allocate the slider type specific extended data*/ /*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*/ /*Init the new slider slider*/
if(copy == NULL) { 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_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); lv_obj_set_height(slider, LV_DPI / 15);
} } else {
/*Copy an existing slider*/
else {
lv_slider_ext_t * copy_ext = lv_obj_get_ext_attr(copy); lv_slider_ext_t * copy_ext = lv_obj_get_ext_attr(copy);
lv_style_list_copy(&ext->style_knob, &copy_ext->style_knob); lv_style_list_copy(&ext->style_knob, &copy_ext->style_knob);
lv_area_copy(&ext->left_knob_area, &copy_ext->left_knob_area); lv_area_copy(&ext->left_knob_area, &copy_ext->left_knob_area);
lv_area_copy(&ext->right_knob_area, &copy_ext->right_knob_area); lv_area_copy(&ext->right_knob_area, &copy_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"); LV_LOG_INFO("slider created");
return slider; return slider;
@ -119,17 +117,6 @@ lv_obj_t * lv_slider_create(lv_obj_t * par, const lv_obj_t * copy)
* Getter functions * 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 * Give the slider is being dragged or not
* @param slider pointer to a slider object * @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. /*The ancestor design function will draw the background and the indicator.
* It also sets ext->bar.indic_area*/ * 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_slider_ext_t * ext = lv_obj_get_ext_attr(slider);
lv_bidi_dir_t base_dir = lv_obj_get_base_dir(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*/ /*Post draw when the children are drawn*/
else if(mode == LV_DESIGN_DRAW_POST) { 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; 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 */ /* Include the ancient signal function */
res = ancestor_signal(slider, sign, param); res = ancestor_signal(slider, sign, param);
if(res != LV_RES_OK) return res; 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_type_t type = lv_slider_get_type(slider);
lv_slider_ext_t * ext = lv_obj_get_ext_attr(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 w = lv_obj_get_width(slider);
lv_coord_t h = lv_obj_get_height(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_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_BG); 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_BG); 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_BG); 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; int32_t range = ext->bar.max_value - ext->bar.min_value;
int16_t new_value = 0; 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 += 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 += 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*/ /*Indic. size is handled by bar*/
slider->ext_draw_pad = LV_MATH_MAX(slider->ext_draw_pad, knob_size); 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 #endif
} }
else if(sign == LV_SIGNAL_CLEANUP) { 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) { else if(sign == LV_SIGNAL_GET_EDITABLE) {
#if LV_USE_GROUP #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; lv_style_list_t * style_dsc_p;
switch(part) { switch(part) {
case LV_SLIDER_PART_BG: case LV_SLIDER_PART_MAIN:
style_dsc_p = &slider->style_list; style_dsc_p = &slider->style_list;
break; break;
case LV_SLIDER_PART_INDIC: case LV_SLIDER_PART_INDIC:

View File

@ -53,9 +53,10 @@ typedef struct {
/** Built-in styles of slider*/ /** Built-in styles of slider*/
enum { enum {
LV_SLIDER_PART_BG, /** Slider background style. */ LV_SLIDER_PART_MAIN = LV_BAR_PART_MAIN, /** Slider background style. */
LV_SLIDER_PART_INDIC, /** Slider indicator (filled area) style. */ LV_SLIDER_PART_INDIC = LV_BAR_PART_INDIC, /** Slider indicator (filled area) style. */
LV_SLIDER_PART_KNOB, /** Slider knob 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 * Create a slider objects
* @param par pointer to an object, it will be the parent of the new slider * @param parent 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 copy DEPRECATED, will be removed in v9.
* Pointer to an other slider to copy.
* @return pointer to the created slider * @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 * 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 * @param slider pointer to a slider object
* @return the value of the main knob of the slider * @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 * Get the value of the left knob of a slider

View File

@ -55,16 +55,17 @@ static lv_design_cb_t ancestor_design;
/** /**
* Create a switch objects * Create a switch objects
* @param par pointer to an object, it will be the parent of the new switch * @param parent 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 copy DEPRECATED, will be removed in v9.
* Pointer to an other switch to copy.
* @return pointer to the created switch * @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"); LV_LOG_TRACE("switch create started");
/*Create the ancestor of switch*/ /*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); LV_ASSERT_MEM(sw);
if(sw == NULL) return NULL; 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*/ /*Init the new switch switch*/
if(copy == NULL) { if(copy == NULL) {
lv_obj_set_click(sw, true); lv_obj_add_flag(sw, LV_OBJ_FLAG_CLICKABLE);
lv_obj_add_protect(sw, LV_PROTECT_PRESS_LOST);
lv_obj_set_size(sw, LV_DPX(60), LV_DPX(35)); lv_obj_set_size(sw, LV_DPX(60), LV_DPX(35));
lv_bar_set_range(sw, 0, 1); lv_bar_set_range(sw, 0, 1);
lv_theme_apply(sw, LV_THEME_SWITCH); lv_theme_apply(sw, LV_THEME_SWITCH);
} } else {
/*Copy an existing switch*/
else {
lv_switch_ext_t * copy_ext = lv_obj_get_ext_attr(copy); lv_switch_ext_t * copy_ext = lv_obj_get_ext_attr(copy);
lv_style_list_copy(&ext->style_knob, &copy_ext->style_knob); lv_style_list_copy(&ext->style_knob, &copy_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*/ /*Refresh the style with new signal function*/
LV_LOG_INFO("switch created"); 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_coord_t knob_size = objh;
lv_area_t knob_area; 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_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_BG); 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 max_indic_w = objw - bg_left - bg_right;
lv_coord_t act_indic_w = lv_area_get_width(&ext->bar.indic_area); 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; 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) { if(sign == LV_SIGNAL_GET_STYLE) {
lv_get_style_info_t * info = param; lv_get_style_info_t * info = param;
info->result = lv_switch_get_style(sw, info->part); info->result = lv_switch_get_style(sw, info->part);
if(info->result != NULL) return LV_RES_OK; if(info->result != NULL) return LV_RES_OK;
else return ancestor_signal(sw, sign, param); else return ancestor_signal(sw, sign, param);
} }
else if(sign == LV_SIGNAL_GET_TYPE) {
if(sign == LV_SIGNAL_GET_TYPE) {
res = ancestor_signal(sw, sign, param); res = ancestor_signal(sw, sign, param);
if(res != LV_RES_OK) return res; 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);
} }
else if(sign == LV_SIGNAL_CLEANUP) {
/* Include the ancient signal function */ _lv_obj_reset_style_list_no_refr(sw, LV_SWITCH_PART_KNOB);
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_RELEASED) { else if(sign == LV_SIGNAL_RELEASED) {
if(lv_switch_get_state(sw)) lv_switch_off(sw, LV_ANIM_ON); 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 += 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 += 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*/ /*Indic. size is handled by bar*/
sw->ext_draw_pad = LV_MATH_MAX(sw->ext_draw_pad, knob_size); 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; lv_style_list_t * style_dsc_p;
switch(part) { switch(part) {
case LV_SWITCH_PART_BG: case LV_SWITCH_PART_MAIN:
style_dsc_p = &sw->style_list; style_dsc_p = &sw->style_list;
break; break;
case LV_SWITCH_PART_INDIC: case LV_SWITCH_PART_INDIC:

View File

@ -19,10 +19,9 @@ extern "C" {
/*Testing of dependencies*/ /*Testing of dependencies*/
#if LV_USE_SLIDER == 0 #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 #endif
#include "../lv_core/lv_obj.h"
#include "lv_bar.h" #include "lv_bar.h"
/********************* /*********************
@ -44,7 +43,7 @@ typedef struct {
* Switch parts. * Switch parts.
*/ */
enum { 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_INDIC = LV_BAR_PART_INDIC, /**< Switch fill area. */
LV_SWITCH_PART_KNOB = _LV_BAR_PART_VIRTUAL_LAST, /**< Switch knob. */ LV_SWITCH_PART_KNOB = _LV_BAR_PART_VIRTUAL_LAST, /**< Switch knob. */
_LV_SWITCH_PART_VIRTUAL_LAST _LV_SWITCH_PART_VIRTUAL_LAST
@ -58,11 +57,12 @@ typedef uint8_t lv_switch_part_t;
/** /**
* Create a switch objects * Create a switch objects
* @param par pointer to an object, it will be the parent of the new switch * @param parent 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 copy DEPRECATED, will be removed in v9.
* Pointer to an other switch to copy.
* @return pointer to the created switch * @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 * Setter functions