diff --git a/src/framework.rs b/src/framework.rs index 5ce606b..5256e73 100644 --- a/src/framework.rs +++ b/src/framework.rs @@ -51,7 +51,7 @@ pub trait Example: 'static + Sized { device: &wgpu::Device, 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 render( &mut self, @@ -367,7 +367,7 @@ fn start( println!("{:#?}", instance.generate_report()); } _ => { - example.update(&device,&queue,event); + example.update(&window,&device,&queue,event); } }, event::Event::DeviceEvent { diff --git a/src/main.rs b/src/main.rs index 42993c1..2c59750 100644 --- a/src/main.rs +++ b/src/main.rs @@ -775,8 +775,7 @@ impl framework::Example for GraphicsData { } #[allow(clippy::single_match)] - fn update(&mut self, device: &wgpu::Device, queue: &wgpu::Queue, event: winit::event::WindowEvent) { - //nothing atm + fn update(&mut self, window: &winit::window::Window, device: &wgpu::Device, queue: &wgpu::Queue, event: winit::event::WindowEvent) { match event { winit::event::WindowEvent::DroppedFile(path) => { println!("opening file: {:?}", &path); @@ -838,6 +837,29 @@ impl framework::Example for GraphicsData { 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); + } + } + }, + _=>(), + } + }, _=>(), } }