Skip to content

UXSegmentedControl

UXSegmentedControl lays equal-width segments across the control. A click selects one (single mode, the default) or toggles it (multi mode). It also serves as the tab picker for a UXTabView. Layout and hit-test are pure geometry, unit-tested without a window. Drawing and the click conversion go through the UXControl seam. Where the platform has native segment art (macOS NSSegmentedControl, iOS UISegmentedControl, GTK’s linked toggle group) the driver realizes it. Elsewhere the control draws one connected bezel with hairline dividers, because a segmented control is a single control rather than a row of separate buttons.

#use <UXKit>
UXSegmentedControl* span = new UXSegmentedControl();
span.addSegment((u8*)"Day", 0);
span.addSegment((u8*)"Week", 1);
span.addSegment((u8*)"Month", 2);
span.selectSegment(1);
span.setAction(&controller.onSpan);
content.addSubview(span, UXGeom.make(8, 8, 210, 24));

The action fires after a pick lands, and the handler reads the current state from the sender:

void onSpan(UXControl* sender) {
i32 seg = ((UXSegmentedControl* ?)sender).selectedSegment();
...
}
  • Inherits UXControl: the weak: callback action, enablement, the fire path.

Segments · addSegment · count · labelAt · tagAt Selection · selectSegment · selectedSegment · isSelected · setMultiSelect Geometry · layout · segmentAtLocalX

void addSegment(u8* label, i32 tag)

Appends a segment. The tag is yours: a stable id that survives reordering.

i32 count(void)

How many segments the row holds.

u8* labelAt(i32 i)

The segment’s label.

i32 tagAt(i32 i)

The segment’s tag.

void selectSegment(i32 i)

Takes an index, not a tag. Single mode selects it and clears the others; multi mode toggles it. Programmatic selection does not fire the action.

i32 selectedSegment(void)

The first selected index, or -1 when none is selected. In multi mode, ask each segment with isSelected instead.

bool isSelected(i32 i)

Whether the segment is on. This is the reader to use in multi mode.

void setMultiSelect(bool on)

Switches to toggling. Set it before attach where it changes the native realization (Win32 chooses check-group vs check).

void layout(i16 width)

Distributes equal widths across the row (the last segment takes the remainder). This is pure geometry, and the tests call it without a window.

i32 segmentAtLocalX(i16 lx)

The segment under a local x, or -1 outside. This is the hit-test half of the same pure geometry.

UXSegmentedControl on the web backend

One connected bezel with hairline dividers, the pick filled with the selection colour. The app-drawn treatment, on canvas.

A view-mode picker driving a tab view:

UXSegmentedControl* mode = new UXSegmentedControl();
mode.addSegment((u8*)"List", 0);
mode.addSegment((u8*)"Icons", 1);
mode.selectSegment(0);
mode.setAction(&controller.onMode);
content.addSubview(mode, UXGeom.make(8, 8, 160, 24));
void onMode(UXControl* sender) {
tabs.selectTab(((UXSegmentedControl* ?)sender).selectedSegment());
}