feat(lv_group): get group count and retrieve by index (#4632)

This commit is contained in:
Fabian Blatz 2023-10-09 18:36:47 +02:00 committed by GitHub
parent e12ac1ae9c
commit 7d52859fe8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 73 additions and 0 deletions

View File

@ -372,6 +372,26 @@ uint32_t lv_group_get_obj_count(lv_group_t * group)
{
return _lv_ll_get_len(&group->obj_ll);
}
uint32_t lv_group_get_count(void)
{
return _lv_ll_get_len(group_ll_p);
}
lv_group_t * lv_group_by_index(uint32_t index)
{
uint32_t len = 0;
void * node;
for(node = _lv_ll_get_tail(group_ll_p); node != NULL; node = _lv_ll_get_prev(group_ll_p, node)) {
if(len == index) {
return (lv_group_t *) node;
}
len++;
}
return NULL;
}
/**********************
* STATIC FUNCTIONS
**********************/

View File

@ -259,6 +259,18 @@ bool lv_group_get_wrap(lv_group_t * group);
*/
uint32_t lv_group_get_obj_count(lv_group_t * group);
/**
* Get the number of groups
* @return number of groups
*/
uint32_t lv_group_get_count(void);
/**
* Get a group by its index
* @return pointer to the group
*/
lv_group_t * lv_group_by_index(uint32_t index);
/**********************
* MACROS
**********************/

View File

@ -0,0 +1,41 @@
#if LV_BUILD_TEST
#include "../lvgl.h"
#include "unity/unity.h"
void setUp(void)
{
}
void tearDown(void)
{
}
void test_group_count(void)
{
lv_group_t * group_1 = lv_group_create();
lv_group_t * group_2 = lv_group_create();
TEST_ASSERT_EQUAL_UINT32(lv_group_get_count(), 2U);
lv_group_del(group_2);
TEST_ASSERT_EQUAL_UINT32(lv_group_get_count(), 1U);
lv_group_del(group_1);
TEST_ASSERT_EQUAL_UINT32(lv_group_get_count(), 0U);
}
void test_group_by_index(void)
{
lv_group_t * group_1 = lv_group_create();
lv_group_t * group_2 = lv_group_create();
TEST_ASSERT_EQUAL_PTR(lv_group_by_index(2), NULL);
TEST_ASSERT_EQUAL_PTR(lv_group_by_index(0), group_1);
TEST_ASSERT_EQUAL_PTR(lv_group_by_index(1), group_2);
lv_group_del(group_1);
lv_group_del(group_2);
}
#endif