1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
| #include "table_oper.h"
void tbl_clicked_style_handler(lv_event_t *e) { lv_obj_t *table = lv_event_get_target(e); Style *style = lv_event_get_user_data(e);
Common_Style *common_style = style->common_style; Table_Style *exclusive_style = style->exclusive_style;
lv_table_get_selected_cell(table, &exclusive_style->click_row, &exclusive_style->click_col); }
void cell_draw(lv_obj_draw_part_dsc_t* dsc, uint32_t row, uint32_t col, Style *style) { Common_Style *common_style = style->common_style; Table_Style *exclusive_style = style->exclusive_style;
dsc->label_dsc->color = lv_color_hex(exclusive_style->row_font_color[row]); dsc->rect_dsc->bg_color = lv_color_hex(exclusive_style->row_background_color[row]);
dsc->rect_dsc->outline_color = lv_color_hex(exclusive_style->outline_color); dsc->rect_dsc->outline_width = exclusive_style->outline_width; }
void cell_clicked_draw(lv_obj_draw_part_dsc_t* dsc, uint32_t row, uint32_t col, Table_Style *style) { switch (style->select_mode) { case 0: if (row == style->click_row) dsc->rect_dsc->bg_color = lv_color_hex(style->select_color); break; case 1: if (col == style->click_col) dsc->rect_dsc->bg_color = lv_color_hex(style->select_color); break; case 2: if (row == style->click_row && col == style->click_col) dsc->rect_dsc->bg_color = lv_color_hex(style->select_color); break; } }
void table_draw(lv_obj_draw_part_dsc_t *dsc, Style *style){ dsc->rect_dsc->bg_opa = 0; }
void tbl_draw_style_handler(lv_event_t *e) { lv_obj_t *widget = lv_event_get_target(e); lv_table_t *table = (lv_table_t *)widget; lv_obj_draw_part_dsc_t *dsc = lv_event_get_param(e); Style *style = lv_event_get_user_data(e);
Common_Style *common_style = style->common_style; Table_Style *exclusive_style = style->exclusive_style;
if (dsc != NULL && dsc->part == LV_PART_ITEMS){ uint32_t row = dsc->id / lv_table_get_col_cnt(widget); uint32_t col = dsc->id - row * lv_table_get_col_cnt(widget);
cell_draw(dsc, row, col, style); cell_clicked_draw(dsc, row, col, exclusive_style); }
if (dsc != NULL && dsc->part == LV_PART_MAIN){ table_draw(dsc, style); }
for (size_t row = 0; row < exclusive_style->row_num; row++) { table->row_h[row] = exclusive_style->row_height; } }
lv_obj_t* add_table(Style *style){ lv_obj_t *table;
Common_Style *common_style = style->common_style; Table_Style *exclusive_style = style->exclusive_style;
table = lv_table_create(lv_scr_act()); lv_obj_set_x(table, common_style->h_ofs); lv_obj_set_y(table, common_style->v_ofs);
lv_table_set_row_cnt(table, exclusive_style->row_num); lv_table_set_col_cnt(table, exclusive_style->col_num); for (size_t col = 0; col < exclusive_style->col_num; col++) { lv_table_set_col_width(table, col, exclusive_style->col_width[col]); }
lv_obj_add_event_cb(table, tbl_draw_style_handler, LV_EVENT_DRAW_PART_BEGIN, style); lv_obj_add_event_cb(table, tbl_clicked_style_handler, LV_EVENT_VALUE_CHANGED, style);
return table; }
|