1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Added a method Component::getChildren() to allow them to be iterated with a range-based for loop, and used this in appropriate places around the codebase

This commit is contained in:
jules 2017-07-19 12:08:47 +01:00
parent 663af835f9
commit 4e5f005421
21 changed files with 182 additions and 223 deletions

View file

@ -52,9 +52,9 @@ namespace ComponentBuilderHelpers
if (c.getComponentID() == compId)
return &c;
for (int i = c.getNumChildComponents(); --i >= 0;)
if (Component* const child = findComponentWithID (*c.getChildComponent (i), compId))
return child;
for (auto* child : c.getChildren())
if (auto* found = findComponentWithID (*child, compId))
return found;
return nullptr;
}
@ -238,7 +238,7 @@ void ComponentBuilder::updateChildComponents (Component& parent, const ValueTree
{
using namespace ComponentBuilderHelpers;
const int numExistingChildComps = parent.getNumChildComponents();
auto numExistingChildComps = parent.getNumChildComponents();
Array<Component*> componentsInOrder;
componentsInOrder.ensureStorageAllocated (numExistingChildComps);
@ -250,15 +250,16 @@ void ComponentBuilder::updateChildComponents (Component& parent, const ValueTree
for (int i = 0; i < numExistingChildComps; ++i)
existingComponents.add (parent.getChildComponent (i));
const int newNumChildren = children.getNumChildren();
auto newNumChildren = children.getNumChildren();
for (int i = 0; i < newNumChildren; ++i)
{
const ValueTree childState (children.getChild (i));
Component* c = removeComponentWithID (existingComponents, getStateId (childState));
auto childState = children.getChild (i);
auto* c = removeComponentWithID (existingComponents, getStateId (childState));
if (c == nullptr)
{
if (TypeHandler* const type = getHandlerForState (childState))
if (auto* type = getHandlerForState (childState))
c = ComponentBuilderHelpers::createNewComponent (*type, childState, &parent);
else
jassertfalse;