diff --git a/src/lv_core/lv_obj.c b/src/lv_core/lv_obj.c index da3c608fa..5ef47389a 100644 --- a/src/lv_core/lv_obj.c +++ b/src/lv_core/lv_obj.c @@ -2358,6 +2358,15 @@ lv_opa_t lv_obj_get_style_opa(const lv_obj_t * obj, uint8_t part, lv_style_prope if(weight >= 0) return value; + + prop = prop & (~LV_STYLE_STATE_MASK); + switch(prop) { + case LV_STYLE_OVERLAY_OPA: + case LV_STYLE_PATTERN_RECOLOR_OPA: + case LV_STYLE_IMAGE_RECOLOR_OPA: + return LV_OPA_TRANSP; + } + return LV_OPA_COVER; } @@ -2425,7 +2434,6 @@ void * lv_obj_get_style_ptr(const lv_obj_t * obj, uint8_t part, lv_style_propert if(weight >= 0) return value; - prop = prop & (~LV_STYLE_STATE_MASK); switch(prop) { case LV_STYLE_FONT: @@ -2848,6 +2856,14 @@ void lv_obj_init_draw_rect_dsc(lv_obj_t * obj, uint8_t part, lv_draw_rect_dsc_t { draw_dsc->radius = lv_obj_get_style_value(obj, part, LV_STYLE_RADIUS); + lv_opa_t opa_scale = lv_obj_get_style_opa(obj, part, LV_STYLE_OPA_SCALE); + if(opa_scale <= LV_OPA_MIN) { + draw_dsc->bg_opa = LV_OPA_TRANSP; + draw_dsc->border_opa = LV_OPA_TRANSP; + draw_dsc->shadow_opa = LV_OPA_TRANSP; + return; + } + draw_dsc->bg_opa = lv_obj_get_style_opa(obj, part, LV_STYLE_BG_OPA); if(draw_dsc->bg_opa > LV_OPA_MIN) { draw_dsc->bg_color = lv_obj_get_style_color(obj, part, LV_STYLE_BG_COLOR); @@ -2866,11 +2882,27 @@ void lv_obj_init_draw_rect_dsc(lv_obj_t * obj, uint8_t part, lv_draw_rect_dsc_t } } + draw_dsc->pattern_src = lv_obj_get_style_ptr(obj, part, LV_STYLE_PATTERN_IMAGE); + if(draw_dsc->pattern_src) { + draw_dsc->pattern_opa = lv_obj_get_style_opa(obj, part, LV_STYLE_PATTERN_OPA); + if(draw_dsc->pattern_opa > LV_OPA_MIN) { + draw_dsc->pattern_repeate = lv_obj_get_style_value(obj, part, LV_STYLE_PATTERN_REPEATE) & 0x1U; + draw_dsc->pattern_recolor = lv_obj_get_style_color(obj, part, LV_STYLE_PATTERN_RECOLOR); + draw_dsc->pattern_recolor_opa = lv_obj_get_style_opa(obj, part, LV_STYLE_PATTERN_RECOLOR_OPA); + if(lv_img_src_get_type(draw_dsc->pattern_src) == LV_IMG_SRC_SYMBOL) { + draw_dsc->pattern_font = lv_obj_get_style_ptr(obj, part, LV_STYLE_FONT); + } + } + } + + draw_dsc->overlay_opa = lv_obj_get_style_opa(obj, part, LV_STYLE_OVERLAY_OPA); + draw_dsc->overlay_color = lv_obj_get_style_color(obj, part, LV_STYLE_OVERLAY_COLOR); - lv_opa_t opa_scale = lv_obj_get_style_opa(obj, part, LV_STYLE_OPA_SCALE); if(opa_scale < LV_OPA_MAX) { draw_dsc->bg_opa = (uint16_t)((uint16_t)draw_dsc->bg_opa * opa_scale) >> 8; draw_dsc->border_opa = (uint16_t)((uint16_t)draw_dsc->border_opa * opa_scale) >> 8; + draw_dsc->shadow_opa = (uint16_t)((uint16_t)draw_dsc->shadow_opa * opa_scale) >> 8; + draw_dsc->pattern_opa = (uint16_t)((uint16_t)draw_dsc->pattern_opa * opa_scale) >> 8; } } @@ -2889,10 +2921,6 @@ void lv_obj_init_draw_label_dsc(lv_obj_t * obj, uint8_t part, lv_draw_label_dsc_ void lv_obj_init_draw_img_dsc(lv_obj_t * obj, uint8_t part, lv_draw_img_dsc_t * draw_dsc) { - draw_dsc->angle = 0; - draw_dsc->zoom = LV_IMG_ZOOM_NONE; - draw_dsc->pivot.x = lv_area_get_width(&obj->coords) / 2; - draw_dsc->pivot.y = lv_area_get_height(&obj->coords) / 2; draw_dsc->opa = lv_obj_get_style_opa(obj, part, LV_STYLE_IMAGE_OPA); if(draw_dsc->opa <= LV_OPA_MIN) return; lv_opa_t opa_scale = lv_obj_get_style_opa(obj, part, LV_STYLE_OPA_SCALE); @@ -2901,8 +2929,18 @@ void lv_obj_init_draw_img_dsc(lv_obj_t * obj, uint8_t part, lv_draw_img_dsc_t * } if(draw_dsc->opa <= LV_OPA_MIN) return; + + draw_dsc->angle = 0; + draw_dsc->zoom = LV_IMG_ZOOM_NONE; + draw_dsc->pivot.x = lv_area_get_width(&obj->coords) / 2; + draw_dsc->pivot.y = lv_area_get_height(&obj->coords) / 2; + + draw_dsc->recolor_opa = lv_obj_get_style_opa(obj, part, LV_STYLE_IMAGE_RECOLOR_OPA); + draw_dsc->recolor = lv_obj_get_style_color(obj, part, LV_STYLE_IMAGE_RECOLOR); + draw_dsc->overlay_opa = lv_obj_get_style_opa(obj, part, LV_STYLE_OVERLAY_OPA); draw_dsc->overlay_color = lv_obj_get_style_color(obj, part, LV_STYLE_OVERLAY_COLOR); + draw_dsc->blend_mode = lv_obj_get_style_value(obj, part, LV_STYLE_IMAGE_BLEND_MODE); } @@ -2919,9 +2957,10 @@ static lv_design_res_t lv_obj_design(lv_obj_t * obj, const lv_area_t * clip_area { if(mode == LV_DESIGN_COVER_CHK) { /*Most trivial test. Is the mask fully IN the object? If no it surely doesn't cover it*/ - if(lv_area_is_in(clip_area, &obj->coords) == false) return LV_DESIGN_RES_NOT_COVER; + lv_coord_t r = lv_obj_get_style_value(obj, LV_OBJ_PART_MAIN, LV_STYLE_RADIUS); + if(lv_area_is_in(clip_area, &obj->coords, r) == false) return LV_DESIGN_RES_NOT_COVER; - if(lv_obj_get_style_value(obj, LV_OBJ_PART_MAIN, LV_STYLE_BG_CLIP_CORNER)) return LV_DESIGN_RES_MASKED; + if(lv_obj_get_style_value(obj, LV_OBJ_PART_MAIN, LV_STYLE_CLIP_CORNER)) return LV_DESIGN_RES_MASKED; if(lv_obj_get_style_value(obj, LV_OBJ_PART_MAIN, LV_STYLE_BG_BLEND_MODE) != LV_BLEND_MODE_NORMAL) return LV_DESIGN_RES_NOT_COVER; if(lv_obj_get_style_value(obj, LV_OBJ_PART_MAIN, LV_STYLE_BORDER_BLEND_MODE) != LV_BLEND_MODE_NORMAL) return LV_DESIGN_RES_NOT_COVER; @@ -2930,26 +2969,6 @@ static lv_design_res_t lv_obj_design(lv_obj_t * obj, const lv_area_t * clip_area if(lv_obj_get_style_opa(obj, LV_OBJ_PART_MAIN, LV_STYLE_BG_OPA) < LV_OPA_MAX) return LV_DESIGN_RES_NOT_COVER; if(lv_obj_get_style_opa(obj, LV_OBJ_PART_MAIN, LV_STYLE_OPA_SCALE) < LV_OPA_MAX) return LV_DESIGN_RES_NOT_COVER; - /* Because of the radius it is not sure the area is covered - * Check the areas where there is no radius*/ - lv_coord_t r = lv_obj_get_style_value(obj, LV_OBJ_PART_MAIN, LV_STYLE_RADIUS); - - if(r == LV_RADIUS_CIRCLE) return LV_DESIGN_RES_NOT_COVER; - - lv_area_t area_tmp; - - /*Check horizontally without radius*/ - lv_obj_get_coords(obj, &area_tmp); - area_tmp.x1 += r; - area_tmp.x2 -= r; - if(lv_area_is_in(clip_area, &area_tmp) == false) return LV_DESIGN_RES_NOT_COVER; - - /*Check vertically without radius*/ - lv_obj_get_coords(obj, &area_tmp); - area_tmp.y1 += r; - area_tmp.y2 -= r; - if(lv_area_is_in(clip_area, &area_tmp) == false) return LV_DESIGN_RES_NOT_COVER; - return LV_DESIGN_RES_COVER; } @@ -2959,7 +2978,7 @@ static lv_design_res_t lv_obj_design(lv_obj_t * obj, const lv_area_t * clip_area lv_obj_init_draw_rect_dsc(obj, LV_OBJ_PART_MAIN, &draw_dsc); lv_draw_rect(&obj->coords, clip_area, &draw_dsc); - if(lv_obj_get_style_value(obj, LV_OBJ_PART_MAIN, LV_STYLE_BG_CLIP_CORNER)) { + if(lv_obj_get_style_value(obj, LV_OBJ_PART_MAIN, LV_STYLE_CLIP_CORNER)) { lv_draw_mask_radius_param_t * mp = lv_mem_buf_get(sizeof(lv_draw_mask_radius_param_t)); lv_coord_t r = lv_obj_get_style_value(obj, LV_OBJ_PART_MAIN, LV_STYLE_RADIUS); @@ -2970,7 +2989,7 @@ static lv_design_res_t lv_obj_design(lv_obj_t * obj, const lv_area_t * clip_area } } else if(mode == LV_DESIGN_DRAW_POST) { - if(lv_obj_get_style_value(obj, LV_OBJ_PART_MAIN, LV_STYLE_BG_CLIP_CORNER)) { + if(lv_obj_get_style_value(obj, LV_OBJ_PART_MAIN, LV_STYLE_CLIP_CORNER)) { lv_draw_mask_radius_param_t * param = lv_draw_mask_remove_custom(obj + 8); lv_mem_buf_release(param); } @@ -3241,7 +3260,7 @@ static lv_res_t style_cache_update_core(lv_obj_t * obj, uint8_t part) if(ptr == LV_FONT_DEFAULT) dsc->cache.font = LV_STYLE_CACHE_FONT_DEFAULT; else dsc->cache.font = LV_STYLE_CACHE_FONT_SKIPPED; - value = lv_obj_get_style_value(obj, part, LV_STYLE_BG_CLIP_CORNER); + value = lv_obj_get_style_value(obj, part, LV_STYLE_CLIP_CORNER); dsc->cache.clip_corner = value; diff --git a/src/lv_core/lv_obj.h b/src/lv_core/lv_obj.h index 4afdb1c08..f649a992e 100644 --- a/src/lv_core/lv_obj.h +++ b/src/lv_core/lv_obj.h @@ -864,6 +864,9 @@ void * lv_obj_get_style_ptr(const lv_obj_t * obj, uint8_t type, lv_style_propert // */ //const lv_style_t * lv_obj_get_style(const lv_obj_t * obj); + +void lv_obj_update_style_cache(lv_obj_t * obj, uint8_t part); + /*----------------- * Attribute get *----------------*/ diff --git a/src/lv_core/lv_refr.c b/src/lv_core/lv_refr.c index acc69e1be..b1615e9fe 100644 --- a/src/lv_core/lv_refr.c +++ b/src/lv_core/lv_refr.c @@ -124,7 +124,7 @@ void lv_inv_area(lv_disp_t * disp, const lv_area_t * area_p) /*Save only if this area is not in one of the saved areas*/ uint16_t i; for(i = 0; i < disp->inv_p; i++) { - if(lv_area_is_in(&com_area, &disp->inv_areas[i]) != false) return; + if(lv_area_is_in(&com_area, &disp->inv_areas[i], 0) != false) return; } /*Save the area*/ @@ -422,7 +422,7 @@ static lv_obj_t * lv_refr_get_top_obj(const lv_area_t * area_p, lv_obj_t * obj) lv_obj_t * found_p = NULL; /*If this object is fully cover the draw area check the children too */ - if(lv_area_is_in(area_p, &obj->coords) && obj->hidden == 0) { + if(lv_area_is_in(area_p, &obj->coords, 0) && obj->hidden == 0) { lv_design_res_t design_res = obj->design_cb(obj, area_p, LV_DESIGN_COVER_CHK); if(design_res == LV_DESIGN_RES_MASKED) return NULL; diff --git a/src/lv_core/lv_style.h b/src/lv_core/lv_style.h index 47aac1f1d..a0e940ddd 100644 --- a/src/lv_core/lv_style.h +++ b/src/lv_core/lv_style.h @@ -75,6 +75,7 @@ typedef union { 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_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), @@ -83,14 +84,13 @@ enum { LV_STYLE_PROP_INIT(LV_STYLE_PAD_RIGHT, 0x1, LV_STYLE_ID_VALUE + 3, LV_STYLE_ATTR_NONE), LV_STYLE_PROP_INIT(LV_STYLE_PAD_INNER, 0x1, LV_STYLE_ID_VALUE + 4, LV_STYLE_ATTR_NONE), - LV_STYLE_PROP_INIT(LV_STYLE_BG_CLIP_CORNER, 0x2, LV_STYLE_ID_VALUE + 0, LV_STYLE_ATTR_NONE), - LV_STYLE_PROP_INIT(LV_STYLE_BG_BLEND_MODE, 0x2, LV_STYLE_ID_VALUE + 1, LV_STYLE_ATTR_NONE), - LV_STYLE_PROP_INIT(LV_STYLE_BG_MAIN_COLOR_STOP, 0x2, LV_STYLE_ID_VALUE + 3, LV_STYLE_ATTR_NONE), - LV_STYLE_PROP_INIT(LV_STYLE_BG_GRAD_COLOR_STOP, 0x2, LV_STYLE_ID_VALUE + 4, LV_STYLE_ATTR_NONE), - LV_STYLE_PROP_INIT(LV_STYLE_BG_GRAD_DIR, 0x2, LV_STYLE_ID_VALUE + 5, LV_STYLE_ATTR_NONE), - LV_STYLE_PROP_INIT(LV_STYLE_BG_COLOR, 0x2, LV_STYLE_ID_COLOR + 0, LV_STYLE_ATTR_NONE), - LV_STYLE_PROP_INIT(LV_STYLE_BG_GRAD_COLOR, 0x2, LV_STYLE_ID_COLOR + 1, LV_STYLE_ATTR_NONE), - LV_STYLE_PROP_INIT(LV_STYLE_BG_OPA, 0x2, LV_STYLE_ID_OPA + 0, LV_STYLE_ATTR_NONE), + LV_STYLE_PROP_INIT(LV_STYLE_BG_BLEND_MODE, 0x2, LV_STYLE_ID_VALUE + 0, LV_STYLE_ATTR_NONE), + LV_STYLE_PROP_INIT(LV_STYLE_BG_COLOR_STOP, 0x2, LV_STYLE_ID_VALUE + 1, LV_STYLE_ATTR_NONE), + LV_STYLE_PROP_INIT(LV_STYLE_BG_GRAD_STOP, 0x2, LV_STYLE_ID_VALUE + 2, LV_STYLE_ATTR_NONE), + LV_STYLE_PROP_INIT(LV_STYLE_BG_GRAD_DIR, 0x2, LV_STYLE_ID_VALUE + 3, LV_STYLE_ATTR_NONE), + LV_STYLE_PROP_INIT(LV_STYLE_BG_COLOR, 0x2, LV_STYLE_ID_COLOR + 0, LV_STYLE_ATTR_NONE), + LV_STYLE_PROP_INIT(LV_STYLE_BG_GRAD_COLOR, 0x2, LV_STYLE_ID_COLOR + 1, LV_STYLE_ATTR_NONE), + LV_STYLE_PROP_INIT(LV_STYLE_BG_OPA, 0x2, LV_STYLE_ID_OPA + 0, LV_STYLE_ATTR_NONE), LV_STYLE_PROP_INIT(LV_STYLE_BORDER_WIDTH, 0x3, LV_STYLE_ID_VALUE + 0, LV_STYLE_ATTR_NONE), LV_STYLE_PROP_INIT(LV_STYLE_BORDER_PART, 0x3, LV_STYLE_ID_VALUE + 1, LV_STYLE_ATTR_NONE), @@ -106,26 +106,33 @@ enum { LV_STYLE_PROP_INIT(LV_STYLE_SHADOW_COLOR, 0x4, LV_STYLE_ID_COLOR + 0, LV_STYLE_ATTR_NONE), LV_STYLE_PROP_INIT(LV_STYLE_SHADOW_OPA, 0x4, LV_STYLE_ID_OPA + 0, LV_STYLE_ATTR_NONE), - LV_STYLE_PROP_INIT(LV_STYLE_LETTER_SPACE, 0x5, LV_STYLE_ID_VALUE + 0, LV_STYLE_ATTR_INHERIT), - LV_STYLE_PROP_INIT(LV_STYLE_LINE_SPACE, 0x5, LV_STYLE_ID_VALUE + 1, LV_STYLE_ATTR_INHERIT), - LV_STYLE_PROP_INIT(LV_STYLE_TEXT_BLEND_MODE, 0x5, LV_STYLE_ID_VALUE + 2, LV_STYLE_ATTR_NONE), - LV_STYLE_PROP_INIT(LV_STYLE_TEXT_COLOR, 0x5, LV_STYLE_ID_COLOR + 0, LV_STYLE_ATTR_INHERIT), - LV_STYLE_PROP_INIT(LV_STYLE_TEXT_OPA, 0x5, LV_STYLE_ID_OPA + 0, LV_STYLE_ATTR_NONE), - LV_STYLE_PROP_INIT(LV_STYLE_FONT, 0x5, LV_STYLE_ID_PTR + 0, LV_STYLE_ATTR_INHERIT), + LV_STYLE_PROP_INIT(LV_STYLE_PATTERN_REPEATE, 0x5, LV_STYLE_ID_VALUE + 0, LV_STYLE_ATTR_NONE), + LV_STYLE_PROP_INIT(LV_STYLE_PATTERN_RECOLOR, 0x5, LV_STYLE_ID_COLOR + 0, LV_STYLE_ATTR_NONE), + LV_STYLE_PROP_INIT(LV_STYLE_PATTERN_OPA, 0x5, LV_STYLE_ID_OPA + 1, LV_STYLE_ATTR_NONE), + LV_STYLE_PROP_INIT(LV_STYLE_PATTERN_RECOLOR_OPA, 0x5, LV_STYLE_ID_OPA + 2, LV_STYLE_ATTR_NONE), + LV_STYLE_PROP_INIT(LV_STYLE_PATTERN_IMAGE, 0x5, LV_STYLE_ID_PTR + 0, LV_STYLE_ATTR_NONE), - LV_STYLE_PROP_INIT(LV_STYLE_LINE_WIDTH, 0x6, LV_STYLE_ID_VALUE + 0, LV_STYLE_ATTR_NONE), - LV_STYLE_PROP_INIT(LV_STYLE_LINE_BLEND_MODE, 0x5, LV_STYLE_ID_VALUE + 1, LV_STYLE_ATTR_NONE), - LV_STYLE_PROP_INIT(LV_STYLE_LINE_COLOR, 0x6, LV_STYLE_ID_COLOR + 0, LV_STYLE_ATTR_NONE), - LV_STYLE_PROP_INIT(LV_STYLE_LINE_OPA, 0x6, LV_STYLE_ID_OPA + 0, LV_STYLE_ATTR_NONE), + LV_STYLE_PROP_INIT(LV_STYLE_LETTER_SPACE, 0x6, LV_STYLE_ID_VALUE + 0, LV_STYLE_ATTR_INHERIT), + LV_STYLE_PROP_INIT(LV_STYLE_LINE_SPACE, 0x6, LV_STYLE_ID_VALUE + 1, LV_STYLE_ATTR_INHERIT), + LV_STYLE_PROP_INIT(LV_STYLE_TEXT_BLEND_MODE, 0x6, LV_STYLE_ID_VALUE + 2, LV_STYLE_ATTR_NONE), + LV_STYLE_PROP_INIT(LV_STYLE_TEXT_COLOR, 0x6, LV_STYLE_ID_COLOR + 0, LV_STYLE_ATTR_INHERIT), + LV_STYLE_PROP_INIT(LV_STYLE_TEXT_OPA, 0x6, LV_STYLE_ID_OPA + 0, LV_STYLE_ATTR_NONE), + LV_STYLE_PROP_INIT(LV_STYLE_FONT, 0x6, LV_STYLE_ID_PTR + 0, LV_STYLE_ATTR_INHERIT), - LV_STYLE_PROP_INIT(LV_STYLE_IMAGE_BLEND_MODE, 0x7, LV_STYLE_ID_VALUE + 0, LV_STYLE_ATTR_NONE), - LV_STYLE_PROP_INIT(LV_STYLE_IMEGE_COLOR, 0x7, LV_STYLE_ID_COLOR + 0, LV_STYLE_ATTR_NONE), - LV_STYLE_PROP_INIT(LV_STYLE_IMAGE_OPA, 0x7, LV_STYLE_ID_OPA + 0, LV_STYLE_ATTR_NONE), + LV_STYLE_PROP_INIT(LV_STYLE_LINE_WIDTH, 0x7, LV_STYLE_ID_VALUE + 0, LV_STYLE_ATTR_NONE), + LV_STYLE_PROP_INIT(LV_STYLE_LINE_BLEND_MODE, 0x7, LV_STYLE_ID_VALUE + 1, LV_STYLE_ATTR_NONE), + LV_STYLE_PROP_INIT(LV_STYLE_LINE_COLOR, 0x7, LV_STYLE_ID_COLOR + 0, LV_STYLE_ATTR_NONE), + LV_STYLE_PROP_INIT(LV_STYLE_LINE_OPA, 0x7, LV_STYLE_ID_OPA + 0, LV_STYLE_ATTR_NONE), - LV_STYLE_PROP_INIT(LV_STYLE_OVERLAY_COLOR, 0x8, LV_STYLE_ID_COLOR + 0, LV_STYLE_ATTR_INHERIT), - LV_STYLE_PROP_INIT(LV_STYLE_OVERLAY_OPA, 0x8, LV_STYLE_ID_OPA + 0, LV_STYLE_ATTR_INHERIT), + LV_STYLE_PROP_INIT(LV_STYLE_IMAGE_BLEND_MODE, 0x8, LV_STYLE_ID_VALUE + 0, LV_STYLE_ATTR_NONE), + LV_STYLE_PROP_INIT(LV_STYLE_IMAGE_RECOLOR, 0x8, LV_STYLE_ID_COLOR + 0, LV_STYLE_ATTR_NONE), + LV_STYLE_PROP_INIT(LV_STYLE_IMAGE_OPA, 0x8, LV_STYLE_ID_OPA + 0, LV_STYLE_ATTR_NONE), + LV_STYLE_PROP_INIT(LV_STYLE_IMAGE_RECOLOR_OPA, 0x8, LV_STYLE_ID_OPA + 1, LV_STYLE_ATTR_NONE), - LV_STYLE_PROP_INIT(LV_STYLE_SCROLLBAR_WIDTH, 0x9, LV_STYLE_ID_VALUE + 0, LV_STYLE_ATTR_NONE), + LV_STYLE_PROP_INIT(LV_STYLE_OVERLAY_COLOR, 0x9, LV_STYLE_ID_COLOR + 0, LV_STYLE_ATTR_INHERIT), + LV_STYLE_PROP_INIT(LV_STYLE_OVERLAY_OPA, 0x9, LV_STYLE_ID_OPA + 0, LV_STYLE_ATTR_INHERIT), + + LV_STYLE_PROP_INIT(LV_STYLE_SCROLLBAR_WIDTH, 0xA, LV_STYLE_ID_VALUE + 0, LV_STYLE_ATTR_NONE), }; diff --git a/src/lv_draw/lv_draw_img.c b/src/lv_draw/lv_draw_img.c index dffb1c104..60c49552b 100644 --- a/src/lv_draw/lv_draw_img.c +++ b/src/lv_draw/lv_draw_img.c @@ -25,7 +25,7 @@ /********************** * STATIC PROTOTYPES **********************/ -static lv_res_t lv_img_draw_core(const lv_area_t * coords, const lv_area_t * mask, lv_draw_img_dsc_t * draw_dsc, const void * src); +static lv_res_t lv_img_draw_core(const lv_area_t * coords, const lv_area_t * mask, const void * src, lv_draw_img_dsc_t * draw_dsc); static void lv_draw_map(const lv_area_t * map_area, const lv_area_t * clip_area, const uint8_t * map_p, lv_draw_img_dsc_t * draw_dsc, bool chroma_key, bool alpha_byte); @@ -197,11 +197,11 @@ lv_img_src_t lv_img_src_get_type(const void * src) * STATIC FUNCTIONS **********************/ -static lv_res_t lv_img_draw_core(const lv_area_t * coords, const lv_area_t * mask, lv_draw_img_dsc_t * draw_dsc, const void * src) +static lv_res_t lv_img_draw_core(const lv_area_t * coords, const lv_area_t * mask, const void * src, lv_draw_img_dsc_t * draw_dsc) { if(draw_dsc->opa <= LV_OPA_MIN) return LV_RES_OK; - lv_img_cache_entry_t * cdsc = lv_img_cache_open(src, draw_dsc->overlay_color); + lv_img_cache_entry_t * cdsc = lv_img_cache_open(src, draw_dsc->recolor); if(cdsc == NULL) return LV_RES_INV; @@ -354,7 +354,7 @@ static void lv_draw_map(const lv_area_t * map_area, const lv_area_t * clip_area, /*The simplest case just copy the pixels into the VDB*/ if(other_mask_cnt == 0 && draw_dsc->angle == 0 && draw_dsc->zoom == LV_IMG_ZOOM_NONE && chroma_key == false && alpha_byte == false && - draw_dsc->opa == LV_OPA_COVER && draw_dsc->overlay_opa == LV_OPA_TRANSP) { + draw_dsc->opa == LV_OPA_COVER && draw_dsc->recolor_opa == LV_OPA_TRANSP) { lv_blend_map(clip_area, map_area, (lv_color_t *)map_p, NULL, LV_DRAW_MASK_RES_FULL_COVER, LV_OPA_COVER, draw_dsc->blend_mode); } /*In the other cases every pixel need to be checked one-by-one*/ @@ -410,7 +410,7 @@ static void lv_draw_map(const lv_area_t * map_area, const lv_area_t * clip_area, trans_dsc.cfg.cf = cf; trans_dsc.cfg.pivot_x = draw_dsc->pivot.x; trans_dsc.cfg.pivot_y = draw_dsc->pivot.y; - trans_dsc.cfg.color = draw_dsc->overlay_color; + trans_dsc.cfg.color = draw_dsc->recolor; trans_dsc.cfg.antialias = draw_dsc->antialias; lv_img_buf_transform_init(&trans_dsc); @@ -463,8 +463,8 @@ static void lv_draw_map(const lv_area_t * map_area, const lv_area_t * clip_area, } } - if(draw_dsc->overlay_opa != 0) { - c = lv_color_mix(draw_dsc->overlay_color, c, draw_dsc->overlay_opa); + if(draw_dsc->recolor_opa != 0) { + c = lv_color_mix(draw_dsc->recolor, c, draw_dsc->recolor_opa); } map2[px_i].full = c.full; diff --git a/src/lv_draw/lv_draw_img.h b/src/lv_draw/lv_draw_img.h index fc6a24d05..f70169e1f 100644 --- a/src/lv_draw/lv_draw_img.h +++ b/src/lv_draw/lv_draw_img.h @@ -36,11 +36,14 @@ typedef struct { lv_point_t pivot; uint16_t zoom; + lv_opa_t recolor_opa; + lv_color_t recolor; + lv_opa_t overlay_opa; lv_color_t overlay_color; - lv_blend_mode_t blend_mode; + uint8_t antialias :1; } lv_draw_img_dsc_t; diff --git a/src/lv_draw/lv_draw_rect.c b/src/lv_draw/lv_draw_rect.c index 7c520591e..4a4e0618f 100644 --- a/src/lv_draw/lv_draw_rect.c +++ b/src/lv_draw/lv_draw_rect.c @@ -32,6 +32,7 @@ static void draw_shadow(const lv_area_t * coords, const lv_area_t * clip, lv_dra static lv_color_t grad_get(lv_draw_rect_dsc_t * dsc, lv_coord_t s, lv_coord_t i); static void shadow_draw_corner_buf(const lv_area_t * coords, lv_opa_t * sh_buf, lv_coord_t s, lv_coord_t r); static void shadow_blur_corner(lv_coord_t size, lv_coord_t sw, lv_opa_t * res_buf, uint16_t * sh_ups_buf); +static void draw_img(const lv_area_t * coords, const lv_area_t * clip, lv_draw_rect_dsc_t * dsc); /********************** * STATIC VARIABLES @@ -51,6 +52,8 @@ void lv_draw_rect_dsc_init(lv_draw_rect_dsc_t * dsc) dsc->bg_opa = LV_OPA_COVER; dsc->bg_grad_color_stop = 0xFF; dsc->border_opa = LV_OPA_COVER; + dsc->overlay_opa = LV_OPA_TRANSP; + dsc->pattern_font = LV_FONT_DEFAULT; } @@ -66,6 +69,7 @@ void lv_draw_rect(const lv_area_t * coords, const lv_area_t * clip, lv_draw_rect draw_shadow(coords, clip, dsc); draw_bg(coords, clip, dsc); + draw_img(coords, clip, dsc); draw_border(coords, clip, dsc); } @@ -912,12 +916,6 @@ static void shadow_draw_corner_buf(const lv_area_t * coords, lv_opa_t * sh_buf, } lv_mem_buf_release(mask_line); - // uint32_t k; - // for(k = 0; k < size * size; k++) { - // sh_buf[k] = (sh_ups_buf[k] * sw) >> SHADOW_UPSACALE_SHIFT ; - // } - // return; - if(sw == 1) { lv_coord_t i; for(i = 0; i < size * size; i++) { @@ -981,8 +979,8 @@ static void shadow_blur_corner(lv_coord_t size, lv_coord_t sw, lv_opa_t * res_bu if(x - s_left - 1 < 0) left_val = sh_ups_tmp_buf[0]; else left_val = sh_ups_tmp_buf[x - s_left - 1]; v += left_val; - } + sh_ups_tmp_buf += size; sh_ups_hor_buf_tmp += size; } @@ -1021,3 +1019,89 @@ static void shadow_blur_corner(lv_coord_t size, lv_coord_t sw, lv_opa_t * res_bu lv_mem_buf_release(sh_ups_hor_buf); } +static void draw_img(const lv_area_t * coords, const lv_area_t * clip, lv_draw_rect_dsc_t * dsc) +{ + if(dsc->pattern_src == NULL) return; + if(dsc->pattern_opa <= LV_OPA_MIN) return; + + lv_img_src_t src_type = lv_img_src_get_type(dsc->pattern_src); + + lv_draw_img_dsc_t img_dsc; + lv_draw_label_dsc_t label_dsc; + lv_coord_t img_w; + lv_coord_t img_h; + + if(src_type == LV_IMG_SRC_FILE || src_type == LV_IMG_SRC_VARIABLE) { + lv_img_header_t header; + lv_res_t res = lv_img_decoder_get_info(dsc->pattern_src, &header); + if(res!= LV_RES_OK) { + LV_LOG_WARN("draw_img: can't get image info"); + return; + } + + img_w = header.w; + img_h = header.h; + + lv_draw_img_dsc_init(&img_dsc); + img_dsc.opa = dsc->pattern_opa; + img_dsc.recolor_opa = dsc->pattern_recolor_opa; + img_dsc.recolor = dsc->pattern_recolor; + } else if(src_type == LV_IMG_SRC_SYMBOL) { + lv_draw_label_dsc_init(&label_dsc); + label_dsc.color = dsc->pattern_recolor; + label_dsc.font = dsc->pattern_font; + lv_point_t s; + lv_txt_get_size(&s, dsc->pattern_src, label_dsc.font, label_dsc.letter_space, label_dsc.line_space, LV_COORD_MAX, LV_TXT_FLAG_NONE); + img_w = s.x; + img_h = s.y; + + } else { + /*Trigger the error handler of image drawer*/ + LV_LOG_WARN("lv_img_design: image source type is unknown"); + lv_draw_img(coords, clip, NULL, NULL); + } + + + + lv_area_t coords_tmp; + + if(dsc->pattern_repeate) { + lv_draw_mask_radius_param_t radius_mask_param; + lv_draw_mask_radius_init(&radius_mask_param, coords, dsc->radius, false); + int16_t radius_mask_id = lv_draw_mask_add(&radius_mask_param, NULL); + + /*Align the pattern to the middle*/ + lv_coord_t ofs_x = (lv_area_get_width(coords) - (lv_area_get_width(coords) / img_w) * img_w) / 2; + lv_coord_t ofs_y = (lv_area_get_height(coords) - (lv_area_get_height(coords) / img_h) * img_h) / 2; + + coords_tmp.y1 = coords->y1 - ofs_y; + coords_tmp.y2 = coords_tmp.y1 + img_h - 1; + for(; coords_tmp.y1 <= coords->y2; coords_tmp.y1 += img_h, coords_tmp.y2 += img_h) { + coords_tmp.x1 = coords->x1 - ofs_x; + coords_tmp.x2 = coords_tmp.x1 + img_w - 1; + for(; coords_tmp.x1 <= coords->x2; coords_tmp.x1 += img_w, coords_tmp.x2 += img_w) { + if(src_type == LV_IMG_SRC_SYMBOL) lv_draw_label(&coords_tmp, clip, &label_dsc, dsc->pattern_src, NULL); + else lv_draw_img(&coords_tmp, clip, dsc->pattern_src, &img_dsc); + } + } + lv_draw_mask_remove_id(radius_mask_id); + } else { + coords_tmp.x1 = coords->x1 + lv_area_get_width(coords) / 2 - img_w / 2; + coords_tmp.y1 = coords->y1 + lv_area_get_height(coords) / 2 - img_h / 2; + coords_tmp.x2 = coords_tmp.x1 + img_w - 1; + coords_tmp.y2 = coords_tmp.y1 + img_h - 1; + + int16_t radius_mask_id = LV_MASK_ID_INV; + if(lv_area_is_in(&coords_tmp, coords, dsc->radius) == false) { + lv_draw_mask_radius_param_t radius_mask_param; + lv_draw_mask_radius_init(&radius_mask_param, coords, dsc->radius, false); + radius_mask_id = lv_draw_mask_add(&radius_mask_param, NULL); + } + + if(src_type == LV_IMG_SRC_SYMBOL) lv_draw_label(&coords_tmp, clip, &label_dsc, dsc->pattern_src, NULL); + else lv_draw_img(&coords_tmp, clip, dsc->pattern_src, &img_dsc); + + lv_draw_mask_remove_id(radius_mask_id); + } +} + diff --git a/src/lv_draw/lv_draw_rect.h b/src/lv_draw/lv_draw_rect.h index d6facb24b..d627ea80c 100644 --- a/src/lv_draw/lv_draw_rect.h +++ b/src/lv_draw/lv_draw_rect.h @@ -50,6 +50,17 @@ typedef struct { lv_style_value_t shadow_ofs_y; lv_opa_t shadow_opa; + /*Pattern*/ + const void * pattern_src; + const lv_font_t * pattern_font; + lv_opa_t pattern_opa; + lv_opa_t pattern_recolor_opa; + lv_color_t pattern_recolor; + uint8_t pattern_repeate :1; + + /*Overlay*/ + lv_opa_t overlay_opa; + lv_color_t overlay_color; }lv_draw_rect_dsc_t; /********************** diff --git a/src/lv_misc/lv_area.c b/src/lv_misc/lv_area.c index 0c43b3a5d..db3a93b3f 100644 --- a/src/lv_misc/lv_area.c +++ b/src/lv_misc/lv_area.c @@ -144,6 +144,7 @@ void lv_area_join(lv_area_t * a_res_p, const lv_area_t * a1_p, const lv_area_t * * Check if a point is on an area * @param a_p pointer to an area * @param p_p pointer to a point + * @param radius radius of area (e.g. for rounded rectangle) * @return false:the point is out of the area */ bool lv_area_is_point_on(const lv_area_t * a_p, const lv_point_t * p_p, lv_coord_t radius) @@ -201,7 +202,7 @@ bool lv_area_is_point_on(const lv_area_t * a_p, const lv_point_t * p_p, lv_coord return lv_point_within_circle(&corner_area, p_p); } /*Not within corners*/ - return false; + return true; } /** @@ -222,10 +223,11 @@ bool lv_area_is_on(const lv_area_t * a1_p, const lv_area_t * a2_p) /** * Check if an area is fully on an other * @param ain_p pointer to an area which could be in 'aholder_p' - * @param aholder pointer to an area which could involve 'ain_p' - * @return + * @param aholder_p pointer to an area which could involve 'ain_p' + * @param radius radius of `aholder_p` (e.g. for rounded rectangle) + * @return true: `ain_p` is fully inside `aholder_p` */ -bool lv_area_is_in(const lv_area_t * ain_p, const lv_area_t * aholder_p) +bool lv_area_is_in(const lv_area_t * ain_p, const lv_area_t * aholder_p, lv_coord_t radius) { bool is_in = false; @@ -234,7 +236,28 @@ bool lv_area_is_in(const lv_area_t * ain_p, const lv_area_t * aholder_p) is_in = true; } - return is_in; + if(radius == 0) return is_in; + + /*Check if the corner points are inside the radius or not*/ + lv_point_t p; + + p.x = ain_p->x1; + p.y = ain_p->y1; + if(lv_area_is_point_on(aholder_p, &p, radius) == false) return false; + + p.x = ain_p->x2; + p.y = ain_p->y1; + if(lv_area_is_point_on(aholder_p, &p, radius) == false) return false; + + p.x = ain_p->x1; + p.y = ain_p->y2; + if(lv_area_is_point_on(aholder_p, &p, radius) == false) return false; + + p.x = ain_p->x2; + p.y = ain_p->y2; + if(lv_area_is_point_on(aholder_p, &p, radius) == false) return false; + + return true; } /** diff --git a/src/lv_misc/lv_area.h b/src/lv_misc/lv_area.h index bff022309..3d4b08ed3 100644 --- a/src/lv_misc/lv_area.h +++ b/src/lv_misc/lv_area.h @@ -159,11 +159,12 @@ bool lv_area_is_on(const lv_area_t * a1_p, const lv_area_t * a2_p); /** * Check if an area is fully on an other - * @param ain_p pointer to an area which could be on aholder_p - * @param aholder pointer to an area which could involve ain_p - * @return + * @param ain_p pointer to an area which could be in 'aholder_p' + * @param aholder_p pointer to an area which could involve 'ain_p' + * @param radius radius of `aholder_p` (e.g. for rounded rectangle) + * @return true: `ain_p` is fully inside `aholder_p` */ -bool lv_area_is_in(const lv_area_t * ain_p, const lv_area_t * aholder_p); +bool lv_area_is_in(const lv_area_t * ain_p, const lv_area_t * aholder_p, lv_coord_t radius); /** * Increment or decrement an area's size by a single amount diff --git a/src/lv_objx/lv_btn.c b/src/lv_objx/lv_btn.c index 466d2ca23..8f89626d6 100644 --- a/src/lv_objx/lv_btn.c +++ b/src/lv_objx/lv_btn.c @@ -450,7 +450,7 @@ static lv_design_res_t lv_btn_design(lv_obj_t * btn, const lv_area_t * clip_area lv_draw_rect(&btn->coords, clip_area, &draw_dsc); - if(lv_obj_get_style_value(btn, LV_OBJ_PART_MAIN, LV_STYLE_BG_CLIP_CORNER)) { + if(lv_obj_get_style_value(btn, LV_OBJ_PART_MAIN, LV_STYLE_CLIP_CORNER)) { lv_draw_mask_radius_param_t * mp = lv_mem_buf_get(sizeof(lv_draw_mask_radius_param_t)); lv_coord_t r = lv_obj_get_style_value(btn, LV_OBJ_PART_MAIN, LV_STYLE_RADIUS); diff --git a/src/lv_objx/lv_ddlist.c b/src/lv_objx/lv_ddlist.c index 46c8936e0..8abda3a98 100644 --- a/src/lv_objx/lv_ddlist.c +++ b/src/lv_objx/lv_ddlist.c @@ -39,6 +39,7 @@ static lv_design_res_t lv_ddlist_design(lv_obj_t * ddlist, const lv_area_t * clip_area, lv_design_mode_t mode); static lv_res_t lv_ddlist_signal(lv_obj_t * ddlist, lv_signal_t sign, void * param); static lv_res_t lv_ddlist_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void * param); +static lv_style_dsc_t * lv_ddlist_get_style(lv_obj_t * ddlist, uint8_t part); static lv_res_t release_handler(lv_obj_t * ddlist); static void lv_ddlist_refr_size(lv_obj_t * ddlist, lv_anim_enable_t anim); static void lv_ddlist_pos_current_option(lv_obj_t * ddlist); @@ -100,8 +101,8 @@ lv_obj_t * lv_ddlist_create(lv_obj_t * par, const lv_obj_t * copy) ext->sel_opt_id = 0; ext->sel_opt_id_ori = 0; ext->option_cnt = 0; - ext->sel_style = &lv_style_plain_color; ext->stay_open = 0; + lv_style_dsc_init(&ext->style_sel); /*The signal and design functions are not copied so set them here*/ lv_obj_set_signal_cb(new_ddlist, lv_ddlist_signal); @@ -124,27 +125,17 @@ lv_obj_t * lv_ddlist_create(lv_obj_t * par, const lv_obj_t * copy) ext->label = lv_label_create(new_ddlist, NULL); lv_cont_set_fit2(new_ddlist, LV_FIT_TIGHT, LV_FIT_NONE); lv_page_set_sb_mode(new_ddlist, LV_SB_MODE_HIDE); - lv_page_set_style(new_ddlist, LV_PAGE_STYLE_SCRL, &lv_style_transp_tight); lv_ddlist_set_options(new_ddlist, "Option 1\nOption 2\nOption 3"); + lv_obj_reset_style(new_ddlist, LV_DDLIST_PART_SCRL); + _ot(new_ddlist, LV_DDLIST_PART_SCRL, DDLIST_SCRL); + _ot(new_ddlist, LV_DDLIST_PART_SEL, DDLIST_SEL); + + /*Restore the original X coordinate*/ if(lv_obj_get_base_dir(new_ddlist) == LV_BIDI_DIR_RTL) lv_obj_set_x(new_ddlist, x - lv_obj_get_width(new_ddlist)); else lv_obj_set_x(new_ddlist, x); - - /*Set the default styles*/ - lv_theme_t * th = lv_theme_get_current(); - if(th) { - lv_ddlist_set_style(new_ddlist, LV_DDLIST_STYLE_BG, th->style.ddlist.bg); - lv_ddlist_set_style(new_ddlist, LV_DDLIST_STYLE_SEL, th->style.ddlist.sel); - lv_ddlist_set_style(new_ddlist, LV_DDLIST_STYLE_SB, th->style.ddlist.sb); - } else { - lv_ddlist_set_style(new_ddlist, LV_DDLIST_STYLE_BG, &lv_style_pretty); - lv_ddlist_set_style(new_ddlist, LV_DDLIST_STYLE_SEL, &lv_style_plain_color); - lv_ddlist_set_style(new_ddlist, LV_DDLIST_STYLE_SB, &lv_style_pretty_color); - } - - } /*Copy an existing drop down list*/ else { @@ -155,14 +146,8 @@ lv_obj_t * lv_ddlist_create(lv_obj_t * par, const lv_obj_t * copy) ext->sel_opt_id_ori = copy_ext->sel_opt_id; ext->fix_height = copy_ext->fix_height; ext->option_cnt = copy_ext->option_cnt; - ext->sel_style = copy_ext->sel_style; ext->symbol = copy_ext->symbol; ext->stay_open = copy_ext->stay_open; - - lv_ddlist_set_style(new_ddlist, LV_DDLIST_STYLE_BG, lv_ddlist_get_style(copy, LV_DDLIST_STYLE_BG)); - lv_ddlist_set_style(new_ddlist, LV_DDLIST_STYLE_SB, lv_ddlist_get_style(copy, LV_DDLIST_STYLE_SB)); - lv_ddlist_set_style(new_ddlist, LV_DDLIST_STYLE_SEL, lv_ddlist_get_style(copy, LV_DDLIST_STYLE_SEL)); - } LV_LOG_INFO("drop down list created"); @@ -305,32 +290,6 @@ void lv_ddlist_set_stay_open(lv_obj_t * ddlist, bool en) ext->stay_open = en ? 1 : 0; } -/** - * Set a style of a drop down list - * @param ddlist pointer to a drop down list object - * @param type which style should be set - * @param style pointer to a style - */ -void lv_ddlist_set_style(lv_obj_t * ddlist, lv_ddlist_style_t type, const lv_style_t * style) -{ - LV_ASSERT_OBJ(ddlist, LV_OBJX_NAME); - - lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); - - switch(type) { - case LV_DDLIST_STYLE_BG: - lv_page_set_style(ddlist, LV_PAGE_STYLE_BG, style); - lv_ddlist_refr_width(ddlist); - break; - case LV_DDLIST_STYLE_SB: lv_page_set_style(ddlist, LV_PAGE_STYLE_SB, style); break; - case LV_DDLIST_STYLE_SEL: - ext->sel_style = style; - lv_obj_t * scrl = lv_page_get_scrl(ddlist); - lv_obj_refresh_ext_draw_pad(scrl); /*Because of the wider selected rectangle*/ - break; - } -} - void lv_ddlist_set_align(lv_obj_t * ddlist, lv_label_align_t align) { LV_ASSERT_OBJ(ddlist, LV_OBJX_NAME); @@ -463,35 +422,10 @@ bool lv_ddlist_get_stay_open(lv_obj_t * ddlist) } /** - * Get a style of a drop down list + * Get the alignment of the labels in a drop down list * @param ddlist pointer to a drop down list object - * @param type which style should be get - * @return style pointer to a style + * @return alignment of labels */ -const lv_style_t * lv_ddlist_get_style(const lv_obj_t * ddlist, lv_ddlist_style_t type) -{ - LV_ASSERT_OBJ(ddlist, LV_OBJX_NAME); - - lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); - const lv_style_t * style; - - switch(type) { - case LV_DDLIST_STYLE_BG: - style = lv_page_get_style(ddlist, LV_PAGE_STYLE_BG); - break; - case LV_DDLIST_STYLE_SB: - style = lv_page_get_style(ddlist, LV_PAGE_STYLE_SB); - break; - case LV_DDLIST_STYLE_SEL: - style = ext->sel_style; - break; - default: - style = NULL; - } - - return style; -} - lv_label_align_t lv_ddlist_get_align(const lv_obj_t * ddlist) { lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); @@ -539,28 +473,6 @@ void lv_ddlist_close(lv_obj_t * ddlist, lv_anim_enable_t anim) * STATIC FUNCTIONS **********************/ -/** - * Get the text alignment flag for a drop down list. - * @param ddlist drop down list - * @return text alignment flag - */ -static lv_txt_flag_t lv_ddlist_get_txt_flag(const lv_obj_t * ddlist) -{ - lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); - - /*The label might be already deleted so just return with some value*/ - if(!ext->label) return LV_TXT_FLAG_CENTER; - - lv_label_align_t align = lv_label_get_align(ext->label); - - switch(align) { - default: - case LV_LABEL_ALIGN_LEFT: return LV_TXT_FLAG_NONE; - case LV_LABEL_ALIGN_CENTER: return LV_TXT_FLAG_CENTER; - case LV_LABEL_ALIGN_RIGHT: return LV_TXT_FLAG_RIGHT; - } -} - /** * Handle the drawing related tasks of the drop down lists * @param ddlist pointer to an object @@ -582,58 +494,53 @@ static lv_design_res_t lv_ddlist_design(lv_obj_t * ddlist, const lv_area_t * cli ancestor_design(ddlist, clip_area, mode); lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); - lv_opa_t opa_scale = lv_obj_get_opa_scale(ddlist); /*If the list is opened draw a rectangle under the selected item*/ if(ext->opened != 0 || ext->force_sel) { - const lv_style_t * style = lv_ddlist_get_style(ddlist, LV_DDLIST_STYLE_BG); - const lv_font_t * font = style->text.font; + const lv_font_t * font = lv_obj_get_style_ptr(ddlist, LV_DDLIST_PART_BG, LV_STYLE_FONT); + lv_style_value_t line_space = lv_obj_get_style_value(ddlist, LV_DDLIST_PART_BG, LV_STYLE_LINE_SPACE); lv_coord_t font_h = lv_font_get_line_height(font); /*Draw the selected*/ lv_area_t rect_area; rect_area.y1 = ext->label->coords.y1; - rect_area.y1 += ext->sel_opt_id * (font_h + style->text.line_space); - rect_area.y1 -= style->text.line_space / 2; + rect_area.y1 += ext->sel_opt_id * (font_h + line_space); + rect_area.y1 -= line_space / 2; - rect_area.y2 = rect_area.y1 + font_h + style->text.line_space - 1; + rect_area.y2 = rect_area.y1 + font_h + line_space - 1; rect_area.x1 = ddlist->coords.x1; rect_area.x2 = ddlist->coords.x2; - lv_draw_rect(&rect_area, clip_area, ext->sel_style, opa_scale); + lv_draw_rect_dsc_t sel_rect; + lv_draw_rect_dsc_init(&sel_rect); + lv_obj_init_draw_rect_dsc(ddlist, LV_DDLIST_PART_SEL, &sel_rect); + lv_draw_rect(&rect_area, clip_area, &sel_rect); } } /*Post draw when the children are drawn*/ else if(mode == LV_DESIGN_DRAW_POST) { /*Redraw the text on the selected area with a different color*/ lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); - lv_opa_t opa_scale = lv_obj_get_opa_scale(ddlist); /*Redraw only in opened state*/ if(ext->opened || ext->force_sel) { - const lv_style_t * style = lv_ddlist_get_style(ddlist, LV_DDLIST_STYLE_BG); - const lv_font_t * font = style->text.font; - lv_coord_t font_h = lv_font_get_line_height(font); + lv_draw_label_dsc_t label_dsc; + lv_draw_label_dsc_init(&label_dsc); + lv_obj_init_draw_label_dsc(ddlist, LV_DDLIST_PART_SEL, &label_dsc); + lv_coord_t font_h = lv_font_get_line_height(label_dsc.font); lv_area_t area_sel; area_sel.y1 = ext->label->coords.y1; - area_sel.y1 += ext->sel_opt_id * (font_h + style->text.line_space); - area_sel.y1 -= style->text.line_space / 2; + area_sel.y1 += ext->sel_opt_id * (font_h + label_dsc.line_space); + area_sel.y1 -= label_dsc.line_space / 2; - area_sel.y2 = area_sel.y1 + font_h + style->text.line_space - 1; + area_sel.y2 = area_sel.y1 + font_h + label_dsc.line_space - 1; area_sel.x1 = ddlist->coords.x1; area_sel.x2 = ddlist->coords.x2; lv_area_t mask_sel; bool area_ok; area_ok = lv_area_intersect(&mask_sel, clip_area, &area_sel); if(area_ok) { - const lv_style_t * sel_style = lv_ddlist_get_style(ddlist, LV_DDLIST_STYLE_SEL); - lv_style_t new_style; - lv_style_copy(&new_style, style); - new_style.text.color = sel_style->text.color; - new_style.text.opa = sel_style->text.opa; - lv_txt_flag_t flag = lv_ddlist_get_txt_flag(ddlist); - lv_draw_label(&ext->label->coords, &mask_sel, &new_style, opa_scale, lv_label_get_text(ext->label), - flag, NULL, NULL, NULL, lv_obj_get_base_dir(ddlist)); + lv_draw_label(&ext->label->coords, &mask_sel, &label_dsc, lv_label_get_text(ext->label), NULL); } } @@ -641,34 +548,30 @@ static lv_design_res_t lv_ddlist_design(lv_obj_t * ddlist, const lv_area_t * cli else { /*Draw the symbol if enabled*/ if(ext->symbol) { - const lv_style_t * style = lv_ddlist_get_style(ddlist, LV_DDLIST_STYLE_BG); - const lv_font_t * font = style->text.font; - const lv_style_t * sel_style = lv_ddlist_get_style(ddlist, LV_DDLIST_STYLE_BG); - lv_coord_t font_h = lv_font_get_line_height(font); - lv_style_t new_style; - lv_style_copy(&new_style, style); - new_style.text.color = sel_style->text.color; - new_style.text.opa = sel_style->text.opa; + lv_draw_label_dsc_t label_dsc; + lv_draw_label_dsc_init(&label_dsc); + lv_obj_init_draw_label_dsc(ddlist, LV_DDLIST_PART_BG, &label_dsc); + lv_coord_t font_h = lv_font_get_line_height(label_dsc.font); lv_area_t area_icon; - lv_coord_t icon_width = lv_txt_get_width(ext->symbol, (uint16_t)strlen(ext->symbol), sel_style->text.font, 0, 0); + lv_coord_t icon_width = lv_txt_get_width(ext->symbol, (uint16_t)strlen(ext->symbol), label_dsc.font, 0, 0); + if(lv_label_get_align(ext->label) != LV_LABEL_ALIGN_RIGHT) { - area_icon.x2 = ddlist->coords.x2 - style->body.padding.right; + area_icon.x2 = ddlist->coords.x2 - lv_obj_get_style_value(ddlist, LV_DDLIST_PART_BG, LV_STYLE_PAD_RIGHT); area_icon.x1 = area_icon.x2 - icon_width; } else { - area_icon.x1 = ddlist->coords.x1 + style->body.padding.left; + area_icon.x1 = ddlist->coords.x1 + lv_obj_get_style_value(ddlist, LV_DDLIST_PART_BG, LV_STYLE_PAD_LEFT); area_icon.x2 = area_icon.x1 + icon_width; } - area_icon.y1 = ddlist->coords.y1 + style->text.line_space; + area_icon.y1 = ddlist->coords.y1 + label_dsc.line_space; area_icon.y2 = area_icon.y1 + font_h; lv_area_t mask_icon; bool area_ok; area_ok = lv_area_intersect(&mask_icon, clip_area, &area_icon); if(area_ok) { - lv_draw_label(&area_icon, &mask_icon, &new_style, opa_scale, ext->symbol, LV_TXT_FLAG_NONE, - NULL, NULL, NULL, lv_obj_get_base_dir(ddlist)); + lv_draw_label(&area_icon, &mask_icon, &label_dsc, ext->symbol, NULL); } } } @@ -689,6 +592,13 @@ static lv_design_res_t lv_ddlist_design(lv_obj_t * ddlist, const lv_area_t * cli static lv_res_t lv_ddlist_signal(lv_obj_t * ddlist, lv_signal_t sign, void * param) { lv_res_t res; + if(sign == LV_SIGNAL_GET_STYLE) { + uint8_t ** type_p = param; + lv_style_dsc_t ** style_dsc_p = param; + *style_dsc_p = lv_ddlist_get_style(ddlist, **type_p); + return LV_RES_OK; + } + /* Include the ancient signal function */ res = ancestor_signal(ddlist, sign, param); if(res != LV_RES_OK) return res; @@ -697,6 +607,7 @@ static lv_res_t lv_ddlist_signal(lv_obj_t * ddlist, lv_signal_t sign, void * par lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); if(sign == LV_SIGNAL_STYLE_CHG) { + lv_ddlist_refr_width(ddlist); lv_ddlist_refr_size(ddlist, 0); } else if(sign == LV_SIGNAL_BASE_DIR_CHG) { lv_label_align_t align = lv_label_get_align(ext->label); @@ -804,12 +715,12 @@ static lv_res_t lv_ddlist_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void * lv_obj_t * ddlist = lv_obj_get_parent(scrl); if(sign == LV_SIGNAL_REFR_EXT_DRAW_PAD) { - /*TODO review this*/ - /* Because of the wider selected rectangle ext. size - * In this way by dragging the scrollable part the wider rectangle area can be redrawn too*/ - const lv_style_t * style = lv_ddlist_get_style(ddlist, LV_DDLIST_STYLE_BG); - lv_coord_t hpad = LV_MATH_MAX(style->body.padding.left, style->body.padding.right); - if(scrl->ext_draw_pad < hpad) scrl->ext_draw_pad = hpad; + /* Make possible to draw on the full width of the background to redraw the selected rectangle + * when the ddlist is scrolled in fix height mode. + * (The scrollabel is scrolled the "select rectangle" is drawn on the bg too)*/ + lv_style_value_t left = lv_obj_get_style_value(ddlist, LV_DDLIST_PART_BG, LV_STYLE_PAD_LEFT); + lv_style_value_t right = lv_obj_get_style_value(ddlist, LV_DDLIST_PART_BG, LV_STYLE_PAD_RIGHT); + ddlist->ext_draw_pad = LV_MATH_MAX(ddlist->ext_draw_pad, LV_MATH_MAX(left, right)); } else if(sign == LV_SIGNAL_RELEASED) { if(lv_indev_is_dragging(lv_indev_get_act()) == false) { release_handler(ddlist); @@ -822,6 +733,39 @@ static lv_res_t lv_ddlist_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void * return res; } +/** + * Get the style descriptor of a part of the object + * @param page pointer the object + * @param part the part from `lv_ddlist_part_t`. (LV_DDLIST_PART_...) + * @return pointer to the style descriptor of the specified part + */ +static lv_style_dsc_t * lv_ddlist_get_style(lv_obj_t * ddlist, uint8_t part) +{ + LV_ASSERT_OBJ(ddlist, LV_OBJX_NAME); + + lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); + lv_style_dsc_t * style_dsc_p; + + switch(part) { + case LV_DDLIST_PART_BG: + style_dsc_p = &ddlist->style_dsc; + break; + case LV_DDLIST_PART_SCRL: + style_dsc_p = lv_obj_get_style(ext->page.scrl, LV_CONT_PART_MAIN); + break; + case LV_DDLIST_PART_SCRL_BAR: + style_dsc_p = &ext->page.sb.style; + break; + case LV_DDLIST_PART_SEL: + style_dsc_p = &ext->style_sel; + break; + default: + style_dsc_p = NULL; + } + + return style_dsc_p; +} + /** * Called when a drop down list is released to open it or set new option * @param ddlist pointer to a drop down list object @@ -904,14 +848,14 @@ static void lv_ddlist_refr_size(lv_obj_t * ddlist, lv_anim_enable_t anim) anim = false; #endif lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); - const lv_style_t * style = lv_obj_get_style(ddlist); lv_coord_t new_height; /*Open the list*/ if(ext->opened) { if(ext->fix_height == 0) { - new_height = - lv_obj_get_height(lv_page_get_scrl(ddlist)) + style->body.padding.top + style->body.padding.bottom; + lv_style_value_t top = lv_obj_get_style_value(ddlist, LV_DDLIST_PART_BG, LV_STYLE_PAD_TOP); + lv_style_value_t bottom = lv_obj_get_style_value(ddlist, LV_DDLIST_PART_BG, LV_STYLE_PAD_BOTTOM); + new_height = lv_obj_get_height(lv_page_get_scrl(ddlist)) + top + bottom; } else { new_height = ext->fix_height; } @@ -919,10 +863,9 @@ static void lv_ddlist_refr_size(lv_obj_t * ddlist, lv_anim_enable_t anim) } /*Close the list*/ else { - const lv_font_t * font = style->text.font; - const lv_style_t * label_style = lv_obj_get_style(ext->label); + const lv_font_t * font = lv_obj_get_style_ptr(ddlist, LV_DDLIST_PART_BG, LV_STYLE_FONT); lv_coord_t font_h = lv_font_get_line_height(font); - new_height = font_h + 2 * label_style->text.line_space; + new_height = font_h + 2 * lv_obj_get_style_value(ddlist, LV_DDLIST_PART_BG, LV_STYLE_LINE_SPACE); lv_page_set_sb_mode(ddlist, LV_SB_MODE_HIDE); } @@ -1006,15 +949,14 @@ static void lv_ddlist_adjust_height(lv_obj_t * ddlist, lv_anim_value_t height) static void lv_ddlist_pos_current_option(lv_obj_t * ddlist) { lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); - const lv_style_t * style = lv_obj_get_style(ddlist); - const lv_font_t * font = style->text.font; + const lv_font_t * font = lv_obj_get_style_ptr(ddlist, LV_DDLIST_PART_BG, LV_STYLE_FONT); lv_coord_t font_h = lv_font_get_line_height(font); - const lv_style_t * label_style = lv_obj_get_style(ext->label); lv_obj_t * scrl = lv_page_get_scrl(ddlist); lv_coord_t h = lv_obj_get_height(ddlist); + lv_style_value_t line_space = lv_obj_get_style_value(ddlist, LV_DDLIST_PART_BG, LV_STYLE_LINE_SPACE); lv_coord_t line_y1 = - ext->sel_opt_id * (font_h + label_style->text.line_space) + ext->label->coords.y1 - scrl->coords.y1; + ext->sel_opt_id * (font_h + line_space) + ext->label->coords.y1 - scrl->coords.y1; lv_obj_set_y(scrl, -line_y1 + (h - font_h) / 2); lv_obj_invalidate(ddlist); diff --git a/src/lv_objx/lv_ddlist.h b/src/lv_objx/lv_ddlist.h index 43c802ccf..7c33acedf 100644 --- a/src/lv_objx/lv_ddlist.h +++ b/src/lv_objx/lv_ddlist.h @@ -43,23 +43,24 @@ typedef struct lv_page_ext_t page; /*Ext. of ancestor*/ /*New data for this type */ lv_obj_t * label; /*Label for the options*/ - const lv_style_t * sel_style; /*Style of the selected option*/ + lv_style_dsc_t style_sel; /*Style of the selected option*/ const char * symbol; /*Arrow or other icon when the drop-down list is closed*/ uint16_t option_cnt; /*Number of options*/ uint16_t sel_opt_id; /*Index of the current option*/ uint16_t sel_opt_id_ori; /*Store the original index on focus*/ + lv_coord_t fix_height; /*Height of the ddlist when opened. (0: auto-size)*/ uint8_t opened : 1; /*1: The list is opened (handled by the library)*/ uint8_t force_sel : 1; /*1: Keep the selection highlight even if the list is closed*/ uint8_t stay_open : 1; /*1: Don't close the list when a new item is selected*/ - lv_coord_t fix_height; /*Height of the ddlist when opened. (0: auto-size)*/ } lv_ddlist_ext_t; enum { - LV_DDLIST_STYLE_BG, - LV_DDLIST_STYLE_SEL, - LV_DDLIST_STYLE_SB, + LV_DDLIST_PART_BG, + LV_DDLIST_PART_SCRL, + LV_DDLIST_PART_SCRL_BAR, + LV_DDLIST_PART_SEL, }; -typedef uint8_t lv_ddlist_style_t; +typedef uint8_t lv_ddlist_part_t; /********************** * GLOBAL PROTOTYPES @@ -139,14 +140,6 @@ static inline void lv_ddlist_set_anim_time(lv_obj_t * ddlist, uint16_t anim_time lv_page_set_anim_time(ddlist, anim_time); } -/** - * Set a style of a drop down list - * @param ddlist pointer to a drop down list object - * @param type which style should be set - * @param style pointer to a style - * */ -void lv_ddlist_set_style(lv_obj_t * ddlist, lv_ddlist_style_t type, const lv_style_t * style); - /** * Set the alignment of the labels in a drop down list * @param ddlist pointer to a drop down list object @@ -227,14 +220,6 @@ static inline uint16_t lv_ddlist_get_anim_time(const lv_obj_t * ddlist) return lv_page_get_anim_time(ddlist); } -/** - * Get a style of a drop down list - * @param ddlist pointer to a drop down list object - * @param type which style should be get - * @return style pointer to a style - */ -const lv_style_t * lv_ddlist_get_style(const lv_obj_t * ddlist, lv_ddlist_style_t type); - /** * Get the alignment of the labels in a drop down list * @param ddlist pointer to a drop down list object diff --git a/src/lv_objx/lv_img.c b/src/lv_objx/lv_img.c index 87c996fa6..d3ac0c883 100644 --- a/src/lv_objx/lv_img.c +++ b/src/lv_objx/lv_img.c @@ -499,7 +499,7 @@ static lv_design_res_t lv_img_design(lv_obj_t * img, const lv_area_t * clip_area if(ext->src_type == LV_IMG_SRC_UNKNOWN || ext->src_type == LV_IMG_SRC_SYMBOL || ext->angle != 0) return LV_DESIGN_RES_NOT_COVER; if(ext->cf == LV_IMG_CF_TRUE_COLOR || ext->cf == LV_IMG_CF_RAW) { - cover = lv_area_is_in(clip_area, &img->coords) ? LV_DESIGN_RES_COVER : LV_DESIGN_RES_NOT_COVER; + cover = lv_area_is_in(clip_area, &img->coords, 0) ? LV_DESIGN_RES_COVER : LV_DESIGN_RES_NOT_COVER; } return cover; diff --git a/src/lv_objx/lv_page.c b/src/lv_objx/lv_page.c index 4aaf38ff0..342911373 100644 --- a/src/lv_objx/lv_page.c +++ b/src/lv_objx/lv_page.c @@ -46,7 +46,7 @@ static void lv_page_sb_refresh(lv_obj_t * page); static lv_design_res_t lv_page_design(lv_obj_t * page, const lv_area_t * clip_area, lv_design_mode_t mode); static lv_res_t lv_page_signal(lv_obj_t * page, lv_signal_t sign, void * param); -static lv_style_dsc_t * lv_page_get_style(lv_obj_t * page, uint8_t type); +static lv_style_dsc_t * lv_page_get_style(lv_obj_t * page, uint8_t part); static lv_res_t lv_page_scrollable_signal(lv_obj_t * scrl, lv_signal_t sign, void * param); static void scrl_def_event_cb(lv_obj_t * scrl, lv_event_t event); #if LV_USE_ANIMATION @@ -652,7 +652,7 @@ static lv_design_res_t lv_page_design(lv_obj_t * page, const lv_area_t * clip_ar lv_draw_rect(&page->coords, clip_area, &draw_dsc); - if(lv_obj_get_style_value(page, LV_PAGE_PART_BG, LV_STYLE_BG_CLIP_CORNER)) { + if(lv_obj_get_style_value(page, LV_PAGE_PART_BG, LV_STYLE_CLIP_CORNER)) { lv_draw_mask_radius_param_t * mp = lv_mem_buf_get(sizeof(lv_draw_mask_radius_param_t)); lv_coord_t r = lv_obj_get_style_value(page, LV_PAGE_PART_BG, LV_STYLE_RADIUS); @@ -738,7 +738,7 @@ static lv_design_res_t lv_page_design(lv_obj_t * page, const lv_area_t * clip_ar } #endif - if(lv_obj_get_style_value(page, LV_PAGE_PART_BG, LV_STYLE_BG_CLIP_CORNER)) { + if(lv_obj_get_style_value(page, LV_PAGE_PART_BG, LV_STYLE_CLIP_CORNER)) { void * param = lv_draw_mask_remove_custom(page + 8); lv_mem_buf_release(param); } @@ -1065,14 +1065,20 @@ static void scrl_def_event_cb(lv_obj_t * scrl, lv_event_t event) } -static lv_style_dsc_t * lv_page_get_style(lv_obj_t * page, uint8_t type) +/** + * Get the style descriptor of a part of the object + * @param page pointer the object + * @param part the part from `lv_page_part_t`. (LV_PAGE_PART_...) + * @return pointer to the style descriptor of the specified part + */ +static lv_style_dsc_t * lv_page_get_style(lv_obj_t * page, uint8_t part) { LV_ASSERT_OBJ(page, LV_OBJX_NAME); lv_page_ext_t * ext = lv_obj_get_ext_attr(page); lv_style_dsc_t * style_dsc_p; - switch(type) { + switch(part) { case LV_PAGE_PART_BG: style_dsc_p = &page->style_dsc; break; @@ -1175,7 +1181,7 @@ static void lv_page_sb_refresh(lv_obj_t * page) lv_area_set_pos(&ext->sb.hor_area, sb_hor_pad + (-(lv_obj_get_x(scrl) -bg_left) * (obj_w - size_tmp - 2 * sb_hor_pad)) / - (scrl_w + bg_left + sb_right - obj_w), + (scrl_w + bg_left + bg_right - obj_w), obj_h - sb_width - sb_bottom); if(ext->sb.mode == LV_SB_MODE_AUTO || ext->sb.mode == LV_SB_MODE_DRAG) ext->sb.hor_draw = 1; diff --git a/src/lv_objx/lv_roller.c b/src/lv_objx/lv_roller.c index 6408012ac..7615af011 100644 --- a/src/lv_objx/lv_roller.c +++ b/src/lv_objx/lv_roller.c @@ -33,6 +33,7 @@ **********************/ static lv_design_res_t lv_roller_design(lv_obj_t * roller, const lv_area_t * clip_area, lv_design_mode_t mode); static lv_res_t lv_roller_scrl_signal(lv_obj_t * roller_scrl, lv_signal_t sign, void * param); +static lv_style_dsc_t * lv_roller_get_style(lv_obj_t * roller, uint8_t part); static lv_res_t lv_roller_signal(lv_obj_t * roller, lv_signal_t sign, void * param); static void refr_position(lv_obj_t * roller, lv_anim_enable_t animen); static void refr_height(lv_obj_t * roller); @@ -102,15 +103,7 @@ lv_obj_t * lv_roller_create(lv_obj_t * par, const lv_obj_t * copy) lv_obj_set_signal_cb(scrl, lv_roller_scrl_signal); - /*Set the default styles*/ - lv_theme_t * th = lv_theme_get_current(); - if(th) { - lv_roller_set_style(new_roller, LV_ROLLER_STYLE_BG, th->style.roller.bg); - lv_roller_set_style(new_roller, LV_ROLLER_STYLE_SEL, th->style.roller.sel); - } else { - /*Refresh the roller's style*/ - lv_obj_refresh_style(new_roller); /*To set scrollable size automatically*/ - } + } /*Copy an existing roller*/ else { @@ -120,9 +113,6 @@ lv_obj_t * lv_roller_create(lv_obj_t * par, const lv_obj_t * copy) lv_obj_t * scrl = lv_page_get_scrl(new_roller); lv_ddlist_open(new_roller, false); lv_obj_set_signal_cb(scrl, lv_roller_scrl_signal); - - /*Refresh the roller's style*/ - lv_obj_refresh_style(new_roller); /*Refresh the style with new signal function*/ } LV_LOG_INFO("roller created"); @@ -232,27 +222,10 @@ void lv_roller_set_visible_row_count(lv_obj_t * roller, uint8_t row_cnt) { LV_ASSERT_OBJ(roller, LV_OBJX_NAME); - lv_roller_ext_t * ext = lv_obj_get_ext_attr(roller); - const lv_style_t * style_label = lv_obj_get_style(ext->ddlist.label); uint8_t n_line_space = (row_cnt > 1) ? row_cnt - 1 : 1; - lv_ddlist_set_fix_height(roller, lv_font_get_line_height(style_label->text.font) * row_cnt + - style_label->text.line_space * n_line_space); -} - -/** - * Set a style of a roller - * @param roller pointer to a roller object - * @param type which style should be set - * @param style pointer to a style - */ -void lv_roller_set_style(lv_obj_t * roller, lv_roller_style_t type, const lv_style_t * style) -{ - LV_ASSERT_OBJ(roller, LV_OBJX_NAME); - - switch(type) { - case LV_ROLLER_STYLE_BG: lv_obj_set_style(roller, style); break; - case LV_ROLLER_STYLE_SEL: lv_ddlist_set_style(roller, LV_DDLIST_STYLE_SEL, style); break; - } + const lv_font_t * font = lv_obj_get_style_ptr(roller, LV_ROLLER_PART_BG, LV_STYLE_FONT); + lv_style_value_t line_space = lv_obj_get_style_value(roller, LV_ROLLER_PART_BG, LV_STYLE_LINE_SPACE); + lv_ddlist_set_fix_height(roller, lv_font_get_line_height(font) * row_cnt + line_space * n_line_space); } /*===================== @@ -322,31 +295,6 @@ bool lv_roller_get_hor_fit(const lv_obj_t * roller) return lv_page_get_scrl_fit_left(roller); } -/** - * Get a style of a roller - * @param roller pointer to a roller object - * @param type which style should be get - * @return style pointer to a style - * */ -const lv_style_t * lv_roller_get_style(const lv_obj_t * roller, lv_roller_style_t type) -{ - LV_ASSERT_OBJ(roller, LV_OBJX_NAME); - - const lv_style_t * style; - switch(type) { - case LV_ROLLER_STYLE_BG: - style = lv_obj_get_style(roller); - break; - case LV_ROLLER_STYLE_SEL: - style = lv_ddlist_get_style(roller, LV_DDLIST_STYLE_SEL); - break; - default: - style = NULL; - } - - return style; -} - /********************** * STATIC FUNCTIONS **********************/ @@ -371,15 +319,13 @@ static lv_design_res_t lv_roller_design(lv_obj_t * roller, const lv_area_t * cli else if(mode == LV_DESIGN_DRAW_MAIN) { draw_bg(roller, clip_area); - const lv_style_t * style = lv_roller_get_style(roller, LV_ROLLER_STYLE_BG); - lv_opa_t opa_scale = lv_obj_get_opa_scale(roller); - const lv_font_t * font = style->text.font; - lv_roller_ext_t * ext = lv_obj_get_ext_attr(roller); + const lv_font_t * font = lv_obj_get_style_ptr(roller, LV_ROLLER_PART_BG, LV_STYLE_FONT); + lv_style_value_t line_space = lv_obj_get_style_value(roller, LV_ROLLER_PART_BG, LV_STYLE_LINE_SPACE); 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 - style->text.line_space / 2; - if((font_h & 0x1) && (style->text.line_space & 0x1)) rect_area.y1--; /*Compensate the two rounding error*/ - rect_area.y2 = rect_area.y1 + font_h + style->text.line_space - 1; + rect_area.y1 = roller->coords.y1 + lv_obj_get_height(roller) / 2 - font_h / 2 - line_space / 2; + if((font_h & 0x1) && (line_space & 0x1)) rect_area.y1--; /*Compensate the two rounding error*/ + rect_area.y2 = rect_area.y1 + font_h + line_space - 1; lv_area_t roller_coords; lv_obj_get_coords(roller, &roller_coords); lv_obj_get_inner_coords(roller, &roller_coords); @@ -387,46 +333,40 @@ static lv_design_res_t lv_roller_design(lv_obj_t * roller, const lv_area_t * cli rect_area.x1 = roller_coords.x1; rect_area.x2 = roller_coords.x2; - lv_draw_rect(&rect_area, clip_area, ext->ddlist.sel_style, opa_scale); + lv_draw_rect_dsc_t sel_dsc; + lv_draw_rect_dsc_init(&sel_dsc); + lv_obj_init_draw_rect_dsc(roller, LV_ROLLER_PART_SEL, &sel_dsc); + lv_draw_rect(&rect_area, clip_area, &sel_dsc); } /*Post draw when the children are drawn*/ else if(mode == LV_DESIGN_DRAW_POST) { - const lv_style_t * style = lv_roller_get_style(roller, LV_ROLLER_STYLE_BG); + lv_draw_label_dsc_t label_dsc; + lv_draw_label_dsc_init(&label_dsc); + lv_obj_init_draw_label_dsc(roller, LV_ROLLER_PART_SEL, &label_dsc); + lv_roller_ext_t * ext = lv_obj_get_ext_attr(roller); - const lv_font_t * font = style->text.font; - lv_coord_t font_h = lv_font_get_line_height(font); - lv_opa_t opa_scale = lv_obj_get_opa_scale(roller); + lv_coord_t font_h = lv_font_get_line_height(label_dsc.font); /*Redraw the text on the selected area with a different color*/ lv_area_t rect_area; - rect_area.y1 = roller->coords.y1 + lv_obj_get_height(roller) / 2 - font_h / 2 - style->text.line_space / 2; - if((font_h & 0x1) && (style->text.line_space & 0x1)) rect_area.y1--; /*Compensate the two rounding error*/ - rect_area.y2 = rect_area.y1 + font_h + style->text.line_space - 1; + rect_area.y1 = roller->coords.y1 + lv_obj_get_height(roller) / 2 - font_h / 2 - label_dsc.line_space / 2; + if((font_h & 0x1) && (label_dsc.line_space & 0x1)) rect_area.y1--; /*Compensate the two rounding error*/ + rect_area.y2 = rect_area.y1 + font_h + label_dsc.line_space - 1; rect_area.x1 = roller->coords.x1; rect_area.x2 = roller->coords.x2; lv_area_t mask_sel; bool area_ok; area_ok = lv_area_intersect(&mask_sel, clip_area, &rect_area); if(area_ok) { - const lv_style_t * sel_style = lv_roller_get_style(roller, LV_ROLLER_STYLE_SEL); - lv_style_t new_style; - lv_txt_flag_t txt_align = LV_TXT_FLAG_NONE; + lv_label_align_t label_align = lv_label_get_align(ext->ddlist.label); - { - lv_label_align_t label_align = lv_label_get_align(ext->ddlist.label); - - if(LV_LABEL_ALIGN_CENTER == label_align) { - txt_align |= LV_TXT_FLAG_CENTER; - } else if(LV_LABEL_ALIGN_RIGHT == label_align) { - txt_align |= LV_TXT_FLAG_RIGHT; - } + if(LV_LABEL_ALIGN_CENTER == label_align) { + label_dsc.flag |= LV_TXT_FLAG_CENTER; + } else if(LV_LABEL_ALIGN_RIGHT == label_align) { + label_dsc.flag |= LV_TXT_FLAG_RIGHT; } - lv_style_copy(&new_style, style); - new_style.text.color = sel_style->text.color; - new_style.text.opa = sel_style->text.opa; - lv_draw_label(&ext->ddlist.label->coords, &mask_sel, &new_style, opa_scale, - lv_label_get_text(ext->ddlist.label), txt_align, NULL, NULL, NULL, lv_obj_get_base_dir(ext->ddlist.label)); + lv_draw_label(&ext->ddlist.label->coords, &mask_sel, &label_dsc, lv_label_get_text(ext->ddlist.label), NULL); } } @@ -442,7 +382,13 @@ static lv_design_res_t lv_roller_design(lv_obj_t * roller, const lv_area_t * cli */ static lv_res_t lv_roller_signal(lv_obj_t * roller, lv_signal_t sign, void * param) { - lv_res_t res = LV_RES_OK; + lv_res_t res; + if(sign == LV_SIGNAL_GET_STYLE) { + uint8_t ** type_p = param; + lv_style_dsc_t ** style_dsc_p = param; + *style_dsc_p = lv_roller_get_style(roller, **type_p); + return LV_RES_OK; + } /*Don't let the drop down list to handle the control signals. It works differently*/ if(sign != LV_SIGNAL_CONTROL && sign != LV_SIGNAL_FOCUS && sign != LV_SIGNAL_DEFOCUS) { @@ -450,6 +396,7 @@ static lv_res_t lv_roller_signal(lv_obj_t * roller, lv_signal_t sign, void * par res = ancestor_signal(roller, sign, param); if(res != LV_RES_OK) return res; } + if(sign == LV_SIGNAL_GET_TYPE) return lv_obj_handle_get_type_signal(param, LV_OBJX_NAME); lv_roller_ext_t * ext = lv_obj_get_ext_attr(roller); @@ -522,6 +469,36 @@ static lv_res_t lv_roller_signal(lv_obj_t * roller, lv_signal_t sign, void * par return res; } +/** + * Get the style descriptor of a part of the object + * @param page pointer the object + * @param part the part from `lv_roller_part_t`. (LV_ROLLER_PART_...) + * @return pointer to the style descriptor of the specified part + */ +static lv_style_dsc_t * lv_roller_get_style(lv_obj_t * roller, uint8_t part) +{ + LV_ASSERT_OBJ(roller, LV_OBJX_NAME); + + lv_roller_ext_t * ext = lv_obj_get_ext_attr(roller); + lv_style_dsc_t * style_dsc_p; + + switch(part) { + case LV_ROLLER_PART_BG: + style_dsc_p = &roller->style_dsc; + break; + case LV_ROLLER_PART_SCRL: + style_dsc_p = lv_obj_get_style(ext->ddlist.page.scrl, LV_CONT_PART_MAIN); + break; + case LV_ROLLER_PART_SEL: + style_dsc_p = &ext->ddlist.style_sel; + break; + default: + style_dsc_p = NULL; + } + + return style_dsc_p; +} + /** * Signal function of the scrollable part of the roller. * @param roller_scrl ointer to the scrollable part of roller (page) @@ -547,17 +524,17 @@ static lv_res_t lv_roller_scrl_signal(lv_obj_t * roller_scrl, lv_signal_t sign, return LV_RES_INV; /*On delete the ddlist signal deletes the label so nothing left to do here*/ - const lv_style_t * style_label = lv_obj_get_style(ext->ddlist.label); - const lv_font_t * font = style_label->text.font; + const lv_font_t * font = lv_obj_get_style_ptr(roller, LV_ROLLER_PART_BG, LV_STYLE_FONT); + lv_style_value_t line_space = lv_obj_get_style_value(roller, LV_ROLLER_PART_BG, LV_STYLE_LINE_SPACE); lv_coord_t font_h = lv_font_get_line_height(font); if(sign == LV_SIGNAL_DRAG_END) { /*If dragged then align the list to have an element in the middle*/ lv_coord_t label_y1 = ext->ddlist.label->coords.y1 - roller->coords.y1; - lv_coord_t label_unit = font_h + style_label->text.line_space; + lv_coord_t label_unit = font_h + line_space; lv_coord_t mid = (roller->coords.y2 - roller->coords.y1) / 2; - id = (mid - label_y1 + style_label->text.line_space / 2) / label_unit; + id = (mid - label_y1 + line_space / 2) / label_unit; if(id < 0) id = 0; if(id >= ext->ddlist.option_cnt) id = ext->ddlist.option_cnt - 1; @@ -599,48 +576,43 @@ static lv_res_t lv_roller_scrl_signal(lv_obj_t * roller_scrl, lv_signal_t sign, */ static void draw_bg(lv_obj_t * roller, const lv_area_t * mask) { - const lv_style_t * style = lv_roller_get_style(roller, LV_ROLLER_STYLE_BG); + lv_draw_rect_dsc_t bg_dsc; + lv_draw_rect_dsc_init(&bg_dsc); + lv_obj_init_draw_rect_dsc(roller, LV_ROLLER_PART_BG, &bg_dsc); + lv_area_t half_mask; - lv_area_t half_roller; lv_coord_t h = lv_obj_get_height(roller); bool union_ok; - lv_area_copy(&half_roller, &roller->coords); - half_roller.x1 -= roller->ext_draw_pad; /*Add ext size too (e.g. because of shadow draw) */ - half_roller.x2 += roller->ext_draw_pad; - half_roller.y1 -= roller->ext_draw_pad; - half_roller.y2 = roller->coords.y1 + h / 2; - - union_ok = lv_area_intersect(&half_mask, &half_roller, mask); - - half_roller.x1 += roller->ext_draw_pad; /*Revert ext. size adding*/ - half_roller.x2 -= roller->ext_draw_pad; - half_roller.y1 += roller->ext_draw_pad; - half_roller.y2 += style->body.radius; + lv_area_copy(&half_mask, &roller->coords); + half_mask.x1 -= roller->ext_draw_pad; /*Add ext size too (e.g. because of shadow draw) */ + half_mask.x2 += roller->ext_draw_pad; + half_mask.y1 -= roller->ext_draw_pad; + half_mask.y2 = roller->coords.y1 + h / 2; + union_ok = lv_area_intersect(&half_mask, &half_mask, mask); + bg_dsc.bg_main_color_stop = bg_dsc.bg_main_color_stop / 2; + bg_dsc.bg_grad_color_stop = 128 - (255 - bg_dsc.bg_grad_color_stop) / 2; if(union_ok) { - lv_draw_rect(&half_roller, &half_mask, style, lv_obj_get_opa_scale(roller)); + lv_draw_rect(&roller->coords, &half_mask, &bg_dsc); } - half_roller.x1 -= roller->ext_draw_pad; /*Add ext size too (e.g. because of shadow draw) */ - half_roller.x2 += roller->ext_draw_pad; - half_roller.y2 = roller->coords.y2 + roller->ext_draw_pad; - half_roller.y1 = roller->coords.y1 + h / 2; - if((h & 0x1) == 0) half_roller.y1++; /*With even height the pixels in the middle would be drawn twice*/ + lv_area_copy(&half_mask, &roller->coords); + half_mask.x1 -= roller->ext_draw_pad; /*Revert ext. size adding*/ + half_mask.x2 += roller->ext_draw_pad; + half_mask.y1 = roller->coords.y1 + h / 2; + half_mask.y2 += roller->ext_draw_pad; - union_ok = lv_area_intersect(&half_mask, &half_roller, mask); - - half_roller.x1 += roller->ext_draw_pad; /*Revert ext. size adding*/ - half_roller.x2 -= roller->ext_draw_pad; - half_roller.y2 -= roller->ext_draw_pad; - half_roller.y1 -= style->body.radius; + union_ok = lv_area_intersect(&half_mask, &half_mask, mask); if(union_ok) { - lv_style_t style_tmp; - memcpy(&style_tmp, style, sizeof(lv_style_t)); - style_tmp.body.main_color = style->body.grad_color; - style_tmp.body.grad_color = style->body.main_color; - lv_draw_rect(&half_roller, &half_mask, &style_tmp, lv_obj_get_opa_scale(roller)); + lv_color_t c = bg_dsc.bg_color; + bg_dsc.bg_color = bg_dsc.bg_grad_color; + bg_dsc.bg_grad_color = c; + + bg_dsc.bg_main_color_stop += 127; + bg_dsc.bg_grad_color_stop += 127; + lv_draw_rect(&roller->coords, &half_mask, &bg_dsc); } } @@ -657,8 +629,8 @@ 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_style_t * style_label = lv_obj_get_style(ext->ddlist.label); - const lv_font_t * font = style_label->text.font; + const lv_font_t * font = lv_obj_get_style_ptr(roller, LV_ROLLER_PART_BG, LV_STYLE_FONT); + lv_style_value_t line_space = lv_obj_get_style_value(roller, LV_ROLLER_PART_BG, LV_STYLE_LINE_SPACE); 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); @@ -671,7 +643,7 @@ static void refr_position(lv_obj_t * roller, lv_anim_enable_t anim_en) int32_t id = ext->ddlist.sel_opt_id; lv_coord_t line_y1 = - id * (font_h + style_label->text.line_space) + ext->ddlist.label->coords.y1 - roller_scrl->coords.y1; + id * (font_h + line_space) + ext->ddlist.label->coords.y1 - roller_scrl->coords.y1; lv_coord_t new_y = -line_y1 + (h - font_h) / 2; if(anim_en == LV_ANIM_OFF || anim_time == 0) { @@ -738,12 +710,12 @@ static void inf_normalize(void * scrl) ext->ddlist.sel_opt_id += (LV_ROLLER_INF_PAGES / 2) * real_id_cnt; /*Select the middle page*/ /*Move to the new id*/ - const lv_style_t * style_label = lv_obj_get_style(ext->ddlist.label); - const lv_font_t * font = style_label->text.font; + const lv_font_t * font = lv_obj_get_style_ptr(roller, LV_ROLLER_PART_BG, LV_STYLE_FONT); + lv_style_value_t line_space = lv_obj_get_style_value(roller, LV_ROLLER_PART_BG, LV_STYLE_LINE_SPACE); lv_coord_t font_h = lv_font_get_line_height(font); lv_coord_t h = lv_obj_get_height(roller); - lv_coord_t line_y1 = ext->ddlist.sel_opt_id * (font_h + style_label->text.line_space) + + lv_coord_t line_y1 = ext->ddlist.sel_opt_id * (font_h + line_space) + ext->ddlist.label->coords.y1 - roller_scrl->coords.y1; lv_coord_t new_y = -line_y1 + (h - font_h) / 2; lv_obj_set_y(roller_scrl, new_y); diff --git a/src/lv_objx/lv_roller.h b/src/lv_objx/lv_roller.h index 2d25ab520..cbd08258a 100644 --- a/src/lv_objx/lv_roller.h +++ b/src/lv_objx/lv_roller.h @@ -53,10 +53,11 @@ typedef struct } lv_roller_ext_t; enum { - LV_ROLLER_STYLE_BG, - LV_ROLLER_STYLE_SEL, + LV_ROLLER_PART_BG, + LV_ROLLER_PART_SCRL, + LV_ROLLER_PART_SEL, }; -typedef uint8_t lv_roller_style_t; +typedef uint8_t lv_roller_part_t; /********************** * GLOBAL PROTOTYPES @@ -124,14 +125,6 @@ static inline void lv_roller_set_anim_time(lv_obj_t * roller, uint16_t anim_time lv_ddlist_set_anim_time(roller, anim_time); } -/** - * Set a style of a roller - * @param roller pointer to a roller object - * @param type which style should be set - * @param style pointer to a style - */ -void lv_roller_set_style(lv_obj_t * roller, lv_roller_style_t type, const lv_style_t * style); - /*===================== * Getter functions *====================*/ @@ -194,14 +187,6 @@ static inline uint16_t lv_roller_get_anim_time(const lv_obj_t * roller) */ bool lv_roller_get_hor_fit(const lv_obj_t * roller); -/** - * Get a style of a roller - * @param roller pointer to a roller object - * @param type which style should be get - * @return style pointer to a style - * */ -const lv_style_t * lv_roller_get_style(const lv_obj_t * roller, lv_roller_style_t type); - /********************** * MACROS **********************/ diff --git a/src/lv_objx/lv_slider.c b/src/lv_objx/lv_slider.c index 51cb80e57..1ea779967 100644 --- a/src/lv_objx/lv_slider.c +++ b/src/lv_objx/lv_slider.c @@ -80,7 +80,6 @@ lv_obj_t * lv_slider_create(lv_obj_t * par, const lv_obj_t * copy) lv_style_dsc_init(&ext->style_knob); ext->value_to_set = NULL; ext->dragging = false; - ext->img_knob = NULL; /*The signal and design functions are not copied so set them here*/ lv_obj_set_signal_cb(new_slider, lv_slider_signal); @@ -107,23 +106,6 @@ lv_obj_t * lv_slider_create(lv_obj_t * par, const lv_obj_t * copy) * Setter functions *====================*/ -/** - * Set an image to display on the knob of the slider - * @param slider pointer to a slider object - * @param img_src pointer to an `lv_img_dsc_t` variable or a path to an image - * (not an `lv_img` object) - */ -void lv_slider_set_knob_img(lv_obj_t * slider, const void * img_src) -{ - LV_ASSERT_OBJ(slider, LV_OBJX_NAME); - - lv_slider_ext_t * ext = lv_obj_get_ext_attr(slider); - - ext->img_knob = img_src; - lv_obj_refresh_ext_draw_pad(slider); - lv_obj_invalidate(slider); -} - /*===================== * Getter functions *====================*/ @@ -152,20 +134,6 @@ bool lv_slider_is_dragged(const lv_obj_t * slider) return ext->dragging ? true : false; } -/** - * Get an image to display on the knob of the slider - * @param slider pointer to a slider object - * @return the image source: pointer to an `lv_img_dsc_t` variable or a path to an image (not an `lv_img` object) - */ -const void * lv_slider_get_knob_img(lv_obj_t * slider, const void * img_src) -{ - LV_ASSERT_OBJ(slider, LV_OBJX_NAME); - - lv_slider_ext_t * ext = lv_obj_get_ext_attr(slider); - - return ext->img_knob; -} - /********************** * STATIC FUNCTIONS **********************/ @@ -385,18 +353,6 @@ static lv_res_t lv_slider_signal(lv_obj_t * slider, lv_signal_t sign, void * par knob_size += knob_sh_width + knob_sh_spread; knob_size += LV_MATH_MAX(LV_MATH_ABS(knob_sh_ox), LV_MATH_ABS(knob_sh_oy)); - if(ext->img_knob) { - lv_img_header_t info; - lv_res_t res; - res = lv_img_decoder_get_info(ext->img_knob, &info); - if(res == LV_RES_OK) { - knob_size = LV_MATH_MAX(knob_size, info.w / 2); - knob_size = LV_MATH_MAX(knob_size, info.h / 2); - } else { - LV_LOG_WARN("slider signal (LV_SIGNAL_REFR_EXT_DRAW_PAD): can't get knob image info") - } - } - lv_style_value_t bg_sh_width = lv_obj_get_style_value(slider, LV_SLIDER_PART_BG, LV_STYLE_SHADOW_WIDTH); lv_style_value_t bg_sh_spread = lv_obj_get_style_value(slider, LV_SLIDER_PART_BG, LV_STYLE_SHADOW_SPREAD); lv_style_value_t bg_sh_ox = lv_obj_get_style_value(slider, LV_SLIDER_PART_BG, LV_STYLE_SHADOW_OFFSET_X); @@ -498,27 +454,5 @@ static void lv_slider_draw_knob(lv_obj_t * slider, const lv_area_t * knob_area, lv_obj_init_draw_rect_dsc(slider, LV_SLIDER_PART_KNOB, &knob_rect_dsc); lv_draw_rect(knob_area, clip_area, &knob_rect_dsc); - - if(ext->img_knob) { - lv_res_t res; - lv_img_header_t info; - res = lv_img_decoder_get_info(ext->img_knob, &info); - if(res == LV_RES_OK) { - lv_coord_t x_ofs = knob_area->x1 + (lv_area_get_width(knob_area) - info.w) / 2; - lv_coord_t y_ofs = knob_area->y1 + (lv_area_get_height(knob_area) - info.h) / 2; - lv_area_t a; - a.x1 = x_ofs; - a.y1 = y_ofs; - a.x2 = info.w - 1 + x_ofs; - a.y2 = info.h - 1 + y_ofs; - - lv_draw_img_dsc_t knob_img_dsc; - lv_draw_img_dsc_init(&knob_img_dsc); - lv_obj_init_draw_img_dsc(slider, LV_SLIDER_PART_KNOB, &knob_img_dsc); - lv_draw_img(&a, clip_area, ext->img_knob, &knob_img_dsc); - } else { - LV_LOG_WARN("lv_slider_design: can't get knob image info") - } - } } #endif diff --git a/src/lv_objx/lv_slider.h b/src/lv_objx/lv_slider.h index 4edb350e8..ac68f79b3 100644 --- a/src/lv_objx/lv_slider.h +++ b/src/lv_objx/lv_slider.h @@ -48,7 +48,6 @@ typedef struct lv_area_t left_knob_area; lv_area_t right_knob_area; int16_t *value_to_set; /* Which bar value to set */ - const void * img_knob; uint8_t dragging :1; /*1: the slider is being dragged*/ } lv_slider_ext_t; @@ -120,14 +119,6 @@ static inline void lv_slider_set_anim_time(lv_obj_t * slider, uint16_t anim_time lv_bar_set_anim_time(slider, anim_time); } -/** - * Set an image to display on the knob of the slider - * @param slider pointer to a slider object - * @param img_src pointer to an `lv_img_dsc_t` variable or a path to an image - * (not an `lv_img` object) - */ -void lv_slider_set_knob_img(lv_obj_t * slider, const void * img_src); - /** * Set the animation time of the slider * @param slider pointer to a bar object diff --git a/src/lv_objx/lv_sw.c b/src/lv_objx/lv_sw.c index d67766bc1..c1aca477d 100644 --- a/src/lv_objx/lv_sw.c +++ b/src/lv_objx/lv_sw.c @@ -210,14 +210,6 @@ static lv_res_t lv_sw_signal(lv_obj_t * sw, lv_signal_t sign, void * param) if(sign == LV_SIGNAL_CLEANUP) { /*Nothing to cleanup. (No dynamically allocated memory in 'ext')*/ } else if(sign == LV_SIGNAL_PRESSED) { - - /*Save the x coordinate of the pressed point to see if the switch was slid*/ - lv_indev_t * indev = lv_indev_get_act(); - if(indev) { - lv_point_t p; - lv_indev_get_point(indev, &p); - ext->start_x = p.x; - } ext->changed = 0; } else if(sign == LV_SIGNAL_PRESSING) { if(ext->state != ext->slider.bar.cur_value) ext->changed = 1; diff --git a/src/lv_objx/lv_sw.h b/src/lv_objx/lv_sw.h index d5e9372ab..a50184463 100644 --- a/src/lv_objx/lv_sw.h +++ b/src/lv_objx/lv_sw.h @@ -37,7 +37,6 @@ typedef struct { lv_slider_ext_t slider; /*Ext. of ancestor*/ /*New data for this type */ - lv_coord_t start_x; uint8_t changed :1; /*Indicates the switch state explicitly changed by drag*/ uint8_t state :1; /*The current state*/ } lv_sw_ext_t; diff --git a/src/lv_themes/lv_theme.h b/src/lv_themes/lv_theme.h index 5024c6730..a59889fed 100644 --- a/src/lv_themes/lv_theme.h +++ b/src/lv_themes/lv_theme.h @@ -70,6 +70,10 @@ typedef enum { LV_THEME_CB, LV_THEME_CB_BULLET, + LV_THEME_DDLIST_BG, + LV_THEME_DDLIST_SCRL, + LV_THEME_DDLIST_SCRL_BAR, + LV_THEME_DDLIST_SEL, }lv_theme_style_t; typedef struct { diff --git a/src/lv_themes/lv_theme_alien.c b/src/lv_themes/lv_theme_alien.c index 9771e4a49..51707bcf2 100644 --- a/src/lv_themes/lv_theme_alien.c +++ b/src/lv_themes/lv_theme_alien.c @@ -7,6 +7,7 @@ * INCLUDES *********************/ #include "lv_theme.h" +#include "../lv_objx/lv_img.h" #if LV_USE_THEME_ALIEN @@ -33,6 +34,7 @@ static lv_style_t transp; static lv_style_t panel; /*General fancy background (e.g. to chart or ta)*/ static lv_style_t btn; static lv_style_t sb; +static lv_style_t transp_tight; #if LV_USE_BAR static lv_style_t bar_indic; @@ -77,7 +79,8 @@ static void basic_init(void) lv_style_set_value(&panel, LV_STYLE_RADIUS, LV_DPI / 16); lv_style_set_value(&panel, LV_STYLE_BORDER_WIDTH, LV_DPI / 50 > 0 ? LV_DPI / 50 : 1); lv_style_set_color(&panel, LV_STYLE_BG_COLOR, LV_COLOR_SILVER); - lv_style_set_color(&panel, LV_STYLE_BG_GRAD_COLOR, LV_COLOR_GRAY); + lv_style_set_color(&panel, LV_STYLE_BG_GRAD_COLOR, LV_COLOR_BLUE); + lv_style_set_value(&panel, LV_STYLE_BG_GRAD_DIR, LV_GRAD_DIR_VER); lv_style_set_color(&panel, LV_STYLE_BORDER_COLOR, LV_COLOR_GRAY); lv_style_set_color(&panel, LV_STYLE_TEXT_COLOR, LV_COLOR_BLACK); @@ -104,8 +107,19 @@ static void basic_init(void) lv_style_set_value(&btn, LV_STYLE_SHADOW_OFFSET_Y, 10); lv_style_set_color(&btn, LV_STYLE_BORDER_COLOR | LV_STYLE_STATE_FOCUS, LV_COLOR_AQUA); lv_style_set_value(&btn, LV_STYLE_BORDER_WIDTH | LV_STYLE_STATE_FOCUS, 6); + lv_style_set_ptr(&btn, LV_STYLE_PATTERN_IMAGE | LV_STYLE_STATE_CHECKED, LV_SYMBOL_OK); + lv_style_set_ptr(&btn, LV_STYLE_FONT | LV_STYLE_STATE_CHECKED, &lv_font_roboto_12); - + lv_style_init(&transp_tight); + lv_style_set_opa(&transp_tight, LV_STYLE_BG_OPA, LV_OPA_TRANSP); + lv_style_set_opa(&transp_tight, LV_STYLE_BORDER_OPA, LV_OPA_TRANSP); + lv_style_set_opa(&transp_tight, LV_STYLE_SHADOW_OPA, LV_OPA_TRANSP); + lv_style_set_opa(&transp_tight, LV_STYLE_PATTERN_OPA, LV_OPA_TRANSP); + lv_style_set_value(&transp_tight, LV_STYLE_PAD_LEFT, 0); + lv_style_set_value(&transp_tight, LV_STYLE_PAD_RIGHT, 0); + lv_style_set_value(&transp_tight, LV_STYLE_PAD_TOP, 0); + lv_style_set_value(&transp_tight, LV_STYLE_PAD_BOTTOM, 0); + lv_style_set_value(&transp_tight, LV_STYLE_PAD_INNER, 0); } @@ -531,47 +545,13 @@ static void list_init(void) static void ddlist_init(void) { #if LV_USE_DDLIST != 0 - lv_style_copy(&ddlist_bg, &panel); - ddlist_bg.text.line_space = LV_DPI / 8; - ddlist_bg.body.padding.left = LV_DPI / 6; - ddlist_bg.body.padding.right = LV_DPI / 6; - ddlist_bg.body.padding.top = LV_DPI / 6; - ddlist_bg.body.padding.bottom = LV_DPI / 6; - - lv_style_copy(&ddlist_sel, &panel); - ddlist_sel.body.main_color = lv_color_hsv_to_rgb(_hue, 45, 70); - ddlist_sel.body.grad_color = lv_color_hsv_to_rgb(_hue, 45, 70); - ddlist_sel.body.opa = LV_OPA_COVER; - ddlist_sel.body.radius = 0; - - theme.style.ddlist.bg = &ddlist_bg; - theme.style.ddlist.sel = &ddlist_sel; - theme.style.ddlist.sb = &sb; #endif } static void roller_init(void) { #if LV_USE_ROLLER != 0 - static lv_style_t roller_bg, roller_sel; - lv_style_copy(&roller_bg, &ddlist_bg); - roller_bg.text.line_space = LV_DPI / 6; - roller_bg.body.radius = LV_DPI / 20; - roller_bg.body.main_color = lv_color_hex3(0x222); - roller_bg.body.grad_color = lv_color_hex3(0x666); - roller_bg.body.border.opa = LV_OPA_30; - roller_bg.text.opa = LV_OPA_70; - roller_bg.text.color = lv_color_hsv_to_rgb(_hue, 20, 70); - roller_bg.body.shadow.width = 0; - lv_style_copy(&roller_sel, &panel); - roller_sel.body.opa = LV_OPA_TRANSP; - roller_sel.body.radius = 0; - roller_sel.text.opa = LV_OPA_COVER; - roller_sel.text.color = lv_color_hsv_to_rgb(_hue, 70, 95); - - theme.style.roller.bg = &roller_bg; - theme.style.roller.sel = &roller_sel; #endif } @@ -781,6 +761,10 @@ lv_style_t * lv_theme_alien_get_style(lv_theme_style_t name) return &panel; case LV_THEME_CB_BULLET: return &btn; + case LV_THEME_DDLIST_SCRL: + return &transp_tight; + case LV_THEME_DDLIST_SEL: + return &btn; } return NULL;