Slider popupDisplay questions


#1

This is a nice feature which I’ve only just discovered(I should look at the demo more often!). Is it possible however to have it appear like a tooltip when the user hovers over the slider? Picture the scenario, you don’t have any text boxes to display the values of your sliders but you need to see what value it is currently set to. Changing the slider could mess up your settings but in order to see the display popup you must change the slider. Also, is it possible to tweak the position of the popup? And finally, I couldn’t find a lookandfeel method for drawing a custom one? Have I missed it(probably)? Thanks.


#2

Can’t remember offhand how it’s done as regards lookandfeel, but yes, good request about the hover-over.


#3

A fellow Jucer showed me a simple way to achieve the same thing by drawing text in the draw…Slider() LookAndFeel method. Crisis averted.


#4

Was the hover over (display popup) ever implemented?

Cheers,

Rail


#5

It’s nice to have it, some of my users would like to see when their mouse hovers on the component.


#6

I added this functionality a while ago… here are some screen grabs from the commit:

You can just use the new Slider method setShowPopupDisplayOnHover (true) to enable this behaviour

Rail


#7

This is awesome.

I just added this to my plugin and it’s up and running on 3 instances, each with different LookAndFeels. Very cool.

It would be great if this was added to JUCE.

Thank you!


#8

Thanks very much Rail. I’ve successfully added the hover effect.

I think you didn’t inherit the Slider class because the structure of the Slider class is not let you. It would be nice to have it as inherited class (of course, if JUCE library itself comes with that, it’s much nicer). Now I’ll have to update JUCE code when I update JUCE.


#9

I use a local copy of the JUCE modules for my project… It would be nice if this were added to the JUCE code though.

Cheers,

Rail


#10

I’ve noticed one small issue with this in a plugin: when my popup is visible and I cmd-tab to another application, the popup stays in front of everything. Thankfully it goes away properly when my plugin reappears.

It would be helpful if there were a way of setting in invisible if the plugin window is not in front, but I can’t find an event that triggers anything like that in Component. Any ideas?


#11

Aah… I never noticed that before (or had any reports of it)… but I believe I can fix that using a Timer and similar code to TooltipWindow::timerCallback() to check if the mouse is over the Slider.

I’ll try and get to that tomorrow.

Rail


#12

Okay… Here you go:

Derive Slider::Pimpl from Timer

class Slider::Pimpl   : public AsyncUpdater,
                        public ButtonListener,  // (can't use Button::Listener due to idiotic VC2005 bug)
                        public LabelListener,
                        public ValueListener,
                        public Timer

In mouseEnter start the timer:

void mouseEnter (const MouseEvent& /* e */)
{
    if (popupDisplayEnabled && showPopupOnHover)
        {
        PopupDisplayComponent* const popup = new PopupDisplayComponent (owner);
        popupDisplay = popup;
        
        if (parentForPopupDisplay != nullptr)
            parentForPopupDisplay->addChildComponent (popup);
        else
            popup->addToDesktop (0);
        
        popup->setVisible (true);
        
        if (popupDisplay != nullptr)
            popupDisplay->updatePosition (owner.getTextFromValue (getValue()));

        if (showPopupOnHover)
            startTimer (250);    // Use whatever timer value you're happy with, Tooltip uses 500
        }
}

In mouseExit stop the Timer:

void mouseExit (const MouseEvent& /* e */)
{
    popupDisplay = nullptr;

    stopTimer();
}

Add the timerCallback method:

void timerCallback() override
{
    if (popupDisplay == nullptr) 
        {
        stopTimer();
        return;
        }

    Desktop& desktop = Desktop::getInstance();
    const MouseInputSource mouseSource (desktop.getMainMouseSource());

    if (desktop.findComponentAt (mouseSource.getScreenPosition().toInt()) != &owner)
        {
        popupDisplay = nullptr;
        
        stopTimer();
        }
}

Now if you Command+Tab to another app which occludes the Slider the popup will go away… the delay to destroy the popup is dependent on the startTimer parameter.

Rail


#13

Awesome. Thank you so much.

@jules, Any chance we can get this very useful addition folded into JUCE?


#14

Unfortunately, now the popupDisplay disappears when the user moves the slider. This probably has something to do with the mousExit() code?


#15

In mouseExit():

 void mouseExit (const MouseEvent& e)
    {
        if (! (owner.isMouseButtonDown() && e.source.isDragging()))
            {
            popupDisplay = nullptr;
            }

        stopTimer();
    }

and timerCallback():

    void timerCallback() override
    {
        Desktop& desktop = Desktop::getInstance();
        const MouseInputSource mouseSource (desktop.getMainMouseSource());

        if (popupDisplay == nullptr || ! owner.isMouseButtonDown() || mouseSource.isDragging())
            {
            stopTimer();
            return;
            }

        if (desktop.findComponentAt (mouseSource.getScreenPosition().toInt()) != &owner)
            {
            popupDisplay = nullptr;
        
            stopTimer();
            }
    }

Does that help?

Rail


#16

@jules: this would be extremely useful and the code is literally in this forum. You even called it a “good request”. Can you please include it in future version of JUCE?

I can, and will, copy the code for now, but I think it would be better if this was included in JUCE by default. Please?


#17

Sure, I’ll take a look today.


#18

Here’s my 4.3.1 based Slider files if it helps:

Rail


#19

Thanks :smiley:


#20

Hi Jules,

I just tested your commit:

It doesn’t seem to be working reliably in my plug-in (it mostly doesn’t show the popup)… my version also would keep the popup open as long as the mouse was over the Slider.

Cheers,

Rail