Description : I need to change the color of a cell based on its value(lets ignore the logic for now)
What MCU/Processor/Board and compiler are you using?
ESP32S3 TFT parallel 3.5 w/ touch. Link: ESP32-S3 Parallel TFT with Touch 3.5'' ILI9488 | Makerfabs using ESP-IDF on Vscode
What LVGL version are you using? 8.3
What do you want to achieve? Change the color of a cell. either the text or the box itself
What have you tried so far? lv_table_set_cell_type(which is deprecated)
Code to reproduce
Add a code snippet which can run in the simulator. It should contain only the relevant code that compiles without errors when separated from your main code base.
The code block(s) should be formatted like:
void create_table(lv_obj_t * parent/*parent screen*/)
{
lv_obj_t * table = lv_table_create(parent);
lv_table_set_col_cnt(table, 2);
lv_table_set_row_cnt(table, 4);
lv_obj_align(table, LV_ALIGN_CENTER, 0, 0);
lv_obj_set_pos(table,0,100);
/*
CONVERSION PROCESS... VERY LONG.... HAS TO BE A QUICKER WAY
*/
char text[10];
sprintf(text, "%d", oil_1);
const char* char_oil_1 = text;
char text2[10];
sprintf(text2, "%d", oil_2);
const char* char_oil_2 = text2;
char text3[10];
sprintf(text3, "%d", battery_1);
const char* char_battery_1 = text3;
char text4[10];
sprintf(text4, "%d", battery_2);
const char* char_battery_2 = text4;
char text5[10];
sprintf(text5, "%d", performance_1);
const char* char_performance_1 = text5;
char text6[10];
sprintf(text6, "%d", performance_2);
const char* char_performance_2 = text6;
// Define the cell styles
static lv_style_t style_red;
static lv_style_t style_yellow;
static lv_style_t style_green;
/*Fill the first column*/
lv_table_set_cell_value(table, 0, 0, "Oil level");
lv_table_set_cell_value(table, 1, 0, char_oil_1);
lv_table_set_cell_value(table, 2, 0, char_oil_2);
//lv_table_set_cell_value(table, 3, 0, "Citron");
/*Fill the second column*/
lv_table_set_cell_value(table, 0, 1, "Battery level");
lv_table_set_cell_value(table, 1, 1, char_battery_1);
lv_table_set_cell_value(table, 2, 1, char_battery_2);
// lv_table_set_cell_value(table, 3, 1, "$6");
lv_table_set_cell_value(table, 0, 2, "Performance");
lv_table_set_cell_value(table, 1, 2, char_performance_1);
lv_table_set_cell_value(table, 2, 2, char_performance_2);
lv_obj_set_size(table,320,250);
// Apply the styles to the cells based on the cell value conditions
for (uint16_t row = 1; row <= 2; row++) {
for (uint16_t col = 0; col <= 2; col++) {
const char* cell_value = lv_table_get_cell_value(table, row, col);
int value = atoi(cell_value);
if (value < 30) {
/*where new method goes*/ // lv_table_set_cell_type(table, row,col,1);
} else if (value >= 30 && value <= 70) {
/*where new method goes*/ //lv_table_set_cell_type(table, row,col,2);
} else {
/*where new method goes*/ // lv_table_set_cell_type(table, row,col,3);
}
}
}
}
/*
Variables are define as global variables ex:
int oil_1 = 64;
int oil_2 = 32;
int battery_1 = 50;
int battery_2 = 11;
int performance_1 = 56;
int performance_2 = 90;
*/