Lv_obj_add_state in an Array?

Description

What MCU/Processor/Board and compiler are you using? Arduino on ESP32 Sunton Board

What LVGL version are you using? 8.3.11

What do you want to achieve?

Set a lot of checkboxes (ui_Screen0 til ui_screen9) to enabled.

What have you tried so far?

Array of Names…

Code to reproduce

The code block(s) should be formatted like:

void set_screen_states() {
  // Set all states to checkes
  lv_obj_add_state(ui_screen0, LV_STATE_CHECKED);
  lv_obj_add_state(ui_screen1, LV_STATE_CHECKED);
  lv_obj_add_state(ui_screen2, LV_STATE_CHECKED);
  lv_obj_add_state(ui_screen3, LV_STATE_CHECKED);
  lv_obj_add_state(ui_screen4, LV_STATE_CHECKED);
  lv_obj_add_state(ui_screen5, LV_STATE_CHECKED);
  lv_obj_add_state(ui_screen6, LV_STATE_CHECKED);
  lv_obj_add_state(ui_screen7, LV_STATE_CHECKED);
  lv_obj_add_state(ui_screen8, LV_STATE_CHECKED);
}

Screenshot and/or video

If possible, add screenshots and/or videos about the current state.

Is this what you are looking for?

lv_obj_t *screens[] = {
        ui_screen0,
        ui_screen1,
        ui_screen2,
        ui_screen3,
        ui_screen4,
        ui_screen5,
        ui_screen6,
        ui_screen7,
        ui_screen8
    };

// find checkboxes and set the state
static void set_checkbox_state_recursive(lv_obj_t *obj, lv_state_t state) {
    // Check if this object is a checkbox
    if (lv_obj_check_type(obj, &lv_checkbox_class)) {
        lv_obj_add_state(obj, state);
    }

    // Iterate through children
    uint32_t child_cnt = lv_obj_get_child_count(obj);
    for (uint32_t i = 0; i < child_cnt; i++) {
        lv_obj_t *child = lv_obj_get_child(obj, i);
        set_checkbox_state_recursive(child);
    }
}

// loop through your screens
void set_screen_states() {
    for (size_t i = 0; i < sizeof(screens) / sizeof(screens[0]); i++) {
        set_checkbox_state_recursive(screens[i], LV_STATE_CHECKED);
    }
}