Sub menus opening upwards

It find JUCE to be a bit peculiar with the way it decides how to position sub menus.

Looking at the code it looks like sub menus will open upwards relative to the parent menu item when past the middle of the display:

Here simply replacing that line with y = target.getY() - border; seems to give the more common behavior of always opening sub menus downwards, within screen limits.

What’s the rational behind JUCE’s current behavior?

There’s a dozen different ways you might want a submenu to appear. JUCE can’t implement them all so it chooses a reasonable default.

You can use withPreferredPopupDirection() to customise the behaviour, and/or possibly withTargetScreenArea().

This is specific to submenus, and the solutions you propose do not work in that case.
This behavior is hardcoded and cannot be changed, and is not the common behavior you find on native MacOS or Windows sub menus (and propably most Linux flavors as well).

In fact the problem has already been raised in the past:

And this one with nice illustrations:

Sorry I missed that this is with submenus.

Yes it looks like alignToRectangle is hard-coded to false for sub-menus and so the branch that uses PopupDirection isn’t called: JUCE/modules/juce_gui_basics/menus/juce_PopupMenu.cpp at 2cdfca8feb300fb424002ba2c2751569e5bacb64 · juce-framework/JUCE · GitHub