lvgl slider(滑动条控件)

源代码:

static lv_obj_t * slider_label;
static void slider_event_cb(lv_obj_t * slider, lv_event_t event)
{
	if (event == LV_EVENT_VALUE_CHANGED) {
		static char buf[4]; /* max 3 bytes for number plus 1 null terminating byte */
		snprintf(buf, 4, "%u", lv_slider_get_value(slider));
		lv_label_set_text(slider_label, buf);
	}
}
	//22. 滑块对象
	//22.1 创建滑块对象
	lv_obj_t * slider = lv_slider_create(lv_scr_act(), NULL);
	lv_obj_set_width(slider, 200);
	lv_obj_align(slider, NULL, LV_ALIGN_CENTER, 0, -80);
	lv_obj_set_event_cb(slider, slider_event_cb);
	lv_slider_set_range(slider, 0, 100);

	//22.2 在滑块对象下创建一个标签
	slider_label = lv_label_create(lv_scr_act(), NULL);
	lv_label_set_text(slider_label, "0");
	lv_obj_set_auto_realign(slider_label, true);
	lv_obj_align(slider_label, slider, LV_ALIGN_OUT_BOTTOM_MID, 0, 10);

	//22.3 创建一个说明标签
	lv_obj_t * info = lv_label_create(lv_scr_act(), NULL);
	lv_label_set_text(info, "Welcome to the slider+label demo!\n"
		"Move the slider and see that the label\n"
		"updates to match it.");
	lv_obj_align(info, NULL, LV_ALIGN_IN_TOP_LEFT, 10, 10);

效果显示:

 

おすすめ

転載: blog.csdn.net/chenliang0224/article/details/112914333