veloren_voxygen/ui/
event.rs1use conrod_core::{event::Input, input::Button};
2use vek::*;
3
4#[derive(Clone, Debug)]
5pub struct Event(pub Input);
6impl Event {
7 pub fn try_from(
8 event: &winit::event::Event<()>,
9 window: &winit::window::Window,
10 ) -> Option<Self> {
11 use conrod_winit::*;
12 struct WindowRef<'a>(&'a winit::window::Window);
15
16 impl WinitWindow for WindowRef<'_> {
19 fn get_inner_size(&self) -> Option<(u32, u32)> {
20 Some(
21 winit::window::Window::inner_size(self.0)
22 .to_logical::<u32>(self.hidpi_factor())
23 .into(),
24 )
25 }
26
27 fn hidpi_factor(&self) -> f64 { winit::window::Window::scale_factor(self.0) }
28 }
29 convert_event!(event, &WindowRef(window)).map(Self)
30 }
31
32 pub fn is_keyboard_or_mouse(&self) -> bool {
33 matches!(
34 self.0,
35 Input::Press(_)
36 | Input::Release(_)
37 | Input::Motion(_)
38 | Input::Touch(_)
39 | Input::Text(_)
40 )
41 }
42
43 pub fn is_keyboard(&self) -> bool {
44 matches!(
45 self.0,
46 Input::Press(Button::Keyboard(_))
47 | Input::Release(Button::Keyboard(_))
48 | Input::Text(_)
49 )
50 }
51
52 pub fn new_resize(dims: Vec2<f64>) -> Self { Self(Input::Resize(dims.x, dims.y)) }
53}