remove LV_TXT_FLAG_NO_BREAK. Text area in one line mode handle's it in its own

This commit is contained in:
Gabor Kiss-Vamosi
2018-07-25 19:36:53 +02:00
parent c4aec5ae33
commit 2d5fa3b9dc
8 changed files with 40 additions and 63 deletions

View File

@@ -63,7 +63,7 @@ static lv_ll_t scr_ll; /*Linked list of screens*/
void lv_init(void)
{
#if USE_LV_LOG
lv_log_add(LV_LOG_LEVEL_INFO, __FILE__, __LINE__, "lv_init called");
lv_log_add(LV_LOG_LEVEL_TRACE, __FILE__, __LINE__, "lv_init called");
#endif
/*Initialize the lv_misc modules*/
@@ -107,7 +107,7 @@ void lv_init(void)
#endif
#if USE_LV_LOG
lv_log_add(LV_LOG_LEVEL_INFO, __FILE__, __LINE__, "lv_init finished");
lv_log_add(LV_LOG_LEVEL_INFO, __FILE__, __LINE__, "lv_init ready");
#endif
}
@@ -124,9 +124,14 @@ void lv_init(void)
*/
lv_obj_t * lv_obj_create(lv_obj_t * parent, lv_obj_t * copy)
{
lv_obj_t * new_obj = NULL;
/*Create a screen if the parent is NULL*/
if(parent == NULL) {
#if USE_LV_LOG
lv_log_add(LV_LOG_LEVEL_TRACE, __FILE__, __LINE__, "Screen create started");
#endif
new_obj = lv_ll_ins_head(&scr_ll);
lv_mem_assert(new_obj);
if(new_obj == NULL) return NULL;
@@ -176,9 +181,16 @@ lv_obj_t * lv_obj_create(lv_obj_t * parent, lv_obj_t * copy)
new_obj->opa_scale = LV_OPA_COVER;
new_obj->ext_attr = NULL;
#if USE_LV_LOG
lv_log_add(LV_LOG_LEVEL_INFO, __FILE__, __LINE__, "Screen create ready");
#endif
}
/*parent != NULL create normal obj. on a parent*/
else {
#if USE_LV_LOG
lv_log_add(LV_LOG_LEVEL_TRACE, __FILE__, __LINE__, "Object create started");
#endif
new_obj = lv_ll_ins_head(&(parent)->child_ll);
lv_mem_assert(new_obj);
if(new_obj == NULL) return NULL;
@@ -260,6 +272,10 @@ lv_obj_t * lv_obj_create(lv_obj_t * parent, lv_obj_t * copy)
#endif
lv_obj_set_pos(new_obj, lv_obj_get_x(copy), lv_obj_get_y(copy));
#if USE_LV_LOG
lv_log_add(LV_LOG_LEVEL_INFO, __FILE__, __LINE__, "Object create ready");
#endif
}

View File

@@ -151,12 +151,12 @@ void lv_disp_flush(int32_t x1, int32_t y1, int32_t x2, int32_t y2, lv_color_t *
if(active->driver.disp_flush != NULL) {
#if USE_LV_LOG
lv_log_add(LV_LOG_LEVEL_TRACE, __FILE__, __LINE__, "Disp. flush called");
lv_log_add(LV_LOG_LEVEL_DEBUG, __FILE__, __LINE__, "Disp. flush called");
#endif
active->driver.disp_flush(x1, y1, x2, y2, color_p);
#if USE_LV_LOG
lv_log_add(LV_LOG_LEVEL_TRACE, __FILE__, __LINE__, "Disp. flush finished");
lv_log_add(LV_LOG_LEVEL_TRACE, __FILE__, __LINE__, "Disp. flush ready");
#endif
} else {

View File

@@ -112,11 +112,11 @@ bool lv_indev_read(lv_indev_t * indev, lv_indev_data_t * data)
if(indev->driver.read) {
data->user_data = indev->driver.user_data;
#if USE_LV_LOG
lv_log_add(LV_LOG_LEVEL_TRACE, __FILE__, __LINE__, "Indev read called");
lv_log_add(LV_LOG_LEVEL_DEBUG, __FILE__, __LINE__, "Indev read called");
#endif
cont = indev->driver.read(data);
#if USE_LV_LOG
lv_log_add(LV_LOG_LEVEL_TRACE, __FILE__, __LINE__, "Indev read finished");
lv_log_add(LV_LOG_LEVEL_TRACE, __FILE__, __LINE__, "Indev read ready");
#endif
} else {
#if USE_LV_LOG

View File

@@ -48,7 +48,6 @@ static bool is_break_char(uint32_t letter);
void lv_txt_get_size(lv_point_t * size_res, const char * text, const lv_font_t * font,
lv_coord_t letter_space, lv_coord_t line_space, lv_coord_t max_width, lv_txt_flag_t flag)
{
size_res->x = 0;
size_res->y = 0;
@@ -76,7 +75,8 @@ void lv_txt_get_size(lv_point_t * size_res, const char * text, const lv_font_t *
line_start = new_line_start;
}
if(line_start != 0 && (text[line_start - 1] == '\n' || text[line_start - 1] == '\r')) {
/*Ma ke the text one line taller if the last character is '\n' or '\r'*/
if((line_start != 0) && (text[line_start - 1] == '\n' || text[line_start - 1] == '\r')) {
size_res->y += letter_height + line_space;
}
@@ -118,9 +118,9 @@ uint16_t lv_txt_get_next_line(const char * txt, const lv_font_t * font,
continue; /*Skip the letter is it is part of a command*/
}
}
/*Check for new line chars*/
if((flag & LV_TXT_FLAG_NO_BREAK) == 0 && (letter == '\n' || letter == '\r')) {
/*Handle \r\n as well*/
if(letter == '\n' || letter == '\r') {
uint32_t i_tmp = i;
uint32_t letter_next = lv_txt_utf8_next(txt, &i_tmp);
if(letter == '\r' && letter_next == '\n') i = i_tmp;
@@ -194,8 +194,11 @@ lv_coord_t lv_txt_get_width(const char * txt, uint16_t length,
continue;
}
}
width += lv_font_get_width(font, letter);
width += letter_space;
}
width -= letter_space; /*Trim the last letter space. Important if the text is center aligned */

View File

@@ -37,8 +37,7 @@ typedef enum
LV_TXT_FLAG_NONE = 0x00,
LV_TXT_FLAG_RECOLOR = 0x01, /*Enable parsing of recolor command*/
LV_TXT_FLAG_EXPAND = 0x02, /*Ignore width (Used by the library)*/
LV_TXT_FLAG_NO_BREAK = 0x04, /*Ignore line breaks (Used by the library)*/
LV_TXT_FLAG_CENTER = 0x08, /*Align the text to the middle*/
LV_TXT_FLAG_CENTER = 0x04, /*Align the text to the middle*/
} lv_txt_flag_t;
typedef enum

View File

@@ -86,7 +86,6 @@ lv_obj_t * lv_label_create(lv_obj_t * par, lv_obj_t * copy)
ext->text = NULL;
ext->static_txt = 0;
ext->recolor = 0;
ext->no_break = 0;
ext->body_draw = 0;
ext->align = LV_LABEL_ALIGN_LEFT;
ext->dot_end = LV_LABEL_DOT_END_INV;
@@ -300,21 +299,6 @@ void lv_label_set_recolor(lv_obj_t * label, bool recolor_en)
lv_label_refr_text(label); /*Refresh the text because the potential colo codes in text needs to be hided or revealed*/
}
/**
* Set the label to ignore (or accept) line breaks on '\n'
* @param label pointer to a label object
* @param no_break_en true: ignore line breaks, false: make line breaks on '\n'
*/
void lv_label_set_no_break(lv_obj_t * label, bool no_break_en)
{
lv_label_ext_t * ext = lv_obj_get_ext_attr(label);
if(ext->no_break == no_break_en) return;
ext->no_break = no_break_en == false ? 0 : 1;
lv_label_refr_text(label);
}
/**
* Set the label to draw (or not draw) background specified in its style's body
* @param label pointer to a label object
@@ -398,17 +382,6 @@ bool lv_label_get_recolor(lv_obj_t * label)
return ext->recolor == 0 ? false : true;
}
/**
* Get the no break attribute
* @param label pointer to a label object
* @return true: no_break_enabled (ignore '\n' line breaks); false: make line breaks on '\n'
*/
bool lv_label_get_no_break(lv_obj_t * label)
{
lv_label_ext_t * ext = lv_obj_get_ext_attr(label);
return ext->no_break == 0 ? false : true;
}
/**
* Get the body draw attribute
* @param label pointer to a label object
@@ -452,7 +425,6 @@ void lv_label_get_letter_pos(lv_obj_t * label, uint16_t index, lv_point_t * pos)
if(ext->recolor != 0) flag |= LV_TXT_FLAG_RECOLOR;
if(ext->expand != 0) flag |= LV_TXT_FLAG_EXPAND;
if(ext->no_break != 0) flag |= LV_TXT_FLAG_NO_BREAK;
if(ext->align == LV_LABEL_ALIGN_CENTER) flag |= LV_TXT_FLAG_CENTER;
/*If the width will be expanded the set the max length to very big */
@@ -529,7 +501,6 @@ uint16_t lv_label_get_letter_on(lv_obj_t * label, lv_point_t * pos)
if(ext->recolor != 0) flag |= LV_TXT_FLAG_RECOLOR;
if(ext->expand != 0) flag |= LV_TXT_FLAG_EXPAND;
if(ext->no_break != 0) flag |= LV_TXT_FLAG_NO_BREAK;
if(ext->align == LV_LABEL_ALIGN_CENTER) flag |= LV_TXT_FLAG_CENTER;
/*If the width will be expanded set the max length to very big */
@@ -696,7 +667,6 @@ static bool lv_label_design(lv_obj_t * label, const lv_area_t * mask, lv_design_
lv_txt_flag_t flag = LV_TXT_FLAG_NONE;
if(ext->recolor != 0) flag |= LV_TXT_FLAG_RECOLOR;
if(ext->expand != 0) flag |= LV_TXT_FLAG_EXPAND;
if(ext->no_break != 0) flag |= LV_TXT_FLAG_NO_BREAK;
if(ext->align == LV_LABEL_ALIGN_CENTER) flag |= LV_TXT_FLAG_CENTER;
lv_draw_label(&coords, mask, style, opa_scale, ext->text, flag, &ext->offset);
@@ -781,7 +751,6 @@ static void lv_label_refr_text(lv_obj_t * label)
lv_txt_flag_t flag = LV_TXT_FLAG_NONE;
if(ext->recolor != 0) flag |= LV_TXT_FLAG_RECOLOR;
if(ext->expand != 0) flag |= LV_TXT_FLAG_EXPAND;
if(ext->no_break != 0) flag |= LV_TXT_FLAG_NO_BREAK;
lv_txt_get_size(&size, ext->text, font, style->text.letter_space, style->text.line_space, max_w, flag);
/*Set the full size in expand mode*/

View File

@@ -71,7 +71,6 @@ typedef struct
uint8_t align :2; /*Align type from 'lv_label_align_t'*/
uint8_t recolor :1; /*Enable in-line letter re-coloring*/
uint8_t expand :1; /*Ignore real width (used by the library with LV_LABEL_LONG_ROLL)*/
uint8_t no_break :1; /*Ignore new line characters*/
uint8_t body_draw :1; /*Draw background body*/
} lv_label_ext_t;
@@ -137,13 +136,6 @@ void lv_label_set_align(lv_obj_t *label, lv_label_align_t align);
*/
void lv_label_set_recolor(lv_obj_t * label, bool recolor_en);
/**
* Set the label to ignore (or accept) line breaks on '\n'
* @param label pointer to a label object
* @param no_break_en true: ignore line breaks, false: make line breaks on '\n'
*/
void lv_label_set_no_break(lv_obj_t * label, bool no_break_en);
/**
* Set the label to draw (or not draw) background specified in its style's body
* @param label pointer to a label object
@@ -199,12 +191,6 @@ lv_label_align_t lv_label_get_align(lv_obj_t * label);
*/
bool lv_label_get_recolor(lv_obj_t * label);
/**
* Get the no break attribute
* @param label pointer to a label object
* @return true: no_break_enabled (ignore '\n' line breaks); false: make line breaks on '\n'
*/
bool lv_label_get_no_break(lv_obj_t * label);
/**
* Get the body draw attribute
* @param label pointer to a label object

View File

@@ -187,6 +187,13 @@ void lv_ta_add_char(lv_obj_t * ta, char c)
{
lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta);
if(ext->one_line && (c == '\n' || c == '\n')) {
#if USE_LV_LOG
lv_log_add(LV_LOG_LEVEL_WARN, __FILE__, __LINE__, "Text area: line break ignored in one-line mode");
#endif
return;
}
if(ext->pwd_mode != 0) pwd_char_hider(ta); /*Make sure all the current text contains only '*'*/
char letter_buf[2];
letter_buf[0] = c;
@@ -234,11 +241,10 @@ void lv_ta_add_text(lv_obj_t * ta, const char * txt)
{
lv_ta_ext_t * ext = lv_obj_get_ext_attr(ta);
if(ext->pwd_mode != 0) pwd_char_hider(ta); /*Make sure all the current text contains only '*'*/
/*Insert the text*/
lv_label_ins_text(ext->label, ext->cursor.pos, txt);
if(ext->pwd_mode != 0) {
ext->pwd_tmp = lv_mem_realloc(ext->pwd_tmp, strlen(ext->pwd_tmp) + strlen(txt) + 1);
lv_mem_assert(ext->pwd_tmp);
@@ -503,7 +509,6 @@ void lv_ta_set_one_line(lv_obj_t * ta, bool en)
lv_page_set_scrl_fit(ta, true, true);
lv_obj_set_height(ta, font_h + (style_ta->body.padding.ver + style_scrl->body.padding.ver) * 2);
lv_label_set_long_mode(ext->label, LV_LABEL_LONG_EXPAND);
lv_label_set_no_break(ext->label, true);
lv_obj_set_pos(lv_page_get_scrl(ta), style_ta->body.padding.hor, style_ta->body.padding.ver);
} else {
lv_style_t * style_ta = lv_obj_get_style(ta);
@@ -511,7 +516,6 @@ void lv_ta_set_one_line(lv_obj_t * ta, bool en)
ext->one_line = 0;
lv_page_set_scrl_fit(ta, false, true);
lv_label_set_long_mode(ext->label, LV_LABEL_LONG_BREAK);
lv_label_set_no_break(ext->label, false);
lv_obj_set_height(ta, LV_TA_DEF_HEIGHT);
lv_obj_set_pos(lv_page_get_scrl(ta), style_ta->body.padding.hor, style_ta->body.padding.ver);
}