Search guides and the APICtrl K
  1. API reference
  2. Native GUI

gfx/popup.h

PopupMenu: a list that opens over everything, takes the mouse, and closes on the next click wherever it lands.

#include <sonore/gfx/popup.h>
On this page

Design notes

Why this is two objects

PopupMenu is a list of items with no window and no platform in it. Content is a Component that draws that list and says which item a point is over. Both can be checked with a Bitmap and no window at all -- which matters more here than anywhere else in the native UI, because a popup is the one control a person cannot inspect while it is open: the moment they alt-tab to look at it, it dismisses.

The window, the grab and the dismissal live in the peers, and they are the only part that needs a display to test.

What a popup has to get right

It must sit above everything, including the host's own window, which means a top-level override-redirect window rather than a child. It must hold the mouse until it is dismissed, or a click meant for the menu goes to whatever is behind it. It must close on a click ANYWHERE, including outside itself and outside the plugin. And it must fit on the screen: a menu opened near the bottom edge that runs off it is a menu whose last items cannot be reached.

Types 2

The list itself: no window, no platform, no drawing.

id is what a caller gets back, and zero is reserved for "dismissed" as it is everywhere -- a menu whose items start at 1 can tell "nothing chosen" from "the first item", and one that starts at 0 cannot.

class PopupContent : public Widget

The menu as a Component.

Owns nothing: the PopupMenu it draws must outlive it, which the peers arrange by keeping both in the same object.

↑↓ to move↵ to openEvery public name in the headers, and every guide