From 7a335a0408b3ee426949a1936255666bc3383ea9 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 2 Sep 2021 15:12:55 +0700 Subject: Implement and expose `read` and `write` helpers for `clipboard` --- winit/src/clipboard.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'winit') diff --git a/winit/src/clipboard.rs b/winit/src/clipboard.rs index 9d0663fa..05d991ff 100644 --- a/winit/src/clipboard.rs +++ b/winit/src/clipboard.rs @@ -1,6 +1,8 @@ //! Access the clipboard. pub use iced_native::clipboard::Action; +use crate::command::{self, Command}; + /// A buffer for short-term storage and transfer within and between /// applications. #[allow(missing_debug_implementations)] @@ -55,3 +57,15 @@ impl iced_native::Clipboard for Clipboard { self.write(contents) } } + +/// Read the current contents of the clipboard. +pub fn read( + f: impl Fn(Option) -> Message + 'static, +) -> Command { + Command::Single(command::Action::Clipboard(Action::Read(Box::new(f)))) +} + +/// Write the given contents to the clipboard. +pub fn write(contents: String) -> Command { + Command::Single(command::Action::Clipboard(Action::Write(contents))) +} -- cgit