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
extern crate winit;
use winit::window::WindowBuilder;
use winit::event::{Event, WindowEvent};
use winit::event_loop::{EventLoop, ControlFlow};
fn main() {
let mut event_loop = winit::EventLoop::new();
let window = winit::Window::new(&event_loop).unwrap();
let event_loop = EventLoop::new();
let window = WindowBuilder::new().build(&event_loop).unwrap();
event_loop.run(|event| {
event_loop.run(move |event, _, control_flow| {
match event {
winit::Event::WindowEvent {
event: winit::WindowEvent::CloseRequested,
..
} => winit::ControlFlow::Break,
_ => winit::ControlFlow::Continue,
Event::WindowEvent {
event: WindowEvent::CloseRequested,
window_id,
} if window_id == window.id() => *control_flow = ControlFlow::Exit,
_ => *control_flow = ControlFlow::Wait,
}
});
}

View file

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