Added on_paste handler to TextInput
This commit is contained in:
parent
1404b88ea6
commit
e8cfa644e7
2 changed files with 28 additions and 3 deletions
|
|
@ -66,6 +66,7 @@ where
|
||||||
padding: Padding,
|
padding: Padding,
|
||||||
size: Option<u16>,
|
size: Option<u16>,
|
||||||
on_change: Box<dyn Fn(String) -> Message + 'a>,
|
on_change: Box<dyn Fn(String) -> Message + 'a>,
|
||||||
|
on_paste: Option<Box<dyn Fn(String) -> Message + 'a>>,
|
||||||
on_submit: Option<Message>,
|
on_submit: Option<Message>,
|
||||||
style: <Renderer::Theme as StyleSheet>::Style,
|
style: <Renderer::Theme as StyleSheet>::Style,
|
||||||
}
|
}
|
||||||
|
|
@ -102,6 +103,7 @@ where
|
||||||
padding: Padding::ZERO,
|
padding: Padding::ZERO,
|
||||||
size: None,
|
size: None,
|
||||||
on_change: Box::new(on_change),
|
on_change: Box::new(on_change),
|
||||||
|
on_paste: None,
|
||||||
on_submit: None,
|
on_submit: None,
|
||||||
style: Default::default(),
|
style: Default::default(),
|
||||||
}
|
}
|
||||||
|
|
@ -112,7 +114,14 @@ where
|
||||||
self.is_secure = true;
|
self.is_secure = true;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
/// Set's the message that should be produced when a message is pasted into the [`TextInput`].
|
||||||
|
pub fn on_paste<OnPaste>(mut self, on_paste: OnPaste) -> Self
|
||||||
|
where
|
||||||
|
OnPaste: 'a + Fn(String) -> Message,
|
||||||
|
{
|
||||||
|
self.on_paste = Some(Box::new(on_paste));
|
||||||
|
self
|
||||||
|
}
|
||||||
/// Sets the [`Font`] of the [`TextInput`].
|
/// Sets the [`Font`] of the [`TextInput`].
|
||||||
///
|
///
|
||||||
/// [`Font`]: crate::text::Renderer::Font
|
/// [`Font`]: crate::text::Renderer::Font
|
||||||
|
|
@ -225,6 +234,7 @@ pub fn update<'a, Message, Renderer>(
|
||||||
font: &Renderer::Font,
|
font: &Renderer::Font,
|
||||||
is_secure: bool,
|
is_secure: bool,
|
||||||
on_change: &dyn Fn(String) -> Message,
|
on_change: &dyn Fn(String) -> Message,
|
||||||
|
on_paste: &Option<Box<dyn Fn(String) -> Message + 'a>>,
|
||||||
on_submit: &Option<Message>,
|
on_submit: &Option<Message>,
|
||||||
state: impl FnOnce() -> &'a mut State,
|
state: impl FnOnce() -> &'a mut State,
|
||||||
) -> event::Status
|
) -> event::Status
|
||||||
|
|
@ -512,7 +522,11 @@ where
|
||||||
|
|
||||||
editor.paste(content.clone());
|
editor.paste(content.clone());
|
||||||
|
|
||||||
let message = (on_change)(editor.contents());
|
let message = if let Some(paste) = &on_paste {
|
||||||
|
(paste)(editor.contents())
|
||||||
|
} else {
|
||||||
|
(on_change)(editor.contents())
|
||||||
|
};
|
||||||
shell.publish(message);
|
shell.publish(message);
|
||||||
|
|
||||||
state.is_pasting = Some(content);
|
state.is_pasting = Some(content);
|
||||||
|
|
@ -804,6 +818,7 @@ where
|
||||||
&self.font,
|
&self.font,
|
||||||
self.is_secure,
|
self.is_secure,
|
||||||
self.on_change.as_ref(),
|
self.on_change.as_ref(),
|
||||||
|
&self.on_paste,
|
||||||
&self.on_submit,
|
&self.on_submit,
|
||||||
|| &mut self.state,
|
|| &mut self.state,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,7 @@ where
|
||||||
padding: Padding,
|
padding: Padding,
|
||||||
size: Option<u16>,
|
size: Option<u16>,
|
||||||
on_change: Box<dyn Fn(String) -> Message + 'a>,
|
on_change: Box<dyn Fn(String) -> Message + 'a>,
|
||||||
|
on_paste: Option<Box<dyn Fn(String) -> Message + 'a>>,
|
||||||
on_submit: Option<Message>,
|
on_submit: Option<Message>,
|
||||||
style: <Renderer::Theme as StyleSheet>::Style,
|
style: <Renderer::Theme as StyleSheet>::Style,
|
||||||
}
|
}
|
||||||
|
|
@ -75,6 +76,7 @@ where
|
||||||
padding: Padding::ZERO,
|
padding: Padding::ZERO,
|
||||||
size: None,
|
size: None,
|
||||||
on_change: Box::new(on_change),
|
on_change: Box::new(on_change),
|
||||||
|
on_paste: None,
|
||||||
on_submit: None,
|
on_submit: None,
|
||||||
style: Default::default(),
|
style: Default::default(),
|
||||||
}
|
}
|
||||||
|
|
@ -85,7 +87,14 @@ where
|
||||||
self.is_secure = true;
|
self.is_secure = true;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
/// Set's the message that should be produced when a message is pasted into the [`TextInput`].
|
||||||
|
pub fn on_paste<OnPaste>(mut self, on_paste: OnPaste) -> Self
|
||||||
|
where
|
||||||
|
OnPaste: 'a + Fn(String) -> Message,
|
||||||
|
{
|
||||||
|
self.on_paste = Some(Box::new(on_paste));
|
||||||
|
self
|
||||||
|
}
|
||||||
/// Sets the [`Font`] of the [`TextInput`].
|
/// Sets the [`Font`] of the [`TextInput`].
|
||||||
///
|
///
|
||||||
/// [`Font`]: text::Renderer::Font
|
/// [`Font`]: text::Renderer::Font
|
||||||
|
|
@ -215,6 +224,7 @@ where
|
||||||
&self.font,
|
&self.font,
|
||||||
self.is_secure,
|
self.is_secure,
|
||||||
self.on_change.as_ref(),
|
self.on_change.as_ref(),
|
||||||
|
&self.on_paste,
|
||||||
&self.on_submit,
|
&self.on_submit,
|
||||||
|| tree.state.downcast_mut::<text_input::State>(),
|
|| tree.state.downcast_mut::<text_input::State>(),
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue