It could be a matter of what happens when.
When the child components are created it’s usually in the constructor.
If you access the lookAndFeel in the constructor of main or a child component, your specialised LookAndFeel is not yet set.
Nevertheless I would advise against putting information in the LookAndFeel. It is designed to be stateless, only drawing code that can be used by any component.
Every Component has a NamedValueSett that you can use using getProperties()
You can add your data there, and in the draw methods you usually get a reference to the component to read the information.
And it has also the benefit that you don’t need the dynamic_cast.
Thanks for this interesting information @Daniel very kind of you.
I think what I’m trying to ultimately achieve here is the ability to have a bunch of these extended-LAFs a bit like how there’s LookAndFeel_v2/3/4 etc. The purpose being to change the lookAndFeel in one place and have it propagate through the apps UI. In that sense these extended-LAF may store options for colours, button styles, and also how much time I want UI things to animate/fade for.
MyLookAndFeel should be a valid implementation derived from MyComponent::LookAndFeelMethods. You can also just implement it in the LookAndFeelMethods and not make it pure virtual.
This guarantees that you always have a lookAndFeel that satisfies your API and you don’t need to cast everytime.
I can share with you the solution I chose in PluginGuiMagic:
The LookAndFeel uses the findColour mechanism. That looks first on the component itself if that colour was set and only if it’s not set it looks up in the LookAndFeel (after figuring out the current LookAndFeel via Component::getLookAndFeel()). So my system makes sure the right colour is always set to the Component directly.
The GUI in PGM is completely dynamic, so when setting the hierarchy and layout machines it also resolves the selected colours and other styling annd layout attributes in a CSS manner and sets them directly on the Component.
That way there is no runtime overhead you can use the original LookAndFeel just like your own (with the exception of the PopupMenu in ComboBox, that needs fixing in the LookAndFeel to use the new targetComponent).