How do you change the colour of a table call text?


I have a table like:

lv_table_set_cell_value(sensorTable, 1, 0, "Thermostat");
lv_table_set_cell_value(sensorTable, 1, 1, "20.25ºC");
lv_table_set_cell_align(sensorTable, 1, 1, LV_LABEL_ALIGN_RIGHT);
lv_table_set_cell_value(sensorTable, 1, 2, "10");
lv_table_set_cell_align(sensorTable, 1, 2, LV_LABEL_ALIGN_RIGHT);
lv_table_set_cell_value(sensorTable, 1, 3, "-0.20");

When setting the value (via another callback) i would like to set/change the colour.

Ive used the following to set the the text of the cell in my loop:

static char buf[5];                                 /* max 4 bytes  for number plus 1 null terminating byte */
String labelvalue = String(lastmsg_now/1000);
labelvalue.toCharArray(buf, 5);

//row 2 column 3 (0 indexed)
lv_table_set_cell_value(sensorTable, 1, 2, buf);

but i cant figure out how to set the style/colour that cell uses.

Can it be done?


Next time, please use the How-to category and fill out the template.

Have you read the table documentation?
Essentially, you have 4 cell types to choose from and you can style each one individually. So, as an example, if you made cell (1,2) a type 2 cell, then you could change the type 2 text color.

Ok will do.

It looks like i overlooked that part of the docs.

Is there any other way of doing the styling? I’m trying to replace the table in my old system with yours, it currently looks like:

As you can see there are 5 rows where i would like to individually change the colour based on the temp.

If there are only 4 cell types I will have to re-think using the table option.

Thanks in advance.

Hold off on answering that. I think I’m being dumb…

I need 3 styles, red blue and green, i can then apply one of those to the cell i need…

Thanks again.

Yes, that was the answer.

To continue this I am using the night theme. As i am changing the colour of the text i have to create a new style.

The one i am copying is lv_style_plain using:

lv_style_copy( &st_temp_blue, &lv_style_plain );
st_temp_blue.text.color = LV_COLOR_BLUE;

But it seems that the background is replaced with the default (white).

Can you tell me how i can get the correct current style for a table?

Ive tried:
const lv_style_t * tbl_style = lv_table_get_style(sensorTable, LV_TABLE_STYLE_CELL1);
lv_style_copy( &st_temp_blue, &tbl_style );

but that errors.

Ive also tried

lv_style_copy( &st_temp_blue, th>style.table );
lv_style_copy( &st_temp_blue, );

Any help would really be appreciated.


It’s probably because you are taking the address of tbl_style when it’s already a pointer. Try lv_style_copy(&st_temp_blue, tbl_style).

Damn! You’re right. Thats what happens when you try to play after 1am…

Thank you!