From 666653efe7cff4e7693d1a771df0327241f96eef Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Fri, 19 Mar 2021 16:01:26 +0100 Subject: [PATCH] fix(refresh): do not redraw the whole object if only part's style changes on a new state --- examples/porting/lv_port_disp_template.c | 14 +++++++------- examples/porting/lv_port_fs_template.c | 2 +- examples/porting/lv_port_indev_template.c | 2 +- examples/widgets/textarea/lv_example_textarea_1.c | 5 ++++- src/core/lv_obj_style.h | 2 +- src/draw/lv_draw_label.c | 2 +- src/font/lv_font_fmt_txt.c | 6 +++++- src/hal/lv_hal_disp.c | 2 +- src/hal/lv_hal_disp.h | 2 +- src/misc/lv_style.h | 2 +- tests/build.py | 4 +++- 11 files changed, 26 insertions(+), 17 deletions(-) diff --git a/examples/porting/lv_port_disp_template.c b/examples/porting/lv_port_disp_template.c index 0294104cc..74c009df7 100644 --- a/examples/porting/lv_port_disp_template.c +++ b/examples/porting/lv_port_disp_template.c @@ -76,27 +76,27 @@ void lv_port_disp_init(void) */ /* Example for 1) */ - static lv_draw_buf_t draw_buf_dsc_1; + static lv_disp_draw_buf_t draw_buf_dsc_1; static lv_color_t buf_1[MY_DISP_HOR_RES * 10]; /*A buffer for 10 rows*/ - lv_draw_buf_init(&draw_buf_dsc_1, buf_1, NULL, MY_DISP_HOR_RES * 10); /*Initialize the display buffer*/ + lv_disp_draw_buf_init(&draw_buf_dsc_1, buf_1, NULL, MY_DISP_HOR_RES * 10); /*Initialize the display buffer*/ /* Example for 2) */ - static lv_draw_buf_t draw_buf_dsc_2; + static lv_disp_draw_buf_t draw_buf_dsc_2; static lv_color_t buf_2_1[MY_DISP_HOR_RES * 10]; /*A buffer for 10 rows*/ static lv_color_t buf_2_1[MY_DISP_HOR_RES * 10]; /*An other buffer for 10 rows*/ - lv_draw_buf_init(&draw_buf_dsc_2, buf_2_1, buf_2_1, MY_DISP_HOR_RES * 10); /*Initialize the display buffer*/ + lv_disp_draw_buf_init(&draw_buf_dsc_2, buf_2_1, buf_2_1, MY_DISP_HOR_RES * 10); /*Initialize the display buffer*/ /* Example for 3) */ - static lv_draw_buf_t draw_buf_dsc_3; + static lv_disp_draw_buf_t draw_buf_dsc_3; static lv_color_t buf_3_1[MY_DISP_HOR_RES * MY_DISP_VER_RES]; /*A screen sized buffer*/ static lv_color_t buf_3_1[MY_DISP_HOR_RES * MY_DISP_VER_RES]; /*An other screen sized buffer*/ - lv_draw_buf_init(&draw_buf_dsc_3, buf_3_1, buf_3_2, MY_DISP_VER_RES * LV_VER_RES_MAX); /*Initialize the display buffer*/ + lv_disp_draw_buf_init(&draw_buf_dsc_3, buf_3_1, buf_3_2, MY_DISP_VER_RES * LV_VER_RES_MAX); /*Initialize the display buffer*/ /*----------------------------------- * Register the display in LVGL *----------------------------------*/ - lv_disp_drv_t disp_drv; /*Descriptor of a display driver*/ + static lv_disp_drv_t disp_drv; /*Descriptor of a display driver*/ lv_disp_drv_init(&disp_drv); /*Basic initialization*/ /*Set up the functions to access to your display*/ diff --git a/examples/porting/lv_port_fs_template.c b/examples/porting/lv_port_fs_template.c index b73508bc1..864980149 100644 --- a/examples/porting/lv_port_fs_template.c +++ b/examples/porting/lv_port_fs_template.c @@ -84,7 +84,7 @@ void lv_port_fs_init(void) *--------------------------------------------------*/ /*Add a simple drive to open images*/ - lv_fs_drv_t fs_drv; + static lv_fs_drv_t fs_drv; lv_fs_drv_init(&fs_drv); /*Set up fields...*/ diff --git a/examples/porting/lv_port_indev_template.c b/examples/porting/lv_port_indev_template.c index 7a209d872..2a6320cdd 100644 --- a/examples/porting/lv_port_indev_template.c +++ b/examples/porting/lv_port_indev_template.c @@ -80,7 +80,7 @@ void lv_port_indev_init(void) * You should shape them according to your hardware */ - lv_indev_drv_t indev_drv; + static lv_indev_drv_t indev_drv; /*------------------ * Touchpad diff --git a/examples/widgets/textarea/lv_example_textarea_1.c b/examples/widgets/textarea/lv_example_textarea_1.c index 353144061..39a3db24b 100644 --- a/examples/widgets/textarea/lv_example_textarea_1.c +++ b/examples/widgets/textarea/lv_example_textarea_1.c @@ -18,10 +18,13 @@ static void btnm_event_handler(lv_obj_t * obj, lv_event_t event) void lv_example_textarea_1(void) { lv_obj_t * ta = lv_textarea_create(lv_scr_act(), NULL); -// lv_textarea_set_one_line(ta, true); + lv_textarea_set_text(ta, "asd"); lv_obj_align(ta, NULL, LV_ALIGN_IN_TOP_MID, 0, 10); lv_obj_add_state(ta, LV_STATE_FOCUSED); /*To be sure the cursor is visible*/ +// lv_obj_set_style_text_align(ta, LV_PART_MAIN, LV_STATE_DEFAULT, LV_TEXT_ALIGN_CENTER); + lv_obj_set_style_text_align(lv_textarea_get_label(ta), LV_PART_MAIN, LV_STATE_DEFAULT, LV_TEXT_ALIGN_CENTER); + static const char * btnm_map[] = {"1", "2", "3", "\n", "4", "5", "6", "\n", "7", "8", "9", "\n", diff --git a/src/core/lv_obj_style.h b/src/core/lv_obj_style.h index 1700958ea..d17ee6113 100644 --- a/src/core/lv_obj_style.h +++ b/src/core/lv_obj_style.h @@ -4,7 +4,7 @@ */ #ifndef LV_OBJ_STYLE_H -#define LV_OB_STYLE_H +#define LV_OBJ_STYLE_H #ifdef __cplusplus extern "C" { diff --git a/src/draw/lv_draw_label.c b/src/draw/lv_draw_label.c index c9d926fa2..2d3930195 100644 --- a/src/draw/lv_draw_label.c +++ b/src/draw/lv_draw_label.c @@ -671,7 +671,7 @@ static void draw_letter_subpx(lv_coord_t pos_x, lv_coord_t pos_y, lv_font_glyph_ lv_color_t * color_buf = lv_mem_buf_get(mask_buf_size * sizeof(lv_color_t)); lv_disp_t * disp = _lv_refr_get_disp_refreshing(); - lv_draw_buf_t * draw_buf = lv_disp_get_draw_buf(disp); + lv_disp_draw_buf_t * draw_buf = lv_disp_get_draw_buf(disp); int32_t disp_buf_width = lv_area_get_width(&draw_buf->area); lv_color_t * disp_buf_buf_tmp = draw_buf->buf_act; diff --git a/src/font/lv_font_fmt_txt.c b/src/font/lv_font_fmt_txt.c index 6c5b8994d..780e090e9 100644 --- a/src/font/lv_font_fmt_txt.c +++ b/src/font/lv_font_fmt_txt.c @@ -92,6 +92,9 @@ const uint8_t * lv_font_get_bitmap_fmt_txt(const lv_font_t * font, uint32_t unic /*Handle compressed bitmap*/ else { #if LV_USE_FONT_COMPRESSED + static size_t last_buf_size = 0; + if(LV_GC_ROOT(_lv_font_decompr_buf) == NULL) last_buf_size = 0; + uint32_t gsize = gdsc->box_w * gdsc->box_h; if(gsize == 0) return NULL; @@ -112,11 +115,12 @@ const uint8_t * lv_font_get_bitmap_fmt_txt(const lv_font_t * font, uint32_t unic break; } - if(lv_mem_get_size(LV_GC_ROOT(_lv_font_decompr_buf)) < buf_size) { + if(last_buf_size < buf_size) { uint8_t * tmp = lv_mem_realloc(LV_GC_ROOT(_lv_font_decompr_buf), buf_size); LV_ASSERT_MALLOC(tmp); if(tmp == NULL) return NULL; LV_GC_ROOT(_lv_font_decompr_buf) = tmp; + last_buf_size = buf_size; } bool prefilter = fdsc->bitmap_format == LV_FONT_FMT_TXT_COMPRESSED ? true : false; diff --git a/src/hal/lv_hal_disp.c b/src/hal/lv_hal_disp.c index 9bb994f9c..82cb80911 100644 --- a/src/hal/lv_hal_disp.c +++ b/src/hal/lv_hal_disp.c @@ -66,7 +66,7 @@ void lv_disp_drv_init(lv_disp_drv_t * driver) /** * Initialize a display buffer - * @param draw_buf pointer `lv_draw_buf_t` variable to initialize + * @param draw_buf pointer `lv_disp_draw_buf_t` variable to initialize * @param buf1 A buffer to be used by LVGL to draw the image. * Always has to specified and can't be NULL. * Can be an array allocated by the user. E.g. `static lv_color_t disp_buf1[1024 * 10]` diff --git a/src/hal/lv_hal_disp.h b/src/hal/lv_hal_disp.h index d7d111695..27c152402 100644 --- a/src/hal/lv_hal_disp.h +++ b/src/hal/lv_hal_disp.h @@ -194,7 +194,7 @@ void lv_disp_drv_init(lv_disp_drv_t * driver); /** * Initialize a display buffer - * @param draw_buf pointer `lv_draw_buf_t` variable to initialize + * @param draw_buf pointer `lv_disp_draw_buf_t` variable to initialize * @param buf1 A buffer to be used by LVGL to draw the image. * Always has to specified and can't be NULL. * Can be an array allocated by the user. E.g. `static lv_color_t disp_buf1[1024 * 10]` diff --git a/src/misc/lv_style.h b/src/misc/lv_style.h index 16b4496f6..018f757dc 100644 --- a/src/misc/lv_style.h +++ b/src/misc/lv_style.h @@ -203,7 +203,7 @@ typedef enum { LV_STYLE_TEXT_LETTER_SPACE = 90 | LV_STYLE_PROP_INHERIT | LV_STYLE_PROP_LAYOUT_REFR, LV_STYLE_TEXT_LINE_SPACE = 91 | LV_STYLE_PROP_INHERIT | LV_STYLE_PROP_LAYOUT_REFR, LV_STYLE_TEXT_DECOR = 92 | LV_STYLE_PROP_INHERIT, - LV_STYLE_TEXT_ALIGN = 93 | LV_STYLE_PROP_INHERIT, + LV_STYLE_TEXT_ALIGN = 93 | LV_STYLE_PROP_INHERIT | LV_STYLE_PROP_LAYOUT_REFR, /*Group 6*/ LV_STYLE_CONTENT_TEXT = 96 | LV_STYLE_PROP_EXT_DRAW, diff --git a/tests/build.py b/tests/build.py index a9c199b11..12d318f25 100755 --- a/tests/build.py +++ b/tests/build.py @@ -127,6 +127,7 @@ minimal_16bit_swap = { "LV_FONT_UNSCII_8":1, + "LV_USE_FONT_SUBPX": 1, "LV_USE_BIDI": 0, "LV_USE_ARABIC_PERSIAN_CHARS":0, @@ -147,6 +148,7 @@ full_32bit = { "LV_USE_LOG":1, "LV_LOG_PRINTF":1, + "LV_USE_FONT_SUBPX": 1, "LV_FONT_SUBPX_BGR":1, "LV_USE_PERF_MONITOR":1, @@ -188,7 +190,7 @@ full_32bit = { "LV_FONT_UNSCII_8":1, "LV_FONT_UNSCII_16":1, "LV_FONT_FMT_TXT_LARGE":1, - "LV_FONT_FMT_TXT_LARGE":1, + "LV_USE_FONT_COMPRESSED":1, "LV_USE_BIDI": 1, "LV_USE_ARABIC_PERSIAN_CHARS":1,