A Component::getAllChildren() method?

Any reason not having such a method in Component? would that be too dangerous or something?

const Array<Component*>& getChildList() const noexcept
    return childComponentList;

it would be pretty handy to write for loops :

for (auto child : getChildList())
    child->setVisible (false);

Why not just use Component:: getNumChildComponents() and Component:: getChildComponent() ??


That’s something I’ve been meaning to add, actually! The only reason I haven’t is that it’d be nicer if the iterator returned a reference for each element rather than a pointer, as none of them can ever be null.

Another approach would be to give Component some begin/end methods to make it directly iterable. Or to have a getChildComponent() method that returns some kind of iterator adapter class.

cool! making it directly iterable sounds great. whatever option you think is best!

It would also be very nice to have a templated findChildComponentOfClass(), similar to the already-existing findParentComponentOfClass ()


Actually, I think a better addition would be something like getChildComponentsOfClass() which would return some kind of iterable array. When looking for a parent, you generally only expect to find a single object, but when looking through children, a more common use-case would be iterating 1 or more objects of that class.


Absolutely, fair point! This would really fascilitate the (quite nice) pattern where you add special capabilities to certain child components, and then need to find them all from the parent.

This would be a very welcome addition - both the initial request and getChildComponentsOfClass(<ComponentClass>)