Struct rat_widget::input::TextInputState

source ·
pub struct TextInputState {
    pub focus: FocusFlag,
    pub invalid: bool,
    pub area: Rect,
    pub inner: Rect,
    pub mouse: MouseFlags,
    pub value: InputCore,
    pub non_exhaustive: NonExhaustive,
}
Expand description

Textinput data & event-handling.

Fields§

§focus: FocusFlag

Current focus state.

§invalid: bool

Display as invalid.

§area: Rect

The whole area with block.

§inner: Rect

Area inside a possible block.

§mouse: MouseFlags

Mouse selection in progress.

§value: InputCore

Editing core

§non_exhaustive: NonExhaustive

Construct with ..Default::default()

Implementations§

source§

impl TextInputState

source

pub fn new() -> 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

pub fn clear(&mut self) -> bool

Reset to empty.

source

pub fn offset(&self) -> usize

Offset shown.

source

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

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

source

pub fn cursor(&self) -> usize

Cursor position.

source

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

Set the cursor position, reset selection.

source

pub fn anchor(&self) -> usize

Selection anchor.

source

pub fn value(&self) -> &str

Text.

source

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

Set text.

source

pub fn is_empty(&self) -> bool

Empty.

source

pub fn len(&self) -> usize

Text length as grapheme count.

source

pub fn has_selection(&self) -> bool

Selection.

source

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

Selection.

source

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

Selection.

source

pub fn select_all(&mut self) -> bool

Selection.

source

pub fn selected_value(&self) -> &str

Selection.

source

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

Insert a char at the current position.

source

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

Deletes the given range.

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 delete_prev_char(&mut self) -> bool

Delete the char before the cursor.

source

pub fn delete_next_char(&mut self) -> bool

Delete the char after the cursor.

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 move_to_next(&mut self, extend_selection: bool) -> bool

Move to the next char.

source

pub fn move_to_prev(&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

source

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

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

source

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

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

source

pub fn set_screen_cursor( &mut self, cursor: isize, 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 screen_cursor(&self) -> Option<(u16, u16)>

The current text cursor as an absolute screen position.

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, FocusKeys, TextOutcome> for TextInputState

source§

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

Handle an event. 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 HasFocusFlag for TextInputState

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.