Skip to content

UXPopUpButton

UXPopUpButton shows one selected item from a list. Clicking pops a menu of the items, and choosing one selects it. The item list and the selection (by index, tag, or title) are the pure, testable model. Drawing the closed button and running the menu are the backend’s job. Where the popup is native (macOS NSPopUpButton, Win32 COMBOBOX, iOS UIButton+UIMenu, Android Spinner, GTK GtkDropDown), the OS drops the list and reports the pick back. On GEM the driver runs a menu at the button’s bottom-left.

#use <UXKit>
UXPopUpButton* align = new UXPopUpButton();
align.addItem((u8*)"Left", 0);
align.addItem((u8*)"Centre", 1);
align.addItem((u8*)"Right", 2);
align.setAction(&controller.onAlign);
content.addSubview(align, UXGeom.make(8, 8, 120, 24));

The first item added becomes the default selection. The action fires after a pick lands, so the handler reads the current value from the sender:

void onAlign(UXControl* sender) {
i32 tag = ((UXPopUpButton* ?)sender).selectedTag();
...
}
  • Inherits UXControl: the weak: callback action, enablement, the fire path.

Items · addItem · removeAllItems · count Selection · selectItem · selectByTag · selectByTitle · selectedIndex · selectedTitle · selectedTag

void addItem(u8* title, i32 tag)

Appends an item. The tag is yours: a stable id that survives reordering, so handlers use selectedTag instead of the index. The first item added becomes the selection.

void removeAllItems(void)

Empties the list and clears the selection.

i32 count(void)

How many items the list holds.

void selectItem(i32 i)

Selects by index (out-of-range picks are ignored). Programmatic selection does not fire the action.

void selectByTag(i32 tag)

Selects the first item carrying the tag.

void selectByTitle(u8* title)

Selects the first item whose title matches.

i32 selectedIndex(void)

The current pick, -1 when the list is empty.

u8* selectedTitle(void)

The current pick’s title, "" when there is none.

i32 selectedTag(void)

The current pick’s tag, -1 when there is none. This is the id a handler usually wants.

UXPopUpButton on the web backend

The theme’s popup bezel with its disclosure chevron: the same Aristo art GEM draws, on canvas.

A units picker whose tag is the conversion factor id:

UXPopUpButton* units = new UXPopUpButton();
units.addItem((u8*)"Pixels", 0);
units.addItem((u8*)"Millimetres", 1);
units.addItem((u8*)"Inches", 2);
units.selectByTag(savedUnit);
units.setAction(&controller.onUnits);
content.addSubview(units, UXGeom.make(8, 8, 140, 24));