Quick question about Label LookAndFeel


#1

Hello to the JUCE team ! Hello @jules !

I have a question about that specific part of juce_Label.cpp :

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

    copyColourIfSpecified (*this, *ed, textWhenEditingColourId, TextEditor::textColourId);
    copyColourIfSpecified (*this, *ed, backgroundWhenEditingColourId, TextEditor::backgroundColourId);
    copyColourIfSpecified (*this, *ed, outlineWhenEditingColourId, TextEditor::focusedOutlineColourId);

    return ed;
} 

I came across a problem one day because I wasn’t able to change the font being used in the TextEditor which is displayed when the Label is editable. I discovered that was because of that function, and because I was using at some point label->setFont() and that what was provided there wasn’t taken into account.

So here is my question : would it make more sense in the JUCE base code to have ed->applyFontToAllText (getFont ()); instead of ed->applyFontToAllText (getLookAndFeel().getLabelFont (*this)); ? To me, the function getFont() always provides the accurate Font being used by the Label, which came from the LookAndFeel definition until it is overrided by Label::setFont, which isn’t detected by the current implementation.

Thanks in advance !
Ivan


#2

getFont() always provides the accurate Font being used by the Label, which came from the LookAndFeel definition

isn’t it the other way around?
the lookAndFeel method can return the label font that you have set using Label::setFont() (as below in LookAndFeel_V2) or something else if you want a different behaviour.

Font LookAndFeel_V2::getLabelFont (Label& label)
{
    return label.getFont();
}

#3

You are right about the look and feel, it’s the other way indeed. I should investigate again my issue, and post a new update there when it’s done…