Trait freya::hooks::TextEditor
source · pub trait TextEditor: Sized + Clone + Display {
type LinesIterator<'a>: Iterator<Item = Line<'a>>
where Self: 'a;
Show 24 methods
// Required methods
fn set(&mut self, text: &str);
fn lines(&self) -> Self::LinesIterator<'_>;
fn insert_char(&mut self, char: char, char_idx: usize);
fn insert(&mut self, text: &str, char_idx: usize);
fn remove(&mut self, range: Range<usize>);
fn char_to_line(&self, char_idx: usize) -> usize;
fn line_to_char(&self, line_idx: usize) -> usize;
fn line(&self, line_idx: usize) -> Option<Line<'_>>;
fn len_lines(&self) -> usize;
fn cursor(&self) -> &TextCursor;
fn cursor_mut(&mut self) -> &mut TextCursor;
fn highlights(&self, editor_id: usize) -> Option<(usize, usize)>;
fn unhighlight(&mut self);
fn highlight_text(&mut self, from: usize, to: usize, editor_id: usize);
fn move_highlight_to_cursor(&mut self);
// Provided methods
fn cursor_row(&self) -> usize { ... }
fn cursor_col(&self) -> usize { ... }
fn cursor_down(&mut self) { ... }
fn cursor_up(&mut self) { ... }
fn cursor_right(&mut self) { ... }
fn cursor_left(&mut self) { ... }
fn cursor_pos(&self) -> usize { ... }
fn set_cursor_pos(&mut self, pos: usize) { ... }
fn process_key(
&mut self,
key: &Key,
code: &Code,
modifiers: &Modifiers
) -> TextEvent { ... }
}
Expand description
Common trait for editable texts
Required Associated Types§
type LinesIterator<'a>: Iterator<Item = Line<'a>> where Self: 'a
Required Methods§
fn set(&mut self, text: &str)
sourcefn lines(&self) -> Self::LinesIterator<'_>
fn lines(&self) -> Self::LinesIterator<'_>
Iterator over all the lines in the text.
sourcefn insert_char(&mut self, char: char, char_idx: usize)
fn insert_char(&mut self, char: char, char_idx: usize)
Insert a character in the text in the given position.
sourcefn insert(&mut self, text: &str, char_idx: usize)
fn insert(&mut self, text: &str, char_idx: usize)
Insert a string in the text in the given position.
sourcefn char_to_line(&self, char_idx: usize) -> usize
fn char_to_line(&self, char_idx: usize) -> usize
Get line from the given char
sourcefn line_to_char(&self, line_idx: usize) -> usize
fn line_to_char(&self, line_idx: usize) -> usize
Get the first char from the given line
sourcefn cursor(&self) -> &TextCursor
fn cursor(&self) -> &TextCursor
Get a readable cursor
sourcefn cursor_mut(&mut self) -> &mut TextCursor
fn cursor_mut(&mut self) -> &mut TextCursor
Get a mutable cursor
fn highlights(&self, editor_id: usize) -> Option<(usize, usize)>
fn unhighlight(&mut self)
fn highlight_text(&mut self, from: usize, to: usize, editor_id: usize)
fn move_highlight_to_cursor(&mut self)
Provided Methods§
sourcefn cursor_row(&self) -> usize
fn cursor_row(&self) -> usize
Get the cursor row
sourcefn cursor_col(&self) -> usize
fn cursor_col(&self) -> usize
Get the cursor column
sourcefn cursor_down(&mut self)
fn cursor_down(&mut self)
Move the cursor 1 line down
sourcefn cursor_right(&mut self)
fn cursor_right(&mut self)
Move the cursor 1 char to the right
sourcefn cursor_left(&mut self)
fn cursor_left(&mut self)
Move the cursor 1 char to the left
sourcefn cursor_pos(&self) -> usize
fn cursor_pos(&self) -> usize
Get the cursor position
sourcefn set_cursor_pos(&mut self, pos: usize)
fn set_cursor_pos(&mut self, pos: usize)
Set the cursor position