Remove T from EventLoopTargetWindow (#3081)

Co-authored-by: nerditation <12248559+nerditation@users.noreply.github.com>
This commit is contained in:
daxpedda 2023-09-03 02:26:53 +02:00 committed by GitHub
parent d68d9eab38
commit 7a2a2341c2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 78 additions and 48 deletions

View file

@ -1,24 +1,30 @@
use std::sync::mpsc::Sender;
use super::runner;
use crate::event::Event;
use crate::event_loop::EventLoopClosed;
use crate::platform_impl::platform::r#async::Channel;
pub struct EventLoopProxy<T: 'static> {
runner: Channel<runner::Shared<T>, T>,
// used to wake the event loop handler, not to actually pass data
runner: Channel<runner::Shared, ()>,
sender: Sender<T>,
}
impl<T: 'static> EventLoopProxy<T> {
pub fn new(runner: runner::Shared<T>) -> Self {
pub fn new(runner: runner::Shared, sender: Sender<T>) -> Self {
Self {
runner: Channel::new(runner, |runner, event| {
runner.send_event(Event::UserEvent(event))
})
.unwrap(),
sender,
}
}
pub fn send_event(&self, event: T) -> Result<(), EventLoopClosed<T>> {
self.runner.send(event);
self.sender.send(event).unwrap();
self.runner.send(());
Ok(())
}
}
@ -27,6 +33,7 @@ impl<T: 'static> Clone for EventLoopProxy<T> {
fn clone(&self) -> Self {
Self {
runner: self.runner.clone(),
sender: self.sender.clone(),
}
}
}