Skip to main content

TextInputView

Struct TextInputView 

Source
pub struct TextInputView<State>
where State: 'static,
{ /* private fields */ }
Expand description

A declarative text field, single-line by default. See the module docs.

Implementations§

Source§

impl<State> TextInputView<State>
where State: 'static,

Source

pub fn placeholder(self, placeholder: impl Into<String>) -> TextInputView<State>

Set the placeholder shown when the field is empty and unfocused.

Source

pub fn on_submit<F>(self, on_submit: F) -> TextInputView<State>
where F: Fn(&mut State, String) + 'static,

Set the submit handler fired on Enter (with the current text); focus is kept.

Source

pub fn text_style(self, text_style: TextStyle) -> TextInputView<State>

Set the content text’s style (family/weight/style/size/color/ letter-spacing/line-height), applied to the field’s TextEditor. Marks the color as explicitly set, so it wins over the themed default (explicit > theme > black fallback — see the module docs). Default (no call) resolves the color from the active theme’s on_surface role, falling back to black with no theme threaded. Does not affect the chrome colors or padding/caret constants.

Source

pub fn multiline(self, max_visible_lines: usize) -> TextInputView<State>

Make this a wrapped multi-line field that grows up to max_visible_lines lines tall, then scrolls internally to keep the caret in view (see the module docs). max_visible_lines is clamped to at least 1.

Switches the default Enter behavior to insert a newline rather than submit; override with submit_on_enter.

Source

pub fn submit_on_enter(self, submit_on_enter: bool) -> TextInputView<State>

Set whether Enter submits (true) or inserts a newline (false), overriding the mode default (submit single-line, newline multi-line). Shift+Enter always does the opposite. A single-line field always submits on Enter regardless of this setting.

Source

pub fn enabled(self, enabled: bool) -> TextInputView<State>

Set whether the field accepts input (default true).

A disabled field refuses focus, so a tap neither places the caret nor raises the keyboard and keyboard/IME editing cannot reach it at all; it paints no caret and dims its text, placeholder and outline (see the module docs). A field disabled while focused drops its focus.

This is disabled, not read-only: a read-only field stays focusable and copyable (Material 3’s and Apple’s HIG’s convention — see read_only), where this option refuses focus outright.

Source

pub fn read_only(self, read_only: bool) -> TextInputView<State>

Set whether the field is read-only (default false): its text cannot be changed, but it is still focusable and copyable, and it paints at full alpha rather than dimmed.

This is the presentation enabled(false) cannot express: an undimmed field that takes no edits, e.g. a static mock that should look identical before and after a live handoff. Unlike enabled(false) it suppresses only editing — a press focuses it, a drag selects, copy and select-all work, and cut and paste are answered with nothing. A focused read-only field asks the shell for the platform input surface (its clipboard route) with the on-screen keyboard suppressed. See the module docs’ “Read-only mode” section for the full contract, the semantics distinction from disabled, and the interaction with obscured/the chrome geometry setters.

Source

pub fn obscured(self, obscured: bool) -> TextInputView<State>

Mask the rendered text with U+2022 BULLET (password mode, default false).

The underlying value is untouched — on_change and the published ImeState still carry the real text, and caret/selection/editing arithmetic is unchanged, including across multi-byte graphemes. The field reports itself to accessibility as Role::PasswordInput. See the module docs for what obscuring deliberately does not do (no platform password keyboard, no autofill).

Source

pub fn padding(self, x: f64, y: f64) -> TextInputView<State>

Override the chrome’s inner padding (chrome edge to text), in logical px. Defaults to [PAD_X]/[PAD_Y] (8×6) — a field that never calls this renders identically to before this setter existed. Independent of text_style’s glyph metrics; see the module docs’ “Chrome” section for why this is a per-instance value rather than a Theme token.

Source

pub fn border_width(self, width: f64) -> TextInputView<State>

Override the chrome’s border thickness, in logical px. Defaults to [BORDER_W] (1.5). Affects only the idle/unfocused border unless focus_ring_width is left unset, in which case the focused border uses this width too (unchanged relative behavior). See the module docs’ “Chrome” section.

Source

pub fn corner_radius(self, radius: f64) -> TextInputView<State>

Override the chrome’s corner radius, in logical px. Defaults to [RADIUS] (6.0). See the module docs’ “Chrome” section.

Source

pub fn caret_width(self, width: f32) -> TextInputView<State>

Override the caret width, in logical px. Defaults to [CARET_W] (1.5). See the module docs’ “Chrome” section.

Source

pub fn focus_ring_width(self, width: f64) -> TextInputView<State>

Use width as the border thickness only while the field is focused, instead of border_width. Unset by default, so a focused field’s border is the same width as its idle border, matching the current behavior exactly. This is the narrow focus-ring escape hatch described in the module docs’ “Chrome” section — combined with a theme’s accent color, it reaches a thicker/differently-colored focus outline without this widget growing a second rendering primitive (a halo) it does not otherwise have.

Trait Implementations§

Source§

impl<State> View<State> for TextInputView<State>
where State: 'static,

Source§

type Element = TextInputWidget

The retained widget this view produces.
Source§

fn build(&self, _ctx: &mut BuildCtx<'_>) -> TextInputWidget

Materialise a fresh widget for this view.
Source§

fn rebuild( &self, prev: &TextInputView<State>, element: &mut TextInputWidget, ctx: &mut BuildCtx<'_>, ) -> ChangeFlags

Reconcile prev (the previous view of the same type) against the live element, mutating it in place and reporting what changed.
Source§

fn teardown(&self, element: &mut TextInputWidget, ctx: &mut BuildCtx<'_>)

Tear down element when this view is being removed. Read more
Source§

fn message(&self, _element: &mut Self::Element, _state: &mut State)

Deliver an event message to this view, mutating application state. Read more

Auto Trait Implementations§

§

impl<State> !RefUnwindSafe for TextInputView<State>

§

impl<State> !Send for TextInputView<State>

§

impl<State> !Sync for TextInputView<State>

§

impl<State> !UnwindSafe for TextInputView<State>

§

impl<State> Freeze for TextInputView<State>

§

impl<State> Unpin for TextInputView<State>

§

impl<State> UnsafeUnpin for TextInputView<State>

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> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(_simd: S, value: T) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

Source§

impl<T> StorageAccess<T> for T

Source§

fn as_borrowed(&self) -> &T

Borrows the value.
Source§

fn into_taken(self) -> T

Takes the value.
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> 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