Widgets¶
A widget shows one field of your model and lets the user change it. You never create a widget yourself. You declare a field, and the type inside it picks the widget.
struct Settings {
core::Field<ui::Slider<>> volume{{.value = 0.6}}; // a slider
core::Field<ui::Checkbox> mute{{.label = "Mute"}}; // a checkbox
core::Field<std::string> status{"Ready"}; // read-only text
};
When the user moves the slider, volume changes and everything that watches it runs.
When your code changes volume, the slider moves.
There is no second copy of the value to keep in step.
New to fields? Read the model and views first. Every widget below runs live in the widget gallery, in your browser.
The families¶
Buttons, checkboxes, sliders, text fields, choices, pickers, labels.
Rows and columns, splits, groups, sections, scroll areas, tabs.
Lists, tables, trees and node boards.
Long documents, code editors, find and replace, completion.
Headings, lists and bold text, read from and written to Markdown.
Scientific plots, and your own drawing.
Menu bars, context menus, dialogs, popovers, tooltips, file dialogs.
Panels the user rearranges, floats and closes.
Typed values dragged from one widget to another.
Which type gives which widget¶
Field type |
Widget |
Page |
|---|---|---|
|
checkbox |
|
|
checkbox with a label |
|
|
button, or a toggle with |
|
|
slider over a range |
|
|
number with steppers |
|
|
one line of text |
|
|
masked text |
|
|
several lines of text |
|
|
text with suggestions |
|
any scoped |
dropdown |
|
|
radio buttons over an enum |
|
|
radio buttons over strings |
|
|
dropdown over strings known at run time |
|
|
color picker |
|
|
date picker |
|
|
time of day |
|
|
read-only text |
|
|
read-only text, a heading, wrapped text |
|
|
a link that opens a URL |
|
|
progress |
|
|
an image |
|
|
the header of a folding section |
|
|
tabs |
|
|
a menu title, and its menu |
|
|
a right-click menu |
|
|
a modal dialog |
|
|
a popover that holds widgets |
|
|
a dock of panels |
Collections are not fields: a core::List<T> is shown by a list or
a table, and a tree source by a tree.
A text::Document is shown by a text view or an editor.
Widgets match on concepts, not on exact types.
Your own string type works in a Label<> if it behaves like a string.
Any scoped enum gets a dropdown, without registering it.