Suggestion: Make slider popupdisplay sticking to sliderknob possible

UPDATE: I ended up figuring out how to achieve something similar with BubbleMessageComponent. If anyone ever ends up finding this and needs something similar, here you go

In my Level2Editor.h:

void sliderValueChanged(Slider* slider) override;
void showBubbleMessage(Slider* slider);

std::unique_ptr<BubbleMessageComponent> popupDisplay;
Component* popupParent;

In my Level2Editor.cpp:

Level2Editor::Level2Editor(AudioProcessor& p, Component* parentForPopup) : processor(p),

    popupParent = nullptr; // am I doing this right?

void Level2Editor::sliderValueChanged(Slider* slider)

void Level2Editor::showBubbleMessage(Slider* slider)
    popupDisplay.reset(new BubbleMessageComponent(0));
    int sliderTop = slider->getY();
    int sliderX = slider->getX();
    int sliderPos = slider->getPositionOfValue(slider->getValue());
    int x = slider->isHorizontal() ? sliderX + sliderPos : sliderX + slider->getWidth() / 2;
    int y = slider->isHorizontal() ? sliderTop + slider->getHeight() / 2 : sliderTop + sliderPos;
    Point<int> pos(x, y);
    AttributedString text(String(slider->getValue(), 2) + slider->getTextValueSuffix());
    popupDisplay.get()->showAt(Rectangle<int>(25, 25).withCentre(pos), text, 300, false, false);

Please let me know if anything above is bad practice.

Original Post:


for a project where only the sliderknob is visible I needed the popupdisplay to stick to it, since I can’t extend the Slider class though I couldn’t implement it.
I did try it by directly editing the Slider class though, this is what it looked like, not sure if this would be the correct way, it works for me though:

This is inside the PopupDisplayComponent struct which is inside the Pimpl class.

void updatePosition (const String& newText)
    text = newText;
    //BubbleComponent::setPosition (&owner);
    int sliderTop = owner.getY();
    int sliderX = owner.getX();
    int sliderPos = owner.getPositionOfValue(owner.getValue());
    int x = owner.isHorizontal() ? sliderX + sliderPos : sliderX + owner.getWidth() / 2;
    int y = owner.isHorizontal() ? sliderTop + owner.getHeight() / 2 : sliderTop + sliderPos;
    Point<int> pos(x, y);
    BubbleComponent::setPosition(Rectangle<int>(25, 25).withCentre(pos));

I apologize if this has been suggested before, I’m quite new to Juce.