PopupMenu Text colour

Hi all!

I am trying to change the text colour of the PopUpMenu of my ComboBox. What I did is simply

myComboBox.setColour(PopupMenu::textColourId, findColour(myColourId)); 

But is there a similar way to change the text colour of all the SubMenus of the RootMenu of the ComboBox?

They should also obey the colours set to the LookAndFeel. In the juce LookAndFeels the PopupMenu of a ComboBox only follows the LookAndFeel, not the ComboBox it is targeting, see here:

You can find fixes in the various posts in that thread where I worked around it, but they all involve patching the LookAndFeel to get the colour from the targetComponent rather than from the LookAndFeel.findColour().

This is the crucial function to add and to use:

1 Like

Further to what Daniel said, there’s an example of a LookAndFeel which extracts colour information from the PopupMenu’s target component in the WidgetsDemo:

The important bit is to override the WithOptions version of the look and feel method, after which you can call findColour on the target component, if it is set.

1 Like

Ohh sorry! You’re right @daniel !

I was using your Foleys Look and Feel and I was trying to change the colours of the submenus, making them equal to the parent menus, by simply calling that:

Now I get that in normal situations (using the standard juce LookAndFeels) this wasn’t possible.
Just to clarify and learn from your suggestion.
By overriding the draw withOptions method, I can get the targetComponent() (that in my case is the ComboBox) and so get the targetComponent → findColour(ColourId) colour, that I can use to draw -text, separators, background- colours ?

Thank you very much @daniel and @reuk !

Exactly. Originally the PopupMenu didn’t have the PopupMenu::Options, so there was no way to communicate things like the targetComponent to the LookAndFeel.
To avoid breaking existing code the drawPopupMenu* methods were kept, but future LookAndFeels have now access to the Options struct.

1 Like

Thank you @daniel !

But… what happen to the submenus? Because this works fine with the root menu of my combo box, but not with the submenus of the rootmenu