List automatically scroll to end when delete top_layer object

List automatically scroll to end when delete top_layer object

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

Linux PC simulator using SDL

What LVGL version are you using?

v8.3.10

What do you want to achieve?

List should not scroll automatically when top_layer object deleted

What have you tried so far?

Code to reproduce.

The below code will execute when cancel button pressed

lv_obj_add_event_cb(cancel_btn, top_layer_close_event_cb, LV_EVENT_CLICKED, text_popup_scr);

static void top_layer_close_event_cb(lv_event_t *e)
{
    lv_event_code_t code = lv_event_get_code(e);
    lv_obj_t *top_layer_scr = lv_event_get_user_data(e);

    if (LV_EVENT_CLICKED == code)
    {   
        lv_obj_clear_flag(lv_layer_top(), LV_OBJ_FLAG_CLICKABLE);
        lv_obj_set_style_bg_opa(lv_layer_top(), LV_OPA_TRANSP, 0);
        lv_obj_del(top_layer_scr);
        lv_obj_del(kb);
        kb = NULL;
    }
}

image

After pressing Cancel Button

Could you please help me to resolve this issue

Hello, have you tried putting the message box on the top layer of the screen? lv_layer_top?

I had a somewhat similar issue some time ago: Lv_roller strange behavior when clearing/adding CLICKABLE flag - #10 by kisvegabor

@Tinus. Yes message box created with lv_layer_top() as parent

1 Like

Issue is not solved. I tried steps described in @Tinus issue but no luck

@kisvegabor Could you please help me to resolve the issue

It happens because you have used lv_group_set_default(), so all list elements and message box buttons are added to the group. When the message box is deleted the previous item in the group is focused, which is the last list item.

To solve it you can do 3 things:

  1. Do not use lv_group_set_default is groups are not needed
  2. Apply lv_obj_clear_flag(list_item, LV_OBJ_FLAG_SCROLL_ON_FOCUS); on each list_item
  3. Manually focus a list item when the message box closes using lv_group_focus_obj(list_item). You can save the last focused object before opening the message box, and focusing it again when the message box is closed.

@kisvegabor Thanks a lot. After removing each list item from default automatically scroll not happen as below

lv_group_remove_obj(list_item)