pub struct InputState {Show 19 fields
pub content: SharedString,
pub placeholder: SharedString,
pub disabled: bool,
pub masked: bool,
pub input_type: InputType,
pub validation_rules: ValidationRules,
pub validation_error: Option<ValidationError>,
pub input_mask: InputMask,
pub aria_label: Option<SharedString>,
pub aria_description: Option<SharedString>,
pub autocomplete: Option<SharedString>,
pub helper_text: Option<SharedString>,
pub success_message: Option<SharedString>,
pub tab_index: Option<i32>,
pub select_on_focus: bool,
pub validate_on_blur: bool,
pub validate_on_change: bool,
pub trim_on_blur: bool,
pub shake_triggered: bool,
/* private fields */
}Expand description
Core input state entity that handles text editing with validation
Fields§
§content: SharedString§placeholder: SharedString§disabled: bool§masked: bool§input_type: InputType§validation_rules: ValidationRules§validation_error: Option<ValidationError>§input_mask: InputMask§aria_label: Option<SharedString>§aria_description: Option<SharedString>§autocomplete: Option<SharedString>§helper_text: Option<SharedString>§success_message: Option<SharedString>§tab_index: Option<i32>§select_on_focus: bool§validate_on_blur: bool§validate_on_change: bool§trim_on_blur: bool§shake_triggered: boolImplementations§
Source§impl InputState
impl InputState
pub fn new(cx: &mut Context<'_, Self>) -> Self
Sourcepub fn input_type(self, input_type: InputType) -> Self
pub fn input_type(self, input_type: InputType) -> Self
Set the input type
Sourcepub fn validation_rules(self, rules: ValidationRules) -> Self
pub fn validation_rules(self, rules: ValidationRules) -> Self
Set validation rules
Sourcepub fn min_length(self, min: usize) -> Self
pub fn min_length(self, min: usize) -> Self
Set minimum length
Sourcepub fn max_length(self, max: usize) -> Self
pub fn max_length(self, max: usize) -> Self
Set maximum length
pub fn placeholder(self, placeholder: impl Into<SharedString>) -> Self
Sourcepub fn value(self, value: impl Into<SharedString>) -> Self
pub fn value(self, value: impl Into<SharedString>) -> Self
Set the initial value.
Equivalent to assigning content directly, but leaves the caret at
the end of the text. To replace the value later with filtering,
validation, and a Change event, use InputState::set_value.
Sourcepub fn select_on_focus(self, select_on_focus: bool) -> Self
pub fn select_on_focus(self, select_on_focus: bool) -> Self
Set whether the whole value is selected when the input gains focus.
Sourcepub fn trim_on_blur(self, trim_on_blur: bool) -> Self
pub fn trim_on_blur(self, trim_on_blur: bool) -> Self
Set whether surrounding whitespace is trimmed on blur (default true).
Sourcepub fn set_placeholder(
&mut self,
placeholder: impl Into<SharedString>,
_window: &mut Window,
cx: &mut Context<'_, Self>,
)
pub fn set_placeholder( &mut self, placeholder: impl Into<SharedString>, _window: &mut Window, cx: &mut Context<'_, Self>, )
Set the placeholder text
pub fn content(&self) -> &str
Sourcepub fn set_value(
&mut self,
value: impl Into<SharedString>,
window: &mut Window,
cx: &mut Context<'_, Self>,
)
pub fn set_value( &mut self, value: impl Into<SharedString>, window: &mut Window, cx: &mut Context<'_, Self>, )
Set the text content with validation
Sourcepub fn apply_initial_value(
&mut self,
value: impl Into<SharedString>,
window: &mut Window,
cx: &mut Context<'_, Self>,
)
pub fn apply_initial_value( &mut self, value: impl Into<SharedString>, window: &mut Window, cx: &mut Context<'_, Self>, )
Apply the builder-supplied initial value exactly once.
Input::render runs every frame; calling set_value there would
overwrite user edits and emit a Change event on every render.
This helper applies the value only on the first call, so subsequent
renders leave the state untouched. To forcefully replace the value
later (e.g., resetting a form), call set_value directly.
Sourcepub fn validate(
&mut self,
cx: &mut Context<'_, Self>,
) -> Result<(), ValidationError>
pub fn validate( &mut self, cx: &mut Context<'_, Self>, ) -> Result<(), ValidationError>
Validate the current input value
pub fn trigger_shake(&mut self)
pub fn left(&mut self, _: &Left, _: &mut Window, cx: &mut Context<'_, Self>)
pub fn right(&mut self, _: &Right, _: &mut Window, cx: &mut Context<'_, Self>)
pub fn word_left( &mut self, _: &WordLeft, _: &mut Window, cx: &mut Context<'_, Self>, )
pub fn word_right( &mut self, _: &WordRight, _: &mut Window, cx: &mut Context<'_, Self>, )
pub fn select_word_left( &mut self, _: &SelectWordLeft, _: &mut Window, cx: &mut Context<'_, Self>, )
pub fn select_word_right( &mut self, _: &SelectWordRight, _: &mut Window, cx: &mut Context<'_, Self>, )
pub fn select_left( &mut self, _: &SelectLeft, _: &mut Window, cx: &mut Context<'_, Self>, )
pub fn select_right( &mut self, _: &SelectRight, _: &mut Window, cx: &mut Context<'_, Self>, )
pub fn select_all( &mut self, _: &SelectAll, _: &mut Window, cx: &mut Context<'_, Self>, )
pub fn home(&mut self, _: &Home, _: &mut Window, cx: &mut Context<'_, Self>)
pub fn end(&mut self, _: &End, _: &mut Window, cx: &mut Context<'_, Self>)
pub fn backspace( &mut self, _: &Backspace, window: &mut Window, cx: &mut Context<'_, Self>, )
pub fn delete( &mut self, _: &Delete, window: &mut Window, cx: &mut Context<'_, Self>, )
pub fn tab(&mut self, _: &Tab, window: &mut Window, cx: &mut Context<'_, Self>)
pub fn shift_tab( &mut self, _: &ShiftTab, window: &mut Window, cx: &mut Context<'_, Self>, )
pub fn paste( &mut self, _: &Paste, window: &mut Window, cx: &mut Context<'_, Self>, )
pub fn copy(&mut self, _: &Copy, _: &mut Window, cx: &mut Context<'_, Self>)
pub fn cut(&mut self, _: &Cut, window: &mut Window, cx: &mut Context<'_, Self>)
pub fn enter(&mut self, _: &Enter, _: &mut Window, cx: &mut Context<'_, Self>)
pub fn escape( &mut self, _: &Escape, _window: &mut Window, cx: &mut Context<'_, Self>, )
Sourcepub fn on_focus(&mut self, _window: &mut Window, cx: &mut Context<'_, Self>)
pub fn on_focus(&mut self, _window: &mut Window, cx: &mut Context<'_, Self>)
Called when the input gains focus
Sourcepub fn on_blur(&mut self, window: &mut Window, cx: &mut Context<'_, Self>)
pub fn on_blur(&mut self, window: &mut Window, cx: &mut Context<'_, Self>)
Called when the input loses focus
pub fn set_masked(&mut self, masked: bool, cx: &mut Context<'_, Self>)
pub fn focus_handle(&self, _: &App) -> FocusHandle
Trait Implementations§
Source§impl EntityInputHandler for InputState
impl EntityInputHandler for InputState
Source§fn text_for_range(
&mut self,
range_utf16: Range<usize>,
actual_range: &mut Option<Range<usize>>,
_window: &mut Window,
_cx: &mut Context<'_, Self>,
) -> Option<String>
fn text_for_range( &mut self, range_utf16: Range<usize>, actual_range: &mut Option<Range<usize>>, _window: &mut Window, _cx: &mut Context<'_, Self>, ) -> Option<String>
InputHandler::text_for_range for detailsSource§fn selected_text_range(
&mut self,
_ignore_disabled_input: bool,
_window: &mut Window,
_cx: &mut Context<'_, Self>,
) -> Option<UTF16Selection>
fn selected_text_range( &mut self, _ignore_disabled_input: bool, _window: &mut Window, _cx: &mut Context<'_, Self>, ) -> Option<UTF16Selection>
InputHandler::selected_text_range for detailsSource§fn marked_text_range(
&self,
_window: &mut Window,
_cx: &mut Context<'_, Self>,
) -> Option<Range<usize>>
fn marked_text_range( &self, _window: &mut Window, _cx: &mut Context<'_, Self>, ) -> Option<Range<usize>>
InputHandler::marked_text_range for detailsSource§fn unmark_text(&mut self, _window: &mut Window, cx: &mut Context<'_, Self>)
fn unmark_text(&mut self, _window: &mut Window, cx: &mut Context<'_, Self>)
InputHandler::unmark_text for detailsSource§fn replace_text_in_range(
&mut self,
range_utf16: Option<Range<usize>>,
new_text: &str,
window: &mut Window,
cx: &mut Context<'_, Self>,
)
fn replace_text_in_range( &mut self, range_utf16: Option<Range<usize>>, new_text: &str, window: &mut Window, cx: &mut Context<'_, Self>, )
InputHandler::replace_text_in_range for detailsSource§fn replace_and_mark_text_in_range(
&mut self,
range_utf16: Option<Range<usize>>,
new_text: &str,
new_selected_range_utf16: Option<Range<usize>>,
window: &mut Window,
cx: &mut Context<'_, Self>,
)
fn replace_and_mark_text_in_range( &mut self, range_utf16: Option<Range<usize>>, new_text: &str, new_selected_range_utf16: Option<Range<usize>>, window: &mut Window, cx: &mut Context<'_, Self>, )
InputHandler::replace_and_mark_text_in_range for detailsSource§fn bounds_for_range(
&mut self,
range_utf16: Range<usize>,
bounds: Bounds<Pixels>,
_window: &mut Window,
_cx: &mut Context<'_, Self>,
) -> Option<Bounds<Pixels>>
fn bounds_for_range( &mut self, range_utf16: Range<usize>, bounds: Bounds<Pixels>, _window: &mut Window, _cx: &mut Context<'_, Self>, ) -> Option<Bounds<Pixels>>
InputHandler::bounds_for_range for detailsSource§fn character_index_for_point(
&mut self,
point: Point<Pixels>,
_window: &mut Window,
_cx: &mut Context<'_, Self>,
) -> Option<usize>
fn character_index_for_point( &mut self, point: Point<Pixels>, _window: &mut Window, _cx: &mut Context<'_, Self>, ) -> Option<usize>
InputHandler::character_index_for_point for detailsSource§fn accepts_text_input(
&self,
_window: &mut Window,
_cx: &mut Context<'_, Self>,
) -> bool
fn accepts_text_input( &self, _window: &mut Window, _cx: &mut Context<'_, Self>, ) -> bool
InputHandler::accepts_text_input for detailsimpl EventEmitter<InputEvent> for InputState
Source§impl Focusable for InputState
impl Focusable for InputState
Source§fn focus_handle(&self, _: &App) -> FocusHandle
fn focus_handle(&self, _: &App) -> FocusHandle
Source§impl Render for InputState
impl Render for InputState
Auto Trait Implementations§
impl !RefUnwindSafe for InputState
impl !Send for InputState
impl !Sync for InputState
impl !UnwindSafe for InputState
impl Freeze for InputState
impl Unpin for InputState
impl UnsafeUnpin 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> 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.impl<S, T> Duplex<S> for Twhere
T: FromSample<S> + ToSample<S>,
Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> 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