Skip to main content

TextArea

Struct TextArea 

Source
pub struct TextArea<Msg> { /* private fields */ }
Expand description

A multi-line text field with word wrap, scrolling and real editing.

Long lines wrap at word boundaries and the area scrolls vertically with a scrollbar once the text is taller than the area. The area measures three to eight rows, growing with its content; give the node a height for a fixed size. The application owns the value and receives every change through on_change; cursor, selection, scroll and undo history live in the runtime.

Keys: Enter inserts a line break. ←/→ move (with Ctrl by word), ↑/↓ move between rows keeping the column, Page Up/Page Down move a page, Home/End go to the row’s start and end (with Ctrl to the text’s), and Shift extends the selection with any of them. Without Shift an arrow clears a selection and moves one step on from its end in that direction. Backspace and Delete, Ctrl+W deletes a word, Ctrl+U deletes to the line start, Ctrl+A selects all, Ctrl+Z undo, Ctrl+Y or Ctrl+Shift+Z redo, Ctrl+C and Ctrl+X copy and cut. Ctrl+Enter submits when TextArea::on_submit is set; terminals without the kitty keyboard protocol may not report it, so offer a button as well. Pasting keeps line breaks. Clicking places the cursor, dragging selects, the wheel and the scrollbar scroll.

A right click (or Shift+F10 and the menu key) opens the edit menu of TextInput: Cut, Copy, Paste and Select all, with the same rules.

Style keys: text-area (bg, fg, padding) with hover, focus, invalid, disabled; text-area-line-number (fg) with selected on the cursor’s line; text-area-counter (fg); and the text input’s text-input-placeholder, text-input-selection, text-input-cursor and scrollbar.

Implementations§

Source§

impl<Msg: 'static> TextArea<Msg>

Source

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

An area showing value.

Source

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

Faint text shown while the area is empty.

Source

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

Marks the value as failing validation.

Source

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

Makes the area read-only and unfocusable.

Source

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

Limits the value to max characters; a line break counts as one.

Source

pub fn line_numbers(self, on: bool) -> Self

Numbers every line in a faint column on the left; wrapped rows are not numbered.

Source

pub fn counter(self, on: bool) -> Self

Shows the character count on a row below the text, with the limit when there is one.

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 Ctrl+Enter is pressed.

Trait Implementations§

Source§

impl<Msg: 'static> Widget<Msg> for TextArea<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 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 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 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 TextArea<Msg>

§

impl<Msg> !Send for TextArea<Msg>

§

impl<Msg> !Sync for TextArea<Msg>

§

impl<Msg> !UnwindSafe for TextArea<Msg>

§

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

§

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

§

impl<Msg> UnsafeUnpin for TextArea<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.