1. 程式人生 > 其它 >LVGL lv_label標籤控制元件(5)

LVGL lv_label標籤控制元件(5)

技術標籤:LVGL

lv_label

相關API在lv_label.h中

文字模式

enum {
	/*實時自動擴充套件標籤物件大小來包裹文字內容*/
    LV_LABEL_LONG_EXPAND,    /**< Expand the object size to the text size*/
    //標籤物件寬度不變,當文字內容超過標籤物件寬度,自動換行文字內容
    LV_LABEL_LONG_BREAK,     /**< Keep the object width, break the too long lines and expand the object
                                height*/
//標籤物件大小不變,當文字內容太長時,顯示...省略號 LV_LABEL_LONG_DOT, /**< Keep the size and write dots at the end if the text is too long*/ //標籤物件大小不變,當文字內容太長時,會自動迴圈向前向後滾動文字 LV_LABEL_LONG_SROLL, /**< Keep the size and roll the text back and forth*/ //標籤物件大小不變,當文字內容太長時,會自動迴圈環形滾動文字 LV_LABEL_LONG_SROLL_CIRC,
/**< Keep the size and roll the text circularly*/ //保持物件大小不變,超過的文字內容將會被剪下掉 LV_LABEL_LONG_CROP, /**< Keep the size and crop the text out of it*/ };

對齊方式

/** Label align policy*/
enum {
    LV_LABEL_ALIGN_LEFT, /**< Align text to left */
    LV_LABEL_ALIGN_CENTER, /**< Align text to center */
LV_LABEL_ALIGN_RIGHT, /**< Align text to right */ LV_LABEL_ALIGN_AUTO, /**< Use LEFT or RIGHT depending on the direction of the text (LTR/RTL)*/ };

標籤樣式

/** Label styles*/
enum {
    LV_LABEL_PART_MAIN,
};

例子

void lv_ex_label_1(void)
{
	//建立標籤物件
    lv_obj_t * label1 = lv_label_create(lv_scr_act(), NULL);
	//設定長文字模式
    lv_label_set_long_mode(label1, LV_LABEL_LONG_BREAK);     /*Break the long lines*/
	//使能文字重繪色功能
    lv_label_set_recolor(label1, true);                      /*Enable re-coloring by commands in the text*/
	//設定文字對齊模式
    lv_label_set_align(label1, LV_LABEL_ALIGN_CENTER);       /*Center aligned lines*/
	//設定文字內容
    lv_label_set_text(label1, "#ff0000 Re-color# #00ff00 words# #0000ff of a# label "
								"and  wrap long text automatically.");
	//設定寬度
    lv_obj_set_width(label1, 150);
	//設定對齊模式
    lv_obj_align(label1, NULL, LV_ALIGN_CENTER, 0, -30);

    lv_obj_t * label2 = lv_label_create(lv_scr_act(), NULL);
    lv_label_set_long_mode(label2, LV_LABEL_LONG_SROLL_CIRC);     /*Circular scroll*/
    lv_obj_set_width(label2, 150);
    lv_label_set_text(label2, "It is a circularly scrolling text. ");
    lv_obj_align(label2, NULL, LV_ALIGN_CENTER, 0, 30);
}

模擬效果
在這裡插入圖片描述
of後面的a也應該是藍色,微控制器拍照實際效果如下
在這裡插入圖片描述