mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-23 22:01:31 +11:00
Update examples and tests to addition of ControlFlow
This commit is contained in:
parent
f2dd2f0752
commit
db9e80bdb6
|
@ -1,9 +1,9 @@
|
||||||
extern crate winit;
|
extern crate winit;
|
||||||
|
|
||||||
use winit::{Event, ElementState, MouseCursor, WindowEvent, KeyboardInput};
|
use winit::{Event, ElementState, MouseCursor, WindowEvent, KeyboardInput, ControlFlow};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let events_loop = winit::EventsLoop::new();
|
let mut events_loop = winit::EventsLoop::new();
|
||||||
|
|
||||||
let window = winit::WindowBuilder::new().build(&events_loop).unwrap();
|
let window = winit::WindowBuilder::new().build(&events_loop).unwrap();
|
||||||
window.set_title("A fantastic window!");
|
window.set_title("A fantastic window!");
|
||||||
|
@ -23,9 +23,10 @@ fn main() {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Event::WindowEvent { event: WindowEvent::Closed, .. } => {
|
Event::WindowEvent { event: WindowEvent::Closed, .. } => {
|
||||||
events_loop.interrupt()
|
return ControlFlow::Complete;
|
||||||
},
|
},
|
||||||
_ => ()
|
_ => ()
|
||||||
}
|
}
|
||||||
|
ControlFlow::Continue
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
extern crate winit;
|
extern crate winit;
|
||||||
|
|
||||||
use std::io::{self, Write};
|
use std::io::{self, Write};
|
||||||
|
use winit::{ControlFlow, Event, WindowEvent};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// enumerating monitors
|
// enumerating monitors
|
||||||
|
@ -22,7 +23,7 @@ fn main() {
|
||||||
monitor
|
monitor
|
||||||
};
|
};
|
||||||
|
|
||||||
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("Hello world!")
|
.with_title("Hello world!")
|
||||||
|
@ -34,16 +35,18 @@ fn main() {
|
||||||
println!("{:?}", event);
|
println!("{:?}", event);
|
||||||
|
|
||||||
match event {
|
match event {
|
||||||
winit::Event::WindowEvent { event, .. } => {
|
Event::WindowEvent { event, .. } => {
|
||||||
match event {
|
match event {
|
||||||
winit::WindowEvent::Closed => events_loop.interrupt(),
|
WindowEvent::Closed => return ControlFlow::Complete,
|
||||||
winit::WindowEvent::KeyboardInput {
|
WindowEvent::KeyboardInput {
|
||||||
input: winit::KeyboardInput { virtual_keycode: Some(winit::VirtualKeyCode::Escape), .. }, ..
|
input: winit::KeyboardInput { virtual_keycode: Some(winit::VirtualKeyCode::Escape), .. }, ..
|
||||||
} => events_loop.interrupt(),
|
} => return ControlFlow::Complete,
|
||||||
_ => ()
|
_ => ()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ControlFlow::Continue
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
extern crate winit;
|
extern crate winit;
|
||||||
|
|
||||||
use winit::{WindowEvent, ElementState, KeyboardInput};
|
use winit::{ControlFlow, WindowEvent, ElementState, KeyboardInput};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let events_loop = winit::EventsLoop::new();
|
let mut events_loop = winit::EventsLoop::new();
|
||||||
|
|
||||||
let window = winit::WindowBuilder::new().build(&events_loop).unwrap();
|
let window = winit::WindowBuilder::new().build(&events_loop).unwrap();
|
||||||
window.set_title("winit - Cursor grabbing test");
|
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 { .. } => {
|
a @ WindowEvent::MouseMoved { .. } => {
|
||||||
println!("{:?}", a);
|
println!("{:?}", a);
|
||||||
|
@ -39,5 +39,7 @@ fn main() {
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ControlFlow::Continue
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
extern crate winit;
|
extern crate winit;
|
||||||
|
|
||||||
fn main() {
|
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_min_dimensions(400, 200)
|
.with_min_dimensions(400, 200)
|
||||||
|
@ -13,8 +13,8 @@ fn main() {
|
||||||
println!("{:?}", event);
|
println!("{:?}", event);
|
||||||
|
|
||||||
match 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,
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
extern crate winit;
|
extern crate winit;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let events_loop = winit::EventsLoop::new();
|
let mut events_loop = winit::EventsLoop::new();
|
||||||
|
|
||||||
let window1 = winit::Window::new(&events_loop).unwrap();
|
let window1 = winit::Window::new(&events_loop).unwrap();
|
||||||
let window2 = winit::Window::new(&events_loop).unwrap();
|
let window2 = winit::Window::new(&events_loop).unwrap();
|
||||||
|
@ -24,10 +24,11 @@ fn main() {
|
||||||
|
|
||||||
num_windows -= 1;
|
num_windows -= 1;
|
||||||
if num_windows == 0 {
|
if num_windows == 0 {
|
||||||
events_loop.interrupt();
|
return winit::ControlFlow::Complete;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
|
winit::ControlFlow::Continue
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
extern crate winit;
|
extern crate winit;
|
||||||
|
|
||||||
fn main() {
|
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!")
|
.with_title("A fantastic window!")
|
||||||
.build(&events_loop)
|
.build(&events_loop)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -22,8 +22,8 @@ fn main() {
|
||||||
println!("{:?}", event);
|
println!("{:?}", event);
|
||||||
match event {
|
match event {
|
||||||
winit::Event::WindowEvent { event: winit::WindowEvent::Closed, .. } =>
|
winit::Event::WindowEvent { event: winit::WindowEvent::Closed, .. } =>
|
||||||
events_loop.interrupt(),
|
winit::ControlFlow::Complete,
|
||||||
_ => ()
|
_ => winit::ControlFlow::Continue,
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
extern crate winit;
|
extern crate winit;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let events_loop = winit::EventsLoop::new();
|
let mut events_loop = winit::EventsLoop::new();
|
||||||
|
|
||||||
let window = winit::WindowBuilder::new().with_decorations(false)
|
let window = winit::WindowBuilder::new().with_decorations(false)
|
||||||
.with_transparency(true)
|
.with_transparency(true)
|
||||||
|
@ -13,8 +13,8 @@ fn main() {
|
||||||
println!("{:?}", event);
|
println!("{:?}", event);
|
||||||
|
|
||||||
match 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,
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
extern crate winit;
|
extern crate winit;
|
||||||
|
|
||||||
fn main() {
|
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!")
|
.with_title("A fantastic window!")
|
||||||
.build(&events_loop)
|
.build(&events_loop)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
27
src/lib.rs
27
src/lib.rs
|
@ -34,10 +34,9 @@
|
||||||
//! screen, such as video games.
|
//! screen, such as video games.
|
||||||
//!
|
//!
|
||||||
//! ```no_run
|
//! ```no_run
|
||||||
//! use winit::Event;
|
//! use winit::{Event, WindowEvent};
|
||||||
//! use winit::WindowEvent;
|
|
||||||
//! # use winit::EventsLoop;
|
//! # use winit::EventsLoop;
|
||||||
//! # let events_loop = EventsLoop::new();
|
//! # let mut events_loop = EventsLoop::new();
|
||||||
//!
|
//!
|
||||||
//! loop {
|
//! loop {
|
||||||
//! events_loop.poll_events(|event| {
|
//! 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
|
//! 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
|
//! ```no_run
|
||||||
//! use winit::Event;
|
//! use winit::{ControlFlow, Event, WindowEvent};
|
||||||
//! use winit::WindowEvent;
|
|
||||||
//! # use winit::EventsLoop;
|
//! # use winit::EventsLoop;
|
||||||
//! # let events_loop = EventsLoop::new();
|
//! # let mut events_loop = EventsLoop::new();
|
||||||
//!
|
//!
|
||||||
//! events_loop.run_forever(|event| {
|
//! events_loop.run_forever(|event| {
|
||||||
//! match event {
|
//! match event {
|
||||||
//! Event::WindowEvent { event: WindowEvent::Closed, .. } => {
|
//! Event::WindowEvent { event: WindowEvent::Closed, .. } => {
|
||||||
//! println!("The window was closed ; stopping");
|
//! println!("The window was closed ; stopping");
|
||||||
//! events_loop.interrupt();
|
//! ControlFlow::Complete
|
||||||
//! },
|
//! },
|
||||||
//! _ => ()
|
//! _ => ControlFlow::Continue,
|
||||||
//! }
|
//! }
|
||||||
//! });
|
//! });
|
||||||
//! ```
|
//! ```
|
||||||
|
@ -137,20 +135,17 @@ pub mod os;
|
||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
/// ```no_run
|
/// ```no_run
|
||||||
/// use winit::Event;
|
/// use winit::{Event, EventsLoop, Window, WindowEvent, ControlFlow};
|
||||||
/// use winit::EventsLoop;
|
|
||||||
/// use winit::Window;
|
|
||||||
/// use winit::WindowEvent;
|
|
||||||
///
|
///
|
||||||
/// let events_loop = EventsLoop::new();
|
/// let mut events_loop = EventsLoop::new();
|
||||||
/// let window = Window::new(&events_loop).unwrap();
|
/// let window = Window::new(&events_loop).unwrap();
|
||||||
///
|
///
|
||||||
/// events_loop.run_forever(|event| {
|
/// events_loop.run_forever(|event| {
|
||||||
/// match event {
|
/// match event {
|
||||||
/// Event::WindowEvent { event: WindowEvent::Closed, .. } => {
|
/// Event::WindowEvent { event: WindowEvent::Closed, .. } => {
|
||||||
/// events_loop.interrupt();
|
/// ControlFlow::Complete
|
||||||
/// },
|
/// },
|
||||||
/// _ => ()
|
/// _ => ControlFlow::Continue,
|
||||||
/// }
|
/// }
|
||||||
/// });
|
/// });
|
||||||
/// ```
|
/// ```
|
||||||
|
|
Loading…
Reference in a new issue