pub struct TextInput {
pub select_on_focus: bool,
/* private fields */
}Expand description
Text input widget state
Fields§
§select_on_focus: boolWhether to select all text when focused
Implementations§
Source§impl TextInput
impl TextInput
Sourcepub fn placeholder(self, text: impl Into<SharedString>) -> Self
pub fn placeholder(self, text: impl Into<SharedString>) -> Self
Set placeholder text (builder pattern)
Sourcepub fn with_value(self, text: impl Into<String>) -> Self
pub fn with_value(self, text: impl Into<String>) -> Self
Set initial value (builder pattern)
Sourcepub fn select_on_focus(self, select: bool) -> Self
pub fn select_on_focus(self, select: bool) -> Self
Set select on focus (builder pattern)
Sourcepub fn masked(self, masked: bool) -> Self
pub fn masked(self, masked: bool) -> Self
Set masked mode for password input (builder pattern)
When masked, the input displays bullet characters instead of the actual text, while retaining full editing functionality (cursor movement, selection, etc.)
Sourcepub fn set_masked(&mut self, masked: bool, cx: &mut Context<'_, Self>)
pub fn set_masked(&mut self, masked: bool, cx: &mut Context<'_, Self>)
Set masked mode programmatically
Sourcepub fn borderless(self, borderless: bool) -> Self
pub fn borderless(self, borderless: bool) -> Self
Set borderless mode for embedding in other controls (builder pattern)
When borderless, the input renders without its own border, background, and rounded corners, allowing it to be embedded in unified containers.
Sourcepub fn input_filter(self, filter: impl Fn(char) -> bool + 'static) -> Self
pub fn input_filter(self, filter: impl Fn(char) -> bool + 'static) -> Self
Set an input filter to restrict allowed characters (builder pattern)
The filter function receives each character and should return true to allow it.
Characters that fail the filter are silently dropped during typing and pasting.
§Example
TextInput::new(cx)
.input_filter(|c| c.is_ascii_digit() || c == '.' || c == '-')Sourcepub fn emit_tab_events(self, emit: bool) -> Self
pub fn emit_tab_events(self, emit: bool) -> Self
Emit Tab/ShiftTab events instead of handling focus navigation (builder pattern)
When true, pressing Tab or Shift+Tab emits TextInputEvent::Tab or
TextInputEvent::ShiftTab respectively, allowing the parent to handle
focus navigation. This is useful when embedding TextInput in other controls
that need to intercept Tab for custom behavior.
When false (default), Tab/Shift+Tab directly calls window.focus_next()
or window.focus_prev().
Sourcepub fn with_enabled(self, enabled: bool) -> Self
pub fn with_enabled(self, enabled: bool) -> Self
Set enabled state (builder pattern)
When disabled, the input does not accept focus, keyboard input, or mouse interaction, and renders with disabled styling.
Sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Check if this input is enabled
Sourcepub fn set_enabled(&mut self, enabled: bool, cx: &mut Context<'_, Self>)
pub fn set_enabled(&mut self, enabled: bool, cx: &mut Context<'_, Self>)
Set enabled state programmatically
Sourcepub fn set_placeholder(
&mut self,
text: impl Into<SharedString>,
cx: &mut Context<'_, Self>,
)
pub fn set_placeholder( &mut self, text: impl Into<SharedString>, cx: &mut Context<'_, Self>, )
Set placeholder text programmatically
Sourcepub fn focus_handle(&self) -> &FocusHandle
pub fn focus_handle(&self) -> &FocusHandle
Get the focus handle
Trait Implementations§
Source§impl Focusable for TextInput
impl Focusable for TextInput
Source§fn focus_handle(&self, _cx: &App) -> FocusHandle
fn focus_handle(&self, _cx: &App) -> FocusHandle
impl EventEmitter<TextInputEvent> for TextInput
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> 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.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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