Skip to main content

TextEditor

Struct TextEditor 

Source
pub struct TextEditor<'a, Parser, Message, Theme = Theme, Renderer = Renderer>
where Parser: Parser, Theme: Catalog, Renderer: Renderer,
{ /* private fields */ }
Expand description

A multi-line text input.

§Example

use iced::widget::text_editor;

struct State {
   content: text_editor::Content,
}

#[derive(Debug, Clone)]
enum Message {
    Edit(text_editor::Action)
}

fn view(state: &State) -> impl Widget<Message> {
    text_editor(&state.content)
        .placeholder("Type something here...")
        .on_action(Message::Edit)
}

fn update(state: &mut State, message: Message) {
    match message {
        Message::Edit(action) => {
            state.content.perform(action);
        }
    }
}

Implementations§

Source§

impl<'a, Message, Theme, Renderer> TextEditor<'a, PlainText, Message, Theme, Renderer>
where Theme: Catalog, Renderer: Renderer,

Source

pub fn new(content: &'a Content<Renderer>) -> Self

Creates new TextEditor with the given Content.

Source§

impl<'a, Message, Renderer> TextEditor<'a, PlainText, Message, Theme, Renderer>
where Renderer: Renderer,

Source

pub fn highlight( self, syntax: &str, ) -> TextEditor<'a, Parser, Message, Theme, Renderer>
where Renderer: Renderer,

Available on crate feature highlighter only.

Highlights the TextEditor using the given syntax.

use iced::color;
use iced::widget::text;
use iced::widget::text_editor;
use iced::Theme;

struct State {
   content: text_editor::Content,
}

fn view(state: &State) -> impl Widget<()> {
    text_editor(&state.content)
        .highlight("rust")
}
Source§

impl<'a, Parser, Message, Theme, Renderer> TextEditor<'a, Parser, Message, Theme, Renderer>
where Parser: Parser, Theme: Catalog, Renderer: Renderer,

Source

pub fn id(self, id: impl Into<Id>) -> Self

Sets the Id of the TextEditor.

Source

pub fn placeholder(self, placeholder: impl IntoFragment<'a>) -> Self

Sets the placeholder of the TextEditor.

Source

pub fn width(self, width: impl Into<Pixels>) -> Self

Sets the width of the TextEditor.

Source

pub fn height(self, height: impl Into<Length>) -> Self

Sets the height of the TextEditor.

Source

pub fn on_action(self, on_edit: impl Fn(Action) -> Message + 'a) -> Self

Sets the message that should be produced when some action is performed in the TextEditor.

If this method is not called, the TextEditor will be disabled.

Source

pub fn font(self, font: impl Into<Font>) -> Self

Sets the Font of the TextEditor.

Source

pub fn size(self, size: impl Into<Pixels>) -> Self

Sets the text size of the TextEditor.

Source

pub fn line_height(self, line_height: impl Into<LineHeight>) -> Self

Sets the text::LineHeight of the TextEditor.

Source

pub fn padding(self, padding: impl Into<Padding>) -> Self

Sets the [Padding] of the TextEditor.

Source

pub fn wrapping(self, wrapping: Wrapping) -> Self

Sets the Wrapping strategy of the TextEditor.

Source

pub fn highlight_with<P: Parser>( self, settings: P::Settings, highlighter: impl Highlighter<P::Output, Theme> + 'a, ) -> TextEditor<'a, P, Message, Theme, Renderer>

Highlights the TextEditor with the given text::Parser and text::Highlighter.

Source

pub fn key_binding( self, key_binding: impl Fn(KeyPress) -> Option<Binding<Message>> + 'a, ) -> Self

Sets the closure to produce key bindings on key presses.

See Binding for the list of available bindings.

Source

pub fn style(self, style: impl Fn(&Theme, Status) -> Style + 'a) -> Self
where Theme::Class<'a>: From<StyleFn<'a, Theme>>,

Sets the style of the TextEditor.

Source

pub fn class(self, class: impl Into<Theme::Class<'a>>) -> Self

Available on crate feature advanced only.

Sets the style class of the TextEditor.

Trait Implementations§

Source§

impl<Parser, Message, Theme, Renderer> Meta for TextEditor<'_, Parser, Message, Theme, Renderer>
where Parser: Parser, Theme: Catalog, Renderer: Renderer,

§

fn is_void(&self) -> bool

Returns whether the [Widget] is Void.
Source§

impl<Parser, Message, Theme, Renderer> Widget<Message, Theme, Renderer> for TextEditor<'_, Parser, Message, Theme, Renderer>
where Parser: Parser, Theme: Catalog, Renderer: Renderer,

Source§

fn tag(&self) -> Tag

Returns the Tag of the [Widget].
Source§

fn state(&self) -> State

Returns the State of the [Widget].
Source§

fn size(&self) -> Size<Length>

Returns the [Size] of the [Widget] in lengths.
Source§

fn layout(&mut self, tree: &mut Tree, renderer: &Renderer, limits: &Limits)

Lays out the [Widget]. Read more
Source§

fn update( &mut self, tree: &mut Tree, event: &Event, layout: Layout, cursor: Cursor, _renderer: &Renderer, shell: &mut Shell<'_, Message>, _viewport: &Rectangle, )

Processes a runtime Event. Read more
Source§

fn draw( &self, tree: &Tree, renderer: &mut Renderer, theme: &Theme, _defaults: &Style, layout: Layout, _cursor: Cursor, viewport: &Rectangle, )

Draws the [Widget] using the associated Renderer.
Source§

fn mouse_interaction( &self, _tree: &Tree, layout: Layout, cursor: Cursor, _viewport: &Rectangle, _renderer: &Renderer, ) -> Interaction

Returns the current [mouse::Interaction] of the [Widget]. Read more
Source§

fn operate( &mut self, tree: &mut Tree, layout: Layout, _viewport: &Rectangle, _renderer: &Renderer, operation: &mut dyn Operation, )

Applies an [Operation] to the [Widget].
§

fn diff(&mut self, tree: &mut Tree)

Reconciles the [Widget] with the provided [Tree].
§

fn overlay<'a>( &'a mut self, _tree: &'a mut Tree, _layout: Layout, _renderer: &Renderer, _viewport: &Rectangle, _translation: Vector, _window: Size, ) -> Vec<Element<'a, Message, Theme, Renderer>>

Returns the overlays of the [Widget].
§

fn _map<F, B>(self, f: F) -> Map<Self, F, Message>
where Self: Sized, F: Fn(Message) -> B,

Applies a transformation to the produced message of this [Widget], returning a [Map]. Read more
§

fn _boxed<'a>(self) -> Element<'a, Message, Theme, Renderer>
where Self: Sized + 'a,

Boxes this [Widget], turning it into a generic [Element].

Auto Trait Implementations§

§

impl<'a, Parser, Message, Theme, Renderer> Freeze for TextEditor<'a, Parser, Message, Theme, Renderer>
where <Theme as Catalog>::Class<'a>: Freeze, <Parser as Parser>::Settings: Freeze,

§

impl<'a, Parser, Message, Theme = Theme, Renderer = Renderer<Renderer, Renderer>> !RefUnwindSafe for TextEditor<'a, Parser, Message, Theme, Renderer>

§

impl<'a, Parser, Message, Theme = Theme, Renderer = Renderer<Renderer, Renderer>> !Send for TextEditor<'a, Parser, Message, Theme, Renderer>

§

impl<'a, Parser, Message, Theme = Theme, Renderer = Renderer<Renderer, Renderer>> !Sync for TextEditor<'a, Parser, Message, Theme, Renderer>

§

impl<'a, Parser, Message, Theme, Renderer> Unpin for TextEditor<'a, Parser, Message, Theme, Renderer>
where <Theme as Catalog>::Class<'a>: Unpin, <Parser as Parser>::Settings: Unpin,

§

impl<'a, Parser, Message, Theme, Renderer> UnsafeUnpin for TextEditor<'a, Parser, Message, Theme, Renderer>
where <Theme as Catalog>::Class<'a>: UnsafeUnpin, <Parser as Parser>::Settings: UnsafeUnpin,

§

impl<'a, Parser, Message, Theme = Theme, Renderer = Renderer<Renderer, Renderer>> !UnwindSafe for TextEditor<'a, Parser, Message, Theme, Renderer>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

Source§

impl<T, Message, Theme, Renderer> Widget<Message, Theme, Renderer> for T
where T: Widget<Message, Theme, Renderer>,

Source§

fn map<F, B>(self, f: F) -> Map<Self, F, Message>
where Self: Sized, F: Fn(Message) -> B,

Applies a transformation to the produced message of this Widget. Read more
Source§

fn boxed<'a>(self) -> Element<'a, Message, Theme, Renderer>
where Self: Sized + 'a,

Boxes this Widget, turning it into a generic Element.
Source§

fn explain( self, color: impl Into<Color>, ) -> impl Widget<Message, Theme, Renderer>
where Self: Sized, Renderer: Renderer,

Marks this Widget as to-be-explained. Read more
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,