Update example in README.md and add move prefix to window.rs example closure (#921)

* Update example in README.md and add move prefix to window.rs example

* Make Window and README example trivially capture window

* Update README.md
This commit is contained in:
Osspial 2019-06-18 11:15:55 -04:00 committed by GitHub
parent c35fdc8d61
commit 72509b5b42
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 12 deletions

View file

@ -32,18 +32,21 @@ another library.
```rust ```rust
extern crate winit; extern crate winit;
use winit::window::WindowBuilder;
use winit::event::{Event, WindowEvent};
use winit::event_loop::{EventLoop, ControlFlow};
fn main() { fn main() {
let mut event_loop = winit::EventLoop::new(); let event_loop = EventLoop::new();
let window = winit::Window::new(&event_loop).unwrap(); let window = WindowBuilder::new().build(&event_loop).unwrap();
event_loop.run(|event| { event_loop.run(move |event, _, control_flow| {
match event { match event {
winit::Event::WindowEvent { Event::WindowEvent {
event: winit::WindowEvent::CloseRequested, event: WindowEvent::CloseRequested,
.. window_id,
} => winit::ControlFlow::Break, } if window_id == window.id() => *control_flow = ControlFlow::Exit,
_ => winit::ControlFlow::Continue, _ => *control_flow = ControlFlow::Wait,
} }
}); });
} }

View file

@ -6,19 +6,19 @@ use winit::event_loop::{EventLoop, ControlFlow};
fn main() { fn main() {
let event_loop = EventLoop::new(); let event_loop = EventLoop::new();
let _window = WindowBuilder::new() let window = WindowBuilder::new()
.with_title("A fantastic window!") .with_title("A fantastic window!")
.build(&event_loop) .build(&event_loop)
.unwrap(); .unwrap();
event_loop.run(|event, _, control_flow| { event_loop.run(move |event, _, control_flow| {
println!("{:?}", event); println!("{:?}", event);
match event { match event {
Event::WindowEvent { Event::WindowEvent {
event: WindowEvent::CloseRequested, event: WindowEvent::CloseRequested,
.. window_id,
} => *control_flow = ControlFlow::Exit, } if window_id == window.id() => *control_flow = ControlFlow::Exit,
_ => *control_flow = ControlFlow::Wait, _ => *control_flow = ControlFlow::Wait,
} }
}); });