diff --git a/CHANGELOG.md b/CHANGELOG.md index dc2347a52..298d77614 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ - Add `decmopr_buf` to GC roots - Fix divisioin by zero in draw_pattern (lv_draw_rect.c) if the image or letter is not found - Fix drawing images with 1 px height or width +- Fix selectiion of options with non-ASCII letters in dropdown list ## v7.4.0 (01.09.2020) diff --git a/src/lv_widgets/lv_dropdown.c b/src/lv_widgets/lv_dropdown.c index 6d53b2f3b..8d61c5bff 100644 --- a/src/lv_widgets/lv_dropdown.c +++ b/src/lv_widgets/lv_dropdown.c @@ -1281,10 +1281,12 @@ static uint16_t get_id_on_point(lv_obj_t * ddlist, lv_coord_t x, lv_coord_t y) y -= label->coords.y1; uint32_t letter_i; + const char * txt = lv_label_get_text(label); + lv_point_t p = {x, y}; letter_i = lv_label_get_letter_on(label, &p); + uint32_t letter_i_byte_pos = _lv_txt_encoded_get_byte_id(txt, letter_i); uint16_t opt = 0; - const char * txt = lv_label_get_text(label); uint32_t i = 0; uint32_t i_prev = 0; @@ -1293,7 +1295,7 @@ static uint16_t get_id_on_point(lv_obj_t * ddlist, lv_coord_t x, lv_coord_t y) uint32_t letter = _lv_txt_encoded_next(txt, &i); /*Count the lines to reach the clicked letter. But ignore the last '\n' because it * still belongs to the clicked line*/ - if(letter == '\n' && i_prev != letter_i) opt++; + if(letter == '\n' && i_prev != letter_i_byte_pos) opt++; i_prev = i; } diff --git a/src/lv_widgets/lv_label.c b/src/lv_widgets/lv_label.c index 65e6397f6..eacba00e0 100644 --- a/src/lv_widgets/lv_label.c +++ b/src/lv_widgets/lv_label.c @@ -688,10 +688,14 @@ void lv_label_get_letter_pos(const lv_obj_t * label, uint32_t char_id, lv_point_ * @return the index of the letter on the 'pos_p' point (E.g. on 0;0 is the 0. letter) * Expressed in character index and not byte index (different in UTF-8) */ -uint32_t lv_label_get_letter_on(const lv_obj_t * label, lv_point_t * pos) +uint32_t lv_label_get_letter_on(const lv_obj_t * label, lv_point_t * pos_in) { LV_ASSERT_OBJ(label, LV_OBJX_NAME); - LV_ASSERT_NULL(pos); + LV_ASSERT_NULL(pos_in); + + lv_point_t pos; + pos.x = pos_in->x - lv_obj_get_style_pad_left(label, LV_LABEL_PART_MAIN); + pos.y = pos_in->y - lv_obj_get_style_pad_top(label, LV_LABEL_PART_MAIN); lv_area_t txt_coords; get_txt_coords(label, &txt_coords); @@ -721,7 +725,7 @@ uint32_t lv_label_get_letter_on(const lv_obj_t * label, lv_point_t * pos) while(txt[line_start] != '\0') { new_line_start += _lv_txt_get_next_line(&txt[line_start], font, letter_space, max_w, flag); - if(pos->y <= y + letter_height) { + if(pos.y <= y + letter_height) { /*The line is found (stored in 'line_start')*/ /* Include the NULL terminator in the last line */ uint32_t tmp = new_line_start; @@ -780,7 +784,7 @@ uint32_t lv_label_get_letter_on(const lv_obj_t * label, lv_point_t * pos) lv_coord_t gw = lv_font_get_glyph_width(font, letter, letter_next); /*Finish if the x position or the last char of the next line is reached*/ - if(pos->x < x + (gw >> 1) || i + line_start == new_line_start || txt[i_act + line_start] == '\0') { + if(pos.x < x + gw || i + line_start == new_line_start || txt[i_act + line_start] == '\0') { i = i_act; break; }