Label texteditor colour

 

Here's a trivial test case, and it's not obvious (from a user of the framework's point of view) why this should result in black text when editing the label:

class MainContentComponent   : public Component

{

public:

    //==============================================================================

    MainContentComponent() {


        LookAndFeel & laf = LookAndFeel::getDefaultLookAndFeel();

        

        laf.setColour(Label::textColourId, Colours::greenyellow);

        laf.setColour(Label::outlineColourId, Colours::grey);

        laf.setColour(Label::ColourIds::backgroundColourId, Colours::darkgreen);


        

        laf.setColour(TextEditor::highlightedTextColourId, Colours::red);

        laf.setColour(TextEditor::highlightColourId, Colours::white);

        laf.setColour(TextEditor::textColourId, Colours::greenyellow);

        laf.setColour(TextEditor::backgroundColourId, Colours::darkblue);

        laf.setColour(TextEditor::ColourIds::focusedOutlineColourId, Colours::yellow);

        

        example = new Label();

        

        addAndMakeVisible(example);

        example->setText("Example", dontSendNotification);

        example->setEditable(true);

        

        setSize (500, 400);

        

    }

    ~MainContentComponent() {}


    void paint (Graphics & g) { g.fillAll(Colours::black); }

    void resized() { example->setBounds(0,0, 300, 20); }


private:

    ScopedPointer<Label> example;

};

 

Maybe it needs a Label::ColourId::textColourWhenEditing?

And on a very minor but related point...

I think there are a couple of cases (SliderLabelComp springs to mind) where the text colours are copied from findColour into the new object when the object is constructed.  It would be best if all objects behaved the same way taking the colours at paint time.

 

I was pleasantly surprised to learn how easy it was to set up a "dark" UI with JUCE, until I ran into this stumbling block.

Isn't it a design exception to limit a custom look-and-feel object from fully controlling the colours of the UI globally? So much effort was put into using the look-and-feel-defined colours consistently elsewhere in the JUCE UI, that this design decision seems a bit off.

In our app, we use label/editors in a number of spots, so it's error-prone to have to remember to clear the colours, and creating a custom label/editor class simply to override createEditorComponent would otherwise be unnecessary if the look-and-feel design worked as expected.

If the text, background, and outline colours need to be overridden in this case, why not simply define three more colours in the look-and-feel for this special purpose?

If three more colours isn't acceptable, surely there's another way to let the look-and-feel be the final authority on colours?

I like the change proposed by bazrush, which keeps the look-and-feel object as the final authority on all colors in the UI.

So to confirm the details, the proposed change would be something like:

   Label::ColourId::textColourWhenEditing

   Label::ColourId::backgroundColourIdWhenEditing

   Label::ColourId::outlineColourIdWhenEditing

With the next version of Mac OS X officially supporting a "dark" UI, this is a good time to make it easier than ever to implement a dark UI in JUCE.

We have a dark UI, and stumbled over this as well. Currently we have to remember to override the colour for TextEditor::textColourId in every single place where we create an editable label. But for instance, changing

setColour (TextEditor::textColourId, Colours::black);

to

setColour (TextEditor::textColourId, findColour (Label::textColourId));

in the Label constructor would avoid this requirement.


--
Roeland

I'm struggling to find the time to plough through all the stuff in this thread and summarise what should happen.. Could someone give me a quick TL;DR !

Jules - I think we are saying implement these (see David's mail): 

 Label::ColourId::textColourWhenEditing

 Label::ColourId::backgroundColourIdWhenEditing

 Label::ColourId::outlineColourIdWhenEditing

So you can do: 

Label label; 

label.setColour(Label::ColourId::backgroundColourIdWhenEditing, Colours::black); 

label.setColour(Label::ColourId::textColourWhenEditing, Colours::green);

label.setColour(Label::ColourId::outlineColourIdWhenEditing, Colours::purple);

And the text editor uses the colours when you click on the label.

Does that help? 

Ok.. so I'm still struggling a bit to see the point of this, but if I understand correctly, you want those extra colour IDs, and then something like this to use them?

TextEditor* Label::createEditorComponent()
{
    TextEditor* const ed = new TextEditor (getName());
    ed->applyFontToAllText (getLookAndFeel().getLabelFont (*this));
    copyAllExplicitColoursTo (*ed);

    if (isColourSpecified (textWhenEditingColourId))
        ed->setColour (TextEditor::textColourId, findColour (textWhenEditingColourId));

    if (isColourSpecified (backgroundWhenEditingColourId))
        ed->setColour (TextEditor::backgroundColourId, findColour (backgroundWhenEditingColourId));

    if (isColourSpecified (outlineWhenEditingColourId))
        ed->setColour (TextEditor::outlineColourId, findColour (outlineWhenEditingColourId));

    return ed;
}

Bump! Anyone try this suggestion?

Ok - just figured out what you're talking about. So that function copies whatever colours are specified in the Label to the Text editor when it's first created.  Sounds great :) 

Ok - have checked in what I did - let me know if it does the job!

Jules - how can we use this with a custom look and feel (rather than by setting the properties for a specific Label)? I've defined the new colourIds in my LookAndFeel but the isColourSpecified() calls in Label::createEditor() are returning false.

Looking at this again, I see two options for the code inside Label::createEditor():

  1. make the conditional checks (isColourSpecified(x) || getLookAndFeel.isColourSpecified(x))
  2. remove the conditional checks and define defaults for the 3 new colour Ids in juce::LookAndFeel

I think it needs to do an additional check if the colour is set in the current LookAndFeel (it only checks this particular label). That way you can specify the colour once in your LookAndFeel.

The point is that you don't need to specify an explicit colour for every editable label like this:

addAndMakeVisible (label1 = new Label ("new label", "text"));
label1->setEditable(true, true, false);
label1->setColour (TextEditor::textColourId, Colours::white);

...

addAndMakeVisible (label2 = new Label ("new label", "text"));
label2->setEditable(true, true, false);
label2->setColour (TextEditor::textColourId, Colours::white);

...

addAndMakeVisible (label3 = new Label ("new label", "text"));
label3->setEditable(true, true, false);
label3->setColour (TextEditor::textColourId, Colours::white);

...

--
Roeland

Roeland, I think both of my suggested solutions achieve this.

Ok, try again now..

Works for me. Thanks Jules.