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: FocusFlagCurrent focus state.
area: RectComplete area.
inner: RectArea inside the borders.
value: InputCoreText edit core
hscroll: ScrollStateHorizontal scroll
vscroll: ScrollState§mouse: MouseFlagsHelper for mouse.
non_exhaustive: NonExhaustiveImplementations§
source§impl TextAreaState
impl TextAreaState
sourcepub fn set_offset(&mut self, offset: (usize, usize)) -> bool
pub fn set_offset(&mut self, offset: (usize, usize)) -> bool
Set the offset for scrolling.
sourcepub fn set_cursor(
&mut self,
cursor: (usize, usize),
extend_selection: bool,
) -> bool
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.
sourcepub fn value_range(&self, range: TextRange) -> Option<RopeSlice<'_>>
pub fn value_range(&self, range: TextRange) -> Option<RopeSlice<'_>>
Text value
sourcepub fn value_as_bytes(&self) -> Bytes<'_>
pub fn value_as_bytes(&self) -> Bytes<'_>
Text as Bytes iterator.
sourcepub fn value_as_chars(&self) -> Chars<'_>
pub fn value_as_chars(&self) -> Chars<'_>
Text as Bytes iterator.
sourcepub fn set_value<S: AsRef<str>>(&mut self, s: S)
pub fn set_value<S: AsRef<str>>(&mut self, s: S)
Set the text value. Resets all internal state.
sourcepub fn set_value_rope(&mut self, s: Rope)
pub fn set_value_rope(&mut self, s: Rope)
Set the text value as a Rope. Resets all internal state.
sourcepub fn line_width(&self, n: usize) -> Option<usize>
pub fn line_width(&self, n: usize) -> Option<usize>
Line width as grapheme count.
sourcepub fn line(&self, n: usize) -> Option<RopeGraphemes<'_>>
pub fn line(&self, n: usize) -> Option<RopeGraphemes<'_>>
Grapheme iterator for a given line. This contains the \n at the end.
sourcepub fn has_selection(&self) -> bool
pub fn has_selection(&self) -> bool
Has a selection?
sourcepub fn set_selection(&mut self, range: TextRange) -> bool
pub fn set_selection(&mut self, range: TextRange) -> bool
Set the selection.
sourcepub fn select_all(&mut self) -> bool
pub fn select_all(&mut self) -> bool
Select all.
sourcepub fn selected_value(&self) -> Option<RopeSlice<'_>>
pub fn selected_value(&self) -> Option<RopeSlice<'_>>
Selection.
sourcepub fn clear_styles(&mut self)
pub fn clear_styles(&mut self)
Clear all set styles.
sourcepub fn add_style(&mut self, range: TextRange, style: usize)
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.
sourcepub fn styles_at(&self, pos: (usize, usize), result: &mut Vec<usize>)
pub fn styles_at(&self, pos: (usize, usize), result: &mut Vec<usize>)
All styles active at the given position.
sourcepub fn byte_pos(&self, byte: usize) -> Option<(usize, usize)>
pub fn byte_pos(&self, byte: usize) -> Option<(usize, usize)>
Convert a byte position to a text area position. Uses grapheme based column indexes.
sourcepub fn byte_at(&self, pos: (usize, usize)) -> Option<(usize, usize)>
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.
sourcepub fn char_pos(&self, byte: usize) -> Option<(usize, usize)>
pub fn char_pos(&self, byte: usize) -> Option<(usize, usize)>
Convert a char position to a text area position. Uses grapheme based column indexes.
sourcepub fn char_at(&self, pos: (usize, usize)) -> Option<usize>
pub fn char_at(&self, pos: (usize, usize)) -> Option<usize>
Convert a text area position to a char position. Uses grapheme based column indexes.
sourcepub fn insert_char(&mut self, c: char) -> bool
pub fn insert_char(&mut self, c: char) -> bool
Insert a character at the cursor position. Removes the selection and inserts the char.
sourcepub fn insert_newline(&mut self) -> bool
pub fn insert_newline(&mut self) -> bool
Insert a line break at the cursor position.
sourcepub fn delete_range(&mut self, range: TextRange) -> bool
pub fn delete_range(&mut self, range: TextRange) -> bool
Deletes the given range.
sourcepub fn delete_next_char(&mut self) -> bool
pub fn delete_next_char(&mut self) -> bool
Deletes the next char or the current selection. Returns true if there was any real change.
sourcepub fn delete_prev_char(&mut self) -> bool
pub fn delete_prev_char(&mut self) -> bool
Deletes the previous char or the selection. Returns true if there was any real change.
pub fn delete_next_word(&mut self) -> bool
pub fn delete_prev_word(&mut self) -> bool
sourcepub fn move_left(&mut self, n: usize, extend_selection: bool) -> bool
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.
sourcepub fn move_right(&mut self, n: usize, extend_selection: bool) -> bool
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.
sourcepub fn move_up(&mut self, n: usize, extend_selection: bool) -> bool
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.
sourcepub fn move_down(&mut self, n: usize, extend_selection: bool) -> bool
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.
sourcepub fn move_to_line_start(&mut self, extend_selection: bool) -> bool
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.
sourcepub fn move_to_line_end(&mut self, extend_selection: bool) -> bool
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.
sourcepub fn move_to_start(&mut self, extend_selection: bool) -> bool
pub fn move_to_start(&mut self, extend_selection: bool) -> bool
Move the cursor to the document start.
sourcepub fn move_to_end(&mut self, extend_selection: bool) -> bool
pub fn move_to_end(&mut self, extend_selection: bool) -> bool
Move the cursor to the document end.
sourcepub fn move_to_screen_start(&mut self, extend_selection: bool) -> bool
pub fn move_to_screen_start(&mut self, extend_selection: bool) -> bool
Move the cursor to the start of the visible area.
sourcepub fn move_to_screen_end(&mut self, extend_selection: bool) -> bool
pub fn move_to_screen_end(&mut self, extend_selection: bool) -> bool
Move the cursor to the end of the visible area.
pub fn move_to_next_word(&mut self, extend_selection: bool) -> bool
pub fn move_to_prev_word(&mut self, extend_selection: bool) -> bool
sourcepub fn from_screen_col(&self, row: usize, x: usize) -> Option<usize>
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.
sourcepub fn to_screen_col(&self, pos: (usize, usize)) -> Option<u16>
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.
sourcepub fn screen_cursor(&self) -> Option<(u16, u16)>
pub fn screen_cursor(&self) -> Option<(u16, u16)>
Cursor position on the screen.
sourcepub fn set_screen_cursor(
&mut self,
cursor: (i16, i16),
extend_selection: bool,
) -> bool
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
impl TextAreaState
sourcepub fn vertical_max_offset(&self) -> usize
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.
sourcepub fn vertical_offset(&self) -> usize
pub fn vertical_offset(&self) -> usize
Current vertical offset.
sourcepub fn vertical_page(&self) -> usize
pub fn vertical_page(&self) -> usize
Vertical page-size at the current offset.
sourcepub fn vertical_scroll(&self) -> usize
pub fn vertical_scroll(&self) -> usize
Suggested scroll per scroll-event.
sourcepub fn horizontal_max_offset(&self) -> usize
pub fn horizontal_max_offset(&self) -> usize
Maximum offset that is accessible with scrolling.
This is currently set to usize::MAX.
sourcepub fn horizontal_offset(&self) -> usize
pub fn horizontal_offset(&self) -> usize
Current horizontal offset.
sourcepub fn horizontal_page(&self) -> usize
pub fn horizontal_page(&self) -> usize
Horizontal page-size at the current offset.
sourcepub fn horizontal_scroll(&self) -> usize
pub fn horizontal_scroll(&self) -> usize
Suggested scroll per scroll-event.
sourcepub fn set_vertical_offset(&mut self, row_offset: usize) -> bool
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.
sourcepub fn set_horizontal_offset(&mut self, col_offset: usize) -> bool
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.
sourcepub fn scroll_to_row(&mut self, pos: usize) -> bool
pub fn scroll_to_row(&mut self, pos: usize) -> bool
Scroll to position.
sourcepub fn scroll_to_col(&mut self, pos: usize) -> bool
pub fn scroll_to_col(&mut self, pos: usize) -> bool
Scroll to position.
sourcepub fn scroll_down(&mut self, delta: usize) -> bool
pub fn scroll_down(&mut self, delta: usize) -> bool
Scrolling
sourcepub fn scroll_left(&mut self, delta: usize) -> bool
pub fn scroll_left(&mut self, delta: usize) -> bool
Scrolling
sourcepub fn scroll_right(&mut self, delta: usize) -> bool
pub fn scroll_right(&mut self, delta: usize) -> bool
Scrolling
Trait Implementations§
source§impl Clone for TextAreaState
impl Clone for TextAreaState
source§fn clone(&self) -> TextAreaState
fn clone(&self) -> TextAreaState
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl Debug for TextAreaState
impl Debug for TextAreaState
source§impl Default for TextAreaState
impl Default for TextAreaState
source§impl HandleEvent<Event, FocusKeys, TextOutcome> for TextAreaState
impl HandleEvent<Event, FocusKeys, TextOutcome> for TextAreaState
source§impl HandleEvent<Event, MouseOnly, TextOutcome> for TextAreaState
impl HandleEvent<Event, MouseOnly, TextOutcome> for TextAreaState
source§impl HandleEvent<Event, ReadOnly, TextOutcome> for TextAreaState
impl HandleEvent<Event, ReadOnly, TextOutcome> for TextAreaState
source§impl HasFocusFlag for TextAreaState
impl HasFocusFlag for TextAreaState
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
Auto Trait Implementations§
impl !Freeze for TextAreaState
impl !RefUnwindSafe for TextAreaState
impl Send for TextAreaState
impl !Sync for TextAreaState
impl Unpin for TextAreaState
impl UnwindSafe for TextAreaState
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§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default 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