A Widget is a drawable object inside an App, such as a text button, number selector, or line chart. Apps and Widgets belong to different layers: ViewManager manages Apps, while Widgets are usually App members and share their App’s lifetime.
An interactive button
1 | class ButtonApp final : public IApplication { |
FocusManager belongs to PixelUI; individual Apps no longer create one. ui.handleInput() first lets FocusManager process LEFT, RIGHT, and SELECT, then passes unconsumed events to the current App.
Focusable state
IWidget defaults to focusable = false. TextButton, IconButton, Label, and NumScroll make themselves focusable; Clock is display-only. Explicitly enable focus when a Brace, Histogram, or CurveChart must participate in navigation:
1 | chart_.setFocusable(true); |
FocusManager navigates only nodes that are focusable, visible, and enabled, and whose ancestors are also visible and enabled.
Widget parent-child tree
The Widget tree allocates no nodes and does not own child objects. It creates intrusive parent-child links between existing Widgets:
1 | class PanelApp final : public IApplication { |
Child coordinates are local to the parent. Children move with the parent. By default, a parent’s bounds clip its children; call setClipChildren(false) to disable clipping.
Widgets are neither copyable nor movable. When a Widget is destroyed or detached from the tree, FocusManager is notified and clears current or active pointers to it.
Built-in Widget reference
| Widget | Purpose | Main configuration |
|---|---|---|
TextButton |
Text button | setCallback, setText, setPosition, setSize |
IconButton |
XBM icon button | setSource, setCallback |
Label |
Text with directional entrance Animation | setText, setLoadPos, setCallback |
NumScroll |
Integer selection | setRange, setValue, getValue, setFixedIntDigits |
Clock |
Analog clock | setHour, setMinute, setSecond, setRadius |
Brace |
Border or container | setDrawContentFunction, addChild, setCallback |
Histogram |
Bar history chart | addData, window and history statistics |
CurveChart |
Line history chart | addData, window and history statistics |
The callback type is PixelUI’s VoidCallback, not std::function. Stored const char* strings and XBM pointers are also non-owning; do not point them at arrays that have left scope.
TextButton and Label
| TextButton | Label |
|---|---|
TextButton uses (x, y, width, height) for its rectangle. Label’s POS selects the direction of its entrance Animation.
NumScroll and Clock
| NumScroll | Clock |
|---|---|
NumScroll coordinates describe the rectangle’s top-left corner. Clock uses center (x, y) and radius. Clock is display-only by default and does not participate in Focus navigation.
Brace
![]()
Brace can draw custom content with setDrawContentFunction() or serve as a parent in the Widget tree. Diagram coordinates and dimensions describe its local bounds.
Fixed Chart buffers
Histogram and CurveChart do not allocate sample buffers on the heap. The caller provides storage:
1 | float samples_[76]{}; |
The number of buffer elements must equal the expanded width. A template static_assert verifies this relationship at compile time. The buffer must outlive the Widget; declaring it before the Chart member gives the correct destruction order.
| Histogram | CurveChart |
|---|---|
Both Charts use the same expansion geometry: EXPAND_BASE selects the fixed corner, and ChartExpandSize<W, H> sets expanded width and height. Histogram draws bars; CurveChart draws a continuous line.
