From c9111563b10619131a410c811831c909453a85f5 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Wed, 17 Oct 2018 05:42:27 +0200 Subject: [PATCH] add lv_cont/page_get_width/height --- lv_objx/lv_cont.c | 24 ++++++++++++++++++++++++ lv_objx/lv_cont.h | 15 +++++++++++++++ lv_objx/lv_page.c | 26 ++++++++++++++++++++++++++ lv_objx/lv_page.h | 15 +++++++++++++++ 4 files changed, 80 insertions(+) diff --git a/lv_objx/lv_cont.c b/lv_objx/lv_cont.c index 89da6ad22..304852a22 100644 --- a/lv_objx/lv_cont.c +++ b/lv_objx/lv_cont.c @@ -189,6 +189,30 @@ bool lv_cont_get_ver_fit(const lv_obj_t * cont) return ext->ver_fit == 0 ? false : true; } +/** + * Get that width reduced by the horizontal padding. Useful if a layout is used. + * @param cont pointer to a container object + * @return the width which still fits into the container + */ +lv_coord_t lv_cont_get_fit_width(lv_obj_t * cont) +{ + lv_style_t * style = lv_cont_get_style(cont); + + return lv_obj_get_width(cont) - 2 * style->body.padding.hor; +} + +/** + * Get that height reduced by the vertical padding. Useful if a layout is used. + * @param cont pointer to a container object + * @return the height which still fits into the container + */ +lv_coord_t lv_cont_get_fit_height(lv_obj_t * cont) +{ + lv_style_t * style = lv_cont_get_style(cont); + + return lv_obj_get_width(cont) - 2 * style->body.padding.hor; +} + /********************** * STATIC FUNCTIONS **********************/ diff --git a/lv_objx/lv_cont.h b/lv_objx/lv_cont.h index f1c37fac7..3259c772f 100644 --- a/lv_objx/lv_cont.h +++ b/lv_objx/lv_cont.h @@ -125,6 +125,21 @@ bool lv_cont_get_hor_fit(const lv_obj_t * cont); */ bool lv_cont_get_ver_fit(const lv_obj_t * cont); + +/** + * Get that width reduced by the horizontal padding. Useful if a layout is used. + * @param cont pointer to a container object + * @return the width which still fits into the container + */ +lv_coord_t lv_cont_get_fit_width(lv_obj_t * cont); + +/** + * Get that height reduced by the vertical padding. Useful if a layout is used. + * @param cont pointer to a container object + * @return the height which still fits into the container + */ +lv_coord_t lv_cont_get_fit_height(lv_obj_t * cont); + /** * Get the style of a container * @param cont pointer to a container object diff --git a/lv_objx/lv_page.c b/lv_objx/lv_page.c index ce27cae5c..9e19261d8 100644 --- a/lv_objx/lv_page.c +++ b/lv_objx/lv_page.c @@ -306,6 +306,32 @@ bool lv_page_get_arrow_scroll(const lv_obj_t * page) return ext->arrow_scroll ? true : false; } +/** + * Get that width which can be set to the children to still not cause overflow (show scrollbars) + * @param page pointer to a page object + * @return the width which still fits into the page + */ +lv_coord_t lv_page_get_fit_width(lv_obj_t * page) +{ + lv_style_t * bg_style = lv_page_get_style(page, LV_PAGE_STYLE_BG); + lv_style_t * scrl_style = lv_page_get_style(page, LV_PAGE_STYLE_SCRL); + + return lv_obj_get_width(page) - 2 * (bg_style->body.padding.hor + scrl_style->body.padding.hor); +} + +/** + * Get that height which can be set to the children to still not cause overflow (show scrollbars) + * @param page pointer to a page object + * @return the height which still fits into the page + */ +lv_coord_t lv_page_get_fit_height(lv_obj_t * page) +{ + lv_style_t * bg_style = lv_page_get_style(page, LV_PAGE_STYLE_BG); + lv_style_t * scrl_style = lv_page_get_style(page, LV_PAGE_STYLE_SCRL); + + return lv_obj_get_height(page) - 2 * (bg_style->body.padding.ver + scrl_style->body.padding.ver); +} + /** * Get a style of a page * @param page pointer to page object diff --git a/lv_objx/lv_page.h b/lv_objx/lv_page.h index 80f4fcb36..975452d09 100644 --- a/lv_objx/lv_page.h +++ b/lv_objx/lv_page.h @@ -217,6 +217,21 @@ lv_sb_mode_t lv_page_get_sb_mode(const lv_obj_t * page); */ bool lv_page_get_arrow_scroll(const lv_obj_t * page); + +/** + * Get that width which can be set to the children to still not cause overflow (show scrollbars) + * @param page pointer to a page object + * @return the width which still fits into the page + */ +lv_coord_t lv_page_get_fit_width(lv_obj_t * page); + +/** + * Get that height which can be set to the children to still not cause overflow (show scrollbars) + * @param page pointer to a page object + * @return the height which still fits into the page + */ +lv_coord_t lv_page_get_fit_height(lv_obj_t * page); + /** * Get width of the scrollable part of a page * @param page pointer to a page object