Skip to main content

TextField

Struct TextField 

Source
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

Source

pub fn new() -> Self

An empty one-line field: line breaks in typed or pasted text become spaces.

Source

pub fn multiline() -> Self

A field whose text may hold line breaks.

Source

pub fn text(&self) -> &str

Source

pub fn selection(&self) -> Range<usize> ⓘ

Source

pub fn is_reversed(&self) -> bool

Source

pub fn marked(&self) -> Option<Range<usize>>

Source

pub fn cursor(&self) -> usize

Where the caret is: the moving end of the selection.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn unmark(&mut self)

Source

pub fn backspace(&mut self)

Source

pub fn delete(&mut self)

Source

pub fn left(&mut self)

Source

pub fn right(&mut self)

Source

pub fn select_left(&mut self)

Source

pub fn select_right(&mut self)

Source

pub fn home(&mut self)

Source

pub fn end(&mut self)

Source

pub fn select_all(&mut self)

Source

pub fn selected_text(&self) -> Option<&str>

The selected text, if any.

Source

pub fn move_to(&mut self, offset: usize)

Source

pub fn select_to(&mut self, offset: usize)

Extend the selection’s moving end to offset.

Source

pub fn set_selection_utf16(&mut self, range: Range<usize>)

Set the selection from a UTF-16 range (platform input methods).

Source

pub fn len_utf16(&self) -> usize

Source

pub fn offset_from_utf16(&self, offset: usize) -> usize

Source

pub fn offset_to_utf16(&self, offset: usize) -> usize

Source

pub fn range_to_utf16(&self, range: &Range<usize>) -> Range<usize> ⓘ

Source

pub fn range_from_utf16(&self, range: &Range<usize>) -> Range<usize> ⓘ

Trait Implementations§

Source§

impl Clone for TextField

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TextField

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for TextField

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for TextField

Source§

impl PartialEq for TextField

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for TextField

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.