Roland1
December 20, 2019, 11:43pm
#1
Can we get ComponentListener::lookAndFeelChanged
please?
I want to write a class that performs updates every time a look and feel changes. So I need to monitor hierarchy changing (which I can do) and LookAndFeel changing (which I can’t do without Inheritance, but I can’t use inheritance because my object may already inherit from Listbox, Button, etc).
what about some hacky thing like this:
struct LnFChecker : Timer
{
struct Listener {
virtual ~Listener() { }
virtual void lookAndFeelChanged(LookAndFeel_V4* newLookAndFeel) = 0;
};
ListenerList<Listener> listeners;
LookAndFeel_V4* lnf = nullptr;
Component* compToMonitor = nullptr;
void timerCallback() override
{
if( compToMonitor )
{
auto* lookAndFeel = compToMonitor->getLookAndFeel();
if( lookAndFeel != lnf )
{
lnf = lookAndFeel;
listenerList.call([](Listener& l) { l.lookAndFeelChanged(lnf); });
}
}
}
};
set the timer hz to whatever you need… It’s possibly a nice bandaid fix…
Can you just use the Component::lookAndFeelChanged() and/or Component:: sendLookAndFeelChange() methods ?
https://docs.juce.com/master/classComponent.html#a74af5830b815f6f985768a5673d01cf2
Instead of a ComponentListener ?
Rail
yfede
December 23, 2019, 11:41am
#4
Perhaps adding a std::function <void ()> onLookAndFeelChange
member to Component could suffice for your purposes?
Maybe that could find a faster route for integration in the JUCE codebase