pub struct TextInputState {
pub value: String,
pub cursor: usize,
pub placeholder: String,
pub max_length: Option<usize>,
pub validation_error: Option<String>,
pub masked: bool,
}Expand description
State for a single-line text input widget.
Pass a mutable reference to Context::text_input each frame. The widget
handles all keyboard events when focused.
§Example
let mut input = TextInputState::with_placeholder("Type here...");
ui.text_input(&mut input);
println!("{}", input.value);Fields§
§value: StringThe current input text.
cursor: usizeCursor position as a character index into value.
placeholder: StringPlaceholder text shown when value is empty.
max_length: Option<usize>Maximum character count. Input is rejected beyond this limit.
validation_error: Option<String>The most recent validation error message, if any.
masked: boolWhen true, input is displayed as • characters (for passwords).
Implementations§
Source§impl TextInputState
impl TextInputState
Sourcepub fn with_placeholder(p: impl Into<String>) -> Self
pub fn with_placeholder(p: impl Into<String>) -> Self
Create a text input with placeholder text shown when the value is empty.
Sourcepub fn max_length(self, len: usize) -> Self
pub fn max_length(self, len: usize) -> Self
Set the maximum allowed character count.
Trait Implementations§
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
Mutably borrows from an owned value. Read more