What is the purpose of component name? What is it used for?
If you are really lazy, you could differentiate components in callbacks via its name. I am using this technique for custom button handling in AlertWindows (there is no getButton() method, so this is the most convenient way).
Also it gets handy when debugging…
…not only if you are lazy, but if the listener implementing the callback is not the owner of the component and you don’t want to publish a pointer there.
This has always been the only real use I can think of for component names. One thing I’ve often wondered about with this is how the performance is if you’re going through a big block of conditional statements in some listener callback doing tons of string compares to figure out where to go with the current component name…
They are really handy when you’re debugging something with a lot of similar looking buttons … ;_) But I’m still confused about the relationship between the name and the componentID. And there’s also a bunch of constructors which seem really keen for you to set a component name … as if the world might fall apart with out it…
IIRC, the name can be anything without limitations, while the componentId (which was introduced much later in the JUCE history) is required to be unique (within the same parent
Component? can’t remember…).
Again IIRC, the componentId was used in an attempt to implement dynamic/relative placement of
Components with the use of expressions evaluated at run time (something like
"button.x = label.right + 10"), with
"label" being the componentIds of those components.
I think that whole approach has been abandoned since some time, and thus the componentId doesn’t serve any particular purpose nowadays.
Any chance we could get confirmation from a ROLI guy on this? I’ve always been curious about this part of the component system.
That was my sense of it as well, that
id should be a unique identifier.
Still wondering about this myself. Been needing to use component name/id stuff recently, and unsure if their usage is intended to be open-ended (i.e. they signify only whatever I want them to) or if there are built-in meanings that I will run afoul of down the line if I don’t respect the established convention.