|
Gin
|
Internal class for mapping component paths to component pointers. More...
#include <gin_componentmap.h>
Public Member Functions | |
| ComponentMap (juce::Component &parent_) | |
| Constructs a ComponentMap for the given parent component. | |
| void | createMap (const std::function< bool(juce::Component &)> &checkChildren=nullptr) |
| Builds the component map by traversing the component hierarchy. | |
| void | addComponent (juce::Component &c) |
| Adds a single component to the map. | |
| juce::String | getComponentPath (juce::Component &c) |
| Gets the hierarchical path for a given component. | |
| juce::Component * | findComponent (const juce::String &path) |
| Finds a component by its path. | |
| void | clearMap () |
| Clears all entries from the component map. | |
| juce::StringArray | dump () |
| Returns all component paths in the map. | |
Protected Attributes | |
| juce::Component & | parent |
Internal class for mapping component paths to component pointers.
ComponentMap builds and maintains a hierarchical path-based lookup system for JUCE components. It traverses a component hierarchy and creates path strings like "/parent/child/grandchild" that map to component pointers for fast lookup.
This is primarily used by LayoutSupport to resolve component references in JSON layout files, allowing expressions like "getX('button')" or inset operations to find components by their component ID.
Component paths follow a hierarchical slash-separated format:
Paths are case-insensitive and derived from:
| ComponentMap::ComponentMap | ( | juce::Component & | parent_ | ) |
Constructs a ComponentMap for the given parent component.
| parent_ | The root component of the hierarchy to map |
| void ComponentMap::createMap | ( | const std::function< bool(juce::Component &)> & | checkChildren = nullptr | ) |
Builds the component map by traversing the component hierarchy.
Recursively visits all child components and adds them to the internal map. Components without an ID (no componentID, name, or layoutID property) are skipped.
| checkChildren | Optional predicate to determine whether to recurse into a component's children. If null, all children are traversed. Return true to continue traversing children, false to skip. |
| void ComponentMap::addComponent | ( | juce::Component & | c | ) |
Adds a single component to the map.
Useful for adding components dynamically after the initial map creation. The component must have a valid ID (componentID, name, or layoutID property).
| c | The component to add to the map |
| juce::String ComponentMap::getComponentPath | ( | juce::Component & | c | ) |
Gets the hierarchical path for a given component.
Walks up the parent chain to build the full path from root to the component. Paths are case-insensitive and follow the format "/parent/child/grandchild".
| c | The component to get the path for |
| juce::Component * ComponentMap::findComponent | ( | const juce::String & | path | ) |
Finds a component by its path.
| path | The path to search for (case-insensitive). Empty string returns the root. |
| void ComponentMap::clearMap | ( | ) |
Clears all entries from the component map.
Useful before rebuilding the map when the component hierarchy changes.
| juce::StringArray ComponentMap::dump | ( | ) |
Returns all component paths in the map.
Useful for debugging or inspecting the component hierarchy.
|
protected |