mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-23 22:01:31 +11:00
Fix examples
This commit is contained in:
parent
c3d2289b0c
commit
7da96121a2
|
@ -1,17 +1,19 @@
|
||||||
extern crate winit;
|
extern crate winit;
|
||||||
|
|
||||||
use winit::{WindowEvent as Event, ElementState, MouseCursor};
|
use winit::{Event, ElementState, MouseCursor, WindowEvent};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let window = winit::WindowBuilder::new().build().unwrap();
|
let events_loop = winit::EventsLoop::new();
|
||||||
|
|
||||||
|
let window = winit::WindowBuilder::new().build(&events_loop).unwrap();
|
||||||
window.set_title("A fantastic window!");
|
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::NoneCursor, 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 cursors = [MouseCursor::Default, MouseCursor::Crosshair, MouseCursor::Hand, MouseCursor::Arrow, MouseCursor::Move, MouseCursor::Text, MouseCursor::Wait, MouseCursor::Help, MouseCursor::Progress, MouseCursor::NotAllowed, MouseCursor::ContextMenu, MouseCursor::NoneCursor, 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;
|
let mut cursor_idx = 0;
|
||||||
|
|
||||||
for event in window.wait_events() {
|
events_loop.run_forever(|event| {
|
||||||
match event {
|
match event {
|
||||||
Event::KeyboardInput(ElementState::Pressed, _, _) => {
|
Event::WindowEvent { event: WindowEvent::KeyboardInput(ElementState::Pressed, _, _), .. } => {
|
||||||
println!("Setting cursor to \"{:?}\"", cursors[cursor_idx]);
|
println!("Setting cursor to \"{:?}\"", cursors[cursor_idx]);
|
||||||
window.set_cursor(cursors[cursor_idx]);
|
window.set_cursor(cursors[cursor_idx]);
|
||||||
if cursor_idx < cursors.len() - 1 {
|
if cursor_idx < cursors.len() - 1 {
|
||||||
|
@ -20,8 +22,10 @@ fn main() {
|
||||||
cursor_idx = 0;
|
cursor_idx = 0;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Event::Closed => break,
|
Event::WindowEvent { event: WindowEvent::Closed, .. } => {
|
||||||
_ => (),
|
events_loop.interrupt()
|
||||||
}
|
},
|
||||||
|
_ => ()
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,19 +22,26 @@ fn main() {
|
||||||
monitor
|
monitor
|
||||||
};
|
};
|
||||||
|
|
||||||
let window = winit::WindowBuilder::new()
|
let events_loop = winit::EventsLoop::new();
|
||||||
|
|
||||||
|
let _window = winit::WindowBuilder::new()
|
||||||
.with_title("Hello world!")
|
.with_title("Hello world!")
|
||||||
.with_fullscreen(monitor)
|
.with_fullscreen(monitor)
|
||||||
.build()
|
.build(&events_loop)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
for event in window.wait_events() {
|
events_loop.run_forever(|event| {
|
||||||
println!("{:?}", event);
|
println!("{:?}", event);
|
||||||
|
|
||||||
match event {
|
match event {
|
||||||
winit::Event::Closed => break,
|
winit::Event::WindowEvent { event, .. } => {
|
||||||
winit::Event::KeyboardInput(_, _, Some(winit::VirtualKeyCode::Escape)) => break,
|
match event {
|
||||||
|
winit::WindowEvent::Closed => events_loop.interrupt(),
|
||||||
|
winit::WindowEvent::KeyboardInput(_, _, Some(winit::VirtualKeyCode::Escape)) => events_loop.interrupt(),
|
||||||
_ => ()
|
_ => ()
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
_ => ()
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +1,22 @@
|
||||||
extern crate winit;
|
extern crate winit;
|
||||||
|
|
||||||
use winit::{WindowEvent as Event, ElementState};
|
use winit::{WindowEvent, ElementState};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let window = winit::WindowBuilder::new().build().unwrap();
|
let events_loop = winit::EventsLoop::new();
|
||||||
|
|
||||||
|
let window = winit::WindowBuilder::new().build(&events_loop).unwrap();
|
||||||
window.set_title("winit - Cursor grabbing test");
|
window.set_title("winit - Cursor grabbing test");
|
||||||
|
|
||||||
let mut grabbed = false;
|
let mut grabbed = false;
|
||||||
|
|
||||||
for event in window.wait_events() {
|
events_loop.run_forever(|event| {
|
||||||
|
println!("{:?}", event);
|
||||||
|
|
||||||
match event {
|
match event {
|
||||||
Event::KeyboardInput(ElementState::Pressed, _, _) => {
|
winit::Event::WindowEvent { event, .. } => {
|
||||||
|
match event {
|
||||||
|
WindowEvent::KeyboardInput(ElementState::Pressed, _, _) => {
|
||||||
if grabbed {
|
if grabbed {
|
||||||
grabbed = false;
|
grabbed = false;
|
||||||
window.set_cursor_state(winit::CursorState::Normal)
|
window.set_cursor_state(winit::CursorState::Normal)
|
||||||
|
@ -22,13 +28,16 @@ fn main() {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
Event::Closed => break,
|
WindowEvent::Closed => events_loop.interrupt(),
|
||||||
|
|
||||||
a @ Event::MouseMoved(_, _) => {
|
a @ WindowEvent::MouseMoved(_, _) => {
|
||||||
println!("{:?}", a);
|
println!("{:?}", a);
|
||||||
},
|
},
|
||||||
|
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
_ => ()
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +1,20 @@
|
||||||
extern crate winit;
|
extern crate winit;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let window = winit::WindowBuilder::new()
|
let events_loop = winit::EventsLoop::new();
|
||||||
|
|
||||||
|
let _window = winit::WindowBuilder::new()
|
||||||
.with_min_dimensions(400, 200)
|
.with_min_dimensions(400, 200)
|
||||||
.with_max_dimensions(800, 400)
|
.with_max_dimensions(800, 400)
|
||||||
.build()
|
.build(&events_loop)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
for event in window.wait_events() {
|
events_loop.run_forever(|event| {
|
||||||
|
println!("{:?}", event);
|
||||||
|
|
||||||
match event {
|
match event {
|
||||||
winit::Event::Closed => break,
|
winit::Event::WindowEvent { event: winit::WindowEvent::Closed, .. } => events_loop.interrupt(),
|
||||||
_ => ()
|
_ => ()
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,34 +1,33 @@
|
||||||
extern crate winit;
|
extern crate winit;
|
||||||
|
|
||||||
use std::thread;
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let window1 = winit::WindowBuilder::new().build().unwrap();
|
let events_loop = winit::EventsLoop::new();
|
||||||
let window2 = winit::WindowBuilder::new().build().unwrap();
|
|
||||||
let window3 = winit::WindowBuilder::new().build().unwrap();
|
|
||||||
|
|
||||||
let t1 = thread::spawn(move || {
|
let window1 = winit::Window::new(&events_loop).unwrap();
|
||||||
run(window1);
|
let window2 = winit::Window::new(&events_loop).unwrap();
|
||||||
});
|
let window3 = winit::Window::new(&events_loop).unwrap();
|
||||||
|
|
||||||
let t2 = thread::spawn(move || {
|
let mut num_windows = 3;
|
||||||
run(window2);
|
|
||||||
});
|
|
||||||
|
|
||||||
let t3 = thread::spawn(move || {
|
events_loop.run_forever(|event| {
|
||||||
run(window3);
|
|
||||||
});
|
|
||||||
|
|
||||||
let _ = t1.join();
|
|
||||||
let _ = t2.join();
|
|
||||||
let _ = t3.join();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn run(window: winit::Window) {
|
|
||||||
for event in window.wait_events() {
|
|
||||||
match event {
|
match event {
|
||||||
winit::Event::Closed => break,
|
winit::Event::WindowEvent { event: winit::WindowEvent::Closed, window_id } => {
|
||||||
_ => ()
|
if window_id == window1.id() {
|
||||||
|
println!("Window 1 has been closed")
|
||||||
|
} else if window_id == window2.id() {
|
||||||
|
println!("Window 2 has been closed")
|
||||||
|
} else if window_id == window3.id() {
|
||||||
|
println!("Window 3 has been closed");
|
||||||
|
} else {
|
||||||
|
unreachable!()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
num_windows -= 1;
|
||||||
|
if num_windows == 0 {
|
||||||
|
events_loop.interrupt();
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,22 +1,20 @@
|
||||||
extern crate winit;
|
extern crate winit;
|
||||||
|
|
||||||
fn resize_callback(width: u32, height: u32) {
|
|
||||||
println!("Window resized to {}x{}", width, height);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut window = winit::WindowBuilder::new().with_decorations(false)
|
let events_loop = winit::EventsLoop::new();
|
||||||
.with_transparency(true)
|
|
||||||
.build().unwrap();
|
|
||||||
window.set_title("A fantastic window!");
|
|
||||||
window.set_window_resize_callback(Some(resize_callback as fn(u32, u32)));
|
|
||||||
|
|
||||||
for event in window.wait_events() {
|
let window = winit::WindowBuilder::new().with_decorations(false)
|
||||||
|
.with_transparency(true)
|
||||||
|
.build(&events_loop).unwrap();
|
||||||
|
|
||||||
|
window.set_title("A fantastic window!");
|
||||||
|
|
||||||
|
events_loop.run_forever(|event| {
|
||||||
println!("{:?}", event);
|
println!("{:?}", event);
|
||||||
|
|
||||||
match event {
|
match event {
|
||||||
winit::Event::Closed => break,
|
winit::Event::WindowEvent { event: winit::WindowEvent::Closed, .. } => events_loop.interrupt(),
|
||||||
_ => ()
|
_ => ()
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue