setColour request



Hey Jules -


I find myself adding little bits of code in the colourChanged() routines of some of my components to set the same colors in the child components.

And it occurs to me that maybe you would be nice enough to add an optional parameter to setColour that would propagate the change to children?


Maybe something like ....


void Component::setColour (const int colourId, Colour colour, bool setForChildren)


    if (properties.set (ComponentHelpers::getColourPropertyId (colourId), (int) colour.getARGB()))

    if (setForChildren) {
        // SET CHILD COLORS :::::
        for (short i=0; i < getNumChildComponents(); i++)
            Component* c = getChildComponent(i);








Hmm, I'm not convinced of the usefulness of that.

BTW, using a 'short' as a loop index is a false economy. It won't be any faster than using an int. In fact it may be slower in some cases, and generate more code to extend/shorten the value.


Yeah, I thought you would say that.  

Seems useful to me, but maybe I'm the only person making a bunch of runtime color changes that I want to push to children.  Anyway, doing it with a bunch of calls in various colourChanged methods isn't so hard.

And thank for the tidbit on short as a loop index.  I didn't actually know that until now.


Remember that functions like this don't actually need to be member functions - you could write your own free function to do exactly the same thing, e.g.

static void setColourIncludingChildren (Component& c, int colourID, Colour newColour)

And there's a trend in modern C++ style to prefer free functions over member functions because it decreases coupling, so many people would say that this approach is actually better than what you asked for.