2020-09-10 11:58:30 +10:00
|
|
|
use simple_logger::SimpleLogger;
|
2019-06-22 01:33:15 +10:00
|
|
|
use winit::{
|
|
|
|
event::{ElementState, Event, KeyboardInput, WindowEvent},
|
|
|
|
event_loop::{ControlFlow, EventLoop},
|
|
|
|
window::{CursorIcon, WindowBuilder},
|
|
|
|
};
|
2015-01-13 11:22:37 +11:00
|
|
|
|
2015-12-27 01:38:00 +11:00
|
|
|
fn main() {
|
2020-09-10 11:58:30 +10:00
|
|
|
SimpleLogger::new().init().unwrap();
|
2019-02-06 02:30:33 +11:00
|
|
|
let event_loop = EventLoop::new();
|
2017-01-29 01:45:01 +11:00
|
|
|
|
2019-02-06 02:30:33 +11:00
|
|
|
let window = WindowBuilder::new().build(&event_loop).unwrap();
|
2015-12-27 01:38:00 +11:00
|
|
|
window.set_title("A fantastic window!");
|
2015-01-13 11:22:37 +11:00
|
|
|
|
|
|
|
let mut cursor_idx = 0;
|
2015-12-27 01:38:00 +11:00
|
|
|
|
2020-01-05 18:12:03 +11:00
|
|
|
event_loop.run(move |event, _, control_flow| {
|
|
|
|
*control_flow = ControlFlow::Wait;
|
|
|
|
|
|
|
|
match event {
|
|
|
|
Event::WindowEvent {
|
|
|
|
event:
|
|
|
|
WindowEvent::KeyboardInput {
|
|
|
|
input:
|
|
|
|
KeyboardInput {
|
|
|
|
state: ElementState::Pressed,
|
|
|
|
..
|
|
|
|
},
|
|
|
|
..
|
|
|
|
},
|
|
|
|
..
|
|
|
|
} => {
|
|
|
|
println!("Setting cursor to \"{:?}\"", CURSORS[cursor_idx]);
|
|
|
|
window.set_cursor_icon(CURSORS[cursor_idx]);
|
|
|
|
if cursor_idx < CURSORS.len() - 1 {
|
|
|
|
cursor_idx += 1;
|
|
|
|
} else {
|
|
|
|
cursor_idx = 0;
|
|
|
|
}
|
2019-06-25 02:14:55 +10:00
|
|
|
}
|
2020-01-05 18:12:03 +11:00
|
|
|
Event::WindowEvent {
|
|
|
|
event: WindowEvent::CloseRequested,
|
|
|
|
..
|
|
|
|
} => {
|
|
|
|
*control_flow = ControlFlow::Exit;
|
|
|
|
}
|
|
|
|
_ => (),
|
2015-06-16 21:48:08 +10:00
|
|
|
}
|
2017-01-29 01:45:01 +11:00
|
|
|
});
|
2015-01-13 11:22:37 +11:00
|
|
|
}
|
2019-02-06 02:30:33 +11:00
|
|
|
|
2019-05-30 11:29:54 +10:00
|
|
|
const CURSORS: &[CursorIcon] = &[
|
2019-06-22 01:33:15 +10:00
|
|
|
CursorIcon::Default,
|
|
|
|
CursorIcon::Crosshair,
|
|
|
|
CursorIcon::Hand,
|
|
|
|
CursorIcon::Arrow,
|
|
|
|
CursorIcon::Move,
|
|
|
|
CursorIcon::Text,
|
|
|
|
CursorIcon::Wait,
|
|
|
|
CursorIcon::Help,
|
|
|
|
CursorIcon::Progress,
|
|
|
|
CursorIcon::NotAllowed,
|
|
|
|
CursorIcon::ContextMenu,
|
|
|
|
CursorIcon::Cell,
|
|
|
|
CursorIcon::VerticalText,
|
|
|
|
CursorIcon::Alias,
|
|
|
|
CursorIcon::Copy,
|
|
|
|
CursorIcon::NoDrop,
|
|
|
|
CursorIcon::Grab,
|
|
|
|
CursorIcon::Grabbing,
|
|
|
|
CursorIcon::AllScroll,
|
|
|
|
CursorIcon::ZoomIn,
|
|
|
|
CursorIcon::ZoomOut,
|
|
|
|
CursorIcon::EResize,
|
|
|
|
CursorIcon::NResize,
|
|
|
|
CursorIcon::NeResize,
|
|
|
|
CursorIcon::NwResize,
|
|
|
|
CursorIcon::SResize,
|
|
|
|
CursorIcon::SeResize,
|
|
|
|
CursorIcon::SwResize,
|
|
|
|
CursorIcon::WResize,
|
|
|
|
CursorIcon::EwResize,
|
|
|
|
CursorIcon::NsResize,
|
|
|
|
CursorIcon::NeswResize,
|
|
|
|
CursorIcon::NwseResize,
|
|
|
|
CursorIcon::ColResize,
|
|
|
|
CursorIcon::RowResize,
|
2019-02-06 02:30:33 +11:00
|
|
|
];
|