Skip to main content

TextInput

Struct TextInput 

Source
pub struct TextInput { /* private fields */ }
Expand description

Single-line editable text input widget state.

Wraps the text string, cursor byte-offset, selection, horizontal scroll, and optional password masking. All editing operations keep the cursor and selection consistent.

Implementations§

Source§

impl TextInput

Source

pub fn new() -> Self

Create an empty TextInput with no masking.

Source

pub fn with_text(text: impl Into<String>) -> Self

Create a TextInput pre-populated with text, cursor at the end.

Source

pub fn with_password(self) -> Self

Enable password masking with the bullet character U+2022.

Source

pub fn text(&self) -> &str

Borrow the raw (un-masked) text.

Source

pub fn cursor(&self) -> usize

Current cursor byte offset.

Source

pub fn selection(&self) -> &Selection

Current selection.

Source

pub fn scroll_offset(&self) -> f32

Current horizontal scroll offset in logical pixels.

Source

pub fn is_password(&self) -> bool

Returns true when password masking is active.

Source

pub fn is_showing_password(&self) -> bool

Returns true when the underlying password text is currently visible.

Source

pub fn display_text(&self) -> String

The text to display — masked when in password mode (unless show-password is toggled on).

Source

pub fn toggle_show_password(&mut self)

Toggle the show/hide state for password fields. No-op on plain fields.

Source

pub fn selected_text(&self) -> &str

Borrow the currently selected slice of the raw text.

Returns an empty string when the selection is collapsed.

Source

pub fn insert(&mut self, s: &str)

Insert a string at the cursor position, replacing any active selection.

Source

pub fn insert_char(&mut self, c: char)

Insert a single character at the cursor position.

Source

pub fn delete_backward(&mut self)

Delete the character immediately before the cursor (backspace).

If there is an active selection, deletes the selection instead.

Source

pub fn delete_forward(&mut self)

Delete the character immediately after the cursor (Delete key).

If there is an active selection, deletes the selection instead.

Source

pub fn move_left(&mut self, shift: bool)

Move the cursor one character to the left.

When shift is false and there is an active selection, the cursor jumps to the start of the selection without extending it.

Source

pub fn move_right(&mut self, shift: bool)

Move the cursor one character to the right.

When shift is false and there is an active selection, the cursor jumps to the end of the selection without extending it.

Source

pub fn move_home(&mut self, shift: bool)

Move the cursor to the beginning of the text (Home key).

Source

pub fn move_end(&mut self, shift: bool)

Move the cursor to the end of the text (End key).

Source

pub fn move_word_left(&mut self, shift: bool)

Move the cursor one word to the left (Ctrl+Left).

Source

pub fn move_word_right(&mut self, shift: bool)

Move the cursor one word to the right (Ctrl+Right).

Source

pub fn move_cursor_to_x(&mut self, x: f32, layout: &TextLayout, shift: bool)

Move the cursor to the byte position nearest to the pixel x-coordinate.

Uses TextLayout::hit_test for positioning. When shift is true, the selection anchor is preserved (keyboard-extend behaviour).

Source

pub fn click(&mut self, x: f32, layout: &TextLayout)

Single-click — move the cursor and collapse the selection.

Source

pub fn double_click(&mut self, x: f32, layout: &TextLayout)

Double-click — select the word nearest to the click position.

Source

pub fn triple_click(&mut self)

Triple-click — select all text.

Source

pub fn select_all(&mut self)

Select all text (Ctrl+A equivalent).

Trait Implementations§

Source§

impl Clone for TextInput

Source§

fn clone(&self) -> TextInput

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 TextInput

Source§

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

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

impl Default for TextInput

Source§

fn default() -> Self

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

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.