From 0ad121865c8bf3c48173aceb7d20d9c50db70f80 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Fri, 19 Apr 2019 06:10:01 +0200 Subject: [PATCH] lv_page: improve repostion of new children --- src/lv_objx/lv_page.c | 20 +++++++++++++------- src/lv_objx/lv_page.h | 2 +- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/lv_objx/lv_page.c b/src/lv_objx/lv_page.c index 6b8141bb0..ec58ab684 100644 --- a/src/lv_objx/lv_page.c +++ b/src/lv_objx/lv_page.c @@ -768,6 +768,9 @@ static lv_res_t lv_page_signal(lv_obj_t * page, lv_signal_t sign, void * param) if(res != LV_RES_OK) return res; lv_page_ext_t * ext = lv_obj_get_ext_attr(page); + lv_fit_t fit_left = lv_page_get_scrl_fit_left(page); + lv_fit_t fit_top = lv_page_get_scrl_fit_top(page); + const lv_style_t * style = lv_page_get_style(page, LV_PAGE_STYLE_SCRL); lv_obj_t * child; if(sign == LV_SIGNAL_CHILD_CHG) { /*Automatically move children to the scrollable object*/ child = lv_obj_get_child(page, NULL); @@ -776,13 +779,16 @@ static lv_res_t lv_page_signal(lv_obj_t * page, lv_signal_t sign, void * param) lv_obj_t * tmp = child; child = lv_obj_get_child(page, child); /*Get the next child before move this*/ - /*Reposition the child to take padding into account*/ - const lv_style_t * style = lv_page_get_style(page, LV_PAGE_STYLE_SCRL); - tmp->coords.x1 += style->body.padding.left; - tmp->coords.x2 += style->body.padding.left; - tmp->coords.y1 += style->body.padding.top; - tmp->coords.y2 += style->body.padding.top; - + /* Reposition the child to take padding into account (Only if it's on (0;0) now) + * It's required to keep new the object on the same coordinate if FIT is enabled.*/ + if((tmp->coords.x1 == page->coords.x1) && (fit_left == LV_FIT_TIGHT || fit_left == LV_FIT_FILL)) { + tmp->coords.x1 += style->body.padding.left; + tmp->coords.x2 += style->body.padding.left; + } + if((tmp->coords.y1 == page->coords.y1) && (fit_top == LV_FIT_TIGHT || fit_top == LV_FIT_FILL)) { + tmp->coords.y1 += style->body.padding.top; + tmp->coords.y2 += style->body.padding.top; + } lv_obj_set_parent(tmp, ext->scrl); } else { child = lv_obj_get_child(page, child); diff --git a/src/lv_objx/lv_page.h b/src/lv_objx/lv_page.h index 7ca1c4482..adda367bb 100644 --- a/src/lv_objx/lv_page.h +++ b/src/lv_objx/lv_page.h @@ -340,7 +340,7 @@ static inline lv_fit_t lv_page_get_scrl_fit_right(const lv_obj_t * page) * @param page pointer to a page object * @return an element of `lv_fit_t` */ -static inline lv_fit_t lv_page_get_scrl_get_fit_top(const lv_obj_t * page) +static inline lv_fit_t lv_page_get_scrl_fit_top(const lv_obj_t * page) { return lv_cont_get_fit_top(lv_page_get_scrl(page)); }