improve table borders

This commit is contained in:
Gabor Kiss-Vamosi
2020-01-14 08:36:36 +01:00
parent c3dddda326
commit 89c0ad468e
5 changed files with 60 additions and 22 deletions

View File

@@ -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); 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_dsc_t * style_dsc = lv_obj_get_style(obj, part);
lv_style_set_int(&style_dsc->local, prop, value); lv_style_set_int(&style_dsc->local, prop, value);

View File

@@ -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_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); void lv_obj_set_style_opa(lv_obj_t * obj, uint8_t type, lv_style_property_t prop, lv_opa_t opa);

View File

@@ -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); lv_draw_mask_add(mp, page + 8);
} }
} else if(mode == LV_DESIGN_DRAW_POST) { } else if(mode == LV_DESIGN_DRAW_POST) {
lv_draw_rect_dsc_t draw_dsc; lv_draw_rect_dsc_t rect_dsc;
lv_draw_rect_dsc_init(&draw_dsc); lv_draw_rect_dsc_init(&rect_dsc);
lv_obj_init_draw_rect_dsc(page, LV_PAGE_PART_BG, &draw_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 only a border. It ensures that the page looks "closed" even with overflowing scrollable*/
draw_dsc.shadow_width = 0; rect_dsc.shadow_width = 0;
draw_dsc.bg_opa = LV_OPA_TRANSP; rect_dsc.bg_opa = LV_OPA_TRANSP;
lv_draw_rect(&page->coords, clip_area, &draw_dsc); lv_draw_rect(&page->coords, clip_area, &rect_dsc);
/*Draw the scrollbars*/ /*Draw the scrollbars*/
lv_page_ext_t * ext = lv_obj_get_ext_attr(page); lv_page_ext_t * ext = lv_obj_get_ext_attr(page);
lv_draw_rect_dsc_init(&draw_dsc); lv_draw_rect_dsc_init(&rect_dsc);
lv_obj_init_draw_rect_dsc(page, LV_PAGE_PART_SCRLBAR, &draw_dsc); lv_obj_init_draw_rect_dsc(page, LV_PAGE_PART_SCRLBAR, &rect_dsc);
lv_area_t sb_area; lv_area_t sb_area;
if(ext->sb.hor_draw && (ext->sb.mode & LV_SB_MODE_HIDE) == 0) { if(ext->sb.hor_draw && (ext->sb.mode & LV_SB_MODE_HIDE) == 0) {
/*Convert the relative coordinates to absolute*/ /*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.y1 += page->coords.y1;
sb_area.x2 += page->coords.x1; sb_area.x2 += page->coords.x1;
sb_area.y2 += page->coords.y1; 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) { 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.y1 += page->coords.y1;
sb_area.x2 += page->coords.x1; sb_area.x2 += page->coords.x1;
sb_area.y2 += page->coords.y1; 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 #if LV_USE_ANIMATION

View File

@@ -37,7 +37,7 @@ static void refr_size(lv_obj_t * table);
* STATIC VARIABLES * STATIC VARIABLES
**********************/ **********************/
static lv_signal_cb_t ancestor_signal; static lv_signal_cb_t ancestor_signal;
static lv_design_cb_t ancestor_scrl_design; static lv_design_cb_t ancestor_design;
/********************** /**********************
* MACROS * 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_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' */ /*Initialize the allocated 'ext' */
ext->cell_data = NULL; 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*/ /*Init the new table table*/
if(copy == NULL) { 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_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_CELL1, LV_THEME_TABLE_CELL1);
lv_obj_add_style_theme(new_table, LV_TABLE_PART_CELL2, LV_THEME_TABLE_CELL2); 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*/ /*Return false if the object is not covers the mask_p area*/
if(mode == LV_DESIGN_COVER_CHK) { if(mode == LV_DESIGN_COVER_CHK) {
return LV_DESIGN_RES_NOT_COVER; return ancestor_design(table, clip_area, mode);
} }
/*Draw the object*/ /*Draw the object*/
else if(mode == LV_DESIGN_DRAW_MAIN) { 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_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_coord_t h_row;
lv_point_t txt_size; lv_point_t txt_size;
lv_area_t cell_area; 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; uint16_t col_merge = 0;
for(col_merge = 0; col_merge + col < ext->col_cnt - 1; col_merge++) { for(col_merge = 0; col_merge + col < ext->col_cnt - 1; col_merge++) {
if(ext->cell_data[cell + col_merge] != NULL) { if(ext->cell_data[cell + col_merge] != NULL) {
format.format_byte = ext->cell_data[cell + col_merge][0]; format.format_byte = ext->cell_data[cell + col_merge][0];
if(format.s.right_merge) 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; 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]) { 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*/ /*Post draw when the children are drawn*/
else if(mode == LV_DESIGN_DRAW_POST) { 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; 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++) { for(cell = row_start, col = 0; cell < row_start + ext->col_cnt; cell++, col++) {
if(ext->cell_data[cell] != NULL) { if(ext->cell_data[cell] != NULL) {
txt_w = ext->col_w[col]; txt_w = ext->col_w[col];
uint16_t col_merge = 0; uint16_t col_merge = 0;
for(col_merge = 0; col_merge + col < ext->col_cnt - 1; col_merge++) { for(col_merge = 0; col_merge + col < ext->col_cnt - 1; col_merge++) {

View File

@@ -87,7 +87,7 @@ static void basic_init(void)
lv_style_init(&scr); lv_style_init(&scr);
lv_style_set_opa(&scr, LV_STYLE_BG_OPA, LV_OPA_COVER); 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_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_init(&transp);
lv_style_set_opa(&transp, LV_STYLE_BG_OPA, LV_OPA_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_BG_COLOR, LV_COLOR_WHITE);
lv_style_set_color(&table_cell, LV_STYLE_BORDER_COLOR, LV_COLOR_BLACK); 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_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_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_RIGHT, LV_DPI/20);
lv_style_set_int(&table_cell, LV_STYLE_PAD_TOP, 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 #if LV_USE_TABLE
case LV_THEME_TABLE_BG: case LV_THEME_TABLE_BG:
return &panel; return NULL;
case LV_THEME_TABLE_CELL1: case LV_THEME_TABLE_CELL1:
case LV_THEME_TABLE_CELL2: case LV_THEME_TABLE_CELL2:
case LV_THEME_TABLE_CELL3: case LV_THEME_TABLE_CELL3: