From 7b4846424173ae5ead5e9af63aeede63e0f50276 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Tue, 13 Oct 2020 20:36:54 +0200 Subject: [PATCH] add lv_obj_get_child_by_id --- src/lv_core/lv_obj.c | 18 ++++++++++++++++++ src/lv_core/lv_obj.h | 8 ++++++++ src/lv_core/lv_obj_pos.c | 36 ++++++++++++++++++------------------ 3 files changed, 44 insertions(+), 18 deletions(-) diff --git a/src/lv_core/lv_obj.c b/src/lv_core/lv_obj.c index aa6e48880..341e2a271 100644 --- a/src/lv_core/lv_obj.c +++ b/src/lv_core/lv_obj.c @@ -1139,6 +1139,24 @@ lv_obj_t * lv_obj_get_child_back(const lv_obj_t * obj, const lv_obj_t * child) return child ? _lv_ll_get_prev(&obj->child_ll, child) : _lv_ll_get_tail(&obj->child_ll); } +/** + * Get the Nth child of a an object. 0th is the lastly created. + * @param obj pointer to an object whose children should be get + * @param id of a child + * @return the child or `NULL` if `id` was greater then the `number of children - 1` + */ +lv_obj_t * lv_obj_get_child_by_id(const lv_obj_t * obj, uint32_t id) +{ + LV_ASSERT_OBJ(obj, LV_OBJX_NAME); + + lv_obj_t * child = lv_obj_get_child(obj, NULL); + uint32_t i; + for(i = 0; i < id; i++) { + child = lv_obj_get_child(obj, child); + } + + return child; +} /** * Count the children of an object (only children directly on 'obj') * @param obj pointer to an object diff --git a/src/lv_core/lv_obj.h b/src/lv_core/lv_obj.h index 7e57432af..bb2c6b4c9 100644 --- a/src/lv_core/lv_obj.h +++ b/src/lv_core/lv_obj.h @@ -592,6 +592,14 @@ lv_obj_t * lv_obj_get_child(const lv_obj_t * obj, const lv_obj_t * child); */ lv_obj_t * lv_obj_get_child_back(const lv_obj_t * obj, const lv_obj_t * child); +/** + * Get the Nth child of a an object. 0th is the lastly created. + * @param obj pointer to an object whose children should be get + * @param id of a child + * @return the child or `NULL` if `id` was greater then the `number of children - 1` + */ +lv_obj_t * lv_obj_get_child_by_id(const lv_obj_t * obj, uint32_t id); + /** * Count the children of an object (only children directly on 'obj') * @param obj pointer to an object diff --git a/src/lv_core/lv_obj_pos.c b/src/lv_core/lv_obj_pos.c index ad78c3d34..57ed5c4d5 100644 --- a/src/lv_core/lv_obj_pos.c +++ b/src/lv_core/lv_obj_pos.c @@ -315,57 +315,57 @@ void lv_obj_align(lv_obj_t * obj, const lv_obj_t * base, lv_align_t align, lv_co case LV_ALIGN_OUT_TOP_LEFT: x = 0; - y = -lv_obj_get_height_fit(obj); + y = -lv_obj_get_height(obj); break; case LV_ALIGN_OUT_TOP_MID: - x = lv_obj_get_width_fit(base) / 2 - lv_obj_get_width_fit(obj) / 2; - y = -lv_obj_get_height_fit(obj); + x = lv_obj_get_width(base) / 2 - lv_obj_get_width(obj) / 2; + y = -lv_obj_get_height(obj); break; case LV_ALIGN_OUT_TOP_RIGHT: - x = lv_obj_get_width_fit(base) - lv_obj_get_width_fit(obj); - y = -lv_obj_get_height_fit(obj); + x = lv_obj_get_width(base) - lv_obj_get_width(obj); + y = -lv_obj_get_height(obj); break; case LV_ALIGN_OUT_BOTTOM_LEFT: x = 0; - y = lv_obj_get_height_fit(base); + y = lv_obj_get_height(base); break; case LV_ALIGN_OUT_BOTTOM_MID: - x = lv_obj_get_width_fit(base) / 2 - lv_obj_get_width_fit(obj) / 2; - y = lv_obj_get_height_fit(base); + x = lv_obj_get_width(base) / 2 - lv_obj_get_width(obj) / 2; + y = lv_obj_get_height(base); break; case LV_ALIGN_OUT_BOTTOM_RIGHT: - x = lv_obj_get_width_fit(base) - lv_obj_get_width_fit(obj); - y = lv_obj_get_height_fit(base); + x = lv_obj_get_width(base) - lv_obj_get_width(obj); + y = lv_obj_get_height(base); break; case LV_ALIGN_OUT_LEFT_TOP: - x = -lv_obj_get_width_fit(obj); + x = -lv_obj_get_width(obj); y = 0; break; case LV_ALIGN_OUT_LEFT_MID: - x = -lv_obj_get_width_fit(obj); - y = lv_obj_get_height_fit(base) / 2 - lv_obj_get_height_fit(obj) / 2; + x = -lv_obj_get_width(obj); + y = lv_obj_get_height(base) / 2 - lv_obj_get_height(obj) / 2; break; case LV_ALIGN_OUT_LEFT_BOTTOM: - x = -lv_obj_get_width_fit(obj); - y = lv_obj_get_height_fit(base) - lv_obj_get_height_fit(obj); + x = -lv_obj_get_width(obj); + y = lv_obj_get_height(base) - lv_obj_get_height(obj); break; case LV_ALIGN_OUT_RIGHT_TOP: - x = lv_obj_get_width_fit(base); + x = lv_obj_get_width(base); y = 0; break; case LV_ALIGN_OUT_RIGHT_MID: - x = lv_obj_get_width_fit(base); - y = lv_obj_get_height_fit(base) / 2 - lv_obj_get_height_fit(obj) / 2; + x = lv_obj_get_width(base); + y = lv_obj_get_height(base) / 2 - lv_obj_get_height(obj) / 2; break; case LV_ALIGN_OUT_RIGHT_BOTTOM: