From 7947a991a46dabd0c2981087ab4bf9151b735a43 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Fri, 21 Dec 2018 15:25:45 +0100 Subject: [PATCH] lv_draw_label: optimization --- lv_draw/lv_draw_label.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/lv_draw/lv_draw_label.c b/lv_draw/lv_draw_label.c index d8b0c0e29..b19be78d6 100644 --- a/lv_draw/lv_draw_label.c +++ b/lv_draw/lv_draw_label.c @@ -69,15 +69,29 @@ void lv_draw_label(const lv_area_t * coords, const lv_area_t * mask, const lv_st w = p.x; } + lv_coord_t line_height = lv_font_get_height(font) + style->text.line_space; + + /*Init variables for the first line*/ lv_coord_t line_width = 0; - uint32_t line_start = 0; - uint32_t line_end = lv_txt_get_next_line(txt, font, style->text.letter_space, w, flag); - lv_point_t pos; pos.x = coords->x1; pos.y = coords->y1; + uint32_t line_start = 0; + uint32_t line_end = lv_txt_get_next_line(txt, font, style->text.letter_space, w, flag); + + /*Go the first visible line*/ + while(pos.y + line_height < mask->y1) { + /*Go to next line*/ + line_start = line_end; + line_end += lv_txt_get_next_line(&txt[line_start], font, style->text.letter_space, w, flag); + pos.y += line_height; + + if(txt[line_start] == '\0') return; + } + + printf("\n"); /*Align to middle*/ if(flag & LV_TXT_FLAG_CENTER) { line_width = lv_txt_get_width(&txt[line_start], line_end - line_start, @@ -115,7 +129,6 @@ void lv_draw_label(const lv_area_t * coords, const lv_area_t * mask, const lv_st lv_rletter_set_background(style->body.main_color); #endif - lv_coord_t line_height = lv_font_get_height(font) + style->text.line_space; /*Write out all lines*/ while(txt[line_start] != '\0') { @@ -129,8 +142,6 @@ void lv_draw_label(const lv_area_t * coords, const lv_area_t * mask, const lv_st while(i < line_end) { letter = lv_txt_encoded_next(txt, &i); - if(pos.y + line_height < mask->y1) continue; - /*Handle the re-color command*/ if((flag & LV_TXT_FLAG_RECOLOR) != 0) { if(letter == (uint32_t)LV_TXT_COLOR_CMD[0]) {