A field edits a value of yours. You pass the value by reference, and the field writes the user's changes into it.
- Field is overloaded on the value type: text, numbers, vectors, lists and dictionaries each get their own form.
- Every form returns true when the value changed.
Text fields
bool Field(ID id, std::string& value, TextEditBehavior textEditBehavior, StyleRef style,
LayoutOverride&& constraints = {});
TextEditBehavior says how the field edits. Its flags combine with |:
| Flag | Effect |
| ContinuousUpdate (default) | Updates value on every keystroke, not only on commit |
| Multiline | Enter adds a newline instead of committing |
| AcceptTabs | Tab inserts a tab instead of moving focus |
| ReadOnly | Text can be selected and copied, not edited |
| None | Updates on commit (Enter or focus loss) |
Class: textbox. In a toolbar: toolbar-textbox.
Field(name);
Field(notes, TextEditBehavior::ContinuousUpdate | TextEditBehavior::Multiline);
if (Field(objectName, TextEditBehavior::None))
RenameObject(objectName);
Field(logText, TextEditBehavior::Multiline | TextEditBehavior::ReadOnly);
SearchField
A text field with an icon at the start, inside the border.
- The icon is a GUIContent's icon; its text is the placeholder.
- The placeholder shows, dimmed, while the field is empty.
- For example, "Filter objects" until something is typed.
- An icon alone converts to a GUIContent, for a field without one.
bool SearchField(ID id, std::string& value, const GUIContent& content, TextEditBehavior textEditBehavior,
StyleRef style, LayoutOverride&& constraints = {});
if (SearchField(filter, searchIcon))
filterDirty = true;
if (SearchField(filter, { searchIcon, "Filter objects" }))
filterDirty = true;
Classes: search-textbox, search-textbox-icon, search-textbox-field, and field-placeholder for the placeholder.
AutocompleteField
A text field with a suggestion list below it while it's focused.
bool AutocompleteField(ID id, std::string& value, std::span<const std::string_view> suggestions,
StyleRef style, LayoutOverride&& constraints = {});
- The list shows up to 12 suggestions that contain the typed text, ignoring case.
- It's empty if the only match equals the typed text.
- Up / Down highlight a suggestion.
- Enter or a click puts the suggestion into value.
- Nothing is highlighted until Down, so Enter right away keeps the typed text.
- Escape, picking, or clicking elsewhere closes the list. Typing opens it again.
- Returns true when value changed, by typing or by picking.
Classes, the same as in command search:
- the field: textbox
- the list: command-search-list
- its rows: menu-item-row
- the highlighted row: command-search-current-row
static constexpr std::string_view kFruits[] = { "Apple", "Banana", "Cherry" };
AutocompleteField(fruit, kFruits);
if (AutocompleteField(fruit, kFruits))
UpdateRecipe();
Dropdown
Shows the selected option and opens the option list below it.
bool Dropdown(ID id, int& selected, std::span<const std::string_view> options, StyleRef style,
LayoutOverride&& constraints = {});
bool Dropdown(int& selected, std::initializer_list<std::string_view> options,
LayoutOverride&& constraints = {});
- Picking an option, by a click or by the arrows and Enter:
- sets selected
- returns true that frame
- the field shows the new option from the next frame
- Escape or clicking elsewhere closes the list without a change.
- The keyboard starts on the current option.
- A selected out of range shows an empty field.
Classes: menu-trigger. The popup: menu, with rows menu-item-row.
static constexpr std::string_view kThemes[] = { "Dark", "Light" };
if (Dropdown(themeIndex, kThemes))
ApplyTheme(themeIndex);
Dropdown(quality, { "Low", "Medium", "High" });
Numeric fields
template<typename T, typename ComponentT = typename TypeDimensions<T>::ComponentType>
bool Field(ID id, T& value, TextEditBehavior textEditBehavior, StyleRef style,
NumericFieldConfig<ComponentT> config = {}, LayoutOverride&& constraints = {});
- Shorter overloads leave out the behavior, the style or the config.
- Types: float, double, and 8- to 64-bit signed and unsigned integers.
The field shows an editable number:
- Drag its label past the drag distance to change the value.
- Ctrl drags slower.
- Shift drags faster.
- Escape restores the value.
- NumericFieldConfig sets the range and the drag speed:
- minVal and maxVal: the lowest and highest value
- stepPerPixel: the change per pixel dragged
- decimals, for a float or double: the digits shown after the point, 0 to 9.
- For example, 2 shows 1 as "1.00".
- -1, the default, shows as few as the value needs.
- What's typed is kept as typed, not rounded to them.
- NaN shows in a warning color.
Class: number-field. In a toolbar: toolbar-number-field. In a node's row: node-number-field.
Field(gain, TextEditBehavior::ContinuousUpdate, NumericFieldConfig<float>{ .decimals = 2 });
FixedDecimalsConverter<float>(2) is the converter it uses, for a field of your own made with RegisterEditableValue.
Field(floatValue);
Field(intValue, NumericFieldConfig<int>{ .minVal = 0, .maxVal = 10 });
DragLabel("Angle");
Field(angle, NumericFieldConfig<float>{ .stepPerPixel = 0.5, .minVal = 0.0f, .maxVal = 360.0f });
Vector fields
Field on a vector type gives one number per component. Each has a colored axis label that you can drag.
- Types, with components X, Y, Z and W:
- int2-int4, uint2-uint4
- short2-short4, ushort2-ushort4
- byte2-byte4
- float2-float4
- Types with components R, G, B and A: color4b, color4f.
- The config applies to each component.
DragLabel("Position");
Field(position);
DragLabel("Scale");
Field(scale, NumericFieldConfig<float>{ .minVal = 0.0f });
Classes: vector-component. The labels: axis-label-x, axis-label-y, axis-label-z, axis-label-w.
Edge, corner and shadow fields
Fields for how a box looks: its border widths or padding, its corner radii, its shadow. Each returns true when the value changed.
EdgesField and CornersField
Four numbers, one a side or a corner, after a link toggle.
bool EdgesField(ID id, BoxEdges& value, NumericFieldConfig<int32_t> config = { .stepPerPixel = 0.25, .minVal = 0, .maxVal = 64 },
LayoutOverride&& constraints = {});
bool CornersField(ID id, BoxCorners& value, NumericFieldConfig<int32_t> config = { .stepPerPixel = 0.25, .minVal = 0, .maxVal = 64 },
LayoutOverride&& constraints = {});
- EdgesField captions its numbers T, R, B and L: top, right, bottom, left.
- CornersField captions them TL, TR, BR and BL: top left, top right, bottom right, bottom left.
- Linked (the chain icon), one number sets all four.
- It starts linked when the four are equal.
- Linking four that differ makes the others the first's: the top, or the top left.
- The numbers are held to the config's range, and to 0 to 65535.
- Drag a caption to change its number, as on a vector field.
BoxEdges border = BoxEdges(1);
Label("Border");
EdgesField(idManager.AllocateDynamicID("border"), border);
BoxCorners corners = BoxCorners(4, 4, 0, 0);
Label("Corners");
CornersField(idManager.AllocateDynamicID("corners"), corners, NumericFieldConfig<int32_t>{ .minVal = 0, .maxVal = 16 });
Classes: the link toggle is box-sides-link, selected while linked; the numbers are vector-component with axis-label-w captions, and the one linked number is the theme's number style.
ShadowField
A shadow's color, and under it its offsets, blur and spread.
bool ShadowField(ID id, BoxShadow& value, LayoutOverride&& constraints = {});
- The color is a ColorField. A transparent color is no shadow.
- X and Y move it, Blur softens it, Spread grows it past the box (shrinks it when negative).
- The offsets and spread are held to -256 to 256, the blur to 0 to 256.
BoxShadow shadow{ .y = 4, .blur = 12, .color = { 0, 0, 0, 90 } };
Label("Shadow");
ShadowField(idManager.AllocateDynamicID("shadow"), shadow);
TypedField
A number field with its type after the value, for example "0.5 f32".
template<typename T> bool TypedField(ID id, T& value, LayoutOverride&& constraints = {});
DragLabel("Speed");
TypedField(speed);
Classes: typed-field, typed-field-input, typed-field-type.
Lists
Field on a std::vector<T> gives a list you can reorder. T is any type Field takes.
- Each row has a grip, the index, the field and a remove button.
- An "Add item" button follows the rows.
- Keep the ID the same every frame, or the reorder state is lost.
- Make it once with idManager.CreateStaticID().
- Alt+Up / Down moves the focused row. Focus follows it.
template<typename T>
void Field(ID id, std::vector<T>& items, StyleRef style, LayoutOverride&& constraints = {});
template<typename T>
void Field(ID id, std::vector<T>& items, LayoutOverride&& constraints = {});
Label("Names", std::to_string(names.size()) + " items");
Field(namesListID, names, LayoutOverride{}.FlexGrow(1));
Classes:
- around the list: collection-area
- inside: collection-list, collection-row, collection-index, collection-remove, collection-add
Dictionaries
A key / value list with std::string keys:
- a header with the types
- one row per entry, with the key, the value and a remove button
- an "Add entry" button
Details:
- A vector of pairs keeps the row order.
- An unordered_map can change its order when it rehashes.
- A renamed key commits on Enter or focus loss.
- Renaming onto a key that already exists is ignored.
template<typename V>
void Field(ID id, std::vector<std::pair<std::string, V>>& items, StyleRef style, LayoutOverride&& constraints = {});
template<typename V>
void Field(ID id, std::unordered_map<std::string, V>& items, StyleRef style, LayoutOverride&& constraints = {});
Label("Stats", std::to_string(stats.size()) + " entries");
Field(stats, LayoutOverride{}.FlexGrow(1));
Field(counts, LayoutOverride{}.FlexGrow(1));
Both also come without the style. Classes: collection-area, collection-header, collection-header-cell, collection-header-caption, collection-header-type, collection-entry, collection-value, collection-remove, collection-add-entry.
Previous: Buttons and toggles | Controls | Next: Sliders