Hi,
this matter has been discussed in different threads but i can't implement it yet. I have tried a lot of thigs with no success.
The thing is if I have a frame, that contains another frame that contains for instance, 2 sliders...how the hell the upper frame gets the callbacks from the slider events??(slidervaluechange, for instance?)
I attached a simple example I am trying to implement....i feel myself fool
I can't get the slidervaluechange callback in the top. I highly appreciate help with this issue. Maybe it is a c++ misunderstanding or whatever, but i can't solve it.
//************************************************************************TOP.h
class GUI : public Component,
private Slider::Listener,
{
public:
GUI ();
~GUI();
void sliderValueChanged(Slider* sliderThatWasMoved) override;
private:
ScopedPointer<faders> component;
}
GUI (TOP).cpp
//************************************************************************TOP.cpp
GUI::GUI ()
{
addAndMakeVisible (component = new faders());
addAndMakeVisible (component2 = new faders());
addAndMakeVisible (component3 = new buttons());
//Here I have tried lot of methods as...and more.
SOLUTION: component->slider->addListener(this); //if child public, else write a public method to return that pointer.
//my error was trying component->addListener(this) or addCOmponentListener(component) or so. I tried to make the entire child listener instead of single components.
}
//I cant't get this callback called!
void GUI::sliderValueChanged(Slider* sliderThatWasMoved)
{
}
//*******************************************************children.h
class faders : public Component,
public SliderListener
//public Slider
{
public:
faders ();
~faders();
ScopedPointer<Slider> slider; (i have tried both public and private)
ScopedPointer<Slider> slider2;
}
//**********************************************************children.cpp
faders::faders ()
{
addAndMakeVisible (slider = new Slider ("new slider"));
slider->setRange (0, 10, 0);
slider->setSliderStyle (Slider::LinearHorizontal);
slider->setTextBoxStyle (Slider::TextBoxLeft, false, 80, 20);
slider->addListener (this);
addAndMakeVisible (slider2 = new Slider ("new slider"));
slider2->setRange (0, 10, 0);
slider2->setSliderStyle (Slider::LinearHorizontal);
slider2->setTextBoxStyle (Slider::TextBoxLeft, false, 80, 20);
slider2->addListener (this);
//Here I have tried lot of methods as...and more.
slider->addListener(getParentComponent()); //get error...
}
void faders::sliderValueChanged (Slider* sliderThatWasMoved)
{
if (sliderThatWasMoved == slider)
{
}
else if (sliderThatWasMoved == slider2)
{
}
}