diff --git a/examples/cursor.rs b/examples/cursor.rs index dcb37971..cd979b99 100644 --- a/examples/cursor.rs +++ b/examples/cursor.rs @@ -1,9 +1,9 @@ extern crate winit; -use winit::{Event, ElementState, MouseCursor, WindowEvent, KeyboardInput}; +use winit::{Event, ElementState, MouseCursor, WindowEvent, KeyboardInput, ControlFlow}; fn main() { - let events_loop = winit::EventsLoop::new(); + let mut events_loop = winit::EventsLoop::new(); let window = winit::WindowBuilder::new().build(&events_loop).unwrap(); window.set_title("A fantastic window!"); @@ -23,9 +23,10 @@ fn main() { } }, Event::WindowEvent { event: WindowEvent::Closed, .. } => { - events_loop.interrupt() + return ControlFlow::Complete; }, _ => () } + ControlFlow::Continue }); } diff --git a/examples/fullscreen.rs b/examples/fullscreen.rs index 1c1d8bdb..921caa61 100644 --- a/examples/fullscreen.rs +++ b/examples/fullscreen.rs @@ -1,6 +1,7 @@ extern crate winit; use std::io::{self, Write}; +use winit::{ControlFlow, Event, WindowEvent}; fn main() { // enumerating monitors @@ -22,7 +23,7 @@ fn main() { monitor }; - let events_loop = winit::EventsLoop::new(); + let mut events_loop = winit::EventsLoop::new(); let _window = winit::WindowBuilder::new() .with_title("Hello world!") @@ -34,16 +35,18 @@ fn main() { println!("{:?}", event); match event { - winit::Event::WindowEvent { event, .. } => { + Event::WindowEvent { event, .. } => { match event { - winit::WindowEvent::Closed => events_loop.interrupt(), - winit::WindowEvent::KeyboardInput { + WindowEvent::Closed => return ControlFlow::Complete, + WindowEvent::KeyboardInput { input: winit::KeyboardInput { virtual_keycode: Some(winit::VirtualKeyCode::Escape), .. }, .. - } => events_loop.interrupt(), + } => return ControlFlow::Complete, _ => () } }, _ => {} } + + ControlFlow::Continue }); } diff --git a/examples/grabbing.rs b/examples/grabbing.rs index 2ba327f4..fc6b7d7c 100644 --- a/examples/grabbing.rs +++ b/examples/grabbing.rs @@ -1,9 +1,9 @@ extern crate winit; -use winit::{WindowEvent, ElementState, KeyboardInput}; +use winit::{ControlFlow, WindowEvent, ElementState, KeyboardInput}; fn main() { - let events_loop = winit::EventsLoop::new(); + let mut events_loop = winit::EventsLoop::new(); let window = winit::WindowBuilder::new().build(&events_loop).unwrap(); window.set_title("winit - Cursor grabbing test"); @@ -28,7 +28,7 @@ fn main() { } }, - WindowEvent::Closed => events_loop.interrupt(), + WindowEvent::Closed => return ControlFlow::Complete, a @ WindowEvent::MouseMoved { .. } => { println!("{:?}", a); @@ -39,5 +39,7 @@ fn main() { } _ => {} } + + ControlFlow::Continue }); } diff --git a/examples/min_max_size.rs b/examples/min_max_size.rs index fe22f3e9..54f03da7 100644 --- a/examples/min_max_size.rs +++ b/examples/min_max_size.rs @@ -1,7 +1,7 @@ extern crate winit; fn main() { - let events_loop = winit::EventsLoop::new(); + let mut events_loop = winit::EventsLoop::new(); let _window = winit::WindowBuilder::new() .with_min_dimensions(400, 200) @@ -13,8 +13,8 @@ fn main() { println!("{:?}", event); match event { - winit::Event::WindowEvent { event: winit::WindowEvent::Closed, .. } => events_loop.interrupt(), - _ => () + winit::Event::WindowEvent { event: winit::WindowEvent::Closed, .. } => winit::ControlFlow::Complete, + _ => winit::ControlFlow::Continue, } }); } diff --git a/examples/multiwindow.rs b/examples/multiwindow.rs index 6c92b69e..28f9955f 100644 --- a/examples/multiwindow.rs +++ b/examples/multiwindow.rs @@ -1,7 +1,7 @@ extern crate winit; fn main() { - let events_loop = winit::EventsLoop::new(); + let mut events_loop = winit::EventsLoop::new(); let window1 = winit::Window::new(&events_loop).unwrap(); let window2 = winit::Window::new(&events_loop).unwrap(); @@ -24,10 +24,11 @@ fn main() { num_windows -= 1; if num_windows == 0 { - events_loop.interrupt(); + return winit::ControlFlow::Complete; } }, _ => (), } + winit::ControlFlow::Continue }) } diff --git a/examples/proxy.rs b/examples/proxy.rs index c3d615a2..8741d775 100644 --- a/examples/proxy.rs +++ b/examples/proxy.rs @@ -1,9 +1,9 @@ extern crate winit; fn main() { - let events_loop = winit::EventsLoop::new(); + let mut events_loop = winit::EventsLoop::new(); - let window = winit::WindowBuilder::new() + let _window = winit::WindowBuilder::new() .with_title("A fantastic window!") .build(&events_loop) .unwrap(); @@ -22,8 +22,8 @@ fn main() { println!("{:?}", event); match event { winit::Event::WindowEvent { event: winit::WindowEvent::Closed, .. } => - events_loop.interrupt(), - _ => () + winit::ControlFlow::Complete, + _ => winit::ControlFlow::Continue, } }); } diff --git a/examples/transparent.rs b/examples/transparent.rs index 9e476dee..da9a80e7 100644 --- a/examples/transparent.rs +++ b/examples/transparent.rs @@ -1,7 +1,7 @@ extern crate winit; fn main() { - let events_loop = winit::EventsLoop::new(); + let mut events_loop = winit::EventsLoop::new(); let window = winit::WindowBuilder::new().with_decorations(false) .with_transparency(true) @@ -13,8 +13,8 @@ fn main() { println!("{:?}", event); match event { - winit::Event::WindowEvent { event: winit::WindowEvent::Closed, .. } => events_loop.interrupt(), - _ => () + winit::Event::WindowEvent { event: winit::WindowEvent::Closed, .. } => winit::ControlFlow::Complete, + _ => winit::ControlFlow::Continue, } }); } diff --git a/examples/window.rs b/examples/window.rs index 921b7ea6..fd5ef6e9 100644 --- a/examples/window.rs +++ b/examples/window.rs @@ -1,9 +1,9 @@ extern crate winit; fn main() { - let events_loop = winit::EventsLoop::new(); + let mut events_loop = winit::EventsLoop::new(); - let window = winit::WindowBuilder::new() + let _window = winit::WindowBuilder::new() .with_title("A fantastic window!") .build(&events_loop) .unwrap(); diff --git a/src/lib.rs b/src/lib.rs index 4097b83a..74d3c5a8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -34,10 +34,9 @@ //! screen, such as video games. //! //! ```no_run -//! use winit::Event; -//! use winit::WindowEvent; +//! use winit::{Event, WindowEvent}; //! # use winit::EventsLoop; -//! # let events_loop = EventsLoop::new(); +//! # let mut events_loop = EventsLoop::new(); //! //! loop { //! events_loop.poll_events(|event| { @@ -52,21 +51,20 @@ //! ``` //! //! The second way is to call `events_loop.run_forever(...)`. As its name tells, it will run -//! forever unless it is stopped by calling `events_loop.interrupt()`. +//! forever unless it is stopped by returning `ControlFlow::Complete`. //! //! ```no_run -//! use winit::Event; -//! use winit::WindowEvent; +//! use winit::{ControlFlow, Event, WindowEvent}; //! # use winit::EventsLoop; -//! # let events_loop = EventsLoop::new(); +//! # let mut events_loop = EventsLoop::new(); //! //! events_loop.run_forever(|event| { //! match event { //! Event::WindowEvent { event: WindowEvent::Closed, .. } => { //! println!("The window was closed ; stopping"); -//! events_loop.interrupt(); +//! ControlFlow::Complete //! }, -//! _ => () +//! _ => ControlFlow::Continue, //! } //! }); //! ``` @@ -137,20 +135,17 @@ pub mod os; /// # Example /// /// ```no_run -/// use winit::Event; -/// use winit::EventsLoop; -/// use winit::Window; -/// use winit::WindowEvent; +/// use winit::{Event, EventsLoop, Window, WindowEvent, ControlFlow}; /// -/// let events_loop = EventsLoop::new(); +/// let mut events_loop = EventsLoop::new(); /// let window = Window::new(&events_loop).unwrap(); /// /// events_loop.run_forever(|event| { /// match event { /// Event::WindowEvent { event: WindowEvent::Closed, .. } => { -/// events_loop.interrupt(); +/// ControlFlow::Complete /// }, -/// _ => () +/// _ => ControlFlow::Continue, /// } /// }); /// ```