Small inconsistency in mouse position in popupmenu

I’m trying to make the PopupMenu more touchscreen friendly. Currently, when we open a PopupMenu after a click or touch on a button, the menu shows up, and the item below the mouse cursor is highlighted (if there is one, it depends on how the popupmenu fits in the screen). If that item is a submenu item, then the submenu also shows up immediately. This is the behaviour that I am trying to change as it seems inconvenient. I have a large menu on a small ipad screen and I want to open submenus only when I click on them.

While doing that, I noticed that the mouse position reported by MouseSourceState in juce_PopupMenu has a rounding issue:

MouseSourceState::handleMouseEvent calls handleMousePosition (e.getScreenPosition());


MouseSourceState::timerCallback() calls source.getScreenPosition().roundToInt()

On my ipad source.getScreenPosition() returns coordinates like ‘184.5 121.5’, which are then rounded to 185 and 122 while e.getScreenPosition() returns 184 and 121.

It can be fixed by replacing e.getScreenPosition() with source.getScreenPosition().roundToInt().

I don’t think it has an impact on the current PopupMenu code, but if one is trying to detect mouse moves by checking for a change of coords in MouseSourceState::handleMousePosition , this will definitively trigger a fake mouse move detection.

1 Like