pub struct TextEditor<'a, Highlighter, Message, Theme = Theme, 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) -> Element<'_, Message> {
text_editor(&state.content)
.placeholder("Type something here...")
.on_action(Message::Edit)
.into()
}
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>
impl<'a, Message, Theme, Renderer> TextEditor<'a, PlainText, Message, Theme, Renderer>
Sourcepub fn new(content: &'a Content<Renderer>) -> Self
pub fn new(content: &'a Content<Renderer>) -> Self
Creates new TextEditor with the given Content.
Source§impl<'a, Highlighter, Message, Theme, Renderer> TextEditor<'a, Highlighter, Message, Theme, Renderer>
impl<'a, Highlighter, Message, Theme, Renderer> TextEditor<'a, Highlighter, Message, Theme, Renderer>
Sourcepub fn placeholder(self, placeholder: impl IntoFragment<'a>) -> Self
pub fn placeholder(self, placeholder: impl IntoFragment<'a>) -> Self
Sets the placeholder of the TextEditor.
Sourcepub fn width(self, width: impl Into<Pixels>) -> Self
pub fn width(self, width: impl Into<Pixels>) -> Self
Sets the width of the TextEditor.
Sourcepub fn height(self, height: impl Into<Length>) -> Self
pub fn height(self, height: impl Into<Length>) -> Self
Sets the height of the TextEditor.
Sourcepub fn min_height(self, min_height: impl Into<Pixels>) -> Self
pub fn min_height(self, min_height: impl Into<Pixels>) -> Self
Sets the minimum height of the TextEditor.
Sourcepub fn max_height(self, max_height: impl Into<Pixels>) -> Self
pub fn max_height(self, max_height: impl Into<Pixels>) -> Self
Sets the maximum height of the TextEditor.
Sourcepub fn on_action(self, on_edit: impl Fn(Action) -> Message + 'a) -> Self
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.
Sourcepub fn size(self, size: impl Into<Pixels>) -> Self
pub fn size(self, size: impl Into<Pixels>) -> Self
Sets the text size of the TextEditor.
Sourcepub fn line_height(self, line_height: impl Into<LineHeight>) -> Self
pub fn line_height(self, line_height: impl Into<LineHeight>) -> Self
Sets the text::LineHeight of the TextEditor.
Sourcepub fn wrapping(self, wrapping: Wrapping) -> Self
pub fn wrapping(self, wrapping: Wrapping) -> Self
Sets the Wrapping strategy of the TextEditor.
Sourcepub fn highlight(
self,
syntax: &str,
theme: Theme,
) -> TextEditor<'a, Highlighter, Message, Theme, Renderer>
Available on crate feature highlighter only.
pub fn highlight( self, syntax: &str, theme: Theme, ) -> TextEditor<'a, Highlighter, Message, Theme, Renderer>
highlighter only.Highlights the TextEditor using the given syntax and theme.
Sourcepub fn highlight_with<H: Highlighter>(
self,
settings: H::Settings,
to_format: fn(&H::Highlight, &Theme) -> Format<Renderer::Font>,
) -> TextEditor<'a, H, Message, Theme, Renderer>
pub fn highlight_with<H: Highlighter>( self, settings: H::Settings, to_format: fn(&H::Highlight, &Theme) -> Format<Renderer::Font>, ) -> TextEditor<'a, H, Message, Theme, Renderer>
Highlights the TextEditor with the given Highlighter and
a strategy to turn its highlights into some text format.
Sourcepub fn key_binding(
self,
key_binding: impl Fn(KeyPress) -> Option<Binding<Message>> + 'a,
) -> Self
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.
Sourcepub fn style(self, style: impl Fn(&Theme, Status) -> Style + 'a) -> Self
pub fn style(self, style: impl Fn(&Theme, Status) -> Style + 'a) -> Self
Sets the style of the TextEditor.
Sourcepub fn class(self, class: impl Into<Theme::Class<'a>>) -> Self
Available on crate feature advanced only.
pub fn class(self, class: impl Into<Theme::Class<'a>>) -> Self
advanced only.Sets the style class of the TextEditor.
Sourcepub fn input_purpose(self, purpose: Purpose) -> Self
pub fn input_purpose(self, purpose: Purpose) -> Self
Sets the IME input_method::Purpose of the TextEditor.
Trait Implementations§
Source§impl<'a, Highlighter, Message, Theme, Renderer> From<TextEditor<'a, Highlighter, Message, Theme, Renderer>> for Element<'a, Message, Theme, Renderer>
impl<'a, Highlighter, Message, Theme, Renderer> From<TextEditor<'a, Highlighter, Message, Theme, Renderer>> for Element<'a, Message, Theme, Renderer>
Source§fn from(
text_editor: TextEditor<'a, Highlighter, Message, Theme, Renderer>,
) -> Self
fn from( text_editor: TextEditor<'a, Highlighter, Message, Theme, Renderer>, ) -> Self
Source§impl<Highlighter, Message, Theme, Renderer> Widget<Message, Theme, Renderer> for TextEditor<'_, Highlighter, Message, Theme, Renderer>
impl<Highlighter, Message, Theme, Renderer> Widget<Message, Theme, Renderer> for TextEditor<'_, Highlighter, Message, Theme, Renderer>
Source§fn update(
&mut self,
tree: &mut Tree,
event: &Event,
layout: Layout<'_>,
cursor: Cursor,
renderer: &Renderer,
shell: &mut Shell<'_, Message>,
_viewport: &Rectangle,
)
fn update( &mut self, tree: &mut Tree, event: &Event, layout: Layout<'_>, cursor: Cursor, renderer: &Renderer, shell: &mut Shell<'_, Message>, _viewport: &Rectangle, )
Source§fn draw(
&self,
tree: &Tree,
renderer: &mut Renderer,
theme: &Theme,
_defaults: &Style,
layout: Layout<'_>,
_cursor: Cursor,
_viewport: &Rectangle,
)
fn draw( &self, tree: &Tree, renderer: &mut Renderer, theme: &Theme, _defaults: &Style, layout: Layout<'_>, _cursor: Cursor, _viewport: &Rectangle, )
Widget using the associated Renderer.