Browse Source

Added Component::findChildWithID

tags/2021-05-28
jules 13 years ago
parent
commit
fee33f45fd
3 changed files with 20 additions and 11 deletions
  1. +12
    -0
      modules/juce_gui_basics/components/juce_Component.cpp
  2. +7
    -2
      modules/juce_gui_basics/components/juce_Component.h
  3. +1
    -9
      modules/juce_gui_basics/positioning/juce_RelativeCoordinatePositioner.cpp

+ 12
- 0
modules/juce_gui_basics/components/juce_Component.cpp View File

@@ -1440,6 +1440,18 @@ int Component::getIndexOfChildComponent (const Component* const child) const noe
return childComponentList.indexOf (const_cast <Component*> (child));
}
Component* Component::findChildWithID (const String& targetID) const noexcept
{
for (int i = childComponentList.size(); --i >= 0;)
{
Component* const c = childComponentList.getUnchecked(i);
if (c->componentID == targetID)
return c;
}
return nullptr;
}
Component* Component::getTopLevelComponent() const noexcept
{
const Component* comp = this;


+ 7
- 2
modules/juce_gui_basics/components/juce_Component.h View File

@@ -101,13 +101,13 @@ public:
virtual void setName (const String& newName);
/** Returns the ID string that was set by setComponentID().
@see setComponentID
@see setComponentID, findChildWithID
*/
const String& getComponentID() const noexcept { return componentID; }
/** Sets the component's ID string.
You can retrieve the ID using getComponentID().
@see getComponentID
@see getComponentID, findChildWithID
*/
void setComponentID (const String& newID);
@@ -699,6 +699,11 @@ public:
*/
int getIndexOfChildComponent (const Component* child) const noexcept;
/** Looks for a child component with the specified ID.
@see setComponentID, getComponentID
*/
Component* findChildWithID (const String& componentID) const noexcept;
/** Adds a child component to this one.
Adding a child component does not mean that the component will own or delete the child - it's


+ 1
- 9
modules/juce_gui_basics/positioning/juce_RelativeCoordinatePositioner.cpp View File

@@ -80,15 +80,7 @@ Component* RelativeCoordinatePositionerBase::ComponentScope::findSiblingComponen
Component* const parent = component.getParentComponent();
if (parent != nullptr)
{
for (int i = parent->getNumChildComponents(); --i >= 0;)
{
Component* const c = parent->getChildComponent(i);
if (c->getComponentID() == componentID)
return c;
}
}
return parent->findChildWithID (componentID);
return nullptr;
}


Loading…
Cancel
Save