Struct rat_widget::text_input::TextInputState
source · pub struct TextInputState {
pub focus: FocusFlag,
pub area: Rect,
pub inner: Rect,
pub value: TextCore<TextString>,
pub invalid: bool,
pub offset: u32,
pub mouse: MouseFlags,
pub non_exhaustive: NonExhaustive,
}Expand description
State for TextInput.
Fields§
§focus: FocusFlagCurrent focus state.
area: RectThe whole area with block.
inner: RectArea inside a possible block.
value: TextCore<TextString>Editing core
invalid: boolDisplay as invalid.
offset: u32Display offset
mouse: MouseFlagsMouse selection in progress.
non_exhaustive: NonExhaustiveConstruct with ..Default::default()
Implementations§
source§impl TextInputState
impl TextInputState
pub fn new() -> TextInputState
pub fn named(name: &str) -> TextInputState
sourcepub fn set_invalid(&mut self, invalid: bool)
pub fn set_invalid(&mut self, invalid: bool)
Renders the widget in invalid style.
sourcepub fn get_invalid(&self) -> bool
pub fn get_invalid(&self) -> bool
Renders the widget in invalid style.
source§impl TextInputState
impl TextInputState
sourcepub fn set_clipboard(&mut self, clip: Option<impl Clipboard + 'static>)
pub fn set_clipboard(&mut self, clip: Option<impl Clipboard + 'static>)
Clipboard
sourcepub fn copy_to_clip(&mut self) -> bool
pub fn copy_to_clip(&mut self) -> bool
Copy to internal buffer
sourcepub fn cut_to_clip(&mut self) -> bool
pub fn cut_to_clip(&mut self) -> bool
Cut to internal buffer
sourcepub fn paste_from_clip(&mut self) -> bool
pub fn paste_from_clip(&mut self) -> bool
Paste from internal buffer.
source§impl TextInputState
impl TextInputState
sourcepub fn set_undo_buffer(&mut self, undo: Option<impl UndoBuffer + 'static>)
pub fn set_undo_buffer(&mut self, undo: Option<impl UndoBuffer + 'static>)
Set undo buffer.
sourcepub fn undo_buffer(&self) -> Option<&dyn UndoBuffer>
pub fn undo_buffer(&self) -> Option<&dyn UndoBuffer>
Undo
sourcepub fn undo_buffer_mut(&mut self) -> Option<&mut dyn UndoBuffer>
pub fn undo_buffer_mut(&mut self) -> Option<&mut dyn UndoBuffer>
Undo
sourcepub fn recent_replay_log(&mut self) -> Vec<UndoEntry>
pub fn recent_replay_log(&mut self) -> Vec<UndoEntry>
Get all recent replay recordings.
sourcepub fn replay_log(&mut self, replay: &[UndoEntry])
pub fn replay_log(&mut self, replay: &[UndoEntry])
Apply the replay recording.
source§impl TextInputState
impl TextInputState
sourcepub fn add_style(&mut self, range: Range<usize>, style: usize)
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.
sourcepub fn add_range_style(
&mut self,
range: Range<u32>,
style: usize,
) -> Result<(), TextError>
pub fn add_range_style( &mut self, range: Range<u32>, 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.
sourcepub fn remove_style(&mut self, range: Range<usize>, style: usize)
pub fn remove_style(&mut self, range: Range<usize>, style: usize)
Remove the exact TextRange and style.
sourcepub fn remove_range_style(
&mut self,
range: Range<u32>,
style: usize,
) -> Result<(), TextError>
pub fn remove_range_style( &mut self, range: Range<u32>, style: usize, ) -> Result<(), TextError>
Remove the exact Range<upos_type> and style.
sourcepub fn styles_in(
&self,
range: Range<usize>,
buf: &mut Vec<(Range<usize>, usize)>,
)
pub fn styles_in( &self, range: Range<usize>, buf: &mut Vec<(Range<usize>, usize)>, )
Find all styles that touch the given range.
sourcepub fn styles_at(&self, byte_pos: usize, buf: &mut Vec<(Range<usize>, usize)>)
pub fn styles_at(&self, byte_pos: usize, buf: &mut Vec<(Range<usize>, usize)>)
All styles active at the given position.
source§impl TextInputState
impl TextInputState
sourcepub fn set_offset(&mut self, offset: u32)
pub fn set_offset(&mut self, offset: u32)
Offset shown. This is corrected if the cursor wouldn’t be visible.
sourcepub fn set_cursor(&mut self, cursor: u32, extend_selection: bool) -> bool
pub fn set_cursor(&mut self, cursor: u32, extend_selection: bool) -> bool
Set the cursor position, reset selection.
sourcepub fn has_selection(&self) -> bool
pub fn has_selection(&self) -> bool
Selection.
sourcepub fn set_selection(&mut self, anchor: u32, cursor: u32) -> bool
pub fn set_selection(&mut self, anchor: u32, cursor: u32) -> bool
Selection.
sourcepub fn select_all(&mut self) -> bool
pub fn select_all(&mut self) -> bool
Selection.
sourcepub fn selected_text(&self) -> &str
pub fn selected_text(&self) -> &str
Selection.
source§impl TextInputState
impl TextInputState
sourcepub fn str_slice_byte(&self, range: Range<usize>) -> Cow<'_, str>
pub fn str_slice_byte(&self, range: Range<usize>) -> Cow<'_, str>
Text slice as Cow
sourcepub fn try_str_slice_byte(
&self,
range: Range<usize>,
) -> Result<Cow<'_, str>, TextError>
pub fn try_str_slice_byte( &self, range: Range<usize>, ) -> Result<Cow<'_, str>, TextError>
Text slice as Cow
sourcepub fn try_str_slice(
&self,
range: Range<u32>,
) -> Result<Cow<'_, str>, TextError>
pub fn try_str_slice( &self, range: Range<u32>, ) -> Result<Cow<'_, str>, TextError>
Text slice as Cow
sourcepub fn line_width(&self) -> u32
pub fn line_width(&self) -> u32
Length as grapheme count.
sourcepub fn glyphs(
&self,
screen_offset: u16,
screen_width: u16,
) -> impl Iterator<Item = Glyph<'_>>
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.
sourcepub fn text_graphemes(
&self,
pos: u32,
) -> impl Iterator<Item = Grapheme<'_>> + Cursor
pub fn text_graphemes( &self, pos: u32, ) -> impl Iterator<Item = Grapheme<'_>> + Cursor
Get a cursor over all the text with the current position set at pos.
sourcepub fn try_text_graphemes(
&self,
pos: u32,
) -> Result<impl Iterator<Item = Grapheme<'_>> + Cursor, TextError>
pub fn try_text_graphemes( &self, pos: u32, ) -> Result<impl Iterator<Item = Grapheme<'_>> + Cursor, TextError>
Get a cursor over all the text with the current position set at pos.
sourcepub fn graphemes(
&self,
range: Range<u32>,
pos: u32,
) -> impl Iterator<Item = Grapheme<'_>> + Cursor
pub fn graphemes( &self, range: Range<u32>, pos: u32, ) -> impl Iterator<Item = Grapheme<'_>> + Cursor
Get a cursor over the text-range the current position set at pos.
sourcepub fn try_graphemes(
&self,
range: Range<u32>,
pos: u32,
) -> Result<impl Iterator<Item = Grapheme<'_>> + Cursor, TextError>
pub fn try_graphemes( &self, range: Range<u32>, pos: u32, ) -> Result<impl Iterator<Item = Grapheme<'_>> + Cursor, TextError>
Get a cursor over the text-range the current position set at pos.
sourcepub fn byte_at(&self, pos: u32) -> Range<usize>
pub fn byte_at(&self, pos: u32) -> Range<usize>
Grapheme position to byte position. This is the (start,end) position of the single grapheme after pos.
sourcepub fn try_byte_at(&self, pos: u32) -> Result<Range<usize>, TextError>
pub fn try_byte_at(&self, pos: u32) -> Result<Range<usize>, TextError>
Grapheme position to byte position. This is the (start,end) position of the single grapheme after pos.
sourcepub fn try_bytes_at_range(
&self,
range: Range<u32>,
) -> Result<Range<usize>, TextError>
pub fn try_bytes_at_range( &self, range: Range<u32>, ) -> Result<Range<usize>, TextError>
Grapheme range to byte range.
sourcepub fn byte_pos(&self, byte: usize) -> u32
pub fn byte_pos(&self, byte: usize) -> u32
Byte position to grapheme position. Returns the position that contains the given byte index.
source§impl TextInputState
impl TextInputState
sourcepub fn set_text<S>(&mut self, s: S)
pub fn set_text<S>(&mut self, s: S)
Set text.
Returns an error if the text contains line-breaks.
sourcepub fn insert_char(&mut self, c: char) -> bool
pub fn insert_char(&mut self, c: char) -> bool
Insert a char at the current position.
sourcepub fn insert_tab(&mut self) -> bool
pub fn insert_tab(&mut self) -> bool
Insert a tab character at the cursor position. Removes the selection and inserts the tab.
sourcepub fn insert_str(&mut self, t: impl AsRef<str>) -> bool
pub fn insert_str(&mut self, t: impl AsRef<str>) -> bool
Insert a str at the current position.
sourcepub fn delete_range(&mut self, range: Range<u32>) -> bool
pub fn delete_range(&mut self, range: Range<u32>) -> bool
Deletes the given range.
source§impl TextInputState
impl TextInputState
sourcepub fn delete_next_char(&mut self) -> bool
pub fn delete_next_char(&mut self) -> bool
Delete the char after the cursor.
sourcepub fn delete_prev_char(&mut self) -> bool
pub fn delete_prev_char(&mut self) -> bool
Delete the char before the cursor.
sourcepub fn next_word_start(&self, pos: u32) -> u32
pub fn next_word_start(&self, pos: u32) -> u32
Find the start of the next word. Word is everything that is not whitespace.
sourcepub fn try_next_word_start(&self, pos: u32) -> Result<u32, TextError>
pub fn try_next_word_start(&self, pos: u32) -> Result<u32, TextError>
Find the start of the next word. Word is everything that is not whitespace.
sourcepub fn next_word_end(&self, pos: u32) -> u32
pub fn next_word_end(&self, pos: u32) -> u32
Find the end of the next word. Skips whitespace first, then goes on until it finds the next whitespace.
sourcepub fn try_next_word_end(&self, pos: u32) -> Result<u32, TextError>
pub fn try_next_word_end(&self, pos: u32) -> Result<u32, TextError>
Find the end of the next word. Skips whitespace first, then goes on until it finds the next whitespace.
sourcepub fn prev_word_start(&self, pos: u32) -> u32
pub fn prev_word_start(&self, pos: u32) -> u32
Find prev word. Skips whitespace first. Attention: start/end are mirrored here compared to next_word_start/next_word_end, both return start<=end!
sourcepub fn try_prev_word_start(&self, pos: u32) -> Result<u32, TextError>
pub fn try_prev_word_start(&self, pos: u32) -> Result<u32, 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!
sourcepub fn prev_word_end(&self, pos: u32) -> u32
pub fn prev_word_end(&self, pos: u32) -> u32
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!
sourcepub fn try_prev_word_end(&self, pos: u32) -> Result<u32, TextError>
pub fn try_prev_word_end(&self, pos: u32) -> Result<u32, 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!
sourcepub fn is_word_boundary(&self, pos: u32) -> bool
pub fn is_word_boundary(&self, pos: u32) -> bool
Is the position at a word boundary?
sourcepub fn try_is_word_boundary(&self, pos: u32) -> Result<bool, TextError>
pub fn try_is_word_boundary(&self, pos: u32) -> Result<bool, TextError>
Is the position at a word boundary?
sourcepub fn word_start(&self, pos: u32) -> u32
pub fn word_start(&self, pos: u32) -> u32
Find the start of the word at pos.
sourcepub fn try_word_start(&self, pos: u32) -> Result<u32, TextError>
pub fn try_word_start(&self, pos: u32) -> Result<u32, TextError>
Find the start of the word at pos.
sourcepub fn try_word_end(&self, pos: u32) -> Result<u32, TextError>
pub fn try_word_end(&self, pos: u32) -> Result<u32, TextError>
Find the end of the word at pos.
sourcepub fn delete_next_word(&mut self) -> bool
pub fn delete_next_word(&mut self) -> bool
Deletes the next word.
sourcepub fn delete_prev_word(&mut self) -> bool
pub fn delete_prev_word(&mut self) -> bool
Deletes the given range.
sourcepub fn move_right(&mut self, extend_selection: bool) -> bool
pub fn move_right(&mut self, extend_selection: bool) -> bool
Move to the next char.
sourcepub fn move_to_line_start(&mut self, extend_selection: bool) -> bool
pub fn move_to_line_start(&mut self, extend_selection: bool) -> bool
Start of line
sourcepub fn move_to_line_end(&mut self, extend_selection: bool) -> bool
pub fn move_to_line_end(&mut self, extend_selection: bool) -> bool
End of line
pub fn move_to_next_word(&mut self, extend_selection: bool) -> bool
pub fn move_to_prev_word(&mut self, extend_selection: bool) -> bool
source§impl TextInputState
impl TextInputState
sourcepub fn screen_to_col(&self, scx: i16) -> u32
pub fn screen_to_col(&self, scx: i16) -> u32
Converts from a widget relative screen coordinate to a grapheme index. x is the relative screen position.
sourcepub fn col_to_screen(&self, pos: u32) -> u16
pub fn col_to_screen(&self, pos: u32) -> u16
Converts a grapheme based position to a screen position relative to the widget area.
sourcepub fn set_screen_cursor(&mut self, cursor: i16, extend_selection: bool) -> bool
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.
sourcepub fn set_screen_cursor_words(
&mut self,
screen_cursor: i16,
extend_selection: bool,
) -> bool
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.
sourcepub fn scroll_left(&mut self, delta: u32) -> bool
pub fn scroll_left(&mut self, delta: u32) -> bool
Scrolling
sourcepub fn scroll_right(&mut self, delta: u32) -> bool
pub fn scroll_right(&mut self, delta: u32) -> bool
Scrolling
sourcepub fn scroll_cursor_to_visible(&mut self) -> bool
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
impl Clone for TextInputState
source§fn clone(&self) -> TextInputState
fn clone(&self) -> TextInputState
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl Debug for TextInputState
impl Debug for TextInputState
source§impl Default for TextInputState
impl Default for TextInputState
source§fn default() -> TextInputState
fn default() -> TextInputState
source§impl HandleEvent<Event, MouseOnly, TextOutcome> for TextInputState
impl HandleEvent<Event, MouseOnly, TextOutcome> for TextInputState
source§impl HandleEvent<Event, ReadOnly, TextOutcome> for TextInputState
impl HandleEvent<Event, ReadOnly, TextOutcome> for TextInputState
source§impl HandleEvent<Event, Regular, TextOutcome> for TextInputState
impl HandleEvent<Event, Regular, TextOutcome> for TextInputState
source§impl HasFocusFlag for TextInputState
impl HasFocusFlag for TextInputState
source§fn z_areas(&self) -> &[ZRect]
fn z_areas(&self) -> &[ZRect]
source§fn is_focused(&self) -> bool
fn is_focused(&self) -> bool
source§fn lost_focus(&self) -> bool
fn lost_focus(&self) -> bool
source§fn gained_focus(&self) -> bool
fn gained_focus(&self) -> bool
source§impl HasScreenCursor for TextInputState
impl HasScreenCursor for TextInputState
Auto Trait Implementations§
impl !Freeze for TextInputState
impl !RefUnwindSafe for TextInputState
impl !Send for TextInputState
impl !Sync for TextInputState
impl Unpin for TextInputState
impl !UnwindSafe for TextInputState
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