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::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
int
startint
end
std::string GetTextInRange(int start, int end) const
Return the text between start
and end
positions.
Parameters
int
startint
end
Return
std::string
void 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&
textint
position
void Delete()
Delete text of current selection.
void DeleteRange(int start, int end)
Delete text between start
and end
positions.
Parameters
int
startint
end
macOS linux
void SetOverlayScrollbar(bool overlay)Set whether to use overlay scrolling.
Parameters
bool
overlay
void SetScrollbarPolicy(Scroll::Policy hpolicy, Scroll::Policy vpolicy)
Set the policy for displaying horizontal and vertical scrollbars.
Parameters
Scroll::Policy
hpolicy - Policy for horizontal scrollbar.Scroll::Policy
vpolicy - Policy for vertical scrollbar.
macOS
void SetScrollElasticity(Scroll::Elasticity helasticity, Scroll::Elasticity velasticity)Set horizontal and vertical scroll elasticity (bounce).
Parameters
Scroll::Elasticity
helasticity - Horizontal scroll elasticity.Scroll::Elasticity
velasticity - Vertical scroll elasticity.
macOS
std::tuple<Scroll::Elasticity, Scroll::Elasticity> GetScrollElasticity() constReturn 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
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