2021-04-08 13:07:48 +02:00
|
|
|
#include "../../lv_examples.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)
|
|
|
|
{
|
2021-03-15 02:03:27 +08:00
|
|
|
/*Create a slider in the center of the display*/
|
2021-03-25 13:36:50 +01:00
|
|
|
lv_obj_t * slider = lv_slider_create(lv_scr_act());
|
2021-03-25 16:14:17 +01:00
|
|
|
lv_obj_center(slider);
|
2021-02-08 09:53:03 +01:00
|
|
|
lv_obj_add_event_cb(slider, slider_event_cb, NULL);
|
|
|
|
|
2021-03-15 02:03:27 +08:00
|
|
|
/*Create a label below the slider*/
|
2021-03-25 13:36:50 +01:00
|
|
|
slider_label = lv_label_create(lv_scr_act());
|
2021-02-08 09:53:03 +01:00
|
|
|
lv_label_set_text(slider_label, "0%");
|
|
|
|
|
2021-03-25 16:14:17 +01:00
|
|
|
lv_obj_align_to(slider_label, slider, LV_ALIGN_OUT_BOTTOM_MID, 0, 10);
|
2021-02-08 09:53:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2021-03-25 16:14:17 +01:00
|
|
|
lv_obj_align_to(slider_label, slider, LV_ALIGN_OUT_BOTTOM_MID, 0, 10);
|
2021-02-08 09:53:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|