From d19792289d316f27dc9316875b9d1b4b5166cc0e Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Wed, 26 Dec 2018 08:24:18 +0100 Subject: [PATCH] add LV_BORDER_INTERNAL --- lv_core/lv_style.h | 13 +++-- lv_objx/lv_btnm.c | 102 +++++++++++++++++++++------------- lv_themes/lv_theme_material.c | 3 +- lv_themes/lv_theme_mono.c | 3 + lv_themes/lv_theme_night.c | 30 +++++----- 5 files changed, 88 insertions(+), 63 deletions(-) diff --git a/lv_core/lv_style.h b/lv_core/lv_style.h index 0e2828bf1..ae50d93f4 100644 --- a/lv_core/lv_style.h +++ b/lv_core/lv_style.h @@ -31,12 +31,13 @@ extern "C" { /*Border types (Use 'OR'ed values)*/ enum { - LV_BORDER_NONE = 0x00, - LV_BORDER_BOTTOM = 0x01, - LV_BORDER_TOP = 0x02, - LV_BORDER_LEFT = 0x04, - LV_BORDER_RIGHT = 0x08, - LV_BORDER_FULL = 0x0F, + LV_BORDER_NONE = 0x00, + LV_BORDER_BOTTOM = 0x01, + LV_BORDER_TOP = 0x02, + LV_BORDER_LEFT = 0x04, + LV_BORDER_RIGHT = 0x08, + LV_BORDER_FULL = 0x0F, + LV_BORDER_INTERNAL = 0x10, /*FOR matrix-like objects (e.g. Button matrix)*/ }; typedef uint8_t lv_border_part_t; diff --git a/lv_objx/lv_btnm.c b/lv_objx/lv_btnm.c index e769733b4..be6e407ad 100644 --- a/lv_objx/lv_btnm.c +++ b/lv_objx/lv_btnm.c @@ -35,7 +35,7 @@ static bool button_is_inactive(const char * btn_str); const char * cut_ctrl_byte(const char * btn_str); static uint16_t get_button_from_point(lv_obj_t * btnm, lv_point_t * p); static uint16_t get_button_text(lv_obj_t * btnm, uint16_t btn_id); -static void create_buttons(lv_obj_t * btnm, const char ** map); +static void allocate_btn_areas(lv_obj_t * btnm, const char ** map); /********************** * STATIC VARIABLES @@ -154,7 +154,7 @@ void lv_btnm_set_map(lv_obj_t * btnm, const char ** map) ext->map_p = map; /*Analyze the map and create the required number of buttons*/ - create_buttons(btnm, map); + allocate_btn_areas(btnm, map); /*Set size and positions of the buttons*/ lv_style_t * style_bg = lv_btnm_get_style(btnm, LV_BTNM_STYLE_BG); @@ -231,10 +231,9 @@ void lv_btnm_set_map(lv_obj_t * btnm, const char ** map) } act_y += btn_h + style_bg->body.padding.inner; - /*If no vertical padding then make sure the last row is at the bottom of 'btnm'*/ - if(style_bg->body.padding.ver == 0 && - act_y + btn_h * 2 > max_h) { /*Last row?*/ - btn_h = max_h - act_y - 1; + /*Make sure the last row is at the bottom of 'btnm'*/ + if(act_y + btn_h * 2 > max_h) { /*Last row?*/ + btn_h = max_h - act_y + style_bg->body.padding.ver - 1; } if(strlen(map_p_tmp[btn_cnt]) == 0) break; /*Break on end of map*/ @@ -456,15 +455,16 @@ static bool lv_btnm_design(lv_obj_t * btnm, const lv_area_t * mask, lv_design_mo uint16_t btn_i = 0; uint16_t txt_i = 0; - + lv_style_t style_tmp; lv_txt_flag_t txt_flag = LV_TXT_FLAG_NONE; - if(ext->recolor) - txt_flag = LV_TXT_FLAG_RECOLOR; + if(ext->recolor) txt_flag = LV_TXT_FLAG_RECOLOR; for(btn_i = 0; btn_i < ext->btn_cnt; btn_i ++, txt_i ++) { /*Search the next valid text in the map*/ - while(strcmp(ext->map_p[txt_i], "\n") == 0) txt_i ++; + while(strcmp(ext->map_p[txt_i], "\n") == 0) { + txt_i ++; + } /*Skip hidden buttons*/ if(button_is_hidden(ext->map_p[txt_i])) continue; @@ -486,7 +486,29 @@ static bool lv_btnm_design(lv_obj_t * btnm, const lv_area_t * mask, lv_design_mo else if(btn_i == ext->btn_id_pr && btn_i == ext->btn_id_tgl) btn_style = lv_btnm_get_style(btnm, LV_BTNM_STYLE_BTN_TGL_PR); else btn_style = lv_btnm_get_style(btnm, LV_BTNM_STYLE_BTN_REL); /*Not possible option, just to be sure*/ - lv_draw_rect(&area_tmp, mask, btn_style, opa_scale); + lv_style_copy(&style_tmp, btn_style); + + /*Remove borders on the edges if `LV_BORDER_INTERNAL`*/ + if(style_tmp.body.border.part & LV_BORDER_INTERNAL) { + if(area_tmp.y1 == btnm->coords.y1 + bg_style->body.padding.ver) { + style_tmp.body.border.part &= ~LV_BORDER_TOP; + } + if(area_tmp.y2 == btnm->coords.y2 - bg_style->body.padding.ver) { + style_tmp.body.border.part &= ~LV_BORDER_BOTTOM; + } + + if(txt_i == 0) { + style_tmp.body.border.part &= ~LV_BORDER_LEFT; + } + else if(strcmp(ext->map_p[txt_i - 1],"\n") == 0) { + style_tmp.body.border.part &= ~LV_BORDER_LEFT; + } + + if(ext->map_p[txt_i + 1][0] == '\0' || strcmp(ext->map_p[txt_i + 1], "\n") == 0) { + style_tmp.body.border.part &= ~LV_BORDER_RIGHT; + } + } + lv_draw_rect(&area_tmp, mask, &style_tmp, opa_scale); /*Calculate the size of the text*/ if(btn_style->glass) btn_style = bg_style; @@ -577,38 +599,38 @@ static lv_res_t lv_btnm_signal(lv_obj_t * btnm, lv_signal_t sign, void * param) if(ext->action) res = ext->action(btnm, cut_ctrl_byte(ext->map_p[txt_i])); if(res == LV_RES_OK) { - /*Invalidate to old pressed area*/; - lv_obj_get_coords(btnm, &btnm_area); - lv_area_copy(&btn_area, &ext->button_areas[ext->btn_id_pr]); - btn_area.x1 += btnm_area.x1; - btn_area.y1 += btnm_area.y1; - btn_area.x2 += btnm_area.x1; - btn_area.y2 += btnm_area.y1; - lv_inv_area(&btn_area); + /*Invalidate to old pressed area*/; + lv_obj_get_coords(btnm, &btnm_area); + lv_area_copy(&btn_area, &ext->button_areas[ext->btn_id_pr]); + btn_area.x1 += btnm_area.x1; + btn_area.y1 += btnm_area.y1; + btn_area.x2 += btnm_area.x1; + btn_area.y2 += btnm_area.y1; + lv_inv_area(&btn_area); - if(ext->toggle != 0) { - /*Invalidate to old toggled area*/; - lv_area_copy(&btn_area, &ext->button_areas[ext->btn_id_tgl]); - btn_area.x1 += btnm_area.x1; - btn_area.y1 += btnm_area.y1; - btn_area.x2 += btnm_area.x1; - btn_area.y2 += btnm_area.y1; - lv_inv_area(&btn_area); - ext->btn_id_tgl = ext->btn_id_pr; + if(ext->toggle != 0) { + /*Invalidate to old toggled area*/; + lv_area_copy(&btn_area, &ext->button_areas[ext->btn_id_tgl]); + btn_area.x1 += btnm_area.x1; + btn_area.y1 += btnm_area.y1; + btn_area.x2 += btnm_area.x1; + btn_area.y2 += btnm_area.y1; + lv_inv_area(&btn_area); + ext->btn_id_tgl = ext->btn_id_pr; - } + } - #if USE_LV_GROUP - /*Leave the clicked button when releases if this not the focused object in a group*/ - lv_group_t * g = lv_obj_get_group(btnm); - if(lv_group_get_focused(g) != btnm) { - ext->btn_id_pr = LV_BTNM_PR_NONE; - } - #else - ext->btn_id_pr = LV_BTNM_PR_NONE; - #endif + #if USE_LV_GROUP + /*Leave the clicked button when releases if this not the focused object in a group*/ + lv_group_t * g = lv_obj_get_group(btnm); + if(lv_group_get_focused(g) != btnm) { + ext->btn_id_pr = LV_BTNM_PR_NONE; + } + #else + ext->btn_id_pr = LV_BTNM_PR_NONE; + #endif - } + } } } } else if(sign == LV_SIGNAL_PRESS_LOST || sign == LV_SIGNAL_DEFOCUS) { @@ -715,7 +737,7 @@ static lv_res_t lv_btnm_signal(lv_obj_t * btnm, lv_signal_t sign, void * param) * @param btnm pointer to button matrix object * @param map_p pointer to a string array */ -static void create_buttons(lv_obj_t * btnm, const char ** map) +static void allocate_btn_areas(lv_obj_t * btnm, const char ** map) { /*Count the buttons in the map*/ uint16_t btn_cnt = 0; diff --git a/lv_themes/lv_theme_material.c b/lv_themes/lv_theme_material.c index accc011bc..e21da8f02 100644 --- a/lv_themes/lv_theme_material.c +++ b/lv_themes/lv_theme_material.c @@ -8,7 +8,6 @@ *********************/ #include "lv_theme.h" - #if USE_LV_THEME_MATERIAL /********************* @@ -434,7 +433,7 @@ static void btnm_init(void) bg.text.color = LV_COLOR_HEX3(0x555); lv_style_copy(&rel, theme.panel); - rel.body.border.part = LV_BORDER_RIGHT; + rel.body.border.part = LV_BORDER_FULL | LV_BORDER_INTERNAL; rel.body.border.width = 1; rel.body.border.color = LV_COLOR_HEX3(0xbbb); rel.body.empty = 1; diff --git a/lv_themes/lv_theme_mono.c b/lv_themes/lv_theme_mono.c index f456caec1..af18f8a5d 100644 --- a/lv_themes/lv_theme_mono.c +++ b/lv_themes/lv_theme_mono.c @@ -426,6 +426,9 @@ static void win_init(void) */ lv_theme_t * lv_theme_mono_init(uint16_t hue, lv_font_t * font) { + + (void)hue; /*Unused*/ + if(font == NULL) font = LV_FONT_DEFAULT; _font = font; diff --git a/lv_themes/lv_theme_night.c b/lv_themes/lv_theme_night.c index 2f37d15a3..5bae3de21 100644 --- a/lv_themes/lv_theme_night.c +++ b/lv_themes/lv_theme_night.c @@ -429,29 +429,29 @@ static void btnm_init(void) btnm_bg.body.border.width = 1; lv_style_copy(&rel, &btn_rel); - rel.body.border.part = LV_BORDER_RIGHT; - rel.body.border.width = 2; - rel.body.radius = 0; + rel.body.border.part = LV_BORDER_FULL | LV_BORDER_INTERNAL; + rel.body.border.width = 1; + rel.body.radius = 2; lv_style_copy(&pr, &btn_pr); - pr.body.border.part = LV_BORDER_RIGHT; - pr.body.border.width = 2; - pr.body.radius = 0; + pr.body.border.part = rel.body.border.part; + pr.body.border.width = rel.body.border.width; + pr.body.radius = rel.body.radius; lv_style_copy(&tgl_rel, &btn_tgl_rel); - tgl_rel.body.border.part = LV_BORDER_RIGHT; - tgl_rel.body.border.width = 2; - tgl_rel.body.radius = 0; + tgl_rel.body.border.part = rel.body.border.part; + tgl_rel.body.border.width = rel.body.border.width; + tgl_rel.body.radius = rel.body.radius; lv_style_copy(&tgl_pr, &btn_tgl_pr); - tgl_pr.body.border.part = LV_BORDER_RIGHT; - tgl_pr.body.border.width = 2; - tgl_pr.body.radius = 0; + tgl_pr.body.border.part = rel.body.border.part; + tgl_pr.body.border.width = rel.body.border.width; + tgl_pr.body.radius = rel.body.radius; lv_style_copy(&ina, &btn_ina); - ina.body.border.part = LV_BORDER_RIGHT; - ina.body.border.width = 2; - ina.body.radius = 0; + ina.body.border.part = rel.body.border.part; + ina.body.border.width = rel.body.border.width; + ina.body.radius = rel.body.radius; theme.btnm.bg = &btnm_bg; theme.btnm.btn.rel = &rel;