Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Text input maybe #2390

Merged
merged 2 commits into from
Sep 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 34 additions & 5 deletions widget/src/text_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,23 @@ where
/// the [`TextInput`].
///
/// If this method is not called, the [`TextInput`] will be disabled.
pub fn on_input<F>(mut self, callback: F) -> Self
where
F: 'a + Fn(String) -> Message,
{
self.on_input = Some(Box::new(callback));
pub fn on_input(
mut self,
on_input: impl Fn(String) -> Message + 'a,
) -> Self {
self.on_input = Some(Box::new(on_input));
self
}

/// Sets the message that should be produced when some text is typed into
/// the [`TextInput`], if `Some`.
///
/// If `None`, the [`TextInput`] will be disabled.
pub fn on_input_maybe(
mut self,
on_input: Option<impl Fn(String) -> Message + 'a>,
) -> Self {
self.on_input = on_input.map(|f| Box::new(f) as _);
self
}

Expand All @@ -144,6 +156,13 @@ where
self
}

/// Sets the message that should be produced when the [`TextInput`] is
/// focused and the enter key is pressed, if `Some`.
pub fn on_submit_maybe(mut self, on_submit: Option<Message>) -> Self {
self.on_submit = on_submit;
self
}

/// Sets the message that should be produced when some text is pasted into
/// the [`TextInput`].
pub fn on_paste(
Expand All @@ -154,6 +173,16 @@ where
self
}

/// Sets the message that should be produced when some text is pasted into
/// the [`TextInput`], if `Some`.
pub fn on_paste_maybe(
mut self,
on_paste: Option<impl Fn(String) -> Message + 'a>,
) -> Self {
self.on_paste = on_paste.map(|f| Box::new(f) as _);
self
}

/// Sets the [`Font`] of the [`TextInput`].
///
/// [`Font`]: text::Renderer::Font
Expand Down
Loading