pub fn from_winit_window_event(
        event: winit::WindowEvent,
        win_w: f64,
        win_h: f64,
    ) -> Option<Self> {
        use self::WindowEvent::*;

        // Translate the coordinates from top-left-origin-with-y-down to centre-origin-with-y-up.
        //
        // winit produces input events in pixels, so these positions need to be divided by the
        // width and height of the window in order to be DPI agnostic.
        let tw = |w: f64| w as geom::scalar::Default;
        let th = |h: f64| h as geom::scalar::Default;
        let tx = |x: f64| (x - win_w / 2.0) as geom::scalar::Default;
        let ty = |y: f64| (-(y - win_h / 2.0)) as geom::scalar::Default;

        let event = match event {
            winit::WindowEvent::Resized(new_size) => {
                let (new_w, new_h) = new_size.into();
                let x = tw(new_w);
                let y = th(new_h);
                Resized(Vector2 { x, y })
            }

            winit::WindowEvent::Moved(new_pos) => {
                let (new_x, new_y) = new_pos.into();
                let x = tx(new_x);
                let y = ty(new_y);
                Moved(Point2 { x, y })
            }

            // TODO: Should separate the behaviour of close requested and destroyed.
            winit::WindowEvent::CloseRequested | winit::WindowEvent::Destroyed => Closed,

            winit::WindowEvent::DroppedFile(path) => DroppedFile(path),

            winit::WindowEvent::HoveredFile(path) => HoveredFile(path),

            winit::WindowEvent::HoveredFileCancelled => HoveredFileCancelled,

            winit::WindowEvent::Focused(b) => {
                if b {
                    Focused
                } else {
                    Unfocused
                }
            }

            winit::WindowEvent::CursorMoved { position, .. } => {
                let (x, y) = position.into();
                let x = tx(x);
                let y = ty(y);
                MouseMoved(Point2 { x, y })
            }

            winit::WindowEvent::CursorEntered { .. } => MouseEntered,

            winit::WindowEvent::CursorLeft { .. } => MouseExited,

            winit::WindowEvent::MouseWheel { delta, phase, .. } => MouseWheel(delta, phase),

            winit::WindowEvent::MouseInput { state, button, .. } => match state {
                ElementState::Pressed => MousePressed(button),
                ElementState::Released => MouseReleased(button),
            },

            winit::WindowEvent::Touch(winit::Touch {
                phase,
                location,
                id,
                ..
            }) => {
                let (x, y) = location.into();
                let x = tx(x);
                let y = ty(y);
                let position = Point2 { x, y };
                let touch = TouchEvent {
                    phase,
                    position,
                    id,
                };
                WindowEvent::Touch(touch)
            }

            winit::WindowEvent::TouchpadPressure {
                device_id,
                pressure,
                stage,
            } => TouchPressure(TouchpadPressure {
                device_id,
                pressure,
                stage,
            }),

            winit::WindowEvent::KeyboardInput { input, .. } => match input.virtual_keycode {
                Some(key) => match input.state {
                    ElementState::Pressed => KeyPressed(key),
                    ElementState::Released => KeyReleased(key),
                },
                None => return None,
            },

            winit::WindowEvent::AxisMotion { .. }
            | winit::WindowEvent::Refresh
            | winit::WindowEvent::ReceivedCharacter(_)
            | winit::WindowEvent::HiDpiFactorChanged(_) => {
                return None;
            }
        };

        Some(event)
    }
/// Produce a simplified, new-user-friendly version of the given `winit::WindowEvent`.
///
/// This strips rarely needed technical information from the event type such as information
/// about the source device, scancodes for keyboard events, etc to make the experience of
/// pattern matching on window events nicer for new users.
///
/// This also interprets the raw pixel positions and dimensions of the raw event into a
/// dpi-agnostic scalar value where (0, 0, 0) is the centre of the screen with the `y` axis
/// increasing in the upwards direction.
///
/// If the user requires this extra information, they should use the `raw` field of the
/// `WindowEvent` type rather than the `simple` one.
Produce a simplified, new-user-friendly version of the given `winit::WindowEvent`.
This strips rarely needed technical information from the event type such as information
about the source device, scancodes for keyboard events, etc to make the experience of
pattern matching on window events nicer for new users.

This also interprets the raw pixel positions and dimensions of the raw event into a
dpi-agnostic scalar value where (0, 0, 0) is the centre of the screen with the `y` axis
increasing in the upwards direction.


Produce a simplified new - user - friendly version of the given ` winit :: WindowEvent ` . This strips rarely needed technical information from the event type such as information about the source device scancodes for keyboard events etc to make the experience of pattern matching on window events nicer for new users . This also interprets the raw pixel positions and dimensions of the raw event into a dpi - agnostic scalar value where ( 0 0 0 ) is the centre of the screen with the ` y ` axis increasing in the upwards direction .
pub fn from_winit_window_event(
        event: winit::WindowEvent,
        win_w: f64,
        win_h: f64,
    ) -> Option<Self> {
        use self::WindowEvent::*;
        // Translate the coordinates from top-left-origin-with-y-down to centre-origin-with-y-up.
        //
        // winit produces input events in pixels, so these positions need to be divided by the
        // width and height of the window in order to be DPI agnostic.
        let tw = |w: f64| w as geom::scalar::Default;
        let th = |h: f64| h as geom::scalar::Default;
        let tx = |x: f64| (x - win_w / 2.0) as geom::scalar::Default;
        let ty = |y: f64| (-(y - win_h / 2.0)) as geom::scalar::Default;
        let event = match event {
            winit::WindowEvent::Resized(new_size) => {
                let (new_w, new_h) = new_size.into();
                let x = tw(new_w);
                let y = th(new_h);
                Resized(Vector2 { x, y })
            }
            winit::WindowEvent::Moved(new_pos) => {
                let (new_x, new_y) = new_pos.into();
                let x = tx(new_x);
                let y = ty(new_y);
                Moved(Point2 { x, y })
            }
            // TODO: Should separate the behaviour of close requested and destroyed.
            winit::WindowEvent::CloseRequested | winit::WindowEvent::Destroyed => Closed,
            winit::WindowEvent::DroppedFile(path) => DroppedFile(path),
            winit::WindowEvent::HoveredFile(path) => HoveredFile(path),
            winit::WindowEvent::HoveredFileCancelled => HoveredFileCancelled,
            winit::WindowEvent::Focused(b) => {
                if b {
                    Focused
                } else {
                    Unfocused
                }
            }
            winit::WindowEvent::CursorMoved { position, .. } => {
                let (x, y) = position.into();
                let x = tx(x);
                let y = ty(y);
                MouseMoved(Point2 { x, y })
            }
            winit::WindowEvent::CursorEntered { .. } => MouseEntered,
            winit::WindowEvent::CursorLeft { .. } => MouseExited,
            winit::WindowEvent::MouseWheel { delta, phase, .. } => MouseWheel(delta, phase),
            winit::WindowEvent::MouseInput { state, button, .. } => match state {
                ElementState::Pressed => MousePressed(button),
                ElementState::Released => MouseReleased(button),
            },
            winit::WindowEvent::Touch(winit::Touch {
                phase,
                location,
                id,
                ..
            }) => {
                let (x, y) = location.into();
                let x = tx(x);
                let y = ty(y);
                let position = Point2 { x, y };
                let touch = TouchEvent {
                    phase,
                    position,
                    id,
                };
                WindowEvent::Touch(touch)
            }
            winit::WindowEvent::TouchpadPressure {
                device_id,
                pressure,
                stage,
            } => TouchPressure(TouchpadPressure {
                device_id,
                pressure,
                stage,
            }),
            winit::WindowEvent::KeyboardInput { input, .. } => match input.virtual_keycode {
                Some(key) => match input.state {
                    ElementState::Pressed => KeyPressed(key),
                    ElementState::Released => KeyReleased(key),
                },
                None => return None,
            },
            winit::WindowEvent::AxisMotion { .. }
            | winit::WindowEvent::Refresh
            | winit::WindowEvent::ReceivedCharacter(_)
            | winit::WindowEvent::HiDpiFactorChanged(_) => {
                return None;
            }
        };
        Some(event)
    }
pub fn from_winit_window_event ( event : winit :: WindowEvent , win_w : f64 , win_h : f64 , ) -> Option < Self > { use self :: WindowEvent :: * ; // Translate the coordinates from top-left-origin-with-y-down to centre-origin-with-y-up. // // winit produces input events in pixels, so these positions need to be divided by the // width and height of the window in order to be DPI agnostic. let tw = | w : f64 | w as geom :: scalar :: Default ; let th = | h : f64 | h as geom :: scalar :: Default ; let tx = | x : f64 | ( x - win_w / 2.0 ) as geom :: scalar :: Default ; let ty = | y : f64 | ( - ( y - win_h / 2.0 ) ) as geom :: scalar :: Default ; let event = match event { winit :: WindowEvent :: Resized ( new_size ) => { let ( new_w , new_h ) = new_size . into ( ) ; let x = tw ( new_w ) ; let y = th ( new_h ) ; Resized ( Vector2 { x , y } ) } winit :: WindowEvent :: Moved ( new_pos ) => { let ( new_x , new_y ) = new_pos . into ( ) ; let x = tx ( new_x ) ; let y = ty ( new_y ) ; Moved ( Point2 { x , y } ) } // TODO: Should separate the behaviour of close requested and destroyed. winit :: WindowEvent :: CloseRequested | winit :: WindowEvent :: Destroyed => Closed , winit :: WindowEvent :: DroppedFile ( path ) => DroppedFile ( path ) , winit :: WindowEvent :: HoveredFile ( path ) => HoveredFile ( path ) , winit :: WindowEvent :: HoveredFileCancelled => HoveredFileCancelled , winit :: WindowEvent :: Focused ( b ) => { if b { Focused } else { Unfocused } } winit :: WindowEvent :: CursorMoved { position , .. } => { let ( x , y ) = position . into ( ) ; let x = tx ( x ) ; let y = ty ( y ) ; MouseMoved ( Point2 { x , y } ) } winit :: WindowEvent :: CursorEntered { .. } => MouseEntered , winit :: WindowEvent :: CursorLeft { .. } => MouseExited , winit :: WindowEvent :: MouseWheel { delta , phase , .. } => MouseWheel ( delta , phase ) , winit :: WindowEvent :: MouseInput { state , button , .. } => match state { ElementState :: Pressed => MousePressed ( button ) , ElementState :: Released => MouseReleased ( button ) , } , winit :: WindowEvent :: Touch ( winit :: Touch { phase , location , id , .. } ) => { let ( x , y ) = location . into ( ) ; let x = tx ( x ) ; let y = ty ( y ) ; let position = Point2 { x , y } ; let touch = TouchEvent { phase , position , id , } ; WindowEvent :: Touch ( touch ) } winit :: WindowEvent :: TouchpadPressure { device_id , pressure , stage , } => TouchPressure ( TouchpadPressure { device_id , pressure , stage , } ) , winit :: WindowEvent :: KeyboardInput { input , .. } => match input . virtual_keycode { Some ( key ) => match input . state { ElementState :: Pressed => KeyPressed ( key ) , ElementState :: Released => KeyReleased ( key ) , } , None => return None , } , winit :: WindowEvent :: AxisMotion { .. } | winit :: WindowEvent :: Refresh | winit :: WindowEvent :: ReceivedCharacter ( _ ) | winit :: WindowEvent :: HiDpiFactorChanged ( _ ) => { return None ; } } ; Some ( event ) }
Produce a simplified, new-user-friendly version of the given `winit::WindowEvent`.
Produce a simplified new - user - friendly version of the given ` winit :: WindowEvent ` .
event
winit::WindowEvent
win_w
f64
win_h
f64
event
winit::WindowEvent
win_w
f64
win_h
f64