Gin
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | List of all members
ComponentMap Class Reference

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
 

Detailed Description

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.

Path Format

Component paths follow a hierarchical slash-separated format:

Paths are case-insensitive and derived from:

  1. Component's "layoutID" property (if set)
  2. Component's componentID (if set)
  3. Component's name (as fallback)

Usage Example

// Create map for a component hierarchy
map.createMap();
// Find a component by path
if (auto* button = map.findComponent ("/dialog/buttons/okButton"))
button->setBounds (x, y, w, h);
// Get path of a component
juce::String path = map.getComponentPath (someComponent);
// Returns something like "/parent/child"
Internal class for mapping component paths to component pointers.
Definition gin_componentmap.h:49
A lightweight 2D point class for projects that don't use juce_graphics.
Definition gin_point.h:25
See also
LayoutSupport

Constructor & Destructor Documentation

◆ ComponentMap()

ComponentMap::ComponentMap ( juce::Component &  parent_)

Constructs a ComponentMap for the given parent component.

Parameters
parent_The root component of the hierarchy to map

Member Function Documentation

◆ createMap()

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.

Parameters
checkChildrenOptional 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.

◆ addComponent()

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).

Parameters
cThe component to add to the map

◆ getComponentPath()

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".

Parameters
cThe component to get the path for
Returns
The component's path string, or empty string if component has no ID

◆ findComponent()

juce::Component * ComponentMap::findComponent ( const juce::String &  path)

Finds a component by its path.

Parameters
pathThe path to search for (case-insensitive). Empty string returns the root.
Returns
Pointer to the component if found, nullptr otherwise

◆ clearMap()

void ComponentMap::clearMap ( )

Clears all entries from the component map.

Useful before rebuilding the map when the component hierarchy changes.

◆ dump()

juce::StringArray ComponentMap::dump ( )

Returns all component paths in the map.

Useful for debugging or inspecting the component hierarchy.

Returns
Array of all registered component paths

Member Data Documentation

◆ parent

juce::Component& ComponentMap::parent
protected

The documentation for this class was generated from the following file: