From 5001c4e6a90cb3e62964ff3dc99dc8711d8c0335 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Sat, 16 Nov 2019 11:22:23 +0100 Subject: [PATCH] theme and minor drawin fixes --- src/lv_core/lv_obj.c | 2 +- src/lv_objx/lv_bar.c | 68 ++++++++++++------------------- src/lv_objx/lv_slider.c | 1 + src/lv_objx/lv_sw.c | 6 +++ src/lv_themes/lv_theme_material.c | 5 +++ src/lv_themes/lv_theme_night.c | 5 +++ 6 files changed, 44 insertions(+), 43 deletions(-) diff --git a/src/lv_core/lv_obj.c b/src/lv_core/lv_obj.c index b43807dcb..a8daedc8b 100644 --- a/src/lv_core/lv_obj.c +++ b/src/lv_core/lv_obj.c @@ -2442,7 +2442,7 @@ static lv_design_res_t lv_obj_design(lv_obj_t * obj, const lv_area_t * clip_area lv_draw_mask_radius_param_t * mp = lv_draw_buf_get(sizeof(lv_draw_mask_radius_param_t)); lv_draw_mask_radius_init(mp, &obj->coords, style->body.radius, false); - /*Add the mask and use `obj+8` as custom id. Don't use `obj` directly because it might be sued by the user*/ + /*Add the mask and use `obj+8` as custom id. Don't use `obj` directly because it might be used by the user*/ lv_draw_mask_add(mp, obj + 8); } } diff --git a/src/lv_objx/lv_bar.c b/src/lv_objx/lv_bar.c index af8b3c91b..94b9cc420 100644 --- a/src/lv_objx/lv_bar.c +++ b/src/lv_objx/lv_bar.c @@ -413,21 +413,21 @@ static lv_design_res_t lv_bar_design(lv_obj_t * bar, const lv_area_t * clip_area static void draw_bg(lv_obj_t * bar, const lv_area_t * clip_area, lv_design_mode_t mode, lv_opa_t opa) { + const lv_style_t * style_bg = lv_bar_get_style(bar, LV_BAR_STYLE_BG); #if LV_USE_GROUP == 0 /*Simply draw the background*/ - ancestor_design_f(bar, mask, mode); + lv_draw_rect(&bar->coords, clip_area, style_bg, opa); #else /* Draw the borders later if the bar is focused. * At value = 100% the indicator can cover to whole background and the focused style won't * be visible*/ if(lv_obj_is_focused(bar)) { - const lv_style_t * style_bg = lv_bar_get_style(bar, LV_BAR_STYLE_BG); lv_style_t style_tmp; lv_style_copy(&style_tmp, style_bg); style_tmp.body.border.width = 0; lv_draw_rect(&bar->coords, clip_area, &style_tmp, opa); } else { - ancestor_design_f(bar, clip_area, mode); + lv_draw_rect(&bar->coords, clip_area, style_bg, opa); } #endif } @@ -526,50 +526,34 @@ static void draw_indic(lv_obj_t * bar, const lv_area_t * clip_area, lv_design_mo /*Do not draw a zero length indicator*/ if(!sym && indic_length == 0) return; - /*If the indicator has a gradient along the longed side, - * mask out only the current indicator area from the big gradient.*/ - if((style_indic->body.main_color.full != style_indic->body.grad_color.full) && - ((objw > objh && style_indic->body.grad_dir == LV_GRAD_DIR_HOR) || - (objh > objw && style_indic->body.grad_dir == LV_GRAD_DIR_VER))) { - lv_style_t style_indic_tmp; - lv_style_copy(&style_indic_tmp, style_indic); + lv_style_t style_indic_tmp; + lv_style_copy(&style_indic_tmp, style_indic); - /*Draw only the shadow*/ - style_indic_tmp.body.opa = LV_OPA_TRANSP; - style_indic_tmp.body.border.width = 0; - lv_draw_rect(&ext->indic_area, clip_area, &style_indic_tmp, opa); + /*Draw only the shadow*/ + style_indic_tmp.body.opa = LV_OPA_TRANSP; + style_indic_tmp.body.border.width = 0; + lv_draw_rect(&ext->indic_area, clip_area, &style_indic_tmp, opa); - /*Draw_only the background*/ - /*Get the max possible indicator area. The gradient should be applied on this*/ - lv_area_t mask_indic_max_area; - lv_area_copy(&mask_indic_max_area, &bar->coords); - mask_indic_max_area.x1 += style_indic->body.padding.left; - mask_indic_max_area.y1 += style_indic->body.padding.top; - mask_indic_max_area.x2 -= style_indic->body.padding.right; - mask_indic_max_area.y2 -= style_indic->body.padding.bottom; + /*Draw_only the background*/ + style_indic_tmp.body.shadow.width = 0; + style_indic_tmp.body.border.width = style_indic->body.border.width; + style_indic_tmp.body.opa = style_indic->body.opa; - /*Create a mask to the current indicator area. This is see only this part from the whole gradient.*/ - lv_draw_mask_radius_param_t mask_indic_param; - lv_draw_mask_radius_init(&mask_indic_param, &ext->indic_area, style_indic->body.radius, false); - int16_t mask_indic_id = lv_draw_mask_add(&mask_indic_param, NULL); + /*Get the max possible indicator area. The gradient should be applied on this*/ + lv_area_t mask_indic_max_area; + lv_area_copy(&mask_indic_max_area, &bar->coords); + mask_indic_max_area.x1 += style_indic->body.padding.left; + mask_indic_max_area.y1 += style_indic->body.padding.top; + mask_indic_max_area.x2 -= style_indic->body.padding.right; + mask_indic_max_area.y2 -= style_indic->body.padding.bottom; - style_indic_tmp.body.shadow.width = 0; - style_indic_tmp.body.opa = style_indic->body.opa; - lv_draw_rect(&mask_indic_max_area, clip_area, &style_indic_tmp, opa); - - lv_draw_mask_remove_id(mask_indic_id); - - /*Draw only the border*/ - style_indic_tmp.body.opa = LV_OPA_TRANSP; - style_indic_tmp.body.border.width = style_indic->body.border.width; - lv_draw_rect(&ext->indic_area, clip_area, &style_indic_tmp, opa); - - } - /*If the gradient is along the short side, simply draw a rectangle.*/ - else { - lv_draw_rect(&ext->indic_area, clip_area, style_indic, opa); - } + /*Create a mask to the current indicator area. This is see only this part from the whole gradient.*/ + lv_draw_mask_radius_param_t mask_indic_param; + lv_draw_mask_radius_init(&mask_indic_param, &ext->indic_area, style_indic->body.radius, false); + int16_t mask_indic_id = lv_draw_mask_add(&mask_indic_param, NULL); + lv_draw_rect(&mask_indic_max_area, clip_area, &style_indic_tmp, opa); + lv_draw_mask_remove_id(mask_indic_id); } /** diff --git a/src/lv_objx/lv_slider.c b/src/lv_objx/lv_slider.c index 3081e8133..4208541eb 100644 --- a/src/lv_objx/lv_slider.c +++ b/src/lv_objx/lv_slider.c @@ -264,6 +264,7 @@ static lv_design_res_t lv_slider_design(lv_obj_t * slider, const lv_area_t * cli } /*Post draw when the children are drawn*/ else if(mode == LV_DESIGN_DRAW_POST) { + return ancestor_design_f(slider, clip_area, mode); } return LV_DESIGN_RES_OK; diff --git a/src/lv_objx/lv_sw.c b/src/lv_objx/lv_sw.c index b7c616c16..dd91e5c5a 100644 --- a/src/lv_objx/lv_sw.c +++ b/src/lv_objx/lv_sw.c @@ -311,10 +311,16 @@ static lv_design_res_t lv_sw_design(lv_obj_t * sw, const lv_area_t * clip_area, knob_area.y1 = sw->coords.y1; knob_area.y2 = sw->coords.y2; + knob_area.x1 -= style_knob->body.padding.left; + knob_area.x2 += style_knob->body.padding.right; + knob_area.y1 -= style_knob->body.padding.top; + knob_area.y2 += style_knob->body.padding.bottom; + lv_draw_rect(&knob_area, clip_area, style_knob, opa_scale); } /*Post draw when the children are drawn*/ else if(mode == LV_DESIGN_DRAW_POST) { + return ancestor_design(sw, clip_area, mode); } return LV_DESIGN_RES_OK; diff --git a/src/lv_themes/lv_theme_material.c b/src/lv_themes/lv_theme_material.c index 579df361c..deceac946 100644 --- a/src/lv_themes/lv_theme_material.c +++ b/src/lv_themes/lv_theme_material.c @@ -254,6 +254,10 @@ static void slider_init(void) knob.body.border.width = 0; knob.body.main_color = theme.style.bar.indic->body.main_color; knob.body.grad_color = knob.body.main_color; + knob.body.padding.left = LV_DPI/25; + knob.body.padding.right = LV_DPI/25; + knob.body.padding.top = LV_DPI/25; + knob.body.padding.bottom = LV_DPI/25; theme.style.slider.bg = theme.style.bar.bg; theme.style.slider.indic = theme.style.bar.indic; @@ -758,6 +762,7 @@ static void table_init(void) cell.body.padding.right = LV_DPI / 12; cell.body.padding.top = LV_DPI / 12; cell.body.padding.bottom = LV_DPI / 12; + cell.body.shadow.width = 0; theme.style.table.bg = &lv_style_transp_tight; theme.style.table.cell = &cell; diff --git a/src/lv_themes/lv_theme_night.c b/src/lv_themes/lv_theme_night.c index 653742de5..69dfad7fc 100644 --- a/src/lv_themes/lv_theme_night.c +++ b/src/lv_themes/lv_theme_night.c @@ -217,6 +217,7 @@ static void bar_init(void) bar_bg.body.padding.top = LV_DPI / 16; bar_bg.body.padding.bottom = LV_DPI / 16; bar_bg.body.radius = LV_RADIUS_CIRCLE; + bar_bg.body.corner_mask = 1; lv_style_copy(&bar_indic, &def); bar_indic.body.main_color = lv_color_hsv_to_rgb(_hue, 80, 70); @@ -241,6 +242,10 @@ static void slider_init(void) static lv_style_t slider_knob; lv_style_copy(&slider_knob, theme.style.btn.rel); slider_knob.body.radius = LV_RADIUS_CIRCLE; + slider_knob.body.padding.left = LV_DPI/25; + slider_knob.body.padding.right = LV_DPI/25; + slider_knob.body.padding.top = LV_DPI/25; + slider_knob.body.padding.bottom = LV_DPI/25; theme.style.slider.bg = theme.style.bar.bg; theme.style.slider.indic = theme.style.bar.indic;