From d93056cd436b433d26fa1f953c06a9ea2fd52862 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Mon, 15 Mar 2021 16:36:13 +0100 Subject: [PATCH] feat(obj): add lv_obj_get_height/width_visible --- src/lv_core/lv_obj_pos.c | 28 ++++++++++++++++++++++++++++ src/lv_core/lv_obj_pos.h | 18 ++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/src/lv_core/lv_obj_pos.c b/src/lv_core/lv_obj_pos.c index 63b3273f7..c15e0086e 100644 --- a/src/lv_core/lv_obj_pos.c +++ b/src/lv_core/lv_obj_pos.c @@ -404,6 +404,34 @@ void lv_obj_get_coords_fit(const lv_obj_t * obj, lv_area_t * area) } +lv_coord_t lv_obj_get_height_visible(const lv_obj_t * obj) +{ + lv_obj_update_layout(lv_obj_get_screen(obj)); + + lv_coord_t h = LV_COORD_MAX; + lv_obj_t * parent = lv_obj_get_parent(obj); + while(parent) { + h = LV_MIN(lv_obj_get_height_fit(parent), h); + parent = lv_obj_get_parent(parent); + } + + return h == LV_COORD_MAX ? LV_DPI_DEF : h; +} + +lv_coord_t lv_obj_get_width_visible(const lv_obj_t * obj) +{ + lv_obj_update_layout(lv_obj_get_screen(obj)); + + lv_coord_t w = LV_COORD_MAX; + lv_obj_t * parent = lv_obj_get_parent(obj); + while(parent) { + w = LV_MIN(lv_obj_get_width_fit(parent), w); + parent = lv_obj_get_parent(parent); + } + + return w == LV_COORD_MAX ? LV_DPI_DEF : w; +} + lv_coord_t lv_obj_get_self_width(struct _lv_obj_t * obj) { lv_point_t p = {0, LV_COORD_MIN}; diff --git a/src/lv_core/lv_obj_pos.h b/src/lv_core/lv_obj_pos.h index 999007919..6eaff866f 100644 --- a/src/lv_core/lv_obj_pos.h +++ b/src/lv_core/lv_obj_pos.h @@ -223,6 +223,24 @@ lv_coord_t lv_obj_get_height_fit(const struct _lv_obj_t * obj); */ void lv_obj_get_coords_fit(const struct _lv_obj_t * obj, lv_area_t * area); +/** + * Get the height which is visible on the the given object without causing overflow. + * If there are smaller grand parents than their height will be considered. + * Useful on nested scrollable objects to get a height that fills the entire visible height. + * @param obj pointer to an object + * @return the visible height + */ +lv_coord_t lv_obj_get_height_visible(const struct _lv_obj_t * obj); + +/** + * Get the widht which is visible on the the given object without causing overflow. + * If there are smaller grand parents than their width will be considered. + * Useful on nested scrollable objects to get a width that fills the entire visible width. + * @param obj pointer to an object + * @return the visible width + */ +lv_coord_t lv_obj_get_width_visible(const struct _lv_obj_t * obj); + /** * Get the width occupied by the "parts" of the widget. E.g. the width of all columns of a table. * @param obj pointer to an objects