mirror of
https://github.com/rust-windowing/winit.git
synced 2026-06-28 07:33:14 -04:00
Update run_forever to hijack thread
This commit is contained in:
@@ -1,22 +1,21 @@
|
||||
extern crate winit;
|
||||
|
||||
use winit::{Event, ElementState, MouseCursor, WindowEvent, KeyboardInput, ControlFlow};
|
||||
use winit::{Event, EventLoop, ElementState, MouseCursor, WindowEvent, KeyboardInput, ControlFlow};
|
||||
|
||||
fn main() {
|
||||
let mut events_loop = winit::EventLoop::new();
|
||||
let mut events_loop = EventLoop::new();
|
||||
|
||||
let window = winit::WindowBuilder::new().build(&events_loop).unwrap();
|
||||
window.set_title("A fantastic window!");
|
||||
|
||||
let cursors = [MouseCursor::Default, MouseCursor::Crosshair, MouseCursor::Hand, MouseCursor::Arrow, MouseCursor::Move, MouseCursor::Text, MouseCursor::Wait, MouseCursor::Help, MouseCursor::Progress, MouseCursor::NotAllowed, MouseCursor::ContextMenu, MouseCursor::Cell, MouseCursor::VerticalText, MouseCursor::Alias, MouseCursor::Copy, MouseCursor::NoDrop, MouseCursor::Grab, MouseCursor::Grabbing, MouseCursor::AllScroll, MouseCursor::ZoomIn, MouseCursor::ZoomOut, MouseCursor::EResize, MouseCursor::NResize, MouseCursor::NeResize, MouseCursor::NwResize, MouseCursor::SResize, MouseCursor::SeResize, MouseCursor::SwResize, MouseCursor::WResize, MouseCursor::EwResize, MouseCursor::NsResize, MouseCursor::NeswResize, MouseCursor::NwseResize, MouseCursor::ColResize, MouseCursor::RowResize];
|
||||
let mut cursor_idx = 0;
|
||||
|
||||
events_loop.run_forever(|event| {
|
||||
events_loop.run_forever(move |event, _: &EventLoop| {
|
||||
match event {
|
||||
Event::WindowEvent { event: WindowEvent::KeyboardInput { input: KeyboardInput { state: ElementState::Pressed, .. }, .. }, .. } => {
|
||||
println!("Setting cursor to \"{:?}\"", cursors[cursor_idx]);
|
||||
window.set_cursor(cursors[cursor_idx]);
|
||||
if cursor_idx < cursors.len() - 1 {
|
||||
println!("Setting cursor to \"{:?}\"", CURSORS[cursor_idx]);
|
||||
window.set_cursor(CURSORS[cursor_idx]);
|
||||
if cursor_idx < CURSORS.len() - 1 {
|
||||
cursor_idx += 1;
|
||||
} else {
|
||||
cursor_idx = 0;
|
||||
@@ -30,3 +29,18 @@ fn main() {
|
||||
ControlFlow::Continue
|
||||
});
|
||||
}
|
||||
|
||||
const CURSORS: &[MouseCursor] = &[
|
||||
MouseCursor::Default, MouseCursor::Crosshair, MouseCursor::Hand,
|
||||
MouseCursor::Arrow, MouseCursor::Move, MouseCursor::Text,
|
||||
MouseCursor::Wait, MouseCursor::Help, MouseCursor::Progress,
|
||||
MouseCursor::NotAllowed, MouseCursor::ContextMenu, MouseCursor::Cell,
|
||||
MouseCursor::VerticalText, MouseCursor::Alias, MouseCursor::Copy,
|
||||
MouseCursor::NoDrop, MouseCursor::Grab, MouseCursor::Grabbing,
|
||||
MouseCursor::AllScroll, MouseCursor::ZoomIn, MouseCursor::ZoomOut,
|
||||
MouseCursor::EResize, MouseCursor::NResize, MouseCursor::NeResize,
|
||||
MouseCursor::NwResize, MouseCursor::SResize, MouseCursor::SeResize,
|
||||
MouseCursor::SwResize, MouseCursor::WResize, MouseCursor::EwResize,
|
||||
MouseCursor::NsResize, MouseCursor::NeswResize, MouseCursor::NwseResize,
|
||||
MouseCursor::ColResize, MouseCursor::RowResize
|
||||
];
|
||||
|
||||
@@ -8,7 +8,7 @@ fn main() {
|
||||
.build(&events_loop)
|
||||
.unwrap();
|
||||
|
||||
events_loop.run_forever(|event| {
|
||||
events_loop.run_forever(move |event, _: &winit::EventLoop| {
|
||||
if let winit::Event::WindowEvent { event, .. } = event {
|
||||
use winit::WindowEvent::*;
|
||||
match event {
|
||||
|
||||
@@ -35,7 +35,7 @@ fn main() {
|
||||
let mut is_maximized = false;
|
||||
let mut decorations = true;
|
||||
|
||||
events_loop.run_forever(|event| {
|
||||
events_loop.run_forever(move |event, _: &winit::EventLoop| {
|
||||
println!("{:?}", event);
|
||||
|
||||
match event {
|
||||
|
||||
@@ -10,7 +10,7 @@ fn main() {
|
||||
|
||||
let mut close_requested = false;
|
||||
|
||||
events_loop.run_forever(|event| {
|
||||
events_loop.run_forever(move |event, _: &winit::EventLoop| {
|
||||
use winit::WindowEvent::*;
|
||||
use winit::ElementState::Released;
|
||||
use winit::VirtualKeyCode::{N, Y};
|
||||
|
||||
@@ -12,7 +12,7 @@ fn main() {
|
||||
window.set_min_dimensions(Some(LogicalSize::new(400.0, 200.0)));
|
||||
window.set_max_dimensions(Some(LogicalSize::new(800.0, 400.0)));
|
||||
|
||||
events_loop.run_forever(|event| {
|
||||
events_loop.run_forever(move |event, _: &winit::EventLoop| {
|
||||
println!("{:?}", event);
|
||||
|
||||
match event {
|
||||
|
||||
@@ -11,19 +11,25 @@ fn main() {
|
||||
windows.insert(window.id(), window);
|
||||
}
|
||||
|
||||
events_loop.run_forever(|event| {
|
||||
events_loop.run_forever(move |event, events_loop: &winit::EventLoop| {
|
||||
match event {
|
||||
winit::Event::WindowEvent {
|
||||
event: winit::WindowEvent::CloseRequested,
|
||||
window_id,
|
||||
} => {
|
||||
println!("Window {:?} has received the signal to close", window_id);
|
||||
winit::Event::WindowEvent { event, window_id } => {
|
||||
match event {
|
||||
winit::WindowEvent::CloseRequested => {
|
||||
println!("Window {:?} has received the signal to close", window_id);
|
||||
|
||||
// This drops the window, causing it to close.
|
||||
windows.remove(&window_id);
|
||||
// This drops the window, causing it to close.
|
||||
windows.remove(&window_id);
|
||||
|
||||
if windows.is_empty() {
|
||||
return winit::ControlFlow::Break;
|
||||
if windows.is_empty() {
|
||||
return winit::ControlFlow::Break;
|
||||
}
|
||||
},
|
||||
winit::WindowEvent::KeyboardInput{..} => {
|
||||
let window = winit::Window::new(&events_loop).unwrap();
|
||||
windows.insert(window.id(), window);
|
||||
},
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
|
||||
@@ -18,7 +18,7 @@ fn main() {
|
||||
}
|
||||
});
|
||||
|
||||
events_loop.run_forever(|event| {
|
||||
events_loop.run_forever(move |event, _: &winit::EventLoop| {
|
||||
println!("{:?}", event);
|
||||
match event {
|
||||
winit::Event::WindowEvent { event: winit::WindowEvent::CloseRequested, .. } =>
|
||||
|
||||
@@ -12,7 +12,7 @@ fn main() {
|
||||
.build(&events_loop)
|
||||
.unwrap();
|
||||
|
||||
events_loop.run_forever(|event| {
|
||||
events_loop.run_forever(move |event, _: &winit::EventLoop| {
|
||||
match event {
|
||||
winit::Event::WindowEvent { event, .. } => match event {
|
||||
winit::WindowEvent::CloseRequested => return winit::ControlFlow::Break,
|
||||
|
||||
@@ -9,7 +9,7 @@ fn main() {
|
||||
|
||||
window.set_title("A fantastic window!");
|
||||
|
||||
events_loop.run_forever(|event| {
|
||||
events_loop.run_forever(move |event, _: &winit::EventLoop| {
|
||||
println!("{:?}", event);
|
||||
|
||||
match event {
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
extern crate winit;
|
||||
|
||||
fn main() {
|
||||
let mut events_loop = winit::EventLoop::new();
|
||||
let events_loop = winit::EventLoop::new();
|
||||
|
||||
let _window = winit::WindowBuilder::new()
|
||||
.with_title("A fantastic window!")
|
||||
.build(&events_loop)
|
||||
.unwrap();
|
||||
|
||||
events_loop.run_forever(|event| {
|
||||
events_loop.run_forever(move |event, _: &winit::EventLoop| {
|
||||
println!("{:?}", event);
|
||||
|
||||
match event {
|
||||
|
||||
@@ -30,7 +30,7 @@ fn main() {
|
||||
.build(&events_loop)
|
||||
.unwrap();
|
||||
|
||||
events_loop.run_forever(|event| {
|
||||
events_loop.run_forever(move |event, _: &EventLoop| {
|
||||
if let winit::Event::WindowEvent { event, .. } = event {
|
||||
use winit::WindowEvent::*;
|
||||
match event {
|
||||
|
||||
Reference in New Issue
Block a user