acid-drop

- Hacking the planet from a LilyGo T-Deck using custom firmware
git clone git://git.acid.vegas/acid-drop.git
Log | Files | Refs | Archive | README | LICENSE

lv_example_slider_1.c (996B)

      1 #include "../../lv_examples.h"
      2 #if LV_USE_SLIDER && LV_BUILD_EXAMPLES
      3 
      4 static void slider_event_cb(lv_event_t * e);
      5 static lv_obj_t * slider_label;
      6 
      7 /**
      8  * A default slider with a label displaying the current value
      9  */
     10 void lv_example_slider_1(void)
     11 {
     12     /*Create a slider in the center of the display*/
     13     lv_obj_t * slider = lv_slider_create(lv_scr_act());
     14     lv_obj_center(slider);
     15     lv_obj_add_event_cb(slider, slider_event_cb, LV_EVENT_VALUE_CHANGED, NULL);
     16 
     17     /*Create a label below the slider*/
     18     slider_label = lv_label_create(lv_scr_act());
     19     lv_label_set_text(slider_label, "0%");
     20 
     21     lv_obj_align_to(slider_label, slider, LV_ALIGN_OUT_BOTTOM_MID, 0, 10);
     22 }
     23 
     24 static void slider_event_cb(lv_event_t * e)
     25 {
     26     lv_obj_t * slider = lv_event_get_target(e);
     27     char buf[8];
     28     lv_snprintf(buf, sizeof(buf), "%d%%", (int)lv_slider_get_value(slider));
     29     lv_label_set_text(slider_label, buf);
     30     lv_obj_align_to(slider_label, slider, LV_ALIGN_OUT_BOTTOM_MID, 0, 10);
     31 }
     32 
     33 #endif