1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-28 07:03:00 +08:00

fix(btnmatrix): add lv_obj_get_style_space_...() and use them to consider border width in btnmatrix (#3725)

This commit is contained in:
Johannes Marbach 2022-10-11 21:14:14 +02:00 committed by GitHub
parent 853163f615
commit ffd3b4cdbd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 50 additions and 24 deletions

View File

@ -248,20 +248,16 @@ void lv_obj_set_height(lv_obj_t * obj, lv_coord_t h)
void lv_obj_set_content_width(lv_obj_t * obj, lv_coord_t w)
{
lv_coord_t pleft = lv_obj_get_style_pad_left(obj, LV_PART_MAIN);
lv_coord_t pright = lv_obj_get_style_pad_right(obj, LV_PART_MAIN);
lv_coord_t border_width = lv_obj_get_style_border_width(obj, LV_PART_MAIN);
lv_obj_set_width(obj, w + pleft + pright + 2 * border_width);
lv_coord_t left = lv_obj_get_style_space_left(obj, LV_PART_MAIN);
lv_coord_t right = lv_obj_get_style_space_right(obj, LV_PART_MAIN);
lv_obj_set_width(obj, w + left + right);
}
void lv_obj_set_content_height(lv_obj_t * obj, lv_coord_t h)
{
lv_coord_t ptop = lv_obj_get_style_pad_top(obj, LV_PART_MAIN);
lv_coord_t pbottom = lv_obj_get_style_pad_bottom(obj, LV_PART_MAIN);
lv_coord_t border_width = lv_obj_get_style_border_width(obj, LV_PART_MAIN);
lv_obj_set_height(obj, h + ptop + pbottom + 2 * border_width);
lv_coord_t top = lv_obj_get_style_space_top(obj, LV_PART_MAIN);
lv_coord_t bottom = lv_obj_get_style_space_bottom(obj, LV_PART_MAIN);
lv_obj_set_height(obj, h + top + bottom);
}
void lv_obj_set_layout(lv_obj_t * obj, uint32_t layout)
@ -570,22 +566,20 @@ lv_coord_t lv_obj_get_content_width(const lv_obj_t * obj)
{
LV_ASSERT_OBJ(obj, MY_CLASS);
lv_coord_t left = lv_obj_get_style_pad_left(obj, LV_PART_MAIN);
lv_coord_t right = lv_obj_get_style_pad_right(obj, LV_PART_MAIN);
lv_coord_t border_width = lv_obj_get_style_border_width(obj, LV_PART_MAIN);
lv_coord_t left = lv_obj_get_style_space_left(obj, LV_PART_MAIN);
lv_coord_t right = lv_obj_get_style_space_right(obj, LV_PART_MAIN);
return lv_obj_get_width(obj) - left - right - 2 * border_width;
return lv_obj_get_width(obj) - left - right;
}
lv_coord_t lv_obj_get_content_height(const lv_obj_t * obj)
{
LV_ASSERT_OBJ(obj, MY_CLASS);
lv_coord_t top = lv_obj_get_style_pad_top(obj, LV_PART_MAIN);
lv_coord_t bottom = lv_obj_get_style_pad_bottom(obj, LV_PART_MAIN);
lv_coord_t border_width = lv_obj_get_style_border_width(obj, LV_PART_MAIN);
lv_coord_t top = lv_obj_get_style_space_top(obj, LV_PART_MAIN);
lv_coord_t bottom = lv_obj_get_style_space_bottom(obj, LV_PART_MAIN);
return lv_obj_get_height(obj) - top - bottom - 2 * border_width;
return lv_obj_get_height(obj) - top - bottom;
}
void lv_obj_get_content_coords(const lv_obj_t * obj, lv_area_t * area)

View File

@ -232,6 +232,38 @@ static inline void lv_obj_set_style_size(struct _lv_obj_t * obj, lv_coord_t widt
lv_obj_set_style_height(obj, height, selector);
}
static inline lv_coord_t lv_obj_get_style_space_left(const struct _lv_obj_t * obj, uint32_t part)
{
lv_coord_t padding = lv_obj_get_style_pad_left(obj, part);
lv_coord_t border_width = lv_obj_get_style_border_width(obj, part);
lv_border_side_t border_side = lv_obj_get_style_border_side(obj, part);
return (border_side & LV_BORDER_SIDE_LEFT) ? padding + border_width : padding;
}
static inline lv_coord_t lv_obj_get_style_space_right(const struct _lv_obj_t * obj, uint32_t part)
{
lv_coord_t padding = lv_obj_get_style_pad_right(obj, part);
lv_coord_t border_width = lv_obj_get_style_border_width(obj, part);
lv_border_side_t border_side = lv_obj_get_style_border_side(obj, part);
return (border_side & LV_BORDER_SIDE_RIGHT) ? padding + border_width : padding;
}
static inline lv_coord_t lv_obj_get_style_space_top(const struct _lv_obj_t * obj, uint32_t part)
{
lv_coord_t padding = lv_obj_get_style_pad_top(obj, part);
lv_coord_t border_width = lv_obj_get_style_border_width(obj, part);
lv_border_side_t border_side = lv_obj_get_style_border_side(obj, part);
return (border_side & LV_BORDER_SIDE_TOP) ? padding + border_width : padding;
}
static inline lv_coord_t lv_obj_get_style_space_bottom(const struct _lv_obj_t * obj, uint32_t part)
{
lv_coord_t padding = lv_obj_get_style_pad_bottom(obj, part);
lv_coord_t border_width = lv_obj_get_style_border_width(obj, part);
lv_border_side_t border_side = lv_obj_get_style_border_side(obj, part);
return (border_side & LV_BORDER_SIDE_BOTTOM) ? padding + border_width : padding;
}
lv_text_align_t lv_obj_calculate_style_text_align(const struct _lv_obj_t * obj, lv_part_t part, const char * txt);

View File

@ -104,8 +104,8 @@ void lv_btnmatrix_set_map(lv_obj_t * obj, const char * map[])
lv_base_dir_t base_dir = lv_obj_get_style_base_dir(obj, LV_PART_MAIN);
/*Set size and positions of the buttons*/
lv_coord_t pleft = lv_obj_get_style_pad_left(obj, LV_PART_MAIN);
lv_coord_t ptop = lv_obj_get_style_pad_top(obj, LV_PART_MAIN);
lv_coord_t sleft = lv_obj_get_style_space_left(obj, LV_PART_MAIN);
lv_coord_t stop = lv_obj_get_style_space_top(obj, LV_PART_MAIN);
lv_coord_t prow = lv_obj_get_style_pad_row(obj, LV_PART_MAIN);
lv_coord_t pcol = lv_obj_get_style_pad_column(obj, LV_PART_MAIN);
@ -138,8 +138,8 @@ void lv_btnmatrix_set_map(lv_obj_t * obj, const char * map[])
continue;
}
lv_coord_t row_y1 = ptop + (max_h_no_gap * row) / btnm->row_cnt + row * prow;
lv_coord_t row_y2 = ptop + (max_h_no_gap * (row + 1)) / btnm->row_cnt + row * prow - 1;
lv_coord_t row_y1 = stop + (max_h_no_gap * row) / btnm->row_cnt + row * prow;
lv_coord_t row_y2 = stop + (max_h_no_gap * (row + 1)) / btnm->row_cnt + row * prow - 1;
/*Set the button size and positions*/
lv_coord_t max_w_no_gap = max_w - (pcol * (btn_cnt - 1));
@ -163,8 +163,8 @@ void lv_btnmatrix_set_map(lv_obj_t * obj, const char * map[])
btn_x2 = max_w - btn_x2;
}
btn_x1 += pleft;
btn_x2 += pleft;
btn_x1 += sleft;
btn_x2 += sleft;
lv_area_set(&btnm->button_areas[btn_tot_i], btn_x1, row_y1, btn_x2, row_y2);

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.5 KiB

After

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 16 KiB