pub struct TextField { /* private fields */ }Expand description
A Material presentation for a caller-owned Base text editing entity.
Keep the entity across renders. It owns selection, undo, composition, focus,
and text. Subscribe to super::TextFieldEvent on the entity to observe user
edits. Set disabled and read-only on the entity before rendering.
Implementations§
Source§impl TextField
impl TextField
Sourcepub fn new(
id: impl Into<ElementId>,
label: impl Into<SharedString>,
state: &Entity<InputBaseState<InputMode>>,
) -> TextField
pub fn new( id: impl Into<ElementId>, label: impl Into<SharedString>, state: &Entity<InputBaseState<InputMode>>, ) -> TextField
Renders a single-line editor.
Sourcepub fn filled(
id: impl Into<ElementId>,
label: impl Into<SharedString>,
state: &Entity<InputBaseState<InputMode>>,
) -> TextField
pub fn filled( id: impl Into<ElementId>, label: impl Into<SharedString>, state: &Entity<InputBaseState<InputMode>>, ) -> TextField
Renders a Filled single-line editor.
Sourcepub fn outlined(
id: impl Into<ElementId>,
label: impl Into<SharedString>,
state: &Entity<InputBaseState<InputMode>>,
) -> TextField
pub fn outlined( id: impl Into<ElementId>, label: impl Into<SharedString>, state: &Entity<InputBaseState<InputMode>>, ) -> TextField
Renders an Outlined single-line editor.
Sourcepub fn multiline(
id: impl Into<ElementId>,
label: impl Into<SharedString>,
state: &Entity<InputBaseState<TextareaMode>>,
) -> TextField
pub fn multiline( id: impl Into<ElementId>, label: impl Into<SharedString>, state: &Entity<InputBaseState<TextareaMode>>, ) -> TextField
Renders a multi-line editor using the row policy configured in its state.
Sourcepub fn secure(
id: impl Into<ElementId>,
label: impl Into<SharedString>,
state: &Entity<InputBaseState<InputMode>>,
) -> TextField
pub fn secure( id: impl Into<ElementId>, label: impl Into<SharedString>, state: &Entity<InputBaseState<InputMode>>, ) -> TextField
Renders a secure password editor. Defaults to TextFieldObfuscationMode::Hidden,
masking the value with •, blocking copy/cut, and suppressing the accessible value
and character count. Call Self::obfuscation_mode with
TextFieldObfuscationMode::Visible to reveal plain text.
Use a dedicated entity initialized with TextFieldState::masked(true)
so the text is protected even before this field is first rendered.
pub fn variant(self, variant: TextFieldVariant) -> TextField
Sourcepub fn obfuscation_mode(self, mode: TextFieldObfuscationMode) -> TextField
pub fn obfuscation_mode(self, mode: TextFieldObfuscationMode) -> TextField
Sets whether a TextField::secure editor is masked (Hidden) or revealed (Visible).
Ignored for non-secure fields.
Sourcepub fn clearable(self, clearable: bool) -> TextField
pub fn clearable(self, clearable: bool) -> TextField
Displays a trailing clear button when the editor is editable and non-empty.
Activating the button clears the Base state via replace_all("") and keeps focus on the
editor. When combined with .visibility_toggle(...) or .trailing(...), built-in controls
render in logical order before custom trailing content.
Sourcepub fn clear_label(self, label: impl Into<SharedString>) -> TextField
pub fn clear_label(self, label: impl Into<SharedString>) -> TextField
Overrides the accessible label of the .clearable(true) button (default "Clear").
Sourcepub fn visibility_toggle(
self,
visible: bool,
on_toggle: impl Fn(bool, &mut Window, &mut App) + 'static,
) -> TextField
pub fn visibility_toggle( self, visible: bool, on_toggle: impl Fn(bool, &mut Window, &mut App) + 'static, ) -> TextField
Adds a controlled password reveal toggle on TextField::secure editors and syncs
Self::obfuscation_mode automatically (Visible when visible is true, Hidden
otherwise). Ignored for non-secure fields.
Sourcepub fn visibility_labels(
self,
show: impl Into<SharedString>,
hide: impl Into<SharedString>,
) -> TextField
pub fn visibility_labels( self, show: impl Into<SharedString>, hide: impl Into<SharedString>, ) -> TextField
Overrides the accessible labels of the .visibility_toggle(...) button
(defaults to "Show password" and "Hide password").
Sourcepub fn font_scale(self, scale: f32) -> TextField
pub fn font_scale(self, scale: f32) -> TextField
Applies the caller’s user text scale to the editor, label, and supporting text.
Sourcepub fn text_style(self, style: TypeStyle) -> TextField
pub fn text_style(self, style: TypeStyle) -> TextField
Overrides the Material type metrics for input, hint, and affixes before applying font scale.
Sourcepub fn shape(self, shape: CornerShape) -> TextField
pub fn shape(self, shape: CornerShape) -> TextField
Overrides the container’s logical corner shape. Full uses the laid-out bounds.
Sourcepub fn content_padding(self, padding: Edges<Pixels>) -> TextField
pub fn content_padding(self, padding: Edges<Pixels>) -> TextField
Sets physical editor insets. An Inside label reserves additional height above the editor.
Sourcepub fn colors(self, colors: TextFieldColors) -> TextField
pub fn colors(self, colors: TextFieldColors) -> TextField
Applies per-state color overrides while preserving theme defaults for unset colors.
Sourcepub fn on_text_layout(
self,
listener: impl FnOnce(TextFieldLayout, &mut Window, &mut App) + 'static,
) -> TextField
pub fn on_text_layout( self, listener: impl FnOnce(TextFieldLayout, &mut Window, &mut App) + 'static, ) -> TextField
Called after paint when the editor’s reported layout changes. Subscribe to the Base entity for text changes that do not affect layout.
Sourcepub fn interaction_source(self, source: &Entity<InteractionSource>) -> TextField
pub fn interaction_source(self, source: &Entity<InteractionSource>) -> TextField
Observes hover, keyboard-visible focus, and disabled state through a shared source. Editing and selection stay with the Base entity.
pub fn supporting_text(self, text: impl Into<SharedString>) -> TextField
Sourcepub fn label_content(self, element: impl IntoElement) -> TextField
pub fn label_content(self, element: impl IntoElement) -> TextField
Replaces the visible label. The constructor label remains the accessible name.
pub fn label_position(self, position: TextFieldLabelPosition) -> TextField
Sourcepub fn label_always_minimized(self, minimized: bool) -> TextField
pub fn label_always_minimized(self, minimized: bool) -> TextField
Keeps an Inside or Cutout label minimized so affixes and hints can remain visible.
Sourcepub fn label_alignment(
self,
expanded: TextFieldLabelAlignment,
minimized: TextFieldLabelAlignment,
) -> TextField
pub fn label_alignment( self, expanded: TextFieldLabelAlignment, minimized: TextFieldLabelAlignment, ) -> TextField
Configures the alignment in each label state. Above uses minimized.
Sourcepub fn placeholder_content(
self,
hint: impl Into<SharedString>,
element: impl IntoElement,
) -> TextField
pub fn placeholder_content( self, hint: impl Into<SharedString>, element: impl IntoElement, ) -> TextField
Replaces the Base placeholder’s presentation. hint is the accessible placeholder.
Sourcepub fn supporting_content(
self,
description: impl Into<SharedString>,
element: impl IntoElement,
) -> TextField
pub fn supporting_content( self, description: impl Into<SharedString>, element: impl IntoElement, ) -> TextField
Supplies custom supporting content and the field’s plain-text accessible description.
Sourcepub fn error(self, message: impl Into<SharedString>) -> TextField
pub fn error(self, message: impl Into<SharedString>) -> TextField
Displays an error message in place of the supporting text.
Sourcepub fn invalid(self, invalid: bool) -> TextField
pub fn invalid(self, invalid: bool) -> TextField
Sets the invalid visual and accessibility state independently of the supporting content.
Sourcepub fn required(self, required: bool) -> TextField
pub fn required(self, required: bool) -> TextField
Displays a required mark and reports the required state to assistive technology.
Sourcepub fn character_count(self, limit: usize) -> TextField
pub fn character_count(self, limit: usize) -> TextField
Shows a Unicode scalar count and the supplied limit. Base still owns validation. The count is omitted for secure or masked fields.
Sourcepub fn leading(self, element: impl IntoElement) -> TextField
pub fn leading(self, element: impl IntoElement) -> TextField
Places an adornment in the 48 dp leading icon slot.
Sourcepub fn trailing(self, element: impl IntoElement) -> TextField
pub fn trailing(self, element: impl IntoElement) -> TextField
Places an addon at the logical end of the editing region.
Sourcepub fn prefix(self, element: impl IntoElement) -> TextField
pub fn prefix(self, element: impl IntoElement) -> TextField
Places an element before the value while the label is minimized.
Sourcepub fn suffix(self, element: impl IntoElement) -> TextField
pub fn suffix(self, element: impl IntoElement) -> TextField
Places an element after the value while the label is minimized.
Trait Implementations§
Source§impl IntoElement for TextField
impl IntoElement for TextField
Source§type Element = ViewElement<TextField>
type Element = ViewElement<TextField>
Source§fn into_element(self) -> <TextField as IntoElement>::Element
fn into_element(self) -> <TextField as IntoElement>::Element
Element.Source§fn into_any_element(self) -> AnyElement
fn into_any_element(self) -> AnyElement
AnyElement.Source§impl RenderOnce for TextField
impl RenderOnce for TextField
Source§fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement
fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement
Render::render() method
which takes a mutable reference.Auto Trait Implementations§
impl !RefUnwindSafe for TextField
impl !Send for TextField
impl !Sync for TextField
impl !UnwindSafe for TextField
impl Forget for TextField
impl Freeze for TextField
impl Move for TextField
impl Unpin for TextField
impl UnsafeUnpin for TextField
Blanket Implementations§
Source§impl<E> AnimationExt for Ewhere
E: IntoElement + 'static,
impl<E> AnimationExt for Ewhere
E: IntoElement + 'static,
Source§fn with_animation(
self,
id: impl Into<ElementId>,
animation: Animation,
animator: impl Fn(Self, f32) -> Self + 'static,
) -> AnimationElement<Self>where
Self: Sized,
fn with_animation(
self,
id: impl Into<ElementId>,
animation: Animation,
animator: impl Fn(Self, f32) -> Self + 'static,
) -> AnimationElement<Self>where
Self: Sized,
Source§fn with_animations(
self,
id: impl Into<ElementId>,
animations: Vec<Animation>,
animator: impl Fn(Self, usize, f32) -> Self + 'static,
) -> AnimationElement<Self>where
Self: Sized,
fn with_animations(
self,
id: impl Into<ElementId>,
animations: Vec<Animation>,
animator: impl Fn(Self, usize, f32) -> Self + 'static,
) -> AnimationElement<Self>where
Self: Sized,
Source§fn with_spring<T>(
self,
id: impl Into<ElementId>,
animation: SpringAnimation<T>,
animator: impl FnOnce(Self, <T as SpringTarget>::Output) -> Self + 'static,
) -> SpringAnimationElement<Self>
fn with_spring<T>( self, id: impl Into<ElementId>, animation: SpringAnimation<T>, animator: impl FnOnce(Self, <T as SpringTarget>::Output) -> Self + 'static, ) -> SpringAnimationElement<Self>
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
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> FluentBuilder for Twhere
T: IntoElement,
impl<T> FluentBuilder for Twhere
T: IntoElement,
Source§fn map<U>(self, f: impl FnOnce(Self) -> U) -> Uwhere
Self: Sized,
fn map<U>(self, f: impl FnOnce(Self) -> U) -> Uwhere
Self: Sized,
Source§fn when(self, condition: bool, then: impl FnOnce(Self) -> Self) -> Selfwhere
Self: Sized,
fn when(self, condition: bool, then: impl FnOnce(Self) -> Self) -> Selfwhere
Self: Sized,
Source§fn when_else(
self,
condition: bool,
then: impl FnOnce(Self) -> Self,
else_fn: impl FnOnce(Self) -> Self,
) -> Selfwhere
Self: Sized,
fn when_else(
self,
condition: bool,
then: impl FnOnce(Self) -> Self,
else_fn: impl FnOnce(Self) -> Self,
) -> Selfwhere
Self: Sized,
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 moreSource§impl<T> MaterialElementExt for Twhere
T: IntoElement,
impl<T> MaterialElementExt for Twhere
T: IntoElement,
Source§fn badge_label(self, text: impl Into<SharedString>) -> Badge
fn badge_label(self, text: impl Into<SharedString>) -> Badge
Badge to this element’s upper trailing edge.Source§fn badge_count(self, count: usize, maximum: usize) -> Badge
fn badge_count(self, count: usize, maximum: usize) -> Badge
Badge to this element’s upper trailing edge.Source§fn tooltip(
self,
id: impl Into<ElementId>,
text: impl Into<SharedString>,
) -> Tooltip
fn tooltip( self, id: impl Into<ElementId>, text: impl Into<SharedString>, ) -> Tooltip
Tooltip.Menu.Source§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<E> TestTextExt for Ewhere
E: IntoElement,
impl<E> TestTextExt for Ewhere
E: IntoElement,
Source§fn test_text(self, text: impl Into<SharedString>) -> Self::Element
fn test_text(self, text: impl Into<SharedString>) -> Self::Element
test-support, records text each time the element paints.
Otherwise returns the element it builds.Source§fn test_alt_text(self, text: impl Into<SharedString>) -> Self::Element
fn test_alt_text(self, text: impl Into<SharedString>) -> Self::Element
Self::test_text for an image’s alternative text, which
stands in for what the element draws.