#[non_exhaustive]pub enum Event<'a, T: 'static> {
NewEvents(StartCause),
WindowEvent {
window_id: WindowId,
event: WindowEvent<'a>,
},
DeviceEvent {
device_id: DeviceId,
event: DeviceEvent,
},
UserEvent(T),
Suspended,
Resumed,
MainEventsCleared,
RedrawRequested(WindowId),
RedrawEventsCleared,
LoopDestroyed,
Opened {
urls: Vec<Url>,
},
Reopen {
has_visible_windows: bool,
},
}
Expand description
Describes a generic event.
See the module-level docs for more information on the event loop manages each event.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
NewEvents(StartCause)
Emitted when new events arrive from the OS to be processed.
This event type is useful as a place to put code that should be done before you start
processing events, such as updating frame timing information for benchmarking or checking
the StartCause
to see if a timer set by
ControlFlow::WaitUntil
has elapsed.
WindowEvent
Emitted when the OS sends an event to a tao window.
Fields
This variant is marked as non-exhaustive
event: WindowEvent<'a>
DeviceEvent
Emitted when the OS sends an event to a device.
Fields
This variant is marked as non-exhaustive
event: DeviceEvent
UserEvent(T)
Emitted when an event is sent from EventLoopProxy::send_event
Suspended
Emitted when the application has been suspended.
Resumed
Emitted when the application has been resumed.
MainEventsCleared
Emitted when all of the event loop’s input events have been processed and redraw processing is about to begin.
This event is useful as a place to put your code that should be run after all
state-changing events have been handled and you want to do stuff (updating state, performing
calculations, etc) that happens as the “main body” of your event loop. If your program only draws
graphics when something changes, it’s usually better to do it in response to
Event::RedrawRequested
, which gets emitted
immediately after this event. Programs that draw graphics continuously, like most games,
can render here unconditionally for simplicity.
RedrawRequested(WindowId)
Emitted after MainEventsCleared
when a window should be redrawn.
This gets triggered in two scenarios:
- The OS has performed an operation that’s invalidated the window’s contents (such as resizing the window).
- The application has explicitly requested a redraw via
Window::request_redraw
.
During each iteration of the event loop, Tao will aggregate duplicate redraw requests into a single event, to help avoid duplicating rendering work.
Mainly of interest to applications with mostly-static graphics that avoid redrawing unless something changes, like most non-game GUIs.
§Platform-specific
- Linux: This is triggered by
draw
signal of the gtk window. It can be used to detect if the window is requested to redraw. But widgets it contains are usually not tied to its signal. So if you really want to draw each component, please consider usingconnect_draw
method fromWidgetExt
directly.
RedrawEventsCleared
Emitted after all RedrawRequested
events have been processed and control flow is about to
be taken away from the program. If there are no RedrawRequested
events, it is emitted
immediately after MainEventsCleared
.
This event is useful for doing any cleanup or bookkeeping work after all the rendering tasks have been completed.
LoopDestroyed
Emitted when the event loop is being shut down.
This is irreversable - if this event is emitted, it is guaranteed to be the last event that gets emitted. You generally want to treat this as an “do on quit” event.
Opened
Emitted when the app is open by external resources, like opening a file or deeplink.
Reopen
§Platform-specific
- macOS: https://developer.apple.com/documentation/appkit/nsapplicationdelegate/1428638-applicationshouldhandlereopen with return value same as hasVisibleWindows
- Other: Unsupported.
Implementations§
Trait Implementations§
impl<'a, T: 'static> StructuralPartialEq for Event<'a, T>
Auto Trait Implementations§
impl<'a, T> Freeze for Event<'a, T>where
T: Freeze,
impl<'a, T> RefUnwindSafe for Event<'a, T>where
T: RefUnwindSafe,
impl<'a, T> Send for Event<'a, T>where
T: Send,
impl<'a, T> Sync for Event<'a, T>where
T: Sync,
impl<'a, T> Unpin for Event<'a, T>where
T: Unpin,
impl<'a, T> !UnwindSafe for Event<'a, T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)