iced::advanced::text::editor

Trait Editor

Source
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§

Source

type Font: Copy + PartialEq + Default

The font of the Editor.

Required Methods§

Source

fn with_text(text: &str) -> Self

Creates a new Editor laid out with the given text.

Source

fn is_empty(&self) -> bool

Returns true if the Editor has no contents.

Source

fn cursor(&self) -> Cursor

Returns the current Cursor of the Editor.

Source

fn cursor_position(&self) -> (usize, usize)

Returns the current cursor position of the Editor.

Line and column, respectively.

Source

fn selection(&self) -> Option<String>

Returns the current selected text of the Editor.

Source

fn line(&self, index: usize) -> Option<&str>

Returns the text of the given line in the Editor, if it exists.

Source

fn line_count(&self) -> usize

Returns the amount of lines in the Editor.

Source

fn perform(&mut self, action: Action)

Performs an Action on the Editor.

Source

fn bounds(&self) -> Size

Returns the current boundaries of the Editor.

Source

fn min_bounds(&self) -> Size

Returns the minimum boundaries to fit the current contents of the Editor.

Source

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.

Source

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.

Implementations on Foreign Types§

Source§

impl Editor for ()

Source§

type Font = Font

Source§

fn with_text(_text: &str)

Source§

fn is_empty(&self) -> bool

Source§

fn cursor(&self) -> Cursor

Source§

fn cursor_position(&self) -> (usize, usize)

Source§

fn selection(&self) -> Option<String>

Source§

fn line(&self, _index: usize) -> Option<&str>

Source§

fn line_count(&self) -> usize

Source§

fn perform(&mut self, _action: Action)

Source§

fn bounds(&self) -> Size

Source§

fn min_bounds(&self) -> Size

Source§

fn update( &mut self, _new_bounds: Size, _new_font: <() as Editor>::Font, _new_size: Pixels, _new_line_height: LineHeight, _new_wrapping: Wrapping, _new_highlighter: &mut impl Highlighter, )

Source§

fn highlight<H>( &mut self, _font: <() as Editor>::Font, _highlighter: &mut H, _format_highlight: impl Fn(&<H as Highlighter>::Highlight) -> Format<<() as Editor>::Font>, )
where H: Highlighter,

Source§

impl Editor for Editor

Source§

type Font = Font

Source§

fn with_text(text: &str) -> Editor

Source§

fn is_empty(&self) -> bool

Source§

fn line(&self, index: usize) -> Option<&str>

Source§

fn line_count(&self) -> usize

Source§

fn selection(&self) -> Option<String>

Source§

fn cursor(&self) -> Cursor

Source§

fn cursor_position(&self) -> (usize, usize)

Source§

fn perform(&mut self, action: Action)

Source§

fn bounds(&self) -> Size

Source§

fn min_bounds(&self) -> Size

Source§

fn update( &mut self, new_bounds: Size, new_font: Font, new_size: Pixels, new_line_height: LineHeight, new_wrapping: Wrapping, new_highlighter: &mut impl Highlighter, )

Source§

fn highlight<H>( &mut self, font: <Editor as Editor>::Font, highlighter: &mut H, format_highlight: impl Fn(&<H as Highlighter>::Highlight) -> Format<<Editor as Editor>::Font>, )
where H: Highlighter,

Implementors§