(
&mut self,
app: &mut App<B>,
event: &WindowEvent,
)
| 21 | } |
| 22 | |
| 23 | pub fn handle_window_event<B: GraphicsBackend>( |
| 24 | &mut self, |
| 25 | app: &mut App<B>, |
| 26 | event: &WindowEvent, |
| 27 | ) { |
| 28 | match event { |
| 29 | WindowEvent::KeyboardInput { event, .. } => { |
| 30 | if let PhysicalKey::Code(code) = event.physical_key |
| 31 | && let Some(key) = map_winit_key_code(code) |
| 32 | { |
| 33 | app.set_key_state(key, event.state == ElementState::Pressed); |
| 34 | } |
| 35 | if event.state == ElementState::Pressed |
| 36 | && !self.text_input_suppressed() |
| 37 | && let Some(text) = event.text.as_ref() |
| 38 | && text.chars().any(|ch| !ch.is_control()) |
| 39 | { |
| 40 | app.push_text_input(text.to_string()); |
| 41 | } |
| 42 | } |
| 43 | WindowEvent::ModifiersChanged(modifiers) => { |
| 44 | self.modifiers = modifiers.state(); |
| 45 | } |
| 46 | WindowEvent::Focused(false) => { |
| 47 | self.modifiers = Modifiers::default().state(); |
| 48 | } |
| 49 | WindowEvent::Ime(winit::event::Ime::Commit(text)) => { |
| 50 | app.push_text_input(text.clone()); |
| 51 | } |
| 52 | WindowEvent::MouseInput { state, button, .. } => { |
| 53 | if let Some(mapped) = map_winit_mouse_button(*button) { |
| 54 | app.set_mouse_button_state(mapped, *state == ElementState::Pressed); |
| 55 | } |
| 56 | } |
| 57 | WindowEvent::CursorMoved { position, .. } => { |
| 58 | if let Some(prev) = self.last_cursor_position { |
| 59 | let dx = (position.x - prev.x) as f32; |
| 60 | let dy = (prev.y - position.y) as f32; |
| 61 | app.add_mouse_delta(dx, dy); |
| 62 | } |
| 63 | app.set_mouse_position(position.x as f32, position.y as f32); |
| 64 | self.last_cursor_position = Some(*position); |
| 65 | } |
| 66 | WindowEvent::CursorLeft { .. } => { |
| 67 | self.last_cursor_position = None; |
| 68 | } |
| 69 | WindowEvent::MouseWheel { delta, .. } => { |
| 70 | let (dx, dy) = match delta { |
| 71 | MouseScrollDelta::LineDelta(x, y) => (*x, *y), |
| 72 | MouseScrollDelta::PixelDelta(pos) => { |
| 73 | ((pos.x as f32) / 40.0, (pos.y as f32) / 40.0) |
| 74 | } |
| 75 | }; |
| 76 | app.add_mouse_wheel(dx, dy); |
| 77 | } |
| 78 | _ => {} |
| 79 | } |
| 80 | } |
no test coverage detected