Button loses buttonOverState unexpectedly

The scenario is this, the mouse is over a button, the button state changes to buttonOver in Juce code, when my own code detects the state change it loads up a popup menu. (You can imagine the intent, mouse goes over button, pop up menu displays, mouse moves away, popup menu disappears). The only problem is as the popupmenu displays, it must be taking the focus away from the button as temporarily the buttonstate will change to buttonNormal, I’d like to make use of that state change to detect when the mouse is genuinely not over it and close the popup menu. As things are the popup menu blinks in and out of existence. I can probably make do by using the mouse directly but I’d like to keep things neat and tidy.

Long question cut short, how do I tell a button to keep hold of the mouse focus regardless of popup menu displaying?

Edit: Come to think of it, this is expected, the popup menu functions by knowing it has focus, and when it doesn’t, it will close itself. I ended up simply subscribing to desktop mouse notifications, I also sent through my own callback object to know for sure when the menu weren’t active. I found it a little weird that the popup menu code deleted that object, I would have preferred if it were simply an interface so my parent object could simply be notified. But it works now.

The thing is, popupmenu’s are an independent child-window of the parent-window - meaning they are independent windows in, and of, themselves, and have their own event loop, which goes away once the window (popup-window) is dismissed. There’s no really ‘sane’ way to handle this from the perspective of the UI framework - but you’ve found a workaround. My advice though, would be to avoid popupmenu’s going forward, and replace them with a scrolling/sliding component which resizes within the geometry of the parent UI, since … popupmenu’s are not really a great user experience on touch-based platforms… going this route provides you with cleaner code, and improves on the overall user experience, also …