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_chart_4.c (2709B)
1 #include "../../lv_examples.h" 2 #if LV_USE_CHART && LV_BUILD_EXAMPLES 3 4 5 static void event_cb(lv_event_t * e) 6 { 7 lv_event_code_t code = lv_event_get_code(e); 8 lv_obj_t * chart = lv_event_get_target(e); 9 10 if(code == LV_EVENT_VALUE_CHANGED) { 11 lv_obj_invalidate(chart); 12 } 13 if(code == LV_EVENT_REFR_EXT_DRAW_SIZE) { 14 lv_coord_t * s = lv_event_get_param(e); 15 *s = LV_MAX(*s, 20); 16 } 17 else if(code == LV_EVENT_DRAW_POST_END) { 18 int32_t id = lv_chart_get_pressed_point(chart); 19 if(id == LV_CHART_POINT_NONE) return; 20 21 LV_LOG_USER("Selected point %d", (int)id); 22 23 lv_chart_series_t * ser = lv_chart_get_series_next(chart, NULL); 24 while(ser) { 25 lv_point_t p; 26 lv_chart_get_point_pos_by_id(chart, ser, id, &p); 27 28 lv_coord_t * y_array = lv_chart_get_y_array(chart, ser); 29 lv_coord_t value = y_array[id]; 30 31 char buf[16]; 32 lv_snprintf(buf, sizeof(buf), LV_SYMBOL_DUMMY"$%d", value); 33 34 lv_draw_rect_dsc_t draw_rect_dsc; 35 lv_draw_rect_dsc_init(&draw_rect_dsc); 36 draw_rect_dsc.bg_color = lv_color_black(); 37 draw_rect_dsc.bg_opa = LV_OPA_50; 38 draw_rect_dsc.radius = 3; 39 draw_rect_dsc.bg_img_src = buf; 40 draw_rect_dsc.bg_img_recolor = lv_color_white(); 41 42 lv_area_t a; 43 a.x1 = chart->coords.x1 + p.x - 20; 44 a.x2 = chart->coords.x1 + p.x + 20; 45 a.y1 = chart->coords.y1 + p.y - 30; 46 a.y2 = chart->coords.y1 + p.y - 10; 47 48 lv_draw_ctx_t * draw_ctx = lv_event_get_draw_ctx(e); 49 lv_draw_rect(draw_ctx, &draw_rect_dsc, &a); 50 51 ser = lv_chart_get_series_next(chart, ser); 52 } 53 } 54 else if(code == LV_EVENT_RELEASED) { 55 lv_obj_invalidate(chart); 56 } 57 } 58 59 /** 60 * Show the value of the pressed points 61 */ 62 void lv_example_chart_4(void) 63 { 64 /*Create a chart*/ 65 lv_obj_t * chart; 66 chart = lv_chart_create(lv_scr_act()); 67 lv_obj_set_size(chart, 200, 150); 68 lv_obj_center(chart); 69 70 lv_obj_add_event_cb(chart, event_cb, LV_EVENT_ALL, NULL); 71 lv_obj_refresh_ext_draw_size(chart); 72 73 /*Zoom in a little in X*/ 74 lv_chart_set_zoom_x(chart, 800); 75 76 /*Add two data series*/ 77 lv_chart_series_t * ser1 = lv_chart_add_series(chart, lv_palette_main(LV_PALETTE_RED), LV_CHART_AXIS_PRIMARY_Y); 78 lv_chart_series_t * ser2 = lv_chart_add_series(chart, lv_palette_main(LV_PALETTE_GREEN), LV_CHART_AXIS_PRIMARY_Y); 79 uint32_t i; 80 for(i = 0; i < 10; i++) { 81 lv_chart_set_next_value(chart, ser1, lv_rand(60, 90)); 82 lv_chart_set_next_value(chart, ser2, lv_rand(10, 40)); 83 } 84 } 85 86 #endif