TextEdit
Plain text input view.
| Header | #include "nativeui/text_edit.h" |
| Namespace | namespace nu |
| Type | class (RefCounted) |
| Inherits | View |
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
const std::string&text
std::string GetText() const
Return currently displayed text.
Return
std::stringvoid 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
intstartintend
std::string GetTextInRange(int start, int end) const
Return the text between start and end positions.
Parameters
intstartintend
Return
std::stringvoid InsertText(const std::string& text)
Insert text at current caret position.
Parameters
const std::string&text
void InsertTextAt(const std::string& text, int position)
Insert text at the position.
Parameters
const std::string&textintposition
void Delete()
Delete text of current selection.
void DeleteRange(int start, int end)
Delete text between start and end positions.
Parameters
intstartintend
void SetOverlayScrollbar(bool overlay) macOS linux
Set whether to use overlay scrolling.
Parameters
booloverlay
void SetScrollbarPolicy(Scroll::Policy hpolicy, Scroll::Policy vpolicy)
Set the policy for displaying horizontal and vertical scrollbars.
Parameters
Scroll::Policyhpolicy - Policy for horizontal scrollbar.Scroll::Policyvpolicy - Policy for vertical scrollbar.
void SetScrollElasticity(Scroll::Elasticity helasticity, Scroll::Elasticity velasticity) macOS
Set horizontal and vertical scroll elasticity (bounce).
Parameters
Scroll::Elasticityhelasticity - Horizontal scroll elasticity.Scroll::Elasticityvelasticity - Vertical scroll elasticity.
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
RectFEvents
void on_text_change(TextEdit* self)
Emitted when user has changed text.
Parameters
TextEdit*self
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
TextEdit*self
Return
bool