blob: fc5db3567912c64d220ef3e24c12233af156f3a7 [file] [log] [blame]
#ifndef _RIVE_CONTAINER_COMPONENT_HPP_
#define _RIVE_CONTAINER_COMPONENT_HPP_
#include "rive/generated/container_component_base.hpp"
#include "rive/typed_children.hpp"
#include <vector>
#include <functional>
namespace rive
{
class ContainerComponent : public ContainerComponentBase
{
public:
template <typename T> TypedChildren<T> children()
{
return TypedChildren<T>(
Span<Core*>((Core**)m_children.data(), m_children.size()));
}
template <typename T> T* firstChild()
{
for (auto* child : m_children)
{
if (child->is<T>())
{
return child->as<T>();
}
}
return nullptr;
}
const std::vector<Component*>& children() const { return m_children; }
virtual void addChild(Component* component);
bool collapse(bool value) override;
// Returns whether predicate returns true for the current Component.
bool forAll(std::function<bool(Component*)> predicate);
// Recursively descend onto all the children in the hierarchy tree.
// If predicate returns false, it won't recurse down a particular
// branch.
void forEachChild(std::function<bool(Component*)> predicate);
private:
std::vector<Component*> m_children;
};
} // namespace rive
#endif