Skip to content

Commit 585bba3

Browse files
committed
Clarify first section of module docs
1 parent 4f33643 commit 585bba3

File tree

1 file changed

+27
-15
lines changed

1 file changed

+27
-15
lines changed

winit/src/lib.rs

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
//! Winit is a cross-platform window creation and event loop management library.
22
//!
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`].
413
//!
514
//! Before you can create a [`Window`], you first need to build an [`EventLoop`]. This is done with
615
//! the [`EventLoop::new()`] function.
@@ -15,26 +24,14 @@
1524
//! }
1625
//! ```
1726
//!
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.
1929
//!
2030
//! # Event handling
2131
//!
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-
//!
2932
//! You can retrieve events by calling [`EventLoop::run_app()`]. This function will dispatch events
3033
//! for every [`Window`] that was created with that particular [`EventLoop`].
3134
//!
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-
//!
3835
//!
3936
//! ```no_run
4037
//! use winit::application::ApplicationHandler;
@@ -111,6 +108,19 @@
111108
//! }
112109
//! ```
113110
//!
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+
//!
114124
//! [`WindowEvent`] has a [`WindowId`] member. In multi-window environments, it should be
115125
//! compared to the value returned by [`Window::id()`] to determine which [`Window`]
116126
//! dispatched the event.
@@ -269,6 +279,8 @@
269279
//! [`raw_window_handle`]: ./window/struct.Window.html#method.raw_window_handle
270280
//! [`raw_display_handle`]: ./window/struct.Window.html#method.raw_display_handle
271281
//! [`EventLoopExtPumpEvents::pump_app_events()`]: crate::event_loop::pump_events::EventLoopExtPumpEvents::pump_app_events()
282+
//! [`ApplicationHandler`]: application::ApplicationHandler
283+
//! [`ActiveEventLoop`]: event_loop::ActiveEventLoop
272284
//! [^1]: `EventLoopExtPumpEvents::pump_app_events()` is only available on Windows, macOS, Android, X11 and Wayland.
273285
274286
#![deny(rust_2018_idioms)]

0 commit comments

Comments
 (0)