Skip to main content

InputState

Struct InputState 

Source
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: bool

Implementations§

Source§

impl InputState

Source

pub fn new(cx: &mut Context<'_, Self>) -> Self

Source

pub fn input_type(self, input_type: InputType) -> Self

Set the input type

Source

pub fn validation_rules(self, rules: ValidationRules) -> Self

Set validation rules

Source

pub fn min_length(self, min: usize) -> Self

Set minimum length

Source

pub fn max_length(self, max: usize) -> Self

Set maximum length

Source

pub fn required(self, required: bool) -> Self

Mark field as required

Source

pub fn placeholder(self, placeholder: impl Into<SharedString>) -> Self

Source

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. This is raw initialization: it bypasses validation rules, filtering, and max_length truncation. To replace the value later with filtering, truncation, validation, and a Change event, use InputState::set_value.

Source

pub fn disabled(self, disabled: bool) -> Self

Set whether user interaction is disabled.

Source

pub fn select_on_focus(self, select_on_focus: bool) -> Self

Set whether the whole value is selected when the input gains focus.

Source

pub fn trim_on_blur(self, trim_on_blur: bool) -> Self

Set whether surrounding whitespace is trimmed on blur (default true).

Source

pub fn set_placeholder( &mut self, placeholder: impl Into<SharedString>, _window: &mut Window, cx: &mut Context<'_, Self>, )

Set the placeholder text

Source

pub fn content(&self) -> &str

Source

pub fn is_composing(&self) -> bool

Whether an IME composition is currently in progress.

While composing, the in-flight text is displayed but not committed: validation and max_length truncation only apply on commit.

Source

pub fn composition_char_count(&self) -> usize

Number of characters in the in-flight IME composition (0 when not composing). content() includes these characters, so the committed length is content().chars().count() - composition_char_count().

Source

pub fn set_value( &mut self, value: impl Into<SharedString>, window: &mut Window, cx: &mut Context<'_, Self>, )

Set the text content with validation

Source

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.

Source

pub fn validate( &mut self, cx: &mut Context<'_, Self>, ) -> Result<(), ValidationError>

Validate the current input value

Source

pub fn trigger_shake(&mut self)

Source

pub fn left(&mut self, _: &Left, _: &mut Window, cx: &mut Context<'_, Self>)

Source

pub fn right(&mut self, _: &Right, _: &mut Window, cx: &mut Context<'_, Self>)

Source

pub fn word_left( &mut self, _: &WordLeft, _: &mut Window, cx: &mut Context<'_, Self>, )

Source

pub fn word_right( &mut self, _: &WordRight, _: &mut Window, cx: &mut Context<'_, Self>, )

Source

pub fn select_word_left( &mut self, _: &SelectWordLeft, _: &mut Window, cx: &mut Context<'_, Self>, )

Source

pub fn select_word_right( &mut self, _: &SelectWordRight, _: &mut Window, cx: &mut Context<'_, Self>, )

Source

pub fn select_left( &mut self, _: &SelectLeft, _: &mut Window, cx: &mut Context<'_, Self>, )

Source

pub fn select_right( &mut self, _: &SelectRight, _: &mut Window, cx: &mut Context<'_, Self>, )

Source

pub fn select_all( &mut self, _: &SelectAll, _: &mut Window, cx: &mut Context<'_, Self>, )

Source

pub fn home(&mut self, _: &Home, _: &mut Window, cx: &mut Context<'_, Self>)

Source

pub fn end(&mut self, _: &End, _: &mut Window, cx: &mut Context<'_, Self>)

Source

pub fn backspace( &mut self, _: &Backspace, window: &mut Window, cx: &mut Context<'_, Self>, )

Source

pub fn delete( &mut self, _: &Delete, window: &mut Window, cx: &mut Context<'_, Self>, )

Source

pub fn tab(&mut self, _: &Tab, window: &mut Window, cx: &mut Context<'_, Self>)

Source

pub fn shift_tab( &mut self, _: &ShiftTab, window: &mut Window, cx: &mut Context<'_, Self>, )

Source

pub fn paste( &mut self, _: &Paste, window: &mut Window, cx: &mut Context<'_, Self>, )

Source

pub fn copy(&mut self, _: &Copy, _: &mut Window, cx: &mut Context<'_, Self>)

Source

pub fn cut(&mut self, _: &Cut, window: &mut Window, cx: &mut Context<'_, Self>)

Source

pub fn enter(&mut self, _: &Enter, _: &mut Window, cx: &mut Context<'_, Self>)

Source

pub fn escape( &mut self, _: &Escape, _window: &mut Window, cx: &mut Context<'_, Self>, )

Source

pub fn on_focus(&mut self, _window: &mut Window, cx: &mut Context<'_, Self>)

Called when the input gains focus

Source

pub fn on_blur(&mut self, window: &mut Window, cx: &mut Context<'_, Self>)

Called when the input loses focus

Source

pub fn set_masked(&mut self, masked: bool, cx: &mut Context<'_, Self>)

Source

pub fn focus_handle(&self, _: &App) -> FocusHandle

Trait Implementations§

Source§

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>

Source§

fn selected_text_range( &mut self, _ignore_disabled_input: bool, _window: &mut Window, _cx: &mut Context<'_, Self>, ) -> Option<UTF16Selection>

Source§

fn marked_text_range( &self, _window: &mut Window, _cx: &mut Context<'_, Self>, ) -> Option<Range<usize>>

Source§

fn unmark_text(&mut self, _window: &mut Window, cx: &mut Context<'_, Self>)

Source§

fn replace_text_in_range( &mut self, range_utf16: Option<Range<usize>>, new_text: &str, window: &mut Window, cx: &mut Context<'_, Self>, )

Source§

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>, )

Source§

fn bounds_for_range( &mut self, range_utf16: Range<usize>, bounds: Bounds<Pixels>, _window: &mut Window, _cx: &mut Context<'_, Self>, ) -> Option<Bounds<Pixels>>

Source§

fn character_index_for_point( &mut self, point: Point<Pixels>, _window: &mut Window, _cx: &mut Context<'_, Self>, ) -> Option<usize>

Source§

fn accepts_text_input( &self, _window: &mut Window, _cx: &mut Context<'_, Self>, ) -> bool

Source§

impl EventEmitter<InputEvent> for InputState

Source§

impl Focusable for InputState

Source§

fn focus_handle(&self, _: &App) -> FocusHandle

Returns the focus handle associated with this view.
Source§

impl Render for InputState

Source§

fn render( &mut self, _window: &mut Window, cx: &mut Context<'_, Self>, ) -> impl IntoElement

Render this view into an element tree.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &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> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more