From ae517b9fa033ba75df5fc6ce766698fab22504fa Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 11 Mar 2021 03:38:20 +0100 Subject: Add `clipboard` argument to `Application::update` --- winit/src/application.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'winit/src') diff --git a/winit/src/application.rs b/winit/src/application.rs index 2cb2c016..d7d7660e 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -29,7 +29,7 @@ use std::mem::ManuallyDrop; /// /// When using an [`Application`] with the `debug` feature enabled, a debug view /// can be toggled by pressing `F12`. -pub trait Application: Program { +pub trait Application: Program { /// The data needed to initialize your [`Application`]. type Flags; @@ -257,6 +257,7 @@ async fn run_instance( &mut application, &mut runtime, &mut debug, + &mut clipboard, &mut messages, ); @@ -409,13 +410,14 @@ pub fn update( application: &mut A, runtime: &mut Runtime, A::Message>, debug: &mut Debug, + clipboard: &mut A::Clipboard, messages: &mut Vec, ) { for message in messages.drain(..) { debug.log_message(&message); debug.update_started(); - let command = runtime.enter(|| application.update(message)); + let command = runtime.enter(|| application.update(message, clipboard)); debug.update_finished(); runtime.spawn(command); -- cgit From a365998264420b1dac26a0de8e50ad4a33900885 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 11 Mar 2021 03:40:15 +0100 Subject: Expose `read` and `write` methods in `iced_winit::Clipboard` directly --- winit/src/clipboard.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'winit/src') diff --git a/winit/src/clipboard.rs b/winit/src/clipboard.rs index 15dc989f..ca25c065 100644 --- a/winit/src/clipboard.rs +++ b/winit/src/clipboard.rs @@ -20,17 +20,17 @@ impl Clipboard { Clipboard { state } } -} -impl iced_native::Clipboard for Clipboard { - fn read(&self) -> Option { + /// Reads the current content of the [`Clipboard`] as text. + pub fn read(&self) -> Option { match &self.state { State::Connected(clipboard) => clipboard.read().ok(), State::Unavailable => None, } } - fn write(&mut self, contents: String) { + /// Writes the given text contents to the [`Clipboard`]. + pub fn write(&mut self, contents: String) { match &mut self.state { State::Connected(clipboard) => match clipboard.write(contents) { Ok(()) => {} @@ -42,3 +42,13 @@ impl iced_native::Clipboard for Clipboard { } } } + +impl iced_native::Clipboard for Clipboard { + fn read(&self) -> Option { + self.read() + } + + fn write(&mut self, contents: String) { + self.write(contents) + } +} -- cgit