rat_text::text_input

Struct TextInputState

Source
pub struct TextInputState {
    pub area: Rect,
    pub inner: Rect,
    pub offset: upos_type,
    pub dark_offset: (u16, u16),
    pub value: TextCore<TextString>,
    pub invalid: bool,
    pub focus: FocusFlag,
    pub mouse: MouseFlags,
    pub non_exhaustive: NonExhaustive,
}
Expand description

State for TextInput.

Fields§

§area: Rect

The whole area with block. read only renewed with each render.

§inner: Rect

Area inside a possible block. read only renewed with each render.

§offset: upos_type

Display offset read+write

§dark_offset: (u16, u16)

Dark offset due to clipping. read only secondary offset due to clipping.

§value: TextCore<TextString>

Editing core

§invalid: bool

Display as invalid. read+write

§focus: FocusFlag

Current focus state. read+write

§mouse: MouseFlags

Mouse selection in progress. read+write

§non_exhaustive: NonExhaustive

Construct with ..Default::default()

Implementations§

Source§

impl TextInputState

Source

pub fn new() -> Self

Source

pub fn named(name: &str) -> Self

Source

pub fn set_invalid(&mut self, invalid: bool)

Renders the widget in invalid style.

Source

pub fn get_invalid(&self) -> bool

Renders the widget in invalid style.

Source§

impl TextInputState

Source

pub fn set_clipboard(&mut self, clip: Option<impl Clipboard + 'static>)

Clipboard

Source

pub fn clipboard(&self) -> Option<&dyn Clipboard>

Clipboard

Source

pub fn copy_to_clip(&mut self) -> bool

Copy to internal buffer

Source

pub fn cut_to_clip(&mut self) -> bool

Cut to internal buffer

Source

pub fn paste_from_clip(&mut self) -> bool

Paste from internal buffer.

Source§

impl TextInputState

Source

pub fn set_undo_buffer(&mut self, undo: Option<impl UndoBuffer + 'static>)

Set undo buffer.

Source

pub fn undo_buffer(&self) -> Option<&dyn UndoBuffer>

Undo

Source

pub fn undo_buffer_mut(&mut self) -> Option<&mut dyn UndoBuffer>

Undo

Source

pub fn recent_replay_log(&mut self) -> Vec<UndoEntry>

Get all recent replay recordings.

Source

pub fn replay_log(&mut self, replay: &[UndoEntry])

Apply the replay recording.

Source

pub fn undo(&mut self) -> bool

Undo operation

Source

pub fn redo(&mut self) -> bool

Redo operation

Source§

impl TextInputState

Source

pub fn set_styles(&mut self, styles: Vec<(Range<usize>, usize)>)

Set and replace all styles.

Source

pub fn add_style(&mut self, range: Range<usize>, style: usize)

Add a style for a TextRange. The style-nr refers to one of the styles set with the widget.

Source

pub fn add_range_style( &mut self, range: Range<upos_type>, style: usize, ) -> Result<(), TextError>

Add a style for a Range<upos_type> to denote the cells. The style-nr refers to one of the styles set with the widget.

Source

pub fn remove_style(&mut self, range: Range<usize>, style: usize)

Remove the exact TextRange and style.

Source

pub fn remove_range_style( &mut self, range: Range<upos_type>, style: usize, ) -> Result<(), TextError>

Remove the exact Range<upos_type> and style.

Source

pub fn styles_in( &self, range: Range<usize>, buf: &mut Vec<(Range<usize>, usize)>, )

Find all styles that touch the given range.

Source

pub fn styles_at(&self, byte_pos: usize, buf: &mut Vec<(Range<usize>, usize)>)

All styles active at the given position.

Source

pub fn style_match(&self, byte_pos: usize, style: usize) -> Option<Range<usize>>

Check if the given style applies at the position and return the complete range for the style.

Source

pub fn styles(&self) -> Option<impl Iterator<Item = (Range<usize>, usize)> + '_>

List of all styles.

Source§

impl TextInputState

Source

pub fn offset(&self) -> upos_type

Offset shown.

Source

pub fn set_offset(&mut self, offset: upos_type)

Offset shown. This is corrected if the cursor wouldn’t be visible.

Source

pub fn cursor(&self) -> upos_type

Cursor position.

Source

pub fn anchor(&self) -> upos_type

Selection anchor.

Source

pub fn set_cursor(&mut self, cursor: upos_type, extend_selection: bool) -> bool

Set the cursor position, reset selection.

Source

pub fn has_selection(&self) -> bool

Selection.

Source

pub fn selection(&self) -> Range<upos_type>

Selection.

Source

pub fn set_selection(&mut self, anchor: upos_type, cursor: upos_type) -> bool

Selection.

Source

pub fn select_all(&mut self) -> bool

Selection.

Source

pub fn selected_text(&self) -> &str

Selection.

Source§

impl TextInputState

Source

pub fn is_empty(&self) -> bool

Empty.

Source

pub fn text(&self) -> &str

Text value.

Source

pub fn str_slice_byte(&self, range: Range<usize>) -> Cow<'_, str>

Text slice as Cow<str>. Uses a byte range.

Source

pub fn try_str_slice_byte( &self, range: Range<usize>, ) -> Result<Cow<'_, str>, TextError>

Text slice as Cow<str>. Uses a byte range.

Source

pub fn str_slice(&self, range: Range<upos_type>) -> Cow<'_, str>

Text slice as Cow<str>

Source

pub fn try_str_slice( &self, range: Range<upos_type>, ) -> Result<Cow<'_, str>, TextError>

Text slice as Cow<str>

Source

pub fn len(&self) -> upos_type

Length as grapheme count.

Source

pub fn line_width(&self) -> upos_type

Length as grapheme count.

Source

pub fn glyphs( &self, screen_offset: u16, screen_width: u16, ) -> impl Iterator<Item = Glyph<'_>>

Iterator for the glyphs of the lines in range. Glyphs here a grapheme + display length.

Source

pub fn text_graphemes(&self, pos: upos_type) -> impl Cursor<Item = Grapheme<'_>>

Get a cursor over all the text with the current position set at pos.

Source

pub fn try_text_graphemes( &self, pos: upos_type, ) -> Result<impl Cursor<Item = Grapheme<'_>>, TextError>

Get a cursor over all the text with the current position set at pos.

Source

pub fn graphemes( &self, range: Range<upos_type>, pos: upos_type, ) -> impl Cursor<Item = Grapheme<'_>>

Get a cursor over the text-range the current position set at pos.

Source

pub fn try_graphemes( &self, range: Range<upos_type>, pos: upos_type, ) -> Result<impl Cursor<Item = Grapheme<'_>>, TextError>

Get a cursor over the text-range the current position set at pos.

Source

pub fn byte_at(&self, pos: upos_type) -> Range<usize>

Grapheme position to byte position. This is the (start,end) position of the single grapheme after pos.

Source

pub fn try_byte_at(&self, pos: upos_type) -> Result<Range<usize>, TextError>

Grapheme position to byte position. This is the (start,end) position of the single grapheme after pos.

Source

pub fn bytes_at_range(&self, range: Range<upos_type>) -> Range<usize>

Grapheme range to byte range.

Source

pub fn try_bytes_at_range( &self, range: Range<upos_type>, ) -> Result<Range<usize>, TextError>

Grapheme range to byte range.

Source

pub fn byte_pos(&self, byte: usize) -> upos_type

Byte position to grapheme position. Returns the position that contains the given byte index.

Source

pub fn try_byte_pos(&self, byte: usize) -> Result<upos_type, TextError>

Byte position to grapheme position. Returns the position that contains the given byte index.

Source

pub fn byte_range(&self, bytes: Range<usize>) -> Range<upos_type>

Byte range to grapheme range.

Source

pub fn try_byte_range( &self, bytes: Range<usize>, ) -> Result<Range<upos_type>, TextError>

Byte range to grapheme range.

Source§

impl TextInputState

Source

pub fn clear(&mut self) -> bool

Reset to empty.

Source

pub fn set_text<S: Into<String>>(&mut self, s: S)

Set text.

Returns an error if the text contains line-breaks.

Source

pub fn insert_char(&mut self, c: char) -> bool

Insert a char at the current position.

Source

pub fn insert_tab(&mut self) -> bool

Insert a tab character at the cursor position. Removes the selection and inserts the tab.

Source

pub fn insert_str(&mut self, t: impl AsRef<str>) -> bool

Insert a str at the current position.

Source

pub fn delete_range(&mut self, range: Range<upos_type>) -> bool

Deletes the given range.

Source

pub fn try_delete_range( &mut self, range: Range<upos_type>, ) -> Result<bool, TextError>

Deletes the given range.

Source§

impl TextInputState

Source

pub fn delete_next_char(&mut self) -> bool

Delete the char after the cursor.

Source

pub fn delete_prev_char(&mut self) -> bool

Delete the char before the cursor.

Source

pub fn next_word_start(&self, pos: upos_type) -> upos_type

Find the start of the next word. Word is everything that is not whitespace.

Source

pub fn try_next_word_start( &self, pos: upos_type, ) -> Result<upos_type, TextError>

Find the start of the next word. Word is everything that is not whitespace.

Source

pub fn next_word_end(&self, pos: upos_type) -> upos_type

Find the end of the next word. Skips whitespace first, then goes on until it finds the next whitespace.

Source

pub fn try_next_word_end(&self, pos: upos_type) -> Result<upos_type, TextError>

Find the end of the next word. Skips whitespace first, then goes on until it finds the next whitespace.

Source

pub fn prev_word_start(&self, pos: upos_type) -> upos_type

Find prev word. Skips whitespace first. Attention: start/end are mirrored here compared to next_word_start/next_word_end, both return start<=end!

Source

pub fn try_prev_word_start( &self, pos: upos_type, ) -> Result<upos_type, TextError>

Find prev word. Skips whitespace first. Attention: start/end are mirrored here compared to next_word_start/next_word_end, both return start<=end!

Source

pub fn prev_word_end(&self, pos: upos_type) -> upos_type

Find the end of the previous word. Word is everything that is not whitespace. Attention: start/end are mirrored here compared to next_word_start/next_word_end, both return start<=end!

Source

pub fn try_prev_word_end(&self, pos: upos_type) -> Result<upos_type, TextError>

Find the end of the previous word. Word is everything that is not whitespace. Attention: start/end are mirrored here compared to next_word_start/next_word_end, both return start<=end!

Source

pub fn is_word_boundary(&self, pos: upos_type) -> bool

Is the position at a word boundary?

Source

pub fn try_is_word_boundary(&self, pos: upos_type) -> Result<bool, TextError>

Is the position at a word boundary?

Source

pub fn word_start(&self, pos: upos_type) -> upos_type

Find the start of the word at pos.

Source

pub fn try_word_start(&self, pos: upos_type) -> Result<upos_type, TextError>

Find the start of the word at pos.

Source

pub fn word_end(&self, pos: upos_type) -> upos_type

Find the end of the word at pos.

Source

pub fn try_word_end(&self, pos: upos_type) -> Result<upos_type, TextError>

Find the end of the word at pos.

Source

pub fn delete_next_word(&mut self) -> bool

Deletes the next word.

Source

pub fn delete_prev_word(&mut self) -> bool

Deletes the given range.

Source

pub fn move_right(&mut self, extend_selection: bool) -> bool

Move to the next char.

Source

pub fn move_left(&mut self, extend_selection: bool) -> bool

Move to the previous char.

Source

pub fn move_to_line_start(&mut self, extend_selection: bool) -> bool

Start of line

Source

pub fn move_to_line_end(&mut self, extend_selection: bool) -> bool

End of line

Source

pub fn move_to_next_word(&mut self, extend_selection: bool) -> bool

Source

pub fn move_to_prev_word(&mut self, extend_selection: bool) -> bool

Source§

impl TextInputState

Source

pub fn screen_to_col(&self, scx: i16) -> upos_type

Converts from a widget relative screen coordinate to a grapheme index. x is the relative screen position.

Source

pub fn col_to_screen(&self, pos: upos_type) -> Option<u16>

Converts a grapheme based position to a screen position relative to the widget area.

Source

pub fn set_screen_cursor(&mut self, cursor: i16, extend_selection: bool) -> bool

Set the cursor position from a screen position relative to the origin of the widget. This value can be negative, which selects a currently not visible position and scrolls to it.

Source

pub fn set_screen_cursor_words( &mut self, screen_cursor: i16, extend_selection: bool, ) -> bool

Set the cursor position from screen coordinates, rounds the position to the next word start/end.

The cursor positions are relative to the inner rect. They may be negative too, this allows setting the cursor to a position that is currently scrolled away.

Source

pub fn scroll_left(&mut self, delta: upos_type) -> bool

Scrolling

Source

pub fn scroll_right(&mut self, delta: upos_type) -> bool

Scrolling

Source

pub fn scroll_cursor_to_visible(&mut self) -> bool

Change the offset in a way that the cursor is visible.

Trait Implementations§

Source§

impl Clone for TextInputState

Source§

fn clone(&self) -> TextInputState

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TextInputState

Source§

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

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

impl Default for TextInputState

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl HandleEvent<Event, MouseOnly, TextOutcome> for TextInputState

Source§

fn handle(&mut self, event: &Event, _keymap: MouseOnly) -> TextOutcome

Handle an event. Read more
Source§

impl HandleEvent<Event, ReadOnly, TextOutcome> for TextInputState

Source§

fn handle(&mut self, event: &Event, _keymap: ReadOnly) -> TextOutcome

Handle an event. Read more
Source§

impl HandleEvent<Event, Regular, TextOutcome> for TextInputState

Source§

fn handle(&mut self, event: &Event, _keymap: Regular) -> TextOutcome

Handle an event. Read more
Source§

impl HasFocus for TextInputState

Source§

fn focus(&self) -> FocusFlag

Access to the flag for the rest.
Source§

fn area(&self) -> Rect

Area for mouse focus. Read more
Source§

fn build(&self, builder: &mut FocusBuilder)

Build the focus-structure for the container.
Source§

fn z_areas(&self) -> &[ZRect]

The widget might have several disjointed/overlapping areas. This is the case if it is showing a popup, but there might be other causes. Read more
Source§

fn navigable(&self) -> Navigation

Declares how the widget interacts with focus. Read more
Source§

fn is_focused(&self) -> bool

Focused?
Source§

fn lost_focus(&self) -> bool

Just lost focus.
Source§

fn gained_focus(&self) -> bool

Just gained focus.
Source§

impl HasScreenCursor for TextInputState

Source§

fn screen_cursor(&self) -> Option<(u16, u16)>

The current text cursor as an absolute screen position.

Source§

impl RelocatableState for TextInputState

Source§

fn relocate(&mut self, shift: (i16, i16), clip: Rect)

Relocate the areas in this widgets state.

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.