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_1.c (2403B)
1 #include "../../lv_examples.h" 2 #if LV_USE_TABLE && LV_BUILD_EXAMPLES 3 4 static void draw_part_event_cb(lv_event_t * e) 5 { 6 lv_obj_t * obj = lv_event_get_target(e); 7 lv_obj_draw_part_dsc_t * dsc = lv_event_get_param(e); 8 /*If the cells are drawn...*/ 9 if(dsc->part == LV_PART_ITEMS) { 10 uint32_t row = dsc->id / lv_table_get_col_cnt(obj); 11 uint32_t col = dsc->id - row * lv_table_get_col_cnt(obj); 12 13 /*Make the texts in the first cell center aligned*/ 14 if(row == 0) { 15 dsc->label_dsc->align = LV_TEXT_ALIGN_CENTER; 16 dsc->rect_dsc->bg_color = lv_color_mix(lv_palette_main(LV_PALETTE_BLUE), dsc->rect_dsc->bg_color, LV_OPA_20); 17 dsc->rect_dsc->bg_opa = LV_OPA_COVER; 18 } 19 /*In the first column align the texts to the right*/ 20 else if(col == 0) { 21 dsc->label_dsc->align = LV_TEXT_ALIGN_RIGHT; 22 } 23 24 /*MAke every 2nd row grayish*/ 25 if((row != 0 && row % 2) == 0) { 26 dsc->rect_dsc->bg_color = lv_color_mix(lv_palette_main(LV_PALETTE_GREY), dsc->rect_dsc->bg_color, LV_OPA_10); 27 dsc->rect_dsc->bg_opa = LV_OPA_COVER; 28 } 29 } 30 } 31 32 33 void lv_example_table_1(void) 34 { 35 lv_obj_t * table = lv_table_create(lv_scr_act()); 36 37 /*Fill the first column*/ 38 lv_table_set_cell_value(table, 0, 0, "Name"); 39 lv_table_set_cell_value(table, 1, 0, "Apple"); 40 lv_table_set_cell_value(table, 2, 0, "Banana"); 41 lv_table_set_cell_value(table, 3, 0, "Lemon"); 42 lv_table_set_cell_value(table, 4, 0, "Grape"); 43 lv_table_set_cell_value(table, 5, 0, "Melon"); 44 lv_table_set_cell_value(table, 6, 0, "Peach"); 45 lv_table_set_cell_value(table, 7, 0, "Nuts"); 46 47 /*Fill the second column*/ 48 lv_table_set_cell_value(table, 0, 1, "Price"); 49 lv_table_set_cell_value(table, 1, 1, "$7"); 50 lv_table_set_cell_value(table, 2, 1, "$4"); 51 lv_table_set_cell_value(table, 3, 1, "$6"); 52 lv_table_set_cell_value(table, 4, 1, "$2"); 53 lv_table_set_cell_value(table, 5, 1, "$5"); 54 lv_table_set_cell_value(table, 6, 1, "$1"); 55 lv_table_set_cell_value(table, 7, 1, "$9"); 56 57 /*Set a smaller height to the table. It'll make it scrollable*/ 58 lv_obj_set_height(table, 200); 59 lv_obj_center(table); 60 61 /*Add an event callback to to apply some custom drawing*/ 62 lv_obj_add_event_cb(table, draw_part_event_cb, LV_EVENT_DRAW_PART_BEGIN, NULL); 63 } 64 65 #endif