Move objects between lists/pages


I want to move a button from one list to another.

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

I’m using a modified version of the simulator

What LVGL version are you using?

I’m using v7.6.0.

What do you want to achieve?

I want to be able to move a button from a list to another list without modifying it’s pointer.

What have you tried so far?

I tried moving the button from the linked list of the one list to the linked list of the other list and updating the parent pointer. The moved over buttons work fully, but are invisible after they were moved. That can be fixed though by clicking on the location of the moved button or focusing the button using a function.

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.

lv_obj_t *src_list = lv_list_create(lv_scr_act(), NULL);
lv_obj_t *md_list = lv_list_create(lv_scr_act(), NULL);

lv_obj_align(src_list, NULL, LV_ALIGN_IN_LEFT_MID, 0, 0);
lv_obj_align(md_list, NULL, LV_ALIGN_IN_RIGHT_MID, 0, 0);

lv_obj_t* src_list_scrbl = lv_page_get_scrollable(src_list);
lv_obj_t* md_list_scrbl = lv_page_get_scrollable(md_list);

lv_obj_t* list_btn = lv_list_add_btn(src_list, NULL, "Sample_text");

_lv_ll_chg_list(&src_list_scrbl->child_ll, &md_list_scrbl->child_ll, list_btn, false);
list_btn->parent = md_list_scrbl;
std::cout << list_btn->signal_cb << std::endl;
list_btn->signal_cb(list_btn, LV_SIGNAL_CHILD_CHG, NULL);
lv_list_focus_btn(md_list, list_btn); // When this line is commented out, the location of the button must be clicked to reveal it.

Screenshot and/or video

The application shown in the video is functionally the same to the provided source code, the buttons on the original list are just created with other arguments.

Generally, you should not be accessing object structure values directly, unless no API for what you are trying to do exists. In this case you should be using the lv_obj_set_parent API to move the button.