diff options
author | 2021-09-02 15:12:55 +0700 | |
---|---|---|
committer | 2021-09-02 15:12:55 +0700 | |
commit | 7a335a0408b3ee426949a1936255666bc3383ea9 (patch) | |
tree | 01894e388d1629c181446c6f41b2204906726841 | |
parent | 6887afdb2c71429fa032d68f2ee3a4a075ecca1d (diff) | |
download | iced-7a335a0408b3ee426949a1936255666bc3383ea9.tar.gz iced-7a335a0408b3ee426949a1936255666bc3383ea9.tar.bz2 iced-7a335a0408b3ee426949a1936255666bc3383ea9.zip |
Implement and expose `read` and `write` helpers for `clipboard`
-rw-r--r-- | glutin/src/lib.rs | 5 | ||||
-rw-r--r-- | src/clipboard.rs | 3 | ||||
-rw-r--r-- | src/lib.rs | 1 | ||||
-rw-r--r-- | winit/src/clipboard.rs | 14 |
4 files changed, 22 insertions, 1 deletions
diff --git a/glutin/src/lib.rs b/glutin/src/lib.rs index 107d9556..cd987e2f 100644 --- a/glutin/src/lib.rs +++ b/glutin/src/lib.rs @@ -16,10 +16,13 @@ pub use iced_native::*; pub mod application; +pub use iced_winit::clipboard; pub use iced_winit::settings; -pub use iced_winit::{Clipboard, Error, Mode}; +pub use iced_winit::{Error, Mode}; #[doc(no_inline)] pub use application::Application; #[doc(no_inline)] +pub use clipboard::Clipboard; +#[doc(no_inline)] pub use settings::Settings; diff --git a/src/clipboard.rs b/src/clipboard.rs new file mode 100644 index 00000000..dde17051 --- /dev/null +++ b/src/clipboard.rs @@ -0,0 +1,3 @@ +//! Access the clipboard. +#[cfg(not(target_arch = "wasm32"))] +pub use crate::runtime::clipboard::{read, write}; @@ -183,6 +183,7 @@ mod error; mod result; mod sandbox; +pub mod clipboard; pub mod executor; pub mod keyboard; pub mod mouse; 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<Message>( + f: impl Fn(Option<String>) -> Message + 'static, +) -> Command<Message> { + Command::Single(command::Action::Clipboard(Action::Read(Box::new(f)))) +} + +/// Write the given contents to the clipboard. +pub fn write<Message>(contents: String) -> Command<Message> { + Command::Single(command::Action::Clipboard(Action::Write(contents))) +} |