pub struct TextInput<Msg> { /* private fields */ }Expand description
A text field with real editing: cursor, selection, word jumps, undo and clipboard.
The application owns the value and receives every change through on_change; cursor,
selection and undo history live in the runtime.
Keys: ←/→ move (with Ctrl by word, with Shift selecting), Home/End, Backspace/Delete, Ctrl+W deletes a word, Ctrl+U deletes to the start, Ctrl+A selects all, Ctrl+Z undo, Ctrl+Y or Ctrl+Shift+Z redo, Ctrl+C and Ctrl+X copy and cut the selection, Enter submits. With a selection, ← and → clear it and move one step on from its left or right end. Pasting inserts text. Clicking places the cursor; dragging selects.
select_on_focus opens the field with part of its text selected,
such as the name without its extension in a rename dialog; typing then replaces just that part.
A right click (or Shift+F10 and the menu key) opens an edit menu with Cut, Copy, Paste and
Select all. A right click inside the selection keeps it; elsewhere it first places the
cursor there. Cut and Copy are disabled without a selection, and always in password fields,
which never copy; Paste is disabled while there is nothing to paste. Paste reads the system
clipboard, then the terminal’s, then the text the application copied last. Entry names are
quvyta.edit.*.
Style keys: text-input (bg, fg, padding) with hover, focus, invalid,
disabled; text-input-prompt, text-input-placeholder, text-input-selection,
text-input-cursor.
Implementations§
Source§impl<Msg: 'static> TextInput<Msg>
impl<Msg: 'static> TextInput<Msg>
Sourcepub fn placeholder(self, text: impl Into<String>) -> Self
pub fn placeholder(self, text: impl Into<String>) -> Self
Faint text shown while the field is empty.
Sourcepub fn max_length(self, max: usize) -> Self
pub fn max_length(self, max: usize) -> Self
Limits the value to max characters.
Sourcepub fn on_change(self, message: impl Fn(String) -> Msg + 'static) -> Self
pub fn on_change(self, message: impl Fn(String) -> Msg + 'static) -> Self
Message carrying the new value after every edit.
Sourcepub fn on_submit(self, message: impl Fn(String) -> Msg + 'static) -> Self
pub fn on_submit(self, message: impl Fn(String) -> Msg + 'static) -> Self
Message carrying the value when Enter is pressed.
Sourcepub fn select_on_focus(self, range: Range<usize>) -> Self
pub fn select_on_focus(self, range: Range<usize>) -> Self
Selects the characters in range each time the field gains focus, with the cursor at the
range’s end, e.g. 0..4 to select main in main.rs. The range counts characters, not
bytes, and is cut to the text. From then on the selection is the user’s: typing replaces
it, the arrows drop it, and a value changed from outside does not bring it back. A click
that gives the field focus places the cursor instead.
Sourcepub fn select_all_on_focus(self) -> Self
pub fn select_all_on_focus(self) -> Self
Selects the whole text each time the field gains focus, like
select_on_focus with a range covering every character.
Trait Implementations§
Source§impl<Msg: 'static> Widget<Msg> for TextInput<Msg>
impl<Msg: 'static> Widget<Msg> for TextInput<Msg>
Source§fn measure(&self, cx: &mut MeasureCx<'_>, available: Size) -> Size
fn measure(&self, cx: &mut MeasureCx<'_>, available: Size) -> Size
available.Source§fn paint_overlay(&self, cx: &mut PaintCx<'_>, anchor: Rect)
fn paint_overlay(&self, cx: &mut PaintCx<'_>, anchor: Rect)
PaintCx::request_overlay. anchor is the area the widget was painted in.Source§fn event(&self, cx: &mut EventCx<'_, Msg>, event: &Event) -> bool
fn event(&self, cx: &mut EventCx<'_, Msg>, event: &Event) -> bool
true when the event was used; unused key and scroll events
bubble to the parent widget.Source§fn children_mut(&mut self) -> &mut [Node<Msg>]
fn children_mut(&mut self) -> &mut [Node<Msg>]
Auto Trait Implementations§
impl<Msg> !RefUnwindSafe for TextInput<Msg>
impl<Msg> !Send for TextInput<Msg>
impl<Msg> !Sync for TextInput<Msg>
impl<Msg> !UnwindSafe for TextInput<Msg>
impl<Msg> Freeze for TextInput<Msg>
impl<Msg> Unpin for TextInput<Msg>
impl<Msg> UnsafeUnpin for TextInput<Msg>
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
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 more