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;
|
||||
|
||||
use winit::{WindowEvent as Event, ElementState, MouseCursor};
|
||||
use winit::{Event, ElementState, MouseCursor, WindowEvent};
|
||||
|
||||
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!");
|
||||
|
||||
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;
|
||||
|
||||
for event in window.wait_events() {
|
||||
events_loop.run_forever(|event| {
|
||||
match event {
|
||||
Event::KeyboardInput(ElementState::Pressed, _, _) => {
|
||||
Event::WindowEvent { event: WindowEvent::KeyboardInput(ElementState::Pressed, _, _), .. } => {
|
||||
println!("Setting cursor to \"{:?}\"", cursors[cursor_idx]);
|
||||
window.set_cursor(cursors[cursor_idx]);
|
||||
if cursor_idx < cursors.len() - 1 {
|
||||
|
@ -20,8 +22,10 @@ fn main() {
|
|||
cursor_idx = 0;
|
||||
}
|
||||
},
|
||||
Event::Closed => break,
|
||||
_ => (),
|
||||
Event::WindowEvent { event: WindowEvent::Closed, .. } => {
|
||||
events_loop.interrupt()
|
||||
},
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -22,19 +22,26 @@ fn main() {
|
|||
monitor
|
||||
};
|
||||
|
||||
let window = winit::WindowBuilder::new()
|
||||
let events_loop = winit::EventsLoop::new();
|
||||
|
||||
let _window = winit::WindowBuilder::new()
|
||||
.with_title("Hello world!")
|
||||
.with_fullscreen(monitor)
|
||||
.build()
|
||||
.build(&events_loop)
|
||||
.unwrap();
|
||||
|
||||
for event in window.wait_events() {
|
||||
events_loop.run_forever(|event| {
|
||||
println!("{:?}", event);
|
||||
|
||||
match event {
|
||||
winit::Event::Closed => break,
|
||||
winit::Event::KeyboardInput(_, _, Some(winit::VirtualKeyCode::Escape)) => break,
|
||||
winit::Event::WindowEvent { event, .. } => {
|
||||
match event {
|
||||
winit::WindowEvent::Closed => events_loop.interrupt(),
|
||||
winit::WindowEvent::KeyboardInput(_, _, Some(winit::VirtualKeyCode::Escape)) => events_loop.interrupt(),
|
||||
_ => ()
|
||||
}
|
||||
},
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,34 +1,43 @@
|
|||
extern crate winit;
|
||||
|
||||
use winit::{WindowEvent as Event, ElementState};
|
||||
use winit::{WindowEvent, ElementState};
|
||||
|
||||
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");
|
||||
|
||||
let mut grabbed = false;
|
||||
|
||||
for event in window.wait_events() {
|
||||
events_loop.run_forever(|event| {
|
||||
println!("{:?}", event);
|
||||
|
||||
match event {
|
||||
Event::KeyboardInput(ElementState::Pressed, _, _) => {
|
||||
if grabbed {
|
||||
grabbed = false;
|
||||
window.set_cursor_state(winit::CursorState::Normal)
|
||||
.ok().expect("could not ungrab mouse cursor");
|
||||
} else {
|
||||
grabbed = true;
|
||||
window.set_cursor_state(winit::CursorState::Grab)
|
||||
.ok().expect("could not grab mouse cursor");
|
||||
winit::Event::WindowEvent { event, .. } => {
|
||||
match event {
|
||||
WindowEvent::KeyboardInput(ElementState::Pressed, _, _) => {
|
||||
if grabbed {
|
||||
grabbed = false;
|
||||
window.set_cursor_state(winit::CursorState::Normal)
|
||||
.ok().expect("could not ungrab mouse cursor");
|
||||
} else {
|
||||
grabbed = true;
|
||||
window.set_cursor_state(winit::CursorState::Grab)
|
||||
.ok().expect("could not grab mouse cursor");
|
||||
}
|
||||
},
|
||||
|
||||
WindowEvent::Closed => events_loop.interrupt(),
|
||||
|
||||
a @ WindowEvent::MouseMoved(_, _) => {
|
||||
println!("{:?}", a);
|
||||
},
|
||||
|
||||
_ => (),
|
||||
}
|
||||
},
|
||||
|
||||
Event::Closed => break,
|
||||
|
||||
a @ Event::MouseMoved(_, _) => {
|
||||
println!("{:?}", a);
|
||||
},
|
||||
|
||||
_ => (),
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,16 +1,20 @@
|
|||
extern crate winit;
|
||||
|
||||
fn main() {
|
||||
let window = winit::WindowBuilder::new()
|
||||
let events_loop = winit::EventsLoop::new();
|
||||
|
||||
let _window = winit::WindowBuilder::new()
|
||||
.with_min_dimensions(400, 200)
|
||||
.with_max_dimensions(800, 400)
|
||||
.build()
|
||||
.build(&events_loop)
|
||||
.unwrap();
|
||||
|
||||
for event in window.wait_events() {
|
||||
events_loop.run_forever(|event| {
|
||||
println!("{:?}", event);
|
||||
|
||||
match event {
|
||||
winit::Event::Closed => break,
|
||||
winit::Event::WindowEvent { event: winit::WindowEvent::Closed, .. } => events_loop.interrupt(),
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,34 +1,33 @@
|
|||
extern crate winit;
|
||||
|
||||
use std::thread;
|
||||
|
||||
fn main() {
|
||||
let window1 = winit::WindowBuilder::new().build().unwrap();
|
||||
let window2 = winit::WindowBuilder::new().build().unwrap();
|
||||
let window3 = winit::WindowBuilder::new().build().unwrap();
|
||||
let events_loop = winit::EventsLoop::new();
|
||||
|
||||
let t1 = thread::spawn(move || {
|
||||
run(window1);
|
||||
});
|
||||
let window1 = winit::Window::new(&events_loop).unwrap();
|
||||
let window2 = winit::Window::new(&events_loop).unwrap();
|
||||
let window3 = winit::Window::new(&events_loop).unwrap();
|
||||
|
||||
let t2 = thread::spawn(move || {
|
||||
run(window2);
|
||||
});
|
||||
let mut num_windows = 3;
|
||||
|
||||
let t3 = thread::spawn(move || {
|
||||
run(window3);
|
||||
});
|
||||
|
||||
let _ = t1.join();
|
||||
let _ = t2.join();
|
||||
let _ = t3.join();
|
||||
}
|
||||
|
||||
fn run(window: winit::Window) {
|
||||
for event in window.wait_events() {
|
||||
events_loop.run_forever(|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;
|
||||
|
||||
fn resize_callback(width: u32, height: u32) {
|
||||
println!("Window resized to {}x{}", width, height);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut window = winit::WindowBuilder::new().with_decorations(false)
|
||||
.with_transparency(true)
|
||||
.build().unwrap();
|
||||
window.set_title("A fantastic window!");
|
||||
window.set_window_resize_callback(Some(resize_callback as fn(u32, u32)));
|
||||
let events_loop = winit::EventsLoop::new();
|
||||
|
||||
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);
|
||||
|
||||
match event {
|
||||
winit::Event::Closed => break,
|
||||
winit::Event::WindowEvent { event: winit::WindowEvent::Closed, .. } => events_loop.interrupt(),
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue