Clicking a button always shows Popmenu

#1

I have a PopMenu that shows when I click a Button. While the PopMenu is showing I want a click on the Button to hide it and not hide first and re-show.

With a CallOutBox this is fairly simple to achieve as you can just use setDismissalMouseClicksAreAlwaysConsumed

CallOutBox* callout = &CallOutBox::launchAsynchronously (contentWidow, r, this);
callout->setDismissalMouseClicksAreAlwaysConsumed(true);

Is there anyway to get the same behavior with a PopMenu?

#2

You could set your button in ‘toggle’ mode and only show the menu when the button is down :

button.setClickingTogglesState (true);

button.onClick = [this]()
{
    if (button.getToggleState())
        menu.showMenuAsync (...);
};

and set your button back in ‘off’ state in your the menu callback :
button.setToggleState (false, dontSendNotification);