TextArea
TextArea
Section titled “TextArea”#include <TextArea.hpp>Inherits:
Widget
A multiline text input widget.
TextArea supports editing text across multiple lines with cursor movement, insertion, deletion, and vertical/horizontal scrolling.
Public Methods
Section titled “Public Methods”| Return | Name | Description |
|---|---|---|
TextArea inline explicit | Creates a TextArea with optional placeholder text. | |
void | setText | Set the text of the TextArea. |
const std::string & | getText const inline | Get the current text of the TextArea. |
void | setPlaceholder inline | Set the placeholder text shown when the TextArea is empty. |
void | setFlowMode inline | Set the text flow mode, which determines how the TextArea handles overflow. |
TextFlowMode | getFlowMode const inline | Get the current text flow mode. |
void | setOnChange inline | Set what happens when the text changes. The callback is called with the new text whenever it changes. |
bool | isFocusable virtual const inline | Returns whether this widget can receive keyboard focus. |
core::Size | measure virtual | Measures how much space this widget needs. |
bool | onEvent virtual | Handles an input event. |
TextArea
Section titled “TextArea”inline explicit
inline explicit TextArea(const std::string & placeholder)Creates a TextArea with optional placeholder text.
Parameters
Section titled “Parameters”placeholderThe text to show when the TextArea is empty (default: empty
setText
Section titled “setText”void setText(const std::string & t)Set the text of the TextArea.
Parameters
Section titled “Parameters”tThe new text content
getText
Section titled “getText”const inline
inline const std::string & getText() constGet the current text of the TextArea.
Returns
Section titled “Returns”The current text content
setPlaceholder
Section titled “setPlaceholder”inline
inline void setPlaceholder(const std::string & p)Set the placeholder text shown when the TextArea is empty.
Parameters
Section titled “Parameters”pThe new placeholder text
setFlowMode
Section titled “setFlowMode”inline
inline void setFlowMode(TextFlowMode mode)Set the text flow mode, which determines how the TextArea handles overflow.
Parameters
Section titled “Parameters”modeThe new TextFlowMode (default: Scroll)
getFlowMode
Section titled “getFlowMode”const inline
inline TextFlowMode getFlowMode() constGet the current text flow mode.
Returns
Section titled “Returns”The current flow mode
setOnChange
Section titled “setOnChange”inline
inline void setOnChange(std::function< void(const std::string &)> cb)Set what happens when the text changes. The callback is called with the new text whenever it changes.
Parameters
Section titled “Parameters”cbThe callback function to call on text change
isFocusable
Section titled “isFocusable”virtual const inline
virtual inline bool isFocusable() constReturns whether this widget can receive keyboard focus.
Widgets like Button and Input return true; containers return false.
Returns
Section titled “Returns”True if this widget can be focused, false otherwise
measure
Section titled “measure”virtual
virtual core::Size measure(int availW, int availH)Measures how much space this widget needs.
Called during the measurement pass to determine widget size requirements. Should return the preferred size based on available space.
Parameters
Section titled “Parameters”-
availWMaximum available width (may be ignored by widget) -
availHMaximum available height (may be ignored by widget)
Returns
Section titled “Returns”The Size this widget wants, or needs at minimum
onEvent
Section titled “onEvent”virtual
virtual bool onEvent(const core::events::Event & event)Handles an input event.
Called by the framework to deliver an event to this widget. The default implementation runs any listeners registered via addEventListener(), then returns false. Subclasses (Button, Input, etc.) override this to add built-in behavior, and should call Widget::onEvent(event) first to give user listeners a chance to handle the event before the widget’s own logic.
Return true if the event was handled, false to let it bubble to the parent widget.
Parameters
Section titled “Parameters”eventThe input event
Returns
Section titled “Returns”True if this widget (or one of its listeners) handled the event
Protected Methods
Section titled “Protected Methods”| Return | Name | Description |
|---|---|---|
void | drawContent virtual | Draws this widget’s content. |
drawContent
Section titled “drawContent”virtual
virtual void drawContent(backend::Buffer & buf, core::Rect inner)Draws this widget’s content.
Called by render() after background and borders are drawn. This is where you should draw your widget’s actual content. The inner rectangle accounts for borders and padding.
Parameters
Section titled “Parameters”-
bufThe buffer to draw to -
innerThe inner rectangle (excluding border/padding)
Private Attributes
Section titled “Private Attributes”| Return | Name | Description |
|---|---|---|
std::string | text | |
std::string | placeholder | |
int | cursor | |
int | preferredColumn | |
int | scrollX | |
int | scrollY | |
TextFlowMode | flowMode | |
std::function< void(const std::string &)> | onChange |
std::string textplaceholder
Section titled “placeholder”std::string placeholdercursor
Section titled “cursor”int cursor = 0preferredColumn
Section titled “preferredColumn”int preferredColumn = -1scrollX
Section titled “scrollX”int scrollX = 0scrollY
Section titled “scrollY”int scrollY = 0flowMode
Section titled “flowMode”TextFlowMode flowMode = TextFlowMode::ScrollonChange
Section titled “onChange”std::function< void(const std::string &)> onChangePrivate Methods
Section titled “Private Methods”| Return | Name | Description |
|---|---|---|
void | insertChar | |
void | insertNewline | |
void | deleteBack | |
void | deleteForward | |
void | moveCursorHorizontal | |
void | moveCursorVertical | |
void | moveToLineBoundary | |
void | updateScroll |
insertChar
Section titled “insertChar”void insertChar(char c)insertNewline
Section titled “insertNewline”void insertNewline()deleteBack
Section titled “deleteBack”void deleteBack()deleteForward
Section titled “deleteForward”void deleteForward()moveCursorHorizontal
Section titled “moveCursorHorizontal”void moveCursorHorizontal(int delta)moveCursorVertical
Section titled “moveCursorVertical”void moveCursorVertical(int delta)moveToLineBoundary
Section titled “moveToLineBoundary”void moveToLineBoundary(bool endOfLine)updateScroll
Section titled “updateScroll”void updateScroll()