From fc29f58754f84c8d9e9cb59b8b5f7e0a2a6b8f8b Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Mon, 9 Dec 2019 14:34:53 +0100 Subject: [PATCH 01/28] fix _WIN64 test (has only on underscore) --- src/lv_misc/lv_types.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lv_misc/lv_types.h b/src/lv_misc/lv_types.h index c588e2451..2c28bca1e 100644 --- a/src/lv_misc/lv_types.h +++ b/src/lv_misc/lv_types.h @@ -18,7 +18,7 @@ extern "C" { * DEFINES *********************/ // Check windows -#ifdef __WIN64 +#ifdef _WIN64 #define LV_ARCH_64 #endif From efeec7d3b6ae9d69648eca5f0f75953518f3067b Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Mon, 9 Dec 2019 14:35:13 +0100 Subject: [PATCH 02/28] minor conversion fixes to eliminate warnings --- src/lv_misc/lv_mem.c | 4 ++-- src/lv_objx/lv_gauge.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lv_misc/lv_mem.c b/src/lv_misc/lv_mem.c index 71e6a1b1d..da38554e4 100644 --- a/src/lv_misc/lv_mem.c +++ b/src/lv_misc/lv_mem.c @@ -456,11 +456,11 @@ static void ent_trunc(lv_mem_ent_t * e, size_t size) uint8_t * e_data = &e->first_data; lv_mem_ent_t * after_new_e = (lv_mem_ent_t *)&e_data[size]; after_new_e->header.s.used = 0; - after_new_e->header.s.d_size = e->header.s.d_size - size - sizeof(lv_mem_header_t); + after_new_e->header.s.d_size = (uint32_t)e->header.s.d_size - size - sizeof(lv_mem_header_t); } /* Set the new size for the original entry */ - e->header.s.d_size = size; + e->header.s.d_size = (uint32_t)size; } #endif diff --git a/src/lv_objx/lv_gauge.h b/src/lv_objx/lv_gauge.h index fb7cf366a..408c1125a 100644 --- a/src/lv_objx/lv_gauge.h +++ b/src/lv_objx/lv_gauge.h @@ -193,7 +193,7 @@ uint8_t lv_gauge_get_label_count(const lv_obj_t * gauge); * @param gauge pointer to a gauge object * @return number of the scale units */ -static inline uint8_t lv_gauge_get_line_count(const lv_obj_t * gauge) +static inline uint16_t lv_gauge_get_line_count(const lv_obj_t * gauge) { return lv_lmeter_get_line_count(gauge); } From cdc2cf90ce66fc4f309ae7564f61fdce33dc7257 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Tue, 10 Dec 2019 15:06:26 +0100 Subject: [PATCH 03/28] lv_color.h: fix Wconversion warnings --- src/lv_misc/lv_color.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/lv_misc/lv_color.h b/src/lv_misc/lv_color.h index dc861690c..b98ec0b61 100644 --- a/src/lv_misc/lv_color.h +++ b/src/lv_misc/lv_color.h @@ -104,9 +104,9 @@ enum { # define LV_COLOR_GET_B1(c) (c).ch.blue # define LV_COLOR_GET_A1(c) 1 -# define LV_COLOR_SET_R8(c, v) (c).ch.red = (uint8_t)((v) & 0x7); -# define LV_COLOR_SET_G8(c, v) (c).ch.green = (uint8_t)((v) & 0x7); -# define LV_COLOR_SET_B8(c, v) (c).ch.blue = (uint8_t)((v) & 0x3); +# define LV_COLOR_SET_R8(c, v) (c).ch.red = (uint8_t)(v) & 0x7U; +# define LV_COLOR_SET_G8(c, v) (c).ch.green = (uint8_t)(v) & 0x7U; +# define LV_COLOR_SET_B8(c, v) (c).ch.blue = (uint8_t)(v) & 0x3U; # define LV_COLOR_SET_A8(c, v) do {} while(0) # define LV_COLOR_GET_R8(c) (c).ch.red @@ -114,10 +114,10 @@ enum { # define LV_COLOR_GET_B8(c) (c).ch.blue # define LV_COLOR_GET_A8(c) 0xFF -# define LV_COLOR_SET_R16(c, v) (c).ch.red = (uint8_t)(((uint8_t)(v)) & 0x1F); -# define LV_COLOR_SET_G16(c, v) (c).ch.green = (uint8_t)((v) & 0x3F); +# define LV_COLOR_SET_R16(c, v) (c).ch.red = (uint8_t)(v) & 0x1FU; +# define LV_COLOR_SET_G16(c, v) (c).ch.green = (uint8_t)(v) & 0x3FU; # define LV_COLOR_SET_G16_SWAP(c, v) {(c).ch.green_h = (uint8_t)(((v) >> 3) & 0x7); (c).ch.green_l = (uint8_t)((v) & 0x7);} -# define LV_COLOR_SET_B16(c, v) (c).ch.blue = (uint8_t)((v) & 0x1F); +# define LV_COLOR_SET_B16(c, v) (c).ch.blue = (uint8_t)(v) & 0x1FU; # define LV_COLOR_SET_A16(c, v) do {} while(0) # define LV_COLOR_GET_R16(c) (c).ch.red @@ -464,14 +464,14 @@ static inline uint8_t lv_color_brightness(lv_color_t color) /* The most simple macro to create a color from R,G and B values */ #if LV_COLOR_DEPTH == 1 -#define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){.full = (b8 >> 7 | g8 >> 7 | r8 >> 7)}) +#define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){.full = ((b8 >> 7) | (g8 >> 7) | (r8 >> 7))}) #elif LV_COLOR_DEPTH == 8 -#define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){{b8 >> 6, g8 >> 5, r8 >> 5}}) +#define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){{(b8 >> 6) & 0x3U, (g8 >> 5) & 0x7U, (r8 >> 5) & 0x7U}}) #elif LV_COLOR_DEPTH == 16 #if LV_COLOR_16_SWAP == 0 -#define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){{b8 >> 3, g8 >> 2, r8 >> 3}}) +#define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){{(b8 >> 3) & 0x1FU, (g8 >> 2) & 0x3FU, (r8 >> 3) & 0x1FU}}) #else -#define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){{g8 >> 5, r8 >> 3, b8 >> 3, (g8 >> 2) & 0x7}}) +#define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){{(g8 >> 5) & 0x7U, (r8 >> 3) & 0x1FU, (b8 >> 3) & 0x1FU, (g8 >> 2) & 0x7U}}) #endif #elif LV_COLOR_DEPTH == 32 #define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){{b8, g8, r8, 0xff}}) /*Fix 0xff alpha*/ From f54ecc470cde598c56488809bac0e42f1fc5b58b Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Wed, 11 Dec 2019 05:33:44 +0100 Subject: [PATCH 04/28] fix text processing with negative letter space --- src/lv_misc/lv_txt.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/lv_misc/lv_txt.c b/src/lv_misc/lv_txt.c index 929fb7511..cc2ba45d5 100644 --- a/src/lv_misc/lv_txt.c +++ b/src/lv_misc/lv_txt.c @@ -200,6 +200,10 @@ static uint16_t lv_txt_get_next_word(const char * txt, const lv_font_t * font, letter_w = lv_font_get_glyph_width(font, letter, letter_next); cur_w += letter_w; + if(letter_w > 0) { + cur_w += letter_space; + } + /* Test if this character fits within max_width */ if(break_index == NO_BREAK_FOUND && cur_w > max_width) { break_index = i; @@ -219,9 +223,6 @@ static uint16_t lv_txt_get_next_word(const char * txt, const lv_font_t * font, /* Update the output width */ if( word_w_ptr != NULL && break_index == NO_BREAK_FOUND ) *word_w_ptr = cur_w; - if(letter_w > 0) { - cur_w += letter_space; - } i = i_next; i_next = i_next_next; From 30539a51ec53ed43c6e66c42cd0e6031c3086525 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patryk=20Krzywdzi=C5=84ski?= Date: Fri, 13 Dec 2019 15:46:55 +0100 Subject: [PATCH 05/28] Cursor need shift to left after merge pull request #1220 --- src/lv_objx/lv_spinbox.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lv_objx/lv_spinbox.c b/src/lv_objx/lv_spinbox.c index 42c229c21..6873085a2 100644 --- a/src/lv_objx/lv_spinbox.c +++ b/src/lv_objx/lv_spinbox.c @@ -405,11 +405,15 @@ static void lv_spinbox_updatevalue(lv_obj_t * spinbox) char buf[LV_SPINBOX_MAX_DIGIT_COUNT + 8]; memset(buf, 0, sizeof(buf)); char * buf_p = buf; + uint8_t cur_shift_left = 0; if (ext->range_min < 0) { // hide sign if there are only positive values /*Add the sign*/ (*buf_p) = ext->value >= 0 ? '+' : '-'; buf_p++; + } else { + /*Cursor need shift to left*/ + cur_shift_left++; } int32_t i; @@ -467,7 +471,7 @@ static void lv_spinbox_updatevalue(lv_obj_t * spinbox) if(cur_pos > intDigits) cur_pos++; /*Skip teh decimal point*/ - cur_pos += ext->digit_padding_left; + cur_pos += (ext->digit_padding_left - cur_shift_left); lv_ta_set_cursor_pos(spinbox, cur_pos); } From d6e4c2f50c2be6a56960a748358ff443e94a71cd Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Sat, 14 Dec 2019 10:49:06 +0100 Subject: [PATCH 06/28] img_cache: for a match, besides src check style too --- src/lv_draw/lv_img_cache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lv_draw/lv_img_cache.c b/src/lv_draw/lv_img_cache.c index 5ca48e438..841e11693 100644 --- a/src/lv_draw/lv_img_cache.c +++ b/src/lv_draw/lv_img_cache.c @@ -85,7 +85,7 @@ lv_img_cache_entry_t * lv_img_cache_open(const void * src, const lv_style_t * st bool match = false; lv_img_src_t src_type = lv_img_src_get_type(cache[i].dec_dsc.src); if(src_type == LV_IMG_SRC_VARIABLE) { - if(cache[i].dec_dsc.src == src) match = true; + if(cache[i].dec_dsc.src == src && cache[i].dec_dsc.style == style) match = true; } else if(src_type == LV_IMG_SRC_FILE) { if(strcmp(cache[i].dec_dsc.src, src) == 0) match = true; } From 1e4883ffc7a8e0edac28fa126a43746242f0f49a Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Mon, 16 Dec 2019 06:14:34 +0100 Subject: [PATCH 07/28] lv_page_creeate: fix false positive assert --- src/lv_objx/lv_page.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/lv_objx/lv_page.c b/src/lv_objx/lv_page.c index b0d308d65..e9a21a2fe 100644 --- a/src/lv_objx/lv_page.c +++ b/src/lv_objx/lv_page.c @@ -150,16 +150,16 @@ lv_obj_t * lv_page_create(lv_obj_t * par, const lv_obj_t * copy) ext->scrl = lv_cont_create(new_page, copy_ext->scrl); lv_obj_set_signal_cb(ext->scrl, lv_page_scrollable_signal); - lv_page_set_sb_mode(new_page, copy_ext->sb.mode); + /* Add the signal function only if 'scrolling' is created + * because everything has to be ready before any signal is received*/ + lv_obj_set_signal_cb(new_page, lv_page_signal); + lv_obj_set_design_cb(new_page, lv_page_design); lv_page_set_style(new_page, LV_PAGE_STYLE_BG, lv_page_get_style(copy, LV_PAGE_STYLE_BG)); lv_page_set_style(new_page, LV_PAGE_STYLE_SCRL, lv_page_get_style(copy, LV_PAGE_STYLE_SCRL)); lv_page_set_style(new_page, LV_PAGE_STYLE_SB, lv_page_get_style(copy, LV_PAGE_STYLE_SB)); - /* Add the signal function only if 'scrolling' is created - * because everything has to be ready before any signal is received*/ - lv_obj_set_signal_cb(new_page, lv_page_signal); - lv_obj_set_design_cb(new_page, lv_page_design); + lv_page_set_sb_mode(new_page, copy_ext->sb.mode); /*Refresh the style with new signal function*/ lv_obj_refresh_style(new_page); From 5f4f516befa81c7eb69857e071fa49841b309f46 Mon Sep 17 00:00:00 2001 From: hannes Date: Mon, 16 Dec 2019 13:34:10 +0100 Subject: [PATCH 08/28] Fix problem: letter space is not regarded in width calculation --- src/lv_misc/lv_txt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lv_misc/lv_txt.c b/src/lv_misc/lv_txt.c index cc2ba45d5..23c05b907 100644 --- a/src/lv_misc/lv_txt.c +++ b/src/lv_misc/lv_txt.c @@ -205,7 +205,7 @@ static uint16_t lv_txt_get_next_word(const char * txt, const lv_font_t * font, } /* Test if this character fits within max_width */ - if(break_index == NO_BREAK_FOUND && cur_w > max_width) { + if(break_index == NO_BREAK_FOUND && (cur_w - letter_space) > max_width) { break_index = i; break_letter_count = word_len - 1; /* break_index is now pointing at the character that doesn't fit */ From f8c67bcc12c14449ec3051a3596fe0986ae52331 Mon Sep 17 00:00:00 2001 From: xennex22 <25083624+xennex22@users.noreply.github.com> Date: Mon, 16 Dec 2019 07:46:33 -0800 Subject: [PATCH 09/28] made lv_slider_draw_knob params const --- src/lv_objx/lv_slider.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lv_objx/lv_slider.c b/src/lv_objx/lv_slider.c index 79a00042f..1b5343969 100644 --- a/src/lv_objx/lv_slider.c +++ b/src/lv_objx/lv_slider.c @@ -33,7 +33,7 @@ static lv_design_res_t lv_slider_design(lv_obj_t * slider, const lv_area_t * clip_area, lv_design_mode_t mode); static lv_res_t lv_slider_signal(lv_obj_t * slider, lv_signal_t sign, void * param); static void lv_slider_position_knob(lv_obj_t * slider, lv_area_t * knob_area, lv_coord_t knob_size, bool hor); -static void lv_slider_draw_knob(lv_obj_t * slider, lv_area_t * knob_area, lv_area_t * clip_area); +static void lv_slider_draw_knob(lv_obj_t * slider, const lv_area_t * knob_area, const lv_area_t * clip_area); /********************** * STATIC VARIABLES @@ -491,7 +491,7 @@ static void lv_slider_position_knob(lv_obj_t * slider, lv_area_t * knob_area, lv knob_area->y2 += style_knob->body.padding.bottom; } -static void lv_slider_draw_knob(lv_obj_t * slider, lv_area_t * knob_area, lv_area_t * clip_area) { +static void lv_slider_draw_knob(lv_obj_t * slider, const lv_area_t * knob_area, const lv_area_t * clip_area) { lv_slider_ext_t * ext = lv_obj_get_ext_attr(slider); const lv_style_t * style_knob = lv_slider_get_style(slider, LV_SLIDER_STYLE_KNOB); lv_opa_t opa_scale = lv_obj_get_opa_scale(slider); From 145864f8725f90142d91d86364fda6eb3038d519 Mon Sep 17 00:00:00 2001 From: xennex22 <25083624+xennex22@users.noreply.github.com> Date: Mon, 16 Dec 2019 07:48:40 -0800 Subject: [PATCH 10/28] made default kb maps const also changed "Bksp" -> LV_SYMBOL_BACKSPACE --- src/lv_objx/lv_kb.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lv_objx/lv_kb.c b/src/lv_objx/lv_kb.c index 28e2614cf..4f23ad0b7 100644 --- a/src/lv_objx/lv_kb.c +++ b/src/lv_objx/lv_kb.c @@ -36,7 +36,7 @@ static void lv_kb_updatemap(lv_obj_t * kb); **********************/ static lv_signal_cb_t ancestor_signal; /* clang-format off */ -static const char * default_kb_map_lc[] = {"1#", "q", "w", "e", "r", "t", "y", "u", "i", "o", "p", LV_SYMBOL_BACKSPACE, "\n", +static const char * const default_kb_map_lc[] = {"1#", "q", "w", "e", "r", "t", "y", "u", "i", "o", "p", LV_SYMBOL_BACKSPACE, "\n", "ABC", "a", "s", "d", "f", "g", "h", "j", "k", "l", LV_SYMBOL_NEW_LINE, "\n", "_", "-", "z", "x", "c", "v", "b", "n", "m", ".", ",", ":", "\n", LV_SYMBOL_CLOSE, LV_SYMBOL_LEFT, " ", LV_SYMBOL_RIGHT, LV_SYMBOL_OK, ""}; @@ -47,7 +47,7 @@ static const lv_btnm_ctrl_t default_kb_ctrl_lc_map[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, LV_KB_CTRL_BTN_FLAGS | 2, 2, 6, 2, LV_KB_CTRL_BTN_FLAGS | 2}; -static const char * default_kb_map_uc[] = {"1#", "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", LV_SYMBOL_BACKSPACE, "\n", +static const char * const default_kb_map_uc[] = {"1#", "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", LV_SYMBOL_BACKSPACE, "\n", "abc", "A", "S", "D", "F", "G", "H", "J", "K", "L", LV_SYMBOL_NEW_LINE, "\n", "_", "-", "Z", "X", "C", "V", "B", "N", "M", ".", ",", ":", "\n", LV_SYMBOL_CLOSE, LV_SYMBOL_LEFT, " ", LV_SYMBOL_RIGHT, LV_SYMBOL_OK, ""}; @@ -58,7 +58,7 @@ static const lv_btnm_ctrl_t default_kb_ctrl_uc_map[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, LV_KB_CTRL_BTN_FLAGS | 2, 2, 6, 2, LV_KB_CTRL_BTN_FLAGS | 2}; -static const char * default_kb_map_spec[] = {"0", "1", "2", "3", "4" ,"5", "6", "7", "8", "9", "Bksp", "\n", +static const char * const default_kb_map_spec[] = {"0", "1", "2", "3", "4" ,"5", "6", "7", "8", "9", LV_SYMBOL_BACKSPACE, "\n", "abc", "+", "-", "/", "*", "=", "%", "!", "?", "#", "<", ">", "\n", "\\", "@", "$", "(", ")", "{", "}", "[", "]", ";", "\"", "'", "\n", LV_SYMBOL_CLOSE, LV_SYMBOL_LEFT, " ", LV_SYMBOL_RIGHT, LV_SYMBOL_OK, ""}; From 92a0ef4be38e54bdd85b0e8a26af76107e09e95b Mon Sep 17 00:00:00 2001 From: xennex22 <25083624+xennex22@users.noreply.github.com> Date: Mon, 16 Dec 2019 07:49:22 -0800 Subject: [PATCH 11/28] removed repeated line --- src/lv_objx/lv_chart.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/lv_objx/lv_chart.c b/src/lv_objx/lv_chart.c index 20ea4980e..44d2ee2b8 100644 --- a/src/lv_objx/lv_chart.c +++ b/src/lv_objx/lv_chart.c @@ -188,8 +188,6 @@ lv_chart_series_t * lv_chart_add_series(lv_obj_t * chart, lv_color_t color) lv_coord_t def = LV_CHART_POINT_DEF; - if(ser == NULL) return NULL; - ser->color = color; ser->points = lv_mem_alloc(sizeof(lv_coord_t) * ext->point_cnt); LV_ASSERT_MEM(ser->points); From 63009588c0706fef581058ef5be209e04ed264fe Mon Sep 17 00:00:00 2001 From: xennex22 <25083624+xennex22@users.noreply.github.com> Date: Mon, 16 Dec 2019 07:51:07 -0800 Subject: [PATCH 12/28] removed unused function prototype --- src/lv_core/lv_indev.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lv_core/lv_indev.c b/src/lv_core/lv_indev.c index 45496a1eb..14579f071 100644 --- a/src/lv_core/lv_indev.c +++ b/src/lv_core/lv_indev.c @@ -39,7 +39,6 @@ static void indev_button_proc(lv_indev_t * i, lv_indev_data_t * data); static void indev_proc_press(lv_indev_proc_t * proc); static void indev_proc_release(lv_indev_proc_t * proc); static void indev_proc_reset_query_handler(lv_indev_t * indev); -static lv_obj_t * indev_search_obj(const lv_indev_proc_t * proc, lv_obj_t * obj); static void indev_drag(lv_indev_proc_t * proc); static void indev_drag_throw(lv_indev_proc_t * proc); static lv_obj_t * get_dragged_obj(lv_obj_t * obj); From 9f447e8a4e5ec2ac5e0b95dc59fab61c3564afd6 Mon Sep 17 00:00:00 2001 From: xennex22 <25083624+xennex22@users.noreply.github.com> Date: Mon, 16 Dec 2019 07:53:18 -0800 Subject: [PATCH 13/28] changed fn ptr return type from false to NULL --- src/lv_core/lv_group.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lv_core/lv_group.c b/src/lv_core/lv_group.c index fc8bfda49..eb74a8977 100644 --- a/src/lv_core/lv_group.c +++ b/src/lv_core/lv_group.c @@ -442,7 +442,7 @@ lv_group_user_data_t * lv_group_get_user_data(lv_group_t * group) */ lv_group_style_mod_cb_t lv_group_get_style_mod_cb(const lv_group_t * group) { - if(!group) return false; + if(!group) return NULL; return group->style_mod_cb; } @@ -453,7 +453,7 @@ lv_group_style_mod_cb_t lv_group_get_style_mod_cb(const lv_group_t * group) */ lv_group_style_mod_cb_t lv_group_get_style_mod_edit_cb(const lv_group_t * group) { - if(!group) return false; + if(!group) return NULL; return group->style_mod_edit_cb; } @@ -464,7 +464,7 @@ lv_group_style_mod_cb_t lv_group_get_style_mod_edit_cb(const lv_group_t * group) */ lv_group_focus_cb_t lv_group_get_focus_cb(const lv_group_t * group) { - if(!group) return false; + if(!group) return NULL; return group->focus_cb; } From dd9d655b3ddb91feaae5341ae7d6c78974aae8c3 Mon Sep 17 00:00:00 2001 From: xennex22 <25083624+xennex22@users.noreply.github.com> Date: Mon, 16 Dec 2019 07:54:26 -0800 Subject: [PATCH 14/28] removed redundent line --- src/lv_objx/lv_chart.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lv_objx/lv_chart.c b/src/lv_objx/lv_chart.c index 44d2ee2b8..7e2134bb7 100644 --- a/src/lv_objx/lv_chart.c +++ b/src/lv_objx/lv_chart.c @@ -931,7 +931,6 @@ static void lv_chart_draw_points(lv_obj_t * chart, const lv_area_t * mask) lv_style_copy(&style_point, &lv_style_plain); style_point.body.border.width = 0; - style_point.body.radius = LV_RADIUS_CIRCLE; style_point.body.opa = ext->series.opa; style_point.body.radius = ext->series.width; From 226e566ebd9e873d33ba4448fe6c88ddaee2c13b Mon Sep 17 00:00:00 2001 From: xennex22 <25083624+xennex22@users.noreply.github.com> Date: Mon, 16 Dec 2019 07:55:19 -0800 Subject: [PATCH 15/28] removed redundent test for NULL --- src/lv_misc/lv_ll.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lv_misc/lv_ll.c b/src/lv_misc/lv_ll.c index 8e2d612f8..57cbfa418 100644 --- a/src/lv_misc/lv_ll.c +++ b/src/lv_misc/lv_ll.c @@ -136,7 +136,6 @@ void * lv_ll_ins_tail(lv_ll_t * ll_p) lv_ll_node_t * n_new; n_new = lv_mem_alloc(ll_p->n_size + LL_NODE_META_SIZE); - if(n_new == NULL) return NULL; if(n_new != NULL) { node_set_next(ll_p, n_new, NULL); /*No next after the new tail*/ From 8e5446c68fae524dfe7dae16042b8460e99a0605 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Thu, 19 Dec 2019 11:14:51 +0100 Subject: [PATCH 16/28] add lv_anim_refr_now() --- src/lv_core/lv_refr.c | 2 ++ src/lv_misc/lv_anim.c | 11 +++++++++++ src/lv_misc/lv_anim.h | 8 ++++++++ 3 files changed, 21 insertions(+) diff --git a/src/lv_core/lv_refr.c b/src/lv_core/lv_refr.c index d8d4ce6c0..6a3affcda 100644 --- a/src/lv_core/lv_refr.c +++ b/src/lv_core/lv_refr.c @@ -73,6 +73,8 @@ void lv_refr_init(void) */ void lv_refr_now(lv_disp_t * disp) { + lv_anim_refr_now(); + if(disp) { lv_disp_refr_task(disp->refr_task); } else { diff --git a/src/lv_misc/lv_anim.c b/src/lv_misc/lv_anim.c index 073ba7831..197959262 100644 --- a/src/lv_misc/lv_anim.c +++ b/src/lv_misc/lv_anim.c @@ -172,6 +172,17 @@ uint16_t lv_anim_speed_to_time(uint16_t speed, lv_anim_value_t start, lv_anim_va return time; } +/** + * Manually refresh the state of the animations. + * Useful to make the animations running in a blocking process where + * `lv_task_handler` can't run for a while. + * Shouldn't be used directly because it is called in `lv_refr_now()`. + */ +void lv_anim_refr_now(void) +{ + anim_task(NULL); +} + /** * Calculate the current value of an animation applying linear characteristic * @param a pointer to an animation diff --git a/src/lv_misc/lv_anim.h b/src/lv_misc/lv_anim.h index 36cc35adc..95fd6acea 100644 --- a/src/lv_misc/lv_anim.h +++ b/src/lv_misc/lv_anim.h @@ -268,6 +268,14 @@ uint16_t lv_anim_count_running(void); */ uint16_t lv_anim_speed_to_time(uint16_t speed, lv_anim_value_t start, lv_anim_value_t end); +/** + * Manually refresh the state of the animations. + * Useful to make the animations running in a blocking process where + * `lv_task_handler` can't run for a while. + * Shouldn't be used directly because it is called in `lv_refr_now()`. + */ +void lv_anim_refr_now(void); + /** * Calculate the current value of an animation applying linear characteristic * @param a pointer to an animation From b01df265eef798a3b3be50cfffadf3feb0146047 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Thu, 19 Dec 2019 14:10:36 +0100 Subject: [PATCH 17/28] lv_sw: fix knob size calculation --- src/lv_objx/lv_sw.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lv_objx/lv_sw.c b/src/lv_objx/lv_sw.c index 095c961bf..4427cc2a6 100644 --- a/src/lv_objx/lv_sw.c +++ b/src/lv_objx/lv_sw.c @@ -545,8 +545,8 @@ static lv_res_t lv_sw_signal(lv_obj_t * sw, lv_signal_t sign, void * param) lv_res_t res; res = lv_img_decoder_get_info(ext->img_knob_off, &info); if(res == LV_RES_OK) { - knob_off_size = LV_MATH_MAX(knob_on_size, info.w / 2); - knob_off_size = LV_MATH_MAX(knob_on_size, info.h / 2); + knob_off_size = LV_MATH_MAX(knob_off_size, info.w / 2); + knob_off_size = LV_MATH_MAX(knob_off_size, info.h / 2); } else { LV_LOG_WARN("slider signal (LV_SIGNAL_REFR_EXT_DRAW_PAD): can't get knob image info") } From 73cb9d45d789bcb12843437e769eac97d40c6c04 Mon Sep 17 00:00:00 2001 From: Themba Dube Date: Thu, 19 Dec 2019 16:21:39 -0500 Subject: [PATCH 18/28] Fix improper position calculation for bar indicator --- src/lv_objx/lv_bar.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/lv_objx/lv_bar.c b/src/lv_objx/lv_bar.c index 1eab6e313..53cebf11e 100644 --- a/src/lv_objx/lv_bar.c +++ b/src/lv_objx/lv_bar.c @@ -203,6 +203,7 @@ void lv_bar_set_range(lv_obj_t * bar, int16_t min, int16_t max) ext->max_value = max; ext->min_value = min; + dprintf("bar type %u\n", lv_bar_get_type(bar)); if(lv_bar_get_type(bar) != LV_BAR_TYPE_CUSTOM) ext->start_value = min; @@ -539,7 +540,7 @@ static void draw_indic(lv_obj_t * bar, const lv_area_t * clip_area, lv_design_mo ext->indic_area.x2 = zero; } } else { - lv_coord_t increment = (anim_start_value * indicw) / range; + lv_coord_t increment = ((anim_start_value-ext->min_value) * indicw) / range; ext->indic_area.x1 += increment; ext->indic_area.x2 += increment; } @@ -557,7 +558,7 @@ static void draw_indic(lv_obj_t * bar, const lv_area_t * clip_area, lv_design_mo ext->indic_area.y1 = zero; } } else { - lv_coord_t increment = (anim_start_value * objh) / range; + lv_coord_t increment = ((anim_start_value-ext->min_value) * objh) / range; ext->indic_area.y1 += increment; ext->indic_area.y2 += increment; } From cba91119e31a78e2feb9f4168b16ec4f615bb3de Mon Sep 17 00:00:00 2001 From: Themba Dube Date: Thu, 19 Dec 2019 16:34:10 -0500 Subject: [PATCH 19/28] Add public API for retrieving option_cnt from ddlist/roller --- src/lv_objx/lv_ddlist.c | 14 ++++++++++++++ src/lv_objx/lv_ddlist.h | 7 +++++++ src/lv_objx/lv_roller.c | 18 ++++++++++++++++++ src/lv_objx/lv_roller.h | 7 +++++++ 4 files changed, 46 insertions(+) diff --git a/src/lv_objx/lv_ddlist.c b/src/lv_objx/lv_ddlist.c index 8b67ec876..46c8936e0 100644 --- a/src/lv_objx/lv_ddlist.c +++ b/src/lv_objx/lv_ddlist.c @@ -375,6 +375,20 @@ uint16_t lv_ddlist_get_selected(const lv_obj_t * ddlist) return ext->sel_opt_id; } +/** + * Get the total number of options + * @param ddlist pointer to drop down list object + * @return the total number of options in the list + */ +uint16_t lv_ddlist_get_option_cnt(const lv_obj_t * ddlist) +{ + LV_ASSERT_OBJ(ddlist, LV_OBJX_NAME); + + lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); + + return ext->option_cnt; +} + /** * Get the current selected option as a string * @param ddlist pointer to ddlist object diff --git a/src/lv_objx/lv_ddlist.h b/src/lv_objx/lv_ddlist.h index 774b52cef..e4d918b17 100644 --- a/src/lv_objx/lv_ddlist.h +++ b/src/lv_objx/lv_ddlist.h @@ -176,6 +176,13 @@ const char * lv_ddlist_get_options(const lv_obj_t * ddlist); */ uint16_t lv_ddlist_get_selected(const lv_obj_t * ddlist); +/** + * Get the total number of options + * @param ddlist pointer to drop down list object + * @return the total number of options in the list + */ +uint16_t lv_ddlist_get_option_cnt(const lv_obj_t * ddlist); + /** * Get the current selected option as a string * @param ddlist pointer to ddlist object diff --git a/src/lv_objx/lv_roller.c b/src/lv_objx/lv_roller.c index 6038dacbe..6b1d33e36 100644 --- a/src/lv_objx/lv_roller.c +++ b/src/lv_objx/lv_roller.c @@ -276,6 +276,24 @@ uint16_t lv_roller_get_selected(const lv_obj_t * roller) } } +/** + * Get the total number of options + * @param roller pointer to a roller object + * @return the total number of options + */ +uint16_t lv_roller_get_option_cnt(const lv_obj_t * roller) +{ + LV_ASSERT_OBJ(roller, LV_OBJX_NAME); + + lv_roller_ext_t * ext = lv_obj_get_ext_attr(roller); + if(ext->mode == LV_ROLLER_MODE_INIFINITE) { + uint16_t real_id_cnt = ext->ddlist.option_cnt / LV_ROLLER_INF_PAGES; + return real_id_cnt; + } else { + return ext->ddlist.option_cnt; + } +} + /** * Get the align attribute. Default alignment after _create is LV_LABEL_ALIGN_CENTER * @param roller pointer to a roller object diff --git a/src/lv_objx/lv_roller.h b/src/lv_objx/lv_roller.h index 5303c3aa1..6375d34c1 100644 --- a/src/lv_objx/lv_roller.h +++ b/src/lv_objx/lv_roller.h @@ -146,6 +146,13 @@ void lv_roller_set_style(lv_obj_t * roller, lv_roller_style_t type, const lv_sty */ uint16_t lv_roller_get_selected(const lv_obj_t * roller); +/** + * Get the total number of options + * @param roller pointer to a roller object + * @return the total number of options in the list + */ +uint16_t lv_roller_get_option_cnt(const lv_obj_t * roller); + /** * Get the current selected option as a string * @param roller pointer to roller object From 0a3a8cc2d6ed387505fe2e7b03bf6fad0b2ad32e Mon Sep 17 00:00:00 2001 From: Themba Dube Date: Thu, 19 Dec 2019 16:36:29 -0500 Subject: [PATCH 20/28] Remove leftover debugging statements --- src/lv_objx/lv_bar.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/lv_objx/lv_bar.c b/src/lv_objx/lv_bar.c index 53cebf11e..f8f992135 100644 --- a/src/lv_objx/lv_bar.c +++ b/src/lv_objx/lv_bar.c @@ -203,9 +203,8 @@ void lv_bar_set_range(lv_obj_t * bar, int16_t min, int16_t max) ext->max_value = max; ext->min_value = min; - dprintf("bar type %u\n", lv_bar_get_type(bar)); - if(lv_bar_get_type(bar) != LV_BAR_TYPE_CUSTOM) - ext->start_value = min; + if(lv_bar_get_type(bar) != LV_BAR_TYPE_CUSTOM) + ext->start_value = min; if(ext->cur_value > max) { ext->cur_value = max; From 1441601e3e594a60b9458ccf4507680070c23ca2 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Sat, 21 Dec 2019 20:25:30 +0100 Subject: [PATCH 21/28] list layout fixes --- src/lv_objx/lv_list.c | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/src/lv_objx/lv_list.c b/src/lv_objx/lv_list.c index cf18e73fa..54fe16a26 100644 --- a/src/lv_objx/lv_list.c +++ b/src/lv_objx/lv_list.c @@ -179,6 +179,13 @@ lv_obj_t * lv_list_add_btn(lv_obj_t * list, const void * img_src, const char * t { LV_ASSERT_OBJ(list, LV_OBJX_NAME); + lv_obj_t * last_btn = lv_list_get_prev_btn(list, NULL); + + /*The coordinates may changed due to autofit so revert them at the end*/ + lv_coord_t pos_x_ori = lv_obj_get_x(list); + lv_coord_t pos_y_ori = lv_obj_get_y(list); + + lv_list_ext_t * ext = lv_obj_get_ext_attr(list); ext->size++; /*Create a list element with the image an the text*/ @@ -197,7 +204,22 @@ lv_obj_t * lv_list_add_btn(lv_obj_t * list, const void * img_src, const char * t lv_page_glue_obj(liste, true); lv_btn_set_layout(liste, LV_LAYOUT_ROW_M); - lv_btn_set_fit2(liste, LV_FIT_FLOOD, LV_FIT_TIGHT); + + lv_layout_t list_layout = lv_list_get_layout(list); + bool layout_ver = false; + if(list_layout == LV_LAYOUT_COL_M || list_layout == LV_LAYOUT_COL_L || list_layout == LV_LAYOUT_COL_R) { + layout_ver = true; + } + + if(layout_ver) { + lv_btn_set_fit2(liste, LV_FIT_FLOOD, LV_FIT_TIGHT); + } else { + lv_coord_t w = last_btn ? lv_obj_get_width(last_btn) : (LV_DPI * 3) / 2; + lv_btn_set_fit2(liste, LV_FIT_NONE, LV_FIT_TIGHT); + lv_obj_set_width(liste, w); + } + + lv_obj_set_protect(liste, LV_PROTECT_PRESS_LOST); lv_obj_set_signal_cb(liste, lv_list_btn_signal); @@ -233,6 +255,8 @@ lv_obj_t * lv_list_add_btn(lv_obj_t * list, const void * img_src, const char * t } #endif + lv_obj_set_pos(list, pos_x_ori, pos_y_ori); + return liste; } @@ -399,16 +423,23 @@ void lv_list_set_style(lv_obj_t * list, lv_list_style_t type, const lv_style_t * while(btn != NULL) { /*If a column layout set the buttons' width to list width*/ if(layout == LV_LAYOUT_COL_M || layout == LV_LAYOUT_COL_L || layout == LV_LAYOUT_COL_R) { - lv_btn_set_fit2(list, LV_FIT_FLOOD, LV_FIT_TIGHT); + lv_btn_set_fit2(btn, LV_FIT_FLOOD, LV_FIT_TIGHT); } /*If a row layout set the buttons' width according to the content*/ else if (layout == LV_LAYOUT_ROW_M || layout == LV_LAYOUT_ROW_T || layout == LV_LAYOUT_ROW_B) { - lv_btn_set_fit(list, LV_FIT_TIGHT); + lv_btn_set_fit(btn, LV_FIT_TIGHT); } btn = lv_list_get_prev_btn(list, btn); } + if(layout == LV_LAYOUT_COL_M || layout == LV_LAYOUT_COL_L || layout == LV_LAYOUT_COL_R) { + lv_page_set_scrl_fit2(list, LV_FIT_FLOOD, LV_FIT_TIGHT); + } else if (layout == LV_LAYOUT_ROW_M || layout == LV_LAYOUT_ROW_T || layout == LV_LAYOUT_ROW_B) { + lv_page_set_scrl_fit2(list, LV_FIT_TIGHT, LV_FIT_TIGHT); + lv_cont_set_fit2(list, LV_FIT_NONE, LV_FIT_TIGHT); + } + lv_page_set_scrl_layout(list, layout); } From 7175231aabcbe19e58681a1f2d7df1f816c3ddec Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Sat, 21 Dec 2019 20:27:01 +0100 Subject: [PATCH 22/28] tileview: call drag_end_handler only if it was dragging --- src/lv_objx/lv_tileview.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lv_objx/lv_tileview.c b/src/lv_objx/lv_tileview.c index 184bcbd58..cd2f83d0c 100644 --- a/src/lv_objx/lv_tileview.c +++ b/src/lv_objx/lv_tileview.c @@ -486,9 +486,9 @@ static void tileview_scrl_event_cb(lv_obj_t * scrl, lv_event_t event) lv_tileview_ext_t * ext = lv_obj_get_ext_attr(tileview); if(lv_indev_is_dragging(indev) && (ext->drag_hor || ext->drag_ver)) { indev->proc.types.pointer.drag_in_prog = 0; + drag_end_handler(tileview); } - drag_end_handler(tileview); } } From 638666f6855ad372cf645690e4d30a031ce32b4b Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Sat, 21 Dec 2019 20:36:19 +0100 Subject: [PATCH 23/28] fix include in lv_api_map.h --- src/lv_api_map.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lv_api_map.h b/src/lv_api_map.h index 18164398e..904dcf93d 100644 --- a/src/lv_api_map.h +++ b/src/lv_api_map.h @@ -13,7 +13,7 @@ extern "C" { /********************* * INCLUDES *********************/ -#include "lvgl/lvgl.h" +#include "../lvgl.h" /********************* * DEFINES From af1453400dd1004129d1e67b0a78d75ac1a26b2b Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Sat, 21 Dec 2019 20:48:44 +0100 Subject: [PATCH 24/28] lv_label: bidi fixes --- src/lv_objx/lv_label.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lv_objx/lv_label.c b/src/lv_objx/lv_label.c index a581fead7..de2a5359d 100644 --- a/src/lv_objx/lv_label.c +++ b/src/lv_objx/lv_label.c @@ -674,7 +674,7 @@ void lv_label_get_letter_pos(const lv_obj_t * label, uint16_t char_id, lv_point_ pos->y = y; #if LV_USE_BIDI - if(mutable_bidi_txt) lv_mem_free(mutable_bidi_txt); + if(mutable_bidi_txt) lv_mem_buf_release(mutable_bidi_txt); #endif } @@ -978,8 +978,8 @@ void lv_label_ins_text(lv_obj_t * label, uint32_t pos, const char * txt) lv_mem_buf_release(bidi_buf); #else lv_txt_ins(ext->text, pos, txt); - lv_label_refr_text(label); #endif + lv_label_refr_text(label); } /** From a010412fde0ec1e2ed755ce3ab2d9579eb5bce8d Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Sat, 21 Dec 2019 21:50:41 +0100 Subject: [PATCH 25/28] roller: fix misalignment if the new options has the same width as the previous --- src/lv_objx/lv_roller.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lv_objx/lv_roller.c b/src/lv_objx/lv_roller.c index e556beed5..4d21bbad6 100644 --- a/src/lv_objx/lv_roller.c +++ b/src/lv_objx/lv_roller.c @@ -149,8 +149,9 @@ void lv_roller_set_options(lv_obj_t * roller, const char * options, lv_roller_mo /* Make sure the roller's height and the scrollable's height is refreshed. * They are refreshed in `LV_SIGNAL_COORD_CHG` but if the new options has the same width - * that signal won't be called. (It called because LV_FIT_TIGHT hor fit)*/ + * that signal won't be called. (It's called because of LV_FIT_TIGHT hor fit)*/ refr_height(roller); + refr_position(roller, LV_ANIM_OFF); } else { ext->mode = LV_ROLLER_MODE_INIFINITE; From 65d79a79059fc7fee81b63dae0d06ff559490c61 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Sat, 21 Dec 2019 22:11:28 +0100 Subject: [PATCH 26/28] img zoom fix when computing with the edge pixels --- a.txt | 127 --------------------------------------- src/lv_draw/lv_img_buf.c | 8 +-- 2 files changed, 4 insertions(+), 131 deletions(-) delete mode 100644 a.txt diff --git a/a.txt b/a.txt deleted file mode 100644 index 5644f9f94..000000000 --- a/a.txt +++ /dev/null @@ -1,127 +0,0 @@ -diff --git a/src/lv_draw/lv_draw_img.c b/src/lv_draw/lv_draw_img.c -index f28c47eb..74f73686 100644 ---- a/src/lv_draw/lv_draw_img.c -+++ b/src/lv_draw/lv_draw_img.c -@@ -406,7 +406,7 @@ static void lv_draw_map(const lv_area_t * map_area, const lv_area_t * clip_area, - trans_dsc.cfg.pivot_x = map_w / 2; - trans_dsc.cfg.pivot_y = map_h / 2; - trans_dsc.cfg.color = style->image.color; -- trans_dsc.cfg.antialias = antialaias; -+ trans_dsc.cfg.antialias = true; - - lv_img_buf_transform_init(&trans_dsc); - } -diff --git a/src/lv_draw/lv_img_buf.c b/src/lv_draw/lv_img_buf.c -index 2b79c7b1..89a57708 100644 ---- a/src/lv_draw/lv_img_buf.c -+++ b/src/lv_draw/lv_img_buf.c -@@ -161,6 +161,68 @@ lv_opa_t lv_img_buf_get_px_alpha(lv_img_dsc_t * dsc, lv_coord_t x, lv_coord_t y) - return LV_OPA_COVER; - } - -+/** -+ * Set the color of a pixel of an image. The alpha channel won't be affected. -+ * @param dsc pointer to an image descriptor -+ * @param x x coordinate of the point to set -+ * @param y x coordinate of the point to set -+ * @param c color of the point -+ * @param safe true: check out of bounds -+ */ -+void lv_img_buf_set_px_color(lv_img_dsc_t * dsc, lv_coord_t x, lv_coord_t y, lv_color_t c) -+{ -+ uint8_t * buf_u8 = (uint8_t *)dsc->data; -+ -+ if(dsc->header.cf == LV_IMG_CF_TRUE_COLOR || dsc->header.cf == LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED) { -+ uint8_t px_size = lv_img_cf_get_px_size(dsc->header.cf) >> 3; -+ uint32_t px = dsc->header.w * y * px_size + x * px_size; -+ memcpy(&buf_u8[px], &c, px_size); -+ } else if(dsc->header.cf == LV_IMG_CF_TRUE_COLOR_ALPHA) { -+ uint8_t px_size = lv_img_cf_get_px_size(dsc->header.cf) >> 3; -+ uint32_t px = dsc->header.w * y * px_size + x * px_size; -+ memcpy(&buf_u8[px], &c, px_size - 1); /*-1 to not overwrite the alpha value*/ -+ } else if(dsc->header.cf == LV_IMG_CF_INDEXED_1BIT) { -+ buf_u8 += sizeof(lv_color32_t) * 2; /*Skip the palette*/ -+ -+ uint8_t bit = x & 0x7; -+ x = x >> 3; -+ -+ /* Get the current pixel. -+ * dsc->header.w + 7 means rounding up to 8 because the lines are byte aligned -+ * so the possible real width are 8 ,16, 24 ...*/ -+ uint32_t px = ((dsc->header.w + 7) >> 3) * y + x; -+ buf_u8[px] = buf_u8[px] & ~(1 << (7 - bit)); -+ buf_u8[px] = buf_u8[px] | ((c.full & 0x1) << (7 - bit)); -+ } else if(dsc->header.cf == LV_IMG_CF_INDEXED_2BIT) { -+ buf_u8 += sizeof(lv_color32_t) * 4; /*Skip the palette*/ -+ uint8_t bit = (x & 0x3) * 2; -+ x = x >> 2; -+ -+ /* Get the current pixel. -+ * dsc->header.w + 3 means rounding up to 4 because the lines are byte aligned -+ * so the possible real width are 4, 8 ,12 ...*/ -+ uint32_t px = ((dsc->header.w + 3) >> 2) * y + x; -+ -+ buf_u8[px] = buf_u8[px] & ~(3 << (6 - bit)); -+ buf_u8[px] = buf_u8[px] | ((c.full & 0x3) << (6 - bit)); -+ } else if(dsc->header.cf == LV_IMG_CF_INDEXED_4BIT) { -+ buf_u8 += sizeof(lv_color32_t) * 16; /*Skip the palette*/ -+ uint8_t bit = (x & 0x1) * 4; -+ x = x >> 1; -+ -+ /* Get the current pixel. -+ * dsc->header.w + 1 means rounding up to 2 because the lines are byte aligned -+ * so the possible real width are 2 ,4, 6 ...*/ -+ uint32_t px = ((dsc->header.w + 1) >> 1) * y + x; -+ buf_u8[px] = buf_u8[px] & ~(0xF << (4 - bit)); -+ buf_u8[px] = buf_u8[px] | ((c.full & 0xF) << (4 - bit)); -+ } else if(dsc->header.cf == LV_IMG_CF_INDEXED_8BIT) { -+ buf_u8 += sizeof(lv_color32_t) * 256; /*Skip the palette*/ -+ uint32_t px = dsc->header.w * y + x; -+ buf_u8[px] = c.full; -+ } -+} -+ - /** - * Set the alpha value of a pixel of an image. The color won't be affected - * @param dsc pointer to an image descriptor -diff --git a/src/lv_draw/lv_img_buf.h b/src/lv_draw/lv_img_buf.h -index 2629b465..3c1d8273 100644 ---- a/src/lv_draw/lv_img_buf.h -+++ b/src/lv_draw/lv_img_buf.h -@@ -205,6 +205,7 @@ lv_color_t lv_img_buf_get_px_color(lv_img_dsc_t * dsc, lv_coord_t x, lv_coord_t - */ - lv_opa_t lv_img_buf_get_px_alpha(lv_img_dsc_t * dsc, lv_coord_t x, lv_coord_t y); - -+ - /** - * Set the color of a pixel of an image. The alpha channel won't be affected. - * @param dsc pointer to an image descriptor -diff --git a/src/lv_objx/lv_img.c b/src/lv_objx/lv_img.c -index 982bb8d9..f792867a 100644 ---- a/src/lv_objx/lv_img.c -+++ b/src/lv_objx/lv_img.c -@@ -273,7 +273,6 @@ void lv_img_set_angle(lv_obj_t * img, int16_t angle) - lv_img_ext_t * ext = lv_obj_get_ext_attr(img); - if(angle == ext->angle) return; - -- lv_obj_invalidate(img); - ext->angle = angle; - lv_obj_refresh_ext_draw_pad(img); - lv_obj_invalidate(img); -@@ -296,7 +295,6 @@ void lv_img_set_zoom(lv_obj_t * img, uint16_t zoom) - - if(zoom == 0) zoom = 1; - -- lv_obj_invalidate(img); - ext->zoom = zoom; - lv_obj_refresh_ext_draw_pad(img); - lv_obj_invalidate(img); -@@ -533,7 +531,7 @@ static lv_res_t lv_img_signal(lv_obj_t * img, lv_signal_t sign, void * param) - } - } else if(sign == LV_SIGNAL_REFR_EXT_DRAW_PAD) { - /*If the image has angle provide enough room for the rotated corners */ -- if(ext->angle || ext->zoom != LV_IMG_ZOOM_NONE) { -+ if(ext->angle && ext->zoom) { - lv_sqrt_res_t ds; - lv_sqrt(ext->w * ext->w + ext->h * ext->h, &ds); - ds.i = (ds.i * ext->zoom + 0) >> 8; /*+10 to be sure anything won't be clipped*/ diff --git a/src/lv_draw/lv_img_buf.c b/src/lv_draw/lv_img_buf.c index a627398b2..5387e7243 100644 --- a/src/lv_draw/lv_img_buf.c +++ b/src/lv_draw/lv_img_buf.c @@ -512,11 +512,11 @@ static inline bool transform_anti_alias(lv_img_transform_dsc_t * dsc) if(xs_fract < 0x70) { xn = - 1; - if(dsc->tmp.xs_int + xn < 0) return false; + if(dsc->tmp.xs_int + xn < 0) xn = 0; xr = xs_fract + 0x80; } else if(xs_fract > 0x90) { xn = 1; - if(dsc->tmp.xs_int + xn >= dsc->cfg.src_w) return false; + if(dsc->tmp.xs_int + xn >= dsc->cfg.src_w) xn = 0; xr = (0xFF - xs_fract) + 0x80; } else { xn = 0; @@ -528,12 +528,12 @@ static inline bool transform_anti_alias(lv_img_transform_dsc_t * dsc) if(ys_fract < 0x70) { yn = - 1; - if(dsc->tmp.ys_int + yn < 0) return false; + if(dsc->tmp.ys_int + yn < 0) yn = 0; yr = ys_fract + 0x80; } else if(ys_fract > 0x90) { yn = 1; - if(dsc->tmp.ys_int + yn >= dsc->cfg.src_h) return false; + if(dsc->tmp.ys_int + yn >= dsc->cfg.src_h) yn = 0; yr = (0xFF - ys_fract) + 0x80; } else { From 248868fef1f4925fada1aa7591b19e3bc837db51 Mon Sep 17 00:00:00 2001 From: Amir Gonnen Date: Sun, 22 Dec 2019 01:35:00 +0200 Subject: [PATCH 27/28] Add lv_deinit function (#1319) --- src/lv_core/lv_obj.c | 12 ++++++++++++ src/lv_core/lv_obj.h | 9 +++++++++ src/lv_misc/lv_gc.c | 11 +++++++++++ src/lv_misc/lv_gc.h | 33 ++++++++++++++++++--------------- src/lv_misc/lv_mem.c | 15 +++++++++++++++ src/lv_misc/lv_mem.h | 6 ++++++ 6 files changed, 71 insertions(+), 15 deletions(-) diff --git a/src/lv_core/lv_obj.c b/src/lv_core/lv_obj.c index 089c5e341..fd0c91892 100644 --- a/src/lv_core/lv_obj.c +++ b/src/lv_core/lv_obj.c @@ -121,6 +121,18 @@ void lv_init(void) LV_LOG_INFO("lv_init ready"); } +#if LV_ENABLE_GC || !LV_MEM_CUSTOM +void lv_deinit(void) +{ + lv_gc_clear_roots(); + lv_log_register_print_cb(NULL); + lv_disp_set_default(NULL); + lv_mem_deinit(); + lv_initialized = false; + LV_LOG_INFO("lv_deinit done"); +} +#endif + /*-------------------- * Create and delete *-------------------*/ diff --git a/src/lv_core/lv_obj.h b/src/lv_core/lv_obj.h index 869871890..3bc8270e4 100644 --- a/src/lv_core/lv_obj.h +++ b/src/lv_core/lv_obj.h @@ -269,6 +269,15 @@ typedef struct */ void lv_init(void); + +/** + * Deinit the 'lv' library + * Currently only implemented when not using custorm allocators, or GC is enabled. + */ +#if LV_ENABLE_GC || !LV_MEM_CUSTOM +void lv_deinit(void); +#endif + /*-------------------- * Create and delete *-------------------*/ diff --git a/src/lv_misc/lv_gc.c b/src/lv_misc/lv_gc.c index 70dfc9a84..94bf532ac 100644 --- a/src/lv_misc/lv_gc.c +++ b/src/lv_misc/lv_gc.c @@ -8,6 +8,11 @@ *********************/ #include "lv_gc.h" +#include "string.h" + +#if defined(LV_GC_INCLUDE) +#include LV_GC_INCLUDE +#endif /* LV_ENABLE_GC */ /********************* * DEFINES @@ -35,6 +40,12 @@ LV_ROOTS * GLOBAL FUNCTIONS **********************/ +void lv_gc_clear_roots(void) +{ +#define LV_CLEAR_ROOT(root_type, root_name) memset(&LV_GC_ROOT(root_name), 0, sizeof(LV_GC_ROOT(root_name))); + LV_ITERATE_ROOTS(LV_CLEAR_ROOT) +} + /********************** * STATIC FUNCTIONS **********************/ diff --git a/src/lv_misc/lv_gc.h b/src/lv_misc/lv_gc.h index 0db9f5cb9..afd4d600a 100644 --- a/src/lv_misc/lv_gc.h +++ b/src/lv_misc/lv_gc.h @@ -30,21 +30,21 @@ extern "C" { * DEFINES *********************/ -#define LV_GC_ROOTS(prefix) \ - prefix lv_ll_t _lv_task_ll; /*Linked list to store the lv_tasks*/ \ - prefix lv_ll_t _lv_disp_ll; /*Linked list of screens*/ \ - prefix lv_ll_t _lv_indev_ll; /*Linked list of screens*/ \ - prefix lv_ll_t _lv_drv_ll; \ - prefix lv_ll_t _lv_file_ll; \ - prefix lv_ll_t _lv_anim_ll; \ - prefix lv_ll_t _lv_group_ll; \ - prefix lv_ll_t _lv_img_defoder_ll; \ - prefix lv_img_cache_entry_t * _lv_img_cache_array; \ - prefix void * _lv_task_act; \ - prefix void * _lv_draw_buf; +#define LV_ITERATE_ROOTS(f) \ + f(lv_ll_t, _lv_task_ll) /*Linked list to store the lv_tasks*/ \ + f(lv_ll_t, _lv_disp_ll) /*Linked list of screens*/ \ + f(lv_ll_t, _lv_indev_ll) /*Linked list of screens*/ \ + f(lv_ll_t, _lv_drv_ll) \ + f(lv_ll_t, _lv_file_ll) \ + f(lv_ll_t, _lv_anim_ll) \ + f(lv_ll_t, _lv_group_ll) \ + f(lv_ll_t, _lv_img_defoder_ll) \ + f(lv_img_cache_entry_t*, _lv_img_cache_array) \ + f(void*, _lv_task_act) \ + f(void*, _lv_draw_buf) -#define LV_NO_PREFIX -#define LV_ROOTS LV_GC_ROOTS(LV_NO_PREFIX) +#define LV_DEFINE_ROOT(root_type, root_name) root_type root_name; +#define LV_ROOTS LV_ITERATE_ROOTS(LV_DEFINE_ROOT) #if LV_ENABLE_GC == 1 #if LV_MEM_CUSTOM != 1 @@ -52,7 +52,8 @@ extern "C" { #endif /* LV_MEM_CUSTOM */ #else /* LV_ENABLE_GC */ #define LV_GC_ROOT(x) x -LV_GC_ROOTS(extern) +#define LV_EXTERN_ROOT(root_type, root_name) extern root_type root_name; +LV_ITERATE_ROOTS(LV_EXTERN_ROOT) #endif /* LV_ENABLE_GC */ /********************** @@ -63,6 +64,8 @@ LV_GC_ROOTS(extern) * GLOBAL PROTOTYPES **********************/ +void lv_gc_clear_roots(void); + /********************** * MACROS **********************/ diff --git a/src/lv_misc/lv_mem.c b/src/lv_misc/lv_mem.c index da38554e4..9b7345ab3 100644 --- a/src/lv_misc/lv_mem.c +++ b/src/lv_misc/lv_mem.c @@ -102,6 +102,21 @@ void lv_mem_init(void) #endif } +/** + * Clean up the memory buffer which frees all the allocated memories. + * @note It work only if `LV_MEM_CUSTOM == 0` + */ +void lv_mem_deinit(void) +{ +#if LV_MEM_CUSTOM == 0 + memset(work_mem, 0x00, (LV_MEM_SIZE / sizeof(MEM_UNIT)) * sizeof(MEM_UNIT)); + lv_mem_ent_t * full = (lv_mem_ent_t *)work_mem; + full->header.s.used = 0; + /*The total mem size id reduced by the first header and the close patterns */ + full->header.s.d_size = LV_MEM_SIZE - sizeof(lv_mem_header_t); +#endif +} + /** * Allocate a memory dynamically * @param size size of the memory to allocate in bytes diff --git a/src/lv_misc/lv_mem.h b/src/lv_misc/lv_mem.h index 34ca3e9e9..f72407421 100644 --- a/src/lv_misc/lv_mem.h +++ b/src/lv_misc/lv_mem.h @@ -55,6 +55,12 @@ typedef struct */ void lv_mem_init(void); +/** + * Clean up the memory buffer which frees all the allocated memories. + * @note It work only if `LV_MEM_CUSTOM == 0` + */ +void lv_mem_deinit(void); + /** * Allocate a memory dynamically * @param size size of the memory to allocate in bytes From 7b4f4619447d7ab67ba7d433307385f13470aa6e Mon Sep 17 00:00:00 2001 From: embeddedt <42941056+embeddedt@users.noreply.github.com> Date: Sun, 22 Dec 2019 13:51:02 +0000 Subject: [PATCH 28/28] Implement custom, opt-in hit-testing handlers for objects (#1318) --- src/lv_core/lv_indev.c | 20 +--------- src/lv_core/lv_obj.c | 63 ++++++++++++++++++++++++++++++ src/lv_core/lv_obj.h | 26 ++++++++++++- src/lv_misc/lv_area.c | 82 ++++++++++++++++++++++++++++++++++++--- src/lv_misc/lv_area.h | 3 +- src/lv_objx/lv_btnm.c | 2 +- src/lv_objx/lv_calendar.c | 4 +- src/lv_objx/lv_cpicker.c | 23 +++++++++++ 8 files changed, 193 insertions(+), 30 deletions(-) diff --git a/src/lv_core/lv_indev.c b/src/lv_core/lv_indev.c index 14579f071..8bf050d5f 100644 --- a/src/lv_core/lv_indev.c +++ b/src/lv_core/lv_indev.c @@ -1034,25 +1034,7 @@ lv_obj_t * lv_indev_search_obj(lv_obj_t * obj, lv_point_t *point) lv_obj_t * found_p = NULL; /*If the point is on this object check its children too*/ -#if LV_USE_EXT_CLICK_AREA == LV_EXT_CLICK_AREA_TINY - lv_area_t ext_area; - ext_area.x1 = obj->coords.x1 - obj->ext_click_pad_hor; - ext_area.x2 = obj->coords.x2 + obj->ext_click_pad_hor; - ext_area.y1 = obj->coords.y1 - obj->ext_click_pad_ver; - ext_area.y2 = obj->coords.y2 + obj->ext_click_pad_ver; - - if(lv_area_is_point_on(&ext_area, point)) { -#elif LV_USE_EXT_CLICK_AREA == LV_EXT_CLICK_AREA_FULL - lv_area_t ext_area; - ext_area.x1 = obj->coords.x1 - obj->ext_click_pad.x1; - ext_area.x2 = obj->coords.x2 + obj->ext_click_pad.x2; - ext_area.y1 = obj->coords.y1 - obj->ext_click_pad.y1; - ext_area.y2 = obj->coords.y2 + obj->ext_click_pad.y2; - - if(lv_area_is_point_on(&ext_area, point)) { -#else - if(lv_area_is_point_on(&obj->coords, point)) { -#endif + if(lv_obj_hittest(obj, point)) { lv_obj_t * i; LV_LL_READ(obj->child_ll, i) diff --git a/src/lv_core/lv_obj.c b/src/lv_core/lv_obj.c index 1d690e78f..781fc448f 100644 --- a/src/lv_core/lv_obj.c +++ b/src/lv_core/lv_obj.c @@ -201,6 +201,7 @@ lv_obj_t * lv_obj_create(lv_obj_t * parent, const lv_obj_t * copy) new_obj->group_p = NULL; #endif /*Set attributes*/ + new_obj->adv_hittest = 0; new_obj->click = 0; new_obj->drag = 0; new_obj->drag_throw = 0; @@ -1275,6 +1276,17 @@ void lv_obj_set_hidden(lv_obj_t * obj, bool en) par->signal_cb(par, LV_SIGNAL_CHILD_CHG, obj); } +/** + * Set whether advanced hit-testing is enabled on an object + * @param obj pointer to an object + * @param en true: advanced hit-testing is enabled + */ +void lv_obj_set_adv_hittest(lv_obj_t * obj, bool en) { + LV_ASSERT_OBJ(obj, LV_OBJX_NAME); + + obj->adv_hittest = en == false ? 0 : 1; +} + /** * Enable or disable the clicking of an object * @param obj pointer to an object @@ -2053,6 +2065,18 @@ bool lv_obj_get_hidden(const lv_obj_t * obj) return obj->hidden == 0 ? false : true; } +/** + * Get whether advanced hit-testing is enabled on an object + * @param obj pointer to an object + * @return true: advanced hit-testing is enabled + */ +bool lv_obj_get_adv_hittest(const lv_obj_t * obj) +{ + LV_ASSERT_OBJ(obj, LV_OBJX_NAME); + + return obj->adv_hittest == 0 ? false : true; +} + /** * Get the click enable attribute of an object * @param obj pointer to an object @@ -2368,6 +2392,45 @@ bool lv_obj_is_focused(const lv_obj_t * obj) * OTHER FUNCTIONS *------------------*/ +/** + * Hit-test an object given a particular point in screen space. + * @param obj object to hit-test + * @param point screen-space point + * @return true if the object is considered under the point + */ +bool lv_obj_hittest(lv_obj_t * obj, lv_point_t * point) { +#if LV_USE_EXT_CLICK_AREA == LV_EXT_CLICK_AREA_TINY + lv_area_t ext_area; + ext_area.x1 = obj->coords.x1 - obj->ext_click_pad_hor; + ext_area.x2 = obj->coords.x2 + obj->ext_click_pad_hor; + ext_area.y1 = obj->coords.y1 - obj->ext_click_pad_ver; + ext_area.y2 = obj->coords.y2 + obj->ext_click_pad_ver; + + if(!lv_area_is_point_on(&ext_area, point, 0)) { +#elif LV_USE_EXT_CLICK_AREA == LV_EXT_CLICK_AREA_FULL + lv_area_t ext_area; + ext_area.x1 = obj->coords.x1 - obj->ext_click_pad.x1; + ext_area.x2 = obj->coords.x2 + obj->ext_click_pad.x2; + ext_area.y1 = obj->coords.y1 - obj->ext_click_pad.y1; + ext_area.y2 = obj->coords.y2 + obj->ext_click_pad.y2; + + if(!lv_area_is_point_on(&ext_area, point, 0)) { +#else + if(!lv_area_is_point_on(&obj->coords, point, 0)) { +#endif + return false; + } + if(obj->adv_hittest) { + lv_hit_test_info_t hit_info; + hit_info.point = point; + hit_info.result = true; + obj->signal_cb(obj, LV_SIGNAL_HIT_TEST, &hit_info); + if(!hit_info.result) + return false; + } + return true; +} + /** * Used in the signal callback to handle `LV_SIGNAL_GET_TYPE` signal * @param obj pointer to an object diff --git a/src/lv_core/lv_obj.h b/src/lv_core/lv_obj.h index c976cad6c..c22498bfd 100644 --- a/src/lv_core/lv_obj.h +++ b/src/lv_core/lv_obj.h @@ -128,6 +128,7 @@ enum { LV_SIGNAL_GET_TYPE, /**< LittlevGL needs to retrieve the object's type */ /*Input device related*/ + LV_SIGNAL_HIT_TEST, /**< Advanced hit-testing */ LV_SIGNAL_PRESSED, /**< The object has been pressed*/ LV_SIGNAL_PRESSING, /**< The object is being pressed (called continuously while pressing)*/ LV_SIGNAL_PRESS_LOST, /**< User is still pressing but slid cursor/finger off of the object */ @@ -225,7 +226,8 @@ typedef struct _lv_obj_t uint8_t parent_event : 1; /**< 1: Send the object's events to the parent too. */ lv_drag_dir_t drag_dir : 3; /**< Which directions the object can be dragged in */ lv_bidi_dir_t base_dir : 2; /**< Base direction of texts related to this object */ - uint8_t reserved : 3; /**< Reserved for future use*/ + uint8_t adv_hittest : 1; /**< 1: Use advanced hit-testing (slower) */ + uint8_t reserved : 2; /**< Reserved for future use*/ uint8_t protect; /**< Automatically happening actions can be prevented. 'OR'ed values from `lv_protect_t`*/ lv_opa_t opa_scale; /**< Scale down the opacity by this factor. Effects all children as well*/ @@ -263,6 +265,12 @@ typedef struct ... [x]: "lv_obj" */ } lv_obj_type_t; +typedef struct _lv_hit_test_info_t +{ + lv_point_t *point; + bool result; +} lv_hit_test_info_t; + /********************** * GLOBAL PROTOTYPES **********************/ @@ -466,6 +474,13 @@ void lv_obj_report_style_mod(lv_style_t * style); */ void lv_obj_set_hidden(lv_obj_t * obj, bool en); +/** + * Set whether advanced hit-testing is enabled on an object + * @param obj pointer to an object + * @param en true: advanced hit-testing is enabled + */ +void lv_obj_set_adv_hittest(lv_obj_t * obj, bool en); + /** * Enable or disable the clicking of an object * @param obj pointer to an object @@ -808,6 +823,13 @@ const lv_style_t * lv_obj_get_style(const lv_obj_t * obj); */ bool lv_obj_get_hidden(const lv_obj_t * obj); +/** + * Get whether advanced hit-testing is enabled on an object + * @param obj pointer to an object + * @return true: advanced hit-testing is enabled + */ +bool lv_obj_get_adv_hittest(const lv_obj_t * obj); + /** * Get the click enable attribute of an object * @param obj pointer to an object @@ -914,6 +936,8 @@ lv_event_cb_t lv_obj_get_event_cb(const lv_obj_t * obj); * Other get *-----------------*/ +bool lv_obj_hittest(lv_obj_t * obj, lv_point_t * point); + /** * Get the ext pointer * @param obj pointer to an object diff --git a/src/lv_misc/lv_area.c b/src/lv_misc/lv_area.c index de649c5b0..174e4f860 100644 --- a/src/lv_misc/lv_area.c +++ b/src/lv_misc/lv_area.c @@ -27,6 +27,8 @@ * STATIC PROTOTYPES **********************/ +static bool lv_point_within_circle(const lv_area_t * area, const lv_point_t * p); + /********************** * STATIC VARIABLES **********************/ @@ -148,15 +150,62 @@ void lv_area_join(lv_area_t * a_res_p, const lv_area_t * a1_p, const lv_area_t * * @param p_p pointer to a point * @return false:the point is out of the area */ -bool lv_area_is_point_on(const lv_area_t * a_p, const lv_point_t * p_p) +bool lv_area_is_point_on(const lv_area_t * a_p, const lv_point_t * p_p, lv_coord_t radius) { - bool is_on = false; - + /*First check the basic area*/ + bool is_on_rect = false; if((p_p->x >= a_p->x1 && p_p->x <= a_p->x2) && ((p_p->y >= a_p->y1 && p_p->y <= a_p->y2))) { - is_on = true; + is_on_rect = true; } - - return is_on; + if(!is_on_rect) + return false; + /*Now handle potential rounded rectangles*/ + if(radius <= 0) { + /*No radius, it is within the rectangle*/ + return true; + } + lv_coord_t max_radius = LV_MATH_MIN(lv_area_get_width(a_p) / 2, lv_area_get_height(a_p) / 2); + if(radius > max_radius) + radius = max_radius; + + /*Check if it's in one of the corners*/ + lv_area_t corner_area; + /*Top left*/ + corner_area.x1 = a_p->x1; + corner_area.x2 = a_p->x1 + radius; + corner_area.y1 = a_p->y1; + corner_area.y2 = a_p->y1 + radius; + if(lv_area_is_point_on(&corner_area, p_p, 0)) { + corner_area.x2 += radius; + corner_area.y2 += radius; + return lv_point_within_circle(&corner_area, p_p); + } + /*Bottom left*/ + corner_area.y1 = a_p->y2 - radius; + corner_area.y2 = a_p->y2; + if(lv_area_is_point_on(&corner_area, p_p, 0)) { + corner_area.x2 += radius; + corner_area.y1 -= radius; + return lv_point_within_circle(&corner_area, p_p); + } + /*Bottom right*/ + corner_area.x1 = a_p->x2 - radius; + corner_area.x2 = a_p->x2; + if(lv_area_is_point_on(&corner_area, p_p, 0)) { + corner_area.x1 -= radius; + corner_area.y1 -= radius; + return lv_point_within_circle(&corner_area, p_p); + } + /*Top right*/ + corner_area.y1 = a_p->y1; + corner_area.y2 = a_p->y1 + radius; + if(lv_area_is_point_on(&corner_area, p_p, 0)) { + corner_area.x1 -= radius; + corner_area.y2 += radius; + return lv_point_within_circle(&corner_area, p_p); + } + /*Not within corners*/ + return false; } /** @@ -208,3 +257,24 @@ void lv_area_increment(lv_area_t * a_p, const lv_coord_t amount) /********************** * STATIC FUNCTIONS **********************/ + +static bool lv_point_within_circle(const lv_area_t * area, const lv_point_t * p) +{ + lv_coord_t r = (area->x2 - area->x1) / 2; + + /* Circle center */ + lv_coord_t cx = area->x1 + r; + lv_coord_t cy = area->y1 + r; + + /*Simplify the code by moving everything to (0, 0) */ + lv_coord_t px = p->x - cx; + lv_coord_t py = p->y - cy; + + int32_t r_sqrd = r*r; + int32_t dist = (px*px) + (py*py); + + if(dist <= r_sqrd) + return true; + else + return false; +} diff --git a/src/lv_misc/lv_area.h b/src/lv_misc/lv_area.h index 211bebd84..375fa009f 100644 --- a/src/lv_misc/lv_area.h +++ b/src/lv_misc/lv_area.h @@ -148,9 +148,10 @@ void lv_area_join(lv_area_t * a_res_p, const lv_area_t * a1_p, const lv_area_t * * Check if a point is on an area * @param a_p pointer to an area * @param p_p pointer to a point + * @param radius radius of area (e.g. for rounded rectangle) * @return false:the point is out of the area */ -bool lv_area_is_point_on(const lv_area_t * a_p, const lv_point_t * p_p); +bool lv_area_is_point_on(const lv_area_t * a_p, const lv_point_t * p_p, lv_coord_t radius); /** * Check if two area has common parts diff --git a/src/lv_objx/lv_btnm.c b/src/lv_objx/lv_btnm.c index 9b38a70f3..e783a1045 100644 --- a/src/lv_objx/lv_btnm.c +++ b/src/lv_objx/lv_btnm.c @@ -1056,7 +1056,7 @@ static uint16_t get_button_from_point(lv_obj_t * btnm, lv_point_t * p) btn_area.y1 += btnm_cords.y1; btn_area.x2 += btnm_cords.x1; btn_area.y2 += btnm_cords.y1; - if(lv_area_is_point_on(&btn_area, p) != false) { + if(lv_area_is_point_on(&btn_area, p, 0) != false) { break; } } diff --git a/src/lv_objx/lv_calendar.c b/src/lv_objx/lv_calendar.c index 1dd83464f..1249340f1 100644 --- a/src/lv_objx/lv_calendar.c +++ b/src/lv_objx/lv_calendar.c @@ -508,7 +508,7 @@ static lv_res_t lv_calendar_signal(lv_obj_t * calendar, lv_signal_t sign, void * lv_indev_get_point(indev, &p); /*If the header is pressed mark an arrow as pressed*/ - if(lv_area_is_point_on(&header_area, &p)) { + if(lv_area_is_point_on(&header_area, &p, 0)) { if(p.x < header_area.x1 + lv_area_get_width(&header_area) / 2) { if(ext->btn_pressing != -1) lv_obj_invalidate(calendar); ext->btn_pressing = -1; @@ -605,7 +605,7 @@ static bool calculate_touched_day(lv_obj_t * calendar, const lv_point_t * touche days_area.y1 = calendar->coords.y1 + get_header_height(calendar) + get_day_names_height(calendar) - style_bg->body.padding.top; - if(lv_area_is_point_on(&days_area, touched_point)) { + if(lv_area_is_point_on(&days_area, touched_point, 0)) { lv_coord_t w = (days_area.x2 - days_area.x1 + 1) / 7; lv_coord_t h = (days_area.y2 - days_area.y1 + 1) / 6; uint8_t x_pos = 0; diff --git a/src/lv_objx/lv_cpicker.c b/src/lv_objx/lv_cpicker.c index aca670083..4f6be702c 100644 --- a/src/lv_objx/lv_cpicker.c +++ b/src/lv_objx/lv_cpicker.c @@ -57,6 +57,7 @@ **********************/ static lv_design_res_t lv_cpicker_design(lv_obj_t * cpicker, const lv_area_t * clip_area, lv_design_mode_t mode); static lv_res_t lv_cpicker_signal(lv_obj_t * cpicker, lv_signal_t sign, void * param); +static bool lv_cpicker_hit(lv_obj_t * cpicker, const lv_point_t * p); static void draw_rect_grad(lv_obj_t * cpicker, const lv_area_t * mask, lv_opa_t opa_scale); static void draw_disc_grad(lv_obj_t * cpicker, const lv_area_t * mask, lv_opa_t opa_scale); @@ -889,11 +890,33 @@ static lv_res_t lv_cpicker_signal(lv_obj_t * cpicker, lv_signal_t sign, void * p res = lv_event_send(cpicker, LV_EVENT_VALUE_CHANGED, NULL); if(res != LV_RES_OK) return res; } + } else if(sign == LV_SIGNAL_HIT_TEST) { + lv_hit_test_info_t *info = param; + info->result = lv_cpicker_hit(cpicker, info->point); } return res; } +static bool lv_cpicker_hit(lv_obj_t * cpicker, const lv_point_t * p) +{ + lv_cpicker_ext_t * ext = (lv_cpicker_ext_t *)lv_obj_get_ext_attr(cpicker); + if(ext->type != LV_CPICKER_TYPE_DISC || ext->preview) + return true; + const lv_style_t * style_main = lv_cpicker_get_style(cpicker, LV_CPICKER_STYLE_MAIN); + lv_area_t area_mid; + lv_area_copy(&area_mid, &cpicker->coords); + area_mid.x1 += style_main->line.width; + area_mid.y1 += style_main->line.width; + area_mid.x2 -= style_main->line.width; + area_mid.y2 -= style_main->line.width; + + if(lv_area_is_point_on(&area_mid, p, LV_RADIUS_CIRCLE)) + return false; + + return true; +} + static void next_color_mode(lv_obj_t * cpicker) { lv_cpicker_ext_t * ext = lv_obj_get_ext_attr(cpicker);