Skip to content

Field

field · Elements · interactive

A control with its label, its help and its error, laid out as one thing.

Import

cpp
#include "gbui/widgets/field.hpp"

Example

Nothing is downloaded until you press it.

cpp
FieldResult field(Ui& ui, const Interaction& input, std::string_view id, const FieldOptions& options, const std::function<void(Ui&)>& control);

Draws the caption, then control, then the help or the error.

API

FieldOptions

OptionTypeDefaultWhat it does
labelstd::string_viewThe caption above the control. Empty draws none, which is what a field inside a table cell or beside its own heading wants.
forIdstd::string_viewThe control this labels, so clicking the caption focuses it. The id of the control built inside the callback — this cannot be worked out from the tree, because the field is built before the control is and a component never reaches into what a caller wrote.
helpstd::string_viewGuidance under the control. Replaced by error while there is one: advice and a complaint in the same place, at the same time, is two things asking to be read first.
errorstd::string_viewWhat is wrong. Non-empty puts the field in its invalid state — the message is drawn in the error colour and the caption goes with it. It does not restyle the control. A component does not reach into another component's options, and a border that changed colour by remote control would be exactly that; pass invalid to the control as well where it has one. What this owns is the message and the caption.
requiredboolfalseMarks the caption with the usual asterisk.
disabledboolfalse
gapfloat5.0fBetween the caption, the control and the message.
widthfloatkAuto
growfloat0.0f

Released under the LGPL-3.0-or-later licence.