TextAreaState

Struct TextAreaState 

Source
pub struct TextAreaState {
Show 17 fields pub area: Rect, pub inner: Rect, pub rendered: Size, pub screen_cursor: Option<(u16, u16)>, pub hscroll: ScrollState, pub vscroll: ScrollState, pub sub_row_offset: upos_type, pub dark_offset: (u16, u16), pub scroll_to_cursor: bool, pub value: TextCore<TextRope>, pub move_col: Option<i16>, pub auto_indent: bool, pub auto_quote: bool, pub text_wrap: TextWrap, pub focus: FocusFlag, pub mouse: MouseFlags, pub non_exhaustive: NonExhaustive,
}
Expand description

State & event handling.

Fields§

§area: Rect

The whole area with block. read only renewed with each render.

§inner: Rect

Area inside a possible block. read only renewed with each render.

§rendered: Size

Rendered dimension. This may differ from (inner.width, inner.height) if the text area has been relocated/clipped. This holds the original rendered dimension before any relocation/clipping.

§screen_cursor: Option<(u16, u16)>

Cursor position on the screen.

§hscroll: ScrollState

Horizontal scroll. When text-break is active this value is ignored. read+write

§vscroll: ScrollState

Vertical offset. read+write

§sub_row_offset: upos_type

When text-break is active, this is the grapheme-offset into the first visible text-row where the display actually starts. read+write but it’s not advised.

§dark_offset: (u16, u16)

Dark offset due to clipping. read only secondary offset due to clipping.

§scroll_to_cursor: bool

The scroll offset will be adjusted to display the cursor. This will be the minimal adjustment, the cursor will stay at the same screen position if it’s already visible or appear at the start/end if it’s not. read+write use scroll_cursor_to_visible().

§value: TextCore<TextRope>

Text edit core

§move_col: Option<i16>

Memory-column for up/down movement.

Up/down movement tries to place the cursor at this column, but might have to clip it, because the current line is too short.

This is kept as a relative screen-position. It may be less than 0, if the widget has been relocated.

§auto_indent: bool

auto indent active

§auto_quote: bool

quote selection active

§text_wrap: TextWrap

text breaking

§focus: FocusFlag

Current focus state.

§mouse: MouseFlags

Mouse selection in progress. read+write

§non_exhaustive: NonExhaustive

Implementations§

Source§

impl TextAreaState

Source

pub fn new() -> Self

New State.

Source

pub fn named(name: &str) -> Self

New state with a focus name.

Source

pub fn set_newline(&mut self, br: impl Into<String>)

Sets the line ending used for insert. There is no auto-detection or conversion done for set_value().

Caution: If this doesn’t match the line ending used in the value, you will get a value with mixed line endings.

Source

pub fn newline(&self) -> &str

Line ending used for insert.

Source

pub fn set_auto_indent(&mut self, indent: bool)

Sets auto-indent on new-line.

Source

pub fn set_auto_quote(&mut self, quote: bool)

Activates ‘add quotes to selection’.

Source

pub fn set_tab_width(&mut self, tabs: u16)

Set tab-width.

Source

pub fn tab_width(&self) -> u16

Tab-width

Source

pub fn set_expand_tabs(&mut self, expand: bool)

Expand tabs to spaces. Only for new inputs.

Source

pub fn expand_tabs(&self) -> bool

Expand tabs to spaces. Only for new inputs.

Source

pub fn set_show_ctrl(&mut self, show_ctrl: bool)

Show glyphs for control characters.

Source

pub fn show_ctrl(&self) -> bool

Show glyphs for control characters.

Source

pub fn set_wrap_ctrl(&mut self, wrap_ctrl: bool)

Show glyphs for text-wrapping. Shows inserted line-breaks, zero-width space (U+200B) or the soft hyphen (U+00AD).

Source

pub fn wrap_ctrl(&self) -> bool

Show glyphs for text-wrapping. Shows inserted line-breaks, zero-width space (U+200B) or the soft hyphen (U+00AD).

Source

pub fn set_text_wrap(&mut self, text_wrap: TextWrap)

Text wrapping mode.

  • TextWrap::Shift means no wrapping.

  • TextWrap::Hard hard-wraps at the right border.

  • TextWrap::Word(n) does word wrapping. n gives the size of the break-region close to the right border. The first space that falls in this region is taken as a break. If that is not possible this will break at the last space before. If there is no space it will hard-wrap the word.

    Space is used as word separator. Hyphen will be used to break a word, and soft-hyphen and zero-width-space will be recognized too.

Source

pub fn text_wrap(&self) -> TextWrap

Text wrapping.

Source

pub fn set_move_col(&mut self, col: Option<i16>)

Extra column information for cursor movement.

The cursor position is capped to the current line length, so if you move up one row, you might end at a position left of the current column. If you move up once more you want to return to the original position. That’s what is stored here.

This stores the relative screen-column, it may be less than 0 if the widget has been relocated.

Source

pub fn move_col(&mut self) -> Option<i16>

Extra column information for cursor movement.

Source§

impl TextAreaState

Source

pub fn set_clipboard(&mut self, clip: Option<impl Clipboard + 'static>)

Clipboard used. Default is to use the global_clipboard().

Source

pub fn clipboard(&self) -> Option<&dyn Clipboard>

Clipboard used. Default is to use the global_clipboard().

Source

pub fn copy_to_clip(&mut self) -> bool

Copy selection to clipboard.

Source

pub fn cut_to_clip(&mut self) -> bool

Cut selection to clipboard.

Source

pub fn paste_from_clip(&mut self) -> bool

Paste from clipboard.

Source§

impl TextAreaState

Source

pub fn set_undo_buffer(&mut self, undo: Option<impl UndoBuffer + 'static>)

Set the undo buffer.

Default is an undo-buffer with 99 undoes.

Adjacent edits will be merged automatically into a single undo. (Type multiple characters, they will be undone in one go.)

Source

pub fn undo_buffer(&self) -> Option<&dyn UndoBuffer>

Access the undo buffer.

Source

pub fn undo_buffer_mut(&mut self) -> Option<&mut dyn UndoBuffer>

Access the undo buffer.

Source

pub fn begin_undo_seq(&mut self)

Begin a sequence of changes that should be undone in one go.

Call begin_undo_seq(), then call any edit-functions. When you are done call end_undo_seq(). Any changes will be undone in a single step.

Source

pub fn end_undo_seq(&mut self)

End a sequence of changes that should be undone in one go.

Source

pub fn recent_replay_log(&mut self) -> Vec<UndoEntry>

Get all recent replay recordings. This log can be sent to a second TextAreaState and can be applied with replay_log().

There are some caveats.

Source

pub fn replay_log(&mut self, replay: &[UndoEntry])

Apply the replay recording.

There are some caveats.

Source

pub fn undo(&mut self) -> bool

Do one undo.

Source

pub fn redo(&mut self) -> bool

Do one redo.

Source§

impl TextAreaState

Source

pub fn set_styles(&mut self, styles: Vec<(Range<usize>, usize)>)

Set and replace all styles.

The ranges are byte-ranges into the text. There is no verification that the ranges fit 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.

But this is only a very basic correction based on insertions and deletes. If you use this for syntax-highlighting you probably need to rebuild the styles.

Source

pub fn set_range_styles( &mut self, styles: Vec<(TextRange, usize)>, ) -> Result<(), TextError>

Set and replace all styles.

The ranges are TextRanges 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.

Source

pub fn add_style(&mut self, range: Range<usize>, style: usize)

Add a style for a byte-range.

The style-idx refers to one of the styles set with the widget. Missing styles are just ignored.

Source

pub fn add_range_style( &mut self, range: TextRange, style: usize, ) -> Result<(), TextError>

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

Source

pub fn remove_style(&mut self, range: Range<usize>, style: usize)

Remove the exact byte-range and style.

Source

pub fn remove_range_style( &mut self, range: TextRange, style: usize, ) -> Result<(), TextError>

Remove the exact TextRange and style.

Source

pub fn styles_in( &self, range: Range<usize>, buf: &mut Vec<(Range<usize>, usize)>, )

Find all styles that touch the given range.

Source

pub fn styles_at(&self, byte_pos: usize, buf: &mut Vec<(Range<usize>, usize)>)

All styles active at the given position.

Source

pub fn style_match(&self, byte_pos: usize, style: usize) -> Option<Range<usize>>

Check if the given style applies at the position and return the complete range for the style.

Source

pub fn styles(&self) -> impl Iterator<Item = (Range<usize>, usize)> + '_

List of all styles.

Source§

impl TextAreaState

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.

The offset uses usize, but it shouldn’t exceed (u32::MAX, u32::MAX). This is due to the internal ScrollState that only knows usize.

Source

pub fn set_sub_row_offset(&mut self, sub_row_offset: upos_type) -> bool

Scrolling uses the offset() for the start of the displayed text. When text-wrapping is active, this is not enough. This gives an extra offset into the first row where rendering should start.

You probably don’t want to set this value. Use set_cursor() instead, it will automatically scroll to make the cursor visible.

If you really want, pos_to_line_start() can help to find the start-position of a visual row. The x-value of the returned TextPosition is a valid value for this function.

Source

pub fn sub_row_offset(&self) -> upos_type

Returns the extra offset into the first row where rendering starts. This is only valid if text-wrapping is active.

Returns the index of the column.

Source

pub fn cursor(&self) -> TextPosition

Cursor position.

Source

pub fn set_cursor( &mut self, cursor: impl Into<TextPosition>, extend_selection: bool, ) -> bool

Set the cursor position and scroll the cursor to a visible offset.

Source

pub fn anchor(&self) -> TextPosition

Selection anchor.

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, anchor: impl Into<TextPosition>, cursor: impl Into<TextPosition>, ) -> bool

Set the selection, anchor and cursor are capped to a valid value. Scrolls the cursor to a visible position.

Source

pub fn select_all(&mut self) -> bool

Select all. Scrolls the cursor to a visible position.

Source

pub fn selected_text(&self) -> Cow<'_, str>

Selected text.

Source§

impl TextAreaState

Source

pub fn is_empty(&self) -> bool

Empty.

Source

pub fn rope(&self) -> &Rope

Access the underlying rope.

Source

pub fn text(&self) -> String

Copy of the text-value.

Source

pub fn str_slice_byte(&self, range: Range<usize>) -> Cow<'_, str>

Text slice as Cow<str>. Uses a byte range.

Panics for an invalid range.

Source

pub fn try_str_slice_byte( &self, range: Range<usize>, ) -> Result<Cow<'_, str>, TextError>

Text slice as Cow<str>. Uses a byte range.

Source

pub fn str_slice(&self, range: impl Into<TextRange>) -> Cow<'_, str>

Text slice as Cow<str>

Panics for an invalid range.

Source

pub fn try_str_slice( &self, range: impl Into<TextRange>, ) -> Result<Cow<'_, str>, TextError>

Text slice as Cow<str>

Source

pub fn len_lines(&self) -> upos_type

Line count.

Source

pub fn line_width(&self, row: upos_type) -> upos_type

Line width as grapheme count.

Panics for an invalid row.

Source

pub fn try_line_width(&self, row: upos_type) -> Result<upos_type, TextError>

Line width as grapheme count.

Source

pub fn line_at(&self, row: upos_type) -> Cow<'_, str>

Line as Cow<str>. This contains the \n at the end.

Panics for an invalid row.

Source

pub fn try_line_at(&self, row: upos_type) -> Result<Cow<'_, str>, TextError>

Line as Cow<str>. This contains the \n at the end.

Source

pub fn lines_at(&self, row: upos_type) -> impl Iterator<Item = Cow<'_, str>>

Iterate over text-lines, starting at offset.

Panics for an invalid row.

Source

pub fn try_lines_at( &self, row: upos_type, ) -> Result<impl Iterator<Item = Cow<'_, str>>, TextError>

Iterate over text-lines, starting at offset.

Source

pub fn glyphs( &self, rows: Range<upos_type>, screen_offset: u16, screen_width: u16, ) -> impl Iterator<Item = Glyph<'_>>

👎Deprecated since 1.1.0: discontinued api

Iterator for the glyphs of the lines in range. Glyphs here a grapheme + display length.

Source

pub fn try_glyphs( &self, rows: Range<upos_type>, screen_offset: u16, screen_width: u16, ) -> Result<impl Iterator<Item = Glyph<'_>>, TextError>

👎Deprecated since 1.1.0: discontinued api

Iterator for the glyphs of the lines in range. Glyphs here a grapheme + display length.

Source

pub fn line_graphemes( &self, row: upos_type, ) -> impl Iterator<Item = Grapheme<'_>>

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

Panics for an invalid row.

Source

pub fn try_line_graphemes( &self, row: upos_type, ) -> Result<impl Iterator<Item = Grapheme<'_>>, TextError>

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

Source

pub fn text_graphemes( &self, pos: TextPosition, ) -> impl Cursor<Item = Grapheme<'_>>

Get a cursor over all the text with the current position set at pos.

Panics for an invalid pos.

Source

pub fn try_text_graphemes( &self, pos: TextPosition, ) -> Result<impl Cursor<Item = Grapheme<'_>>, TextError>

Get a cursor over all the text with the current position set at pos.

Source

pub fn graphemes( &self, range: TextRange, pos: TextPosition, ) -> impl Cursor<Item = Grapheme<'_>>

Get a cursor over the text-range the current position set at pos.

Panics for an invalid pos.

Source

pub fn try_graphemes( &self, range: TextRange, pos: TextPosition, ) -> Result<impl Cursor<Item = Grapheme<'_>>, TextError>

Get a cursor over the text-range the current position set at pos.

Source

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

Grapheme position to byte position. This is the (start,end) position of the single grapheme after pos.

Panics for an invalid pos.

Source

pub fn try_byte_at(&self, pos: TextPosition) -> Result<Range<usize>, TextError>

Grapheme position to byte position. This is the (start,end) position of the single grapheme after pos.

Source

pub fn bytes_at_range(&self, range: TextRange) -> Range<usize>

Grapheme range to byte range.

Panics for an invalid range.

Source

pub fn try_bytes_at_range( &self, range: TextRange, ) -> Result<Range<usize>, TextError>

Grapheme range to byte range.

Source

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

Byte position to grapheme position. Returns the position that contains the given byte index.

Panics for an invalid byte pos.

Source

pub fn try_byte_pos(&self, byte: usize) -> Result<TextPosition, TextError>

Byte position to grapheme position. Returns the position that contains the given byte index.

Source

pub fn byte_range(&self, bytes: Range<usize>) -> TextRange

Byte range to grapheme range.

Panics for an invalid range.

Source

pub fn try_byte_range( &self, bytes: Range<usize>, ) -> Result<TextRange, TextError>

Byte range to grapheme range.

Source§

impl TextAreaState

Source

pub fn clear(&mut self) -> bool

Clear everything.

Source

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

Set the text value.

Resets all internal state.

Source

pub fn set_rope(&mut self, r: Rope)

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

Source

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

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

You can insert a tab with this. But it will not indent the current selection. It will expand the tab though. Use insert_tab() for this.

You can insert a new-line with this. But it will not do an auto-indent. Use insert_new_line() for this.

Source

pub fn insert_tab(&mut self) -> bool

Inserts tab at the current position. This respects the tab-width set.

If there is a text-selection the text-rows will be indented instead. This can be deactivated with auto_indent=false.

Source

pub fn insert_backtab(&mut self) -> bool

Dedent the selected text by tab-width. If there is no selection this does nothing.

This can be deactivated with auto_indent=false.

Source

pub fn insert_str(&mut self, t: impl AsRef<str>) -> bool

Insert text at the cursor position. Removes the selection and inserts the text.

Source

pub fn insert_newline(&mut self) -> bool

Insert a line break at the cursor position.

If auto_indent is set the new line starts with the same indent as the current.

Source

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

Deletes the given range.

Panics for an invalid range.

Source

pub fn try_delete_range( &mut self, range: impl Into<TextRange>, ) -> Result<bool, TextError>

Deletes the given range.

Source§

impl TextAreaState

Source

pub fn duplicate_text(&mut self) -> bool

Duplicates the selection or the current line. Returns true if there was any real change.

Source

pub fn delete_line(&mut self) -> bool

Deletes the current line. Returns true if there was any real change.

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 next_word_start(&self, pos: impl Into<TextPosition>) -> TextPosition

Find the start of the next word. If the position is at the start or inside a word, the same position is returned.

Panics for an invalid pos.

Source

pub fn try_next_word_start( &self, pos: impl Into<TextPosition>, ) -> Result<TextPosition, TextError>

Find the start of the next word. If the position is at the start or inside a word, the same position is returned.

Source

pub fn next_word_end(&self, pos: impl Into<TextPosition>) -> TextPosition

Find the end of the next word. Skips whitespace first, then goes on until it finds the next whitespace.

Panics for an invalid pos.

Source

pub fn try_next_word_end( &self, pos: impl Into<TextPosition>, ) -> Result<TextPosition, TextError>

Find the end of the next word. Skips whitespace first, then goes on until it finds the next whitespace.

Source

pub fn prev_word_start(&self, pos: impl Into<TextPosition>) -> TextPosition

Find the start of the prev word. Skips whitespace first, then goes on until it finds the next whitespace.

Attention: start/end are mirrored here compared to next_word_start/next_word_end, both return start<=end!

Panics for an invalid range.

Source

pub fn try_prev_word_start( &self, pos: impl Into<TextPosition>, ) -> Result<TextPosition, TextError>

Find the start of the prev word. Skips whitespace first, then goes on until it finds the next whitespace.

Attention: start/end are mirrored here compared to next_word_start/next_word_end, both return start<=end!

Source

pub fn prev_word_end(&self, pos: impl Into<TextPosition>) -> TextPosition

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!

Panics for an invalid range.

Source

pub fn try_prev_word_end( &self, pos: impl Into<TextPosition>, ) -> Result<TextPosition, 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!

Source

pub fn is_word_boundary(&self, pos: impl Into<TextPosition>) -> bool

Is the position at a word boundary?

Panics for an invalid range.

Source

pub fn try_is_word_boundary( &self, pos: impl Into<TextPosition>, ) -> Result<bool, TextError>

Is the position at a word boundary?

Source

pub fn word_start(&self, pos: impl Into<TextPosition>) -> TextPosition

Find the start of the word at pos. Returns pos if the position is not inside a word.

Panics for an invalid range.

Source

pub fn try_word_start( &self, pos: impl Into<TextPosition>, ) -> Result<TextPosition, TextError>

Find the start of the word at pos. Returns pos if the position is not inside a word.

Source

pub fn word_end(&self, pos: impl Into<TextPosition>) -> TextPosition

Find the end of the word at pos. Returns pos if the position is not inside a word.

Panics for an invalid range.

Source

pub fn try_word_end( &self, pos: impl Into<TextPosition>, ) -> Result<TextPosition, TextError>

Find the end of the word at pos. Returns pos if the position is not inside a word.

Source

pub fn delete_next_word(&mut self) -> bool

Delete the next word. This alternates deleting the whitespace between words and the words themselves.

If there is a selection, removes only the selected text.

Source

pub fn delete_prev_word(&mut self) -> bool

Deletes the previous word. This alternates deleting the whitespace between words and the words themselves.

If there is a selection, removes only the selected text.

Source

pub fn move_left(&mut self, n: u16, 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: u16, 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: u16, 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: u16, 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

Move the cursor to the next word.

Source

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

Move the cursor to the previous word.

Source§

impl TextAreaState

Source

pub fn screen_to_pos(&self, scr_pos: (u16, u16)) -> Option<TextPosition>

Find the text-position for an absolute screen-position.

Source

pub fn pos_to_screen(&self, pos: TextPosition) -> Option<(u16, u16)>

Find the absolute screen-position for a text-position

Source

pub fn pos_to_line_start(&self, pos: TextPosition) -> TextPosition

Return the starting position for the visible line containing the given position.

Source

pub fn pos_to_line_end(&self, pos: TextPosition) -> TextPosition

Return the end position for the visible line containing the given position.

Source

pub fn pos_to_relative_screen(&self, pos: TextPosition) -> Option<(i16, i16)>

Return the screen_position for the given text position relative to the origin of the widget.

This may be outside the visible area, if the text-area has been relocated. It may even be outside the screen, so this returns an (i16, i16) as an absolute screen position.

If the text-position is outside the rendered area, this will return None.

Source

pub fn relative_screen_to_pos( &self, scr_pos: (i16, i16), ) -> Option<TextPosition>

Find the text-position for the widget-relative screen-position.

Source§

impl TextAreaState

Source

pub fn screen_to_row(&self, scy: i16) -> upos_type

👎Deprecated since 1.1.0: replaced by relative_screen_to_pos()

Converts from a widget relative screen coordinate to a line. It limits its result to a valid row.

Source

pub fn screen_to_col(&self, row: upos_type, scx: i16) -> upos_type

👎Deprecated since 1.1.0: replaced by relative_screen_to_pos()

Converts from a widget relative screen coordinate to a grapheme index. It limits its result to a valid column.

  • row is a row-index into the value, not a screen-row. It can be calculated with screen_to_row().
  • x is the relative screen position.
Source

pub fn try_screen_to_col( &self, row: upos_type, scx: i16, ) -> Result<upos_type, TextError>

👎Deprecated since 1.1.0: replaced by relative_screen_to_pos()

Converts from a widget relative screen coordinate to a grapheme index. It limits its result to a valid column.

  • row is a row-index into the value, not a screen-row. It can be calculated with screen_to_row().
  • x is the relative screen position.
Source

pub fn row_to_screen(&self, pos: impl Into<TextPosition>) -> Option<u16>

👎Deprecated since 1.1.0: replaced by pos_to_relative_screen()

Converts the row of the position to a screen position relative to the widget area.

Source

pub fn col_to_screen(&self, pos: impl Into<TextPosition>) -> Option<u16>

👎Deprecated since 1.1.0: replaced by pos_to_relative_screen()

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

Source

pub fn try_col_to_screen( &self, pos: impl Into<TextPosition>, ) -> Result<Option<u16>, TextError>

👎Deprecated since 1.1.0: replaced by pos_to_relative_screen()

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

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

pub fn set_screen_cursor_words( &mut self, cursor: (i16, 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.

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.

This offset is ignored if there is any text-wrapping.

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.

This scroll-offset is ignored if there is any text-wrapping.

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

Does nothing if there is any text-wrapping.

Source

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

Scrolling

Does nothing if there is any text-wrapping.

Source

pub fn scroll_sub_row_offset(&mut self, col: upos_type) -> bool

If there is some form of text-wrapping active, this changes the start-column for rendering the first visible line.

The effect looks like scrolling the visible rows.

Source§

impl TextAreaState

Source

pub fn scroll_cursor_to_visible(&mut self)

Scroll that the cursor is visible. All move-fn do this automatically.

Trait Implementations§

Source§

impl Clone for TextAreaState

Source§

fn clone(&self) -> Self

Returns a duplicate 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, 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 HandleEvent<Event, Regular, TextOutcome> for TextAreaState

Source§

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

Handle an event. Read more
Source§

impl HasFocus for TextAreaState

Source§

fn build(&self, builder: &mut FocusBuilder)

Build the focus-structure for the container.
Source§

fn focus(&self) -> FocusFlag

Access to the flag for the rest.
Source§

fn area(&self) -> Rect

Area for mouse focus. Read more
Source§

fn navigable(&self) -> Navigation

Declares how the widget interacts with focus. Read more
Source§

fn id(&self) -> usize

Provide a unique id for the widget.
Source§

fn area_z(&self) -> u16

Z value for the area. 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.
Source§

impl HasScreenCursor for TextAreaState

Source§

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

Cursor position on the screen.

Source§

impl RelocatableState for TextAreaState

Source§

fn relocate(&mut self, shift: (i16, i16), clip: Rect)

Relocate the areas in this widgets state. Read more

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§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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,

Source§

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

Source§

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

Source§

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.