Colour settings in struct

Hi everyone!

I’m a super beginner when it comes to JUCE and C++.
Could somebody give me some advice if I can color presets instead of hex values in struct (for readability)?

struct CustomDrumPads :juce::OwnedArray<juce::TextButton>
{
    CustomDrumPads () :juce::OwnedArray<juce::TextButton> ()
    {
        enum juce::TextButton::ColourIds
        {
            buttonColourId = juce::Colours::yellow, //How can I use the colour preset here?
            buttonOnColourId = 0xff852963,
            textOffColourId  = 0xfffffaf0,
            textOnColourId   = 0xff555555
        };
    }
};

Thank you for any reply!

Yes :nerd_face:

Yes, you can certainly use those preset colours instead of raw hexes, but I think you might be confusing ColourIds and Colours. The ColourIds are just used for looking up a certain Colour. So, this doesn’t make sense:

buttonColourId = juce::Colours::yellow, //How can I use the colour preset here?

There are multiple ways to set the actual colours used by a Component. One simple way if you have e.g. a TextButton called btn is this:

btn.setColour (juce::TextButton::ColourIds::buttonColourId, juce::Colours::yellow);

which would tell that particular button to be yellow.
Hope this helps a bit!

Thanks chrhaase!

1 Like