diff options
author | 2024-04-17 13:42:35 +0200 | |
---|---|---|
committer | 2024-09-07 22:57:15 +0200 | |
commit | 827ba5b16c4acb1b63535898d4ef7df5ea2b8703 (patch) | |
tree | ccf2c053821bfc56fab9a21c80c348a04794bc51 /widget | |
parent | 9426418adbaac40f584fe16b623521a3a21a1a4c (diff) | |
download | iced-827ba5b16c4acb1b63535898d4ef7df5ea2b8703.tar.gz iced-827ba5b16c4acb1b63535898d4ef7df5ea2b8703.tar.bz2 iced-827ba5b16c4acb1b63535898d4ef7df5ea2b8703.zip |
Add `*_maybe` helper methods for `TextInput`
Diffstat (limited to 'widget')
-rw-r--r-- | widget/src/text_input.rs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/widget/src/text_input.rs b/widget/src/text_input.rs index 92047381..e129826c 100644 --- a/widget/src/text_input.rs +++ b/widget/src/text_input.rs @@ -137,6 +137,21 @@ where 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<F>(mut self, callback: Option<F>) -> Self + where + F: 'a + Fn(String) -> Message, + { + self.on_input = match callback { + Some(c) => Some(Box::new(c)), + None => None, + }; + self + } + /// Sets the message that should be produced when the [`TextInput`] is /// focused and the enter key is pressed. pub fn on_submit(mut self, message: Message) -> Self { @@ -144,6 +159,15 @@ where self } + /// Sets the message that should be produced when the [`TextInput`] is + /// focused and the enter key is pressed, if `Some`. + /// + /// If `None` the [`TextInput`] nothing will happen. + 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( @@ -154,6 +178,21 @@ where self } + /// Sets the message that should be produced when some text is pasted into + /// the [`TextInput`], if `Some`. + /// + /// If `None` nothing will happen. + pub fn on_paste_maybe( + mut self, + on_paste: Option<impl Fn(String) -> Message + 'a>, + ) -> Self { + self.on_paste = match on_paste { + Some(func) => Some(Box::new(func)), + None => None, + }; + self + } + /// Sets the [`Font`] of the [`TextInput`]. /// /// [`Font`]: text::Renderer::Font |