Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(obj):scrolling exception when using lv_obj_set_parent() interface #3210

Merged
merged 1 commit into from
Mar 29, 2022

Conversation

guoweilkd
Copy link
Contributor

@guoweilkd guoweilkd commented Mar 28, 2022

Description of the feature or fix

Resetting parent may cause the relative coordinates of this obj to change, but obj->coords did not change. This sometimes leads to errors in the calculation of lv_obj_readjust_scroll() functions.

test code:

lv_obj_t * obj0;
lv_obj_t * obj2;
lv_obj_t * obj3;
static void btn_cb(lv_event_t * e)
{
    lv_event_code_t code = lv_event_get_code(e);
    lv_obj_t * btn = lv_event_get_target(e);

    if(code == LV_EVENT_CLICKED) {
        lv_obj_set_parent(obj0, obj2);
        lv_obj_del_async(obj3);
    }
}

void lv_set_parent(void)
{
    obj0 = lv_obj_create(lv_scr_act());
    lv_obj_set_size(obj0, 100, 300);
    lv_obj_set_style_bg_color(obj0, lv_palette_main(LV_PALETTE_RED), LV_PART_MAIN);

    obj2 = lv_obj_create(lv_scr_act());
    lv_obj_set_size(obj2, 400, 400);
    lv_obj_set_style_border_color(obj2, lv_palette_main(LV_PALETTE_BLUE), LV_PART_MAIN);
    lv_obj_set_align(obj2, LV_ALIGN_TOP_RIGHT);

    obj3 = lv_obj_create(obj2);
    lv_obj_set_size(obj3, 200, 600);

    lv_obj_t * btn;
    btn = lv_btn_create(obj3);
    lv_obj_set_align(btn, LV_ALIGN_BOTTOM_MID);
    lv_obj_add_event_cb(btn, btn_cb, LV_EVENT_ALL, NULL);
}

Checkpoints

  • Follow the styling guide
  • Run code-format.py from the scripts folder. astyle needs to be installed.
  • Update the documentation

@guoweilkd guoweilkd changed the title fix(obj):scrolling exception when using interface fix(obj):scrolling exception when using lv_obj_set_parent() interface Mar 29, 2022
@guoweilkd guoweilkd changed the title fix(obj):scrolling exception when using lv_obj_set_parent() interface fix(obj):scrolling exception when using lv_obj_set_parent() interface Mar 29, 2022
@kisvegabor
Copy link
Member

kisvegabor commented Mar 29, 2022

Hi,

It seems to me the issue is rather coming from lv_obj_del() because the scroll position of the blue-bordered rectangle is not updated when the red rectangle is deleted.

I could fix it by adding lv_obj_update_layout(par); before:

lv_obj_readjust_scroll(par, LV_ANIM_OFF);

It was required because when the object was moved to the new parent, its positioned wasn't recalculated yet (it's not problem normally) and lv_obj_readjust_scroll readjusted the scroll with the invalid coordinates. lv_obj_update_layout(par) makes sure that the all coordinates are correct when the scroll is recalculated.

Could you confirms if it work on your end too?

@guoweilkd
Copy link
Contributor Author

I could fix it by adding lv_obj_update_layout(par); before:

it works good.

@kisvegabor
Copy link
Member

Great, please update the PR, and I'll merge it.

@kisvegabor kisvegabor merged commit 6b628e5 into lvgl:master Mar 29, 2022
@kisvegabor
Copy link
Member

kisvegabor commented Mar 29, 2022

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants