Popup menu position

I’m not sure how much influence Panorama X has on this issue or whether it’s dictated purely by the OS, but it’s an irritation nonetheless (Panorama X .b25 under macOS 10.13):

When using popupbutton or popupbelowbutton (which, as far as I can tell, are identical statements), the resulting popup menu is centred vertically (approximately) on the position of the button. Another pair of apparently identical statements is popupclick and popupatmouse, both of which effectively do the same as popupbutton and popupbelowbutton, assuming the mouse pointer has not moved between the clicking of the button and the statement generating the menu. If the menu is long enough, and the button is close enough to the top of the screen not to be able to accommodate half the height of the menu above it, the bottom part only of the menu is displayed, with a scroll arrow at the top to show the remainder.

I would have expected both popupbutton and popupbelowbutton to position the top of the menu either over the button (either level with the top of it or with the top edge of the menu centred on it), and popupclick and popupatmouse to place the top LH corner of the menu at the mouse pointer, or perhaps to centre the first item on the Y-co-ordinate of the pointer. Failing that, I would have expected the menu to drop down from the top of the screen rather than attempt to extend above it, thereby necessitating a truncation and an upward scroll arrow. Unless the menu is longer than the entire height of the screen, truncation and scroll arrows ought not to be necessary.

The best workaround I have found for this is to find the screen rectangle of the button pressed, convert that to window co-ordinates and use its bottom-left co-ordinates to position the menu immediately below the button:

let ButtonRectangle=xytoxy(info("buttonrectangle"),"s","f")
popupbynumber Menu,rbottom(ButtonRectangle)+8,rleft(ButtonRectangle),"",Result

(the ‘+8’ is to stop the menu part-covering my particular buttons) — but that seems a rather cack-handed approach when there are built-in statements which, I feel, ought to behave in a similar way.

If the button is very close to the bottom of the screen, the above code results in the menu automatically positioned entirely above the button, which is good, and if it’s fairly close to the bottom it appears in the position specified, truncated at the bottom with a downward scroll arrow. That is all consistent with the behaviour, for instance, of the ‘Action’ menu in the Finder toolbar, which also positions the whole menu below the ‘Action’ button when it can. That suggests to me that this is ‘standard’ Apple behaviour for popups, rather than the way that Panorama does it. And, although it would be better if it avoided truncation and a downward scroll arrow unless absolutely necessary, it is still better than the default behaviour of Panorama popups.