From 89c0ad468ee0a09bb4361f02968110430f9e7735 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Tue, 14 Jan 2020 08:36:36 +0100 Subject: [PATCH] improve table borders --- src/lv_core/lv_obj.c | 2 +- src/lv_core/lv_obj.h | 2 +- src/lv_objx/lv_page.c | 20 ++++++------- src/lv_objx/lv_table.c | 53 +++++++++++++++++++++++++++++----- src/lv_themes/lv_theme_alien.c | 5 ++-- 5 files changed, 60 insertions(+), 22 deletions(-) diff --git a/src/lv_core/lv_obj.c b/src/lv_core/lv_obj.c index 5befcafea..258d9be77 100644 --- a/src/lv_core/lv_obj.c +++ b/src/lv_core/lv_obj.c @@ -1185,7 +1185,7 @@ void lv_obj_set_style_color(lv_obj_t * obj, uint8_t part, lv_style_property_t pr lv_obj_refresh_style(obj); } -void lv_obj_set_style_value(lv_obj_t * obj, uint8_t part, lv_style_property_t prop, lv_style_int_t value) +void lv_obj_set_style_int(lv_obj_t * obj, uint8_t part, lv_style_property_t prop, lv_style_int_t value) { lv_style_dsc_t * style_dsc = lv_obj_get_style(obj, part); lv_style_set_int(&style_dsc->local, prop, value); diff --git a/src/lv_core/lv_obj.h b/src/lv_core/lv_obj.h index b0f4e4567..2e591f889 100644 --- a/src/lv_core/lv_obj.h +++ b/src/lv_core/lv_obj.h @@ -493,7 +493,7 @@ void lv_obj_set_style(lv_obj_t * obj, const lv_style_t * style); void lv_obj_set_style_color(lv_obj_t * obj, uint8_t type, lv_style_property_t prop, lv_color_t color); -void lv_obj_set_style_value(lv_obj_t * obj, uint8_t type, lv_style_property_t prop, lv_style_int_t value); +void lv_obj_set_style_int(lv_obj_t * obj, uint8_t type, lv_style_property_t prop, lv_style_int_t value); void lv_obj_set_style_opa(lv_obj_t * obj, uint8_t type, lv_style_property_t prop, lv_opa_t opa); diff --git a/src/lv_objx/lv_page.c b/src/lv_objx/lv_page.c index fcfec0251..cdd1f6e84 100644 --- a/src/lv_objx/lv_page.c +++ b/src/lv_objx/lv_page.c @@ -662,19 +662,19 @@ static lv_design_res_t lv_page_design(lv_obj_t * page, const lv_area_t * clip_ar lv_draw_mask_add(mp, page + 8); } } else if(mode == LV_DESIGN_DRAW_POST) { - lv_draw_rect_dsc_t draw_dsc; - lv_draw_rect_dsc_init(&draw_dsc); - lv_obj_init_draw_rect_dsc(page, LV_PAGE_PART_BG, &draw_dsc); + lv_draw_rect_dsc_t rect_dsc; + lv_draw_rect_dsc_init(&rect_dsc); + lv_obj_init_draw_rect_dsc(page, LV_PAGE_PART_BG, &rect_dsc); /*Draw only a border. It ensures that the page looks "closed" even with overflowing scrollable*/ - draw_dsc.shadow_width = 0; - draw_dsc.bg_opa = LV_OPA_TRANSP; - lv_draw_rect(&page->coords, clip_area, &draw_dsc); + rect_dsc.shadow_width = 0; + rect_dsc.bg_opa = LV_OPA_TRANSP; + lv_draw_rect(&page->coords, clip_area, &rect_dsc); /*Draw the scrollbars*/ lv_page_ext_t * ext = lv_obj_get_ext_attr(page); - lv_draw_rect_dsc_init(&draw_dsc); - lv_obj_init_draw_rect_dsc(page, LV_PAGE_PART_SCRLBAR, &draw_dsc); + lv_draw_rect_dsc_init(&rect_dsc); + lv_obj_init_draw_rect_dsc(page, LV_PAGE_PART_SCRLBAR, &rect_dsc); lv_area_t sb_area; if(ext->sb.hor_draw && (ext->sb.mode & LV_SB_MODE_HIDE) == 0) { /*Convert the relative coordinates to absolute*/ @@ -683,7 +683,7 @@ static lv_design_res_t lv_page_design(lv_obj_t * page, const lv_area_t * clip_ar sb_area.y1 += page->coords.y1; sb_area.x2 += page->coords.x1; sb_area.y2 += page->coords.y1; - lv_draw_rect(&sb_area, clip_area, &draw_dsc); + lv_draw_rect(&sb_area, clip_area, &rect_dsc); } if(ext->sb.ver_draw && (ext->sb.mode & LV_SB_MODE_HIDE) == 0) { @@ -693,7 +693,7 @@ static lv_design_res_t lv_page_design(lv_obj_t * page, const lv_area_t * clip_ar sb_area.y1 += page->coords.y1; sb_area.x2 += page->coords.x1; sb_area.y2 += page->coords.y1; - lv_draw_rect(&sb_area, clip_area, &draw_dsc); + lv_draw_rect(&sb_area, clip_area, &rect_dsc); } #if LV_USE_ANIMATION diff --git a/src/lv_objx/lv_table.c b/src/lv_objx/lv_table.c index e9df79789..dae1ab300 100644 --- a/src/lv_objx/lv_table.c +++ b/src/lv_objx/lv_table.c @@ -37,7 +37,7 @@ static void refr_size(lv_obj_t * table); * STATIC VARIABLES **********************/ static lv_signal_cb_t ancestor_signal; -static lv_design_cb_t ancestor_scrl_design; +static lv_design_cb_t ancestor_design; /********************** * MACROS @@ -71,7 +71,7 @@ lv_obj_t * lv_table_create(lv_obj_t * par, const lv_obj_t * copy) } if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_cb(new_table); - if(ancestor_scrl_design == NULL) ancestor_scrl_design = lv_obj_get_design_cb(new_table); + if(ancestor_design == NULL) ancestor_design = lv_obj_get_design_cb(new_table); /*Initialize the allocated 'ext' */ ext->cell_data = NULL; @@ -93,6 +93,7 @@ lv_obj_t * lv_table_create(lv_obj_t * par, const lv_obj_t * copy) /*Init the new table table*/ if(copy == NULL) { + lv_style_dsc_reset(&new_table->style_dsc); lv_obj_add_style_theme(new_table, LV_TABLE_PART_BG, LV_THEME_TABLE_BG); lv_obj_add_style_theme(new_table, LV_TABLE_PART_CELL1, LV_THEME_TABLE_CELL1); lv_obj_add_style_theme(new_table, LV_TABLE_PART_CELL2, LV_THEME_TABLE_CELL2); @@ -579,13 +580,31 @@ static lv_design_res_t lv_table_design(lv_obj_t * table, const lv_area_t * clip_ { /*Return false if the object is not covers the mask_p area*/ if(mode == LV_DESIGN_COVER_CHK) { - return LV_DESIGN_RES_NOT_COVER; + return ancestor_design(table, clip_area, mode); } /*Draw the object*/ else if(mode == LV_DESIGN_DRAW_MAIN) { - ancestor_scrl_design(table, clip_area, mode); - lv_table_ext_t * ext = lv_obj_get_ext_attr(table); + + lv_draw_rect_dsc_t draw_dsc; + lv_draw_rect_dsc_init(&draw_dsc); + lv_obj_init_draw_rect_dsc(table, LV_TABLE_PART_BG, &draw_dsc); + + /*Draw without border first*/ + draw_dsc.border_width = 0; + + lv_draw_rect(&table->coords, clip_area, &draw_dsc); + + if(lv_obj_get_style_int(table, LV_TABLE_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_int(table, LV_TABLE_PART_BG, LV_STYLE_RADIUS); + + lv_draw_mask_radius_init(mp, &table->coords, r, false); + /*Add the mask and use some table specific data as custom id. Don't use `table` directly because it might be used by the user*/ + lv_draw_mask_add(mp, ext->cell_style); + } + lv_coord_t h_row; lv_point_t txt_size; lv_area_t cell_area; @@ -651,7 +670,6 @@ static lv_design_res_t lv_table_design(lv_obj_t * table, const lv_area_t * clip_ uint16_t col_merge = 0; for(col_merge = 0; col_merge + col < ext->col_cnt - 1; col_merge++) { - if(ext->cell_data[cell + col_merge] != NULL) { format.format_byte = ext->cell_data[cell + col_merge][0]; if(format.s.right_merge) @@ -666,7 +684,13 @@ static lv_design_res_t lv_table_design(lv_obj_t * table, const lv_area_t * clip_ uint8_t cell_type = format.s.type; - lv_draw_rect(&cell_area, clip_area, &rect_dsc[cell_type]); + /*Expand the cell area with a half border to avoid drawing 2 borders next to each other*/ + lv_area_t cell_area_border; + lv_area_copy(&cell_area_border, &cell_area); + cell_area_border.x2 += rect_dsc[cell_type].border_width / 2 + (rect_dsc[cell_type].border_width & 0x1); + cell_area_border.y2 += rect_dsc[cell_type].border_width / 2 + (rect_dsc[cell_type].border_width & 0x1); + + lv_draw_rect(&cell_area_border, clip_area, &rect_dsc[cell_type]); if(ext->cell_data[cell]) { @@ -735,6 +759,20 @@ static lv_design_res_t lv_table_design(lv_obj_t * table, const lv_area_t * clip_ } /*Post draw when the children are drawn*/ else if(mode == LV_DESIGN_DRAW_POST) { + lv_draw_rect_dsc_t draw_dsc; + lv_draw_rect_dsc_init(&draw_dsc); + lv_obj_init_draw_rect_dsc(table, LV_TABLE_PART_BG, &draw_dsc); + + /*Draw only a border to allow drawing a border around the whole table*/ + draw_dsc.shadow_width = 0; + draw_dsc.bg_opa = LV_OPA_TRANSP; + lv_draw_rect(&table->coords, clip_area, &draw_dsc); + + lv_table_ext_t * ext = lv_obj_get_ext_attr(table); + if(lv_obj_get_style_int(table, LV_TABLE_PART_BG, LV_STYLE_CLIP_CORNER)) { + void * param = lv_draw_mask_remove_custom(ext->cell_style); + lv_mem_buf_release(param); + } } return LV_DESIGN_RES_OK; @@ -876,7 +914,6 @@ static lv_coord_t get_row_height(lv_obj_t * table, uint16_t row_id) for(cell = row_start, col = 0; cell < row_start + ext->col_cnt; cell++, col++) { if(ext->cell_data[cell] != NULL) { - txt_w = ext->col_w[col]; uint16_t col_merge = 0; for(col_merge = 0; col_merge + col < ext->col_cnt - 1; col_merge++) { diff --git a/src/lv_themes/lv_theme_alien.c b/src/lv_themes/lv_theme_alien.c index 9944660af..d3820269d 100644 --- a/src/lv_themes/lv_theme_alien.c +++ b/src/lv_themes/lv_theme_alien.c @@ -87,7 +87,7 @@ static void basic_init(void) lv_style_init(&scr); lv_style_set_opa(&scr, LV_STYLE_BG_OPA, LV_OPA_COVER); lv_style_set_color(&scr, LV_STYLE_BG_COLOR, LV_COLOR_MAKE(0x20, 0x20, 0x20)); - lv_style_set_color(&scr, LV_STYLE_TEXT_COLOR , LV_COLOR_WHITE); + lv_style_set_color(&scr, LV_STYLE_TEXT_COLOR , LV_COLOR_GRAY); lv_style_init(&transp); lv_style_set_opa(&transp, LV_STYLE_BG_OPA, LV_OPA_TRANSP); @@ -512,6 +512,7 @@ static void table_init(void) lv_style_set_color(&table_cell, LV_STYLE_BG_COLOR, LV_COLOR_WHITE); lv_style_set_color(&table_cell, LV_STYLE_BORDER_COLOR, LV_COLOR_BLACK); lv_style_set_int(&table_cell, LV_STYLE_BORDER_WIDTH, 1); + lv_style_set_int(&table_cell, LV_STYLE_BORDER_SIDE, LV_BORDER_SIDE_LEFT | LV_BORDER_SIDE_RIGHT); lv_style_set_int(&table_cell, LV_STYLE_PAD_LEFT, LV_DPI/20); lv_style_set_int(&table_cell, LV_STYLE_PAD_RIGHT, LV_DPI/20); lv_style_set_int(&table_cell, LV_STYLE_PAD_TOP, LV_DPI/20); @@ -707,7 +708,7 @@ lv_style_t * lv_theme_alien_get_style(lv_theme_style_t name) #if LV_USE_TABLE case LV_THEME_TABLE_BG: - return &panel; + return NULL; case LV_THEME_TABLE_CELL1: case LV_THEME_TABLE_CELL2: case LV_THEME_TABLE_CELL3: