How to change the font of a Slider textbox?

I’m trying to change the font of a slider text box. I was expecting to be able to do this by overriding LookAndFeel::createSliderTextBox but that function never gets called.

What is the proper way?

Looks like createSliderTextBox gets called from lookAndFeelChanged, and then only if TextEntryBoxPosition != NoTextBox. Are you setting a TextEntryBoxPosition?

For which SliderStyle is this?

Are you setting a TextEntryBoxPosition?

Yes:

slider.setTextBoxStyle (juce::Slider::TextEntryBoxPosition::TextBoxLeft, false, 40, 20);

For which SliderStyle is this?

juce::Slider::SliderStyle::RotaryHorizontalVerticalDrag

OK, and probably it’s important that setTextBoxStyle gets called before the LAF is applied?

Maybe set a breakpoint in Slider::lookAndFeelChanged and make sure it’s being called, and check what happens when it is called?

May be related to this:

I’ve found that you may need to manually call sendLookAndFeelChange() on the slider to get it to register some appearance changes.

Might be a stupid answer, but why not using the Projucer?

How would the Projucer help with this?

You can use the GUI Editor panel to create and modify your plugin GUI. If you create a Slider component, then on the GUI Editor go to subcomponents, click on the Slider you created and you should see the “font” option, where you chan choose between many different fonts, and I’m pretty sure you can add new ones as well.

Since there is this option available, I wouldn’t suggest using the LookAndFeel class to change font. It’s much quicker this way!

Ah, that is what you meant. Thanks for elaborating.

I’m not using the GUI editor but I like your idea to see how the GUI editor implements this. Unfortunately I can’t find the font option. Am I missing something?

I’m sorry, I thought you wanted to change the font of like a label textbox referred to the slider, not the font of the value number. Didn’t know the “font” field is not available for that. There must be an easier approach to this, using the LookAndFeel class feels so unnecessary, also because I guess you would need that font to be present in every single component.

In my projects, I am changing the font in Slider Textboxes. I took a look into how exactly I am achieving that, since it’s been awhile.

I have a custom LookAndFeel applied to the Sliders, and in that LookAndFeel, I override:

getLabelFont(Label& label)

I then return in that function the desired font. This works, since the textbox part of the slider is actually a Label.

Example: setting this to return “Bradley Hand”:

1 Like

Thank you very much for your input! This is the solution!

I solved it without creating a new lookandfeel class:

juce::Font DefaultTheme::LookAndFeel::getLabelFont (juce::Label& label)
{
    if (dynamic_cast<juce::Slider*> (label.getParentComponent()))
        return Fonts::Raleway::bold();
    return LookAndFeel_V4::getLabelFont (label);
}
2 Likes

Brilliant!