Skip to content

UXToolbar

UXToolbar is a row of toolbar items (icon-and-label buttons, fixed gaps, separators) laid out left to right. Two behaviours distinguish it from a row of buttons. Flexible spaces absorb the leftover width, to push a group right or centre one between two others. When the fixed items exceed the width, the trailing ones move into an overflow set, which a native toolbar shows under a chevron. The layout and hit test are pure geometry, unit-tested without a window.

On macOS it realizes as an NSToolbar, which is window chrome above the content area, so it has its own kind. On Win32 it realizes as a native toolbar control, and on GEM as the app-drawn row.

#use <UXKit>
UXToolbar* tb = new UXToolbar();
tb.addItem((u8*)"doc.new", (u8*)"New", 1, 48);
tb.addItem((u8*)"doc.open", (u8*)"Open", 2, 48);
tb.addSeparator();
tb.addFlexibleSpace();
tb.addItem((u8*)"search", (u8*)"Find", 9, 48); // pushed to the right edge
tb.setAction(&controller.onTool);
void onTool(UXControl* sender) {
UXToolbar* t = (UXToolbar* ?)sender;
i32 tag = t.itemAt(t.selection()).tag;
...
}

Items · addItem · addSpace · addFlexibleSpace · addSeparator · count Selection · selection Overflow · overflow Geometry · layout

void addItem(u8* ident, u8* label, i32 tag, i16 width)

A clickable item. ident names the icon (a native backend maps it to platform art), label is the text, tag is yours to use, and width is its fixed extent.

void addSpace(void)

A fixed gap.

void addFlexibleSpace(void)

A gap that absorbs an equal share of the leftover width. This one item type provides all of a toolbar’s layout control.

void addSeparator(void)

A thin rule between groups.

i32 count(void)

How many items there are, including spaces and separators.

i32 selection(void)

The index of the last clicked item, or -1 before any click. A native toolbar’s click arrives by tag and is recorded here too, so reading it works the same on every backend.

i32 overflow(void)

How many trailing items did not fit at the last layout. The chevron menu shows these.

void layout(i16 width)

Places every item: fixed widths first, then flexible spaces sharing the remainder, with trailing items marked invisible when the width runs out. Pure geometry; the tests call it without a window.

UXToolbar on Web

The app-drawn fallback: bezeled items, separators, and a flexible space pushing the last group right.