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_btnmatrix_2.c (2670B)
1 #include "../../lv_examples.h" 2 #if LV_USE_BTNMATRIX && 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 * obj = lv_event_get_target(e); 9 if(code == LV_EVENT_DRAW_PART_BEGIN) { 10 lv_obj_draw_part_dsc_t * dsc = lv_event_get_param(e); 11 12 /*Change the draw descriptor the 2nd button*/ 13 if(dsc->id == 1) { 14 dsc->rect_dsc->radius = 0; 15 if(lv_btnmatrix_get_selected_btn(obj) == dsc->id) dsc->rect_dsc->bg_color = lv_palette_darken(LV_PALETTE_BLUE, 3); 16 else dsc->rect_dsc->bg_color = lv_palette_main(LV_PALETTE_BLUE); 17 18 dsc->rect_dsc->shadow_width = 6; 19 dsc->rect_dsc->shadow_ofs_x = 3; 20 dsc->rect_dsc->shadow_ofs_y = 3; 21 dsc->label_dsc->color = lv_color_white(); 22 } 23 /*Change the draw descriptor the 3rd button*/ 24 else if(dsc->id == 2) { 25 dsc->rect_dsc->radius = LV_RADIUS_CIRCLE; 26 if(lv_btnmatrix_get_selected_btn(obj) == dsc->id) dsc->rect_dsc->bg_color = lv_palette_darken(LV_PALETTE_RED, 3); 27 else dsc->rect_dsc->bg_color = lv_palette_main(LV_PALETTE_RED); 28 29 dsc->label_dsc->color = lv_color_white(); 30 } 31 else if(dsc->id == 3) { 32 dsc->label_dsc->opa = LV_OPA_TRANSP; /*Hide the text if any*/ 33 34 } 35 } 36 if(code == LV_EVENT_DRAW_PART_END) { 37 lv_obj_draw_part_dsc_t * dsc = lv_event_get_param(e); 38 39 /*Add custom content to the 4th button when the button itself was drawn*/ 40 if(dsc->id == 3) { 41 LV_IMG_DECLARE(img_star); 42 lv_img_header_t header; 43 lv_res_t res = lv_img_decoder_get_info(&img_star, &header); 44 if(res != LV_RES_OK) return; 45 46 lv_area_t a; 47 a.x1 = dsc->draw_area->x1 + (lv_area_get_width(dsc->draw_area) - header.w) / 2; 48 a.x2 = a.x1 + header.w - 1; 49 a.y1 = dsc->draw_area->y1 + (lv_area_get_height(dsc->draw_area) - header.h) / 2; 50 a.y2 = a.y1 + header.h - 1; 51 52 lv_draw_img_dsc_t img_draw_dsc; 53 lv_draw_img_dsc_init(&img_draw_dsc); 54 img_draw_dsc.recolor = lv_color_black(); 55 if(lv_btnmatrix_get_selected_btn(obj) == dsc->id) img_draw_dsc.recolor_opa = LV_OPA_30; 56 57 lv_draw_img(dsc->draw_ctx, &img_draw_dsc, &a, &img_star); 58 } 59 } 60 } 61 62 /** 63 * Add custom drawer to the button matrix to customize buttons one by one 64 */ 65 void lv_example_btnmatrix_2(void) 66 { 67 lv_obj_t * btnm = lv_btnmatrix_create(lv_scr_act()); 68 lv_obj_add_event_cb(btnm, event_cb, LV_EVENT_ALL, NULL); 69 lv_obj_center(btnm); 70 } 71 72 #endif