@@ -6,7 +6,17 @@ use crate::event_loop::ActiveEventLoop;
66use crate :: platform:: macos:: ApplicationHandlerExtMacOS ;
77use crate :: window:: WindowId ;
88
9- /// The handler of the application events.
9+ /// The handler of application-level events.
10+ ///
11+ /// See [the top-level docs] for example usage, and [`EventLoop::run_app`] for an overview of when
12+ /// events are delivered.
13+ ///
14+ /// This is [dropped] when the event loop is shut down. Note that this only works if you're passing
15+ /// the entire state to [`EventLoop::run_app`] (passing `&mut app` won't work).
16+ ///
17+ /// [the top-level docs]: crate
18+ /// [`EventLoop::run_app`]: crate::event_loop::EventLoop::run_app
19+ /// [dropped]: std::ops::Drop
1020pub trait ApplicationHandler {
1121 /// Emitted when new events arrive from the OS to be processed.
1222 ///
@@ -57,7 +67,6 @@ pub trait ApplicationHandler {
5767 ///
5868 /// [`resumed()`]: Self::resumed()
5969 /// [`suspended()`]: Self::suspended()
60- /// [`exiting()`]: Self::exiting()
6170 fn resumed ( & mut self , event_loop : & dyn ActiveEventLoop ) {
6271 let _ = event_loop;
6372 }
@@ -162,16 +171,14 @@ pub trait ApplicationHandler {
162171 ///
163172 /// let (sender, receiver) = mpsc::channel();
164173 ///
165- /// let mut app = MyApp { receiver };
166- ///
167174 /// // Send an event in a loop
168175 /// let proxy = event_loop.create_proxy();
169176 /// let background_thread = thread::spawn(move || {
170177 /// let mut i = 0;
171178 /// loop {
172179 /// println!("sending: {i}");
173180 /// if sender.send(i).is_err() {
174- /// // Stop sending once `MyApp` is dropped
181+ /// // Stop sending once the receiver is dropped
175182 /// break;
176183 /// }
177184 /// // Trigger the wake-up _after_ we placed the event in the channel.
@@ -182,9 +189,8 @@ pub trait ApplicationHandler {
182189 /// }
183190 /// });
184191 ///
185- /// event_loop.run_app(&mut app )?;
192+ /// event_loop.run_app(MyApp { receiver } )?;
186193 ///
187- /// drop(app);
188194 /// background_thread.join().unwrap();
189195 ///
190196 /// Ok(())
@@ -203,6 +209,10 @@ pub trait ApplicationHandler {
203209 ) ;
204210
205211 /// Emitted when the OS sends an event to a device.
212+ ///
213+ /// For this to be called, it must be enabled with [`EventLoop::listen_device_events`].
214+ ///
215+ /// [`EventLoop::listen_device_events`]: crate::event_loop::EventLoop::listen_device_events
206216 fn device_event (
207217 & mut self ,
208218 event_loop : & dyn ActiveEventLoop ,
@@ -258,7 +268,7 @@ pub trait ApplicationHandler {
258268 /// to the user. This is a good place to stop refreshing UI, running animations and other visual
259269 /// things. It is driven by Android's [`onStop()`] method.
260270 ///
261- /// After this event the application either receives [`resumed()`] again, or [`exiting()`] .
271+ /// After this event the application either receives [`resumed()`] again, or will exit .
262272 ///
263273 /// [`onStop()`]: https://developer.android.com/reference/android/app/Activity#onStop()
264274 ///
@@ -268,7 +278,6 @@ pub trait ApplicationHandler {
268278 ///
269279 /// [`resumed()`]: Self::resumed()
270280 /// [`suspended()`]: Self::suspended()
271- /// [`exiting()`]: Self::exiting()
272281 fn suspended ( & mut self , event_loop : & dyn ActiveEventLoop ) {
273282 let _ = event_loop;
274283 }
@@ -310,14 +319,6 @@ pub trait ApplicationHandler {
310319 let _ = event_loop;
311320 }
312321
313- /// Emitted when the event loop is being shut down.
314- ///
315- /// This is irreversible - if this method is called, it is guaranteed that the event loop
316- /// will exit right after.
317- fn exiting ( & mut self , event_loop : & dyn ActiveEventLoop ) {
318- let _ = event_loop;
319- }
320-
321322 /// Emitted when the application has received a memory warning.
322323 ///
323324 /// ## Platform-specific
@@ -413,11 +414,6 @@ impl<A: ?Sized + ApplicationHandler> ApplicationHandler for &mut A {
413414 ( * * self ) . destroy_surfaces ( event_loop) ;
414415 }
415416
416- #[ inline]
417- fn exiting ( & mut self , event_loop : & dyn ActiveEventLoop ) {
418- ( * * self ) . exiting ( event_loop) ;
419- }
420-
421417 #[ inline]
422418 fn memory_warning ( & mut self , event_loop : & dyn ActiveEventLoop ) {
423419 ( * * self ) . memory_warning ( event_loop) ;
@@ -487,11 +483,6 @@ impl<A: ?Sized + ApplicationHandler> ApplicationHandler for Box<A> {
487483 ( * * self ) . destroy_surfaces ( event_loop) ;
488484 }
489485
490- #[ inline]
491- fn exiting ( & mut self , event_loop : & dyn ActiveEventLoop ) {
492- ( * * self ) . exiting ( event_loop) ;
493- }
494-
495486 #[ inline]
496487 fn memory_warning ( & mut self , event_loop : & dyn ActiveEventLoop ) {
497488 ( * * self ) . memory_warning ( event_loop) ;
0 commit comments