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
impl TextInput
Sourcepub fn with_text(text: impl Into<String>) -> Self
pub fn with_text(text: impl Into<String>) -> Self
Create a TextInput pre-populated with text, cursor at the end.
Sourcepub fn with_password(self) -> Self
pub fn with_password(self) -> Self
Enable password masking with the bullet character U+2022.
Sourcepub fn scroll_offset(&self) -> f32
pub fn scroll_offset(&self) -> f32
Current horizontal scroll offset in logical pixels.
Sourcepub fn is_password(&self) -> bool
pub fn is_password(&self) -> bool
Returns true when password masking is active.
Sourcepub fn is_showing_password(&self) -> bool
pub fn is_showing_password(&self) -> bool
Returns true when the underlying password text is currently visible.
Sourcepub fn display_text(&self) -> String
pub fn display_text(&self) -> String
The text to display — masked when in password mode (unless show-password is toggled on).
Sourcepub fn toggle_show_password(&mut self)
pub fn toggle_show_password(&mut self)
Toggle the show/hide state for password fields. No-op on plain fields.
Sourcepub fn selected_text(&self) -> &str
pub fn selected_text(&self) -> &str
Borrow the currently selected slice of the raw text.
Returns an empty string when the selection is collapsed.
Sourcepub fn insert(&mut self, s: &str)
pub fn insert(&mut self, s: &str)
Insert a string at the cursor position, replacing any active selection.
Sourcepub fn insert_char(&mut self, c: char)
pub fn insert_char(&mut self, c: char)
Insert a single character at the cursor position.
Sourcepub fn delete_backward(&mut self)
pub fn delete_backward(&mut self)
Delete the character immediately before the cursor (backspace).
If there is an active selection, deletes the selection instead.
Sourcepub fn delete_forward(&mut self)
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.
Sourcepub fn move_left(&mut self, shift: bool)
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.
Sourcepub fn move_right(&mut self, shift: bool)
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.
Sourcepub fn move_home(&mut self, shift: bool)
pub fn move_home(&mut self, shift: bool)
Move the cursor to the beginning of the text (Home key).
Sourcepub fn move_word_left(&mut self, shift: bool)
pub fn move_word_left(&mut self, shift: bool)
Move the cursor one word to the left (Ctrl+Left).
Sourcepub fn move_word_right(&mut self, shift: bool)
pub fn move_word_right(&mut self, shift: bool)
Move the cursor one word to the right (Ctrl+Right).
Sourcepub fn move_cursor_to_x(&mut self, x: f32, layout: &TextLayout, shift: bool)
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).
Sourcepub fn click(&mut self, x: f32, layout: &TextLayout)
pub fn click(&mut self, x: f32, layout: &TextLayout)
Single-click — move the cursor and collapse the selection.
Sourcepub fn double_click(&mut self, x: f32, layout: &TextLayout)
pub fn double_click(&mut self, x: f32, layout: &TextLayout)
Double-click — select the word nearest to the click position.
Sourcepub fn triple_click(&mut self)
pub fn triple_click(&mut self)
Triple-click — select all text.
Sourcepub fn select_all(&mut self)
pub fn select_all(&mut self)
Select all text (Ctrl+A equivalent).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for TextInput
impl RefUnwindSafe for TextInput
impl Send for TextInput
impl Sync for TextInput
impl Unpin for TextInput
impl UnsafeUnpin for TextInput
impl UnwindSafe for TextInput
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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