iced::advanced::text

Trait Editor

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§

type Font: Copy + PartialEq + Default

The font of the Editor.

Required Methods§

fn with_text(text: &str) -> Self

Creates a new Editor laid out with the given text.

fn is_empty(&self) -> bool

Returns true if the Editor has no contents.

fn cursor(&self) -> Cursor

Returns the current Cursor of the Editor.

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

Returns the current cursor position of the Editor.

Line and column, respectively.

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

Returns the current selected text of the Editor.

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

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

fn line_count(&self) -> usize

Returns the amount of lines in the Editor.

fn perform(&mut self, action: Action)

Performs an Action on the Editor.

fn bounds(&self) -> Size

Returns the current boundaries of the Editor.

fn min_bounds(&self) -> Size

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

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.

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§

§

impl Editor for ()

§

type Font = Font

§

fn with_text(_text: &str)

§

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: <() as Editor>::Font, _new_size: Pixels, _new_line_height: LineHeight, _new_wrapping: Wrapping, _new_highlighter: &mut impl Highlighter, )

§

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§