Skip to content

Commit

Permalink
Update example in README.md and add move prefix to window.rs example …
Browse files Browse the repository at this point in the history
…closure (rust-windowing#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
  • Loading branch information
Osspial authored Jun 18, 2019
1 parent c35fdc8 commit 72509b5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
19 changes: 11 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
});
}
Expand Down
8 changes: 4 additions & 4 deletions examples/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
});
Expand Down

0 comments on commit 72509b5

Please sign in to comment.