pub struct TextInput { /* private fields */ }Expand description
A focusable single-line (or multi-line) text field backed by a real
String buffer. Keyboard input is handled via key events (key_char +
editing keys), so typed characters genuinely appear and backspace deletes.
IME composition (e.g. Vietnamese/CJK input methods) is handled via the
EntityInputHandler impl, so composed text commits correctly.
This is a stateful view: create with cx.new(|cx| TextInput::new(cx)) and
store the resulting Entity<TextInput>.
Implementations§
Source§impl TextInput
impl TextInput
pub fn new(cx: &mut App) -> Self
pub fn placeholder(self, placeholder: impl Into<SharedString>) -> Self
pub fn multiline(self, multiline: bool) -> Self
Sourcepub fn submit_on_enter(self, submit_on_enter: bool) -> Self
pub fn submit_on_enter(self, submit_on_enter: bool) -> Self
When true, plain Enter fires Self::on_submit instead of
inserting a newline; Shift/Ctrl/Cmd+Enter still inserts a newline (in
multiline mode). Defaults to false, which preserves the previous
behavior of always inserting a newline on Enter in multiline mode
(e.g. CodeEditor’s free-form multiline input).
Sourcepub fn on_submit(
self,
handler: impl Fn(&mut Window, &mut Context<'_, Self>) + 'static,
) -> Self
pub fn on_submit( self, handler: impl Fn(&mut Window, &mut Context<'_, Self>) + 'static, ) -> Self
Registers a callback fired when the user presses plain Enter while
Self::submit_on_enter is true. Has no effect otherwise.
Sourcepub fn read_only(self, read_only: bool) -> Self
pub fn read_only(self, read_only: bool) -> Self
When true, the input no longer accepts keyboard edits (used for
read-only code previews). Focus/selection styling is unaffected.
Sourcepub fn invalid(self, invalid: bool) -> Self
pub fn invalid(self, invalid: bool) -> Self
Sets the error validation state (red border/ring) when invalid is
true, otherwise clears back to InputValidationState::Neutral.
Sourcepub fn success(self, success: bool) -> Self
pub fn success(self, success: bool) -> Self
Sets the success validation state (green border/ring) when success
is true, otherwise clears back to InputValidationState::Neutral.
Sourcepub fn warning(self, warning: bool) -> Self
pub fn warning(self, warning: bool) -> Self
Sets the warning validation state (amber border/ring) when warning
is true, otherwise clears back to InputValidationState::Neutral.
Sourcepub fn set_text(&mut self, text: impl Into<String>, cx: &mut Context<'_, Self>)
pub fn set_text(&mut self, text: impl Into<String>, cx: &mut Context<'_, Self>)
Programmatically sets the text content (e.g. SearchInput/Combobox
setting the display text after a selection). Notifies for re-render.
Sourcepub fn clear(&mut self, cx: &mut Context<'_, Self>)
pub fn clear(&mut self, cx: &mut Context<'_, Self>)
Clears the text content (e.g. SearchInput’s clear button). Notifies
for re-render.
Sourcepub fn set_read_only(&mut self, read_only: bool, cx: &mut Context<'_, Self>)
pub fn set_read_only(&mut self, read_only: bool, cx: &mut Context<'_, Self>)
Dynamically toggles read-only mode after construction (e.g.
CodeEditor switching an already-created input between editable and
preview modes). Notifies for re-render.
Trait Implementations§
Source§impl EntityInputHandler for TextInput
impl EntityInputHandler for TextInput
Source§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>
No cursor/selection tracking — this is an append-only field. Returning
None tells the platform there is no active selection (IME commits at
the end).
Source§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>>
The byte range of in-progress IME marked (composition) text.
Source§fn text_for_range(
&mut self,
range_utf16: Range<usize>,
_adjusted_range: &mut Option<Range<usize>>,
_window: &mut Window,
_cx: &mut Context<'_, Self>,
) -> Option<String>
fn text_for_range( &mut self, range_utf16: Range<usize>, _adjusted_range: &mut Option<Range<usize>>, _window: &mut Window, _cx: &mut Context<'_, Self>, ) -> Option<String>
Returns the text in the given UTF-16 range (used by the platform to read back what’s around the composition).
Source§fn replace_text_in_range(
&mut self,
range: Option<Range<usize>>,
text: &str,
_window: &mut Window,
cx: &mut Context<'_, Self>,
)
fn replace_text_in_range( &mut self, range: Option<Range<usize>>, text: &str, _window: &mut Window, cx: &mut Context<'_, Self>, )
IME committed text (or a plain paste/insert). Replaces any in-progress marked range, otherwise appends at the end.
Source§fn replace_and_mark_text_in_range(
&mut self,
range: Option<Range<usize>>,
new_text: &str,
_new_selected_range: Option<Range<usize>>,
_window: &mut Window,
cx: &mut Context<'_, Self>,
)
fn replace_and_mark_text_in_range( &mut self, range: Option<Range<usize>>, new_text: &str, _new_selected_range: Option<Range<usize>>, _window: &mut Window, cx: &mut Context<'_, Self>, )
IME composition in progress — replace the given range (or append) with
new_text and mark it as the active composition range.
Source§fn unmark_text(&mut self, _window: &mut Window, cx: &mut Context<'_, Self>)
fn unmark_text(&mut self, _window: &mut Window, cx: &mut Context<'_, Self>)
Composition finalized/abandoned — drop the mark without changing text.
Source§fn bounds_for_range(
&mut self,
_range_utf16: Range<usize>,
element_bounds: Bounds<Pixels>,
_window: &mut Window,
_cx: &mut Context<'_, Self>,
) -> Option<Bounds<Pixels>>
fn bounds_for_range( &mut self, _range_utf16: Range<usize>, element_bounds: Bounds<Pixels>, _window: &mut Window, _cx: &mut Context<'_, Self>, ) -> Option<Bounds<Pixels>>
Bounds for a UTF-16 range within the field, for IME candidate placement. Best-effort: returns the element bounds (candidates appear near the field, not pixel-perfect per-character).
Source§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 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§impl Focusable for TextInput
impl Focusable for TextInput
Source§fn focus_handle(&self, _cx: &App) -> FocusHandle
fn focus_handle(&self, _cx: &App) -> FocusHandle
Auto Trait Implementations§
impl !RefUnwindSafe for TextInput
impl !Send for TextInput
impl !Sync for TextInput
impl !UnwindSafe for TextInput
impl Freeze for TextInput
impl Unpin for TextInput
impl UnsafeUnpin for TextInput
Blanket Implementations§
Source§impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
T: Real + Zero + Arithmetics + Clone,
Swp: WhitePoint<T>,
Dwp: WhitePoint<T>,
D: AdaptFrom<S, Swp, Dwp, T>,
impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
T: Real + Zero + Arithmetics + Clone,
Swp: WhitePoint<T>,
Dwp: WhitePoint<T>,
D: AdaptFrom<S, Swp, Dwp, T>,
Source§fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<T>,
fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<T>,
Source§fn adapt_into(self) -> D
fn adapt_into(self) -> D
Source§impl<T, C> ArraysFrom<C> for Twhere
C: IntoArrays<T>,
impl<T, C> ArraysFrom<C> for Twhere
C: IntoArrays<T>,
Source§fn arrays_from(colors: C) -> T
fn arrays_from(colors: C) -> T
Source§impl<T, C> ArraysInto<C> for Twhere
C: FromArrays<T>,
impl<T, C> ArraysInto<C> for Twhere
C: FromArrays<T>,
Source§fn arrays_into(self) -> C
fn arrays_into(self) -> C
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<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for Uwhere
T: FromCam16Unclamped<WpParam, U>,
impl<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for Uwhere
T: FromCam16Unclamped<WpParam, U>,
Source§type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar
type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar
parameters when converting.Source§fn cam16_into_unclamped(
self,
parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>,
) -> T
fn cam16_into_unclamped( self, parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>, ) -> T
self into C, using the provided parameters.impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T, C> ComponentsFrom<C> for Twhere
C: IntoComponents<T>,
impl<T, C> ComponentsFrom<C> for Twhere
C: IntoComponents<T>,
Source§fn components_from(colors: C) -> T
fn components_from(colors: C) -> T
Source§impl<T> FromAngle<T> for T
impl<T> FromAngle<T> for T
Source§fn from_angle(angle: T) -> T
fn from_angle(angle: T) -> T
angle.Source§impl<T, U> FromStimulus<U> for Twhere
U: IntoStimulus<T>,
impl<T, U> FromStimulus<U> for Twhere
U: IntoStimulus<T>,
Source§fn from_stimulus(other: U) -> T
fn from_stimulus(other: U) -> T
other into Self, while performing the appropriate scaling,
rounding and clamping.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, U> IntoAngle<U> for Twhere
U: FromAngle<T>,
impl<T, U> IntoAngle<U> for Twhere
U: FromAngle<T>,
Source§fn into_angle(self) -> U
fn into_angle(self) -> U
T.Source§impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for Uwhere
T: Cam16FromUnclamped<WpParam, U>,
impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for Uwhere
T: Cam16FromUnclamped<WpParam, U>,
Source§type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar
type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar
parameters when converting.Source§fn into_cam16_unclamped(
self,
parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>,
) -> T
fn into_cam16_unclamped( self, parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>, ) -> T
self into C, using the provided parameters.Source§impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
Source§fn into_color(self) -> U
fn into_color(self) -> U
Source§impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
Source§fn into_color_unclamped(self) -> U
fn into_color_unclamped(self) -> U
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> IntoStimulus<T> for T
impl<T> IntoStimulus<T> for T
Source§fn into_stimulus(self) -> T
fn into_stimulus(self) -> T
self into T, while performing the appropriate scaling,
rounding and clamping.Source§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
impl<T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
Source§type Error = <C as TryFromComponents<T>>::Error
type Error = <C as TryFromComponents<T>>::Error
try_into_colors fails to cast.Source§fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>
fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>
Source§impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
Source§fn try_into_color(self) -> Result<U, OutOfBounds<U>>
fn try_into_color(self) -> Result<U, OutOfBounds<U>>
OutOfBounds error is returned which contains
the unclamped color. Read more