Struct rat_widget::textarea::TextAreaState

source ·
pub struct TextAreaState {
    pub focus: FocusFlag,
    pub area: Rect,
    pub inner: Rect,
    pub value: InputCore,
    pub hscroll: ScrollState,
    pub vscroll: ScrollState,
    pub mouse: MouseFlags,
    pub non_exhaustive: NonExhaustive,
}
Expand description

State for the text-area.

Fields§

§focus: FocusFlag

Current focus state.

§area: Rect

Complete area.

§inner: Rect

Area inside the borders.

§value: InputCore

Text edit core

§hscroll: ScrollState

Horizontal scroll

§vscroll: ScrollState§mouse: MouseFlags

Helper for mouse.

§non_exhaustive: NonExhaustive

Implementations§

source§

impl TextAreaState

source

pub fn new() -> Self

New State.

source

pub fn clear(&mut self) -> bool

Clear everything.

source

pub fn offset(&self) -> (usize, usize)

Current offset for scrolling.

source

pub fn set_offset(&mut self, offset: (usize, usize)) -> bool

Set the offset for scrolling.

source

pub fn cursor(&self) -> (usize, usize)

Cursor position.

source

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

Set the cursor position. This doesn’t scroll the cursor to a visible position. Use TextAreaState::scroll_cursor_to_visible() for that.

source

pub fn anchor(&self) -> (usize, usize)

Selection anchor.

source

pub fn value(&self) -> String

Text value

source

pub fn value_range(&self, range: TextRange) -> Option<RopeSlice<'_>>

Text value

source

pub fn value_as_bytes(&self) -> Bytes<'_>

Text as Bytes iterator.

source

pub fn value_as_chars(&self) -> Chars<'_>

Text as Bytes iterator.

source

pub fn set_value<S: AsRef<str>>(&mut self, s: S)

Set the text value. Resets all internal state.

source

pub fn set_value_rope(&mut self, s: Rope)

Set the text value as a Rope. Resets all internal state.

source

pub fn is_empty(&self) -> bool

Empty.

source

pub fn line_len(&self) -> usize

Line count.

source

pub fn line_width(&self, n: usize) -> Option<usize>

Line width as grapheme count.

source

pub fn line(&self, n: usize) -> Option<RopeGraphemes<'_>>

Grapheme iterator for a given line. This contains the \n at the end.

source

pub fn has_selection(&self) -> bool

Has a selection?

source

pub fn selection(&self) -> TextRange

Current selection.

source

pub fn set_selection(&mut self, range: TextRange) -> bool

Set the selection.

source

pub fn select_all(&mut self) -> bool

Select all.

source

pub fn selected_value(&self) -> Option<RopeSlice<'_>>

Selection.

source

pub fn clear_styles(&mut self)

Clear all set styles.

source

pub fn add_style(&mut self, range: TextRange, style: usize)

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

source

pub fn styles_at(&self, pos: (usize, usize), result: &mut Vec<usize>)

All styles active at the given position.

source

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

Convert a byte position to a text area position. Uses grapheme based column indexes.

source

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

Convert a text area position to a byte range. Uses grapheme based column indexes. Returns (byte-start, byte-end) of the grapheme at the given position.

source

pub fn char_pos(&self, byte: usize) -> Option<(usize, usize)>

Convert a char position to a text area position. Uses grapheme based column indexes.

source

pub fn char_at(&self, pos: (usize, usize)) -> Option<usize>

Convert a text area position to a char position. Uses grapheme based column indexes.

source

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

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

source

pub fn insert_newline(&mut self) -> bool

Insert a line break at the cursor position.

source

pub fn delete_range(&mut self, range: TextRange) -> bool

Deletes the given range.

source

pub fn delete_next_char(&mut self) -> bool

Deletes the next char or the current selection. Returns true if there was any real change.

source

pub fn delete_prev_char(&mut self) -> bool

Deletes the previous char or the selection. Returns true if there was any real change.

source

pub fn delete_next_word(&mut self) -> bool

source

pub fn delete_prev_word(&mut self) -> bool

source

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

Move the cursor left. Scrolls the cursor to visible. Returns true if there was any real change.

source

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

Move the cursor right. Scrolls the cursor to visible. Returns true if there was any real change.

source

pub fn move_up(&mut self, n: usize, extend_selection: bool) -> bool

Move the cursor up. Scrolls the cursor to visible. Returns true if there was any real change.

source

pub fn move_down(&mut self, n: usize, extend_selection: bool) -> bool

Move the cursor down. Scrolls the cursor to visible. Returns true if there was any real change.

source

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

Move the cursor to the start of the line. Scrolls the cursor to visible. Returns true if there was any real change.

source

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

Move the cursor to the end of the line. Scrolls to visible, if necessary. Returns true if there was any real change.

source

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

Move the cursor to the document start.

source

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

Move the cursor to the document end.

source

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

Move the cursor to the start of the visible area.

source

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

Move the cursor to the end of the visible area.

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

pub fn from_screen_col(&self, row: usize, x: usize) -> Option<usize>

Converts from a widget relative screen coordinate to a grapheme index. Row is a row-index into the value, not a screen-row. x is the relative screen position.

source

pub fn to_screen_col(&self, pos: (usize, usize)) -> Option<u16>

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

source

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

Cursor position on the screen.

source

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

Set the cursor position from screen coordinates.

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§

impl TextAreaState

source

pub fn vertical_max_offset(&self) -> usize

Maximum offset that is accessible with scrolling.

This is shorter than the length of the content by whatever fills the last page. This is the base for the scrollbar content_length.

source

pub fn vertical_offset(&self) -> usize

Current vertical offset.

source

pub fn vertical_page(&self) -> usize

Vertical page-size at the current offset.

source

pub fn vertical_scroll(&self) -> usize

Suggested scroll per scroll-event.

source

pub fn horizontal_max_offset(&self) -> usize

Maximum offset that is accessible with scrolling.

This is currently set to usize::MAX.

source

pub fn horizontal_offset(&self) -> usize

Current horizontal offset.

source

pub fn horizontal_page(&self) -> usize

Horizontal page-size at the current offset.

source

pub fn horizontal_scroll(&self) -> usize

Suggested scroll per scroll-event.

source

pub fn set_vertical_offset(&mut self, row_offset: usize) -> bool

Change the vertical offset.

Due to overscroll it’s possible that this is an invalid offset for the widget. The widget must deal with this situation.

The widget returns true if the offset changed at all.

source

pub fn set_horizontal_offset(&mut self, col_offset: usize) -> bool

Change the horizontal offset.

Due to overscroll it’s possible that this is an invalid offset for the widget. The widget must deal with this situation.

The widget returns true if the offset changed at all.

source

pub fn scroll_to_row(&mut self, pos: usize) -> bool

Scroll to position.

source

pub fn scroll_to_col(&mut self, pos: usize) -> bool

Scroll to position.

source

pub fn scroll_up(&mut self, delta: usize) -> bool

Scrolling

source

pub fn scroll_down(&mut self, delta: usize) -> bool

Scrolling

source

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

Scrolling

source

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

Scrolling

Trait Implementations§

source§

impl Clone for TextAreaState

source§

fn clone(&self) -> TextAreaState

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 TextAreaState

source§

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

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

impl Default for TextAreaState

source§

fn default() -> Self

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

impl HandleEvent<Event, FocusKeys, TextOutcome> for TextAreaState

source§

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

Handle an event. Read more
source§

impl HandleEvent<Event, MouseOnly, TextOutcome> for TextAreaState

source§

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

Handle an event. Read more
source§

impl HandleEvent<Event, ReadOnly, TextOutcome> for TextAreaState

source§

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

Handle an event. Read more
source§

impl HasFocusFlag for TextAreaState

source§

fn focus(&self) -> &FocusFlag

Access to the flag for the rest.
source§

fn area(&self) -> Rect

Access the area for mouse focus.
source§

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

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

fn navigable(&self) -> bool

If the widget is focusable, but doesn’t want to partake in keyboard navigation it returns false here. 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.

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§

default 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> 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,

§

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>,

§

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>,

§

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.