|
1 | 1 | //! Winit is a cross-platform window creation and event loop management library. |
2 | 2 | //! |
3 | | -//! # Building windows |
| 3 | +//! # Getting started |
| 4 | +//! |
| 5 | +//! The core of the windowing system is the [`EventLoop`] and the [`ApplicationHandler`]. You can |
| 6 | +//! use these together to create a [`Window`], which will send events to the [`ActiveEventLoop`], |
| 7 | +//! which associates one or more [`Window`]s with a single [`EventLoop`]. |
| 8 | +//! |
| 9 | +//! You must also define a struct which implements [`ApplicationHandler`], which will determine how |
| 10 | +//! events are handled. The example below shows a simple [`ApplicationHandler`] implementation. |
| 11 | +//! The [`ApplicationHandler`] trait is the glue which provides access to the [`ActiveEventLoop`], |
| 12 | +//! which allows you to create [`Window`]s with [`create_window`]. |
4 | 13 | //! |
5 | 14 | //! Before you can create a [`Window`], you first need to build an [`EventLoop`]. This is done with |
6 | 15 | //! the [`EventLoop::new()`] function. |
|
15 | 24 | //! } |
16 | 25 | //! ``` |
17 | 26 | //! |
18 | | -//! Then you create a [`Window`] with [`create_window`]. |
| 27 | +//! Then you create a [`Window`] with [`create_window`], usually inside of your |
| 28 | +//! [`ApplicationHandler`] code. |
19 | 29 | //! |
20 | 30 | //! # Event handling |
21 | 31 | //! |
22 | | -//! Once a [`Window`] has been created, it will generate different *events*. A [`Window`] object can |
23 | | -//! generate [`WindowEvent`]s when certain input events occur, such as a cursor moving over the |
24 | | -//! window or a key getting pressed while the window is focused. Devices can generate |
25 | | -//! [`DeviceEvent`]s, which contain unfiltered event data that isn't specific to a certain window. |
26 | | -//! Some user activity, like mouse movement, can generate both a [`WindowEvent`] *and* a |
27 | | -//! [`DeviceEvent`]. |
28 | | -//! |
29 | 32 | //! You can retrieve events by calling [`EventLoop::run_app()`]. This function will dispatch events |
30 | 33 | //! for every [`Window`] that was created with that particular [`EventLoop`]. |
31 | 34 | //! |
32 | | -//! Winit no longer uses a `EventLoop::poll_events() -> impl Iterator<Event>`-based event loop |
33 | | -//! model, since that can't be implemented properly on some platforms (e.g Web, iOS) and works |
34 | | -//! poorly on most other platforms. However, this model can be re-implemented to an extent with |
35 | | -//! [`EventLoopExtPumpEvents::pump_app_events()`] [^1]. See that method's documentation for more |
36 | | -//! reasons about why it's discouraged beyond compatibility reasons. |
37 | | -//! |
38 | 35 | //! |
39 | 36 | //! ```no_run |
40 | 37 | //! use winit::application::ApplicationHandler; |
|
111 | 108 | //! } |
112 | 109 | //! ``` |
113 | 110 | //! |
| 111 | +//! Once a [`Window`] has been created, it will generate different *events*. A [`Window`] object can |
| 112 | +//! generate [`WindowEvent`]s when certain input events occur, such as a cursor moving over the |
| 113 | +//! window or a key getting pressed while the window is focused. Devices can generate |
| 114 | +//! [`DeviceEvent`]s, which contain unfiltered event data that isn't specific to a certain window. |
| 115 | +//! Some user activity, like mouse movement, can generate both a [`WindowEvent`] *and* a |
| 116 | +//! [`DeviceEvent`]. |
| 117 | +//! |
| 118 | +//! Winit no longer uses a `EventLoop::poll_events() -> impl Iterator<Event>`-based event loop |
| 119 | +//! model, since that can't be implemented properly on some platforms (e.g Web, iOS) and works |
| 120 | +//! poorly on most other platforms. However, this model can be re-implemented to an extent with |
| 121 | +//! [`EventLoopExtPumpEvents::pump_app_events()`] [^1]. See that method's documentation for more |
| 122 | +//! reasons about why it's discouraged beyond compatibility reasons. |
| 123 | +//! |
114 | 124 | //! [`WindowEvent`] has a [`WindowId`] member. In multi-window environments, it should be |
115 | 125 | //! compared to the value returned by [`Window::id()`] to determine which [`Window`] |
116 | 126 | //! dispatched the event. |
|
269 | 279 | //! [`raw_window_handle`]: ./window/struct.Window.html#method.raw_window_handle |
270 | 280 | //! [`raw_display_handle`]: ./window/struct.Window.html#method.raw_display_handle |
271 | 281 | //! [`EventLoopExtPumpEvents::pump_app_events()`]: crate::event_loop::pump_events::EventLoopExtPumpEvents::pump_app_events() |
| 282 | +//! [`ApplicationHandler`]: application::ApplicationHandler |
| 283 | +//! [`ActiveEventLoop`]: event_loop::ActiveEventLoop |
272 | 284 | //! [^1]: `EventLoopExtPumpEvents::pump_app_events()` is only available on Windows, macOS, Android, X11 and Wayland. |
273 | 285 |
|
274 | 286 | #![deny(rust_2018_idioms)] |
|
0 commit comments