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<()>

source

pub fn new() -> Self

👎Deprecated: use EventLoop::builder instead

Start building a new event loop.

source§

impl<T> EventLoopBuilder<T>

source

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 or X11 unset WAYLAND_DISPLAY or DISPLAY respectively when building the event loop.
  • Android: must be configured with an AndroidApp from android_main() by calling .with_android_app(app) before calling .build(), otherwise it’ll panic.
Examples found in repository?
examples/window.rs (line 47)
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>

source§

fn default() -> EventLoopBuilder<T>

Returns the “default value” for a type. Read more
source§

impl<T> EventLoopBuilderExtAndroid for EventLoopBuilder<T>

Available on android_platform only.
source§

fn with_android_app(&mut self, app: AndroidApp) -> &mut Self

Associates the AndroidApp that was passed to android_main() with the event loop Read more
source§

fn handle_volume_keys(&mut self) -> &mut Self

Calling this will mark the volume keys to be manually handled by the application Read more
source§

impl<T> EventLoopBuilderExtMacOS for EventLoopBuilder<T>

Available on macos_platform only.
source§

fn with_activation_policy( &mut self, activation_policy: ActivationPolicy ) -> &mut Self

Sets the activation policy for the application. Read more
source§

fn with_default_menu(&mut self, enable: bool) -> &mut Self

Used to control whether a default menubar menu is created. Read more
source§

fn with_activate_ignoring_other_apps(&mut self, ignore: bool) -> &mut Self

Used to prevent the application from automatically activating when launched if another application is already active. Read more
source§

impl<T> EventLoopBuilderExtWayland for EventLoopBuilder<T>

Available on wayland_platform only.
source§

fn with_wayland(&mut self) -> &mut Self

Force using Wayland.
source§

fn with_any_thread(&mut self, any_thread: bool) -> &mut Self

Whether to allow the event loop to be created off of the main thread. Read more
source§

impl<T> EventLoopBuilderExtWindows for EventLoopBuilder<T>

Available on windows_platform only.
source§

fn with_any_thread(&mut self, any_thread: bool) -> &mut Self

Whether to allow the event loop to be created off of the main thread. Read more
source§

fn with_dpi_aware(&mut self, dpi_aware: bool) -> &mut Self

Whether to enable process-wide DPI awareness. Read more
source§

fn with_msg_hook<F>(&mut self, callback: F) -> &mut Self
where F: FnMut(*const c_void) -> bool + 'static,

A callback to be executed before dispatching a win32 message to the window procedure. Return true to disable winit’s internal message dispatching. Read more
source§

impl<T> EventLoopBuilderExtX11 for EventLoopBuilder<T>

Available on x11_platform only.
source§

fn with_x11(&mut self) -> &mut Self

Force using X11.
source§

fn with_any_thread(&mut self, any_thread: bool) -> &mut Self

Whether to allow the event loop to be created off of the main thread. Read more

Auto Trait Implementations§

§

impl<T> Freeze for EventLoopBuilder<T>

§

impl<T> !RefUnwindSafe for EventLoopBuilder<T>

§

impl<T> !Send for EventLoopBuilder<T>

§

impl<T> !Sync for EventLoopBuilder<T>

§

impl<T> Unpin for EventLoopBuilder<T>
where T: Unpin,

§

impl<T> !UnwindSafe for EventLoopBuilder<T>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more