From da581072b4ae8302c140379d35f33874954214e5 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Sun, 17 Dec 2017 20:11:14 +0100 Subject: [PATCH] minor fixes --- lv_objx/lv_ddlist.c | 31 +++++++++++++++++++++++++++++++ lv_objx/lv_gauge.c | 4 ++-- lv_objx/lv_roller.c | 17 ++++++++++++++--- lv_objx/lv_roller.h | 6 ++++++ lv_themes/lv_theme_alien.c | 4 +++- lv_themes/lv_theme_mono.c | 4 +++- lv_themes/lv_theme_night.c | 13 +++++++------ 7 files changed, 66 insertions(+), 13 deletions(-) diff --git a/lv_objx/lv_ddlist.c b/lv_objx/lv_ddlist.c index 55c9fd078..2dc7fcf74 100644 --- a/lv_objx/lv_ddlist.c +++ b/lv_objx/lv_ddlist.c @@ -441,6 +441,37 @@ static bool lv_ddlist_design(lv_obj_t * ddlist, const lv_area_t * mask, lv_desig /*Post draw when the children are drawn*/ else if(mode == LV_DESIGN_DRAW_POST) { ancestor_design(ddlist, mask, mode); + + /*Redraw the text on the selected area with a different color*/ + lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); + + /*Redraw only in opened state*/ + if(ext->opened == 0) return true; + + 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_height_scale(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.y2 = area_sel.y1 + font_h + style->text.line_space; + area_sel.x1 = ddlist->coords.x1; + area_sel.x2 = ddlist->coords.x2; + lv_area_t mask_sel; + bool area_ok; + area_ok = lv_area_union(&mask_sel, mask, &area_sel); + if(area_ok) { + 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_draw_label(&ext->label->coords, &mask_sel, &new_style, + lv_label_get_text(ext->label), LV_TXT_FLAG_NONE, NULL); + } } return true; diff --git a/lv_objx/lv_gauge.c b/lv_objx/lv_gauge.c index 26a9f6182..5e43ceedc 100644 --- a/lv_objx/lv_gauge.c +++ b/lv_objx/lv_gauge.c @@ -371,7 +371,7 @@ static void lv_gauge_draw_needle(lv_obj_t * gauge, const lv_area_t * mask) { lv_style_t style_needle; lv_gauge_ext_t * ext = lv_obj_get_ext_attr(gauge); - lv_style_t * style = lv_obj_get_style(gauge); + lv_style_t * style = lv_gauge_get_style(gauge); lv_coord_t r = lv_obj_get_width(gauge) / 2 - style->body.padding.hor; lv_coord_t x_ofs = lv_obj_get_width(gauge) / 2 + gauge->coords.x1; @@ -384,7 +384,7 @@ static void lv_gauge_draw_needle(lv_obj_t * gauge, const lv_area_t * mask) lv_point_t p_end; uint8_t i; - memcpy(&style_needle, style, sizeof(lv_style_t)); + lv_style_copy(&style_needle, style); p_mid.x = x_ofs; p_mid.y = y_ofs; diff --git a/lv_objx/lv_roller.c b/lv_objx/lv_roller.c index 8f28b2885..c1c3e436c 100644 --- a/lv_objx/lv_roller.c +++ b/lv_objx/lv_roller.c @@ -74,9 +74,7 @@ lv_obj_t * lv_roller_create(lv_obj_t * par, lv_obj_t * copy) lv_page_set_rel_action(new_roller, NULL); /*Roller don't uses it (like ddlist)*/ lv_page_set_scrl_fit(new_roller, true, false); /*Height is specified directly*/ lv_ddlist_open(new_roller, false); - lv_style_t * style_label = lv_obj_get_style(ext->ddlist.label); - lv_ddlist_set_fix_height(new_roller, lv_font_get_height_scale(style_label->text.font) * 3 + style_label->text.line_space * 4); - + lv_roller_set_row_count(new_roller, 3); lv_label_set_align(ext->ddlist.label, LV_LABEL_ALIGN_CENTER); lv_obj_set_signal_func(scrl, lv_roller_scrl_signal); @@ -119,6 +117,18 @@ void lv_roller_set_selected(lv_obj_t *roller, uint16_t sel_opt, bool anim_en) refr_position(roller, anim_en); } +/** + * Set the height to show the given number of rows (options) + * @param roller pointer to a roller object + * @param row_cnt number of desired visible rows + */ +void lv_roller_set_row_count(lv_obj_t *roller, uint8_t row_cnt) +{ + lv_roller_ext_t *ext = lv_obj_get_ext_attr(roller); + lv_style_t * style_label = lv_obj_get_style(ext->ddlist.label); + lv_ddlist_set_fix_height(roller, lv_font_get_height_scale(style_label->text.font) * row_cnt + style_label->text.line_space * (row_cnt + 1)); + +} /** * Set a style of a roller * @param roller pointer to a roller object @@ -212,6 +222,7 @@ static bool lv_roller_design(lv_obj_t * roller, const lv_area_t * mask, lv_desig 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_height_scale(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; diff --git a/lv_objx/lv_roller.h b/lv_objx/lv_roller.h index 799049138..dd09a07ed 100644 --- a/lv_objx/lv_roller.h +++ b/lv_objx/lv_roller.h @@ -71,6 +71,12 @@ static inline void lv_roller_set_options(lv_obj_t * roller, const char * options */ void lv_roller_set_selected(lv_obj_t *roller, uint16_t sel_opt, bool anim_en); +/** + * Set the height to show the given number of rows (options) + * @param roller pointer to a roller object + * @param row_cnt number of desired visible rows + */ +void lv_roller_set_row_count(lv_obj_t *roller, uint8_t row_cnt); /** * Enable or disable the horizontal fit to the content diff --git a/lv_themes/lv_theme_alien.c b/lv_themes/lv_theme_alien.c index 1a548bb4a..a2548da2a 100644 --- a/lv_themes/lv_theme_alien.c +++ b/lv_themes/lv_theme_alien.c @@ -564,7 +564,9 @@ static void ddlist_init(void) { #if USE_LV_DDLIST != 0 lv_style_copy(&ddlist_bg, &panel); - ddlist_bg.text.line_space = LV_DPI / 10; + ddlist_bg.text.line_space = LV_DPI / 8; + ddlist_bg.body.padding.hor = LV_DPI / 6; + ddlist_bg.body.padding.ver = LV_DPI / 6; lv_style_copy(&ddlist_sel, &panel); ddlist_sel.body.main_color = lv_color_hsv_to_rgb(_hue, 45, 70); diff --git a/lv_themes/lv_theme_mono.c b/lv_themes/lv_theme_mono.c index ac363770b..05602bdcb 100644 --- a/lv_themes/lv_theme_mono.c +++ b/lv_themes/lv_theme_mono.c @@ -170,10 +170,12 @@ static void bar_init(void) lv_style_copy(&bar_bg, &light_frame); bar_bg.body.padding.hor = LV_DPI / 15; bar_bg.body.padding.ver = LV_DPI / 15; + bar_bg.body.radius = LV_RADIUS_CIRCLE; lv_style_copy(&bar_indic, &dark_frame); bar_indic.body.padding.hor = LV_DPI / 30; bar_indic.body.padding.ver = LV_DPI / 30; + bar_indic.body.radius = LV_RADIUS_CIRCLE; theme.bar.bg = &bar_bg; theme.bar.indic = &bar_indic; @@ -341,7 +343,7 @@ static void ddlist_init(void) theme.ddlist.bg = &light_frame; - theme.ddlist.sel = &light_plain; + theme.ddlist.sel = &dark_plain; theme.ddlist.sb = &dark_frame; #endif } diff --git a/lv_themes/lv_theme_night.c b/lv_themes/lv_theme_night.c index 017027f04..9a0830208 100644 --- a/lv_themes/lv_theme_night.c +++ b/lv_themes/lv_theme_night.c @@ -52,12 +52,13 @@ static lv_font_t * _font; static void basic_init(void) { lv_style_copy(&def, &lv_style_pretty); /*Initialize the default style*/ + def.text.font = _font; lv_style_copy(&bg, &lv_style_plain); bg.body.main_color = lv_color_hsv_to_rgb(_hue, 11, 30); bg.body.grad_color = lv_color_hsv_to_rgb(_hue, 11, 30); bg.text.color = lv_color_hsv_to_rgb(_hue, 5, 95); - + bg.text.font = _font; lv_style_copy(&sb, &def); sb.body.main_color = lv_color_hsv_to_rgb(_hue, 30, 60); @@ -69,7 +70,6 @@ static void basic_init(void) sb.body.radius = LV_DPI / 30; sb.body.opa = LV_OPA_COVER; - lv_style_copy(&panel, &bg); panel.body.main_color = lv_color_hsv_to_rgb(_hue, 11, 18); panel.body.grad_color = lv_color_hsv_to_rgb(_hue, 11, 18); @@ -97,7 +97,7 @@ static void btn_init(void) { #if USE_LV_BTN != 0 - lv_style_copy(&btn_rel, &lv_style_pretty); + lv_style_copy(&btn_rel, &def); btn_rel.body.main_color = lv_color_hsv_to_rgb(_hue, 10, 40); btn_rel.body.grad_color = lv_color_hsv_to_rgb(_hue, 10, 20); btn_rel.body.border.color = LV_COLOR_HEX3(0x111); @@ -183,7 +183,7 @@ static void led_init(void) { #if USE_LV_LED != 0 static lv_style_t led; - lv_style_copy(&led, &lv_style_pretty_color); + lv_style_copy(&led, &def); led.body.shadow.width = LV_DPI / 10; led.body.radius = LV_RADIUS_CIRCLE; led.body.border.width= LV_DPI / 30; @@ -205,7 +205,7 @@ static void bar_init(void) bar_bg.body.padding.hor = LV_DPI / 16; bar_bg.body.radius = LV_RADIUS_CIRCLE; - lv_style_copy(&bar_indic, &lv_style_pretty); + lv_style_copy(&bar_indic, &def); bar_indic.body.main_color = lv_color_hsv_to_rgb(_hue, 80, 70); bar_indic.body.grad_color = lv_color_hsv_to_rgb(_hue, 80, 70); bar_indic.body.border.color = lv_color_hsv_to_rgb(_hue, 20, 15); @@ -551,9 +551,10 @@ static void win_init(void) win_header.body.padding.ver = 0; static lv_style_t win_btn_pr; - lv_style_copy(&win_btn_pr, &lv_style_plain); + lv_style_copy(&win_btn_pr, &def); win_btn_pr.body.main_color = lv_color_hsv_to_rgb(_hue, 10, 10); win_btn_pr.body.grad_color = lv_color_hsv_to_rgb(_hue, 10, 10); + win_btn_pr.text.color = LV_COLOR_HEX3(0xaaa); theme.win.bg = &win_bg; theme.win.sb = &sb;