mirror of
https://github.com/lvgl/lvgl.git
synced 2024-11-27 11:43:43 +08:00
feat(lv_group): get group count and retrieve by index (#4632)
This commit is contained in:
parent
e12ac1ae9c
commit
7d52859fe8
@ -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
|
||||
**********************/
|
||||
|
@ -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
|
||||
**********************/
|
||||
|
41
tests/src/test_cases/test_group.c
Normal file
41
tests/src/test_cases/test_group.c
Normal 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
|
Loading…
Reference in New Issue
Block a user