1 /** 2 * @file lv_table.h 3 * 4 */ 5 6 #ifndef LV_TABLE_H 7 #define LV_TABLE_H 8 9 #ifdef __cplusplus 10 extern "C" { 11 #endif 12 13 /********************* 14 * INCLUDES 15 *********************/ 16 #ifdef LV_CONF_INCLUDE_SIMPLE 17 #include "lv_conf.h" 18 #else 19 #include "../../lv_conf.h" 20 #endif 21 22 #if LV_USE_TABLE != 0 23 24 /*Testing of dependencies*/ 25 #if LV_USE_LABEL == 0 26 #error "lv_table: lv_label is required. Enable it in lv_conf.h (LV_USE_LABEL 1) " 27 #endif 28 29 #include "../lv_core/lv_obj.h" 30 #include "lv_label.h" 31 32 /********************* 33 * DEFINES 34 *********************/ 35 #ifndef LV_TABLE_COL_MAX 36 #define LV_TABLE_COL_MAX 12 37 #endif 38 39 #define LV_TABLE_CELL_STYLE_CNT 4 40 /********************** 41 * TYPEDEFS 42 **********************/ 43 44 /** 45 * Internal table cell format structure. 46 * 47 * Use the `lv_table` APIs instead. 48 */ 49 typedef union 50 { 51 struct 52 { 53 uint8_t align : 2; 54 uint8_t right_merge : 1; 55 uint8_t type : 2; 56 uint8_t crop : 1; 57 } s; 58 uint8_t format_byte; 59 } lv_table_cell_format_t; 60 61 /*Data of table*/ 62 typedef struct 63 { 64 /*New data for this type */ 65 uint16_t col_cnt; 66 uint16_t row_cnt; 67 char ** cell_data; 68 const lv_style_t * cell_style[LV_TABLE_CELL_STYLE_CNT]; 69 lv_coord_t col_w[LV_TABLE_COL_MAX]; 70 } lv_table_ext_t; 71 72 /*Styles*/ 73 enum { 74 LV_TABLE_STYLE_BG, 75 LV_TABLE_STYLE_CELL1, 76 LV_TABLE_STYLE_CELL2, 77 LV_TABLE_STYLE_CELL3, 78 LV_TABLE_STYLE_CELL4, 79 }; 80 typedef uint8_t lv_table_style_t; 81 82 /********************** 83 * GLOBAL PROTOTYPES 84 **********************/ 85 86 /** 87 * Create a table object 88 * @param par pointer to an object, it will be the parent of the new table 89 * @param copy pointer to a table object, if not NULL then the new object will be copied from it 90 * @return pointer to the created table 91 */ 92 lv_obj_t * lv_table_create(lv_obj_t * par, const lv_obj_t * copy); 93 94 /*===================== 95 * Setter functions 96 *====================*/ 97 98 /** 99 * Set the value of a cell. 100 * @param table pointer to a Table object 101 * @param row id of the row [0 .. row_cnt -1] 102 * @param col id of the column [0 .. col_cnt -1] 103 * @param txt text to display in the cell. It will be copied and saved so this variable is not 104 * required after this function call. 105 */ 106 void lv_table_set_cell_value(lv_obj_t * table, uint16_t row, uint16_t col, const char * txt); 107 108 /** 109 * Set the number of rows 110 * @param table table pointer to a Table object 111 * @param row_cnt number of rows 112 */ 113 void lv_table_set_row_cnt(lv_obj_t * table, uint16_t row_cnt); 114 115 /** 116 * Set the number of columns 117 * @param table table pointer to a Table object 118 * @param col_cnt number of columns. Must be < LV_TABLE_COL_MAX 119 */ 120 void lv_table_set_col_cnt(lv_obj_t * table, uint16_t col_cnt); 121 122 /** 123 * Set the width of a column 124 * @param table table pointer to a Table object 125 * @param col_id id of the column [0 .. LV_TABLE_COL_MAX -1] 126 * @param w width of the column 127 */ 128 void lv_table_set_col_width(lv_obj_t * table, uint16_t col_id, lv_coord_t w); 129 130 /** 131 * Set the text align in a cell 132 * @param table pointer to a Table object 133 * @param row id of the row [0 .. row_cnt -1] 134 * @param col id of the column [0 .. col_cnt -1] 135 * @param align LV_LABEL_ALIGN_LEFT or LV_LABEL_ALIGN_CENTER or LV_LABEL_ALIGN_RIGHT 136 */ 137 void lv_table_set_cell_align(lv_obj_t * table, uint16_t row, uint16_t col, lv_label_align_t align); 138 139 /** 140 * Set the type of a cell. 141 * @param table pointer to a Table object 142 * @param row id of the row [0 .. row_cnt -1] 143 * @param col id of the column [0 .. col_cnt -1] 144 * @param type 1,2,3 or 4. The cell style will be chosen accordingly. 145 */ 146 void lv_table_set_cell_type(lv_obj_t * table, uint16_t row, uint16_t col, uint8_t type); 147 148 /** 149 * Set the cell crop. (Don't adjust the height of the cell according to its content) 150 * @param table pointer to a Table object 151 * @param row id of the row [0 .. row_cnt -1] 152 * @param col id of the column [0 .. col_cnt -1] 153 * @param crop true: crop the cell content; false: set the cell height to the content. 154 */ 155 void lv_table_set_cell_crop(lv_obj_t * table, uint16_t row, uint16_t col, bool crop); 156 157 /** 158 * Merge a cell with the right neighbor. The value of the cell to the right won't be displayed. 159 * @param table table pointer to a Table object 160 * @param row id of the row [0 .. row_cnt -1] 161 * @param col id of the column [0 .. col_cnt -1] 162 * @param en true: merge right; false: don't merge right 163 */ 164 void lv_table_set_cell_merge_right(lv_obj_t * table, uint16_t row, uint16_t col, bool en); 165 166 /** 167 * Set a style of a table. 168 * @param table pointer to table object 169 * @param type which style should be set 170 * @param style pointer to a style 171 */ 172 void lv_table_set_style(lv_obj_t * table, lv_table_style_t type, const lv_style_t * style); 173 174 /*===================== 175 * Getter functions 176 *====================*/ 177 178 /** 179 * Get the value of a cell. 180 * @param table pointer to a Table object 181 * @param row id of the row [0 .. row_cnt -1] 182 * @param col id of the column [0 .. col_cnt -1] 183 * @return text in the cell 184 */ 185 const char * lv_table_get_cell_value(lv_obj_t * table, uint16_t row, uint16_t col); 186 187 /** 188 * Get the number of rows. 189 * @param table table pointer to a Table object 190 * @return number of rows. 191 */ 192 uint16_t lv_table_get_row_cnt(lv_obj_t * table); 193 194 /** 195 * Get the number of columns. 196 * @param table table pointer to a Table object 197 * @return number of columns. 198 */ 199 uint16_t lv_table_get_col_cnt(lv_obj_t * table); 200 201 /** 202 * Get the width of a column 203 * @param table table pointer to a Table object 204 * @param col_id id of the column [0 .. LV_TABLE_COL_MAX -1] 205 * @return width of the column 206 */ 207 lv_coord_t lv_table_get_col_width(lv_obj_t * table, uint16_t col_id); 208 209 /** 210 * Get the text align of a cell 211 * @param table pointer to a Table object 212 * @param row id of the row [0 .. row_cnt -1] 213 * @param col id of the column [0 .. col_cnt -1] 214 * @return LV_LABEL_ALIGN_LEFT (default in case of error) or LV_LABEL_ALIGN_CENTER or 215 * LV_LABEL_ALIGN_RIGHT 216 */ 217 lv_label_align_t lv_table_get_cell_align(lv_obj_t * table, uint16_t row, uint16_t col); 218 219 /** 220 * Get the type of a cell 221 * @param table pointer to a Table object 222 * @param row id of the row [0 .. row_cnt -1] 223 * @param col id of the column [0 .. col_cnt -1] 224 * @return 1,2,3 or 4 225 */ 226 lv_label_align_t lv_table_get_cell_type(lv_obj_t * table, uint16_t row, uint16_t col); 227 228 /** 229 * Get the crop property of a cell 230 * @param table pointer to a Table object 231 * @param row id of the row [0 .. row_cnt -1] 232 * @param col id of the column [0 .. col_cnt -1] 233 * @return true: text crop enabled; false: disabled 234 */ 235 lv_label_align_t lv_table_get_cell_crop(lv_obj_t * table, uint16_t row, uint16_t col); 236 237 /** 238 * Get the cell merge attribute. 239 * @param table table pointer to a Table object 240 * @param row id of the row [0 .. row_cnt -1] 241 * @param col id of the column [0 .. col_cnt -1] 242 * @return true: merge right; false: don't merge right 243 */ 244 bool lv_table_get_cell_merge_right(lv_obj_t * table, uint16_t row, uint16_t col); 245 246 /** 247 * Get style of a table. 248 * @param table pointer to table object 249 * @param type which style should be get 250 * @return style pointer to the style 251 */ 252 const lv_style_t * lv_table_get_style(const lv_obj_t * table, lv_table_style_t type); 253 254 /*===================== 255 * Other functions 256 *====================*/ 257 258 /********************** 259 * MACROS 260 **********************/ 261 262 #endif /*LV_USE_TABLE*/ 263 264 #ifdef __cplusplus 265 } /* extern "C" */ 266 #endif 267 268 #endif /*LV_TABLE_H*/ 269