pub struct TextInputState {
pub text: String,
pub cursor_pos: usize,
pub selection_anchor: Option<usize>,
pub focused: bool,
pub caret_visible: bool,
pub last_edit_time: f32,
}Expand description
Text input state managed by the renderer.
Components don’t store this directly — the renderer maintains it and components query/modify it through the Renderer trait methods.
Fields§
§text: StringThe full text content.
cursor_pos: usizeCursor position as byte offset into the text.
selection_anchor: Option<usize>Selection anchor. If Some, the selection is from anchor to cursor. If None, there is no selection.
focused: boolWhether the input is focused (shows cursor, accepts keyboard).
caret_visible: boolWhether the caret is currently visible (for blinking).
last_edit_time: f32Last edit timestamp for undo coalescing.
Implementations§
Source§impl TextInputState
impl TextInputState
Sourcepub fn new(text: impl Into<String>) -> Self
pub fn new(text: impl Into<String>) -> Self
Create a new TextInputState with the given initial text.
Sourcepub fn selection_range(&self) -> Option<(usize, usize)>
pub fn selection_range(&self) -> Option<(usize, usize)>
Get the selection range as (start, end) byte offsets. Returns None if there is no selection.
Sourcepub fn selected_text(&self) -> String
pub fn selected_text(&self) -> String
Get the selected text, or empty string if no selection.
Sourcepub fn insert(&mut self, new_text: &str)
pub fn insert(&mut self, new_text: &str)
Insert text at the current cursor position, replacing any selection.
Sourcepub fn delete(&mut self, backward: bool, count: usize) -> String
pub fn delete(&mut self, backward: bool, count: usize) -> String
Delete characters. If there’s a selection, delete it.
Otherwise delete count characters backward (backspace) or forward (delete).
Sourcepub fn move_cursor(&mut self, direction: TextDirection, extend_selection: bool)
pub fn move_cursor(&mut self, direction: TextDirection, extend_selection: bool)
Move the cursor in the given direction.
Sourcepub fn select_all(&mut self)
pub fn select_all(&mut self)
Select all text.
Sourcepub fn cursor_byte_pos(&self) -> usize
pub fn cursor_byte_pos(&self) -> usize
Get the byte offset of the cursor.
Trait Implementations§
Source§impl Clone for TextInputState
impl Clone for TextInputState
Source§fn clone(&self) -> TextInputState
fn clone(&self) -> TextInputState
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for TextInputState
impl Debug for TextInputState
Source§impl Default for TextInputState
impl Default for TextInputState
Source§fn default() -> TextInputState
fn default() -> TextInputState
Auto Trait Implementations§
impl Freeze for TextInputState
impl RefUnwindSafe for TextInputState
impl Send for TextInputState
impl Sync for TextInputState
impl Unpin for TextInputState
impl UnsafeUnpin for TextInputState
impl UnwindSafe for TextInputState
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.