We’re trying to solve the problem of having Components with custom look and feel methods being implemented in a custom LookAndFeel class without the need to dynamic_cast to our custom type from Component::getLookAndFeel()
every time the component is painted.
E.g. instead of
void paint (juce::Graphics& g) override
{
if (auto laf = dynamic_cast<LookAndFeelMethods*>(&getLookAndFeel())
laf->drawThing(...);
}
we can have
void paint (juce::Graphics& g) override
{
lookAndFeelHandlerObject->drawThing(...);
}
Currently our lookAndFeelHandlerObject
is a templated class that holds a pointer to a nested LookAndFeelMethods
struct that each of our custom components has (similar to how juce components do it). The class privately inherits from Component
and adds itself as a child to our custom components so it can receive callbacks when its look and feel changes (and therefor the parent’s) where it can then update the pointer it holds.
This method is a little hacky as we have to have a Component that’s not actually acting as a ‘real’ component. It would be a lot nicer if we could have it as a ComponentListener
instead but currently there’s no componentLookAndFeelChanged()
callback in ComponentListener
.