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_table_2.c (3332B)
1 #include "../../lv_examples.h" 2 #if LV_USE_TABLE && LV_BUILD_EXAMPLES 3 4 #define ITEM_CNT 200 5 6 static void draw_event_cb(lv_event_t * e) 7 { 8 lv_obj_t * obj = lv_event_get_target(e); 9 lv_obj_draw_part_dsc_t * dsc = lv_event_get_draw_part_dsc(e); 10 /*If the cells are drawn...*/ 11 if(dsc->part == LV_PART_ITEMS) { 12 bool chk = lv_table_has_cell_ctrl(obj, dsc->id, 0, LV_TABLE_CELL_CTRL_CUSTOM_1); 13 14 lv_draw_rect_dsc_t rect_dsc; 15 lv_draw_rect_dsc_init(&rect_dsc); 16 rect_dsc.bg_color = chk ? lv_theme_get_color_primary(obj) : lv_palette_lighten(LV_PALETTE_GREY, 2); 17 rect_dsc.radius = LV_RADIUS_CIRCLE; 18 19 lv_area_t sw_area; 20 sw_area.x1 = dsc->draw_area->x2 - 50; 21 sw_area.x2 = sw_area.x1 + 40; 22 sw_area.y1 = dsc->draw_area->y1 + lv_area_get_height(dsc->draw_area) / 2 - 10; 23 sw_area.y2 = sw_area.y1 + 20; 24 lv_draw_rect(dsc->draw_ctx, &rect_dsc, &sw_area); 25 26 rect_dsc.bg_color = lv_color_white(); 27 if(chk) { 28 sw_area.x2 -= 2; 29 sw_area.x1 = sw_area.x2 - 16; 30 } 31 else { 32 sw_area.x1 += 2; 33 sw_area.x2 = sw_area.x1 + 16; 34 } 35 sw_area.y1 += 2; 36 sw_area.y2 -= 2; 37 lv_draw_rect(dsc->draw_ctx, &rect_dsc, &sw_area); 38 } 39 } 40 41 static void change_event_cb(lv_event_t * e) 42 { 43 lv_obj_t * obj = lv_event_get_target(e); 44 uint16_t col; 45 uint16_t row; 46 lv_table_get_selected_cell(obj, &row, &col); 47 bool chk = lv_table_has_cell_ctrl(obj, row, 0, LV_TABLE_CELL_CTRL_CUSTOM_1); 48 if(chk) lv_table_clear_cell_ctrl(obj, row, 0, LV_TABLE_CELL_CTRL_CUSTOM_1); 49 else lv_table_add_cell_ctrl(obj, row, 0, LV_TABLE_CELL_CTRL_CUSTOM_1); 50 } 51 52 53 /** 54 * A very light-weighted list created from table 55 */ 56 void lv_example_table_2(void) 57 { 58 /*Measure memory usage*/ 59 lv_mem_monitor_t mon1; 60 lv_mem_monitor(&mon1); 61 62 uint32_t t = lv_tick_get(); 63 64 lv_obj_t * table = lv_table_create(lv_scr_act()); 65 66 /*Set a smaller height to the table. It'll make it scrollable*/ 67 lv_obj_set_size(table, LV_SIZE_CONTENT, 200); 68 69 lv_table_set_col_width(table, 0, 150); 70 lv_table_set_row_cnt(table, ITEM_CNT); /*Not required but avoids a lot of memory reallocation lv_table_set_set_value*/ 71 lv_table_set_col_cnt(table, 1); 72 73 /*Don't make the cell pressed, we will draw something different in the event*/ 74 lv_obj_remove_style(table, NULL, LV_PART_ITEMS | LV_STATE_PRESSED); 75 76 uint32_t i; 77 for(i = 0; i < ITEM_CNT; i++) { 78 lv_table_set_cell_value_fmt(table, i, 0, "Item %"LV_PRIu32, i + 1); 79 } 80 81 lv_obj_align(table, LV_ALIGN_CENTER, 0, -20); 82 83 /*Add an event callback to to apply some custom drawing*/ 84 lv_obj_add_event_cb(table, draw_event_cb, LV_EVENT_DRAW_PART_END, NULL); 85 lv_obj_add_event_cb(table, change_event_cb, LV_EVENT_VALUE_CHANGED, NULL); 86 87 lv_mem_monitor_t mon2; 88 lv_mem_monitor(&mon2); 89 90 uint32_t mem_used = mon1.free_size - mon2.free_size; 91 92 uint32_t elaps = lv_tick_elaps(t); 93 94 lv_obj_t * label = lv_label_create(lv_scr_act()); 95 lv_label_set_text_fmt(label, "%"LV_PRIu32" items were created in %"LV_PRIu32" ms\n" 96 "using %"LV_PRIu32" bytes of memory", 97 ITEM_CNT, elaps, mem_used); 98 99 lv_obj_align(label, LV_ALIGN_BOTTOM_MID, 0, -10); 100 101 } 102 103 #endif