Files
lvgl/examples/others/observer/lv_example_observer_1.c
Zoltan Janosy 4f541cf523 feat(observer): implemented an observer pattern (#4541)
Co-authored-by: Zoltan Janosy <zjanosy@fishman.com>
Co-authored-by: Gabor Kiss-Vamosi <kisvegabor@gmail.com>
2023-10-09 23:20:29 +02:00

26 lines
730 B
C

#include "../../lv_examples.h"
#if LV_USE_OBSERVER && LV_USE_SLIDER && LV_USE_LABEL && LV_BUILD_EXAMPLES
static lv_subject_t temperature_subject;
/**
* A slider sends a message on value change and a label display's that value
*/
void lv_example_observer_1(void)
{
lv_subject_init_int(&temperature_subject, 28);
/*Create a slider in the center of the display*/
lv_obj_t * slider = lv_slider_create(lv_scr_act());
lv_obj_center(slider);
lv_slider_bind_value(slider, &temperature_subject);
/*Create a label below the slider*/
lv_obj_t * label = lv_label_create(lv_scr_act());
lv_obj_align(label, LV_ALIGN_CENTER, 0, 30);
lv_label_bind_text(label, &temperature_subject, "%d °C");
}
#endif