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,
impl<State> TextInputView<State>where
State: 'static,
Sourcepub fn placeholder(self, placeholder: impl Into<String>) -> TextInputView<State>
pub fn placeholder(self, placeholder: impl Into<String>) -> TextInputView<State>
Set the placeholder shown when the field is empty and unfocused.
Sourcepub fn on_submit<F>(self, on_submit: F) -> TextInputView<State>
pub fn on_submit<F>(self, on_submit: F) -> TextInputView<State>
Set the submit handler fired on Enter (with the current text); focus is kept.
Sourcepub fn text_style(self, text_style: TextStyle) -> TextInputView<State>
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.
Sourcepub fn multiline(self, max_visible_lines: usize) -> TextInputView<State>
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.
Sourcepub fn submit_on_enter(self, submit_on_enter: bool) -> TextInputView<State>
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.
Sourcepub fn enabled(self, enabled: bool) -> TextInputView<State>
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.
Sourcepub fn read_only(self, read_only: bool) -> TextInputView<State>
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.
Sourcepub fn obscured(self, obscured: bool) -> TextInputView<State>
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).
Sourcepub fn padding(self, x: f64, y: f64) -> TextInputView<State>
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.
Sourcepub fn border_width(self, width: f64) -> TextInputView<State>
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.
Sourcepub fn corner_radius(self, radius: f64) -> TextInputView<State>
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.
Sourcepub fn caret_width(self, width: f32) -> TextInputView<State>
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.
Sourcepub fn focus_ring_width(self, width: f64) -> TextInputView<State>
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,
impl<State> View<State> for TextInputView<State>where
State: 'static,
Source§type Element = TextInputWidget
type Element = TextInputWidget
Source§fn build(&self, _ctx: &mut BuildCtx<'_>) -> TextInputWidget
fn build(&self, _ctx: &mut BuildCtx<'_>) -> TextInputWidget
Source§fn rebuild(
&self,
prev: &TextInputView<State>,
element: &mut TextInputWidget,
ctx: &mut BuildCtx<'_>,
) -> ChangeFlags
fn rebuild( &self, prev: &TextInputView<State>, element: &mut TextInputWidget, ctx: &mut BuildCtx<'_>, ) -> ChangeFlags
prev (the previous view of the same type) against the live
element, mutating it in place and reporting what changed.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>where
Rc<dyn Fn(&mut State, String)>: UnsafeUnpin,
Option<Rc<dyn Fn(&mut State, String)>>: UnsafeUnpin,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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.