Skip to content

Textarea

textarea · Elements · interactive

A multi-line plain text box.

Import

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

Example

Nothing is downloaded until you press it.

cpp
TextEditResult textarea(Ui& ui, const Interaction& input, std::string_view id, TextareaState& state, const TextareaOptions& options = {});

Edits state in place when it has focus, and reports what happened. submitted is the modified Return; changed is any edit at all. The component never writes to your model — the text in state is yours and this is the only thing that touches it. The view follows the caret: typing at the bottom of a full box scrolls it, and so does moving there with the arrows. Nothing else moves it on its own, so a reader who has scrolled up to check something stays where they put themselves until they type again.

API

TextareaOptions

OptionTypeDefaultWhat it does
namestd::string_viewWhat this is called, for a reader who cannot see the caption beside it. Unnecessary when a label or a field names it — those attach the relation, and a name given twice is a name read out twice. Necessary the rest of the time, and the placeholder is not a substitute: a box named by its placeholder loses its name the moment somebody types in it.
placeholderstd::string_view
disabledboolfalse
readOnlyboolfalse
rowsint4How many lines tall the box is, before anything is typed. A count of lines rather than a height in pixels, because that is the unit the answer is in — "about four lines" survives a change of type size and "96 px" does not.
maxRowsint0Grows with the content, to this many lines, then scrolls. Zero keeps the box at rows from the first frame, which is what a form with a fixed layout wants. A chat composer or a commit message box wants this set: the box starts small and opens up as the writing goes on, which is the behaviour everyone now expects and nobody asks for.
submitOnModifiedReturnbooltrueCtrl+Return — Cmd+Return on macOS — reports submitted. Return itself belongs to the text.
widthfloatkAuto
growfloat0.0f

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