Hello to all,
I'm a beginner at both Juce and C++, learning C++ thru Stroustrup's "PPP", and Juce thru Robinson's "Getting started with Juce".
So far so good, I slowly progress, and it's very rewarding.
Learning the basics of GUI, I train by creating small GUIs, and I have a problem when I try to break in several custom subcomponent a GUI.
To simplify:
Let's say I have two custom classes of components:
-FirstComponant (inherits Component), has a private Button member: button
-SecondComponent (inherits Component), has a private Label member: label
I'd like that the button member of FirstComponent, when clicked, would write "button from FirstComponent was clicked" on the label member of SecondComponent, regardless of the hierachy of the above components themselves, i.e.:
case A: ThirdComponent contain one instance of FirstComponent, and one instance of SecondComponent
case B: FirstComponent contain an instance of SecondComponent
case C: SecondComponent contain an instance of FirstComponent.
If I have both a Button and a Label members of the same FourthComponent, It's pretty clear how to proceed:
-1- FourthComponent should inherit from Button::Listener. It can now listen to a Button.
-2- button needs to broadcast toward the FourthComponent class: this is the method addListener(this)
(which works because FourthComponent is a Button::Listener)
-3- FourthComponent needs to implement at least the pure virtual function that came from Button::Listener:
void buttonClicked(Button * buttonReceived)
{
if (button == buttonReceived) label->setText("button from FourthComponent was clicked", dontSendNotification);
}
done.
In my more general situation, here is what I think should be done but I don't know if it makes sense:
-1- SecondComponent should inherit Button::Listener (so it can listen to the button)
-2- FirstComponent member button should know it needs to broadcast towards the SecondComponent instance.
button->addListener(...)
case A: I don't know how to do it. I need to be able to describe the another class member of the parent Class, most probably a private member.
case B: simply the member of type SecondComponent. But that member is most probably private, right?
case C: I don't know: I need to be able to describe the parent class
-3- SecondComponent should implement the needed pure virtual function:
void buttonClicked(Button* buttonReceived)
problem is: how do I test that buttonReceived is indeed the right one?
case A: I don't know how to do it. I need to be able to describe another class member of the parent Class.
case B: I don't know either: I need to be able to describe the parent class
case C: simply the member of the FirstComponent. But that member is private.
In all cases I'm stuck, I might be totally on the wrong track here, so let me know,
Best regards.