lv_label: LV_LABEL_LONG_ROLL addad to scroll the text not the object
This commit is contained in:
@@ -228,14 +228,22 @@ void lv_draw_triangle(const point_t * points, const area_t * mask_p, color_t col
|
||||
* @param style pointer to a style
|
||||
* @param txt 0 terminated text to write
|
||||
* @param flag settings for the text from 'txt_flag_t' enum
|
||||
* @param offset text offset in x and y direction (NULL if unused)
|
||||
*
|
||||
*/
|
||||
void lv_draw_label(const area_t * cords_p,const area_t * mask_p, const lv_style_t * style,
|
||||
const char * txt, txt_flag_t flag)
|
||||
const char * txt, txt_flag_t flag, point_t * offset)
|
||||
{
|
||||
const font_t * font = style->font;
|
||||
cord_t w;
|
||||
|
||||
cord_t w = area_get_width(cords_p);
|
||||
|
||||
if((flag & TXT_FLAG_EXPAND) == 0) {
|
||||
w = area_get_width(cords_p);
|
||||
} else {
|
||||
point_t p;
|
||||
txt_get_size(&p, txt, style->font, style->letter_space, style->line_space, CORD_MAX, flag);
|
||||
w = p.x;
|
||||
}
|
||||
/*Init variables for the first line*/
|
||||
cord_t line_length = 0;
|
||||
uint32_t line_start = 0;
|
||||
@@ -257,8 +265,15 @@ void lv_draw_label(const area_t * cords_p,const area_t * mask_p, const lv_style_
|
||||
uint16_t par_start;
|
||||
color_t recolor;
|
||||
|
||||
if(offset != NULL) {
|
||||
pos.y += offset->y;
|
||||
}
|
||||
|
||||
/*Write out all lines*/
|
||||
while(txt[line_start] != '\0') {
|
||||
if(offset != NULL) {
|
||||
pos.x += offset->x;
|
||||
}
|
||||
/*Write all letter of a line*/
|
||||
cmd_state = CMD_STATE_WAIT;
|
||||
|
||||
@@ -305,8 +320,11 @@ void lv_draw_label(const area_t * cords_p,const area_t * mask_p, const lv_style_
|
||||
if(cmd_state == CMD_STATE_IN) color = recolor;
|
||||
letter_fp(&pos, mask_p, font, letter, color, style->opa);
|
||||
|
||||
if((flag & TXT_FLAG_PWD) == 0 || txt[i + 1] == '\0') pos.x += (font_get_width(font, txt[i]) >> FONT_ANTIALIAS) + style->letter_space;
|
||||
else pos.x += (font_get_width(font, '*') >> FONT_ANTIALIAS) + style->letter_space;
|
||||
if((flag & TXT_FLAG_PWD) == 0 || txt[i + 1] == '\0') {
|
||||
pos.x += (font_get_width(font, txt[i]) >> FONT_ANTIALIAS) + style->letter_space;
|
||||
} else {
|
||||
pos.x += (font_get_width(font, '*') >> FONT_ANTIALIAS) + style->letter_space;
|
||||
}
|
||||
}
|
||||
/*Go to next line*/
|
||||
line_start = line_end;
|
||||
@@ -337,7 +355,7 @@ void lv_draw_img(const area_t * cords_p, const area_t * mask_p,
|
||||
{
|
||||
if(fn == NULL) {
|
||||
lv_draw_rect(cords_p, mask_p, lv_style_get(LV_STYLE_PLAIN, NULL));
|
||||
lv_draw_label(cords_p, mask_p, lv_style_get(LV_STYLE_PLAIN, NULL), "No data", TXT_FLAG_NONE);
|
||||
lv_draw_label(cords_p, mask_p, lv_style_get(LV_STYLE_PLAIN, NULL), "No data", TXT_FLAG_NONE, NULL);
|
||||
} else {
|
||||
fs_file_t file;
|
||||
fs_res_t res = fs_open(&file, fn, FS_MODE_RD);
|
||||
@@ -417,7 +435,7 @@ void lv_draw_img(const area_t * cords_p, const area_t * mask_p,
|
||||
|
||||
if(res != FS_RES_OK) {
|
||||
lv_draw_rect(cords_p, mask_p, lv_style_get(LV_STYLE_PLAIN, NULL));
|
||||
lv_draw_label(cords_p, mask_p, lv_style_get(LV_STYLE_PLAIN, NULL), "No data", TXT_FLAG_NONE);
|
||||
lv_draw_label(cords_p, mask_p, lv_style_get(LV_STYLE_PLAIN, NULL), "No data", TXT_FLAG_NONE, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,9 +53,10 @@ void lv_draw_triangle(const point_t * points, const area_t * mask_p, color_t col
|
||||
* @param style_p pointer to a style
|
||||
* @param txt 0 terminated text to write
|
||||
* @param flags settings for the text from 'txt_flag_t' enum
|
||||
* @param offset text offset in x and y direction (NULL if unused)
|
||||
*/
|
||||
void lv_draw_label(const area_t * cords_p,const area_t * mask_p, const lv_style_t * style_p,
|
||||
const char * txt, txt_flag_t flag);
|
||||
const char * txt, txt_flag_t flag, point_t * offset);
|
||||
|
||||
/**
|
||||
* Draw an image
|
||||
|
||||
@@ -437,7 +437,7 @@ static bool lv_btnm_design(lv_obj_t * btnm, const area_t * mask, lv_design_mode_
|
||||
area_tmp.x2 = area_tmp.x1 + txt_size.x;
|
||||
area_tmp.y2 = area_tmp.y1 + txt_size.y;
|
||||
|
||||
lv_draw_label(&area_tmp, mask, btn_style, ext->map_p[txt_i], TXT_FLAG_NONE);
|
||||
lv_draw_label(&area_tmp, mask, btn_style, ext->map_p[txt_i], TXT_FLAG_NONE, NULL);
|
||||
txt_i ++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -397,7 +397,7 @@ static void lv_gauge_draw_scale(lv_obj_t * gauge, const area_t * mask, lv_style_
|
||||
label_cord.x2 = label_cord.x1 + label_size.x;
|
||||
label_cord.y2 = label_cord.y1 + label_size.y;
|
||||
|
||||
lv_draw_label(&label_cord, mask, style, scale_txt, TXT_FLAG_NONE);
|
||||
lv_draw_label(&label_cord, mask, style, scale_txt, TXT_FLAG_NONE, NULL);
|
||||
}
|
||||
}
|
||||
/**
|
||||
|
||||
@@ -328,7 +328,7 @@ static bool lv_img_design(lv_obj_t * img, const area_t * mask, lv_design_mode_t
|
||||
lv_draw_img(&cords_tmp, mask, style, opa, ext->fn);
|
||||
#else
|
||||
if(sym == false) lv_draw_img(&cords_tmp, mask, style, ext->fn);
|
||||
else lv_draw_label(&cords_tmp, mask, style, ext->fn, TXT_FLAG_NONE);
|
||||
else lv_draw_label(&cords_tmp, mask, style, ext->fn, TXT_FLAG_NONE, NULL);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,6 +49,8 @@
|
||||
**********************/
|
||||
static bool lv_label_design(lv_obj_t * label, const area_t * mask, lv_design_mode_t mode);
|
||||
static void lv_label_refr_text(lv_obj_t * label);
|
||||
static void lv_label_set_offset_x(lv_obj_t * label, cord_t x);
|
||||
static void lv_label_set_offset_y(lv_obj_t * label, cord_t y);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
@@ -84,7 +86,8 @@ lv_obj_t * lv_label_create(lv_obj_t * par, lv_obj_t * copy)
|
||||
ext->pwd = 0;
|
||||
ext->dot_end = LV_LABEL_DOT_END_INV;
|
||||
ext->long_mode = LV_LABEL_LONG_EXPAND;
|
||||
|
||||
ext->offset.x = 0;
|
||||
ext->offset.y = 0;
|
||||
lv_obj_set_design_f(new_label, lv_label_design);
|
||||
lv_obj_set_signal_f(new_label, lv_label_signal);
|
||||
|
||||
@@ -139,6 +142,12 @@ bool lv_label_signal(lv_obj_t * label, lv_signal_t sign, void * param)
|
||||
lv_label_set_text(label, NULL);
|
||||
break;
|
||||
|
||||
case LV_SIGNAL_CORD_CHG:
|
||||
if(lv_obj_get_width(label) != area_get_width(param) ||
|
||||
lv_obj_get_height(label) != area_get_height(param)) {
|
||||
lv_label_refr_text(label);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -277,11 +286,16 @@ void lv_label_set_long_mode(lv_obj_t * label, lv_label_long_mode_t long_mode)
|
||||
}
|
||||
}
|
||||
|
||||
/*Delete the scroller animations*/
|
||||
if(ext->long_mode == LV_LABEL_LONG_SCROLL) {
|
||||
/*Delete the old animation (if exists)*/
|
||||
anim_del(label, (anim_fp_t) lv_obj_set_x);
|
||||
anim_del(label, (anim_fp_t) lv_obj_set_y);
|
||||
}
|
||||
anim_del(label, (anim_fp_t) lv_label_set_offset_x);
|
||||
anim_del(label, (anim_fp_t) lv_label_set_offset_y);
|
||||
ext->offset.x = 0;
|
||||
ext->offset.y = 0;
|
||||
|
||||
if(long_mode == LV_LABEL_LONG_ROLL) ext->expand = 1;
|
||||
else ext->expand = 0;
|
||||
|
||||
ext->long_mode = long_mode;
|
||||
lv_label_refr_text(label);
|
||||
@@ -385,6 +399,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->pwd != 0) flag |= TXT_FLAG_PWD;
|
||||
if(ext->expand != 0) flag |= TXT_FLAG_EXPAND;
|
||||
|
||||
/*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) {
|
||||
@@ -453,6 +468,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->pwd != 0) flag |= TXT_FLAG_PWD;
|
||||
if(ext->expand != 0) flag |= TXT_FLAG_EXPAND;
|
||||
|
||||
/*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) {
|
||||
@@ -525,9 +541,15 @@ 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->pwd != 0) flag |= TXT_FLAG_PWD;
|
||||
if(ext->expand != 0) flag |= TXT_FLAG_EXPAND;
|
||||
|
||||
if(strcmp("Folder1", ext->txt) == 0) {
|
||||
uint8_t i;
|
||||
i = 0;
|
||||
i++;
|
||||
}
|
||||
|
||||
lv_draw_label(&cords, mask, lv_obj_get_style(label), ext->txt, flag);
|
||||
lv_draw_label(&cords, mask, lv_obj_get_style(label), ext->txt, flag, &ext->offset);
|
||||
|
||||
|
||||
}
|
||||
@@ -551,7 +573,8 @@ static void lv_label_refr_text(lv_obj_t * label)
|
||||
ext->dot_end = LV_LABEL_DOT_END_INV; /*Initialize the dot end index*/
|
||||
|
||||
/*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) {
|
||||
if(ext->long_mode == LV_LABEL_LONG_EXPAND ||
|
||||
ext->long_mode == LV_LABEL_LONG_SCROLL) {
|
||||
max_w = CORD_MAX;
|
||||
}
|
||||
|
||||
@@ -560,6 +583,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->pwd != 0) flag |= TXT_FLAG_PWD;
|
||||
if(ext->expand != 0) flag |= TXT_FLAG_EXPAND;
|
||||
txt_get_size(&size, ext->txt, font, style->letter_space, style->line_space, max_w, flag);
|
||||
|
||||
/*Refresh the full size in expand mode*/
|
||||
@@ -611,6 +635,43 @@ static void lv_label_refr_text(lv_obj_t * label)
|
||||
}
|
||||
}
|
||||
}
|
||||
/*In roll mode keep the size but start offset animations*/
|
||||
else if(ext->long_mode == LV_LABEL_LONG_ROLL) {
|
||||
anim_t anim;
|
||||
anim.var = label;
|
||||
anim.repeat = 1;
|
||||
anim.playback = 1;
|
||||
anim.start = font_get_width(font, ' ') >> FONT_ANTIALIAS;
|
||||
anim.act_time = 0;
|
||||
anim.end_cb = NULL;
|
||||
anim.path = anim_get_path(ANIM_PATH_LIN);
|
||||
anim.playback_pause = LV_LABEL_SCROLL_PLAYBACK_PAUSE;
|
||||
anim.repeat_pause = LV_LABEL_SCROLL_REPEAT_PAUSE;
|
||||
|
||||
bool hor_anim = false;
|
||||
if(size.x > lv_obj_get_width(label)) {
|
||||
anim.end = lv_obj_get_width(label) - size.x -
|
||||
(font_get_width(font, ' ') >> FONT_ANTIALIAS);
|
||||
anim.fp = (anim_fp_t) lv_label_set_offset_x;
|
||||
anim.time = anim_speed_to_time(LV_LABEL_SCROLL_SPEED, anim.start, anim.end);
|
||||
anim_create(&anim);
|
||||
hor_anim = true;
|
||||
}
|
||||
|
||||
if(size.y > lv_obj_get_height(label)) {
|
||||
anim.end = lv_obj_get_height(label) - size.y -
|
||||
(font_get_height(font) - FONT_ANTIALIAS);
|
||||
anim.fp = (anim_fp_t)lv_label_set_offset_y;
|
||||
|
||||
/*Different animation speed if horizontal animation is created too*/
|
||||
if(hor_anim == false) {
|
||||
anim.time = anim_speed_to_time(LV_LABEL_SCROLL_SPEED, anim.start, anim.end);
|
||||
} else {
|
||||
anim.time = anim_speed_to_time(LV_LABEL_SCROLL_SPEED_VER, anim.start, anim.end);
|
||||
}
|
||||
anim_create(&anim);
|
||||
}
|
||||
}
|
||||
/*In break mode only the height can change*/
|
||||
else if (ext->long_mode == LV_LABEL_LONG_BREAK) {
|
||||
lv_obj_set_height(label, size.y);
|
||||
@@ -653,4 +714,18 @@ static void lv_label_refr_text(lv_obj_t * label)
|
||||
lv_obj_inv(label);
|
||||
}
|
||||
|
||||
|
||||
static void lv_label_set_offset_x(lv_obj_t * label, cord_t x)
|
||||
{
|
||||
lv_label_ext_t * ext = lv_obj_get_ext(label);
|
||||
ext->offset.x = x;
|
||||
lv_obj_inv(label);
|
||||
}
|
||||
|
||||
static void lv_label_set_offset_y(lv_obj_t * label, cord_t y)
|
||||
{
|
||||
lv_label_ext_t * ext = lv_obj_get_ext(label);
|
||||
ext->offset.y = y;
|
||||
lv_obj_inv(label);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -32,6 +32,7 @@ typedef enum
|
||||
LV_LABEL_LONG_BREAK, /*Keep the object width, break the too long lines and expand the object height*/
|
||||
LV_LABEL_LONG_DOTS, /*Keep the object size, break the text and write dots in the last line*/
|
||||
LV_LABEL_LONG_SCROLL, /*Expand the object size and scroll the text on the parent (move the label object)*/
|
||||
LV_LABEL_LONG_ROLL, /*Keep the size and roll the text infinitely*/
|
||||
}lv_label_long_mode_t;
|
||||
|
||||
/*Data of label*/
|
||||
@@ -43,9 +44,11 @@ typedef struct
|
||||
lv_label_long_mode_t long_mode; /*Determinate what to do with the long texts*/
|
||||
char dot_tmp[LV_LABEL_DOT_NUM + 1]; /*Store the character which are replaced by dots (Handled by the library)*/
|
||||
uint16_t dot_end; /*The text end position in dot mode (Handled by the library)*/
|
||||
point_t 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 pwd :1; /*Convert letters to '*' when draw*/
|
||||
uint8_t expand :1; /*Force expand size when solving line length (used by the library with LV_LABEL_LONG_ROLL)*/
|
||||
}lv_label_ext_t;
|
||||
|
||||
/**********************
|
||||
|
||||
@@ -136,20 +136,6 @@ lv_obj_t * lv_list_add(lv_obj_t * list, const char * img_fn, const char * txt, l
|
||||
lv_cont_set_layout(liste, LV_CONT_LAYOUT_ROW_M);
|
||||
lv_cont_set_fit(liste, false, true);
|
||||
|
||||
if(img_fn != NULL && img_fn[0] != '\0') {
|
||||
lv_obj_t * img = lv_img_create(liste, NULL);
|
||||
lv_img_set_file(img, img_fn);
|
||||
lv_obj_set_style(img, ext->style_img);
|
||||
lv_obj_set_click(img, false);
|
||||
}
|
||||
|
||||
if(txt != NULL) {
|
||||
lv_obj_t * label = lv_label_create(liste, NULL);
|
||||
lv_label_set_text(label, txt);
|
||||
lv_obj_set_style(label, ext->styles_btn[LV_BTN_STATE_REL]);
|
||||
lv_obj_set_click(label, false);
|
||||
}
|
||||
|
||||
/*Make the size adjustment*/
|
||||
cord_t w = lv_obj_get_width(list);
|
||||
lv_style_t * style_scrl = lv_obj_get_style(lv_page_get_scrl(list));
|
||||
@@ -162,6 +148,23 @@ lv_obj_t * lv_list_add(lv_obj_t * list, const char * img_fn, const char * txt, l
|
||||
}
|
||||
lv_obj_set_width(liste, w);
|
||||
|
||||
if(img_fn != NULL && img_fn[0] != '\0') {
|
||||
lv_obj_t * img = lv_img_create(liste, NULL);
|
||||
lv_img_set_file(img, img_fn);
|
||||
lv_obj_set_style(img, ext->style_img);
|
||||
lv_obj_set_click(img, false);
|
||||
}
|
||||
|
||||
if(txt != NULL) {
|
||||
lv_obj_t * label = lv_label_create(liste, NULL);
|
||||
lv_style_t * style_label = lv_obj_get_style(label);
|
||||
lv_label_set_text(label, txt);
|
||||
lv_obj_set_style(label, ext->styles_btn[LV_BTN_STATE_REL]);
|
||||
lv_obj_set_click(label, false);
|
||||
lv_label_set_long_mode(label, LV_LABEL_LONG_ROLL);
|
||||
lv_obj_set_size(label, liste->cords.x2 - label->cords.x1, font_get_height(style_label->font));
|
||||
}
|
||||
|
||||
return liste;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user