TextEdit

Plain text input view.

Header#include "nativeui/text_edit.h"
Namespacenamespace nu
Typeclass (RefCounted)
InheritsView

The selection range in TextEdit use 0-based index, the start and end both start from 0, and end is the index of the character after the range.

Using -1 as end means the end of the text.

The range uses character index instead of byte index, be careful when using programming languages without Unicode support.

Constructors

TextEdit()

Create a new TextEdit.

Class properties

const char* kClassName

The class name of this view.

Methods

void SetText(const std::string& text)

Change the text in the view.

Parameters

std::string GetText() const

Return currently displayed text.

Return

std::string

void Undo()

Undo the last edit operation in the undo queue.

void CanUndo() const

Return whether there are any actions in undo queue.

void Redo()

Redo the next action in the redo queue

void CanRedo() const

Return whether there are any actions in redo queue.

void Cut()

Delete (cut) the current selection, if any, copy the deleted text to the clipboard.

void Copy()

Copy current selection to clipboard.

void Paste()

Copy the current content of the clipboard to current caret position.

void SelectAll()

Select all text.

std::tuple<int, int> GetSelectionRange() const

Return the start position and end position of current selection.

If nothing is selected, the cursor position will be returned as both values, ie. (0, 0).

Return

std::tuple<int, int>

void SelectRange(int start, int end)

Select text between start and end positions.

Parameters

std::string GetTextInRange(int start, int end) const

Return the text between start and end positions.

Parameters

Return

std::string

void InsertText(const std::string& text)

Insert text at current caret position.

Parameters

void InsertTextAt(const std::string& text, int position)

Insert text at the position.

Parameters

void Delete()

Delete text of current selection.

void DeleteRange(int start, int end)

Delete text between start and end positions.

Parameters

void SetOverlayScrollbar(bool overlay) macOS linux

Set whether to use overlay scrolling.

Parameters

void SetScrollbarPolicy(Scroll::Policy hpolicy, Scroll::Policy vpolicy)

Set the policy for displaying horizontal and vertical scrollbars.

Parameters

void SetScrollElasticity(Scroll::Elasticity helasticity, Scroll::Elasticity velasticity) macOS

Set horizontal and vertical scroll elasticity (bounce).

Parameters

std::tuple<Scroll::Elasticity, Scroll::Elasticity> GetScrollElasticity() const macOS

Return the horizontal and vertical scroll elasticity.

Return

std::tuple<Scroll::Elasticity, Scroll::Elasticity>

RectF GetTextBounds() const

Return the text extend.

Return

RectF

Events

void on_text_change(TextEdit* self)

Emitted when user has changed text.

Parameters

Preventable

No.

Delegates

bool should_insert_new_line(TextEdit* self)

Called when user presses Return to insert new line, should return whether it is allowed.

Parameters

Return

bool