lv_label_refr_text
时间: 2023-07-02 07:20:04 浏览: 95
lv_label_refr_text()函数是lvgl库中的一个标签控件函数,其作用是刷新标签控件中的文本内容。
在lv_label.c源文件中,lv_label_refr_text()函数的实现如下:
```c
/**
* Refresh the label with its text. It can be used after the label's text has changed.
* @param label pointer to label object
*/
void lv_label_refr_text(lv_obj_t * label)
{
lv_label_ext_t * ext = lv_obj_get_ext_attr(label);
/*If the size is set before the text add it the object's height*/
if(ext->recolor != LV_COLOR_TRANSP && ext->recolor_opa != LV_OPA_TRANSP) {
lv_style_t * style = lv_obj_get_style(label);
lv_coord_t letter_space = style->text.line_space + style->text.letter_space;
lv_label_set_text_int(ext->text, ext->long_mode, label, ext->letter_space, letter_space, style->text.font,
ext->recolor, ext->recolor_opa);
} else {
lv_style_t * style = lv_obj_get_style(label);
lv_coord_t letter_space = style->text.line_space + style->text.letter_space;
lv_label_set_text_int(ext->text, ext->long_mode, label, ext->letter_space, letter_space, style->text.font,
style->text.color, LV_OPA_COVER);
}
lv_obj_invalidate(label);
}
```
从上面的代码可以看出,lv_label_refr_text()函数会根据标签控件的长文本模式、字体、文本的颜色等信息来重新设置标签控件中的文本内容,并通过lv_obj_invalidate()函数通知标签控件需要重新绘制。
在实际应用中,当标签控件的文本内容发生变化时,可以调用lv_label_refr_text()函数来更新显示的文本内容。
阅读全文