diff --git a/src/lv_core/lv_disp.c b/src/lv_core/lv_disp.c index bcb73829e..f87f19962 100644 --- a/src/lv_core/lv_disp.c +++ b/src/lv_core/lv_disp.c @@ -43,7 +43,7 @@ lv_obj_t * lv_disp_get_scr_act(lv_disp_t * disp) { if(!disp) disp = lv_disp_get_default(); if(!disp) { - LV_LOG_WARN("lv_scr_act: no display registered to get its top layer"); + LV_LOG_WARN("lv_scr_act: no display registered to get its act. screen"); return NULL; } @@ -89,7 +89,7 @@ lv_obj_t * lv_disp_get_layer_sys(lv_disp_t * disp) { if(!disp) disp = lv_disp_get_default(); if(!disp) { - LV_LOG_WARN("lv_layer_sys: no display registered to get its top layer"); + LV_LOG_WARN("lv_layer_sys: no display registered to get its sys. layer"); return NULL; } diff --git a/src/lv_core/lv_indev.c b/src/lv_core/lv_indev.c index 152e356c7..5c322f28f 100644 --- a/src/lv_core/lv_indev.c +++ b/src/lv_core/lv_indev.c @@ -820,6 +820,11 @@ static void indev_proc_press(lv_indev_proc_t * proc) if(indev_reset_check(proc)) return; if(indev_act->proc.wait_until_release) return; + + /*Handle focus*/ + indev_click_focus(&indev_act->proc); + if(indev_reset_check(proc)) return; + } } @@ -944,9 +949,6 @@ static void indev_proc_release(lv_indev_proc_t * proc) if(indev_reset_check(proc)) return; } - indev_click_focus(&indev_act->proc); - if(indev_reset_check(proc)) return; - /*Send LV_EVENT_DRAG_THROW_BEGIN if required */ /*If drag parent is active check recursively the drag_parent attribute*/ lv_obj_t * drag_obj = get_dragged_obj(indev_obj_act); diff --git a/src/lv_core/lv_obj.c b/src/lv_core/lv_obj.c index 3e7c10bf4..5095e3ae4 100644 --- a/src/lv_core/lv_obj.c +++ b/src/lv_core/lv_obj.c @@ -737,7 +737,6 @@ void lv_obj_set_size(lv_obj_t * obj, lv_coord_t w, lv_coord_t h) { LV_ASSERT_OBJ(obj, LV_OBJX_NAME); - /* Do nothing if the size is not changed */ /* It is very important else recursive resizing can * occur without size change*/ @@ -1139,12 +1138,6 @@ void lv_obj_add_style(lv_obj_t * obj, uint8_t part, lv_style_t * style) } -void lv_obj_add_theme(void * obj, uint8_t part, uint16_t name) -{ - lv_obj_add_style(obj, part, lv_theme_get_style(name)); -} - - void lv_obj_reset_style(lv_obj_t * obj, uint8_t part) { lv_style_list_t * style_dsc = lv_obj_get_style_list(obj, part); @@ -2698,7 +2691,7 @@ static void lv_obj_del_async_cb(void * obj) */ void lv_obj_init_draw_rect_dsc(lv_obj_t * obj, uint8_t part, lv_draw_rect_dsc_t * draw_dsc) { - draw_dsc->radius = lv_obj_get_style_radius(obj, LV_OBJ_PART_MAIN); + draw_dsc->radius = lv_obj_get_style_radius(obj, part); lv_opa_t opa_scale = lv_obj_get_style_opa_scale(obj, part); if(opa_scale <= LV_OPA_MIN) { @@ -2819,8 +2812,8 @@ void lv_obj_init_draw_label_dsc(lv_obj_t * obj, uint8_t part, lv_draw_label_dsc_ if(draw_dsc->opa <= LV_OPA_MIN) return; draw_dsc->color = lv_obj_get_style_text_color(obj, part); - draw_dsc->letter_space = lv_obj_get_style_letter_space(obj, part); - draw_dsc->line_space = lv_obj_get_style_line_space(obj, part); + draw_dsc->letter_space = lv_obj_get_style_text_letter_space(obj, part); + draw_dsc->line_space = lv_obj_get_style_text_line_space(obj, part); draw_dsc->font = lv_obj_get_style_font(obj, part); @@ -2887,24 +2880,24 @@ lv_coord_t lv_obj_get_draw_rect_ext_pad_size(lv_obj_t * obj, uint8_t part) lv_opa_t sh_opa = lv_obj_get_style_shadow_opa(obj, part); if(sh_opa > LV_OPA_MIN) { - lv_coord_t sh_width = lv_obj_get_style_shadow_width(obj, LV_OBJ_PART_MAIN); + lv_coord_t sh_width = lv_obj_get_style_shadow_width(obj, part); if(sh_width) { sh_width = sh_width / 2; /*THe blur adds only half width*/ sh_width++; - sh_width += lv_obj_get_style_shadow_spread(obj, LV_OBJ_PART_MAIN); - sh_width += LV_MATH_MAX(LV_MATH_ABS(lv_obj_get_style_shadow_offset_x(obj, LV_OBJ_PART_MAIN)), - LV_MATH_ABS(lv_obj_get_style_shadow_offset_y(obj, LV_OBJ_PART_MAIN))); + sh_width += lv_obj_get_style_shadow_spread(obj, part); + sh_width += LV_MATH_MAX(LV_MATH_ABS(lv_obj_get_style_shadow_offset_x(obj, part)), + LV_MATH_ABS(lv_obj_get_style_shadow_offset_y(obj, part))); s = LV_MATH_MAX(s, sh_width); } } lv_opa_t value_opa = lv_obj_get_style_value_opa(obj, part); if(value_opa > LV_OPA_MIN) { - const char * value_str = lv_obj_get_style_value_str(obj, LV_OBJ_PART_MAIN); + const char * value_str = lv_obj_get_style_value_str(obj, part); if(value_str) { - lv_style_int_t letter_space = lv_obj_get_style_value_letter_space(obj, LV_OBJ_PART_MAIN); - lv_style_int_t line_space = lv_obj_get_style_value_letter_space(obj, LV_OBJ_PART_MAIN); - const lv_font_t * font = lv_obj_get_style_value_font(obj, LV_OBJ_PART_MAIN); + lv_style_int_t letter_space = lv_obj_get_style_value_letter_space(obj, part); + lv_style_int_t line_space = lv_obj_get_style_value_letter_space(obj, part); + const lv_font_t * font = lv_obj_get_style_value_font(obj, part); lv_point_t txt_size; lv_txt_get_size(&txt_size, value_str, font, letter_space, line_space, LV_COORD_MAX, LV_TXT_FLAG_NONE); @@ -2915,9 +2908,9 @@ lv_coord_t lv_obj_get_draw_rect_ext_pad_size(lv_obj_t * obj, uint8_t part) value_area.x2 = txt_size.x - 1; value_area.y2 = txt_size.y - 1; - lv_style_int_t align = lv_obj_get_style_value_align(obj, LV_OBJ_PART_MAIN); - lv_style_int_t xofs = lv_obj_get_style_value_ofs_x(obj, LV_OBJ_PART_MAIN); - lv_style_int_t yofs = lv_obj_get_style_value_ofs_y(obj, LV_OBJ_PART_MAIN); + lv_style_int_t align = lv_obj_get_style_value_align(obj, part); + lv_style_int_t xofs = lv_obj_get_style_value_ofs_x(obj, part); + lv_style_int_t yofs = lv_obj_get_style_value_ofs_y(obj, part); lv_point_t p_align; lv_area_align(&obj->coords, &value_area, align, &p_align); @@ -2935,9 +2928,9 @@ lv_coord_t lv_obj_get_draw_rect_ext_pad_size(lv_obj_t * obj, uint8_t part) lv_opa_t outline_opa = lv_obj_get_style_outline_opa(obj, part); if(outline_opa > LV_OPA_MIN) { - lv_style_int_t outline_width = lv_obj_get_style_outline_width(obj, LV_OBJ_PART_MAIN); + lv_style_int_t outline_width = lv_obj_get_style_outline_width(obj, part); if(outline_width) { - lv_style_int_t outline_pad = lv_obj_get_style_outline_pad(obj, LV_OBJ_PART_MAIN); + lv_style_int_t outline_pad = lv_obj_get_style_outline_pad(obj, part); s = LV_MATH_MAX(s, outline_pad + outline_width); } } diff --git a/src/lv_core/lv_obj.h b/src/lv_core/lv_obj.h index 71feb9747..85b641dca 100644 --- a/src/lv_core/lv_obj.h +++ b/src/lv_core/lv_obj.h @@ -494,8 +494,6 @@ void lv_obj_set_style_ptr(lv_obj_t * obj, uint8_t type, lv_style_property_t prop void lv_obj_add_style(lv_obj_t * obj, uint8_t type, lv_style_t * style); -void lv_obj_add_theme(void * obj, uint8_t part, uint16_t name); - void lv_obj_reset_style(lv_obj_t * obj, uint8_t type); /** @@ -904,6 +902,7 @@ static inline void lv_style_set_##func_name (lv_style_t * style, lv_style_state_ LV_OBJ_STYLE_SET_GET_DECLARE(RADIUS, radius, lv_style_int_t,_int); LV_OBJ_STYLE_SET_GET_DECLARE(CLIP_CORNER, clip_corner, bool, _int); LV_OBJ_STYLE_SET_GET_DECLARE(TRANSITION_TIME, transition_time, lv_style_int_t, _int); +LV_OBJ_STYLE_SET_GET_DECLARE(SIZE, size, lv_style_int_t, _int); LV_OBJ_STYLE_SET_GET_DECLARE(OPA_SCALE, opa_scale, lv_opa_t, _opa); LV_OBJ_STYLE_SET_GET_DECLARE(PAD_TOP, pad_top, lv_style_int_t, _int); LV_OBJ_STYLE_SET_GET_DECLARE(PAD_BOTTOM, pad_bottom, lv_style_int_t, _int); @@ -951,8 +950,8 @@ LV_OBJ_STYLE_SET_GET_DECLARE(VALUE_COLOR, value_color, lv_color_t, _color); LV_OBJ_STYLE_SET_GET_DECLARE(VALUE_OPA, value_opa, lv_opa_t, _opa); LV_OBJ_STYLE_SET_GET_DECLARE(VALUE_FONT, value_font, const lv_font_t * , _ptr); LV_OBJ_STYLE_SET_GET_DECLARE(VALUE_STR, value_str, const char * , _ptr); -LV_OBJ_STYLE_SET_GET_DECLARE(TEXT_LETTER_SPACE, letter_space, lv_style_int_t, _int); -LV_OBJ_STYLE_SET_GET_DECLARE(TEXT_LINE_SPACE, line_space, lv_style_int_t, _int); +LV_OBJ_STYLE_SET_GET_DECLARE(TEXT_LETTER_SPACE, text_letter_space, lv_style_int_t, _int); +LV_OBJ_STYLE_SET_GET_DECLARE(TEXT_LINE_SPACE, text_line_space, lv_style_int_t, _int); LV_OBJ_STYLE_SET_GET_DECLARE(TEXT_BLEND_MODE, text_blend_mode, lv_blend_mode_t, _int); LV_OBJ_STYLE_SET_GET_DECLARE(TEXT_COLOR, text_color, lv_color_t, _color); LV_OBJ_STYLE_SET_GET_DECLARE(TEXT_SEL_COLOR, text_sel_color, lv_color_t, _color); @@ -969,10 +968,10 @@ LV_OBJ_STYLE_SET_GET_DECLARE(IMAGE_BLEND_MODE, image_blend_mode, lv_blend_mode_t LV_OBJ_STYLE_SET_GET_DECLARE(IMAGE_RECOLOR, image_recolor, lv_color_t, _color); LV_OBJ_STYLE_SET_GET_DECLARE(IMAGE_OPA, image_opa, lv_opa_t, _opa); LV_OBJ_STYLE_SET_GET_DECLARE(IMAGE_RECOLOR_OPA, image_recolor_opa, lv_opa_t, _opa); -LV_OBJ_STYLE_SET_GET_DECLARE(SIZE, size, lv_style_int_t, _int); LV_OBJ_STYLE_SET_GET_DECLARE(SCALE_WIDTH, scale_width, lv_style_int_t, _int); LV_OBJ_STYLE_SET_GET_DECLARE(SCALE_BORDER_WIDTH, scale_border_width, lv_style_int_t, _int); LV_OBJ_STYLE_SET_GET_DECLARE(SCALE_END_BORDER_WIDTH, scale_end_border_width, lv_style_int_t, _int); +LV_OBJ_STYLE_SET_GET_DECLARE(SCALE_END_LINE_WIDTH, scale_end_line_width, lv_style_int_t, _int); LV_OBJ_STYLE_SET_GET_DECLARE(SCALE_COLOR, scale_color, lv_color_t, _color); LV_OBJ_STYLE_SET_GET_DECLARE(SCALE_GRAD_COLOR, scale_grad_color, lv_color_t, _color); LV_OBJ_STYLE_SET_GET_DECLARE(SCALE_END_COLOR, scale_end_color, lv_color_t, _color); diff --git a/src/lv_core/lv_style.h b/src/lv_core/lv_style.h index 8d8b11c6c..d420be21f 100644 --- a/src/lv_core/lv_style.h +++ b/src/lv_core/lv_style.h @@ -79,6 +79,7 @@ enum { LV_STYLE_PROP_INIT(LV_STYLE_RADIUS, 0x0, LV_STYLE_ID_VALUE + 0, LV_STYLE_ATTR_NONE), LV_STYLE_PROP_INIT(LV_STYLE_CLIP_CORNER, 0x0, LV_STYLE_ID_VALUE + 1, LV_STYLE_ATTR_NONE), LV_STYLE_PROP_INIT(LV_STYLE_TRANSITION_TIME, 0x0, LV_STYLE_ID_VALUE + 2, LV_STYLE_ATTR_NONE), + LV_STYLE_PROP_INIT(LV_STYLE_SIZE, 0x0, LV_STYLE_ID_VALUE + 3, LV_STYLE_ATTR_NONE), LV_STYLE_PROP_INIT(LV_STYLE_OPA_SCALE, 0x0, LV_STYLE_ID_OPA + 0, LV_STYLE_ATTR_INHERIT), LV_STYLE_PROP_INIT(LV_STYLE_PAD_TOP, 0x1, LV_STYLE_ID_VALUE + 0, LV_STYLE_ATTR_NONE), @@ -155,10 +156,10 @@ enum { LV_STYLE_PROP_INIT(LV_STYLE_IMAGE_OPA, 0xA, LV_STYLE_ID_OPA + 0, LV_STYLE_ATTR_INHERIT), LV_STYLE_PROP_INIT(LV_STYLE_IMAGE_RECOLOR_OPA, 0xA, LV_STYLE_ID_OPA + 1, LV_STYLE_ATTR_INHERIT), - LV_STYLE_PROP_INIT(LV_STYLE_SIZE, 0xB, LV_STYLE_ID_VALUE + 0, LV_STYLE_ATTR_NONE), - LV_STYLE_PROP_INIT(LV_STYLE_SCALE_WIDTH, 0xB, LV_STYLE_ID_VALUE + 1, LV_STYLE_ATTR_NONE), - LV_STYLE_PROP_INIT(LV_STYLE_SCALE_BORDER_WIDTH, 0xB, LV_STYLE_ID_VALUE + 2, LV_STYLE_ATTR_NONE), - LV_STYLE_PROP_INIT(LV_STYLE_SCALE_END_BORDER_WIDTH, 0xB, LV_STYLE_ID_VALUE + 3, LV_STYLE_ATTR_NONE), + LV_STYLE_PROP_INIT(LV_STYLE_SCALE_WIDTH, 0xB, LV_STYLE_ID_VALUE + 0, LV_STYLE_ATTR_NONE), + LV_STYLE_PROP_INIT(LV_STYLE_SCALE_BORDER_WIDTH, 0xB, LV_STYLE_ID_VALUE + 1, LV_STYLE_ATTR_NONE), + LV_STYLE_PROP_INIT(LV_STYLE_SCALE_END_BORDER_WIDTH, 0xB, LV_STYLE_ID_VALUE + 2, LV_STYLE_ATTR_NONE), + LV_STYLE_PROP_INIT(LV_STYLE_SCALE_END_LINE_WIDTH, 0xB, LV_STYLE_ID_VALUE + 3, LV_STYLE_ATTR_NONE), LV_STYLE_PROP_INIT(LV_STYLE_SCALE_COLOR, 0xB, LV_STYLE_ID_COLOR + 0, LV_STYLE_ATTR_NONE), LV_STYLE_PROP_INIT(LV_STYLE_SCALE_GRAD_COLOR, 0xB, LV_STYLE_ID_COLOR + 1, LV_STYLE_ATTR_NONE), LV_STYLE_PROP_INIT(LV_STYLE_SCALE_END_COLOR, 0xB, LV_STYLE_ID_COLOR + 2, LV_STYLE_ATTR_NONE), diff --git a/src/lv_draw/lv_draw_arc.c b/src/lv_draw/lv_draw_arc.c index 31cf5c412..102520bb2 100644 --- a/src/lv_draw/lv_draw_arc.c +++ b/src/lv_draw/lv_draw_arc.c @@ -93,6 +93,8 @@ void lv_draw_arc(lv_coord_t center_x, lv_coord_t center_y, uint16_t radius, uin lv_draw_rect(&area, clip_area, &cir_dsc); return; } + if(start_angle >= 360) start_angle -= 360; + if(end_angle >= 360) end_angle -= 360; lv_draw_mask_angle_param_t mask_angle_param; lv_draw_mask_angle_init(&mask_angle_param, center_x, center_y, start_angle, end_angle); diff --git a/src/lv_objx/lv_arc.c b/src/lv_objx/lv_arc.c index 807138d36..a609f7a29 100644 --- a/src/lv_objx/lv_arc.c +++ b/src/lv_objx/lv_arc.c @@ -93,8 +93,12 @@ lv_obj_t * lv_arc_create(lv_obj_t * par, const lv_obj_t * copy) /*Copy an existing arc*/ else { lv_arc_ext_t * copy_ext = lv_obj_get_ext_attr(copy); - ext->arc_angle_start = copy_ext->arc_angle_start; - ext->arc_angle_end = copy_ext->arc_angle_end; + ext->arc_angle_start = copy_ext->arc_angle_start; + ext->arc_angle_end = copy_ext->arc_angle_end; + ext->bg_angle_start = copy_ext->bg_angle_start; + ext->bg_angle_end = copy_ext->bg_angle_end; + + lv_style_list_copy(&ext->style_arc, ©_ext->style_arc); /*Refresh the style with new signal function*/ lv_obj_refresh_style(arc); @@ -118,7 +122,7 @@ lv_obj_t * lv_arc_create(lv_obj_t * par, const lv_obj_t * copy) *====================*/ /** - * Set the start angle of an arc. 0 deg: right, 90 bottom: right etc. + * Set the start angle of an arc. 0 deg: right, 90 bottom, etc. * @param arc pointer to an arc object * @param start the start angle [0..360] */ @@ -151,7 +155,7 @@ void lv_arc_set_start_angle(lv_obj_t * arc, int16_t start) } /** - * Set the start angle of an arc. 0 deg: right, 90 bottom: right etc. + * Set the start angle of an arc. 0 deg: right, 90 bottom, etc. * @param arc pointer to an arc object * @param start the start angle [0..360] */ @@ -161,8 +165,6 @@ void lv_arc_set_end_angle(lv_obj_t * arc, int16_t end) lv_arc_ext_t * ext = lv_obj_get_ext_attr(arc); - if(end > 360) end -= 360; - /*Too large move, the whole arc need to be invalidated anyway*/ if(LV_MATH_ABS(end - ext->arc_angle_end) >= 180) { lv_obj_invalidate(arc); @@ -207,6 +209,96 @@ void lv_arc_set_angles(lv_obj_t * arc, uint16_t start, uint16_t end) inv_arc_area(arc, ext->arc_angle_start, ext->arc_angle_end); } +/** + * Set the start angle of an arc background. 0 deg: right, 90 bottom, etc. + * @param arc pointer to an arc object + * @param start the start angle + */ +void lv_arc_set_bg_start_angle(lv_obj_t * arc, int16_t start) +{ + LV_ASSERT_OBJ(arc, LV_OBJX_NAME); + + lv_arc_ext_t * ext = lv_obj_get_ext_attr(arc); + + if(start > 360) start -= 360; + + /*Too large move, the whole arc need to be invalidated anyway*/ + if(LV_MATH_ABS(start - ext->bg_angle_start) >= 180) { + lv_obj_invalidate(arc); + } + /*Only a smaller incremental move*/ + else if(ext->bg_angle_start > ext->bg_angle_end && start > ext->bg_angle_end) { + inv_arc_area(arc, LV_MATH_MIN(ext->bg_angle_start, start), LV_MATH_MAX(ext->bg_angle_start, start)); + } + /*Only a smaller incremental move*/ + else if(ext->bg_angle_start < ext->arc_angle_end && start < ext->bg_angle_end) { + inv_arc_area(arc, LV_MATH_MIN(ext->arc_angle_start, start), LV_MATH_MAX(ext->arc_angle_start, start)); + } + /*Crossing the start angle makes the whole arc change*/ + else { + lv_obj_invalidate(arc); + } + + ext->bg_angle_start = start; +} + +/** + * Set the start angle of an arc background. 0 deg: right, 90 bottom etc. + * @param arc pointer to an arc object + * @param end the end angle + */ +void lv_arc_set_bg_end_angle(lv_obj_t * arc, int16_t end) +{ + LV_ASSERT_OBJ(arc, LV_OBJX_NAME); + + lv_arc_ext_t * ext = lv_obj_get_ext_attr(arc); + + if(end > 360) end -= 360; + + /*Too large move, the whole arc need to be invalidated anyway*/ + if(LV_MATH_ABS(end - ext->bg_angle_end) >= 180) { + lv_obj_invalidate(arc); + } + /*Only a smaller incremental move*/ + 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 ) { + 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*/ + else { + lv_obj_invalidate(arc); + } + + ext->bg_angle_end= end; +} + +/** + * Set the start and end angles of the arc background + * @param arc pointer to an arc object + * @param start the start angle + * @param end the end angle + */ +void lv_arc_set_bg_angles(lv_obj_t * arc, uint16_t start, uint16_t end) +{ + LV_ASSERT_OBJ(arc, LV_OBJX_NAME); + + lv_arc_ext_t * ext = lv_obj_get_ext_attr(arc); + + if(end > 360) end -= 360; + if(start > 360) start -= 360; + + inv_arc_area(arc, ext->bg_angle_start, ext->bg_angle_end); + + ext->bg_angle_start = start; + ext->bg_angle_end = end; + + inv_arc_area(arc, ext->bg_angle_start, ext->bg_angle_end); +} + + /*===================== * Getter functions *====================*/ @@ -271,9 +363,19 @@ static lv_design_res_t lv_arc_design(lv_obj_t * arc, const lv_area_t * clip_area else if(mode == LV_DESIGN_DRAW_MAIN) { lv_arc_ext_t * ext = lv_obj_get_ext_attr(arc); - lv_coord_t r = (LV_MATH_MIN(lv_obj_get_width(arc), lv_obj_get_height(arc))) / 2; - lv_coord_t x = arc->coords.x1 + lv_obj_get_width(arc) / 2; - lv_coord_t y = arc->coords.y1 + lv_obj_get_height(arc) / 2; + lv_draw_rect_dsc_t bg_dsc; + lv_draw_rect_dsc_init(&bg_dsc); + lv_obj_init_draw_rect_dsc(arc, LV_ARC_PART_BG, &bg_dsc); + + lv_draw_rect(&arc->coords, clip_area, &bg_dsc); + + lv_coord_t left = lv_obj_get_style_pad_left(arc, LV_ARC_PART_BG); + lv_coord_t right = lv_obj_get_style_pad_right(arc, LV_ARC_PART_BG); + lv_coord_t top = lv_obj_get_style_pad_top(arc, LV_ARC_PART_BG); + lv_coord_t bottom = lv_obj_get_style_pad_bottom(arc, LV_ARC_PART_BG); + lv_coord_t r = (LV_MATH_MIN(lv_obj_get_width(arc) - left - right, lv_obj_get_height(arc) - top - bottom)) / 2; + lv_coord_t x = arc->coords.x1 + r + left; + lv_coord_t y = arc->coords.y1 + r + top; lv_draw_line_dsc_t arc_dsc; lv_draw_line_dsc_init(&arc_dsc); @@ -353,11 +455,19 @@ static lv_style_list_t * lv_arc_get_style(lv_obj_t * arc, uint8_t part) static void inv_arc_area(lv_obj_t * arc, uint16_t start_angle, uint16_t end_angle) { + if(start_angle >= 360) start_angle -= 360; + if(end_angle >= 360) end_angle -= 360; + uint8_t start_quarter = start_angle / 90; uint8_t end_quarter = end_angle / 90; - lv_coord_t x = arc->coords.x1 + lv_obj_get_width(arc) / 2; - lv_coord_t y = arc->coords.y1 + lv_obj_get_height(arc) / 2; - lv_coord_t rout = (LV_MATH_MIN(lv_obj_get_width(arc), lv_obj_get_height(arc))) / 2; + + lv_coord_t left = lv_obj_get_style_pad_left(arc, LV_ARC_PART_BG); + lv_coord_t right = lv_obj_get_style_pad_right(arc, LV_ARC_PART_BG); + lv_coord_t top = lv_obj_get_style_pad_top(arc, LV_ARC_PART_BG); + lv_coord_t bottom = lv_obj_get_style_pad_bottom(arc, LV_ARC_PART_BG); + lv_coord_t rout = (LV_MATH_MIN(lv_obj_get_width(arc) - left - right, lv_obj_get_height(arc) - top - bottom)) / 2; + lv_coord_t x = arc->coords.x1 + rout + left; + lv_coord_t y = arc->coords.y1 + rout + top; lv_style_int_t w = lv_obj_get_style_line_width(arc, LV_ARC_PART_ARC); lv_style_int_t rounded = lv_obj_get_style_line_rounded(arc, LV_ARC_PART_ARC); lv_coord_t rin = rout - w; diff --git a/src/lv_objx/lv_arc.h b/src/lv_objx/lv_arc.h index 8a61eb56e..91d0d3130 100644 --- a/src/lv_objx/lv_arc.h +++ b/src/lv_objx/lv_arc.h @@ -68,14 +68,14 @@ lv_obj_t * lv_arc_create(lv_obj_t * par, const lv_obj_t * copy); *====================*/ /** - * Set the start angle of an arc. 0 deg: right, 90 bottom: right etc. + * Set the start angle of an arc. 0 deg: right, 90 bottom, etc. * @param arc pointer to an arc object * @param start the start angle */ void lv_arc_set_start_angle(lv_obj_t * arc, int16_t start); /** - * Set the start angle of an arc. 0 deg: right, 90 bottom: right etc. + * Set the start angle of an arc. 0 deg: right, 90 bottom, etc. * @param arc pointer to an arc object * @param end the end angle */ @@ -89,6 +89,28 @@ void lv_arc_set_end_angle(lv_obj_t * arc, int16_t end); */ void lv_arc_set_angles(lv_obj_t * arc, uint16_t start, uint16_t end); +/** + * Set the start angle of an arc background. 0 deg: right, 90 bottom, etc. + * @param arc pointer to an arc object + * @param start the start angle + */ +void lv_arc_set_bg_start_angle(lv_obj_t * arc, int16_t start); + +/** + * Set the start angle of an arc background. 0 deg: right, 90 bottom etc. + * @param arc pointer to an arc object + * @param end the end angle + */ +void lv_arc_set_bg_end_angle(lv_obj_t * arc, int16_t end); + +/** + * Set the start and end angles of the arc background + * @param arc pointer to an arc object + * @param start the start angle + * @param end the end angle + */ +void lv_arc_set_bg_angles(lv_obj_t * arc, uint16_t start, uint16_t end); + /*===================== * Getter functions *====================*/ diff --git a/src/lv_objx/lv_bar.c b/src/lv_objx/lv_bar.c index 80561b4bb..b7bb88277 100644 --- a/src/lv_objx/lv_bar.c +++ b/src/lv_objx/lv_bar.c @@ -123,7 +123,6 @@ lv_obj_t * lv_bar_create(lv_obj_t * par, const lv_obj_t * copy) ext->start_value = ext_copy->start_value; ext->max_value = ext_copy->max_value; ext->cur_value = ext_copy->cur_value; - ext->style_indic = ext_copy->style_indic; ext->type = ext_copy->type; lv_style_list_copy(&ext->style_indic, &ext_copy->style_indic); @@ -512,7 +511,7 @@ static void draw_indic(lv_obj_t * bar, const lv_area_t * clip_area) 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; - void * pattern_src = draw_indic_dsc.pattern_image; + const void * pattern_src = draw_indic_dsc.pattern_image; draw_indic_dsc.bg_opa = LV_OPA_TRANSP; draw_indic_dsc.border_opa = LV_OPA_TRANSP; draw_indic_dsc.value_opa = LV_OPA_TRANSP; @@ -600,7 +599,7 @@ static lv_res_t lv_bar_signal(lv_obj_t * bar, lv_signal_t sign, void * param) 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_SLIDER_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); diff --git a/src/lv_objx/lv_btnm.c b/src/lv_objx/lv_btnm.c index 0e42a7c00..303292ba9 100644 --- a/src/lv_objx/lv_btnm.c +++ b/src/lv_objx/lv_btnm.c @@ -587,7 +587,6 @@ static lv_design_res_t lv_btnm_design(lv_obj_t * btnm, const lv_area_t * clip_ar else if(mode == LV_DESIGN_DRAW_MAIN) { ancestor_design_f(btnm, clip_area, mode); - lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm); if(ext->btn_cnt == 0) return LV_DESIGN_RES_OK; lv_area_t area_btnm; @@ -795,7 +794,6 @@ static lv_res_t lv_btnm_signal(lv_obj_t * btnm, lv_signal_t sign, void * param) invalidate_button_area(btnm, ext->btn_id_pr); lv_indev_type_t indev_type = lv_indev_get_type(lv_indev_get_act()); - if(indev_type == LV_INDEV_TYPE_POINTER || indev_type == LV_INDEV_TYPE_BUTTON) { uint16_t btn_pr; /*Search the pressed area*/ @@ -860,7 +858,14 @@ static lv_res_t lv_btnm_signal(lv_obj_t * btnm, lv_signal_t sign, void * param) /*Invalidate to old pressed area*/; invalidate_button_area(btnm, ext->btn_id_pr); - ext->btn_id_focused = ext->btn_id_pr; + invalidate_button_area(btnm, ext->btn_id_focused); + + + lv_indev_type_t indev_type = lv_indev_get_type(lv_indev_get_act()); + if(indev_type == LV_INDEV_TYPE_KEYPAD || indev_type == LV_INDEV_TYPE_ENCODER) { + ext->btn_id_focused = ext->btn_id_pr; + } + ext->btn_id_pr = LV_BTNM_BTN_NONE; if(button_is_click_trig(ext->ctrl_bits[ext->btn_id_act]) == true && diff --git a/src/lv_objx/lv_calendar.c b/src/lv_objx/lv_calendar.c index 2dd1b8511..8c885d70b 100644 --- a/src/lv_objx/lv_calendar.c +++ b/src/lv_objx/lv_calendar.c @@ -826,7 +826,10 @@ static void draw_dates(lv_obj_t * calendar, const lv_area_t * clip_area) box_area.y1 = days_y1 + ((days_h - box_size) * week) / 5; box_area.y2 = box_area.y1 + box_size - 1; - if(box_area.y1 > clip_area->y2) return; + if(box_area.y1 > clip_area->y2) { + calendar->state_dsc = state_ori; + return; + } lv_area_t label_area; label_area.y1 = box_area.y1 + (lv_area_get_height(&box_area) - lv_font_get_line_height(nums_font)) / 2; diff --git a/src/lv_objx/lv_cpicker.c b/src/lv_objx/lv_cpicker.c index 61a261aaf..72ed5279b 100644 --- a/src/lv_objx/lv_cpicker.c +++ b/src/lv_objx/lv_cpicker.c @@ -619,7 +619,7 @@ static void draw_indic(lv_obj_t * cpicker, const lv_area_t * mask) lv_cpicker_ext_t * ext = lv_obj_get_ext_attr(cpicker); lv_draw_rect_dsc_t cir_dsc; - lv_draw_tect_dsc_init(&cir_dsc); + lv_draw_rect_dsc_init(&cir_dsc); lv_obj_init_draw_rect_dsc(cpicker, LV_CPICKER_PART_INDIC, &cir_dsc); cir_dsc.radius = LV_RADIUS_CIRCLE; diff --git a/src/lv_objx/lv_ddlist.c b/src/lv_objx/lv_ddlist.c index 834c9c04c..28859a08e 100644 --- a/src/lv_objx/lv_ddlist.c +++ b/src/lv_objx/lv_ddlist.c @@ -49,8 +49,8 @@ static lv_res_t lv_ddlist_signal(lv_obj_t * ddlist, lv_signal_t sign, void * par static lv_res_t lv_ddlist_page_signal(lv_obj_t * page, lv_signal_t sign, void * param); static lv_res_t lv_ddlist_page_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void * param); static lv_style_list_t * lv_ddlist_get_style(lv_obj_t * ddlist, uint8_t part); -void draw_box(lv_obj_t * ddlist, const lv_area_t * clip_area, uint16_t id, lv_obj_state_t state); -void draw_box_label(lv_obj_t * ddlist, const lv_area_t * clip_area, uint16_t id, lv_obj_state_t state); +static void draw_box(lv_obj_t * ddlist, const lv_area_t * clip_area, uint16_t id, lv_obj_state_t state); +static void draw_box_label(lv_obj_t * ddlist, const lv_area_t * clip_area, uint16_t id, lv_obj_state_t state); static lv_res_t page_release_handler(lv_obj_t * page); static void page_press_handler(lv_obj_t * page); static uint16_t get_id_on_point(lv_obj_t * ddlist, lv_coord_t x, lv_coord_t y); @@ -107,13 +107,13 @@ lv_obj_t * lv_ddlist_create(lv_obj_t * par, const lv_obj_t * copy) ext->page = NULL; ext->options = NULL; ext->symbol = LV_SYMBOL_DOWN; - ext->text = "Select one"; + ext->text = "Select"; ext->show_selected = 1; ext->sel_opt_id = 0; ext->sel_opt_id_orig = 0; ext->pr_opt_id = LV_DDLIST_PR_NONE; ext->option_cnt = 0; - ext->dir = LV_DDLIST_DIR_LEFT; + ext->dir = LV_DDLIST_DIR_DOWN; ext->max_height = LV_DPI * 2; ext->anim_time = LV_DDLIST_DEF_ANIM_TIME; lv_style_list_init(&ext->style_page); @@ -126,8 +126,6 @@ lv_obj_t * lv_ddlist_create(lv_obj_t * par, const lv_obj_t * copy) /*Init the new drop down list drop down list*/ if(copy == NULL) { - lv_cont_set_fit2(ddlist, LV_FIT_NONE, LV_FIT_TIGHT); - lv_ddlist_set_options(ddlist, "Option 1\nOption 2\nOption 3"); lv_theme_apply(ddlist, LV_THEME_DDLIST); @@ -154,6 +152,22 @@ lv_obj_t * lv_ddlist_create(lv_obj_t * par, const lv_obj_t * copy) * Setter functions *====================*/ +/** + * Set text of the ddlist (Displayed on the button if `show_selected = false`) + * @param ddlist pointer to a drop down list object + * @param txt the text as a string (Only it's pointer is saved) + */ +void lv_ddlist_set_text(lv_obj_t * ddlist, const char * txt) +{ + LV_ASSERT_OBJ(ddlist, LV_OBJX_NAME); + lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); + if(ext->text == txt) return; + + ext->text = txt; + + lv_obj_invalidate(ddlist); +} + /** * Set the options in a drop down list from a string * @param ddlist pointer to drop down list object @@ -253,10 +267,40 @@ void lv_ddlist_set_dir(lv_obj_t * ddlist, lv_ddlist_dir_t dir) lv_obj_invalidate(ddlist); } + +/** + * Set whether the ddlist highlight the last selected option and display its text or not + * @param ddlist pointer to a drop down list object + * @param show true/false + */ +void lv_ddlist_set_show_selected(lv_obj_t * ddlist, bool show) +{ + LV_ASSERT_OBJ(ddlist, LV_OBJX_NAME); + + lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); + if(ext->show_selected == show) return; + + ext->show_selected = show; + + lv_obj_invalidate(ddlist); +} /*===================== * Getter functions *====================*/ +/** + * Get text of the ddlist (Displayed on the button if `show_selected = false`) + * @param ddlist pointer to a drop down list object + * @return the text string + */ +const char * lv_ddlist_get_text(lv_obj_t * ddlist) +{ + LV_ASSERT_OBJ(ddlist, LV_OBJX_NAME); + lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); + + return ext->text; +} + /** * Get the options of a drop down list * @param ddlist pointer to drop down list object @@ -369,6 +413,19 @@ lv_ddlist_dir_t lv_ddlist_get_dir(const lv_obj_t * ddlist) return ext->dir; } +/** + * Get whether the ddlist highlight the last selected option and display its text or not + * @param ddlist pointer to a drop down list object + * @return true/false + */ +bool lv_ddlist_get_show_selected(lv_obj_t * ddlist) +{ + lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); + + return ext->show_selected ? true : false; + +} + /*===================== * Other functions *====================*/ @@ -533,8 +590,8 @@ static lv_design_res_t lv_ddlist_design(lv_obj_t * ddlist, const lv_area_t * cli const char * opt_txt = ext->text; if(ext->show_selected) { - char * buf = lv_mem_buf_get(256); - lv_ddlist_get_selected_str(ddlist, buf, 256); + char * buf = lv_mem_buf_get(128); + lv_ddlist_get_selected_str(ddlist, buf, 128); opt_txt = buf; } @@ -544,28 +601,40 @@ static lv_design_res_t lv_ddlist_design(lv_obj_t * ddlist, const lv_area_t * cli 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); - txt_area.x1 = ddlist->coords.x1 + left; txt_area.y1 = ddlist->coords.y1 + top; - txt_area.x2 = txt_area.x1 + txt_size.x; txt_area.y2 = txt_area.y1 + txt_size.y; + /*Center align the text if no symbol*/ + 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 { + txt_area.x1 = ddlist->coords.x1 + left; + txt_area.x2 = txt_area.x1 + txt_size.x; + } lv_draw_label(&txt_area, clip_area, &label_dsc, txt, NULL); } txt = ext->dir != LV_DDLIST_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); - - txt_area.x2 = ddlist->coords.x2 - right; - txt_area.x1 = txt_area.x2 - txt_size.x; txt_area.y1 = ddlist->coords.y1 + top; txt_area.y2 = txt_area.y1 + txt_size.y; + /*Center align the text if no symbol*/ + 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 { + txt_area.x1 = txt_area.x2 - txt_size.x; + txt_area.x2 = ddlist->coords.x2 - right; + } + lv_draw_label(&txt_area, clip_area, &label_dsc, txt, NULL); } if(ext->show_selected && ext->sel_opt_id_orig >= 0) { - lv_mem_buf_release(opt_txt); + lv_mem_buf_release((char *)opt_txt); } } else if(mode == LV_DESIGN_DRAW_POST) { @@ -865,7 +934,7 @@ static lv_style_list_t * lv_ddlist_get_style(lv_obj_t * ddlist, uint8_t part) return style_dsc_p; } -void draw_box(lv_obj_t * ddlist, const lv_area_t * clip_area, uint16_t id, lv_obj_state_t state) +static void draw_box(lv_obj_t * ddlist, const lv_area_t * clip_area, uint16_t id, lv_obj_state_t state) { lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); lv_obj_t * page = ext->page; @@ -877,7 +946,7 @@ void draw_box(lv_obj_t * ddlist, const lv_area_t * clip_area, uint16_t id, lv_ob /*Draw a rectangle under the selected item*/ const lv_font_t * font = lv_obj_get_style_font(ddlist, LV_DDLIST_PART_LIST); - lv_style_int_t line_space = lv_obj_get_style_line_space(ddlist, LV_DDLIST_PART_LIST); + lv_style_int_t line_space = lv_obj_get_style_text_line_space(ddlist, LV_DDLIST_PART_LIST); lv_coord_t font_h = lv_font_get_line_height(font); /*Draw the selected*/ @@ -901,7 +970,7 @@ void draw_box(lv_obj_t * ddlist, const lv_area_t * clip_area, uint16_t id, lv_ob -void draw_box_label(lv_obj_t * ddlist, const lv_area_t * clip_area, uint16_t id, lv_obj_state_t state) +static void draw_box_label(lv_obj_t * ddlist, const lv_area_t * clip_area, uint16_t id, lv_obj_state_t state) { lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); lv_obj_t * page = ext->page; @@ -914,6 +983,7 @@ void draw_box_label(lv_obj_t * ddlist, const lv_area_t * clip_area, uint16_t id, lv_draw_label_dsc_t label_dsc; lv_draw_label_dsc_init(&label_dsc); lv_obj_init_draw_label_dsc(ddlist, LV_DDLIST_PART_SELECTED, &label_dsc); + label_dsc.line_space = lv_obj_get_style_text_line_space(ddlist, LV_DDLIST_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); @@ -1036,7 +1106,7 @@ static void pos_selected(lv_obj_t * ddlist) lv_obj_t * label = get_label(ddlist); lv_coord_t h = lv_obj_get_height(ext->page); - lv_style_int_t line_space = lv_obj_get_style_line_space(ddlist, LV_DDLIST_PART_LIST); + lv_style_int_t line_space = lv_obj_get_style_text_line_space(ddlist, LV_DDLIST_PART_LIST); lv_coord_t line_y1 = ext->sel_opt_id * (font_h + line_space) + label->coords.y1 - scrl->coords.y1; diff --git a/src/lv_objx/lv_ddlist.h b/src/lv_objx/lv_ddlist.h index 6b92594c7..f68bde92d 100644 --- a/src/lv_objx/lv_ddlist.h +++ b/src/lv_objx/lv_ddlist.h @@ -93,6 +93,13 @@ lv_obj_t * lv_ddlist_create(lv_obj_t * par, const lv_obj_t * copy); * Setter functions *====================*/ +/** + * Set text of the ddlist (Displayed on the button if `show_selected = false`) + * @param ddlist pointer to a drop down list object + * @param txt the text as a string (Only it's pointer is saved) + */ +void lv_ddlist_set_text(lv_obj_t * ddlist, const char * txt); + /** * Set the options in a drop down list from a string * @param ddlist pointer to drop down list object @@ -148,10 +155,24 @@ static inline void lv_ddlist_set_anim_time(lv_obj_t * ddlist, uint16_t anim_time */ void lv_ddlist_set_dir(lv_obj_t * ddlist, lv_ddlist_dir_t dir); +/** + * Set whether the ddlist highlight the last selected option and display its text or not + * @param ddlist pointer to a drop down list object + * @param show true/false + */ +void lv_ddlist_set_show_selected(lv_obj_t * ddlist, bool show); + /*===================== * Getter functions *====================*/ +/** + * Get text of the ddlist (Displayed on the button if `show_selected = false`) + * @param ddlist pointer to a drop down list object + * @return the text string + */ +const char * lv_ddlist_get_text(lv_obj_t * ddlist); + /** * Get the options of a drop down list * @param ddlist pointer to drop down list object @@ -202,6 +223,13 @@ const char * lv_ddlist_get_symbol(lv_obj_t * ddlist); */ lv_ddlist_dir_t lv_ddlist_get_dir(const lv_obj_t * ddlist); +/** + * Get whether the ddlist highlight the last selected option and display its text or not + * @param ddlist pointer to a drop down list object + * @return true/false + */ +bool lv_ddlist_get_show_selected(lv_obj_t * ddlist); + /** * Get the scroll bar mode of a drop down list * @param ddlist pointer to a drop down list object diff --git a/src/lv_objx/lv_gauge.c b/src/lv_objx/lv_gauge.c index a1a2d003e..8565dfce2 100644 --- a/src/lv_objx/lv_gauge.c +++ b/src/lv_objx/lv_gauge.c @@ -350,19 +350,13 @@ static lv_design_res_t lv_gauge_design(lv_obj_t * gauge, const lv_area_t * clip_ } /*Draw the object*/ else if(mode == LV_DESIGN_DRAW_MAIN) { - lv_draw_rect_dsc_t bg_dsc; - lv_draw_rect_dsc_init(&bg_dsc); - lv_obj_init_draw_rect_dsc(gauge, LV_GAUGE_PART_MAIN, &bg_dsc); - lv_draw_rect(&gauge->coords, clip_area, &bg_dsc); + ancestor_design(gauge, clip_area, mode); lv_gauge_ext_t * ext = lv_obj_get_ext_attr(gauge); lv_gauge_draw_labels(gauge, clip_area); - /*Draw the ancestor line meter with max value to show the rainbow like line colors*/ + /*Add the strong lines*/ uint16_t line_cnt_tmp = ext->lmeter.line_cnt; - - lv_lmeter_draw_scale(gauge, clip_area, LV_GAUGE_PART_MAIN); - ext->lmeter.line_cnt = ext->label_count; /*Only to labels*/ lv_lmeter_draw_scale(gauge, clip_area, LV_GAUGE_PART_STRONG); ext->lmeter.line_cnt = line_cnt_tmp; /*Restore the parameters*/ diff --git a/src/lv_objx/lv_img.c b/src/lv_objx/lv_img.c index 6b9f34a11..b615d48cc 100644 --- a/src/lv_objx/lv_img.c +++ b/src/lv_objx/lv_img.c @@ -193,8 +193,8 @@ void lv_img_set_src(lv_obj_t * img, const void * src_img) if(src_type == LV_IMG_SRC_SYMBOL) { /*`lv_img_dsc_get_info` couldn't set the with and height of a font so set it here*/ const lv_font_t * font = lv_obj_get_style_font(img, LV_IMG_PART_MAIN); - lv_style_int_t letter_space = lv_obj_get_style_letter_space(img, LV_IMG_PART_MAIN); - lv_style_int_t line_space = lv_obj_get_style_line_space(img, LV_IMG_PART_MAIN); + lv_style_int_t letter_space = lv_obj_get_style_text_letter_space(img, LV_IMG_PART_MAIN); + lv_style_int_t line_space = lv_obj_get_style_text_line_space(img, LV_IMG_PART_MAIN); lv_point_t size; lv_txt_get_size(&size, src_img, font, letter_space, line_space, LV_COORD_MAX, LV_TXT_FLAG_NONE); diff --git a/src/lv_objx/lv_label.c b/src/lv_objx/lv_label.c index f5e3376c1..d87e19969 100644 --- a/src/lv_objx/lv_label.c +++ b/src/lv_objx/lv_label.c @@ -124,7 +124,6 @@ lv_obj_t * lv_label_create(lv_obj_t * par, const lv_obj_t * copy) lv_obj_set_design_cb(new_label, lv_label_design); lv_obj_set_signal_cb(new_label, lv_label_signal); - /*Init the new label*/ if(copy == NULL) { lv_obj_set_click(new_label, false); @@ -160,7 +159,7 @@ lv_obj_t * lv_label_create(lv_obj_t * par, const lv_obj_t * copy) ext->dot_end = copy_ext->dot_end; /*Refresh the style with new signal function*/ -// lv_obj_refresh_style(new_label); + lv_obj_refresh_style(new_label); } LV_LOG_INFO("label created"); @@ -566,8 +565,8 @@ void lv_label_get_letter_pos(const lv_obj_t * label, uint16_t char_id, lv_point_ uint32_t new_line_start = 0; lv_coord_t max_w = lv_area_get_width(&txt_coords); const lv_font_t * font = lv_obj_get_style_font(label, LV_LABEL_PART_MAIN); - lv_style_int_t line_space = lv_obj_get_style_line_space(label, LV_LABEL_PART_MAIN); - lv_style_int_t letter_space = lv_obj_get_style_letter_space(label, LV_LABEL_PART_MAIN); + lv_style_int_t line_space = lv_obj_get_style_text_line_space(label, LV_LABEL_PART_MAIN); + lv_style_int_t letter_space = lv_obj_get_style_text_letter_space(label, LV_LABEL_PART_MAIN); lv_coord_t letter_height = lv_font_get_line_height(font); lv_coord_t y = 0; lv_txt_flag_t flag = LV_TXT_FLAG_NONE; @@ -672,8 +671,8 @@ uint16_t lv_label_get_letter_on(const lv_obj_t * label, lv_point_t * pos) uint32_t new_line_start = 0; lv_coord_t max_w = lv_area_get_width(&txt_coords); const lv_font_t * font = lv_obj_get_style_font(label, LV_LABEL_PART_MAIN); - lv_style_int_t line_space = lv_obj_get_style_line_space(label, LV_LABEL_PART_MAIN); - lv_style_int_t letter_space = lv_obj_get_style_letter_space(label, LV_LABEL_PART_MAIN); + lv_style_int_t line_space = lv_obj_get_style_text_line_space(label, LV_LABEL_PART_MAIN); + lv_style_int_t letter_space = lv_obj_get_style_text_letter_space(label, LV_LABEL_PART_MAIN); lv_coord_t letter_height = lv_font_get_line_height(font); lv_coord_t y = 0; lv_txt_flag_t flag = LV_TXT_FLAG_NONE; @@ -835,8 +834,8 @@ bool lv_label_is_char_under_pos(const lv_obj_t * label, lv_point_t * pos) uint32_t new_line_start = 0; lv_coord_t max_w = lv_area_get_width(&txt_coords); const lv_font_t * font = lv_obj_get_style_font(label, LV_LABEL_PART_MAIN); - lv_style_int_t line_space = lv_obj_get_style_line_space(label, LV_LABEL_PART_MAIN); - lv_style_int_t letter_space = lv_obj_get_style_letter_space(label, LV_LABEL_PART_MAIN); + lv_style_int_t line_space = lv_obj_get_style_text_line_space(label, LV_LABEL_PART_MAIN); + lv_style_int_t letter_space = lv_obj_get_style_text_letter_space(label, LV_LABEL_PART_MAIN); lv_coord_t letter_height = lv_font_get_line_height(font); lv_coord_t y = 0; lv_txt_flag_t flag = LV_TXT_FLAG_NONE; @@ -1180,8 +1179,8 @@ static void lv_label_refr_text(lv_obj_t * label) get_txt_coords(label, &txt_coords); lv_coord_t max_w = lv_area_get_width(&txt_coords); const lv_font_t * font = lv_obj_get_style_font(label, LV_LABEL_PART_MAIN); - lv_style_int_t line_space = lv_obj_get_style_line_space(label, LV_LABEL_PART_MAIN); - lv_style_int_t letter_space = lv_obj_get_style_letter_space(label, LV_LABEL_PART_MAIN); + lv_style_int_t line_space = lv_obj_get_style_text_line_space(label, LV_LABEL_PART_MAIN); + lv_style_int_t letter_space = lv_obj_get_style_text_letter_space(label, LV_LABEL_PART_MAIN); /*If the width will be expanded set the max length to very big */ if(ext->long_mode == LV_LABEL_LONG_EXPAND) { diff --git a/src/lv_objx/lv_line.c b/src/lv_objx/lv_line.c index 87c468f2a..4365b4bac 100644 --- a/src/lv_objx/lv_line.c +++ b/src/lv_objx/lv_line.c @@ -93,8 +93,9 @@ lv_obj_t * lv_line_create(lv_obj_t * par, const lv_obj_t * copy) lv_line_set_y_invert(line, lv_line_get_y_invert(copy)); lv_line_set_auto_size(line, lv_line_get_auto_size(copy)); lv_line_set_points(line, copy_ext->point_array, copy_ext->point_num); + /*Refresh the style with new signal function*/ -// lv_obj_refresh_style(line); + lv_obj_refresh_style(line); } LV_LOG_INFO("line created"); diff --git a/src/lv_objx/lv_lmeter.c b/src/lv_objx/lv_lmeter.c index 991a946b0..64dc0142c 100644 --- a/src/lv_objx/lv_lmeter.c +++ b/src/lv_objx/lv_lmeter.c @@ -294,6 +294,8 @@ void lv_lmeter_draw_scale(lv_obj_t * lmeter, const lv_area_t * clip_area, uint8_ lv_draw_line_dsc_init(&line_dsc); lv_obj_init_draw_line_dsc(lmeter, part, &line_dsc); + lv_style_int_t end_line_width = lv_obj_get_style_scale_end_line_width(lmeter, part); + for(i = 0; i < ext->line_cnt; i++) { /*Calculate the position a scale label*/ int16_t angle = (i * ext->scale_angle) / (ext->line_cnt - 1) + angle_ofs; @@ -325,7 +327,10 @@ void lv_lmeter_draw_scale(lv_obj_t * lmeter, const lv_area_t * clip_area, uint8_ p1.x = x_out + x_ofs; p1.y = y_out + y_ofs; - if(i >= level) line_dsc.color = end_color; + if(i >= level) { + line_dsc.color = end_color; + line_dsc.width = end_line_width; + } else line_dsc.color = lv_color_mix(grad_color, main_color, (255 * i) / ext->line_cnt); lv_draw_line(&p1, &p2, clip_area, &line_dsc); diff --git a/src/lv_objx/lv_page.c b/src/lv_objx/lv_page.c index b44442fa7..7dbc2f91c 100644 --- a/src/lv_objx/lv_page.c +++ b/src/lv_objx/lv_page.c @@ -1022,7 +1022,18 @@ static lv_res_t lv_page_scrollable_signal(lv_obj_t * scrl, lv_signal_t sign, voi page_ext->sb.ver_draw = 0; } } - } else if(sign == LV_SIGNAL_CLEANUP) { + } 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) { + 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); + if(res != LV_RES_OK) return res; + } + else if(sign == LV_SIGNAL_CLEANUP) { page_ext->scrl = NULL; } return res; diff --git a/src/lv_objx/lv_roller.c b/src/lv_objx/lv_roller.c index d751995ca..a4c335313 100644 --- a/src/lv_objx/lv_roller.c +++ b/src/lv_objx/lv_roller.c @@ -242,7 +242,7 @@ void lv_roller_set_visible_row_count(lv_obj_t * roller, uint8_t row_cnt) uint8_t n_line_space = (row_cnt > 1) ? row_cnt - 1 : 1; const lv_font_t * font = lv_obj_get_style_font(roller, LV_ROLLER_PART_BG); - lv_style_int_t line_space = lv_obj_get_style_line_space(roller, LV_ROLLER_PART_BG); + lv_style_int_t line_space = lv_obj_get_style_text_line_space(roller, LV_ROLLER_PART_BG); lv_obj_set_height(roller, lv_font_get_line_height(font) * row_cnt + line_space * n_line_space); refr_position(roller, LV_ANIM_OFF); @@ -372,7 +372,7 @@ static lv_design_res_t lv_roller_design(lv_obj_t * roller, const lv_area_t * cli draw_bg(roller, clip_area); const lv_font_t * font = lv_obj_get_style_font(roller, LV_ROLLER_PART_BG); - lv_style_int_t line_space = lv_obj_get_style_line_space(roller, LV_ROLLER_PART_BG); + lv_style_int_t line_space = lv_obj_get_style_text_line_space(roller, LV_ROLLER_PART_BG); lv_coord_t font_h = lv_font_get_line_height(font); lv_area_t rect_area; rect_area.y1 = roller->coords.y1 + lv_obj_get_height(roller) / 2 - font_h / 2 - line_space / 2; @@ -573,7 +573,7 @@ static lv_res_t lv_roller_scrl_signal(lv_obj_t * roller_scrl, lv_signal_t sign, lv_roller_ext_t * ext = lv_obj_get_ext_attr(roller); const lv_font_t * font = lv_obj_get_style_font(roller, LV_ROLLER_PART_BG); - lv_style_int_t line_space = lv_obj_get_style_line_space(roller, LV_ROLLER_PART_BG); + lv_style_int_t line_space = lv_obj_get_style_text_line_space(roller, LV_ROLLER_PART_BG); lv_coord_t font_h = lv_font_get_line_height(font); if(sign == LV_SIGNAL_DRAG_END) { @@ -678,7 +678,7 @@ static void refr_position(lv_obj_t * roller, lv_anim_enable_t anim_en) lv_obj_t * roller_scrl = lv_page_get_scrl(roller); lv_roller_ext_t * ext = lv_obj_get_ext_attr(roller); const lv_font_t * font = lv_obj_get_style_font(roller, LV_ROLLER_PART_BG); - lv_style_int_t line_space = lv_obj_get_style_line_space(roller, LV_ROLLER_PART_BG); + lv_style_int_t line_space = lv_obj_get_style_text_line_space(roller, LV_ROLLER_PART_BG); lv_coord_t font_h = lv_font_get_line_height(font); lv_coord_t h = lv_obj_get_height(roller); uint16_t anim_time = lv_roller_get_anim_time(roller); @@ -822,7 +822,7 @@ static void inf_normalize(void * scrl) /*Move to the new id*/ const lv_font_t * font = lv_obj_get_style_font(roller, LV_ROLLER_PART_BG); - lv_style_int_t line_space = lv_obj_get_style_line_space(roller, LV_ROLLER_PART_BG); + lv_style_int_t line_space = lv_obj_get_style_text_line_space(roller, LV_ROLLER_PART_BG); lv_coord_t font_h = lv_font_get_line_height(font); lv_coord_t h = lv_obj_get_height(roller); diff --git a/src/lv_objx/lv_slider.c b/src/lv_objx/lv_slider.c index 3b9d65987..c39b705b7 100644 --- a/src/lv_objx/lv_slider.c +++ b/src/lv_objx/lv_slider.c @@ -79,6 +79,7 @@ lv_obj_t * lv_slider_create(lv_obj_t * par, const lv_obj_t * copy) /*Initialize the allocated 'ext' */ ext->value_to_set = NULL; ext->dragging = 0; + lv_style_list_init(&ext->style_knob); /*The signal and design functions are not copied so set them here*/ lv_obj_set_signal_cb(new_slider, lv_slider_signal); @@ -89,7 +90,6 @@ lv_obj_t * lv_slider_create(lv_obj_t * par, const lv_obj_t * copy) lv_obj_set_click(new_slider, true); lv_obj_set_protect(new_slider, LV_PROTECT_PRESS_LOST); - lv_style_list_init(&ext->style_knob); lv_theme_apply(new_slider, LV_THEME_SLIDER); lv_obj_set_height(new_slider, LV_DPI / 15); } diff --git a/src/lv_objx/lv_sw.c b/src/lv_objx/lv_sw.c index 37e8a74fb..c353aa741 100644 --- a/src/lv_objx/lv_sw.c +++ b/src/lv_objx/lv_sw.c @@ -63,49 +63,50 @@ lv_obj_t * lv_sw_create(lv_obj_t * par, const lv_obj_t * copy) LV_LOG_TRACE("switch create started"); /*Create the ancestor of switch*/ - lv_obj_t * new_sw = lv_bar_create(par, copy); - LV_ASSERT_MEM(new_sw); + lv_obj_t * sw = lv_bar_create(par, copy); + LV_ASSERT_MEM(sw); - if(new_sw == NULL) return NULL; + if(sw == NULL) return NULL; - if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_cb(new_sw); - if(ancestor_design == NULL) ancestor_design = lv_obj_get_design_cb(new_sw); + if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_cb(sw); + if(ancestor_design == NULL) ancestor_design = lv_obj_get_design_cb(sw); /*Allocate the switch type specific extended data*/ - lv_sw_ext_t * ext = lv_obj_allocate_ext_attr(new_sw, sizeof(lv_sw_ext_t)); + lv_sw_ext_t * ext = lv_obj_allocate_ext_attr(sw, sizeof(lv_sw_ext_t)); LV_ASSERT_MEM(ext); if(ext == NULL) { - lv_obj_del(new_sw); + lv_obj_del(sw); return NULL; } + lv_style_list_init(&ext->style_knob); + /*The signal and design functions are not copied so set them here*/ - lv_obj_set_signal_cb(new_sw, lv_sw_signal); - lv_obj_set_design_cb(new_sw, lv_sw_design); + lv_obj_set_signal_cb(sw, lv_sw_signal); + lv_obj_set_design_cb(sw, lv_sw_design); /*Init the new switch switch*/ if(copy == NULL) { - lv_obj_set_click(new_sw, true); - lv_obj_set_protect(new_sw, LV_PROTECT_PRESS_LOST); - lv_obj_set_size(new_sw, 2 * LV_DPI / 3, LV_DPI / 3); - lv_bar_set_range(new_sw, 0, 1); + lv_obj_set_click(sw, true); + lv_obj_set_protect(sw, LV_PROTECT_PRESS_LOST); + lv_obj_set_size(sw, 2 * LV_DPI / 3, LV_DPI / 3); + lv_bar_set_range(sw, 0, 1); - lv_style_list_init(&ext->style_knob); - - lv_theme_apply(new_sw, LV_THEME_SW); + lv_theme_apply(sw, LV_THEME_SW); } /*Copy an existing switch*/ else { -// lv_sw_ext_t * copy_ext = lv_obj_get_ext_attr(copy); -// ext->style_knob_off = copy_ext->style_knob_off; -// ext->style_knob_on = copy_ext->style_knob_on; + lv_sw_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); } /*Refresh the style with new signal function*/ LV_LOG_INFO("switch created"); - return new_sw; + return sw; } /*===================== diff --git a/src/lv_objx/lv_ta.c b/src/lv_objx/lv_ta.c index f88d7706f..5da04edda 100644 --- a/src/lv_objx/lv_ta.c +++ b/src/lv_objx/lv_ta.c @@ -1208,7 +1208,7 @@ void lv_ta_cursor_down(lv_obj_t * ta) /*Increment the y with one line and keep the valid x*/ - lv_style_int_t line_space = lv_obj_get_style_line_space(ta, LV_TA_PART_BG); + lv_style_int_t line_space = lv_obj_get_style_text_line_space(ta, LV_TA_PART_BG); const lv_font_t * font = lv_obj_get_style_font(ta, LV_TA_PART_BG); lv_coord_t font_h = lv_font_get_line_height(font); pos.y += font_h + line_space + 1; @@ -1240,7 +1240,7 @@ void lv_ta_cursor_up(lv_obj_t * ta) lv_label_get_letter_pos(ext->label, lv_ta_get_cursor_pos(ta), &pos); /*Decrement the y with one line and keep the valid x*/ - lv_style_int_t line_space = lv_obj_get_style_line_space(ta, LV_TA_PART_BG); + lv_style_int_t line_space = lv_obj_get_style_text_line_space(ta, LV_TA_PART_BG); const lv_font_t * font = lv_obj_get_style_font(ta, LV_TA_PART_BG); lv_coord_t font_h = lv_font_get_line_height(font); pos.y -= font_h + line_space - 1; @@ -1504,7 +1504,7 @@ static lv_res_t lv_ta_scrollable_signal(lv_obj_t * scrl, lv_signal_t sign, void if(sign == LV_SIGNAL_REFR_EXT_DRAW_PAD) { /*Set ext. size because the cursor might be out of this object*/ - lv_style_int_t line_space = lv_obj_get_style_line_space(ta, LV_TA_PART_BG); + lv_style_int_t line_space = lv_obj_get_style_text_line_space(ta, LV_TA_PART_BG); const lv_font_t * font = lv_obj_get_style_font(ta, LV_TA_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); diff --git a/src/lv_objx/lv_table.c b/src/lv_objx/lv_table.c index ed481226a..22acbc2bd 100644 --- a/src/lv_objx/lv_table.c +++ b/src/lv_objx/lv_table.c @@ -861,8 +861,8 @@ static void refr_size(lv_obj_t * table) cell_right[i] = lv_obj_get_style_pad_right(table, LV_TABLE_PART_CELL1 + i); cell_top[i] = lv_obj_get_style_pad_top(table, LV_TABLE_PART_CELL1 + i); cell_bottom[i] = lv_obj_get_style_pad_bottom(table, LV_TABLE_PART_CELL1 + i); - letter_space[i] = lv_obj_get_style_letter_space(table, LV_TABLE_PART_CELL1 + i); - line_space[i] = lv_obj_get_style_line_space(table, LV_TABLE_PART_CELL1 + i); + letter_space[i] = lv_obj_get_style_text_letter_space(table, LV_TABLE_PART_CELL1 + i); + line_space[i] = lv_obj_get_style_text_line_space(table, LV_TABLE_PART_CELL1 + i); font[i] = lv_obj_get_style_font(table, LV_TABLE_PART_CELL1 + i); } diff --git a/src/lv_objx/lv_win.c b/src/lv_objx/lv_win.c index 018fc7c9e..7fc7cb232 100644 --- a/src/lv_objx/lv_win.c +++ b/src/lv_objx/lv_win.c @@ -27,12 +27,14 @@ * STATIC PROTOTYPES **********************/ static lv_res_t lv_win_signal(lv_obj_t * win, lv_signal_t sign, void * param); +static lv_design_res_t lv_win_header_design(lv_obj_t * header, const lv_area_t * clip_area, lv_design_mode_t mode); static lv_style_list_t * lv_win_get_style(lv_obj_t * win, uint8_t part); static void lv_win_realign(lv_obj_t * win); /********************** * STATIC VARIABLES **********************/ +static lv_design_cb_t ancestor_header_design; static lv_signal_cb_t ancestor_signal; /********************** @@ -97,10 +99,11 @@ lv_obj_t * lv_win_create(lv_obj_t * par, const lv_obj_t * copy) /*Create a holder for the header*/ ext->header = lv_obj_create(new_win, NULL); - /*Move back the header because it is automatically moved to the scrollable */ + /*Move back to window background because it's automatically moved to the content page*/ lv_obj_set_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); + lv_obj_set_design_cb(ext->header, lv_win_header_design); lv_obj_set_signal_cb(new_win, lv_win_signal); lv_theme_apply(new_win, LV_THEME_WIN); @@ -438,7 +441,54 @@ void lv_win_focus(lv_obj_t * win, lv_obj_t * obj, lv_anim_enable_t anim_en) /********************** * STATIC FUNCTIONS **********************/ +/** + * Handle the drawing related tasks of the window header + * @param header pointer to an object + * @param clip_area the object will be drawn only in this area + * @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area + * (return 'true' if yes) + * LV_DESIGN_DRAW: draw the object (always return 'true') + * LV_DESIGN_DRAW_POST: drawing after every children are drawn + * @param return an element of `lv_design_res_t` + */ +static lv_design_res_t lv_win_header_design(lv_obj_t * header, const lv_area_t * clip_area, lv_design_mode_t mode) +{ + /*Return false if the object is not covers the mask_p area*/ + if(mode == LV_DESIGN_COVER_CHK) { + return ancestor_header_design(header, clip_area, mode); + } + /*Draw the object*/ + else if(mode == LV_DESIGN_DRAW_MAIN) { + ancestor_header_design(header, clip_area, mode); + lv_obj_t * win = lv_obj_get_parent(header); + lv_win_ext_t * ext = lv_obj_get_ext_attr(win); + + lv_style_int_t left = lv_obj_get_style_pad_left(header, LV_OBJ_PART_MAIN); + lv_style_int_t top = lv_obj_get_style_pad_top(header, LV_OBJ_PART_MAIN); + + lv_draw_label_dsc_t label_dsc; + lv_draw_label_dsc_init(&label_dsc); + lv_obj_init_draw_label_dsc(header, LV_OBJ_PART_MAIN, &label_dsc); + + lv_area_t txt_area; + 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); + + txt_area.x1 = header->coords.x1 + left; + txt_area.y1 = header->coords.y1 + (lv_obj_get_height(header) - txt_size.y) / 2; + txt_area.x2 = txt_area.x1 + txt_size.x; + 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) { + ancestor_header_design(header, clip_area, mode); + } + + return LV_DESIGN_RES_OK; +} /** * Signal function of the window * @param win pointer to a window object @@ -539,7 +589,7 @@ static lv_style_list_t * lv_win_get_style(lv_obj_t * win, uint8_t part) } /** * Realign the building elements of a window - * @param win pointer to window objectker + * @param win pointer to a window object */ static void lv_win_realign(lv_obj_t * win) { @@ -547,6 +597,8 @@ static void lv_win_realign(lv_obj_t * win) if(ext->page == NULL || ext->header == NULL) return; + lv_obj_set_width(ext->header, lv_obj_get_width(win)); + lv_obj_t * btn; lv_obj_t * btn_prev = NULL; lv_coord_t btn_size = lv_obj_get_height_fit(ext->header); @@ -554,7 +606,6 @@ static void lv_win_realign(lv_obj_t * win) lv_style_int_t header_right = lv_obj_get_style_pad_right(win, LV_WIN_PART_HEADER); /*Refresh the size of all control buttons*/ btn = lv_obj_get_child_back(ext->header, NULL); - btn = lv_obj_get_child_back(ext->header, btn); /*Skip the title*/ while(btn != NULL) { lv_obj_set_size(btn, btn_size, btn_size); if(btn_prev == NULL) { diff --git a/src/lv_themes/lv_theme.c b/src/lv_themes/lv_theme.c index 0c832935e..3769b7bf7 100644 --- a/src/lv_themes/lv_theme.c +++ b/src/lv_themes/lv_theme.c @@ -53,10 +53,6 @@ lv_theme_t * lv_theme_get_act(void) return act_theme; } -lv_style_t * lv_theme_get_style(lv_theme_style_t name) -{ - return act_theme->get_style_cb(name); -} void lv_theme_apply(lv_obj_t * obj, lv_theme_style_t name) { diff --git a/src/lv_themes/lv_theme.h b/src/lv_themes/lv_theme.h index 4fac91256..35c555a52 100644 --- a/src/lv_themes/lv_theme.h +++ b/src/lv_themes/lv_theme.h @@ -111,7 +111,6 @@ typedef enum { }lv_theme_style_t; typedef struct { - lv_style_t * (*get_style_cb)(lv_theme_style_t); void (*apply_cb)(lv_obj_t *,lv_theme_style_t); }lv_theme_t; diff --git a/src/lv_themes/lv_theme_alien.c b/src/lv_themes/lv_theme_alien.c index 694620a2a..c9167771c 100644 --- a/src/lv_themes/lv_theme_alien.c +++ b/src/lv_themes/lv_theme_alien.c @@ -89,7 +89,7 @@ static lv_style_t list_bg, list_btn; #endif #if LV_USE_DDLIST -static lv_style_t ddlist_bg, ddlist_sel; +static lv_style_t ddlist_btn, ddlist_page, ddlist_sel; #endif #if LV_USE_TA @@ -176,7 +176,7 @@ static void basic_init(void) lv_style_set_pad_top(&btn, LV_STYLE_STATE_NORMAL, LV_DPI / 10); lv_style_set_pad_bottom(&btn, LV_STYLE_STATE_NORMAL, LV_DPI / 10); lv_style_set_pad_inner(&btn, LV_STYLE_STATE_NORMAL, LV_DPI / 10); - lv_style_set_transition_time(&btn, LV_STYLE_STATE_NORMAL, 3000); + lv_style_set_transition_time(&btn, LV_STYLE_STATE_NORMAL, 300); lv_style_set_transition_time(&btn, LV_STYLE_STATE_PRESSED, 0); lv_style_set_bg_color(&btn, LV_STYLE_STATE_FOCUS, lv_color_mix(LV_COLOR_RED, COLOR_ACCENT, LV_OPA_50)); @@ -403,7 +403,16 @@ static void lmeter_init(void) lv_style_set_color(&lmeter, LV_STYLE_SCALE_COLOR, LV_COLOR_AQUA); lv_style_set_color(&lmeter, LV_STYLE_SCALE_GRAD_COLOR, LV_COLOR_NAVY); lv_style_set_color(&lmeter, LV_STYLE_SCALE_END_COLOR, LV_COLOR_GRAY); - lv_style_set_int(&lmeter, LV_STYLE_LINE_WIDTH, 2); + lv_style_set_line_rounded(&lmeter, LV_STYLE_STATE_NORMAL, true); + lv_style_set_int(&lmeter, LV_STYLE_LINE_WIDTH, 4); + lv_style_set_scale_end_line_width(&lmeter, LV_STYLE_STATE_NORMAL, 2); + + /*Padding to not clip rounded line endings*/ + lv_style_set_pad_left(&lmeter, LV_STYLE_STATE_NORMAL, 3); + lv_style_set_pad_right(&lmeter, LV_STYLE_STATE_NORMAL, 3); + lv_style_set_pad_top(&lmeter, LV_STYLE_STATE_NORMAL, 3); + lv_style_set_pad_bottom(&lmeter, LV_STYLE_STATE_NORMAL, 3); + #endif } @@ -418,29 +427,31 @@ static void gauge_init(void) lv_style_set_scale_grad_color(&gauge_main, LV_STYLE_STATE_NORMAL, COLOR_DISABLED); lv_style_set_scale_end_color(&gauge_main, LV_STYLE_STATE_NORMAL, COLOR_ACCENT); lv_style_set_line_width(&gauge_main, LV_STYLE_STATE_NORMAL, 2); + lv_style_set_scale_end_line_width(&gauge_main, LV_STYLE_STATE_NORMAL, 4); lv_style_set_scale_end_border_width(&gauge_main, LV_STYLE_STATE_NORMAL, 4); lv_style_set_bg_opa(&gauge_main, LV_STYLE_STATE_NORMAL, LV_OPA_COVER); lv_style_set_pad_left(&gauge_main, LV_STYLE_STATE_NORMAL, LV_DPI / 10); lv_style_set_pad_right(&gauge_main, LV_STYLE_STATE_NORMAL, LV_DPI / 10); lv_style_set_pad_top(&gauge_main, LV_STYLE_STATE_NORMAL, LV_DPI / 10); - lv_style_set_pad_inner(&gauge_main, LV_STYLE_STATE_NORMAL, LV_DPI / 8); - + lv_style_set_pad_inner(&gauge_main, LV_STYLE_STATE_NORMAL, LV_DPI / 6); + lv_style_set_scale_width(&gauge_main, LV_STYLE_STATE_NORMAL, LV_DPI/12); lv_style_init(&gauge_strong); lv_style_set_color(&gauge_strong, LV_STYLE_SCALE_COLOR, COLOR_DISABLED); lv_style_set_color(&gauge_strong, LV_STYLE_SCALE_GRAD_COLOR, COLOR_DISABLED); lv_style_set_color(&gauge_strong, LV_STYLE_SCALE_END_COLOR, COLOR_ACCENT); lv_style_set_int(&gauge_strong, LV_STYLE_LINE_WIDTH, 4); - lv_style_set_int(&gauge_strong, LV_STYLE_SCALE_WIDTH, LV_DPI/5); - lv_style_set_int(&gauge_strong, LV_STYLE_PAD_INNER, LV_DPI/10); + lv_style_set_scale_end_line_width(&gauge_strong, LV_STYLE_STATE_NORMAL, 4); + lv_style_set_scale_width(&gauge_strong, LV_STYLE_STATE_NORMAL, LV_DPI/7); lv_style_init(&gauge_needle); lv_style_set_color(&gauge_needle, LV_STYLE_LINE_COLOR, LV_COLOR_WHITE); - lv_style_set_int(&gauge_needle, LV_STYLE_LINE_WIDTH, LV_DPI / 30); + lv_style_set_line_width(&gauge_needle, LV_STYLE_STATE_NORMAL, LV_DPI / 20); lv_style_set_bg_opa(&gauge_needle, LV_STYLE_STATE_NORMAL, LV_OPA_COVER); lv_style_set_bg_color(&gauge_needle, LV_STYLE_STATE_NORMAL, LV_COLOR_WHITE); - lv_style_set_size(&gauge_needle, LV_STYLE_STATE_NORMAL, 10); - lv_style_set_pad_inner(&gauge_needle, LV_STYLE_STATE_NORMAL, LV_DPI / 5); + lv_style_set_radius(&gauge_needle, LV_STYLE_STATE_NORMAL, LV_RADIUS_CIRCLE); + lv_style_set_size(&gauge_needle, LV_STYLE_STATE_NORMAL, LV_DPI / 7); + lv_style_set_pad_inner(&gauge_needle, LV_STYLE_STATE_NORMAL, LV_DPI / 10); #endif } @@ -559,14 +570,17 @@ static void btnm_init(void) { #if LV_USE_BTNM lv_style_init(&btnm_bg); + lv_style_set_bg_opa(&btnm_bg, LV_STYLE_STATE_NORMAL, LV_OPA_COVER); lv_style_set_int(&btnm_bg, LV_STYLE_BORDER_WIDTH, LV_DPI / 50); lv_style_set_color(&btnm_bg, LV_STYLE_BORDER_COLOR, lv_color_hex(0x373a3f)); lv_style_set_int(&btnm_bg, LV_STYLE_RADIUS, LV_DPI / 20); lv_style_set_int(&btnm_bg, LV_STYLE_CLIP_CORNER, 1); lv_style_set_int(&btnm_bg, LV_STYLE_BORDER_POST, 1); + lv_style_set_bg_color(&btnm_bg, LV_STYLE_STATE_NORMAL, COLOR_CONTAINER); + lv_style_set_border_color(&btnm_bg, LV_STYLE_STATE_FOCUS, lv_color_hex3(0xf66)); lv_style_init(&btnm_btn); - lv_style_set_int(&btnm_btn, LV_STYLE_BORDER_WIDTH, LV_DPI / 50); + lv_style_set_int(&btnm_btn, LV_STYLE_BORDER_WIDTH, LV_DPI / 70 > 0? LV_DPI / 70 : 1); lv_style_set_int(&btnm_btn, LV_STYLE_BORDER_SIDE, LV_BORDER_SIDE_FULL); lv_style_set_color(&btnm_btn, LV_STYLE_BORDER_COLOR, lv_color_hex(0x373a3f)); lv_style_set_color(&btnm_btn, LV_STYLE_BG_COLOR | LV_STYLE_STATE_PRESSED, lv_color_hex3(0x666)); @@ -686,6 +700,31 @@ static void ddlist_init(void) { #if LV_USE_DDLIST != 0 + lv_style_init(&ddlist_btn); + lv_style_copy(&ddlist_btn, &panel); + lv_style_set_border_side(&ddlist_btn, LV_STYLE_STATE_NORMAL, LV_BORDER_SIDE_FULL); + lv_style_set_bg_color(&ddlist_btn, LV_STYLE_STATE_PRESSED, lv_color_hex3(0x666)); + lv_style_set_pad_top(&ddlist_btn, LV_STYLE_STATE_NORMAL, LV_DPI / 10); + lv_style_set_pad_bottom(&ddlist_btn, LV_STYLE_STATE_NORMAL, LV_DPI / 10); + + lv_style_init(&ddlist_page); + lv_style_copy(&ddlist_page, &panel); + lv_style_set_border_side(&ddlist_page, LV_STYLE_STATE_NORMAL, LV_BORDER_SIDE_FULL); + lv_style_set_bg_color(&ddlist_page, LV_STYLE_STATE_NORMAL, lv_color_hex3(0xeee)); + lv_style_set_text_color(&ddlist_page, LV_STYLE_STATE_NORMAL, lv_color_hex3(0x333)); + lv_style_set_text_line_space(&ddlist_page, LV_STYLE_STATE_NORMAL, LV_DPI / 5); + lv_style_set_border_post(&ddlist_page, LV_STYLE_STATE_NORMAL, true); + + lv_style_init(&ddlist_sel); + lv_style_set_bg_opa(&ddlist_sel, LV_STYLE_STATE_NORMAL, LV_OPA_COVER); + lv_style_set_bg_color(&ddlist_sel, LV_STYLE_STATE_NORMAL, COLOR_ACCENT); + + lv_style_set_bg_color(&ddlist_sel, LV_STYLE_STATE_PRESSED, LV_COLOR_SILVER); + + lv_style_set_text_color(&ddlist_sel, LV_STYLE_STATE_NORMAL, lv_color_hex3(0x333)); + + + #endif } @@ -809,11 +848,8 @@ lv_theme_t * lv_theme_alien_init(uint16_t hue, lv_font_t * font) table_init(); win_init(); - - theme.get_style_cb = lv_theme_alien_get_style; theme.apply_cb = lv_theme_alien_apply; - lv_mem_monitor_t mon2; lv_mem_monitor(&mon2); printf("theme size: %d\n", mon1.free_size - mon2.free_size); @@ -845,17 +881,23 @@ void lv_theme_alien_apply(lv_obj_t * obj, lv_theme_style_t name) lv_style_list_reset(list); lv_style_list_add_style(list, &panel); break; +#if LV_USE_CONT case LV_THEME_CONT: list = lv_obj_get_style_list(obj, LV_CONT_PART_MAIN); lv_style_list_reset(list); lv_style_list_add_style(list, &panel); break; +#endif + +#if LV_USE_BTN case LV_THEME_BTN: list = lv_obj_get_style_list(obj, LV_BTN_PART_MAIN); lv_style_list_reset(list); lv_style_list_add_style(list, &btn); break; +#endif +#if LV_USE_BTNM case LV_THEME_BTNM: list = lv_obj_get_style_list(obj, LV_BTNM_PART_BG); lv_style_list_reset(list); @@ -865,6 +907,9 @@ void lv_theme_alien_apply(lv_obj_t * obj, lv_theme_style_t name) lv_style_list_reset(list); lv_style_list_add_style(list, &btnm_btn); break; +#endif + +#if LV_USE_KB case LV_THEME_KB: list = lv_obj_get_style_list(obj, LV_KB_PART_BG); lv_style_list_reset(list); @@ -874,6 +919,9 @@ void lv_theme_alien_apply(lv_obj_t * obj, lv_theme_style_t name) lv_style_list_reset(list); lv_style_list_add_style(list, &btnm_btn); break; +#endif + +#if LV_USE_BAR case LV_THEME_BAR: list = lv_obj_get_style_list(obj, LV_BAR_PART_BG); lv_style_list_reset(list); @@ -883,7 +931,9 @@ void lv_theme_alien_apply(lv_obj_t * obj, lv_theme_style_t name) lv_style_list_reset(list); lv_style_list_add_style(list, &bar_indic); break; +#endif +#if LV_USE_SW case LV_THEME_SW: list = lv_obj_get_style_list(obj, LV_SW_PART_BG); lv_style_list_reset(list); @@ -897,6 +947,7 @@ void lv_theme_alien_apply(lv_obj_t * obj, lv_theme_style_t name) lv_style_list_reset(list); lv_style_list_add_style(list, &sw_knob); break; +#endif #if LV_USE_IMG case LV_THEME_IMAGE: @@ -1062,7 +1113,7 @@ void lv_theme_alien_apply(lv_obj_t * obj, lv_theme_style_t name) break; #endif -#if LV_USE_DDLIST +#if LV_USE_LIST case LV_THEME_LIST: list = lv_obj_get_style_list(obj, LV_LIST_PART_BG); lv_style_list_reset(list); @@ -1087,11 +1138,11 @@ void lv_theme_alien_apply(lv_obj_t * obj, lv_theme_style_t name) case LV_THEME_DDLIST: list = lv_obj_get_style_list(obj, LV_DDLIST_PART_BTN); lv_style_list_reset(list); - lv_style_list_add_style(list, &btn); + lv_style_list_add_style(list, &ddlist_btn); list = lv_obj_get_style_list(obj, LV_DDLIST_PART_LIST); lv_style_list_reset(list); - lv_style_list_add_style(list, &panel); + lv_style_list_add_style(list, &ddlist_page); list = lv_obj_get_style_list(obj, LV_DDLIST_PART_SCRLBAR); lv_style_list_reset(list); @@ -1099,7 +1150,7 @@ void lv_theme_alien_apply(lv_obj_t * obj, lv_theme_style_t name) list = lv_obj_get_style_list(obj, LV_DDLIST_PART_SELECTED); lv_style_list_reset(list); - lv_style_list_add_style(list, &btn); + lv_style_list_add_style(list, &ddlist_sel); break; #endif @@ -1172,7 +1223,7 @@ void lv_theme_alien_apply(lv_obj_t * obj, lv_theme_style_t name) case LV_THEME_WIN_BTN: list = lv_obj_get_style_list(obj, LV_BTN_PART_MAIN); lv_style_list_reset(list); - lv_style_list_add_style(list, &tabview_btns); + lv_style_list_add_style(list, &btn); break; #endif @@ -1196,7 +1247,7 @@ void lv_theme_alien_apply(lv_obj_t * obj, lv_theme_style_t name) break; #endif -#if LV_USE_TA +#if LV_USE_CALENDAR case LV_THEME_CALENDAR: list = lv_obj_get_style_list(obj, LV_CALENDAR_PART_BG); lv_style_list_reset(list); @@ -1215,6 +1266,13 @@ void lv_theme_alien_apply(lv_obj_t * obj, lv_theme_style_t name) lv_style_list_add_style(list, &calendar_daynames); break; #endif +#if LV_USE_LMETER + case LV_THEME_LMETER: + list = lv_obj_get_style_list(obj, LV_LMETER_PART_MAIN); + lv_style_list_reset(list); + lv_style_list_add_style(list, &lmeter); + break; +#endif #if LV_USE_GAUGE case LV_THEME_GAUGE: list = lv_obj_get_style_list(obj, LV_GAUGE_PART_MAIN); @@ -1238,23 +1296,6 @@ void lv_theme_alien_apply(lv_obj_t * obj, lv_theme_style_t name) } -lv_style_t * lv_theme_alien_get_style(lv_theme_style_t name) -{ - switch(name) { -#if LV_USE_LMETER - case LV_THEME_LMETER: - return &lmeter; -#endif - -#if LV_USE_LED - case LV_THEME_LED: - return &btn; -#endif - } - - return NULL; -} - /********************** * STATIC FUNCTIONS **********************/