Skip to content

Commit 3251044

Browse files
committed
Add child only after the parent has been fully constructed
1 parent 7a4dea6 commit 3251044

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

complete/tremolo_plugin/include/Tremolo/MessageOnClick.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ class MessageOnClick : private juce::MouseListener {
66
MessageOnClick(juce::Component& topLevelComponent,
77
juce::Component& clickTarget,
88
juce::String messageOnClick)
9-
: target{clickTarget}, message{std::move(messageOnClick)} {
9+
: parent{topLevelComponent},
10+
target{clickTarget},
11+
message{std::move(messageOnClick)} {
1012
popup.setAllowedPlacement(juce::BubbleComponent::BubblePlacement::below);
1113
popup.setAlwaysOnTop(true);
12-
topLevelComponent.addChildComponent(popup);
1314

1415
message.setColour(
1516
CustomLookAndFeel::getColor(CustomLookAndFeel::Colors::paleBlue));
@@ -24,11 +25,15 @@ class MessageOnClick : private juce::MouseListener {
2425

2526
private:
2627
void displayPopup() {
28+
// only the first call to addChildComponent() has an effect
29+
parent.addChildComponent(popup);
30+
2731
if (!popup.isVisible()) {
2832
popup.showAt(&target, message, 0, true);
2933
}
3034
}
3135

36+
juce::Component& parent;
3237
juce::Component& target;
3338
juce::AttributedString message;
3439
juce::BubbleMessageComponent popup;

0 commit comments

Comments
 (0)