mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-23 22:01:31 +11:00
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:
parent
c35fdc8d61
commit
72509b5b42
19
README.md
19
README.md
|
@ -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,
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue