How to change styles in table (v7-dev)


In version 6, I was able to change the styles of different elements of a table, but I don’t find a way in v7.

What MCU/Processor/Board and compiler are you using?

CodeBlocks simulator - lvgl version 7.0-dev

What do you want to achieve?

I want to be able to change the style of the table

What have you tried so far?

I have seen in the code that the table still has different styles, but not the way to change/update them

Code to reproduce

In version 6.1, I was doing this:

    lv_theme_t * th_act = lv_theme_get_current();

    static lv_style_t style_cell1;
    lv_style_copy(&style_cell1, th_act->style.table.cell);
    style_cell1.body.opa = LV_OPA_50;
    style_cell1.body.border.width = 1;
    style_cell1.text.font = &lv_font_roboto_12;

    /*Create a header cell style*/
    static lv_style_t style_cell2;
    lv_style_copy(&style_cell2, th_act->style.table.cell);
    style_cell2.body.opa = LV_OPA_80;
    style_cell2.body.border.width = 1;
    style_cell2.text.font = &lv_font_roboto_12;

    static lv_style_t style_cell3;
    lv_style_copy(&style_cell3, th_act->style.table.cell);
    style_cell3.body.opa = LV_OPA_0;
    style_cell3.body.border.width = 0;
    style_cell3.text.font = &lv_font_unscii_8;
    table = lv_table_create(scr, NULL);

	#ifdef _USE_STYLES
	    lv_table_set_style(table, LV_TABLE_STYLE_CELL1, &style_cell1);
	    lv_table_set_style(table, LV_TABLE_STYLE_CELL2, &style_cell2);
	    lv_table_set_style(table, LV_TABLE_STYLE_CELL3, &style_cell3);

What’s the correct way to change them?

You should be able to use lv_obj_add_style(table, LV_TABLE_PART_CELLx, &style_cellx); (replace x with the number)

1 Like

Ok, I was searching for TABLE related functions, and did not think about obj functions…

All the new style system is a bit different, still digging through it.