add cursor grab
This commit is contained in:
parent
355d391ea5
commit
95d16271de
@ -51,7 +51,7 @@ pub trait Example: 'static + Sized {
|
|||||||
device: &wgpu::Device,
|
device: &wgpu::Device,
|
||||||
queue: &wgpu::Queue,
|
queue: &wgpu::Queue,
|
||||||
);
|
);
|
||||||
fn update(&mut self, device: &wgpu::Device, queue: &wgpu::Queue, event: WindowEvent);
|
fn update(&mut self, window: &winit::window::Window, device: &wgpu::Device, queue: &wgpu::Queue, event: WindowEvent);
|
||||||
fn device_event(&mut self, event: DeviceEvent);
|
fn device_event(&mut self, event: DeviceEvent);
|
||||||
fn render(
|
fn render(
|
||||||
&mut self,
|
&mut self,
|
||||||
@ -367,7 +367,7 @@ fn start<E: Example>(
|
|||||||
println!("{:#?}", instance.generate_report());
|
println!("{:#?}", instance.generate_report());
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
example.update(&device,&queue,event);
|
example.update(&window,&device,&queue,event);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
event::Event::DeviceEvent {
|
event::Event::DeviceEvent {
|
||||||
|
26
src/main.rs
26
src/main.rs
@ -775,8 +775,7 @@ impl framework::Example for GraphicsData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::single_match)]
|
#[allow(clippy::single_match)]
|
||||||
fn update(&mut self, device: &wgpu::Device, queue: &wgpu::Queue, event: winit::event::WindowEvent) {
|
fn update(&mut self, window: &winit::window::Window, device: &wgpu::Device, queue: &wgpu::Queue, event: winit::event::WindowEvent) {
|
||||||
//nothing atm
|
|
||||||
match event {
|
match event {
|
||||||
winit::event::WindowEvent::DroppedFile(path) => {
|
winit::event::WindowEvent::DroppedFile(path) => {
|
||||||
println!("opening file: {:?}", &path);
|
println!("opening file: {:?}", &path);
|
||||||
@ -838,6 +837,29 @@ impl framework::Example for GraphicsData {
|
|||||||
println!("Could not open file");
|
println!("Could not open file");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
winit::event::WindowEvent::KeyboardInput {
|
||||||
|
input:winit::event::KeyboardInput{state, virtual_keycode,..},
|
||||||
|
..
|
||||||
|
}=>{
|
||||||
|
let s=match state {
|
||||||
|
winit::event::ElementState::Pressed => true,
|
||||||
|
winit::event::ElementState::Released => false,
|
||||||
|
};
|
||||||
|
match virtual_keycode{
|
||||||
|
Some(winit::event::VirtualKeyCode::Tab)=>{
|
||||||
|
if s{
|
||||||
|
if let Ok(())=window.set_cursor_grab(winit::window::CursorGrabMode::None){
|
||||||
|
window.set_cursor_visible(true);
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
if let Ok(())=window.set_cursor_grab(winit::window::CursorGrabMode::Locked){
|
||||||
|
window.set_cursor_visible(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
_=>(),
|
||||||
|
}
|
||||||
|
},
|
||||||
_=>(),
|
_=>(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user