Struct winit::event_loop::EventLoopBuilder
source · pub struct EventLoopBuilder<T: 'static> { /* private fields */ }
Expand description
Object that allows building the event loop.
This is used to make specifying options that affect the whole application easier. But note that constructing multiple event loops is not supported.
This can be created using EventLoop::new
or EventLoop::with_user_event
.
Implementations§
source§impl EventLoopBuilder<()>
impl EventLoopBuilder<()>
source§impl<T> EventLoopBuilder<T>
impl<T> EventLoopBuilder<T>
sourcepub fn build(&mut self) -> Result<EventLoop<T>, EventLoopError>
pub fn build(&mut self) -> Result<EventLoop<T>, EventLoopError>
Builds a new event loop.
For cross-platform compatibility, the EventLoop
must be created on the main thread,
and only once per application.
Calling this function will result in display backend initialisation.
§Panics
Attempting to create the event loop off the main thread will panic. This
restriction isn’t strictly necessary on all platforms, but is imposed to
eliminate any nasty surprises when porting to platforms that require it.
EventLoopBuilderExt::any_thread
functions are exposed in the relevant
platform
module if the target platform supports creating an event
loop on any thread.
§Platform-specific
- Wayland/X11: to prevent running under
Wayland
orX11
unsetWAYLAND_DISPLAY
orDISPLAY
respectively when building the event loop. - Android: must be configured with an
AndroidApp
fromandroid_main()
by calling.with_android_app(app)
before calling.build()
, otherwise it’ll panic.
Examples found in repository?
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
fn main() -> Result<(), Box<dyn Error>> {
#[cfg(web_platform)]
console_error_panic_hook::set_once();
tracing::init();
let event_loop = EventLoop::<UserEvent>::with_user_event().build()?;
let _event_loop_proxy = event_loop.create_proxy();
// Wire the user event from another thread.
#[cfg(not(web_platform))]
std::thread::spawn(move || {
// Wake up the `event_loop` once every second and dispatch a custom event
// from a different thread.
info!("Starting to send user event every second");
loop {
let _ = _event_loop_proxy.send_event(UserEvent::WakeUp);
std::thread::sleep(std::time::Duration::from_secs(1));
}
});
let mut state = Application::new(&event_loop);
event_loop.run_app(&mut state).map_err(Into::into)
}
Trait Implementations§
source§impl<T: Default + 'static> Default for EventLoopBuilder<T>
impl<T: Default + 'static> Default for EventLoopBuilder<T>
source§fn default() -> EventLoopBuilder<T>
fn default() -> EventLoopBuilder<T>
source§impl<T> EventLoopBuilderExtAndroid for EventLoopBuilder<T>
Available on android_platform
only.
impl<T> EventLoopBuilderExtAndroid for EventLoopBuilder<T>
android_platform
only.source§fn with_android_app(&mut self, app: AndroidApp) -> &mut Self
fn with_android_app(&mut self, app: AndroidApp) -> &mut Self
source§fn handle_volume_keys(&mut self) -> &mut Self
fn handle_volume_keys(&mut self) -> &mut Self
source§impl<T> EventLoopBuilderExtMacOS for EventLoopBuilder<T>
Available on macos_platform
only.
impl<T> EventLoopBuilderExtMacOS for EventLoopBuilder<T>
macos_platform
only.source§fn with_activation_policy(
&mut self,
activation_policy: ActivationPolicy
) -> &mut Self
fn with_activation_policy( &mut self, activation_policy: ActivationPolicy ) -> &mut Self
source§impl<T> EventLoopBuilderExtWayland for EventLoopBuilder<T>
Available on wayland_platform
only.
impl<T> EventLoopBuilderExtWayland for EventLoopBuilder<T>
wayland_platform
only.source§fn with_wayland(&mut self) -> &mut Self
fn with_wayland(&mut self) -> &mut Self
source§impl<T> EventLoopBuilderExtWindows for EventLoopBuilder<T>
Available on windows_platform
only.
impl<T> EventLoopBuilderExtWindows for EventLoopBuilder<T>
windows_platform
only.source§impl<T> EventLoopBuilderExtX11 for EventLoopBuilder<T>
Available on x11_platform
only.
impl<T> EventLoopBuilderExtX11 for EventLoopBuilder<T>
x11_platform
only.