How to "concat" a container object with an integer id?

Sorry for the newbie question, is there a way to add an int number to a container id?
In case I have a set of containers like this, numbered from 1 to 30

lv_obj_set_style_bg_color(container1, lv_color_hex(0xFF0000), LV_PART_MAIN | LV_STATE_DEFAULT);

I want to change the background dynamically later on. So far not a problem but I’d like to avoid a switch block of 30 rows like that. Can I set the ID of the container somehow?

As the containers are generated by SquarelineStudio I cannot really change it to an array like container[1].
Not sure if that would work in C++ anyway. :confused:


You ask in lvgl squareline question , but ok.
Simple create yourself array and use it.

lv_obj_t * youraracont[] = { ui_container1, ....}


If all of the objects are a child of the same parent it is easy to do because they will be added to the internal child array in the parent object in the order in which they were added. You simply have to use something along these lines

uint32_t count = lv_obj_get_child_cnt(parent);
lv_obj_t * child;

for (uint32_t i = 0; i<count; i++) {
    child = lv_obj_get_child(parent, i);
    // do whatever it is you want to do with the child

you can optionally use hard coded numbers if you only want to do something to one of them.

lv_obj_t * child = lv_obj_get_child(parent, 10);
// do whatever with the child