pub struct TextArea<M, D = TextBuffer> { /* private fields */ }Expand description
Lines of text somebody edits, drawn from a TextDocument.
§Blinking
As TextInput: the caret blinks only while the widget
has focus, and an unfocused editor asks for no frames.
§Focus
No focus ring. The caret is the sign that the keyboard goes here, and a ring around a widget the size of a window would frame the whole window.
§Moving by word
Ctrl and an arrow move by word, and so does Option on a Mac; Command and an arrow go to the start or end of the line, and with Home or End to the start or end of the document. Shift extends with all of them.
§Selecting
A press places the caret, a second on the same spot takes the word under it,
and a third takes the line — its text, not the newline after it, so deleting
a line taken that way leaves an empty one rather than pulling the next one
up. A fourth press starts the count again. Dragging extends from where the
press landed, and Shift extends with the arrows, Home, End and a click. The
word rule is TextInput’s, shared so that a
double-click takes the same run of characters in a field as in an editor.
Implementations§
Source§impl<M> TextArea<M, TextBuffer>
impl<M> TextArea<M, TextBuffer>
Source§impl<M, D: TextDocument> TextArea<M, D>
impl<M, D: TextDocument> TextArea<M, D>
Sourcepub fn with_change(self, message: M) -> Self
pub fn with_change(self, message: M) -> Self
Sets the message emitted after every edit a person makes.
Sourcepub fn with_clipboard(self, message: fn(ClipboardRequest) -> M) -> Self
pub fn with_clipboard(self, message: fn(ClipboardRequest) -> M) -> Self
Sets how clipboard requests reach the application. Without it, copy, cut and paste do nothing.
Sourcepub fn with_style(self, style: TextStyle) -> Self
pub fn with_style(self, style: TextStyle) -> Self
Sets the font and size.
Sourcepub fn with_gutter(self, gutter: bool) -> Self
pub fn with_gutter(self, gutter: bool) -> Self
Whether to number the lines down the left.
Sourcepub fn with_tab_width(self, columns: u8) -> Self
pub fn with_tab_width(self, columns: u8) -> Self
Sets how many columns apart the tab stops are; four unless told. A column is a space wide, and at least one.
Sourcepub fn with_read_only(self, read_only: bool) -> Self
pub fn with_read_only(self, read_only: bool) -> Self
Shows the text and places a caret in it, but changes nothing.
Sourcepub fn with_smooth_scroll(self, smooth: bool) -> Self
pub fn with_smooth_scroll(self, smooth: bool) -> Self
Whether the wheel moves the text a pixel at a time, as a trackpad reports it, rather than a whole line once a line’s worth has built up. Off unless told. A fast wheel goes as far either way.
Sourcepub fn document_mut(&mut self) -> &mut D
pub fn document_mut(&mut self) -> &mut D
The document, to change. Silent; the caret is clamped to whatever the document says next time it is used.
Sourcepub fn set_document(&mut self, doc: D)
pub fn set_document(&mut self, doc: D)
Replaces the document, putting the caret at the start.
Sourcepub fn set_style(&mut self, style: TextStyle)
pub fn set_style(&mut self, style: TextStyle)
Replaces the font and size. The measured width of the text goes with the old font, and is taken again as the lines are drawn.
Sourcepub fn set_gutter(&mut self, gutter: bool)
pub fn set_gutter(&mut self, gutter: bool)
Numbers the lines, or stops.
Sourcepub fn set_tab_width(&mut self, columns: u8)
pub fn set_tab_width(&mut self, columns: u8)
Moves the tab stops columns apart, at least one. Tabs are part of
how wide a line is, so that is measured again as the lines are drawn.
Sourcepub const fn is_read_only(&self) -> bool
pub const fn is_read_only(&self) -> bool
Whether editing is off.
Sourcepub fn set_read_only(&mut self, read_only: bool)
pub fn set_read_only(&mut self, read_only: bool)
Turns editing off or on.
Sourcepub const fn smooth_scroll(&self) -> bool
pub const fn smooth_scroll(&self) -> bool
Whether the wheel scrolls a pixel at a time.
Sourcepub fn set_smooth_scroll(&mut self, smooth: bool)
pub fn set_smooth_scroll(&mut self, smooth: bool)
Scrolls by the pixel, or by the line. Turned off, the view settles on the line it was part way through.
Sourcepub fn set_caret(&mut self, pos: Pos)
pub fn set_caret(&mut self, pos: Pos)
Puts the caret at pos, clamped to the document, and clears the
selection. The view follows on the next event or paint.
Sourcepub fn selection(&self) -> Option<(Pos, Pos)>
pub fn selection(&self) -> Option<(Pos, Pos)>
The selection as (from, to), or None if nothing is selected.
Sourcepub fn select_all(&mut self)
pub fn select_all(&mut self)
Selects everything.
Sourcepub fn selected_text(&self) -> Option<String>
pub fn selected_text(&self) -> Option<String>
The selected text, lines joined by \n, or None if nothing is
selected.
Sourcepub fn insert_text(&mut self, text: &str)
pub fn insert_text(&mut self, text: &str)
Replaces the selection, or inserts at the caret, and leaves the caret
after the text. Silent: this is how an application answers a
ClipboardRequest::Paste, and it knows it did.
Sourcepub fn set_top(&mut self, line: usize)
pub fn set_top(&mut self, line: usize)
Scrolls so line is the first drawn, clamped to the lines known.
Sourcepub const fn top_px(&self) -> i32
pub const fn top_px(&self) -> i32
Pixels of the first line drawn that are scrolled up out of view: 0
unless smooth_scroll is on, and less than a
row.
Sourcepub fn visible_rows(&self) -> usize
pub fn visible_rows(&self) -> usize
Whole rows the last paint had room for; 0 before the first.
Sourcepub fn go_to(&mut self, line: usize)
pub fn go_to(&mut self, line: usize)
Puts the caret at the start of 0-based line, clamped to the lines
known, and scrolls so the line sits in the middle of the view — as
far as the last paint’s row count can say where the middle is.
Sourcepub fn select_range(&mut self, from: Pos, to: Pos)
pub fn select_range(&mut self, from: Pos, to: Pos)
Selects [from, to) with the caret at to, both clamped to the
document, and scrolls the selection into view: centred on its first
line if that was off screen, and sideways on the next paint, which has
the fonts to measure it with. What a find lands on. Silent.
Trait Implementations§
Source§impl<M> Default for TextArea<M, TextBuffer>
impl<M> Default for TextArea<M, TextBuffer>
Source§impl<M, D: TextDocument> Describe for TextArea<M, D>
impl<M, D: TextDocument> Describe for TextArea<M, D>
Source§const DOC: &'static str = "Lines of text somebody edits."
const DOC: &'static str = "Lines of text somebody edits."
Source§const ICON: &'static Icon
const ICON: &'static Icon
Source§const PROPERTIES: &'static [Property]
const PROPERTIES: &'static [Property]
Source§impl<M: Clone + 'static, D: TextDocument> Widget<M> for TextArea<M, D>
impl<M: Clone + 'static, D: TextDocument> Widget<M> for TextArea<M, D>
Source§fn snap(&mut self, now_ms: u64) -> Animation
fn snap(&mut self, now_ms: u64) -> Animation
Blinking is a schedule, not a motion; see TextInput.
Source§fn describe(&self) -> Option<&dyn DynDescribe>
fn describe(&self) -> Option<&dyn DynDescribe>
Source§fn describe_mut(&mut self) -> Option<&mut dyn DynDescribe>
fn describe_mut(&mut self) -> Option<&mut dyn DynDescribe>
describe.Source§fn measure(&self, ctx: &mut MeasureCtx<'_>, _offered: Offer) -> Measured
fn measure(&self, ctx: &mut MeasureCtx<'_>, _offered: Offer) -> Measured
Source§fn paint(&self, ctx: &mut PaintCtx<'_>, canvas: &mut Pen<'_>)
fn paint(&self, ctx: &mut PaintCtx<'_>, canvas: &mut Pen<'_>)
canvas, which is already clipped to this widget’s bounds
intersected with the damage region being repainted. Read moreSource§fn on_event(&mut self, event: &Event<'_>, ctx: &mut EventCtx<'_, M>) -> Handled
fn on_event(&mut self, event: &Event<'_>, ctx: &mut EventCtx<'_, M>) -> Handled
Source§fn accepts_pointer(&self) -> bool
fn accepts_pointer(&self) -> bool
true if the pointer can hit this widget. Read moreSource§fn animate(&mut self, now_ms: u64) -> Animation
fn animate(&mut self, now_ms: u64) -> Animation
EventCtx::request_animation — and stops being called
the moment it answers Wake::Never. Read moreSource§fn preserves_focus(&self) -> bool
fn preserves_focus(&self) -> bool
true if a press on this widget should leave focus exactly where
it is. Read moreAuto Trait Implementations§
impl<M, D = TextBuffer> !Freeze for TextArea<M, D>
impl<M, D = TextBuffer> !RefUnwindSafe for TextArea<M, D>
impl<M, D = TextBuffer> !Sync for TextArea<M, D>
impl<M, D> Send for TextArea<M, D>
impl<M, D> Unpin for TextArea<M, D>
impl<M, D> UnsafeUnpin for TextArea<M, D>where
RefCell<D>: UnsafeUnpin,
Option<M>: UnsafeUnpin,
Option<fn(ClipboardRequest) -> M>: UnsafeUnpin,
impl<M, D> UnwindSafe for TextArea<M, D>
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> DynDescribe for Twhere
T: Describe,
impl<T> DynDescribe for Twhere
T: Describe,
Source§fn kind(&self) -> &'static str
fn kind(&self) -> &'static str
Describe::KIND.Source§fn properties(&self) -> &'static [Property]
fn properties(&self) -> &'static [Property]
Describe::PROPERTIES.Source§fn get_property(&self, name: &str) -> Option<Value>
fn get_property(&self, name: &str) -> Option<Value>
Describe::get.Source§fn set_property(
&mut self,
name: &str,
value: Value,
) -> Result<(), PropertyError>
fn set_property( &mut self, name: &str, value: Value, ) -> Result<(), PropertyError>
Describe::set.