mirror of
https://github.com/lvgl/lvgl.git
synced 2026-05-30 15:17:33 +08:00
Merge pull request #1259 from joltwallet/fix/txt_cursor_wrap
Fix cursor wrapping described in https://github.com/littlevgl/lvgl/is…
This commit is contained in:
+9
-11
@@ -266,6 +266,9 @@ static uint16_t lv_txt_get_next_word(const char * txt, const lv_font_t * font,
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the next line of text. Check line length and break chars too.
|
* Get the next line of text. Check line length and break chars too.
|
||||||
|
*
|
||||||
|
* A line of txt includes the \n character.
|
||||||
|
*
|
||||||
* @param txt a '\0' terminated string
|
* @param txt a '\0' terminated string
|
||||||
* @param font pointer to a font
|
* @param font pointer to a font
|
||||||
* @param letter_space letter space
|
* @param letter_space letter space
|
||||||
@@ -295,18 +298,13 @@ uint16_t lv_txt_get_next_line(const char * txt, const lv_font_t * font,
|
|||||||
|
|
||||||
i += advance;
|
i += advance;
|
||||||
|
|
||||||
if(txt[i] == '\n') break;
|
if(txt[0] == '\n') break;
|
||||||
}
|
|
||||||
|
if(txt[i] == '\n'){
|
||||||
|
i++; /* Include the following newline in the current line */
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
/* If this is the last of the string, make sure pointer is at NULL-terminator.
|
|
||||||
* This catches the case, for example of a string ending in "\n" */
|
|
||||||
if(txt[i] != '\0'){
|
|
||||||
uint32_t i_next = i;
|
|
||||||
int tmp;
|
|
||||||
uint32_t letter_next = lv_txt_encoded_next(txt, &i_next); /*Gets current character*/
|
|
||||||
tmp = i_next;
|
|
||||||
letter_next = lv_txt_encoded_next(txt, &i_next); /*Gets subsequent character*/
|
|
||||||
if(letter_next == '\0') i = tmp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*Always step at least one to avoid infinite loops*/
|
/*Always step at least one to avoid infinite loops*/
|
||||||
|
|||||||
+28
-22
@@ -661,7 +661,15 @@ uint16_t lv_label_get_letter_on(const lv_obj_t * label, lv_point_t * pos)
|
|||||||
while(txt[line_start] != '\0') {
|
while(txt[line_start] != '\0') {
|
||||||
new_line_start += lv_txt_get_next_line(&txt[line_start], font, style->text.letter_space, max_w, flag);
|
new_line_start += lv_txt_get_next_line(&txt[line_start], font, style->text.letter_space, max_w, flag);
|
||||||
|
|
||||||
if(pos->y <= y + letter_height) break; /*The line is found (stored in 'line_start')*/
|
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;
|
||||||
|
uint32_t letter;
|
||||||
|
letter = lv_txt_encoded_prev(txt, &tmp);
|
||||||
|
if(letter != '\n' && txt[new_line_start] == '\0' ) new_line_start++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
y += letter_height + style->text.line_space;
|
y += letter_height + style->text.line_space;
|
||||||
|
|
||||||
line_start = new_line_start;
|
line_start = new_line_start;
|
||||||
@@ -682,31 +690,29 @@ uint16_t lv_label_get_letter_on(const lv_obj_t * label, lv_point_t * pos)
|
|||||||
uint32_t letter;
|
uint32_t letter;
|
||||||
uint32_t letter_next;
|
uint32_t letter_next;
|
||||||
|
|
||||||
if(new_line_start > 0) {
|
while(i < new_line_start) {
|
||||||
while(i < new_line_start) {
|
/* Get the current letter.*/
|
||||||
/* Get the current letter.*/
|
letter = lv_txt_encoded_next(txt, &i);
|
||||||
letter = lv_txt_encoded_next(txt, &i);
|
|
||||||
|
|
||||||
/*Get the next letter too for kerning*/
|
/*Get the next letter too for kerning*/
|
||||||
letter_next = lv_txt_encoded_next(&txt[i], NULL);
|
letter_next = lv_txt_encoded_next(&txt[i], NULL);
|
||||||
|
|
||||||
/*Handle the recolor command*/
|
/*Handle the recolor command*/
|
||||||
if((flag & LV_TXT_FLAG_RECOLOR) != 0) {
|
if((flag & LV_TXT_FLAG_RECOLOR) != 0) {
|
||||||
if(lv_txt_is_cmd(&cmd_state, txt[i]) != false) {
|
if(lv_txt_is_cmd(&cmd_state, txt[i]) != false) {
|
||||||
continue; /*Skip the letter is it is part of a command*/
|
continue; /*Skip the letter is it is part of a command*/
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
x += lv_font_get_glyph_width(font, letter, letter_next);
|
|
||||||
|
|
||||||
/*Finish if the x position or the last char of the line is reached*/
|
|
||||||
if(pos->x < x || i == new_line_start) {
|
|
||||||
i = i_act;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
x += style->text.letter_space;
|
|
||||||
i_act = i;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
x += lv_font_get_glyph_width(font, letter, letter_next);
|
||||||
|
|
||||||
|
/*Finish if the x position or the last char of the line is reached*/
|
||||||
|
if(pos->x < x || i == new_line_start) {
|
||||||
|
i = i_act;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
x += style->text.letter_space;
|
||||||
|
i_act = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
return lv_encoded_get_char_id(txt, i);
|
return lv_encoded_get_char_id(txt, i);
|
||||||
|
|||||||
Reference in New Issue
Block a user