I am working with a PopUpMenu and have done various ways of doing this but can't seem to get it just right. All in all, I would like:
- PopUpMenu
- Appears on Mouseover of a specific button
- Disappears on mouseleave of parent component of button
- The popupmenu is outside parent component of button
I got the furthest using a timer every 500ms to ping the button to see isMouseOver() and to see if the popupmenu is a nullptr. If the popumenu is a nullptr, then I create it (the popupmenu is a scoped pointer) and show it (have tried all four methods). This at least satisfies the appearing on mouseover of a specific button.
The problem is that no matter which method I use like showMenuAsync, it doesn't clear and set the menu to nullptr. I have to actually press a button on the menu to get it to close. One thing I tried to do was:
void classClassy::timerCallback() { if (addImgButton->isMouseOver() && m_AddImgButtonList == nullptr) { m_AddImgButtonList = new PopupMenu(); if (m_AddImgButtonList != nullptr) { juce::PopupMenu::Options m_options; m_options.withTargetScreenArea(juce::Rectangle<int>(100,100,600,600)); m_AddImgButtonList->addItem(1, "cats", true, false); m_AddImgButtonList->showMenuAsync(m_options, ModalCallbackFunction::forComponent(popupMenuFinishedCallback, this)); } } else if (m_AddImgButtonList != nullptr && isMouseOverOrDragging()) { m_AddImgButtonList->clear(); m_AddImgButtonList = nullptr; } } void classClassy::popupMenuFinishedCallback(int result, BottomMenuComponent* thiscomponent) { thiscomponent->closePopUpMenu(); thiscomponent->repaint(); } void classClassy::closePopUpMenu() { if (m_AddImgButtonList != nullptr) { m_AddImgButtonList->clear(); m_AddImgButtonList = nullptr; } }
How would I go about doing this properly?