Useful C++ function

I needed to be able to get the lv_obj_t* of all child objects recursively, so I wrote this. Some may find value:

std::vector<lv_obj_t*> ObjectTools::GetChildren(lv_obj_t* object)
{
	lv_obj_t * i;
	std::vector<lv_obj_t*> children;
	lv_obj_t * result = nullptr;

	result = (lv_obj_t*)lv_ll_get_head(&object->child_ll);
	while(result!=nullptr)
	{
		children.push_back(result);
		std::vector<lv_obj_t*> cNodes = GetChildren(result);
		children.insert(children.end(), cNodes.begin(), cNodes.end());
		result = (lv_obj_t*)lv_ll_get_next(&object->child_ll, result);
	}

	return children;
}
3 Likes

A note: use ```cpp and ``` instead of <code> and </code>, respectively. The forum didn’t format <code> and </code> properly.

1 Like

Hokay :slight_smile:

Thanks for sharing!