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_event_3.c (1200B)

      1 #include "../lv_examples.h"
      2 #if LV_BUILD_EXAMPLES && LV_USE_FLEX
      3 
      4 static void event_cb(lv_event_t * e)
      5 {
      6     /*The original target of the event. Can be the buttons or the container*/
      7     lv_obj_t * target = lv_event_get_target(e);
      8 
      9     /*The current target is always the container as the event is added to it*/
     10     lv_obj_t * cont = lv_event_get_current_target(e);
     11 
     12     /*If container was clicked do nothing*/
     13     if(target == cont) return;
     14 
     15     /*Make the clicked buttons red*/
     16     lv_obj_set_style_bg_color(target, lv_palette_main(LV_PALETTE_RED), 0);
     17 }
     18 
     19 /**
     20  * Demonstrate event bubbling
     21  */
     22 void lv_example_event_3(void)
     23 {
     24 
     25     lv_obj_t * cont = lv_obj_create(lv_scr_act());
     26     lv_obj_set_size(cont, 290, 200);
     27     lv_obj_center(cont);
     28     lv_obj_set_flex_flow(cont, LV_FLEX_FLOW_ROW_WRAP);
     29 
     30     uint32_t i;
     31     for(i = 0; i < 30; i++) {
     32         lv_obj_t * btn = lv_btn_create(cont);
     33         lv_obj_set_size(btn, 80, 50);
     34         lv_obj_add_flag(btn, LV_OBJ_FLAG_EVENT_BUBBLE);
     35 
     36         lv_obj_t * label = lv_label_create(btn);
     37         lv_label_set_text_fmt(label, "%"LV_PRIu32, i);
     38         lv_obj_center(label);
     39     }
     40 
     41     lv_obj_add_event_cb(cont, event_cb, LV_EVENT_CLICKED, NULL);
     42 }
     43 
     44 #endif