Label texteditor colour


#1

I just noticed that when you click on a label it creates a textEditor and the text in that editor (once you type some) is black (regardless of the lookAndFeel colour settings).

If selected, it changes to the proper TextEditor highlightedTextColourId colour, but then goes back to black if you start typing.
Once the label loses focus it goes to the Label::textColourId of course.

Anyway, that’s different from how textEditors behave and seems kinda wonky.

Here’s what I have in my LookAndFeel class. Let me know if there is some colour I am missing that would override that white.

setColour(Label::textColourId, Colours::greenyellow); 
setColour(Label::outlineColourId, Colours::grey);
    
setColour(TextEditor::highlightedTextColourId, Colours::red);
setColour(TextEditor::highlightColourId, Colours::darkgrey);
setColour(TextEditor::textColourId, Colours::greenyellow);
setColour(TextEditor::backgroundColourId, Colours::black);

#2

Ok - here is the ISSUE and FIX:

TextEditors that are created from Labels don’t get all the proper color (err … colour) info from the Label’s set LookAndFeel. So, if I override the drawLabel method in my lookAndFeel class I can change this colour.

In other words … simply doing:


myLookAndFeel::myLookAndFeel() 
{
     setColour(TextEditor::textColourId, Colours::greenyellow);
}

does NOT propagate to textEditors created from Labels that have inherited that style.

Instead we use a hack …

[code]
void StyleSheet::drawLabel (Graphics& g, Label& label)
{

// HACK !!!!
label.setColour (TextEditor::textColourId, Colours::greenyellow);

… now it works

}[/code]


#3

Why not using a TextEditor in the first place? you can configure it to look like a label and basically you’re done, right?


#4

Thanks for this fix Aaron, this issue was driving me insane.


#5

Just found this post after coming onto this problem again. Wow … so weird to search the forum and find the answer in your own post, eh?

Jules - what about adding something to get the Label’s textEditors to use the DefaultLookAndFeel ?


#6

Sorry, don’t understand what you mean…?


#7

So … if you specify TextEditor colors in a LookAndFeel object, and then set that LookAndFeel as the default for a project, then create a label, you will notice that the textEditor created by the label (when it is double clicked on) does NOT use the specified LookAndFeel.

Similarly, some elements created by various custom dialogs (file browsers, etc) don’t use certain LookAndFeel Colors that you would expect them to use (the file browser created from the PluginBrowser object is one).

I’ve fixed this where I could in my LookAndFeel class with things like:


void StyleSheet::drawLabel (Graphics& g, Label& label) {
     
    label.setColour (TextEditor::textColourId, findColour(TextEditor::textColourId));

And also by setting the LookAndFeel of dialog boxes after creating them.

But really - they should default to using the “default” look and feel.


#8

No, not true - it definitely does use the normal l+f. But it does inherit any expliticly-specified colours from the label, so that it matches it. Have a look at Label::createEditorComponent(), and maybe override that if you want to avoid those colours being inherited.


#9

No, let me rephrase this …

In the constructor for Label(), it sets some colours …

from juce_label:

    setColour (TextEditor::textColourId, Colours::black);
    setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
    setColour (TextEditor::outlineColourId, Colours::transparentBlack);

This is annoying, since it makes it impossible to set the default color for the textEditors that are created by Labels (the text is always black). Couldn’t you use findColour() instead, and set Labels to create textEditors with the default Texteditor textColour?


#10

That wouldn’t really work, because if needs to override the colours in the default l+f… Why not call Component::removeColour() to clear those from your label?


#11

Yeah, there are a bunch of ways to do it individually, on each Label.
There really should be a way to set the textColor globally though, right?

Overriding it in the default l+f currently doesn’t work either, since it literally specifies Colours::black in the Label constructor.

What if you made the Label constructor use the default l+f instead of Colours::black, then it would be easy enough to specify the Color in the default l+f, yeah?


#12

Well, there’s only one default l+f globally, but the label wants its text box to have a different background colour to the default one (i.e. it wants it to match the label’s background colour).


#13

No no … we’re not talking about the background colour … that does match (the Label BG, as it should).

But the TEXT colour does not. Text colours in Label created textEditors are always BLACK! Which is annoying if you are doing a dark background color scheme!

just sayin’


#14

Hi Aaron, you need to set textBoxTextColourId - take a look inside createSliderTextBox().


#15

I wasn’t actually talking about Slider related textboxes, just ones created from a normal Label.

But yeah, I see that the slider related Labels and Textboxes use the TextBoxColour Ids (as one might expect).

Uncustomized Labels however, do not.

Really, it doesn’t matter much to me, I have this working by overriding a bunch of LookAndFeel methods.

But for the novice, it seems confusing that you can specify every Label and TextEditor related colour, and still get black text when you edit the label. I know it took me a long time to figure out how to override that when I first looked at it.

Anyway, no worries.


#16

So which looks and feels need to be overridden? Just DrawLabel? Because that hadn’t solved if for me. It looks like the drawing of the text is done in the TextEditor when it’s being edited, as it has to break text up into regions of contiguous style (i.e. selected vs unselected parts). I tried hacking that a bit but hopefully you’ve got an easier way Aaron?


#17

Just wanted to chime in that I just encountered this problem, and found this thread, so Jules, would be good if you take a look, seems to be a common point of confusion. Just to clarify what the problem is, if you create a Label that has been .setEditable (true, false, true), when you click the Label, the resulting editor’s text is always black. Confused me for a good half an hour.


#18

Yeah, just overriding drawLabel as shown further up in this thread will solve this. Not so elegant, but hey.


#19

Bump!  I was just driving myself round in circles trying to figure out what I'd done wrong. This could use a fix maybe?


#20

Is there really a bug that needs fixing here? Some people will want to be able to specify a different colour for the text when it's being edited, so having two text colour settings doesn't seem like a problem to me.

e.g.

        label.setColour (Label::textColourId, Colours::red);
        label.setColour (TextEditor::textColourId, Colours::blue);

..would give you a red label that changes to blue text when edited.

I guess I could add some extra logic to see whether a TextEditor::textColourId colour has been specified, and to default to the label colour if not, but it all gets a bit hairy because there are per-component and per-lookandfeel colour settings, so someone may want to use the editor colour that's specified by their L+F, but still want to override the label colour in the component.