pub struct InputState {
pub text: String,
pub cursor_pos: usize,
pub focused: bool,
pub enabled: bool,
pub scroll_offset: usize,
}Expand description
State for an input field.
Fields§
§text: StringThe text content.
cursor_pos: usizeCursor position (character index).
focused: boolWhether the input has focus.
enabled: boolWhether the input is enabled.
scroll_offset: usizeHorizontal scroll offset for long text.
Implementations§
Source§impl InputState
impl InputState
Sourcepub fn new(text: impl Into<String>) -> Self
pub fn new(text: impl Into<String>) -> Self
Create a new input state with initial text.
Cursor is positioned at the end of the text.
Sourcepub fn insert_char(&mut self, c: char)
pub fn insert_char(&mut self, c: char)
Insert a character at cursor position.
Sourcepub fn insert_str(&mut self, s: &str)
pub fn insert_str(&mut self, s: &str)
Insert a string at cursor position.
Sourcepub fn delete_char_backward(&mut self) -> bool
pub fn delete_char_backward(&mut self) -> bool
Delete character before cursor (backspace).
Returns true if a character was deleted.
Sourcepub fn delete_char_forward(&mut self) -> bool
pub fn delete_char_forward(&mut self) -> bool
Delete character at cursor (delete key).
Returns true if a character was deleted.
Sourcepub fn delete_word_backward(&mut self) -> bool
pub fn delete_word_backward(&mut self) -> bool
Delete word before cursor.
Returns true if any characters were deleted.
Sourcepub fn move_right(&mut self)
pub fn move_right(&mut self)
Move cursor right by one character.
Sourcepub fn move_word_left(&mut self)
pub fn move_word_left(&mut self)
Move cursor left by one word.
Sourcepub fn move_word_right(&mut self)
pub fn move_word_right(&mut self)
Move cursor right by one word.
Sourcepub fn set_text(&mut self, text: impl Into<String>)
pub fn set_text(&mut self, text: impl Into<String>)
Set the text content.
Cursor is moved to the end.
Sourcepub fn text_before_cursor(&self) -> &str
pub fn text_before_cursor(&self) -> &str
Get text before cursor.
Sourcepub fn text_after_cursor(&self) -> &str
pub fn text_after_cursor(&self) -> &str
Get text after cursor.
Trait Implementations§
Source§impl Clone for InputState
impl Clone for InputState
Source§fn clone(&self) -> InputState
fn clone(&self) -> InputState
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for InputState
impl Debug for InputState
Auto Trait Implementations§
impl Freeze for InputState
impl RefUnwindSafe for InputState
impl Send for InputState
impl Sync for InputState
impl Unpin for InputState
impl UnwindSafe for InputState
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