FR: getLabel for Sliders

I know this has been requested multiple times before, but for easier customization, it would really help to get direct access to a reference (or pointer) of the label used by the slider.

Or maybe make the existing pointer public?



and BTW Slider (simple) feature requests

Yep, those are all sensible requests (but only because the Label is already exposed via the interface - the standard response is that we never expose implementation details without a very good reason). I’ll add these to the backlog, but no promises about a timeline.

I know I’m waking the zombies, but I can’t second this request enough. Even if it were just something like const juce::Label* Slider::getLabel() that would still be an improvement.

As an example of why, I was trying today to adjust the width of my slider’s text box automatically so that it would always fit the smallest and largest values of the slider (including units) without squashing them. This slider is just a vertical bar style with everything that’s not text set to be transparent. I want to find a minimal width because I have to fit several of them into a tight space.

To get the font that the slider will use, I call LookAndFeel::getLabelFont(Label& label). Unfortunately, I don’t have access to the label, so I create a dummy label and pass it to the slider’s look and feel. Alternatively, I can call createSliderTextBox(Slider& slider), but this then requires freeing when I’m done.

Once I have the font, I can then use getStringWidthFloat() on my min and max value strings and then take the max of that. From there, I can take the ceiling of that, and then use that to set the width of the slider’s textBox using Slider::setTextBoxStyle.

Unfortunately, the text still gets cut off, because Label automatically adds a Bordersize of {1, 5, 1, 5} around the text box in its constructor. I found this after a bit of head scratching. Once you add that and an extra pixel, it will work.

I know that I could implement this using LookAndFeel to get access to the label, but this feels clunky. LookAndFeel is a big class relative to the size of the thing I’m trying to do and I’d prefer not to keep around a slightly different version of a LookAndFeel just to do something like changing the justification of the label when I want to have two sliders next to each other with their labels right and left aligned respectively. I’d run in to the same thing if I wanted to have the font of the focused slider have its font in bold. (and would have to make sure that the LookAndFeel didn’t get used on ordinary labels)

I definitely appreciate the goal of keeping users away from places where they can needlessly shoot themselves in their feet, but I really hope that you’ll reconsider the access level here.


It’s hard to believe this is still not available. Not to mention, there should be access to the TextEditor that gets created when you edit the value in the Slider TextBox. Somewhat related:

I can second that working with this automatic label added from the Slider is a pain. I just wanted to change the font size of the label to allow small sizes and it was actually quite complicated considering its actually an easy task.