mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-28 07:03:00 +08:00
Mostly working long text; need to fix dangling newline and remove debugging code
This commit is contained in:
parent
3227a2c780
commit
44b2197721
@ -13,6 +13,7 @@
|
||||
#include "lv_disp.h"
|
||||
#include "../lv_themes/lv_theme.h"
|
||||
#include "../lv_draw/lv_draw.h"
|
||||
#include "../lv_draw/lv_img_cache.h"
|
||||
#include "../lv_misc/lv_anim.h"
|
||||
#include "../lv_misc/lv_task.h"
|
||||
#include "../lv_misc/lv_fs.h"
|
||||
|
@ -8,7 +8,10 @@
|
||||
*********************/
|
||||
#include "lv_txt.h"
|
||||
#include "lv_math.h"
|
||||
|
||||
// TODO: remove
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
@ -152,13 +155,14 @@ static uint16_t lv_txt_get_next_word(const char * txt, const lv_font_t * font,
|
||||
lv_coord_t letter_space, lv_coord_t max_width,
|
||||
lv_txt_flag_t flag, uint32_t *word_w_ptr)
|
||||
{
|
||||
if(txt == NULL) return 0;
|
||||
if(txt == NULL || txt[0] == '\0') return 0;
|
||||
if(font == NULL) return 0;
|
||||
|
||||
if(flag & LV_TXT_FLAG_EXPAND) max_width = LV_COORD_MAX;
|
||||
|
||||
uint32_t i = 0; /* Iterating index into txt */
|
||||
uint32_t i_next = 0; /* */
|
||||
uint32_t i_next_next = 0; /* */
|
||||
lv_txt_cmd_state_t cmd_state = LV_TXT_CMD_STATE_WAIT;
|
||||
uint32_t letter_w;
|
||||
uint32_t letter = 0; /* Letter at i */
|
||||
@ -168,13 +172,19 @@ static uint16_t lv_txt_get_next_word(const char * txt, const lv_font_t * font,
|
||||
uint32_t break_letter_count = 0;
|
||||
lv_coord_t cur_w = 0; /* Pixel Width of transversed string */
|
||||
|
||||
letter_next = lv_txt_encoded_next(txt, &i_next);
|
||||
printf("max width: %d\n", max_width);
|
||||
letter = lv_txt_encoded_next(txt, &i_next);
|
||||
i_next_next = i_next;
|
||||
|
||||
if(letter == '\n' || letter == '\r' || is_break_char(letter)) {
|
||||
//printf("pre_while_loop: %d\n", i_next);
|
||||
return i_next;
|
||||
}
|
||||
|
||||
while(txt[i] != '\0') {
|
||||
letter = letter_next;
|
||||
i = i_next;
|
||||
letter_next = lv_txt_encoded_next(txt, &i_next);
|
||||
//printf("top of while %d\n", i);
|
||||
letter_next = lv_txt_encoded_next(txt, &i_next_next);
|
||||
//printf("i: %d i_next: %d i_next_next: %d txt[i]:\"%c\" letter:\"%c\"\n", i, i_next, i_next_next, txt[i], letter);
|
||||
//assert(txt[i]==letter);
|
||||
word_len++;
|
||||
|
||||
/*Handle the recolor command*/
|
||||
@ -187,13 +197,15 @@ static uint16_t lv_txt_get_next_word(const char * txt, const lv_font_t * font,
|
||||
/*Check the transversed string pixel width*/
|
||||
letter_w = lv_font_get_glyph_width(font, letter, letter_next);
|
||||
cur_w += letter_w;
|
||||
//printf("%d BLOOP\n", __LINE__);
|
||||
|
||||
/* Test if this character fits within max_width */
|
||||
if( break_index == NO_BREAK_FOUND && cur_w > max_width) {
|
||||
printf("cur_w %d exceeds max_width %d\n", cur_w, max_width);
|
||||
// break_index is now pointing at the character that doesn't fit
|
||||
break_index = i;
|
||||
lv_txt_encoded_prev(txt, &break_index);
|
||||
if(break_index > 0) { // zero is possible if first character doesn't fit in width
|
||||
lv_txt_encoded_prev(txt, &break_index);
|
||||
}
|
||||
break_letter_count = word_len - 1;
|
||||
}
|
||||
|
||||
@ -204,34 +216,35 @@ static uint16_t lv_txt_get_next_word(const char * txt, const lv_font_t * font,
|
||||
|
||||
/*Check for new line chars and breakchars*/
|
||||
if(letter == '\n' || letter == '\r' || is_break_char(letter)) {
|
||||
// i is now pointing at the character after the word
|
||||
printf("break found at %d\n", i);
|
||||
word_len--;
|
||||
//printf("meow %d %d\n", i, i_next);
|
||||
break;
|
||||
}
|
||||
|
||||
if(letter_w > 0) {
|
||||
cur_w += letter_space;
|
||||
}
|
||||
i = i_next;
|
||||
i_next = i_next_next;
|
||||
letter = letter_next;
|
||||
}
|
||||
|
||||
/* Entire Word fits in the provided space */
|
||||
if( break_index == NO_BREAK_FOUND ) {
|
||||
printf("nobreak\n");
|
||||
//if( word_w_ptr != NULL && (letter == '\r' || letter == '\n')) *word_w_ptr = 0;
|
||||
if(letter == '\r' && letter_next == '\n') return i_next;
|
||||
//printf("(%d): txt[i] \"%c\"\n", __LINE__, txt[i]);
|
||||
return i;
|
||||
}
|
||||
|
||||
/* Word doesn't fit in provided space, but isn't "long" */
|
||||
if(word_len < LV_TXT_LINE_BREAK_LONG_LEN) {
|
||||
printf("doesn't fit in space\n");
|
||||
if(word_w_ptr != NULL) *word_w_ptr = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Word is "long," but insufficient amounts can fit in provided space */
|
||||
if(break_letter_count < LV_TXT_LINE_BREAK_LONG_PRE_MIN_LEN) {
|
||||
printf("long, doesn't fit in space\n");
|
||||
if(word_w_ptr != NULL) *word_w_ptr = 0;
|
||||
return 0;
|
||||
}
|
||||
@ -277,32 +290,35 @@ uint16_t lv_txt_get_next_line(const char * txt, const lv_font_t * font,
|
||||
if(flag & LV_TXT_FLAG_EXPAND) max_width = LV_COORD_MAX;
|
||||
|
||||
uint32_t i = 0; /* Iterating index into txt */
|
||||
uint32_t i_next = 0; /* */
|
||||
uint32_t letter = 0; /* Letter at i */
|
||||
uint32_t letter_next = 0; /* Letter at i_next */
|
||||
|
||||
letter_next = lv_txt_encoded_next(txt, &i_next);
|
||||
|
||||
printf("\n\n\n");
|
||||
|
||||
while(txt[i] != '\0') {
|
||||
//letter = letter_next;
|
||||
//i = i_next;
|
||||
//letter_next = lv_txt_encoded_next(txt, &i_next);
|
||||
//printf("\n\n(%d): FULL_TEXT (len %d) \"%s\"\n", __LINE__, strlen(txt), txt);
|
||||
|
||||
while(txt[i] != '\0' && max_width > 0) {
|
||||
//printf("(%d): MAX_WIDTH: %d\n", __LINE__, max_width);
|
||||
uint32_t word_w = 0;
|
||||
uint32_t advance = lv_txt_get_next_word(&txt[i], font, letter_space,
|
||||
max_width, flag, &word_w);
|
||||
printf("word_w: %d\n", word_w);
|
||||
max_width -= word_w;
|
||||
|
||||
{ //debug
|
||||
printf("Word is %d long: \"", advance);
|
||||
for(uint32_t j = 0; j < advance; j++){
|
||||
printf("%c", txt[i+j]);
|
||||
}
|
||||
printf("\"\n");
|
||||
}
|
||||
|
||||
if( advance == 0 ){
|
||||
if(i == 0) lv_txt_encoded_next(txt, &i); // prevent inf loops
|
||||
if(i == 0) {
|
||||
lv_txt_encoded_next(txt, &i); // prevent inf loops
|
||||
printf("inf loop prevented\n");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
printf("Getting next word\n");
|
||||
i += advance;
|
||||
|
||||
if(txt[i] == '\n') { printf("nl_break\n");break;}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user