2021-02-08 09:53:03 +01:00
|
|
|
#include "../../../lvgl.h"
|
2021-02-14 14:56:34 +01:00
|
|
|
#if LV_USE_SLIDER && LV_BUILD_EXAMPLES
|
2021-02-08 09:53:03 +01:00
|
|
|
|
|
|
|
static void slider_event_cb(lv_obj_t * slider, lv_event_t event);
|
|
|
|
static lv_obj_t * slider_label;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A default slider with a label displaying the current value
|
|
|
|
*/
|
|
|
|
void lv_example_slider_1(void)
|
|
|
|
{
|
|
|
|
/* Create a slider in the center of the display */
|
|
|
|
lv_obj_t * slider = lv_slider_create(lv_scr_act(), NULL);
|
|
|
|
lv_obj_align(slider, NULL, LV_ALIGN_CENTER, 0, 0);
|
|
|
|
lv_obj_add_event_cb(slider, slider_event_cb, NULL);
|
|
|
|
|
|
|
|
/* Create a label below the slider */
|
|
|
|
slider_label = lv_label_create(lv_scr_act(), NULL);
|
|
|
|
lv_label_set_text(slider_label, "0%");
|
|
|
|
|
|
|
|
lv_obj_align(slider_label, slider, LV_ALIGN_OUT_BOTTOM_MID, 0, 10);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void slider_event_cb(lv_obj_t * slider, lv_event_t event)
|
|
|
|
{
|
|
|
|
if(event == LV_EVENT_VALUE_CHANGED) {
|
|
|
|
char buf[8];
|
|
|
|
lv_snprintf(buf, sizeof(buf), "%d%%", lv_slider_get_value(slider));
|
|
|
|
lv_label_set_text(slider_label, buf);
|
|
|
|
lv_obj_align(slider_label, slider, LV_ALIGN_OUT_BOTTOM_MID, 0, 10);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|