mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-28 07:03:00 +08:00
Proper word wrapping taking into account letter_space
This commit is contained in:
parent
0a0df60f77
commit
b7c08e8aed
@ -148,6 +148,7 @@ uint16_t lv_txt_get_next_line(const char * txt, const lv_font_t * font,
|
|||||||
|
|
||||||
uint32_t i = 0;
|
uint32_t i = 0;
|
||||||
lv_coord_t cur_w = 0;
|
lv_coord_t cur_w = 0;
|
||||||
|
lv_coord_t w_at_last_break = 0;
|
||||||
uint32_t last_break = NO_BREAK_FOUND;
|
uint32_t last_break = NO_BREAK_FOUND;
|
||||||
lv_txt_cmd_state_t cmd_state = LV_TXT_CMD_STATE_WAIT;
|
lv_txt_cmd_state_t cmd_state = LV_TXT_CMD_STATE_WAIT;
|
||||||
uint32_t letter = 0;
|
uint32_t letter = 0;
|
||||||
@ -176,36 +177,32 @@ uint16_t lv_txt_get_next_line(const char * txt, const lv_font_t * font,
|
|||||||
/*If the txt is too long then finish, this is the line end*/
|
/*If the txt is too long then finish, this is the line end*/
|
||||||
if(cur_w > max_width) {
|
if(cur_w > max_width) {
|
||||||
/* Continue searching for next breakable character to see if the next word will fit */
|
/* Continue searching for next breakable character to see if the next word will fit */
|
||||||
uint32_t i_tmp = i;
|
if( last_break != NO_BREAK_FOUND ) {
|
||||||
cur_w = 0;
|
uint32_t i_tmp = i;
|
||||||
while(txt[i_tmp] != 0) {
|
cur_w -= w_at_last_break;
|
||||||
letter = lv_txt_encoded_next(txt, &i_tmp);
|
while(txt[i_tmp] != 0) {
|
||||||
/*Check for new line chars*/
|
letter = lv_txt_encoded_next(txt, &i_tmp);
|
||||||
if(letter == '\n' || letter == '\r') {
|
/*Check for new line chars*/
|
||||||
uint32_t i_tmp2 = i;
|
if(letter == '\n' || letter == '\r') {
|
||||||
uint32_t letter_next = lv_txt_encoded_next(txt, &i_tmp2);
|
uint32_t i_tmp2 = i_tmp;
|
||||||
if(letter == '\r' && letter_next == '\n') i = i_tmp2;
|
uint32_t letter_next = lv_txt_encoded_next(txt, &i_tmp2);
|
||||||
break;
|
if(letter == '\r' && letter_next == '\n') i = i_tmp2;
|
||||||
}
|
i = last_break;
|
||||||
else if (is_break_char(letter)) {
|
break;
|
||||||
break;
|
}
|
||||||
|
else if (is_break_char(letter)) {
|
||||||
|
i = last_break;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
lv_coord_t letter_width = lv_font_get_width(font, letter);
|
||||||
|
cur_w += letter_width;
|
||||||
|
if(cur_w > max_width) {
|
||||||
|
/* Current letter already exceeds, return previous */
|
||||||
|
lv_txt_encoded_prev(txt, &i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
cur_w += letter_space;
|
||||||
}
|
}
|
||||||
lv_coord_t letter_width = lv_font_get_width(font, letter);
|
|
||||||
cur_w += letter_width;
|
|
||||||
if(cur_w > max_width) {
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*If this a break char then break here.*/
|
|
||||||
if(is_break_char(letter)) {
|
|
||||||
/* Now 'i' points to the next char because of txt_utf8_next()
|
|
||||||
* But we need the first char of the next line so keep it.
|
|
||||||
* Hence do nothing here*/
|
|
||||||
}
|
|
||||||
/*If already a break character is found, then break there*/
|
|
||||||
if(last_break != NO_BREAK_FOUND) {
|
|
||||||
i = last_break;
|
|
||||||
} else {
|
} else {
|
||||||
/* Now this character is out of the area so it will be first character of the next line*/
|
/* Now this character is out of the area so it will be first character of the next line*/
|
||||||
/* But 'i' already points to the next character (because of lv_txt_utf8_next) step beck one*/
|
/* But 'i' already points to the next character (because of lv_txt_utf8_next) step beck one*/
|
||||||
@ -222,6 +219,7 @@ uint16_t lv_txt_get_next_line(const char * txt, const lv_font_t * font,
|
|||||||
* txt can be broken here later */
|
* txt can be broken here later */
|
||||||
else if(is_break_char(letter)) {
|
else if(is_break_char(letter)) {
|
||||||
last_break = i; /*Save the first char index after break*/
|
last_break = i; /*Save the first char index after break*/
|
||||||
|
w_at_last_break = cur_w;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user