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_roller_3.c (3538B)
1 #include "../../lv_examples.h" 2 #if LV_USE_ROLLER && LV_DRAW_COMPLEX && LV_BUILD_EXAMPLES 3 4 static void mask_event_cb(lv_event_t * e) 5 { 6 lv_event_code_t code = lv_event_get_code(e); 7 lv_obj_t * obj = lv_event_get_target(e); 8 9 static int16_t mask_top_id = -1; 10 static int16_t mask_bottom_id = -1; 11 12 if(code == LV_EVENT_COVER_CHECK) { 13 lv_event_set_cover_res(e, LV_COVER_RES_MASKED); 14 15 } 16 else if(code == LV_EVENT_DRAW_MAIN_BEGIN) { 17 /* add mask */ 18 const lv_font_t * font = lv_obj_get_style_text_font(obj, LV_PART_MAIN); 19 lv_coord_t line_space = lv_obj_get_style_text_line_space(obj, LV_PART_MAIN); 20 lv_coord_t font_h = lv_font_get_line_height(font); 21 22 lv_area_t roller_coords; 23 lv_obj_get_coords(obj, &roller_coords); 24 25 lv_area_t rect_area; 26 rect_area.x1 = roller_coords.x1; 27 rect_area.x2 = roller_coords.x2; 28 rect_area.y1 = roller_coords.y1; 29 rect_area.y2 = roller_coords.y1 + (lv_obj_get_height(obj) - font_h - line_space) / 2; 30 31 lv_draw_mask_fade_param_t * fade_mask_top = lv_mem_buf_get(sizeof(lv_draw_mask_fade_param_t)); 32 lv_draw_mask_fade_init(fade_mask_top, &rect_area, LV_OPA_TRANSP, rect_area.y1, LV_OPA_COVER, rect_area.y2); 33 mask_top_id = lv_draw_mask_add(fade_mask_top, NULL); 34 35 rect_area.y1 = rect_area.y2 + font_h + line_space - 1; 36 rect_area.y2 = roller_coords.y2; 37 38 lv_draw_mask_fade_param_t * fade_mask_bottom = lv_mem_buf_get(sizeof(lv_draw_mask_fade_param_t)); 39 lv_draw_mask_fade_init(fade_mask_bottom, &rect_area, LV_OPA_COVER, rect_area.y1, LV_OPA_TRANSP, rect_area.y2); 40 mask_bottom_id = lv_draw_mask_add(fade_mask_bottom, NULL); 41 42 } 43 else if(code == LV_EVENT_DRAW_POST_END) { 44 lv_draw_mask_fade_param_t * fade_mask_top = lv_draw_mask_remove_id(mask_top_id); 45 lv_draw_mask_fade_param_t * fade_mask_bottom = lv_draw_mask_remove_id(mask_bottom_id); 46 lv_draw_mask_free_param(fade_mask_top); 47 lv_draw_mask_free_param(fade_mask_bottom); 48 lv_mem_buf_release(fade_mask_top); 49 lv_mem_buf_release(fade_mask_bottom); 50 mask_top_id = -1; 51 mask_bottom_id = -1; 52 } 53 } 54 55 /** 56 * Add a fade mask to roller. 57 */ 58 void lv_example_roller_3(void) 59 { 60 static lv_style_t style; 61 lv_style_init(&style); 62 lv_style_set_bg_color(&style, lv_color_black()); 63 lv_style_set_text_color(&style, lv_color_white()); 64 lv_style_set_border_width(&style, 0); 65 lv_style_set_pad_all(&style, 0); 66 lv_obj_add_style(lv_scr_act(), &style, 0); 67 68 lv_obj_t * roller1 = lv_roller_create(lv_scr_act()); 69 lv_obj_add_style(roller1, &style, 0); 70 lv_obj_set_style_bg_opa(roller1, LV_OPA_TRANSP, LV_PART_SELECTED); 71 72 #if LV_FONT_MONTSERRAT_22 73 lv_obj_set_style_text_font(roller1, &lv_font_montserrat_22, LV_PART_SELECTED); 74 #endif 75 76 lv_roller_set_options(roller1, 77 "January\n" 78 "February\n" 79 "March\n" 80 "April\n" 81 "May\n" 82 "June\n" 83 "July\n" 84 "August\n" 85 "September\n" 86 "October\n" 87 "November\n" 88 "December", 89 LV_ROLLER_MODE_NORMAL); 90 91 lv_obj_center(roller1); 92 lv_roller_set_visible_row_count(roller1, 3); 93 lv_obj_add_event_cb(roller1, mask_event_cb, LV_EVENT_ALL, NULL); 94 } 95 96 #endif