Slider::setNumDecimalPlacesToDisplay method

I know the suggested method to change the number of decimal places shown in a slider is to use Slider::getTextFromValue(), but for a simple Slider I don’t want to subclass the Slider class and I just want a simple method to change the number of decimal places… so if possible could you please add:

void Slider::setNumDecimalPlacesToDisplay (int numDecimalPlacesToDisplay)
{
    pimpl->numDecimalPlaces = numDecimalPlacesToDisplay;
    
    updateText();
}

A recent commit (bug fix to the String class) has changed the number of decimal places Slider is showing to 7, where it didn’t before.

Thanks,

Rail

4 Likes

Thanks Rail, I’ve added this to develop and it should appear on the public repo shortly.

4 Likes

Thanks Fabian!

Cheers,

Rail

Note that when the slider’s range is changed, then the number of decimals is reset to 7 (or something else if you have a range interval) in Slider::Pimpl::updateRange()

So the following does not work :

slider.setNumDecimalPlacesToDisplay (0);
slider.setRange (0., 100.);

setRange() resets it to 7 decimal places…

    void setRange (double newMin, double newMax, double newInt)
    {
        if (minimum != newMin || maximum != newMax || interval != newInt)
        {
           // blah, blah, blah...

           // figure out the number of DPs needed to display all values at this
            // interval setting.
            numDecimalPlaces = 7;

           // blah, blah, blah...

            updateText();
        }
    }

Rail

Just got the same problem…

+1

Still a problem…

Thank you for reporting.

1 Like

I’m having an issue with this when using LinearVertical sliders. No matter what I do, it won’t display 0 decimal places.

These are sliders with APVTS::sliderAttachments. The parameters associated with those sliders have a lambda function to remove the decimal places (String(value, 0)). Also, I tried with and without the line slider.setNumDecimalPlacesToDisplay(0); No luck.

But…everything works fine for rotary sliders.

Bug?

On a side note, it seems wrong that Slider::setTextBoxStyle(Slider::TextBoxBelow, allowEdit, width, height); combines a setting (where to place the textbox) with sizing parameters (width & height). Normally, you want to set the placement of the textbox once upon creating the slider, and leave the width & height parameters to be set in the resize() method. My 2 cents.

Try using the AudioProcessorValueTreeStateParameterAttributes::withStringFromValueFunction() option instead of using Slider::setNumDecimalPlacesToDisplay()

Rail

Tried. No joy.