LVGL lv_linemeter刻度指示器(19)

lv_linemeter

刻度指示器分为活跃刻度线和非活跃刻度线,利用可以设置为不同颜色,其中活跃刻度线还能设置渐变效果。

样式

/*Styles*/
enum {
    LV_LINEMETER_PART_MAIN,
    _LV_LINEMETER_PART_VIRTUAL_LAST,
    _LV_LINEMETER_PART_REAL_LAST = _LV_OBJ_PART_REAL_LAST,
};
typedef uint8_t lv_linemeter_part_t;

例子

int val = 0;
lv_obj_t * lmeter;
lv_obj_t * label;
void task_cb(lv_task_t task)
{
	char buf[5];
	val += 5;
	if (val > 100)
		val = 0;
	lv_linemeter_set_value(lmeter, val);
	sprintf(buf, "%d%%", val);
	lv_label_set_text(label,buf);
}
void lv_ex_linemeter_1(void)
{
	static lv_style_t style_lmeter;
	lv_style_init(&style_lmeter);
	lv_style_set_line_width(&style_lmeter, LV_STATE_DEFAULT,3);//活跃刻度线宽度
	lv_style_set_line_color(&style_lmeter, LV_STATE_DEFAULT, LV_COLOR_GREEN);//活跃刻度线起始颜色
	lv_style_set_scale_grad_color(&style_lmeter, LV_STATE_DEFAULT, LV_COLOR_RED);//活跃刻度线终止颜色
	//lv_style_set_scale_end_color(&style_lmeter, LV_STATE_DEFAULT, LV_COLOR_YELLOW);//非活跃刻度线颜色
	//lv_style_set_scale_end_line_width(&style_lmeter, LV_STATE_DEFAULT, 6);//非活跃刻度线宽度
	lv_style_set_scale_width(&style_lmeter, LV_STATE_DEFAULT, 15);//设置刻度线长度

    lmeter = lv_linemeter_create(lv_scr_act(), NULL);
    lv_linemeter_set_range(lmeter, 0, 100);                   /*设置刻度值范围*/
    lv_linemeter_set_value(lmeter, 0);                       /*设置刻度值*/
    lv_linemeter_set_scale(lmeter, 240, 21);                  /*设置角度和刻度线数*/
    lv_obj_set_size(lmeter, 150, 150);
    lv_obj_align(lmeter, NULL, LV_ALIGN_CENTER, 0, 0);
	lv_obj_add_style(lmeter, LV_LINEMETER_PART_MAIN, &style_lmeter);

	label = lv_label_create(lv_scr_act(),NULL);
	lv_obj_align(label, lmeter, LV_ALIGN_CENTER, 0, 0);
	lv_obj_set_auto_realign(label, true);
	lv_label_set_text(label, "0%");

	lv_task_create(task_cb,300, LV_TASK_PRIO_MID, NULL);
}

LVGL lv_linemeter刻度指示器(19)_第1张图片

你可能感兴趣的:(LVGL)