Textarea
textarea · Elements · interactive
A multi-line plain text box.
Import
cpp
#include "gbui/widgets/textarea.hpp"Example
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
| Option | Type | Default | What it does |
|---|---|---|---|
name | std::string_view | What 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. | |
placeholder | std::string_view | ||
disabled | bool | false | |
readOnly | bool | false | |
rows | int | 4 | How 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. |
maxRows | int | 0 | Grows 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. |
submitOnModifiedReturn | bool | true | Ctrl+Return — Cmd+Return on macOS — reports submitted. Return itself belongs to the text. |
width | float | kAuto | |
grow | float | 0.0f |