cxhawk
February 17, 2010, 11:00pm
1
It’s a very good feature to have a text entry box for slider. But this box does not work with two valued slider. I found you only need to override two functions to make it work:
void Slider::labelTextChanged(Label* label)
{
const String text = label->getText();
int index = text.indexOfChar(T(','));
if(index>0)
{
const String low = text.substring(0, index);
const String high = text.substring(index+1, text.length());
setMinValue(low.getDoubleValue());
setMaxValue(high.getDoubleValue());
updateText();
}
}
const String getTextFromValue(double value)
{
String text;
text.printf(T("%.0f,%.0f"), getMinValue(), getMaxValue());
return text;
}
However, the labelTextChanged in Slider is not virtual so I cannot override it. Is it possible to add this small feature? Thanks.
jules
February 18, 2010, 10:18am
2
?? It’s already virtual - it’s part of the LabelListener interface…
cxhawk
February 19, 2010, 6:49pm
3
But the Slider class override it with a non-virtual one. Does this work in C++?
jules
February 19, 2010, 10:23pm
4
It’s impossible to ‘unvirtualise’ a method! Any method that overrides a virtual method is by definition virtual, you don’t need to use the keyword.
kcp63
October 17, 2022, 11:26pm
5
Necro in case anyone is searching for how to do this (which is how I got to this thread)
slider.textFromValueFunction = [&](double v) { return juce::String(slider.getMinValue()) + ", " + juce::String(slider.getMaxValue()); }; // Defines textbox value
You can then force the textbox to refresh when slider value changes:
slider.updateText(); // Forces textbox refresh
2 Likes