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;
}
Available on crate feature
advanced
only.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
.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.