mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-14 06:42:58 +08:00
feat(coords) follow CCS border-box model
This commit is contained in:
parent
ee14b00398
commit
e9388c1aa0
@ -274,16 +274,18 @@ 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);
|
||||
lv_obj_set_width(obj, w + pleft + pright + 2 * border_width);
|
||||
}
|
||||
|
||||
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);
|
||||
lv_obj_set_height(obj, h + ptop + pbottom + 2 * border_width);
|
||||
}
|
||||
|
||||
void lv_obj_set_layout(lv_obj_t * obj, uint32_t layout)
|
||||
@ -506,6 +508,7 @@ lv_coord_t lv_obj_get_x(const lv_obj_t * obj)
|
||||
rel_x = obj->coords.x1 - parent->coords.x1;
|
||||
rel_x += lv_obj_get_scroll_x(parent);
|
||||
rel_x -= lv_obj_get_style_pad_left(parent, LV_PART_MAIN);
|
||||
rel_x -= lv_obj_get_style_border_width(parent, LV_PART_MAIN);
|
||||
}
|
||||
else {
|
||||
rel_x = obj->coords.x1;
|
||||
@ -530,6 +533,7 @@ lv_coord_t lv_obj_get_y(const lv_obj_t * obj)
|
||||
rel_y = obj->coords.y1 - parent->coords.y1;
|
||||
rel_y += lv_obj_get_scroll_y(parent);
|
||||
rel_y -= lv_obj_get_style_pad_top(parent, LV_PART_MAIN);
|
||||
rel_y -= lv_obj_get_style_border_width(parent, LV_PART_MAIN);
|
||||
}
|
||||
else {
|
||||
rel_y = obj->coords.y1;
|
||||
@ -564,8 +568,9 @@ lv_coord_t lv_obj_get_content_width(const lv_obj_t * obj)
|
||||
|
||||
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);
|
||||
|
||||
return lv_obj_get_width(obj) - left - right;
|
||||
return lv_obj_get_width(obj) - left - right - 2 * border_width;
|
||||
}
|
||||
|
||||
lv_coord_t lv_obj_get_content_height(const lv_obj_t * obj)
|
||||
@ -574,15 +579,18 @@ lv_coord_t lv_obj_get_content_height(const lv_obj_t * obj)
|
||||
|
||||
lv_coord_t top = lv_obj_get_style_pad_top((lv_obj_t *)obj, LV_PART_MAIN);
|
||||
lv_coord_t bottom = lv_obj_get_style_pad_bottom((lv_obj_t *)obj, LV_PART_MAIN);
|
||||
lv_coord_t border_width = lv_obj_get_style_border_width(obj, LV_PART_MAIN);
|
||||
|
||||
return lv_obj_get_height(obj) - top - bottom;
|
||||
return lv_obj_get_height(obj) - top - bottom - 2 * border_width;
|
||||
}
|
||||
|
||||
void lv_obj_get_content_coords(const lv_obj_t * obj, lv_area_t * area)
|
||||
{
|
||||
LV_ASSERT_OBJ(obj, MY_CLASS);
|
||||
lv_coord_t border_width = lv_obj_get_style_border_width(obj, LV_PART_MAIN);
|
||||
|
||||
lv_obj_get_coords(obj, area);
|
||||
lv_area_increase(area, -border_width, -border_width);
|
||||
area->x1 += lv_obj_get_style_pad_left(obj, LV_PART_MAIN);
|
||||
area->x2 -= lv_obj_get_style_pad_right(obj, LV_PART_MAIN);
|
||||
area->y1 += lv_obj_get_style_pad_top(obj, LV_PART_MAIN);
|
||||
@ -703,6 +711,10 @@ void lv_obj_move_to(lv_obj_t * obj, lv_coord_t x, lv_coord_t y)
|
||||
x += pad_left + parent->coords.x1 - lv_obj_get_scroll_x(parent);
|
||||
y += pad_top + parent->coords.y1 - lv_obj_get_scroll_y(parent);
|
||||
}
|
||||
|
||||
lv_coord_t border_width = lv_obj_get_style_border_width(parent, LV_PART_MAIN);
|
||||
x += border_width;
|
||||
y += border_width;
|
||||
}
|
||||
|
||||
/*Calculate and set the movement*/
|
||||
|
@ -145,11 +145,12 @@ lv_coord_t lv_obj_get_scroll_bottom(lv_obj_t * obj)
|
||||
|
||||
lv_coord_t pad_top = lv_obj_get_style_pad_top(obj, LV_PART_MAIN);
|
||||
lv_coord_t pad_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);
|
||||
|
||||
child_res -= (obj->coords.y2 - pad_bottom);
|
||||
child_res -= (obj->coords.y2 - pad_bottom - border_width);
|
||||
|
||||
lv_coord_t self_h = lv_obj_get_self_height(obj);
|
||||
self_h = self_h - (lv_obj_get_height(obj) - pad_top - pad_bottom);
|
||||
self_h = self_h - (lv_obj_get_height(obj) - pad_top - pad_bottom - 2 * border_width);
|
||||
self_h -= lv_obj_get_scroll_y(obj);
|
||||
return LV_MAX(child_res, self_h);
|
||||
}
|
||||
|
@ -432,8 +432,9 @@ void lv_dropdown_open(lv_obj_t * dropdown_obj)
|
||||
}
|
||||
|
||||
lv_coord_t label_h = lv_obj_get_height(label);
|
||||
lv_coord_t top = lv_obj_get_style_pad_top(dropdown->list, LV_PART_MAIN);
|
||||
lv_coord_t bottom = lv_obj_get_style_pad_bottom(dropdown->list, LV_PART_MAIN);
|
||||
lv_coord_t border_width = lv_obj_get_style_border_width(dropdown->list, LV_PART_MAIN);
|
||||
lv_coord_t top = lv_obj_get_style_pad_top(dropdown->list, LV_PART_MAIN) + border_width;
|
||||
lv_coord_t bottom = lv_obj_get_style_pad_bottom(dropdown->list, LV_PART_MAIN) + border_width;
|
||||
|
||||
lv_coord_t list_fit_h = label_h + top + bottom;
|
||||
lv_coord_t list_h = list_fit_h;
|
||||
@ -723,9 +724,10 @@ static void draw_main(lv_event_t * e)
|
||||
lv_dropdown_t * dropdown = (lv_dropdown_t *)obj;
|
||||
const lv_area_t * clip_area = lv_event_get_param(e);
|
||||
|
||||
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 top = lv_obj_get_style_pad_top(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_pad_left(obj, LV_PART_MAIN) + border_width;
|
||||
lv_coord_t right = lv_obj_get_style_pad_right(obj, LV_PART_MAIN) + border_width;
|
||||
lv_coord_t top = lv_obj_get_style_pad_top(obj, LV_PART_MAIN) + border_width;
|
||||
|
||||
lv_draw_label_dsc_t symbol_dsc;
|
||||
lv_draw_label_dsc_init(&symbol_dsc);
|
||||
|
@ -581,7 +581,6 @@ static void refr_position(lv_obj_t * obj, lv_anim_enable_t anim_en)
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
lv_roller_t * roller = (lv_roller_t*)obj;
|
||||
const lv_font_t * font = lv_obj_get_style_text_font(obj, LV_PART_MAIN);
|
||||
lv_coord_t line_space = lv_obj_get_style_text_line_space(obj, LV_PART_MAIN);
|
||||
@ -620,7 +619,6 @@ static void refr_position(lv_obj_t * obj, lv_anim_enable_t anim_en)
|
||||
|
||||
static lv_res_t release_handler(lv_obj_t * obj)
|
||||
{
|
||||
|
||||
lv_obj_t * label = get_label(obj);
|
||||
if(label == NULL) return LV_RES_OK;
|
||||
|
||||
|
@ -1040,7 +1040,7 @@ static void start_cursor_blink(lv_obj_t * obj)
|
||||
|
||||
static void refr_cursor_area(lv_obj_t * obj)
|
||||
{
|
||||
lv_textarea_t * ta = (lv_textarea_t *)obj;
|
||||
lv_textarea_t * ta = (lv_textarea_t *)obj;
|
||||
|
||||
const lv_font_t * font = lv_obj_get_style_text_font(obj, LV_PART_MAIN);
|
||||
lv_coord_t line_space = lv_obj_get_style_text_line_space(obj, LV_PART_MAIN);
|
||||
@ -1271,12 +1271,10 @@ static void draw_placeholder(lv_event_t * e)
|
||||
|
||||
lv_coord_t left = lv_obj_get_style_pad_left(obj, LV_PART_MAIN);
|
||||
lv_coord_t top = lv_obj_get_style_pad_top(obj, LV_PART_MAIN);
|
||||
lv_coord_t border_width = lv_obj_get_style_border_width(obj, LV_PART_MAIN);
|
||||
lv_area_t ph_coords;
|
||||
lv_area_copy(&ph_coords, &obj->coords);
|
||||
ph_coords.x1 += left;
|
||||
ph_coords.x2 += left;
|
||||
ph_coords.y1 += top;
|
||||
ph_coords.y2 += top;
|
||||
lv_area_move(&ph_coords, left + border_width, top + border_width);
|
||||
lv_draw_label(&ph_coords, clip_area, &ph_dsc, ta->placeholder_txt, NULL);
|
||||
}
|
||||
}
|
||||
@ -1311,8 +1309,9 @@ static void draw_cursor(lv_event_t * e)
|
||||
if(cur_dsc.bg_opa == LV_OPA_COVER) {
|
||||
lv_coord_t left = lv_obj_get_style_pad_left(obj, LV_PART_CURSOR);
|
||||
lv_coord_t top = lv_obj_get_style_pad_top(obj, LV_PART_CURSOR);
|
||||
cur_area.x1 += left;
|
||||
cur_area.y1 += top;
|
||||
lv_coord_t border_width = lv_obj_get_style_border_width(obj, LV_PART_MAIN);
|
||||
cur_area.x1 += left + border_width;
|
||||
cur_area.y1 += top + border_width;
|
||||
|
||||
lv_draw_label_dsc_t cur_label_dsc;
|
||||
lv_draw_label_dsc_init(&cur_label_dsc);
|
||||
|
Loading…
x
Reference in New Issue
Block a user