From 556306a269cb0a7f44240fd42ac60e187f0abcaa Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Mon, 15 Oct 2018 12:38:13 +0200 Subject: [PATCH] add lv_page/cont_fit_width/height functions --- lv_objx/lv_cont.c | 24 ++++++++++++++++++++++++ lv_objx/lv_cont.h | 15 +++++++++++++++ lv_objx/lv_page.c | 26 ++++++++++++++++++++++++++ lv_objx/lv_page.h | 15 +++++++++++++++ lv_themes/lv_theme_material.c | 2 +- 5 files changed, 81 insertions(+), 1 deletion(-) 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 793b9647b..29d965f3e 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 diff --git a/lv_themes/lv_theme_material.c b/lv_themes/lv_theme_material.c index 40f0fc55f..accc011bc 100644 --- a/lv_themes/lv_theme_material.c +++ b/lv_themes/lv_theme_material.c @@ -718,7 +718,7 @@ static void win_init(void) lv_style_copy(&header, &def); header.body.main_color = LV_COLOR_HEX3(0xccc); header.body.grad_color = header.body.main_color; - header.body.radius = DEF_RADIUS; + header.body.radius = 0; header.body.border.width = 1; header.body.border.color = LV_COLOR_HEX3(0xbbb); header.body.border.part = LV_BORDER_BOTTOM;