mirror of
https://github.com/rust-windowing/winit.git
synced 2026-08-29 04:40:04 -04:00
docs: add fn main to root examples
This is not strictly required, but makes the examples a bit easier to read understand (especially since the `EventLoop` really _should_ be created inside `fn main`, and not in some random function potentially running on a random thread).
This commit is contained in:
committed by
Kirill Chibisov
parent
bbab3d8e35
commit
bab2d82fd3
30
src/lib.rs
30
src/lib.rs
@@ -7,7 +7,12 @@
|
|||||||
//!
|
//!
|
||||||
//! ```no_run
|
//! ```no_run
|
||||||
//! use winit::event_loop::EventLoop;
|
//! use winit::event_loop::EventLoop;
|
||||||
//! let event_loop = EventLoop::new().unwrap();
|
//!
|
||||||
|
//! # // Intentionally use `fn main` for clarity
|
||||||
|
//! fn main() {
|
||||||
|
//! let event_loop = EventLoop::new().unwrap();
|
||||||
|
//! // ...
|
||||||
|
//! }
|
||||||
//! ```
|
//! ```
|
||||||
//!
|
//!
|
||||||
//! Then you create a [`Window`] with [`create_window`].
|
//! Then you create a [`Window`] with [`create_window`].
|
||||||
@@ -84,19 +89,22 @@
|
|||||||
//! }
|
//! }
|
||||||
//! }
|
//! }
|
||||||
//!
|
//!
|
||||||
//! let event_loop = EventLoop::new().unwrap();
|
//! # // Intentionally use `fn main` for clarity
|
||||||
|
//! fn main() {
|
||||||
|
//! let event_loop = EventLoop::new().unwrap();
|
||||||
//!
|
//!
|
||||||
//! // ControlFlow::Poll continuously runs the event loop, even if the OS hasn't
|
//! // ControlFlow::Poll continuously runs the event loop, even if the OS hasn't
|
||||||
//! // dispatched any events. This is ideal for games and similar applications.
|
//! // dispatched any events. This is ideal for games and similar applications.
|
||||||
//! event_loop.set_control_flow(ControlFlow::Poll);
|
//! event_loop.set_control_flow(ControlFlow::Poll);
|
||||||
//!
|
//!
|
||||||
//! // ControlFlow::Wait pauses the event loop if no events are available to process.
|
//! // ControlFlow::Wait pauses the event loop if no events are available to process.
|
||||||
//! // This is ideal for non-game applications that only update in response to user
|
//! // This is ideal for non-game applications that only update in response to user
|
||||||
//! // input, and uses significantly less power/CPU time than ControlFlow::Poll.
|
//! // input, and uses significantly less power/CPU time than ControlFlow::Poll.
|
||||||
//! event_loop.set_control_flow(ControlFlow::Wait);
|
//! event_loop.set_control_flow(ControlFlow::Wait);
|
||||||
//!
|
//!
|
||||||
//! let mut app = App::default();
|
//! let mut app = App::default();
|
||||||
//! event_loop.run_app(&mut app);
|
//! event_loop.run_app(&mut app);
|
||||||
|
//! }
|
||||||
//! ```
|
//! ```
|
||||||
//!
|
//!
|
||||||
//! [`WindowEvent`] has a [`WindowId`] member. In multi-window environments, it should be
|
//! [`WindowEvent`] has a [`WindowId`] member. In multi-window environments, it should be
|
||||||
|
|||||||
Reference in New Issue
Block a user