Skip to content

TextView

#include <TextView.hpp>

Inherits: Widget

A read-only multiline text widget.

TextView displays text over multiple lines and supports optional vertical scrolling for long content.

ReturnNameDescription
TextViewDefaulted constructor.
TextView inline explicitCreate a text view with text inside it.
voidsetText inlineSet the text content of the TextView.
const std::string &getText const inlineGet the current text content of the TextView.
voidsetFlowMode inlineSet the text flow mode, which determines how the TextArea handles overflow.
TextFlowModegetFlowMode const inlineGet the current text flow mode.
boolisFocusable virtual constReturns whether this widget can receive keyboard focus.
boolonEvent virtualHandles an input event.
voidsetScrollX
intscrollX const inline
voidsetScrollY
intscrollY const inline
core::Sizemeasure virtualMeasures how much space this widget needs.

TextView() = default

Defaulted constructor.


inline explicit

inline explicit TextView(const std::string & text)

Create a text view with text inside it.

  • text The text to display in the TextView

inline

inline void setText(const std::string & t)

Set the text content of the TextView.

  • t The new text content

const inline

inline const std::string & getText() const

Get the current text content of the TextView.

The current text content


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


virtual const

virtual 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 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


void setScrollX(int x)

const inline

inline int scrollX() const

void setScrollY(int y)

const inline

inline int scrollY() const

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

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
intscrollOffsetX
intscrollOffsetY
TextFlowModeflowMode

std::string text

int scrollOffsetX = 0

int scrollOffsetY = 0

TextFlowMode flowMode = TextFlowMode::Scroll