Skip to content

Commit 6c2263f

Browse files
authored
fix(textarea): fill letter space with selection bg color. (lvgl#8238)
1 parent 58bed43 commit 6c2263f

File tree

5 files changed

+25
-4
lines changed

5 files changed

+25
-4
lines changed

src/draw/lv_draw_label.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,9 +461,9 @@ void lv_draw_label_iterate_characters(lv_draw_task_t * t, const lv_draw_label_ds
461461
letter_w = lv_text_is_marker(letter) ? 0 : glyph_dsc.adv_w;
462462

463463
/*Always set the bg_coordinates for placeholder drawing*/
464-
bg_coords.x1 = pos.x;
464+
bg_coords.x1 = pos.x - dsc->letter_space / 2;
465465
bg_coords.y1 = pos.y;
466-
bg_coords.x2 = pos.x + letter_w - 1;
466+
bg_coords.x2 = pos.x + letter_w - 1 + (dsc->letter_space + 1) / 2;
467467
bg_coords.y2 = pos.y + line_height - 1;
468468

469469
if(next_char_offset >= line_end - line_start) {

src/widgets/textarea/lv_textarea.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,11 +1198,12 @@ static void refr_cursor_area(lv_obj_t * obj)
11981198
int32_t bottom = lv_obj_get_style_pad_bottom(obj, LV_PART_CURSOR) + border_width;
11991199
int32_t left = lv_obj_get_style_pad_left(obj, LV_PART_CURSOR) + border_width;
12001200
int32_t right = lv_obj_get_style_pad_right(obj, LV_PART_CURSOR) + border_width;
1201+
int32_t letter_space_w = lv_obj_get_style_text_letter_space(ta->label, LV_PART_MAIN);
12011202

12021203
lv_area_t cur_area;
1203-
cur_area.x1 = letter_pos.x - left;
1204+
cur_area.x1 = letter_pos.x - left - letter_space_w / 2;
12041205
cur_area.y1 = letter_pos.y - top;
1205-
cur_area.x2 = letter_pos.x + right + letter_w - 1;
1206+
cur_area.x2 = letter_pos.x + right + letter_w - 1 + (letter_space_w + 1) / 2;
12061207
cur_area.y2 = letter_pos.y + bottom + letter_h - 1;
12071208

12081209
/*Save the new area*/
1.7 KB
Loading
4.82 KB
Loading

tests/src/test_cases/draw/test_draw_label.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,24 @@ void test_label_selection_and_recolor(void)
145145
TEST_ASSERT_EQUAL_SCREENSHOT("draw/label_selection_and_recolor.png");
146146
}
147147

148+
void test_label_selection_with_letter_space(void)
149+
{
150+
lv_color_t color = lv_palette_main(LV_PALETTE_BLUE);
151+
lv_color_t sel_bg_color = lv_palette_lighten(LV_PALETTE_RED, 4);
152+
lv_color_t sel_color = lv_palette_darken(LV_PALETTE_RED, 4);
153+
154+
lv_obj_t * label = lv_label_create(lv_screen_active());
155+
lv_label_set_text(label, "Testing selection with letter space label.");
156+
lv_obj_set_style_text_color(label, color, 0);
157+
lv_obj_set_style_text_opa(label, LV_OPA_COVER, 0);
158+
lv_obj_set_style_text_align(label, LV_TEXT_ALIGN_LEFT, 0);
159+
lv_obj_set_style_bg_color(label, sel_bg_color, LV_PART_SELECTED);
160+
lv_obj_set_style_text_color(label, sel_color, LV_PART_SELECTED);
161+
lv_obj_set_style_text_letter_space(label, 10, 0);
162+
lv_label_set_text_selection_start(label, 10);
163+
lv_label_set_text_selection_end(label, 25);
164+
165+
TEST_ASSERT_EQUAL_SCREENSHOT("draw/label_selection_letter_space.png");
166+
}
167+
148168
#endif

0 commit comments

Comments
 (0)