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_4.c (1750B)

      1 #include "../lv_examples.h"
      2 
      3 #if LV_BUILD_EXAMPLES
      4 
      5 static int n = 3;
      6 static lv_obj_t * label = NULL;
      7 
      8 static void timer_cb(lv_timer_t * timer)
      9 {
     10     if(n < 3 || n > 32) {
     11         n = 3;
     12     }
     13     else {
     14         static uint32_t old_tick = 0;
     15         uint32_t tick = lv_tick_get();
     16         if(!old_tick) {
     17             old_tick = tick;
     18         }
     19         if(tick - old_tick > 3000) {
     20             n++;
     21             lv_label_set_text_fmt(label, "%d sides", n);
     22             old_tick = tick;
     23         }
     24     }
     25     lv_obj_invalidate(timer->user_data);
     26 }
     27 
     28 static void event_cb(lv_event_t * e)
     29 {
     30     /*The original target of the event. Can be the buttons or the container*/
     31     lv_draw_ctx_t * draw_ctx = lv_event_get_draw_ctx(e);
     32     lv_draw_rect_dsc_t draw_dsc;
     33     lv_draw_rect_dsc_init(&draw_dsc);
     34     draw_dsc.bg_color = lv_palette_main(LV_PALETTE_LIGHT_GREEN);
     35     draw_dsc.bg_opa = LV_OPA_COVER;
     36     lv_point_t points[32];
     37     int i, r = 150;
     38     uint32_t tick = lv_tick_get();
     39     for(i = 0; i < n; i++) {
     40         int angle = i * 360 / n + ((tick % 36000) / 100);
     41         lv_coord_t x = 150 + (r * lv_trigo_cos(angle) >> LV_TRIGO_SHIFT), y =
     42                            150 + (r * lv_trigo_sin(angle) >> LV_TRIGO_SHIFT);
     43         points[i].x = x;
     44         points[i].y = y;
     45     }
     46     lv_draw_polygon(draw_ctx, &draw_dsc, points, n);
     47 }
     48 
     49 /**
     50  * Demonstrate event bubbling
     51  */
     52 void lv_example_event_4(void)
     53 {
     54 
     55     lv_obj_t * cont = lv_obj_create(lv_scr_act());
     56     lv_obj_remove_style_all(cont);
     57     lv_obj_set_size(cont, 300, 300);
     58     label = lv_label_create(cont);
     59     lv_label_set_text_fmt(label, "%d sides", n);
     60     lv_obj_center(label);
     61 
     62     lv_obj_add_event_cb(cont, event_cb, LV_EVENT_DRAW_MAIN, NULL);
     63     lv_timer_create(timer_cb, 17, cont);
     64 }
     65 
     66 #endif