1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-14 06:42:58 +08:00

perf(label): add size cache for get self size event (#3546)

Signed-off-by: pengyiqiang <pengyiqiang@xiaomi.com>

Co-authored-by: pengyiqiang <pengyiqiang@xiaomi.com>
This commit is contained in:
_VIFEXTech 2022-08-10 00:07:08 +08:00 committed by GitHub
parent 87456815a1
commit ed4df8c1bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 14 deletions

View File

@ -763,8 +763,9 @@ static void lv_label_event(const lv_obj_class_t * class_p, lv_event_t * e)
lv_label_refr_text(obj);
}
else if(code == LV_EVENT_GET_SELF_SIZE) {
lv_point_t size;
lv_label_t * label = (lv_label_t *)obj;
if(label->invalid_size_cache) {
const lv_font_t * font = lv_obj_get_style_text_font(obj, LV_PART_MAIN);
lv_coord_t letter_space = lv_obj_get_style_text_letter_space(obj, LV_PART_MAIN);
lv_coord_t line_space = lv_obj_get_style_text_line_space(obj, LV_PART_MAIN);
@ -776,11 +777,13 @@ static void lv_label_event(const lv_obj_class_t * class_p, lv_event_t * e)
if(lv_obj_get_style_width(obj, LV_PART_MAIN) == LV_SIZE_CONTENT && !obj->w_layout) w = LV_COORD_MAX;
else w = lv_obj_get_content_width(obj);
lv_txt_get_size(&size, label->text, font, letter_space, line_space, w, flag);
lv_txt_get_size(&label->size_cache, label->text, font, letter_space, line_space, w, flag);
label->invalid_size_cache = false;
}
lv_point_t * self_size = lv_event_get_param(e);
self_size->x = LV_MAX(self_size->x, size.x);
self_size->y = LV_MAX(self_size->y, size.y);
self_size->x = LV_MAX(self_size->x, label->size_cache.x);
self_size->y = LV_MAX(self_size->y, label->size_cache.y);
}
else if(code == LV_EVENT_DRAW_MAIN) {
draw_main(e);
@ -899,6 +902,7 @@ static void lv_label_refr_text(lv_obj_t * obj)
#if LV_LABEL_LONG_TXT_HINT
label->hint.line_start = -1; /*The hint is invalid if the text changes*/
#endif
label->invalid_size_cache = true;
lv_area_t txt_coords;
lv_obj_get_content_coords(obj, &txt_coords);

View File

@ -68,12 +68,14 @@ typedef struct {
uint32_t sel_end;
#endif
lv_point_t size_cache; /*Text size cache*/
lv_point_t offset; /*Text draw position offset*/
lv_label_long_mode_t long_mode : 3; /*Determine what to do with the long texts*/
uint8_t static_txt : 1; /*Flag to indicate the text is static*/
uint8_t recolor : 1; /*Enable in-line letter re-coloring*/
uint8_t expand : 1; /*Ignore real width (used by the library with LV_LABEL_LONG_SCROLL)*/
uint8_t dot_tmp_alloc : 1; /*1: dot is allocated, 0: dot directly holds up to 4 chars*/
uint8_t invalid_size_cache : 1; /*1: Recalculate size and update cache*/
} lv_label_t;
extern const lv_obj_class_t lv_label_class;