pub struct TextField { /* private fields */ }Expand description
The state of one text field: its text, the selection (with which end moves), and any text
an input method has marked while composing. Offsets are UTF-8 byte offsets on grapheme
boundaries; the *_utf16 helpers convert for platform input methods.
Implementations§
Source§impl TextField
impl TextField
Sourcepub fn new() -> Self
pub fn new() -> Self
An empty one-line field: line breaks in typed or pasted text become spaces.
pub fn text(&self) -> &str
pub fn selection(&self) -> Range<usize> ⓘ
pub fn is_reversed(&self) -> bool
pub fn marked(&self) -> Option<Range<usize>>
Sourcepub fn set_text_selected(&mut self, text: &str)
pub fn set_text_selected(&mut self, text: &str)
Replace the whole text and select all of it, as an address bar does when a page loads or the field is focused.
Sourcepub fn append_selected(&mut self, suffix: &str)
pub fn append_selected(&mut self, suffix: &str)
Add suffix after the text and select it (an inline completion): the
next typed character replaces it, Backspace removes it, and Right
moves the caret past it.
Sourcepub fn replace(&mut self, range: Option<Range<usize>>, text: &str)
pub fn replace(&mut self, range: Option<Range<usize>>, text: &str)
Replace range (or the marked text, else the selection) with text
and put the caret after it.
Sourcepub fn replace_and_mark(
&mut self,
range: Option<Range<usize>>,
text: &str,
selected_in_new: Option<Range<usize>>,
)
pub fn replace_and_mark( &mut self, range: Option<Range<usize>>, text: &str, selected_in_new: Option<Range<usize>>, )
Like Self::replace for input-method composition: the new text is
marked, and selected_in_new (relative to it) becomes the selection.
pub fn unmark(&mut self)
pub fn backspace(&mut self)
pub fn delete(&mut self)
pub fn left(&mut self)
pub fn right(&mut self)
pub fn select_left(&mut self)
pub fn select_right(&mut self)
pub fn home(&mut self)
pub fn end(&mut self)
pub fn select_all(&mut self)
Sourcepub fn selected_text(&self) -> Option<&str>
pub fn selected_text(&self) -> Option<&str>
The selected text, if any.
pub fn move_to(&mut self, offset: usize)
Sourcepub fn set_selection_utf16(&mut self, range: Range<usize>)
pub fn set_selection_utf16(&mut self, range: Range<usize>)
Set the selection from a UTF-16 range (platform input methods).