Question about drawLinearSlider()


#1

It seems that the height parameter of drawLinearSlider() is never the full height of the slider itself? The method is called from Slider::pimpl::paint(), but sliderRect.getHeight() always seems to be less than the height set using setBounds(). I thought it may have something to do with the textbox, but even when I set no textbox my slider is still too short. For example, I set my vertical slider to be 100 and use setTextBoxStyle() to indicate I don’t wish to have a textbox, but when drawLinearSlider() is called the height of the slider is 82. I’m probably missing something here, and this Is this expected. In which case can someone explain to me why? Cheers.


#2

Hi @Rory,
this is handled in the Slider::LookAndFeel methods, so it depends which look and feel you are using.
I think the default is LookAndFeel_V2, so the code responsible for that can be found here:

You can inherit that class to achieve any behaviour and drawing you like.
So eventually you get an idea there, what the designer of the slider had in mind, when he/she reduced the size by factor 0.9.

HTH


#3

Hi Danny. I’m already overriding these methods in my own look and feel. However, the reduction in height is not done there at all but in the Slider::pimpl::paint method. This is obviously done by design, but it seems a little confusing to me that the height passed to setBounds() is not passed to any of the linear slider’s LookAndFeel methods. Or at least that how it appears to me. Even the JUCE draw linear slider methods compensate by adding extra values to the ‘height’ parameter. It just seems a little counter intuitive.


#4

You are right, it is not really obvious. IMHO it happens here:

So if you change that to

Slider::SliderLayout MyLookAndFeel::getSliderLayout (Slider& slider) override
{
    Slider::SliderLayout layout;
    layout.sliderBounds = slider.getLocalBounds();
    return layout;
}

you should be fine…


#5

That’s the one Daniel! Thanks very much for taking the time to look into it for me. Much appreciated.