mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Added Component::findChildWithID
This commit is contained in:
parent
4b59682077
commit
fee33f45fd
3 changed files with 20 additions and 11 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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…
Add table
Add a link
Reference in a new issue