pub struct TextInputState {Show 15 fields
pub area: Rect,
pub inner: Rect,
pub rendered: Size,
pub offset: u32,
pub dark_offset: (u16, u16),
pub scroll_to_cursor: Rc<Cell<bool>>,
pub value: TextCore<TextString>,
pub invalid: bool,
pub passwd: bool,
pub overwrite: Rc<Cell<bool>>,
pub on_focus_gained: Rc<Cell<TextFocusGained>>,
pub on_focus_lost: Rc<Cell<TextFocusLost>>,
pub focus: FocusFlag,
pub mouse: MouseFlags,
pub non_exhaustive: NonExhaustive,
}Expand description
State for TextInput.
Fields§
§area: RectThe whole area with block. read only renewed with each render.
inner: RectArea inside a possible block. read only renewed with each render.
rendered: SizeRendered dimension. This may differ from (inner.width, inner.height) if the text area has been relocated. read only renewed with each render.
offset: u32Display offset. read+write
dark_offset: (u16, u16)Dark offset due to clipping. Always set during rendering. read only ignore this value.
scroll_to_cursor: Rc<Cell<bool>>read only use scroll_cursor_to_visible
value: TextCore<TextString>Editing core
invalid: boolDisplay as invalid. read only use set_invalid
passwd: boolDisplay as password. read only use passwd
overwrite: Rc<Cell<bool>>The next user edit clears the text for doing any edit. It will reset this flag. Other interactions may reset this flag too. read only use set_overwrite
on_focus_gained: Rc<Cell<TextFocusGained>>Focus behaviour. read only use on_focus_gained
on_focus_lost: Rc<Cell<TextFocusLost>>Focus behaviour. read only use on_focus_lost
focus: FocusFlagCurrent focus state. read + write But don’t write it.
mouse: MouseFlagsMouse selection in progress. read+write
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 set_overwrite(&mut self, overwrite: bool)
pub fn set_overwrite(&mut self, overwrite: bool)
The next edit operation will overwrite the current content instead of adding text. Any move operations will cancel this overwrite.
Sourcepub fn set_show_ctrl(&mut self, show_ctrl: bool)
pub fn set_show_ctrl(&mut self, show_ctrl: bool)
Show glyphs for control characters.
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 used. Default is to use the global_clipboard().
Sourcepub fn clipboard(&self) -> Option<&dyn Clipboard>
pub fn clipboard(&self) -> Option<&dyn Clipboard>
Clipboard used. Default is to use the global_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 set_styles(&mut self, styles: Vec<(Range<usize>, usize)>)
pub fn set_styles(&mut self, styles: Vec<(Range<usize>, usize)>)
Set and replace all styles.
The ranges are byte-ranges into the text. Each byte-range maps to an index into the styles set with the widget.
Any style-idx that don’t have a match there are just ignored. You can use this to store other range based information. The ranges are corrected during edits, no need to recalculate everything after each keystroke.
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-idx refers to one of the styles set with the widget. Missing styles are just ignored.
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 char range. 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 char-range 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)
Set the text-offset.
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. Scrolls the cursor to a visible position.
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. Scrolls the cursor to a visible position.
Sourcepub fn select_all(&mut self) -> bool
pub fn select_all(&mut self) -> bool
Selection. Scrolls the cursor to a visible position.
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<str>. Uses a byte range.
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<str>. Uses a byte range.
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<str>
Sourcepub fn line_width(&self) -> u32
pub fn line_width(&self) -> u32
Length as grapheme count.
Sourcepub fn text_graphemes(
&self,
pos: u32,
) -> <TextString as TextStore>::GraphemeIter<'_>
pub fn text_graphemes( &self, pos: u32, ) -> <TextString as TextStore>::GraphemeIter<'_>
Get a cursor over all the text with the current position set at pos.
Sourcepub fn try_text_graphemes(
&self,
pos: u32,
) -> Result<<TextString as TextStore>::GraphemeIter<'_>, TextError>
pub fn try_text_graphemes( &self, pos: u32, ) -> Result<<TextString as TextStore>::GraphemeIter<'_>, TextError>
Get a cursor over all the text with the current position set at pos.
Sourcepub fn graphemes(
&self,
range: Range<u32>,
pos: u32,
) -> <TextString as TextStore>::GraphemeIter<'_>
pub fn graphemes( &self, range: Range<u32>, pos: u32, ) -> <TextString as TextStore>::GraphemeIter<'_>
Get a cursor over the text-range the current position set at pos.
Sourcepub fn try_graphemes(
&self,
range: Range<u32>,
pos: u32,
) -> Result<<TextString as TextStore>::GraphemeIter<'_>, TextError>
pub fn try_graphemes( &self, range: Range<u32>, pos: u32, ) -> Result<<TextString as TextStore>::GraphemeIter<'_>, 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_value<S>(&mut self, s: S)
pub fn set_value<S>(&mut self, s: S)
Set text.
Returns an error if the text contains line-breaks.
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_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) -> Option<u16>
pub fn col_to_screen(&self, pos: u32) -> Option<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)
pub fn scroll_cursor_to_visible(&mut self)
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 HasFocus for TextInputState
impl HasFocus for TextInputState
Source§fn build(&self, builder: &mut FocusBuilder)
fn build(&self, builder: &mut FocusBuilder)
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§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