Thanks @daniel
I should explain what it is a bit more. The code below is the header file for the main component that has a custom RotaryHorizontalVerticalDrag slider component and a series of buttons for each value, represented by the OwnedArray _valueButtons, which is then populated by setValues at instantiation.
class SnapSliderComponent : public Component,
public Button::Listener,
public Slider::Listener
{
public:
explicit SnapSliderComponent(const int);
void resized() override;
SnapSlider& getSlider() { return slider; }
void setValues(Array<float>);
Array<float> getValues(){return _values;};
private:
int _type;
Array<float> _values;
SnapSlider slider;
Label label1, label2;
OwnedArray<PushButton> _valueButtons;
void buttonClicked (Button* button) override;
void sliderValueChanged (Slider * slider) override;
};
The buttons are then created and placed in resized(). The buttons use setValue to change the slider value in buttonClicked(). Additionally, the buttons are looped through to place them in front or behind the pot using the following code:
slider.setValue(button->getName().getDoubleValue());
for (auto* comp : _valueButtons)
{
if(button == comp)button->toBehind(&slider);
else comp->toFront(false);
}
In the same way sliderValueChanged is called to reposition the buttons:
for (auto* comp : _valueButtons)
{
if(String(slider->getValue()) == comp->getName())comp->toBehind(slider);
else comp->toFront(false);
}
The SnapSlider class extends the Slider class and overrides the snapValue function so that values are snapped when the rotary slider is dragged. The getSlider function in the main component returns the address of the slider component which is then used to attach an APVTS parameter during instantiation. An instantiation looks like:
_gainSlider.getSlider().setKnobScale(0.1f);
_gainSlider.getSlider().setKnobBaseColour(Colours::blue);
_gainSlider.getSlider().setKnobDetail(true);
_gainSlider.getSlider().setTextColour(Colours::white);
_gainSlider.getSlider().setTickColour(Colours::transparentBlack);
_gainSlider.getSlider().setSliderStyle(SnapSlider::SliderStyle::RotaryHorizontalVerticalDrag);
_gainSlider.getSlider().setTextBoxStyle(SnapSlider::NoTextBox, true, 0, 0);
_gainSlider.setValues(controller->getGainValues());
addChildComponent(_gainSlider);
p_gainAttachment.reset (new SliderAttachment (_valueTreeState, "gain_" + String(_channel) + "_" + _band, _gainSlider.getSlider()));
_gainSlider.getSlider().addListener(this);
The PushButton class extends the TextButton class simply to adjust the look and feel.
Hopefully, these snippets shed a bit of light on how this all fits together. I have placed breakpoints all over the place and nothing is triggered whenever setVisible is called by parent GroupComponent that holds these sliders.
Thanks for your help.