pub trait Editor: Sized + Default {
type Font: Copy + PartialEq + Default;
// Required methods
fn with_text(text: &str) -> Self;
fn is_empty(&self) -> bool;
fn cursor(&self) -> Cursor;
fn cursor_position(&self) -> (usize, usize);
fn selection(&self) -> Option<String>;
fn line(&self, index: usize) -> Option<&str>;
fn line_count(&self) -> usize;
fn perform(&mut self, action: Action);
fn bounds(&self) -> Size;
fn min_bounds(&self) -> Size;
fn update(
&mut self,
new_bounds: Size,
new_font: Self::Font,
new_size: Pixels,
new_line_height: LineHeight,
new_wrapping: Wrapping,
new_highlighter: &mut impl Highlighter,
);
fn highlight<H>(
&mut self,
font: Self::Font,
highlighter: &mut H,
format_highlight: impl Fn(&<H as Highlighter>::Highlight) -> Format<Self::Font>,
)
where H: Highlighter;
}
Expand description
A component that can be used by widgets to edit multi-line text.
Required Associated Types§
Required Methods§
sourcefn cursor_position(&self) -> (usize, usize)
fn cursor_position(&self) -> (usize, usize)
Returns the current cursor position of the Editor
.
Line and column, respectively.
sourcefn line(&self, index: usize) -> Option<&str>
fn line(&self, index: usize) -> Option<&str>
Returns the text of the given line in the Editor
, if it exists.
sourcefn line_count(&self) -> usize
fn line_count(&self) -> usize
Returns the amount of lines in the Editor
.
sourcefn min_bounds(&self) -> Size
fn min_bounds(&self) -> Size
Returns the minimum boundaries to fit the current contents of
the Editor
.
sourcefn update(
&mut self,
new_bounds: Size,
new_font: Self::Font,
new_size: Pixels,
new_line_height: LineHeight,
new_wrapping: Wrapping,
new_highlighter: &mut impl Highlighter,
)
fn update( &mut self, new_bounds: Size, new_font: Self::Font, new_size: Pixels, new_line_height: LineHeight, new_wrapping: Wrapping, new_highlighter: &mut impl Highlighter, )
Updates the Editor
with some new attributes.
sourcefn highlight<H>(
&mut self,
font: Self::Font,
highlighter: &mut H,
format_highlight: impl Fn(&<H as Highlighter>::Highlight) -> Format<Self::Font>,
)where
H: Highlighter,
fn highlight<H>(
&mut self,
font: Self::Font,
highlighter: &mut H,
format_highlight: impl Fn(&<H as Highlighter>::Highlight) -> Format<Self::Font>,
)where
H: Highlighter,
Runs a text Highlighter
in the Editor
.
Object Safety§
This trait is not object safe.