Force SetColour

Hi,

 

I have a Combobox and when ever it changes i call SetColour (i.e. setColour(TextEditor::textColourId, Colour (0xFF808080));) to change background and text colour on a couple TextEditors (My text editor is a custom class DoubleTextEditor that is based on TextEditor but not much going on inside). But the colour doesnt show untill the value in the TextEditor changes. Is there a way to force Setcolour? i tried repaint and that didnt work and other things. What will cause my SetColour to show without having to change the value. or do i need to hack it so it resets the same value just so it redraws itself and changes the color i set it to?

 

Regards,

Brad

Maybe call lookAndFeelChanged?

The following changes the background but it doesnt update the Text

 

void DoubleEditor::enablementChanged()

{

    if(isEnabled())

    {

        setColour(backgroundColourId, Colour (0xFF000000));

        setColour(textColourId, Colour (0xFFFFFFFF));

    }

    else

    {

        setColour (textColourId, Colour (0xFF808080));

        setColour (backgroundColourId, Colour (0xFF404040));

    }

}

Noob here with a similar issue for my plugin, figured I’d bump. I have a Rec / Stop TextButton to toggle on and off to record an audio stream. Basically, it should say Rec and be darkred when not recording, and say Stop and be black when recording. As J.Hodge would say, hope that’s not confusing!

In my AudioProcessorEditor constructor I call:

    recButton.setColour(0x1000100, Colours::darkred);
    recButton.setButtonText("Rec");

Then I have this function:

void AudioProcessorEditor::buttonClicked(Button* button)
{
    
    if (button == &recButton)
    {
        if (recorder.isRecording() == false)
        {
            recButton.setColour(0x1000100, Colours::black);
            recButton.setButtonText("Stop");
            recButton.onClick = [this](){ recorder.record(); };
        }
        
        else
        {
            recButton.setColour(0x1000100, Colours::darkred);
            recButton.setButtonText("Rec");
            recButton.onClick = [this]() {recorder.stop(); };
        }
    }
}

Weirdly enough I get the opposite result - it changes the text but does not reset the colour.

JUCE documentation states:

Changing a colour will cause a synchronous callback to the colourChanged() method, which your component can override if it needs to do something when colours are altered.

But I’m not sure where to override colourChanged(). If anyone could help that’d be hugely helpful, thanks!

First of all, I would avoid calling the setColour with the hex codes, but rather use the enums.

Buttons have different states and handle colours by themselves. If you set your Button to setClickingTogglesState (true), the it will display buttonColourId and if it is toggled on, it shows the colour set with buttonOnColourId.

So it is sufficient to call in the constructor:

button.setClickingTogglesState (true);
button.setColour (buttonColourId, Colours::darkgrey);
button.setColour (buttonOnColourId, Colours::red);

Since this setColour is in the button namespace, it should work like this. If you have trouble, explicitly mention TextButton’s namespace:

button.setClickingTogglesState (true);
button.setColour (TextButton::buttonColourId, Colours::darkgrey);
button.setColour (TextButton::buttonOnColourId, Colours::red);

It’s always good to have a look at the available ColourIds.

Hope that helps