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

feat(core): Add lv_group_get_obj_by_index method (#6589)

This commit is contained in:
Fabian Blatz 2024-08-15 09:41:22 +02:00 committed by GitHub
parent 58c7bb110a
commit d7b82c7966
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 45 additions and 3 deletions

View File

@ -377,6 +377,20 @@ uint32_t lv_group_get_obj_count(lv_group_t * group)
return lv_ll_get_len(&group->obj_ll);
}
lv_obj_t * lv_group_get_obj_by_index(lv_group_t * group, uint32_t index)
{
uint32_t len = 0;
lv_obj_t ** obj;
LV_LL_READ(&group->obj_ll, obj) {
if(len == index) {
return *obj;
}
len++;
}
return NULL;
}
uint32_t lv_group_get_count(void)
{
return lv_ll_get_len(group_ll_p);
@ -385,11 +399,11 @@ uint32_t lv_group_get_count(void)
lv_group_t * lv_group_by_index(uint32_t index)
{
uint32_t len = 0;
void * node;
lv_group_t * group;
for(node = lv_ll_get_tail(group_ll_p); node != NULL; node = lv_ll_get_prev(group_ll_p, node)) {
LV_LL_READ_BACK(group_ll_p, group) {
if(len == index) {
return (lv_group_t *) node;
return group;
}
len++;
}

View File

@ -213,6 +213,14 @@ bool lv_group_get_wrap(lv_group_t * group);
*/
uint32_t lv_group_get_obj_count(lv_group_t * group);
/**
* Get the nth object within a group
* @param group pointer to a group
* @param index index of object within the group
* @return pointer to the object
*/
lv_obj_t * lv_group_get_obj_by_index(lv_group_t * group, uint32_t index);
/**
* Get the number of groups
* @return number of groups
@ -221,6 +229,7 @@ uint32_t lv_group_get_count(void);
/**
* Get a group by its index
* @param index index of the group
* @return pointer to the group
*/
lv_group_t * lv_group_by_index(uint32_t index);

View File

@ -39,4 +39,23 @@ void test_group_by_index(void)
lv_group_delete(group_2);
}
void test_group_obj_by_index(void)
{
lv_group_t * group = lv_group_create();
TEST_ASSERT_EQUAL_PTR(lv_group_get_obj_by_index(group, 0), NULL);
lv_obj_t * obj_0 = lv_obj_create(NULL);
lv_obj_t * obj_1 = lv_obj_create(NULL);
lv_group_add_obj(group, obj_0);
lv_group_add_obj(group, obj_1);
TEST_ASSERT_EQUAL_PTR(lv_group_get_obj_by_index(group, 0), obj_0);
TEST_ASSERT_EQUAL_PTR(lv_group_get_obj_by_index(group, 1), obj_1);
lv_group_remove_obj(obj_0);
TEST_ASSERT_EQUAL_PTR(lv_group_get_obj_by_index(group, 0), obj_1);
TEST_ASSERT_EQUAL_PTR(lv_group_get_obj_by_index(group, 1), NULL);
}
#endif