lvgl gauge(表盘控件)

	//9. 仪表控件
	//设置时钟的网址:https://blog.csdn.net/mymycsdn321/article/details/108060627
	//9.1 设置仪表的样式
	static lv_style_t gauge_style;
	lv_style_copy(&gauge_style, &lv_style_pretty_color);
	gauge_style.body.main_color = lv_color_hex3(0x666);     /*开始的刻度条颜色*/
	gauge_style.body.grad_color = lv_color_hex3(0x666);		/*结束的刻度条颜色*/
	gauge_style.body.padding.left = 10;                     /*刻度条的长度*/
	gauge_style.body.padding.inner = 8;						/*文本与刻度条的距离*/
	gauge_style.body.border.color = lv_color_hex3(0x333);   /*指针圆环的颜色*/
	gauge_style.line.width = 3;                             /*线条宽度*/
	gauge_style.text.color = lv_color_hex3(0x333);          /*文本颜色*/
	gauge_style.line.color = LV_COLOR_RED;                  /*超出临界值的线条颜色*/
	//9.2 描述针的颜色
	static lv_color_t needle_colors[3];
	needle_colors[0] = LV_COLOR_BLUE;
	needle_colors[1] = LV_COLOR_ORANGE;
	needle_colors[2] = LV_COLOR_PURPLE;
	//9.3 创建一个仪表控件
	lv_obj_t * gauge1 = lv_gauge_create(lv_scr_act(), NULL);
	//9.4 设置仪表的样式
	lv_gauge_set_style(gauge1, LV_GAUGE_STYLE_MAIN, &gauge_style);
	//9.5 设置指针的个数
	lv_gauge_set_needle_count(gauge1, 3, needle_colors);
	//9.6 设置仪表控件的大小
	lv_obj_set_size(gauge1, 150, 150);
	//9.7 设置仪表控件的位置
	lv_obj_align(gauge1, NULL, LV_ALIGN_CENTER, 0, 120);
	//9.8 在刻度上设置一个临界值。在此值之后'线条.颜色'将绘制比例线
	lv_gauge_set_critical_value(gauge1, 80);
	//9.9 设置仪表的最小值和最大值
	lv_gauge_set_range(gauge1, 0, 100);
	//9.10 设置指针的值
	lv_gauge_set_value(gauge1, 0, 10);
	lv_gauge_set_value(gauge1, 1, 20);
	lv_gauge_set_value(gauge1, 2, 30);

效果

lvgl gauge(表盘控件)_第1张图片

 

 

你可能感兴趣的:(GUI)