mirror of
https://github.com/rust-windowing/winit.git
synced 2026-08-31 22:00:04 -04:00
Web: set control flow strategies on EventLoop (#3740)
This commit is contained in:
committed by
Kirill Chibisov
parent
3d7d766182
commit
a974640a66
@@ -190,6 +190,20 @@ pub trait EventLoopExtWebSys {
|
|||||||
fn spawn<F>(self, event_handler: F)
|
fn spawn<F>(self, event_handler: F)
|
||||||
where
|
where
|
||||||
F: 'static + FnMut(Event<Self::UserEvent>, &ActiveEventLoop);
|
F: 'static + FnMut(Event<Self::UserEvent>, &ActiveEventLoop);
|
||||||
|
|
||||||
|
/// Sets the strategy for [`ControlFlow::Poll`].
|
||||||
|
///
|
||||||
|
/// See [`PollStrategy`].
|
||||||
|
///
|
||||||
|
/// [`ControlFlow::Poll`]: crate::event_loop::ControlFlow::Poll
|
||||||
|
fn set_poll_strategy(&self, strategy: PollStrategy);
|
||||||
|
|
||||||
|
/// Gets the strategy for [`ControlFlow::Poll`].
|
||||||
|
///
|
||||||
|
/// See [`PollStrategy`].
|
||||||
|
///
|
||||||
|
/// [`ControlFlow::Poll`]: crate::event_loop::ControlFlow::Poll
|
||||||
|
fn poll_strategy(&self) -> PollStrategy;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> EventLoopExtWebSys for EventLoop<T> {
|
impl<T> EventLoopExtWebSys for EventLoop<T> {
|
||||||
@@ -207,6 +221,14 @@ impl<T> EventLoopExtWebSys for EventLoop<T> {
|
|||||||
{
|
{
|
||||||
self.event_loop.spawn(event_handler)
|
self.event_loop.spawn(event_handler)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn set_poll_strategy(&self, strategy: PollStrategy) {
|
||||||
|
self.event_loop.set_poll_strategy(strategy);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn poll_strategy(&self) -> PollStrategy {
|
||||||
|
self.event_loop.poll_strategy()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait ActiveEventLoopExtWebSys {
|
pub trait ActiveEventLoopExtWebSys {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ use std::sync::mpsc::{self, Receiver, Sender};
|
|||||||
use crate::error::EventLoopError;
|
use crate::error::EventLoopError;
|
||||||
use crate::event::Event;
|
use crate::event::Event;
|
||||||
use crate::event_loop::ActiveEventLoop as RootActiveEventLoop;
|
use crate::event_loop::ActiveEventLoop as RootActiveEventLoop;
|
||||||
|
use crate::platform::web::{ActiveEventLoopExtWebSys, PollStrategy};
|
||||||
|
|
||||||
use super::{backend, device, window};
|
use super::{backend, device, window};
|
||||||
|
|
||||||
@@ -99,4 +100,12 @@ impl<T> EventLoop<T> {
|
|||||||
pub fn window_target(&self) -> &RootActiveEventLoop {
|
pub fn window_target(&self) -> &RootActiveEventLoop {
|
||||||
&self.elw
|
&self.elw
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_poll_strategy(&self, strategy: PollStrategy) {
|
||||||
|
self.elw.set_poll_strategy(strategy);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn poll_strategy(&self) -> PollStrategy {
|
||||||
|
self.elw.poll_strategy()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user