[FR] Make Component::setTitle virtual

We often use composite components for widgets like buttons and sliders - rather than inheriting from JUCE widgets, we instead simply ‘wrap’ them in higher-level components.

This makes accessibility a little tricky as the parent is the first to be exposed to screen readers, but is displayed as a ‘group’, rather than the underlying widget that we actually want to be accessed. This is easily fixed by giving the composite component the ignored accessibility role so only its children are exposed to the screen reader.

However, with things like titles, help text, etc. we want to be able to set those things on the composite component so it can behave as much like a ‘real’ widget as possible, but it’s the children that need those strings. Currently there’s no way to know when those strings are changed and so no convenient way to forward the strings to the children.

Currently, we have something like:

class CustomButton : public juce::Component
{
public:
    // Allow users of CustomButton to set the title of the wrapped ToggleButton
    void setButtonTitle (const juce::String& newTitle)
    {
        m_button.setTitle (newTitle);
    }

private:
    juce::ToggleButton m_button;
};

m_customButton.setTitle ("abc"); // ERROR - title not used by screen-readers
m_customButton.setButtonTitle ("abc"); // Have to use awkward workaround instead

Which somewhat exposes the implementation of our composite components by having the extra setter, and means they can’t properly be used through pointers or references to the base class!

It’d be great if instead we could simply have:

class CustomButton : public juce::Component
{
public:
    void setTitle (const juce::String& newTitle) override
    {
        juce::Component::setTitle (newTitle);
        m_button.setTitle (newTitle);
    }

private:
    juce::ToggleButton m_button;
};

m_customButton.setTitle ("abc"); // Title is forwarded to child - screen readers are happy!

Currently we only really need this for titles, but it’d be great if the other accessibility setters were virtual too to allow for the same behaviour as I’m sure we’ll run into this again at some point!

Alternative solution might be to have some sort of callback mechanism to allow components to be informed when their title has changed, e.g. Component::titleChanged() - however that would mean bloating the interface of Component with even more methods so is not as neat a solution IMO.

In other use-cases, I can see this being useful for error-checking accessibility strings on ‘normal’ widgets:

class MyButton : public juce::Button
{
public:
    void setTitle (const juce::String& newTitle) override
    {
        jassert (newTitle.isNotEmpty());
        jassert (spellCheck (newTitle));
        jassert (! containsProfanity (newTitle));

        juce::Component::setTitle (newTitle);
    }
};