Add conversion for `MouseButton` in `winit`

This commit is contained in:
Héctor Ramón Jiménez 2019-09-02 05:10:14 +02:00
parent 6d248719f3
commit 28009bc26d
3 changed files with 184 additions and 180 deletions

View File

@ -9,15 +9,11 @@ pub enum ButtonState {
}
#[cfg(feature = "winit")]
mod winit_conversion {
use winit::event::ElementState;
impl From<ElementState> for super::ButtonState {
fn from(element_state: ElementState) -> Self {
match element_state {
ElementState::Pressed => super::ButtonState::Pressed,
ElementState::Released => super::ButtonState::Released,
}
impl From<winit::event::ElementState> for ButtonState {
fn from(element_state: winit::event::ElementState) -> Self {
match element_state {
winit::event::ElementState::Pressed => ButtonState::Pressed,
winit::event::ElementState::Released => ButtonState::Released,
}
}
}

View File

@ -198,178 +198,174 @@ pub enum KeyCode {
}
#[cfg(feature = "winit")]
mod winit_conversion {
use winit::event::VirtualKeyCode;
impl From<VirtualKeyCode> for super::KeyCode {
fn from(virtual_keycode: VirtualKeyCode) -> Self {
match virtual_keycode {
VirtualKeyCode::Key1 => super::KeyCode::Key1,
VirtualKeyCode::Key2 => super::KeyCode::Key2,
VirtualKeyCode::Key3 => super::KeyCode::Key3,
VirtualKeyCode::Key4 => super::KeyCode::Key4,
VirtualKeyCode::Key5 => super::KeyCode::Key5,
VirtualKeyCode::Key6 => super::KeyCode::Key6,
VirtualKeyCode::Key7 => super::KeyCode::Key7,
VirtualKeyCode::Key8 => super::KeyCode::Key8,
VirtualKeyCode::Key9 => super::KeyCode::Key9,
VirtualKeyCode::Key0 => super::KeyCode::Key0,
VirtualKeyCode::A => super::KeyCode::A,
VirtualKeyCode::B => super::KeyCode::B,
VirtualKeyCode::C => super::KeyCode::C,
VirtualKeyCode::D => super::KeyCode::D,
VirtualKeyCode::E => super::KeyCode::E,
VirtualKeyCode::F => super::KeyCode::F,
VirtualKeyCode::G => super::KeyCode::G,
VirtualKeyCode::H => super::KeyCode::H,
VirtualKeyCode::I => super::KeyCode::I,
VirtualKeyCode::J => super::KeyCode::J,
VirtualKeyCode::K => super::KeyCode::K,
VirtualKeyCode::L => super::KeyCode::L,
VirtualKeyCode::M => super::KeyCode::M,
VirtualKeyCode::N => super::KeyCode::N,
VirtualKeyCode::O => super::KeyCode::O,
VirtualKeyCode::P => super::KeyCode::P,
VirtualKeyCode::Q => super::KeyCode::Q,
VirtualKeyCode::R => super::KeyCode::R,
VirtualKeyCode::S => super::KeyCode::S,
VirtualKeyCode::T => super::KeyCode::T,
VirtualKeyCode::U => super::KeyCode::U,
VirtualKeyCode::V => super::KeyCode::V,
VirtualKeyCode::W => super::KeyCode::W,
VirtualKeyCode::X => super::KeyCode::X,
VirtualKeyCode::Y => super::KeyCode::Y,
VirtualKeyCode::Z => super::KeyCode::Z,
VirtualKeyCode::Escape => super::KeyCode::Escape,
VirtualKeyCode::F1 => super::KeyCode::F1,
VirtualKeyCode::F2 => super::KeyCode::F2,
VirtualKeyCode::F3 => super::KeyCode::F3,
VirtualKeyCode::F4 => super::KeyCode::F4,
VirtualKeyCode::F5 => super::KeyCode::F5,
VirtualKeyCode::F6 => super::KeyCode::F6,
VirtualKeyCode::F7 => super::KeyCode::F7,
VirtualKeyCode::F8 => super::KeyCode::F8,
VirtualKeyCode::F9 => super::KeyCode::F9,
VirtualKeyCode::F10 => super::KeyCode::F10,
VirtualKeyCode::F11 => super::KeyCode::F11,
VirtualKeyCode::F12 => super::KeyCode::F12,
VirtualKeyCode::F13 => super::KeyCode::F13,
VirtualKeyCode::F14 => super::KeyCode::F14,
VirtualKeyCode::F15 => super::KeyCode::F15,
VirtualKeyCode::F16 => super::KeyCode::F16,
VirtualKeyCode::F17 => super::KeyCode::F17,
VirtualKeyCode::F18 => super::KeyCode::F18,
VirtualKeyCode::F19 => super::KeyCode::F19,
VirtualKeyCode::F20 => super::KeyCode::F20,
VirtualKeyCode::F21 => super::KeyCode::F21,
VirtualKeyCode::F22 => super::KeyCode::F22,
VirtualKeyCode::F23 => super::KeyCode::F23,
VirtualKeyCode::F24 => super::KeyCode::F24,
VirtualKeyCode::Snapshot => super::KeyCode::Snapshot,
VirtualKeyCode::Scroll => super::KeyCode::Scroll,
VirtualKeyCode::Pause => super::KeyCode::Pause,
VirtualKeyCode::Insert => super::KeyCode::Insert,
VirtualKeyCode::Home => super::KeyCode::Home,
VirtualKeyCode::Delete => super::KeyCode::Delete,
VirtualKeyCode::End => super::KeyCode::End,
VirtualKeyCode::PageDown => super::KeyCode::PageDown,
VirtualKeyCode::PageUp => super::KeyCode::PageUp,
VirtualKeyCode::Left => super::KeyCode::Left,
VirtualKeyCode::Up => super::KeyCode::Up,
VirtualKeyCode::Right => super::KeyCode::Right,
VirtualKeyCode::Down => super::KeyCode::Down,
VirtualKeyCode::Back => super::KeyCode::Backspace,
VirtualKeyCode::Return => super::KeyCode::Enter,
VirtualKeyCode::Space => super::KeyCode::Space,
VirtualKeyCode::Compose => super::KeyCode::Compose,
VirtualKeyCode::Caret => super::KeyCode::Caret,
VirtualKeyCode::Numlock => super::KeyCode::Numlock,
VirtualKeyCode::Numpad0 => super::KeyCode::Numpad0,
VirtualKeyCode::Numpad1 => super::KeyCode::Numpad1,
VirtualKeyCode::Numpad2 => super::KeyCode::Numpad2,
VirtualKeyCode::Numpad3 => super::KeyCode::Numpad3,
VirtualKeyCode::Numpad4 => super::KeyCode::Numpad4,
VirtualKeyCode::Numpad5 => super::KeyCode::Numpad5,
VirtualKeyCode::Numpad6 => super::KeyCode::Numpad6,
VirtualKeyCode::Numpad7 => super::KeyCode::Numpad7,
VirtualKeyCode::Numpad8 => super::KeyCode::Numpad8,
VirtualKeyCode::Numpad9 => super::KeyCode::Numpad9,
VirtualKeyCode::AbntC1 => super::KeyCode::AbntC1,
VirtualKeyCode::AbntC2 => super::KeyCode::AbntC2,
VirtualKeyCode::Add => super::KeyCode::Add,
VirtualKeyCode::Apostrophe => super::KeyCode::Apostrophe,
VirtualKeyCode::Apps => super::KeyCode::Apps,
VirtualKeyCode::At => super::KeyCode::At,
VirtualKeyCode::Ax => super::KeyCode::Ax,
VirtualKeyCode::Backslash => super::KeyCode::Backslash,
VirtualKeyCode::Calculator => super::KeyCode::Calculator,
VirtualKeyCode::Capital => super::KeyCode::Capital,
VirtualKeyCode::Colon => super::KeyCode::Colon,
VirtualKeyCode::Comma => super::KeyCode::Comma,
VirtualKeyCode::Convert => super::KeyCode::Convert,
VirtualKeyCode::Decimal => super::KeyCode::Decimal,
VirtualKeyCode::Divide => super::KeyCode::Divide,
VirtualKeyCode::Equals => super::KeyCode::Equals,
VirtualKeyCode::Grave => super::KeyCode::Grave,
VirtualKeyCode::Kana => super::KeyCode::Kana,
VirtualKeyCode::Kanji => super::KeyCode::Kanji,
VirtualKeyCode::LAlt => super::KeyCode::LAlt,
VirtualKeyCode::LBracket => super::KeyCode::LBracket,
VirtualKeyCode::LControl => super::KeyCode::LControl,
VirtualKeyCode::LShift => super::KeyCode::LShift,
VirtualKeyCode::LWin => super::KeyCode::LWin,
VirtualKeyCode::Mail => super::KeyCode::Mail,
VirtualKeyCode::MediaSelect => super::KeyCode::MediaSelect,
VirtualKeyCode::MediaStop => super::KeyCode::MediaStop,
VirtualKeyCode::Minus => super::KeyCode::Minus,
VirtualKeyCode::Multiply => super::KeyCode::Multiply,
VirtualKeyCode::Mute => super::KeyCode::Mute,
VirtualKeyCode::MyComputer => super::KeyCode::MyComputer,
VirtualKeyCode::NavigateForward => {
super::KeyCode::NavigateForward
}
VirtualKeyCode::NavigateBackward => {
super::KeyCode::NavigateBackward
}
VirtualKeyCode::NextTrack => super::KeyCode::NextTrack,
VirtualKeyCode::NoConvert => super::KeyCode::NoConvert,
VirtualKeyCode::NumpadComma => super::KeyCode::NumpadComma,
VirtualKeyCode::NumpadEnter => super::KeyCode::NumpadEnter,
VirtualKeyCode::NumpadEquals => super::KeyCode::NumpadEquals,
VirtualKeyCode::OEM102 => super::KeyCode::OEM102,
VirtualKeyCode::Period => super::KeyCode::Period,
VirtualKeyCode::PlayPause => super::KeyCode::PlayPause,
VirtualKeyCode::Power => super::KeyCode::Power,
VirtualKeyCode::PrevTrack => super::KeyCode::PrevTrack,
VirtualKeyCode::RAlt => super::KeyCode::RAlt,
VirtualKeyCode::RBracket => super::KeyCode::RBracket,
VirtualKeyCode::RControl => super::KeyCode::RControl,
VirtualKeyCode::RShift => super::KeyCode::RShift,
VirtualKeyCode::RWin => super::KeyCode::RWin,
VirtualKeyCode::Semicolon => super::KeyCode::Semicolon,
VirtualKeyCode::Slash => super::KeyCode::Slash,
VirtualKeyCode::Sleep => super::KeyCode::Sleep,
VirtualKeyCode::Stop => super::KeyCode::Stop,
VirtualKeyCode::Subtract => super::KeyCode::Subtract,
VirtualKeyCode::Sysrq => super::KeyCode::Sysrq,
VirtualKeyCode::Tab => super::KeyCode::Tab,
VirtualKeyCode::Underline => super::KeyCode::Underline,
VirtualKeyCode::Unlabeled => super::KeyCode::Unlabeled,
VirtualKeyCode::VolumeDown => super::KeyCode::VolumeDown,
VirtualKeyCode::VolumeUp => super::KeyCode::VolumeUp,
VirtualKeyCode::Wake => super::KeyCode::Wake,
VirtualKeyCode::WebBack => super::KeyCode::WebBack,
VirtualKeyCode::WebFavorites => super::KeyCode::WebFavorites,
VirtualKeyCode::WebForward => super::KeyCode::WebForward,
VirtualKeyCode::WebHome => super::KeyCode::WebHome,
VirtualKeyCode::WebRefresh => super::KeyCode::WebRefresh,
VirtualKeyCode::WebSearch => super::KeyCode::WebSearch,
VirtualKeyCode::WebStop => super::KeyCode::WebStop,
VirtualKeyCode::Yen => super::KeyCode::Yen,
VirtualKeyCode::Copy => super::KeyCode::Copy,
VirtualKeyCode::Paste => super::KeyCode::Paste,
VirtualKeyCode::Cut => super::KeyCode::Cut,
impl From<winit::event::VirtualKeyCode> for KeyCode {
fn from(virtual_keycode: winit::event::VirtualKeyCode) -> Self {
match virtual_keycode {
winit::event::VirtualKeyCode::Key1 => KeyCode::Key1,
winit::event::VirtualKeyCode::Key2 => KeyCode::Key2,
winit::event::VirtualKeyCode::Key3 => KeyCode::Key3,
winit::event::VirtualKeyCode::Key4 => KeyCode::Key4,
winit::event::VirtualKeyCode::Key5 => KeyCode::Key5,
winit::event::VirtualKeyCode::Key6 => KeyCode::Key6,
winit::event::VirtualKeyCode::Key7 => KeyCode::Key7,
winit::event::VirtualKeyCode::Key8 => KeyCode::Key8,
winit::event::VirtualKeyCode::Key9 => KeyCode::Key9,
winit::event::VirtualKeyCode::Key0 => KeyCode::Key0,
winit::event::VirtualKeyCode::A => KeyCode::A,
winit::event::VirtualKeyCode::B => KeyCode::B,
winit::event::VirtualKeyCode::C => KeyCode::C,
winit::event::VirtualKeyCode::D => KeyCode::D,
winit::event::VirtualKeyCode::E => KeyCode::E,
winit::event::VirtualKeyCode::F => KeyCode::F,
winit::event::VirtualKeyCode::G => KeyCode::G,
winit::event::VirtualKeyCode::H => KeyCode::H,
winit::event::VirtualKeyCode::I => KeyCode::I,
winit::event::VirtualKeyCode::J => KeyCode::J,
winit::event::VirtualKeyCode::K => KeyCode::K,
winit::event::VirtualKeyCode::L => KeyCode::L,
winit::event::VirtualKeyCode::M => KeyCode::M,
winit::event::VirtualKeyCode::N => KeyCode::N,
winit::event::VirtualKeyCode::O => KeyCode::O,
winit::event::VirtualKeyCode::P => KeyCode::P,
winit::event::VirtualKeyCode::Q => KeyCode::Q,
winit::event::VirtualKeyCode::R => KeyCode::R,
winit::event::VirtualKeyCode::S => KeyCode::S,
winit::event::VirtualKeyCode::T => KeyCode::T,
winit::event::VirtualKeyCode::U => KeyCode::U,
winit::event::VirtualKeyCode::V => KeyCode::V,
winit::event::VirtualKeyCode::W => KeyCode::W,
winit::event::VirtualKeyCode::X => KeyCode::X,
winit::event::VirtualKeyCode::Y => KeyCode::Y,
winit::event::VirtualKeyCode::Z => KeyCode::Z,
winit::event::VirtualKeyCode::Escape => KeyCode::Escape,
winit::event::VirtualKeyCode::F1 => KeyCode::F1,
winit::event::VirtualKeyCode::F2 => KeyCode::F2,
winit::event::VirtualKeyCode::F3 => KeyCode::F3,
winit::event::VirtualKeyCode::F4 => KeyCode::F4,
winit::event::VirtualKeyCode::F5 => KeyCode::F5,
winit::event::VirtualKeyCode::F6 => KeyCode::F6,
winit::event::VirtualKeyCode::F7 => KeyCode::F7,
winit::event::VirtualKeyCode::F8 => KeyCode::F8,
winit::event::VirtualKeyCode::F9 => KeyCode::F9,
winit::event::VirtualKeyCode::F10 => KeyCode::F10,
winit::event::VirtualKeyCode::F11 => KeyCode::F11,
winit::event::VirtualKeyCode::F12 => KeyCode::F12,
winit::event::VirtualKeyCode::F13 => KeyCode::F13,
winit::event::VirtualKeyCode::F14 => KeyCode::F14,
winit::event::VirtualKeyCode::F15 => KeyCode::F15,
winit::event::VirtualKeyCode::F16 => KeyCode::F16,
winit::event::VirtualKeyCode::F17 => KeyCode::F17,
winit::event::VirtualKeyCode::F18 => KeyCode::F18,
winit::event::VirtualKeyCode::F19 => KeyCode::F19,
winit::event::VirtualKeyCode::F20 => KeyCode::F20,
winit::event::VirtualKeyCode::F21 => KeyCode::F21,
winit::event::VirtualKeyCode::F22 => KeyCode::F22,
winit::event::VirtualKeyCode::F23 => KeyCode::F23,
winit::event::VirtualKeyCode::F24 => KeyCode::F24,
winit::event::VirtualKeyCode::Snapshot => KeyCode::Snapshot,
winit::event::VirtualKeyCode::Scroll => KeyCode::Scroll,
winit::event::VirtualKeyCode::Pause => KeyCode::Pause,
winit::event::VirtualKeyCode::Insert => KeyCode::Insert,
winit::event::VirtualKeyCode::Home => KeyCode::Home,
winit::event::VirtualKeyCode::Delete => KeyCode::Delete,
winit::event::VirtualKeyCode::End => KeyCode::End,
winit::event::VirtualKeyCode::PageDown => KeyCode::PageDown,
winit::event::VirtualKeyCode::PageUp => KeyCode::PageUp,
winit::event::VirtualKeyCode::Left => KeyCode::Left,
winit::event::VirtualKeyCode::Up => KeyCode::Up,
winit::event::VirtualKeyCode::Right => KeyCode::Right,
winit::event::VirtualKeyCode::Down => KeyCode::Down,
winit::event::VirtualKeyCode::Back => KeyCode::Backspace,
winit::event::VirtualKeyCode::Return => KeyCode::Enter,
winit::event::VirtualKeyCode::Space => KeyCode::Space,
winit::event::VirtualKeyCode::Compose => KeyCode::Compose,
winit::event::VirtualKeyCode::Caret => KeyCode::Caret,
winit::event::VirtualKeyCode::Numlock => KeyCode::Numlock,
winit::event::VirtualKeyCode::Numpad0 => KeyCode::Numpad0,
winit::event::VirtualKeyCode::Numpad1 => KeyCode::Numpad1,
winit::event::VirtualKeyCode::Numpad2 => KeyCode::Numpad2,
winit::event::VirtualKeyCode::Numpad3 => KeyCode::Numpad3,
winit::event::VirtualKeyCode::Numpad4 => KeyCode::Numpad4,
winit::event::VirtualKeyCode::Numpad5 => KeyCode::Numpad5,
winit::event::VirtualKeyCode::Numpad6 => KeyCode::Numpad6,
winit::event::VirtualKeyCode::Numpad7 => KeyCode::Numpad7,
winit::event::VirtualKeyCode::Numpad8 => KeyCode::Numpad8,
winit::event::VirtualKeyCode::Numpad9 => KeyCode::Numpad9,
winit::event::VirtualKeyCode::AbntC1 => KeyCode::AbntC1,
winit::event::VirtualKeyCode::AbntC2 => KeyCode::AbntC2,
winit::event::VirtualKeyCode::Add => KeyCode::Add,
winit::event::VirtualKeyCode::Apostrophe => KeyCode::Apostrophe,
winit::event::VirtualKeyCode::Apps => KeyCode::Apps,
winit::event::VirtualKeyCode::At => KeyCode::At,
winit::event::VirtualKeyCode::Ax => KeyCode::Ax,
winit::event::VirtualKeyCode::Backslash => KeyCode::Backslash,
winit::event::VirtualKeyCode::Calculator => KeyCode::Calculator,
winit::event::VirtualKeyCode::Capital => KeyCode::Capital,
winit::event::VirtualKeyCode::Colon => KeyCode::Colon,
winit::event::VirtualKeyCode::Comma => KeyCode::Comma,
winit::event::VirtualKeyCode::Convert => KeyCode::Convert,
winit::event::VirtualKeyCode::Decimal => KeyCode::Decimal,
winit::event::VirtualKeyCode::Divide => KeyCode::Divide,
winit::event::VirtualKeyCode::Equals => KeyCode::Equals,
winit::event::VirtualKeyCode::Grave => KeyCode::Grave,
winit::event::VirtualKeyCode::Kana => KeyCode::Kana,
winit::event::VirtualKeyCode::Kanji => KeyCode::Kanji,
winit::event::VirtualKeyCode::LAlt => KeyCode::LAlt,
winit::event::VirtualKeyCode::LBracket => KeyCode::LBracket,
winit::event::VirtualKeyCode::LControl => KeyCode::LControl,
winit::event::VirtualKeyCode::LShift => KeyCode::LShift,
winit::event::VirtualKeyCode::LWin => KeyCode::LWin,
winit::event::VirtualKeyCode::Mail => KeyCode::Mail,
winit::event::VirtualKeyCode::MediaSelect => KeyCode::MediaSelect,
winit::event::VirtualKeyCode::MediaStop => KeyCode::MediaStop,
winit::event::VirtualKeyCode::Minus => KeyCode::Minus,
winit::event::VirtualKeyCode::Multiply => KeyCode::Multiply,
winit::event::VirtualKeyCode::Mute => KeyCode::Mute,
winit::event::VirtualKeyCode::MyComputer => KeyCode::MyComputer,
winit::event::VirtualKeyCode::NavigateForward => {
KeyCode::NavigateForward
}
winit::event::VirtualKeyCode::NavigateBackward => {
KeyCode::NavigateBackward
}
winit::event::VirtualKeyCode::NextTrack => KeyCode::NextTrack,
winit::event::VirtualKeyCode::NoConvert => KeyCode::NoConvert,
winit::event::VirtualKeyCode::NumpadComma => KeyCode::NumpadComma,
winit::event::VirtualKeyCode::NumpadEnter => KeyCode::NumpadEnter,
winit::event::VirtualKeyCode::NumpadEquals => KeyCode::NumpadEquals,
winit::event::VirtualKeyCode::OEM102 => KeyCode::OEM102,
winit::event::VirtualKeyCode::Period => KeyCode::Period,
winit::event::VirtualKeyCode::PlayPause => KeyCode::PlayPause,
winit::event::VirtualKeyCode::Power => KeyCode::Power,
winit::event::VirtualKeyCode::PrevTrack => KeyCode::PrevTrack,
winit::event::VirtualKeyCode::RAlt => KeyCode::RAlt,
winit::event::VirtualKeyCode::RBracket => KeyCode::RBracket,
winit::event::VirtualKeyCode::RControl => KeyCode::RControl,
winit::event::VirtualKeyCode::RShift => KeyCode::RShift,
winit::event::VirtualKeyCode::RWin => KeyCode::RWin,
winit::event::VirtualKeyCode::Semicolon => KeyCode::Semicolon,
winit::event::VirtualKeyCode::Slash => KeyCode::Slash,
winit::event::VirtualKeyCode::Sleep => KeyCode::Sleep,
winit::event::VirtualKeyCode::Stop => KeyCode::Stop,
winit::event::VirtualKeyCode::Subtract => KeyCode::Subtract,
winit::event::VirtualKeyCode::Sysrq => KeyCode::Sysrq,
winit::event::VirtualKeyCode::Tab => KeyCode::Tab,
winit::event::VirtualKeyCode::Underline => KeyCode::Underline,
winit::event::VirtualKeyCode::Unlabeled => KeyCode::Unlabeled,
winit::event::VirtualKeyCode::VolumeDown => KeyCode::VolumeDown,
winit::event::VirtualKeyCode::VolumeUp => KeyCode::VolumeUp,
winit::event::VirtualKeyCode::Wake => KeyCode::Wake,
winit::event::VirtualKeyCode::WebBack => KeyCode::WebBack,
winit::event::VirtualKeyCode::WebFavorites => KeyCode::WebFavorites,
winit::event::VirtualKeyCode::WebForward => KeyCode::WebForward,
winit::event::VirtualKeyCode::WebHome => KeyCode::WebHome,
winit::event::VirtualKeyCode::WebRefresh => KeyCode::WebRefresh,
winit::event::VirtualKeyCode::WebSearch => KeyCode::WebSearch,
winit::event::VirtualKeyCode::WebStop => KeyCode::WebStop,
winit::event::VirtualKeyCode::Yen => KeyCode::Yen,
winit::event::VirtualKeyCode::Copy => KeyCode::Copy,
winit::event::VirtualKeyCode::Paste => KeyCode::Paste,
winit::event::VirtualKeyCode::Cut => KeyCode::Cut,
}
}
}

View File

@ -13,3 +13,15 @@ pub enum Button {
/// Some other button.
Other(u8),
}
#[cfg(feature = "winit")]
impl From<winit::event::MouseButton> for super::Button {
fn from(mouse_button: winit::event::MouseButton) -> Self {
match mouse_button {
winit::event::MouseButton::Left => Button::Left,
winit::event::MouseButton::Right => Button::Right,
winit::event::MouseButton::Middle => Button::Middle,
winit::event::MouseButton::Other(other) => Button::Other(other),
}
}
}