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
impl TextInput
Sourcepub fn with_placeholder(self, placeholder: impl Into<String>) -> Self
pub fn with_placeholder(self, placeholder: impl Into<String>) -> Self
The input showing placeholder, dimmed, while it is empty.
Sourcepub fn set_text(
&mut self,
cx: &mut EventCx<'_>,
text: impl Into<String>,
) -> Result<(), ParagraphError>
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.
Sourcepub fn has_selection(&self) -> bool
pub fn has_selection(&self) -> bool
Whether text is selected, to cut or copy.
Sourcepub fn copy(&mut self, cx: &mut EventCx<'_>) -> bool
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.
Sourcepub fn cut(&mut self, cx: &mut EventCx<'_>) -> bool
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).
Sourcepub fn paste(&mut self, cx: &mut EventCx<'_>) -> bool
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.
Trait Implementations§
Source§impl Widget for TextInput
impl Widget for TextInput
Source§fn accessibility(&self, _: &PaintCx<'_>, node: &mut AccessNode)
fn accessibility(&self, _: &PaintCx<'_>, node: &mut AccessNode)
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
fn access_action( &mut self, cx: &mut EventCx<'_>, request: &AccessRequest<'_>, ) -> Handled
Source§fn measure(&mut self, cx: &mut LayoutCx<'_>, _: Constraints) -> Size
fn measure(&mut self, cx: &mut LayoutCx<'_>, _: Constraints) -> Size
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)
fn layout(&mut self, cx: &mut LayoutCx<'_>, size: Size)
Source§fn paint(&mut self, cx: &PaintCx<'_>, canvas: &mut Canvas<'_>)
fn paint(&mut self, cx: &PaintCx<'_>, canvas: &mut Canvas<'_>)
Source§fn event(&mut self, cx: &mut EventCx<'_>, event: &Event<'_>) -> Handled
fn event(&mut self, cx: &mut EventCx<'_>, event: &Event<'_>) -> Handled
event. An event the widget does not handle goes on to its parent.