1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-14 06:42:58 +08:00

add lv_obj_get_child_by_id

This commit is contained in:
Gabor Kiss-Vamosi 2020-10-13 20:36:54 +02:00
parent 68058eeff1
commit 7b48464241
3 changed files with 44 additions and 18 deletions

View File

@ -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

View File

@ -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

View File

@ -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: