Skip to main content

TextInput

Struct TextInput 

Source
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.

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>

Source

pub fn new(value: impl Into<String>) -> Self

A field showing value.

Source

pub fn placeholder(self, text: impl Into<String>) -> Self

Faint text shown while the field is empty.

Source

pub fn password(self, password: bool) -> Self

Masks every character.

Source

pub fn invalid(self, invalid: bool) -> Self

Marks the value as failing validation.

Source

pub fn disabled(self, disabled: bool) -> Self

Makes the field read-only and unfocusable.

Source

pub fn max_length(self, max: usize) -> Self

Limits the value to max characters.

Source

pub fn on_change(self, message: impl Fn(String) -> Msg + 'static) -> Self

Message carrying the new value after every edit.

Source

pub fn on_submit(self, message: impl Fn(String) -> Msg + 'static) -> Self

Message carrying the value when Enter is pressed.

Trait Implementations§

Source§

impl<Msg: 'static> Widget<Msg> for TextInput<Msg>

Source§

fn measure(&self, cx: &mut MeasureCx<'_>, available: Size) -> Size

The size the widget wants when it may use up to available.
Source§

fn paint(&self, cx: &mut PaintCx<'_>, area: Rect)

Draws the widget into area.
Source§

fn paint_overlay(&self, cx: &mut PaintCx<'_>, anchor: Rect)

Draws the widget’s overlay after the whole view was painted, when it asked for one with PaintCx::request_overlay. anchor is the area the widget was painted in.
Source§

fn event(&self, cx: &mut EventCx<'_, Msg>, event: &Event) -> bool

Handles input. Returns true when the event was used; unused key and scroll events bubble to the parent widget.
Source§

fn focusable(&self) -> bool

Whether the widget can take keyboard focus.
Source§

fn children(&self) -> &[Node<Msg>]

Child nodes, for widgets that contain other widgets.
Source§

fn children_mut(&mut self) -> &mut [Node<Msg>]

Mutable child nodes, used to assign ids.

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>
where Option<Box<dyn Fn(String) -> Msg>>: Freeze,

§

impl<Msg> Unpin for TextInput<Msg>
where Option<Box<dyn Fn(String) -> Msg>>: Unpin,

§

impl<Msg> UnsafeUnpin for TextInput<Msg>
where Option<Box<dyn Fn(String) -> Msg>>: UnsafeUnpin,

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
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.