Skip to content

UXCheckbox

UXCheckbox is a toggle that remembers. Click it and it flips isChecked, repaints, and fires its action, like a button that remembers its state. Where the platform has a native check box (Win32, macOS, iOS once the overlay lands) the driver realizes one. Where it does not (GEM, web), the control paints itself from the theme’s check / check.selected sprites, through the same drawRect seam as any custom view. State lives in the neutral object in both cases, so a test can toggle and read it identically on every backend.

#use <UXKit>
UXCheckbox* c = new UXCheckbox();
c.setTitle((u8*)"Subscribe");
c.setChecked(true);
c.setAction(&controller.onSubscribe); // fires AFTER the toggle
content.addSubview(c, UXGeom.make(8, 8, 120, 20));

The action fires after the state flips, so the handler reads the new state from the sender:

void onSubscribe(UXControl* sender) {
bool on = ((UXCheckbox* ?)sender).isChecked();
...
}

The themed sprite draws at its native 21×21 (stretching blurs pixel art). A disabled checkbox greys its label and consumes nothing.

For the one-of-a-set variant, see UXRadioButton. It draws the same way, and the mutual exclusion lives in UXRadioGroup as plain neutral logic: select() clears the others, and that is all of radio behaviour.

  • Inherits UXControl: title, the callback action (auto-zeroing), the fire path.

State · isChecked · setChecked Realization · kind · attachTo Events · mouseDown

bool isChecked(void)

The current state. The neutral object holds it, whatever realized the control.

void setChecked(bool c)

Sets the state programmatically and marks the control dirty. Does not fire the action: actions are for the user’s toggles, and code that sets the state already knows it.

UXKind kind(void)

UXKindCheckbox: native where the backend has the art, app-drawn everywhere else. The driver decides; the control does not know which.

void attachTo(UXViewTree* t, UXRect frame)

Realizes into the tree and stores the title (as the node’s spec) and self (as its peer). A native backend needs both to build a real check box; the app-drawn path ignores both.

void mouseDown(UXEvent* e)

Toggle, repaint, fire, in that order, so the action always sees the new state. When disabled, does nothing.

UXCheckbox on the web backend

The theme’s check.selected sprite at its native 21×21: the same Aristo art GEM draws, 9-sliced from the same atlas.

A settings row whose apply button reads the toggles:

UXCheckbox* bold = new UXCheckbox();
UXCheckbox* italic = new UXCheckbox();
bold.setTitle((u8*)"Bold"); bold.setChecked(true);
italic.setTitle((u8*)"Italic");
content.addSubview(bold, UXGeom.make(8, 8, 100, 20));
content.addSubview(italic, UXGeom.make(8, 32, 100, 20));
// later, in an action:
face.setStyle(bold.isChecked(), italic.isChecked());