MouseOver juce::Popupmenu custom item

How is the mouseover highlighting suppose to work with a custom items in a juce::Popupmenu? I thought easiest for my purpose of showing an .svg based DrawableComposites is to use a juce::DrawableButton, but this resolves in pretty erratic behaviour. It flickers (looks like even the screen outside my plugin!) and keeps the mouseover state when the mouse is gone or doesn’t change to mouseover when the mouse actually is over.

Is this working at all?

I follow the tradition to soliloquy here a bit:

I tried to simplify the the custom component class and inserted an inherited DrawableComposite, where I overwrote mouseEnter() and mouseExit(). Although I see myriads of contradictionary mouse enter and exit indications when the mouse firstly enters - I don’t see any mouse (exit) indication anymore on mouse exit and re-enter.

So my question remains: Is it working at all? Or shouldn’t I bother?

(Accepted answer include: “Go away, spent your time more wisely!” or anything, but having my continuously soliloquising here makes me feel even more nerdy then already anticipated when using things like “juce”.)

1 Like

You need to subclass PopupMenu::CustomComponent for this so you can query CustomComponent::isItemHighlighted(). Something like this, for example:

 class SVGCustomComponent : public PopupMenu::CustomComponent
{
public:
    SVGCustomComponent()
    {
        if (up != nullptr && down != nullptr)
            drawableButton.setImages (up);

        addAndMakeVisible (&drawableButton);
        setSize (64, 46);
    }

    void getIdealSize (int& idealWidth, int& idealHeight) override
    {
        idealWidth = 64;
        idealHeight = 46;
    }

    void resized() override
    {
        drawableButton.setBounds (getLocalBounds());
    }

    void paint (Graphics& g) override
    {
        if (up != nullptr && down != nullptr)
            drawableButton.setImages (isItemHighlighted() ? down : up);
    }

private:
    ScopedPointer<Drawable> up   {Drawable::createFromImageData (BinaryData::up_svg, BinaryData::up_svgSize)};
    ScopedPointer<Drawable> down {Drawable::createFromImageData (BinaryData::down_svg, BinaryData::down_svgSize)};
    DrawableButton drawableButton {"hey", DrawableButton::ImageStretched};
};
2 Likes

Thanks @fabian,
thats working now! Great!

Some doubts:

  • wouldn’t it be more obvious if a standard component in a standard manner (i.e. mouse over) could be used?
  • shouldn’t addAndMakeVisible() already set the correct size?
  • (mis)using paint() to select the images is a hack, right?

Thanks!