Skip to content

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.

ReturnNameDescription
TextArea inline explicitCreates a TextArea with optional placeholder text.
voidsetTextSet the text of the TextArea.
const std::string &getText const inlineGet the current text of the TextArea.
voidsetPlaceholder inlineSet the placeholder text shown when the TextArea is empty.
voidsetFlowMode inlineSet the text flow mode, which determines how the TextArea handles overflow.
TextFlowModegetFlowMode const inlineGet the current text flow mode.
voidsetOnChange inlineSet what happens when the text changes. The callback is called with the new text whenever it changes.
boolisFocusable virtual const inlineReturns whether this widget can receive keyboard focus.
core::Sizemeasure virtualMeasures how much space this widget needs.
boolonEvent virtualHandles an input event.

inline explicit

inline explicit TextArea(const std::string & placeholder)

Creates a TextArea with optional placeholder text.

  • placeholder The text to show when the TextArea is empty (default: empty

void setText(const std::string & t)

Set the text of the TextArea.

  • t The new text content

const inline

inline const std::string & getText() const

Get the current text of the TextArea.

The current text content


inline

inline void setPlaceholder(const std::string & p)

Set the placeholder text shown when the TextArea is empty.

  • p The new placeholder text

inline

inline void setFlowMode(TextFlowMode mode)

Set the text flow mode, which determines how the TextArea handles overflow.

  • mode The new TextFlowMode (default: Scroll)

const inline

inline TextFlowMode getFlowMode() const

Get the current text flow mode.

The current flow mode


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.

  • cb The callback function to call on text change

virtual const inline

virtual inline bool isFocusable() const

Returns whether this widget can receive keyboard focus.

Widgets like Button and Input return true; containers return false.

True if this widget can be focused, false otherwise


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.

  • availW Maximum available width (may be ignored by widget)

  • availH Maximum available height (may be ignored by widget)

The Size this widget wants, or needs at minimum


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.

  • event The input event

True if this widget (or one of its listeners) handled the event

ReturnNameDescription
voiddrawContent virtualDraws this widget’s content.

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.

  • buf The buffer to draw to

  • inner The inner rectangle (excluding border/padding)

ReturnNameDescription
std::stringtext
std::stringplaceholder
intcursor
intpreferredColumn
intscrollX
intscrollY
TextFlowModeflowMode
std::function< void(const std::string &)>onChange

std::string text

std::string placeholder

int cursor = 0

int preferredColumn = -1

int scrollX = 0

int scrollY = 0

TextFlowMode flowMode = TextFlowMode::Scroll

std::function< void(const std::string &)> onChange
ReturnNameDescription
voidinsertChar
voidinsertNewline
voiddeleteBack
voiddeleteForward
voidmoveCursorHorizontal
voidmoveCursorVertical
voidmoveToLineBoundary
voidupdateScroll

void insertChar(char c)

void insertNewline()

void deleteBack()

void deleteForward()

void moveCursorHorizontal(int delta)

void moveCursorVertical(int delta)

void moveToLineBoundary(bool endOfLine)

void updateScroll()