I added a label to my GUI and expected to see some text on screen. None appeared.
So I investigated and found some oddities in the juce::Label class
juce::Label
sets up colors like this in the constructor:
Label::Label (const String& name, const String& labelText)
: Component (name),
textValue (labelText),
lastTextValue (labelText)
{
setColour (TextEditor::textColourId, Colours::black);
setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
setColour (TextEditor::outlineColourId, Colours::transparentBlack);
textValue.addListener (this);
}
the Label::paint
function does this:
void Label::paint (Graphics& g)
{
getLookAndFeel().drawLabel (g, *this);
}
The only drawLabel
implementation in the framework is in LookAndFeel_v2, and it does this:
void LookAndFeel_V2::drawLabel (Graphics& g, Label& label)
{
g.fillAll (label.findColour (Label::backgroundColourId));
if (! label.isBeingEdited())
{
auto alpha = label.isEnabled() ? 1.0f : 0.5f;
const Font font (getLabelFont (label));
g.setColour (label.findColour (Label::textColourId).withMultipliedAlpha (alpha));
g.setFont (font);
auto textArea = getLabelBorderSize (label).subtractedFrom (label.getLocalBounds());
g.drawFittedText (label.getText(), textArea, label.getJustificationType(),
jmax (1, (int) ((float) textArea.getHeight() / font.getHeight())),
label.getMinimumHorizontalScale());
g.setColour (label.findColour (Label::outlineColourId).withMultipliedAlpha (alpha));
}
else if (label.isEnabled())
{
g.setColour (label.findColour (Label::outlineColourId));
}
g.drawRect (label.getLocalBounds());
}
Why is the Label
constructor setting the LNF TextEditor
colors and not the LNF Label
colors?