Struct rat_widget::textarea::TextArea
source · pub struct TextArea<'a> { /* private fields */ }Expand description
Text area widget.
Backend used is ropey, so large texts are no problem. Editing time increases with the number of styles applied. Everything below a million styles should be fine.
For emoji support this uses unicode_display_width which helps with those double-width emojis. Input of emojis strongly depends on the terminal. It may or may not work. And even with display there are sometimes strange glitches that I haven’t found yet.
Keyboard and mouse are implemented for crossterm, but it should be easy to extend to other event-types. Every interaction is available as function on the state.
Scrolling doesn’t depend on the cursor, but the editing and move functions take care that the cursor stays visible.
Wordwrap is not available. For display only use Paragraph, as for editing: why?
You can directly access the underlying Rope for readonly purposes, and conversion from/to byte/char positions are available. That should probably be enough to write a parser that generates some styling.
The cursor must set externally on the ratatui Frame as usual. screen_cursor gives you the correct value. There is the inverse too set_screen_cursor For more interactions you can use from_screen_col, and to_screen_col. They calculate everything, even in the presence of more complex graphemes and those double-width emojis.
Implementations§
source§impl<'a> TextArea<'a>
impl<'a> TextArea<'a>
sourcepub fn styles(self, style: TextAreaStyle) -> TextArea<'a>
pub fn styles(self, style: TextAreaStyle) -> TextArea<'a>
Set the combined style.
sourcepub fn focus_style(self, style: Style) -> TextArea<'a>
pub fn focus_style(self, style: Style) -> TextArea<'a>
Style when focused.
sourcepub fn select_style(self, style: Style) -> TextArea<'a>
pub fn select_style(self, style: Style) -> TextArea<'a>
Selection style.
sourcepub fn text_style<T>(self, styles: T) -> TextArea<'a>where
T: IntoIterator<Item = Style>,
pub fn text_style<T>(self, styles: T) -> TextArea<'a>where
T: IntoIterator<Item = Style>,
List of text-styles.
Use TextAreaState::add_style() to refer a text range to one of these styles.
sourcepub fn set_horizontal_max_offset(self, offset: usize) -> TextArea<'a>
pub fn set_horizontal_max_offset(self, offset: usize) -> TextArea<'a>
Set a maximum horizontal offset that will be used even if there is no horizontal scrollbar set.
This widget doesn’t try to find a maximum text-length for all lines.
Default is 255
sourcepub fn set_horizontal_overscroll(self, overscroll: usize) -> TextArea<'a>
pub fn set_horizontal_overscroll(self, overscroll: usize) -> TextArea<'a>
Set a horizontal overscroll that will be used even if there is no horizontal scrollbar set.
Default is 16384
Trait Implementations§
source§impl<'a> StatefulWidget for TextArea<'a>
impl<'a> StatefulWidget for TextArea<'a>
source§type State = TextAreaState
type State = TextAreaState
Auto Trait Implementations§
impl<'a> Freeze for TextArea<'a>
impl<'a> RefUnwindSafe for TextArea<'a>
impl<'a> Send for TextArea<'a>
impl<'a> Sync for TextArea<'a>
impl<'a> Unpin for TextArea<'a>
impl<'a> UnwindSafe for TextArea<'a>
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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