1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-28 07:03:00 +08:00

lv_ta: lv_ta_set_one_line added

This commit is contained in:
Gabor 2017-08-16 11:28:04 +02:00
parent 3e053db00b
commit 1ff5f1f91d
4 changed files with 91 additions and 10 deletions

View File

@ -84,6 +84,7 @@ lv_obj_t * lv_label_create(lv_obj_t * par, lv_obj_t * copy)
ext->txt = NULL;
ext->static_txt = 0;
ext->recolor = 0;
ext->no_break = 0;
ext->dot_end = LV_LABEL_DOT_END_INV;
ext->long_mode = LV_LABEL_LONG_EXPAND;
ext->offset.x = 0;
@ -308,6 +309,19 @@ void lv_label_set_recolor(lv_obj_t * label, bool recolor)
lv_label_refr_text(label);
}
/**
* Set the label the ignore (or accept) line breaks on '\n'
* @param label pointer to a label object
* @param en true: ignore line breaks, false: make line breaks on '\n'
*/
void lv_label_set_no_break(lv_obj_t * label, bool en)
{
lv_label_ext_t * ext = lv_obj_get_ext(label);
ext->no_break = en == false ? 0 : 1;
lv_label_refr_text(label);
}
/*=====================
* Getter functions
*====================*/
@ -367,6 +381,7 @@ void lv_label_get_letter_pos(lv_obj_t * label, uint16_t index, point_t * pos)
if(ext->recolor != 0) flag |= TXT_FLAG_RECOLOR;
if(ext->expand != 0) flag |= TXT_FLAG_EXPAND;
if(ext->no_break != 0) flag |= TXT_FLAG_NO_BREAK;
/*If the width will be expanded the set the max length to very big */
if(ext->long_mode == LV_LABEL_LONG_EXPAND || ext->long_mode == LV_LABEL_LONG_SCROLL) {
@ -402,6 +417,8 @@ void lv_label_get_letter_pos(lv_obj_t * label, uint16_t index, point_t * pos)
}
if(x > style->letter_space) x-= style->letter_space;
if(style->txt_align == LV_TXT_ALIGN_MID) {
cord_t line_w;
line_w = txt_get_width(&txt[line_start], new_line_start - line_start,
@ -435,6 +452,7 @@ uint16_t lv_label_get_letter_on(lv_obj_t * label, point_t * pos)
if(ext->recolor != 0) flag |= TXT_FLAG_RECOLOR;
if(ext->expand != 0) flag |= TXT_FLAG_EXPAND;
if(ext->no_break != 0) flag |= TXT_FLAG_NO_BREAK;
/*If the width will be expanded set the max length to very big */
if(ext->long_mode == LV_LABEL_LONG_EXPAND || ext->long_mode == LV_LABEL_LONG_SCROLL) {
@ -513,6 +531,7 @@ static bool lv_label_design(lv_obj_t * label, const area_t * mask, lv_design_mod
txt_flag_t flag = TXT_FLAG_NONE;
if(ext->recolor != 0) flag |= TXT_FLAG_RECOLOR;
if(ext->expand != 0) flag |= TXT_FLAG_EXPAND;
if(ext->no_break != 0) flag |= TXT_FLAG_NO_BREAK;
lv_draw_label(&cords, mask, style, ext->txt, flag, &ext->offset);
}
@ -546,6 +565,7 @@ static void lv_label_refr_text(lv_obj_t * label)
txt_flag_t flag = TXT_FLAG_NONE;
if(ext->recolor != 0) flag |= TXT_FLAG_RECOLOR;
if(ext->expand != 0) flag |= TXT_FLAG_EXPAND;
if(ext->no_break != 0) flag |= TXT_FLAG_NO_BREAK;
txt_get_size(&size, ext->txt, font, style->letter_space, style->line_space, max_w, flag);
/*Refresh the full size in expand mode*/

View File

@ -51,7 +51,8 @@ typedef struct
point_t offset; /*Text draw position offset*/
uint8_t static_txt :1; /*Flag to indicate the text is static*/
uint8_t recolor :1; /*Enable in-line letter re-coloring*/
uint8_t expand :1; /*Force expand size when solving line length (used by the library with LV_LABEL_LONG_ROLL)*/
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*/
}lv_label_ext_t;
/**********************
@ -119,12 +120,13 @@ void lv_label_set_long_mode(lv_obj_t * label, lv_label_long_mode_t long_mode);
*/
void lv_label_set_recolor(lv_obj_t * label, bool recolor);
/**
* Enable the password mode
* Set the label the ignore (or accept) line breaks on '\n'
* @param label pointer to a label object
* @param pwd true: enable password mode, false: disable
* @param en true: ignore line breaks, false: make line breaks on '\n'
*/
void lv_label_set_pwd_mode(lv_obj_t * label, bool pwd);
void lv_label_set_no_break(lv_obj_t * label, bool en);
/**
* Get the text of a label

View File

@ -173,12 +173,13 @@ bool lv_ta_signal(lv_obj_t * ta, lv_signal_t sign, void * param)
} else if(sign == LV_SIGNAL_CORD_CHG) {
/*Set the label width according to the text area width*/
if(ext->label != NULL) {
lv_obj_set_width(ext->label, lv_obj_get_width(ta) - 2 *
(style->hpad + style->hpad));
if(lv_obj_get_width(ta) != area_get_width(param) ||
lv_obj_get_height(ta) != area_get_height(param)) {
lv_obj_set_width(ext->label, lv_obj_get_width(ta) - 2 * style->hpad);
lv_label_set_text(ext->label, NULL);
}
}
} else if (sign == LV_SIGNAL_CONTROLL) {
lv_ta_ext_t * ext = lv_obj_get_ext(ta);
char c = *((char*)param);
if(c == LV_GROUP_KEY_RIGHT) {
lv_ta_cursor_right(ta);
@ -312,6 +313,12 @@ void lv_ta_set_text(lv_obj_t * ta, const char * txt)
lv_label_set_text(ext->label, txt);
lv_ta_set_cursor_pos(ta, LV_TA_CUR_LAST);
/*Don't let 'width == 0' because cursor will not be visible*/
if(lv_obj_get_width(ext->label) == 0) {
lv_style_t * style = lv_obj_get_style(ext->label);
lv_obj_set_width(ext->label, style->line_width);
}
/*It is a valid x step so save it*/
lv_ta_save_valid_cursor_x(ta);
@ -353,6 +360,11 @@ void lv_ta_del(lv_obj_t * ta)
/*Refresh the label*/
lv_label_set_text(ext->label, buf);
/*Don't let 'width == 0' because cursor will not be visible*/
if(lv_obj_get_width(ext->label) == 0) {
lv_style_t * style = lv_obj_get_style(ext->label);
lv_obj_set_width(ext->label, style->line_width);
}
/*Move the cursor to the place of the deleted character*/
lv_ta_set_cursor_pos(ta, lv_ta_get_cursor_pos(ta) - 1);
@ -404,6 +416,16 @@ void lv_ta_set_cursor_pos(lv_obj_t * ta, int16_t pos)
lv_obj_set_y(label_par, -(cur_pos.y - lv_obj_get_height(ta) +
font_h + 2 * style_scrl->vpad));
}
/*Check the left (use the font_h as general unit)*/
if(lv_obj_get_x(label_par) + cur_pos.x < font_h) {
lv_obj_set_x(label_par, - cur_pos.x + font_h);
}
/*Check the right (use the font_h as general unit)*/
if(label_cords.x1 + cur_pos.x + font_h + style_scrl->hpad > ta_cords.x2) {
lv_obj_set_x(label_par, -(cur_pos.x - lv_obj_get_width(ta) +
font_h + 2 * style_scrl->hpad));
}
lv_obj_inv(ta);
}
@ -533,6 +555,36 @@ void lv_ta_set_pwd_mode(lv_obj_t * ta, bool en)
ext->pwd_mode = en == false ? 0 : 1;
}
/**
* Configure the text area to one line or back to normal
* @param ta pointer to a Text area object
* @param en true: one line, false: normal
*/
void lv_ta_set_one_line(lv_obj_t * ta, bool en)
{
if(en != false) {
lv_ta_ext_t * ext = lv_obj_get_ext(ta);
lv_style_t * style_ta = lv_obj_get_style(ta);
lv_style_t * style_label = lv_obj_get_style(ext->label);
lv_cont_set_fit(lv_page_get_scrl(ta), true, true);
lv_obj_set_height(ta, font_get_height(style_label->font) + style_ta->vpad * 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->hpad, style_ta->vpad);
} else {
lv_ta_ext_t * ext = lv_obj_get_ext(ta);
lv_style_t * style_ta = lv_obj_get_style(ta);
lv_cont_set_fit(lv_page_get_scrl(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->hpad, style_ta->vpad);
}
}
/*=====================
* Getter functions
*====================*/
@ -664,9 +716,9 @@ static bool lv_ta_scrling_design(lv_obj_t * scrling, const area_t * mask, lv_des
area_t cur_area;
lv_style_t * labels_p = lv_obj_get_style(ta_ext->label);
cur_area.x1 = letter_pos.x + ta_ext->label->cords.x1;
cur_area.x1 = letter_pos.x + ta_ext->label->cords.x1 - scrl_style->line_width / 2 ;
cur_area.y1 = letter_pos.y + ta_ext->label->cords.y1;
cur_area.x2 = letter_pos.x + ta_ext->label->cords.x1 + scrl_style->line_width ;
cur_area.x2 = letter_pos.x + ta_ext->label->cords.x1 + scrl_style->line_width / 2 + (scrl_style->line_width & 0x1);
cur_area.y2 = letter_pos.y + ta_ext->label->cords.y1 + (font_get_height(labels_p->font) >> FONT_ANTIALIAS);
lv_style_t cur_rects;

View File

@ -147,6 +147,13 @@ void lv_ta_set_cursor_show(lv_obj_t * ta, bool show);
*/
void lv_ta_set_pwd_mode(lv_obj_t * ta, bool en);
/**
* Configure the Text area to one line or back to normal
* @param ta pointer to a text area object
* @param en true: one line, false: normal
*/
void lv_ta_set_one_line(lv_obj_t * ta, bool en);
/**
* Get the text of the i the text area
* @param ta obj pointer to a text area object