Skip to main content

TextInput

Struct TextInput 

Source
pub struct TextInput { /* private fields */ }
Expand description

A single line of editable text. Reports ActionKind::Changed after every edit and ActionKind::Submitted on Enter.

Clicks place the caret (two select a word, three everything), dragging selects, the arrow keys and Home/End move (with Shift: select; with Ctrl, or Cmd on macOS: by word), Backspace and Delete remove characters or words, and input methods compose in place.

Ctrl (Cmd on macOS) with X, C and V cuts, copies and pastes through the Ui’s clipboard, as do Shift+Delete, Ctrl+Insert and Shift+Insert; pasted line breaks become spaces. Ctrl+Z undoes, Ctrl+Y or Ctrl+Shift+Z redoes (see TextEditor for what one step is). An application’s Edit menu calls the same cut, copy, paste, undo and redo from an Ui::update on the input.

Implementations§

Source§

impl TextInput

Source

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

An input holding text.

Source

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

The input showing placeholder, dimmed, while it is empty.

Source

pub fn text(&self) -> &str

The text.

Source

pub fn set_text( &mut self, cx: &mut EventCx<'_>, text: impl Into<String>, ) -> Result<(), ParagraphError>

Replaces the text, the caret at its end.

§Errors

ParagraphError::UnreadableFont if a font for text cannot be read; nothing changes.

Source

pub fn has_selection(&self) -> bool

Whether text is selected, to cut or copy.

Source

pub fn can_undo(&self) -> bool

Whether there is an edit to undo.

Source

pub fn can_redo(&self) -> bool

Whether there is an edit to redo.

Source

pub fn copy(&mut self, cx: &mut EventCx<'_>) -> bool

Puts the selected text on the clipboard; false if none is selected, an input method is composing, or the clipboard would not take it.

Source

pub fn cut(&mut self, cx: &mut EventCx<'_>) -> bool

Copies the selected text and deletes it; nothing is deleted unless it was copied. The edit methods return false when the text did not change, including when it could not be laid out again (a font that cannot be read).

Source

pub fn paste(&mut self, cx: &mut EventCx<'_>) -> bool

Replaces the selection with the clipboard’s text, its line breaks made spaces; false if the clipboard holds no text.

Source

pub fn undo(&mut self, cx: &mut EventCx<'_>) -> bool

Takes back the last edit; false if there is none.

Source

pub fn redo(&mut self, cx: &mut EventCx<'_>) -> bool

Makes the last undone edit again; false if there is none.

Trait Implementations§

Source§

impl Debug for TextInput

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Widget for TextInput

Source§

fn accessibility(&self, _: &PaintCx<'_>, node: &mut AccessNode)

Describes the widget to assistive technology: fills node, which starts as a Role::Group with the widget’s rectangle. Called only while assistive technology is listening; it may allocate.
Source§

fn access_action( &mut self, cx: &mut EventCx<'_>, request: &AccessRequest<'_>, ) -> Handled

Does what assistive technology asks (only actions the widget’s node lists are asked of it). Focus and scrolling into view are done for every widget; a request the widget does not handle goes on to its parent if it is a scroll.
Source§

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

The size the widget wants within constraints, for a widget without children (one with children is sized by its style and its children). Physical pixels.
Source§

fn layout(&mut self, cx: &mut LayoutCx<'_>, size: Size)

Layout decided the widget’s size: re-wrap text or recompute anything that depends on it. Called after every layout pass that changed the size.
Source§

fn paint(&mut self, cx: &PaintCx<'_>, canvas: &mut Canvas<'_>)

Paints the widget below its children.
Source§

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

Handles event. An event the widget does not handle goes on to its parent.
Source§

fn accepts_focus(&self) -> bool

Whether the widget takes keyboard focus, by click or by Tab.
Source§

fn paint_over(&mut self, cx: &PaintCx<'_>, canvas: &mut Canvas<'_>)

Paints the widget over its children: scroll bars, focus rings, overlays.
Source§

fn focus_on_press(&self) -> bool

Whether a press on the widget, or on a widget inside it that takes no focus, focuses it (if it accepts focus). A container reachable by Tab, such as a dock’s tab list, says no, so clicks on its contents do not focus it; it can still ask for focus itself.

Auto Trait Implementations§

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> ErasedDestructor for T
where T: 'static,

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