Allow clipboard access in Widget::on_event
This commit is contained in:
parent
0f2e20f5e5
commit
a14b39555e
20 changed files with 89 additions and 26 deletions
|
|
@ -13,6 +13,7 @@ debug = []
|
|||
[dependencies]
|
||||
iced_native = { version = "0.1.0-alpha", path = "../native" }
|
||||
winit = { version = "0.20.0-alpha3", git = "https://github.com/rust-windowing/winit", rev = "709808eb4e69044705fcb214bcc30556db761405"}
|
||||
window_clipboard = "=0.1.0-alpha.1"
|
||||
futures = { version = "0.3", features = ["thread-pool"] }
|
||||
log = "0.4"
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ use crate::{
|
|||
conversion,
|
||||
input::{keyboard, mouse},
|
||||
renderer::{Target, Windowed},
|
||||
subscription, Cache, Command, Container, Debug, Element, Event, Length,
|
||||
MouseCursor, Settings, Subscription, UserInterface,
|
||||
subscription, Cache, Clipboard, Command, Container, Debug, Element, Event,
|
||||
Length, MouseCursor, Settings, Subscription, UserInterface,
|
||||
};
|
||||
|
||||
/// An interactive, native cross-platform application.
|
||||
|
|
@ -139,6 +139,7 @@ pub trait Application: Sized {
|
|||
let mut size = window.inner_size();
|
||||
let mut resized = false;
|
||||
|
||||
let clipboard = Clipboard::new(&window);
|
||||
let mut renderer = Self::Renderer::new();
|
||||
|
||||
let mut target = {
|
||||
|
|
@ -193,8 +194,13 @@ pub trait Application: Sized {
|
|||
subscription_pool.broadcast_event(*event)
|
||||
});
|
||||
|
||||
let mut messages =
|
||||
user_interface.update(&renderer, events.drain(..));
|
||||
let mut messages = user_interface.update(
|
||||
&renderer,
|
||||
clipboard
|
||||
.as_ref()
|
||||
.map(|c| c as &dyn iced_native::Clipboard),
|
||||
events.drain(..),
|
||||
);
|
||||
messages.extend(external_messages.drain(..));
|
||||
debug.event_processing_finished();
|
||||
|
||||
|
|
|
|||
13
winit/src/clipboard.rs
Normal file
13
winit/src/clipboard.rs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
pub struct Clipboard(window_clipboard::Clipboard);
|
||||
|
||||
impl Clipboard {
|
||||
pub fn new(window: &winit::window::Window) -> Option<Clipboard> {
|
||||
window_clipboard::Clipboard::new(window).map(Clipboard).ok()
|
||||
}
|
||||
}
|
||||
|
||||
impl iced_native::Clipboard for Clipboard {
|
||||
fn content(&self) -> Option<String> {
|
||||
self.0.read().ok()
|
||||
}
|
||||
}
|
||||
|
|
@ -29,11 +29,9 @@ pub mod conversion;
|
|||
pub mod settings;
|
||||
|
||||
mod application;
|
||||
mod clipboard;
|
||||
mod subscription;
|
||||
|
||||
pub use application::Application;
|
||||
pub use settings::Settings;
|
||||
|
||||
// We disable debug capabilities on release builds unless the `debug` feature
|
||||
// is explicitly enabled.
|
||||
#[cfg(feature = "debug")]
|
||||
|
|
@ -43,4 +41,8 @@ mod debug;
|
|||
#[path = "debug/null.rs"]
|
||||
mod debug;
|
||||
|
||||
pub use application::Application;
|
||||
pub use settings::Settings;
|
||||
|
||||
use clipboard::Clipboard;
|
||||
use debug::Debug;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue