pub struct TextInput<'a, Message, Theme = Theme, Renderer = Renderer>where
Theme: Catalog,
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 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 padding<P: Into<Padding>>(self, padding: P) -> Self
pub fn padding<P: Into<Padding>>(self, padding: P) -> Self
Sets the [Padding
] of the TextInput
.
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(
&self,
tree: &mut Tree,
layout: Layout<'_>,
_renderer: &Renderer,
operation: &mut dyn Operation,
)
fn operate( &self, tree: &mut Tree, layout: Layout<'_>, _renderer: &Renderer, operation: &mut dyn Operation, )
Applies an [
Operation
] to the [Widget
].Source§fn update(
&mut self,
tree: &mut Tree,
event: &Event,
layout: Layout<'_>,
cursor: Cursor,
renderer: &Renderer,
clipboard: &mut dyn Clipboard,
shell: &mut Shell<'_, Message>,
_viewport: &Rectangle,
)
fn update( &mut self, tree: &mut Tree, event: &Event, layout: Layout<'_>, cursor: Cursor, renderer: &Renderer, clipboard: &mut dyn Clipboard, 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, )
Draws the [
Widget
] using the associated Renderer
.Source§fn mouse_interaction(
&self,
_state: &Tree,
layout: Layout<'_>,
cursor: Cursor,
_viewport: &Rectangle,
_renderer: &Renderer,
) -> Interaction
fn mouse_interaction( &self, _state: &Tree, layout: Layout<'_>, cursor: Cursor, _viewport: &Rectangle, _renderer: &Renderer, ) -> Interaction
Auto Trait Implementations§
impl<'a, Message, Theme, Renderer> Freeze for TextInput<'a, Message, Theme, Renderer>
impl<'a, Message, Theme = Theme, Renderer = Renderer<Renderer, Renderer>> !RefUnwindSafe for TextInput<'a, Message, Theme, Renderer>
impl<'a, Message, Theme = Theme, Renderer = Renderer<Renderer, Renderer>> !Send for TextInput<'a, Message, Theme, Renderer>
impl<'a, Message, Theme = Theme, Renderer = Renderer<Renderer, Renderer>> !Sync for TextInput<'a, Message, Theme, Renderer>
impl<'a, Message, Theme, Renderer> Unpin for TextInput<'a, Message, Theme, Renderer>
impl<'a, Message, Theme = Theme, Renderer = Renderer<Renderer, Renderer>> !UnwindSafe for TextInput<'a, Message, Theme, Renderer>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn 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>
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)
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)
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.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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