I everyboby,
I can’t figure out how to find the way to set sliders range from clicking a Button.
I’m trying to do like a preset Button but as you can see i’m new at programing and i keep missing terms would anybody got a clue? thanks
There’s two ways you can listen to button presses.
The first is to register as a juce::Button::Listener
, like so:
class MyComponent : public juce::Component,
public juce::Button::Listener
{
public:
MyComponent()
{
addAndMakeVisible(m_button);
m_button.addListener(this);
}
private:
void buttonClicked(juce::Button* buttonThatWasClicked) override
{
if (buttonThatWasClicked == &m_button)
{
// Set slider's range here.
}
}
juce::TextButton m_button {"Click Me!"};
juce::Slider m_slider;
};
The second way is to assign a lambda to the button’s onClick
method, like so:
class MyComponent : public juce::Component
{
public:
MyComponent()
{
addAndMakeVisible(m_button);
m_button.onClick = [this]() {
// Set slider range here.
};
}
juce::TextButton m_button {"Click Me!"};
juce::Slider m_slider;
};
As for setting the slider’s range, you can do so by calling setRange
on the slider and passing in the min and max values, and optionally a third argument for the interval:
const auto min = 0.0;
const auto max = 10.0;
const auto interval = 0.1;
m_slider.setRange (min, max, interval);
If you then want to set the slider’s current value, call setValue()
:
m_slider.setValue (5.0);
1 Like
Brilliant! Thanks a lot Jimmi.