pub struct TextInput<'a, Message, Theme = Theme, Renderer = Renderer>{ /* private fields */ }Expand description
A field that can be filled with text.
§Example
use iced::widget::text_input;
struct State {
content: String,
}
#[derive(Debug, Clone)]
enum Message {
ContentChanged(String)
}
fn view(state: &State) -> Element<'_, Message> {
text_input("Type something here...", &state.content)
.on_input(Message::ContentChanged)
.into()
}
fn update(state: &mut State, message: Message) {
match message {
Message::ContentChanged(content) => {
state.content = content;
}
}
}Implementations§
Source§impl<'a, Message, Theme, Renderer> TextInput<'a, Message, Theme, Renderer>
impl<'a, Message, Theme, Renderer> TextInput<'a, Message, Theme, Renderer>
Sourcepub fn new(placeholder: &str, value: &str) -> Self
pub fn new(placeholder: &str, value: &str) -> Self
Creates a new TextInput with the given placeholder and
its current value.
Sourcepub fn secure(self, is_secure: bool) -> Self
pub fn secure(self, is_secure: bool) -> Self
Converts the TextInput into a secure password input.
Sourcepub fn input_purpose(self, purpose: Purpose) -> Self
pub fn input_purpose(self, purpose: Purpose) -> Self
Sets the IME input_method::Purpose of the TextInput.
This overrides the default purpose derived from Self::secure.
Sourcepub fn on_input_maybe(
self,
on_input: Option<impl Fn(String) -> Message + 'a>,
) -> Self
pub fn on_input_maybe( self, on_input: Option<impl Fn(String) -> Message + 'a>, ) -> Self
Sourcepub fn on_submit(self, message: Message) -> Self
pub fn on_submit(self, message: Message) -> Self
Sets the message that should be produced when the TextInput is
focused and the enter key is pressed.
Sourcepub fn on_submit_maybe(self, on_submit: Option<Message>) -> Self
pub fn on_submit_maybe(self, on_submit: Option<Message>) -> Self
Sets the message that should be produced when the TextInput is
focused and the enter key is pressed, if Some.
Sourcepub fn on_paste(self, on_paste: impl Fn(String) -> Message + 'a) -> Self
pub fn on_paste(self, on_paste: impl Fn(String) -> Message + 'a) -> Self
Sets the message that should be produced when some text is pasted into
the TextInput.
Sourcepub fn on_paste_maybe(
self,
on_paste: Option<impl Fn(String) -> Message + 'a>,
) -> Self
pub fn on_paste_maybe( self, on_paste: Option<impl Fn(String) -> Message + 'a>, ) -> Self
Sets the message that should be produced when some text is pasted into
the TextInput, if Some.
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 TextInput.
Sourcepub fn align_x(self, alignment: impl Into<Horizontal>) -> Self
pub fn align_x(self, alignment: impl Into<Horizontal>) -> Self
Sets the horizontal alignment of the TextInput.
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 TextInput.
Sourcepub fn class(self, class: impl Into<Theme::Class<'a>>) -> Self
pub fn class(self, class: impl Into<Theme::Class<'a>>) -> Self
Sets the style class of the TextInput.
Trait Implementations§
Source§impl<'a, Message, Theme, Renderer> From<TextInput<'a, Message, Theme, Renderer>> for Element<'a, Message, Theme, Renderer>
impl<'a, Message, Theme, Renderer> From<TextInput<'a, Message, Theme, Renderer>> for Element<'a, Message, Theme, Renderer>
Source§impl<Message, Theme, Renderer> Widget<Message, Theme, Renderer> for TextInput<'_, Message, Theme, Renderer>
impl<Message, Theme, Renderer> Widget<Message, Theme, Renderer> for TextInput<'_, Message, Theme, Renderer>
Source§fn operate(
&mut self,
tree: &mut Tree,
layout: Layout<'_>,
_renderer: &Renderer,
operation: &mut dyn Operation,
)
fn operate( &mut self, tree: &mut Tree, layout: Layout<'_>, _renderer: &Renderer, operation: &mut dyn Operation, )
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,
_style: &Style,
layout: Layout<'_>,
cursor: Cursor,
viewport: &Rectangle,
)
fn draw( &self, tree: &Tree, renderer: &mut Renderer, theme: &Theme, _style: &Style, layout: Layout<'_>, cursor: Cursor, viewport: &Rectangle, )
Widget using the associated Renderer.