Hi everyone,
I have observed this weird behavior when trying to set the background color of a TextEditor to what is written in it and the text color to either white or black to be readable (example: if you type “#00F” the background should change to blue and the text color should change to white, whereas if you type “#FFFFFF”, the background should change to white and the text color should change to black). It appears as if any change to the text color made with a call to “editor.setColour(TextEditor::textColourId, …);” affects only the latest character.
I use this rule for the text color:
if (c.getLightness()>0.7) {
editor.setColour(TextEditor::textColourId, Colours::black);
} else {
editor.setColour(TextEditor::textColourId, Colours::white);
}
When I type “#FFFFFF”, I get a black #, white FFF, black FF, white F. I wasn’t aware that multi-colored text is even possible…
There’s a workaround, but it’s kind of ugly:
editor.setText(“”,dontSendNotification);
editor.setText(text,dontSendNotification);
Is there a better way to do this?