mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-11-13 19:08:41 -06:00
move cursor to center on unlock
This commit is contained in:
parent
0a352ac291
commit
ca74c7799c
|
@ -1,9 +1,7 @@
|
|||
use shipyard::{AllStoragesView, IntoIter, NonSendSync, Unique, UniqueView, UniqueViewMut, View};
|
||||
use crate::{events::InputDeviceEvent, rendering::Renderer};
|
||||
use crate::{events::InputDeviceEvent, rendering::{Renderer, WindowSize}};
|
||||
use winit::{
|
||||
event::{DeviceEvent, ElementState, RawKeyEvent},
|
||||
keyboard::{KeyCode, PhysicalKey},
|
||||
window::CursorGrabMode
|
||||
dpi::PhysicalPosition, event::{DeviceEvent, ElementState, RawKeyEvent}, keyboard::{KeyCode, PhysicalKey}, window::CursorGrabMode
|
||||
};
|
||||
|
||||
#[derive(Unique)]
|
||||
|
@ -43,6 +41,8 @@ pub fn lock_cursor_now(
|
|||
pub fn debug_toggle_lock(
|
||||
mut lock: UniqueViewMut<CursorLock>,
|
||||
device_events: View<InputDeviceEvent>,
|
||||
ren: NonSendSync<UniqueView<Renderer>>,
|
||||
size: UniqueView<WindowSize>,
|
||||
) {
|
||||
for evt in device_events.iter() {
|
||||
if let DeviceEvent::Key(RawKeyEvent {
|
||||
|
@ -50,6 +50,10 @@ pub fn debug_toggle_lock(
|
|||
state: ElementState::Pressed,
|
||||
}) = evt.event {
|
||||
lock.0 = !lock.0;
|
||||
if !lock.0 {
|
||||
let center = PhysicalPosition::new(size.0.x as f64 / 2., size.0.y as f64 / 2.);
|
||||
let _ = ren.window.set_cursor_position(center);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue