Merge pull request #1047 from iced-rs/revert-menus

Revert system menus support
This commit is contained in:
Héctor Ramón 2021-09-15 15:50:25 +07:00 committed by GitHub
commit 099981cfc2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 19 additions and 673 deletions

View file

@ -73,7 +73,6 @@ members = [
"examples/geometry",
"examples/integration_opengl",
"examples/integration_wgpu",
"examples/menu",
"examples/pane_grid",
"examples/pick_list",
"examples/pokedex",

View file

@ -1,10 +1,8 @@
//! Listen to keyboard events.
mod event;
mod hotkey;
mod key_code;
mod modifiers;
pub use event::Event;
pub use hotkey::Hotkey;
pub use key_code::KeyCode;
pub use modifiers::Modifiers;

View file

@ -1,18 +0,0 @@
use crate::keyboard::{KeyCode, Modifiers};
/// Representation of a hotkey, consists on the combination of a [`KeyCode`] and [`Modifiers`].
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Hotkey {
/// The key that represents this hotkey.
pub key: KeyCode,
/// The list of modifiers that represents this hotkey.
pub modifiers: Modifiers,
}
impl Hotkey {
/// Creates a new [`Hotkey`] with the given [`Modifiers`] and [`KeyCode`].
pub fn new(modifiers: Modifiers, key: KeyCode) -> Self {
Self { modifiers, key }
}
}

View file

@ -15,7 +15,6 @@
#![forbid(unsafe_code)]
#![forbid(rust_2018_idioms)]
pub mod keyboard;
pub mod menu;
pub mod mouse;
pub mod text;
@ -35,7 +34,6 @@ pub use background::Background;
pub use color::Color;
pub use font::Font;
pub use length::Length;
pub use menu::Menu;
pub use padding::Padding;
pub use point::Point;
pub use rectangle::Rectangle;

View file

@ -1,145 +0,0 @@
//! Build menus for your application.
use crate::keyboard::Hotkey;
/// Menu representation.
///
/// This can be used by `shell` implementations to create a menu.
#[derive(Debug, Clone)]
pub struct Menu<Message> {
entries: Vec<Entry<Message>>,
}
impl<Message> PartialEq for Menu<Message> {
fn eq(&self, other: &Self) -> bool {
self.entries == other.entries
}
}
impl<Message> Menu<Message> {
/// Creates an empty [`Menu`].
pub fn new() -> Self {
Self::with_entries(Vec::new())
}
/// Creates a new [`Menu`] with the given entries.
pub fn with_entries(entries: Vec<Entry<Message>>) -> Self {
Self { entries }
}
/// Returns a [`MenuEntry`] iterator.
pub fn iter(&self) -> impl Iterator<Item = &Entry<Message>> {
self.entries.iter()
}
/// Adds an [`Entry`] to the [`Menu`].
pub fn push(mut self, entry: Entry<Message>) -> Self {
self.entries.push(entry);
self
}
/// Maps the `Message` of the [`Menu`] using the provided function.
///
/// This is useful to compose menus and split them into different
/// abstraction levels.
pub fn map<B>(self, f: impl Fn(Message) -> B + Copy) -> Menu<B> {
// TODO: Use a boxed trait to avoid reallocation of entries
Menu {
entries: self
.entries
.into_iter()
.map(|entry| entry.map(f))
.collect(),
}
}
}
/// Represents one of the possible entries used to build a [`Menu`].
#[derive(Debug, Clone)]
pub enum Entry<Message> {
/// Item for a [`Menu`]
Item {
/// The title of the item
title: String,
/// The [`Hotkey`] to activate the item, if any
hotkey: Option<Hotkey>,
/// The message generated when the item is activated
on_activation: Message,
},
/// Dropdown for a [`Menu`]
Dropdown {
/// Title of the dropdown
title: String,
/// The submenu of the dropdown
submenu: Menu<Message>,
},
/// Separator for a [`Menu`]
Separator,
}
impl<Message> Entry<Message> {
/// Creates an [`Entry::Item`].
pub fn item<S: Into<String>>(
title: S,
hotkey: impl Into<Option<Hotkey>>,
on_activation: Message,
) -> Self {
let title = title.into();
let hotkey = hotkey.into();
Self::Item {
title,
hotkey,
on_activation,
}
}
/// Creates an [`Entry::Dropdown`].
pub fn dropdown<S: Into<String>>(title: S, submenu: Menu<Message>) -> Self {
let title = title.into();
Self::Dropdown { title, submenu }
}
fn map<B>(self, f: impl Fn(Message) -> B + Copy) -> Entry<B> {
match self {
Self::Item {
title,
hotkey,
on_activation,
} => Entry::Item {
title,
hotkey,
on_activation: f(on_activation),
},
Self::Dropdown { title, submenu } => Entry::Dropdown {
title,
submenu: submenu.map(f),
},
Self::Separator => Entry::Separator,
}
}
}
impl<Message> PartialEq for Entry<Message> {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(
Entry::Item { title, hotkey, .. },
Entry::Item {
title: other_title,
hotkey: other_hotkey,
..
},
) => title == other_title && hotkey == other_hotkey,
(
Entry::Dropdown { title, submenu },
Entry::Dropdown {
title: other_title,
submenu: other_submenu,
},
) => title == other_title && submenu == other_submenu,
(Entry::Separator, Entry::Separator) => true,
_ => false,
}
}
}

View file

@ -6,7 +6,6 @@ mod style;
use grid::Grid;
use iced::button::{self, Button};
use iced::executor;
use iced::menu::{self, Menu};
use iced::pick_list::{self, PickList};
use iced::slider::{self, Slider};
use iced::time;
@ -130,13 +129,6 @@ impl Application for GameOfLife {
}
}
fn menu(&self) -> Menu<Message> {
Menu::with_entries(vec![menu::Entry::dropdown(
"Presets",
Preset::menu().map(Message::PresetPicked),
)])
}
fn view(&mut self) -> Element<Message> {
let version = self.version;
let selected_speed = self.next_speed.unwrap_or(self.speed);

View file

@ -1,5 +1,3 @@
use iced::menu::{self, Menu};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Preset {
Custom,
@ -28,17 +26,6 @@ pub static ALL: &[Preset] = &[
];
impl Preset {
pub fn menu() -> Menu<Self> {
Menu::with_entries(
ALL.iter()
.copied()
.map(|preset| {
menu::Entry::item(preset.to_string(), None, preset)
})
.collect(),
)
}
pub fn life(self) -> Vec<(isize, isize)> {
#[rustfmt::skip]
let cells = match self {

View file

@ -1,10 +0,0 @@
[package]
name = "menu"
version = "0.1.0"
authors = ["Héctor Ramón Jiménez <hector0193@gmail.com>"]
edition = "2018"
publish = false
[dependencies]
iced = { path = "../.." }
iced_native = { path = "../../native" }

View file

@ -1,112 +0,0 @@
use iced::menu::{self, Menu};
use iced::{
executor, Application, Command, Container, Element, Length, Settings, Text,
};
use iced_native::keyboard::{Hotkey, KeyCode, Modifiers};
pub fn main() -> iced::Result {
App::run(Settings::default())
}
#[derive(Debug, Default)]
struct App {
selected: Option<Entry>,
}
#[derive(Debug, Clone)]
enum Entry {
One,
Two,
Three,
A,
B,
C,
}
#[derive(Debug, Clone)]
enum Message {
MenuActivated(Entry),
}
impl Application for App {
type Executor = executor::Default;
type Message = Message;
type Flags = ();
fn new(_flags: ()) -> (App, Command<Message>) {
(App::default(), Command::none())
}
fn title(&self) -> String {
String::from("Menu - Iced")
}
fn menu(&self) -> Menu<Message> {
let alt = Modifiers::ALT;
let ctrl_shift = Modifiers::CTRL | Modifiers::SHIFT;
Menu::with_entries(vec![
menu::Entry::dropdown(
"First",
Menu::with_entries(vec![
menu::Entry::item(
"One",
Hotkey::new(alt, KeyCode::F1),
Message::MenuActivated(Entry::One),
),
menu::Entry::item(
"Two",
Hotkey::new(alt, KeyCode::F2),
Message::MenuActivated(Entry::Two),
),
menu::Entry::Separator,
menu::Entry::item(
"Three",
Hotkey::new(alt, KeyCode::F3),
Message::MenuActivated(Entry::Three),
),
]),
),
menu::Entry::dropdown(
"Second",
Menu::with_entries(vec![
menu::Entry::item(
"A",
Hotkey::new(ctrl_shift, KeyCode::A),
Message::MenuActivated(Entry::A),
),
menu::Entry::item(
"B",
Hotkey::new(ctrl_shift, KeyCode::B),
Message::MenuActivated(Entry::B),
),
menu::Entry::Separator,
menu::Entry::item(
"C",
Hotkey::new(ctrl_shift, KeyCode::C),
Message::MenuActivated(Entry::C),
),
]),
),
])
}
fn update(&mut self, message: Message) -> Command<Message> {
match message {
Message::MenuActivated(entry) => self.selected = Some(entry),
}
Command::none()
}
fn view(&mut self) -> Element<Message> {
Container::new(
Text::new(format!("Selected {:?}", self.selected)).size(48),
)
.width(Length::Fill)
.height(Length::Fill)
.center_x()
.center_y()
.into()
}
}

View file

@ -16,7 +16,7 @@ debug = ["iced_winit/debug"]
[dependencies.glutin]
version = "0.27"
git = "https://github.com/iced-rs/glutin"
rev = "849352f1cb7021b7514a3104daf3e6236c915dac"
rev = "2564d0ab87cf2ad824a2a58733aebe40dd2f29bb"
[dependencies.iced_native]
version = "0.4"

View file

@ -51,15 +51,12 @@ where
let subscription = application.subscription();
let context = {
let builder = settings
.window
.into_builder(
&application.title(),
application.mode(),
event_loop.primary_monitor(),
settings.id,
)
.with_menu(Some(conversion::menu(&application.menu())));
let builder = settings.window.into_builder(
&application.title(),
application.mode(),
event_loop.primary_monitor(),
settings.id,
);
let context = ContextBuilder::new()
.with_vsync(true)
@ -331,16 +328,6 @@ async fn run_instance<A, E, C>(
// TODO: Handle animations!
// Maybe we can use `ControlFlow::WaitUntil` for this.
}
event::Event::WindowEvent {
event: event::WindowEvent::MenuEntryActivated(entry_id),
..
} => {
if let Some(message) =
conversion::menu_message(state.menu(), entry_id)
{
messages.push(message);
}
}
event::Event::WindowEvent {
event: window_event,
..

View file

@ -62,8 +62,8 @@ mod debug;
mod debug;
pub use iced_core::{
menu, Align, Background, Color, Font, HorizontalAlignment, Length, Menu,
Padding, Point, Rectangle, Size, Vector, VerticalAlignment,
Align, Background, Color, Font, HorizontalAlignment, Length, Padding,
Point, Rectangle, Size, Vector, VerticalAlignment,
};
pub use iced_futures::{executor, futures};

View file

@ -11,7 +11,7 @@ pub trait Program: Sized {
type Renderer: Renderer;
/// The type of __messages__ your [`Program`] will produce.
type Message: std::fmt::Debug + Clone + Send;
type Message: std::fmt::Debug + Send;
/// Handles a __message__ and updates the state of the [`Program`].
///

View file

@ -1,5 +1,5 @@
use crate::window;
use crate::{Color, Command, Element, Executor, Menu, Settings, Subscription};
use crate::{Color, Command, Element, Executor, Settings, Subscription};
/// An interactive cross-platform application.
///
@ -97,7 +97,7 @@ pub trait Application: Sized {
type Executor: Executor;
/// The type of __messages__ your [`Application`] will produce.
type Message: std::fmt::Debug + Clone + Send;
type Message: std::fmt::Debug + Send;
/// The data needed to initialize your [`Application`].
type Flags;
@ -185,13 +185,6 @@ pub trait Application: Sized {
false
}
/// Returns the current system [`Menu`] of the [`Application`].
///
/// By default, it returns an empty [`Menu`].
fn menu(&self) -> Menu<Self::Message> {
Menu::new()
}
/// Runs the [`Application`].
///
/// On native platforms, this method will take control of the current thread
@ -293,10 +286,6 @@ where
fn should_exit(&self) -> bool {
self.0.should_exit()
}
fn menu(&self) -> Menu<Self::Message> {
self.0.menu()
}
}
#[cfg(target_arch = "wasm32")]

View file

@ -246,7 +246,6 @@ pub use sandbox::Sandbox;
pub use settings::Settings;
pub use runtime::{
futures, menu, Align, Background, Color, Command, Font,
HorizontalAlignment, Length, Menu, Point, Rectangle, Size, Subscription,
Vector, VerticalAlignment,
futures, Align, Background, Color, Command, Font, HorizontalAlignment,
Length, Point, Rectangle, Size, Subscription, Vector, VerticalAlignment,
};

View file

@ -87,7 +87,7 @@ use crate::{
/// ```
pub trait Sandbox {
/// The type of __messages__ your [`Sandbox`] will produce.
type Message: std::fmt::Debug + Clone + Send;
type Message: std::fmt::Debug + Send;
/// Initializes the [`Sandbox`].
///

View file

@ -74,8 +74,8 @@ pub use dodrio;
pub use element::Element;
pub use hasher::Hasher;
pub use iced_core::{
keyboard, menu, mouse, Align, Background, Color, Font, HorizontalAlignment,
Length, Menu, Padding, Point, Rectangle, Size, Vector, VerticalAlignment,
keyboard, mouse, Align, Background, Color, Font, HorizontalAlignment,
Length, Padding, Point, Rectangle, Size, Vector, VerticalAlignment,
};
pub use iced_futures::{executor, futures};
pub use subscription::Subscription;

View file

@ -21,7 +21,7 @@ thiserror = "1.0"
[dependencies.winit]
version = "0.25"
git = "https://github.com/iced-rs/winit"
rev = "24a75a7bdc10d2dc2f520c36284618e9ae6c2568"
rev = "44a9a6fc442fcfa3fa0dfc2d5a2f86fdf4aba10c"
[dependencies.iced_native]
version = "0.4"

View file

@ -15,7 +15,6 @@ use iced_futures::futures;
use iced_futures::futures::channel::mpsc;
use iced_graphics::window;
use iced_native::program::Program;
use iced_native::Menu;
use iced_native::{Cache, UserInterface};
use std::mem::ManuallyDrop;
@ -100,13 +99,6 @@ pub trait Application: Program {
fn should_exit(&self) -> bool {
false
}
/// Returns the current system [`Menu`] of the [`Application`].
///
/// By default, it returns an empty [`Menu`].
fn menu(&self) -> Menu<Self::Message> {
Menu::new()
}
}
/// Runs an [`Application`] with an executor, compositor, and the provided
@ -153,7 +145,6 @@ where
event_loop.primary_monitor(),
settings.id,
)
.with_menu(Some(conversion::menu(&application.menu())))
.build(&event_loop)
.map_err(Error::WindowCreationFailed)?;
@ -419,16 +410,6 @@ async fn run_instance<A, E, C>(
},
}
}
event::Event::WindowEvent {
event: event::WindowEvent::MenuEntryActivated(entry_id),
..
} => {
if let Some(message) =
conversion::menu_message(state.menu(), entry_id)
{
messages.push(message);
}
}
event::Event::WindowEvent {
event: window_event,
..

View file

@ -1,5 +1,5 @@
use crate::conversion;
use crate::{Application, Color, Debug, Menu, Mode, Point, Size, Viewport};
use crate::{Application, Color, Debug, Mode, Point, Size, Viewport};
use std::marker::PhantomData;
use winit::event::{Touch, WindowEvent};
@ -9,7 +9,6 @@ use winit::window::Window;
#[derive(Debug, Clone)]
pub struct State<A: Application> {
title: String,
menu: Menu<A::Message>,
mode: Mode,
background_color: Color,
scale_factor: f64,
@ -24,7 +23,6 @@ impl<A: Application> State<A> {
/// Creates a new [`State`] for the provided [`Application`] and window.
pub fn new(application: &A, window: &Window) -> Self {
let title = application.title();
let menu = application.menu();
let mode = application.mode();
let background_color = application.background_color();
let scale_factor = application.scale_factor();
@ -40,7 +38,6 @@ impl<A: Application> State<A> {
Self {
title,
menu,
mode,
background_color,
scale_factor,
@ -53,11 +50,6 @@ impl<A: Application> State<A> {
}
}
/// Returns the current [`Menu`] of the [`State`].
pub fn menu(&self) -> &Menu<A::Message> {
&self.menu
}
/// Returns the current background [`Color`] of the [`State`].
pub fn background_color(&self) -> Color {
self.background_color
@ -211,14 +203,5 @@ impl<A: Application> State<A> {
self.scale_factor = new_scale_factor;
}
// Update menu
let new_menu = application.menu();
if self.menu != new_menu {
window.set_menu(Some(conversion::menu(&new_menu)));
self.menu = new_menu;
}
}
}

View file

@ -3,7 +3,6 @@
//! [`winit`]: https://github.com/rust-windowing/winit
//! [`iced_native`]: https://github.com/hecrj/iced/tree/master/native
use crate::keyboard;
use crate::menu::{self, Menu};
use crate::mouse;
use crate::touch;
use crate::window;
@ -206,110 +205,6 @@ pub fn visible(mode: Mode) -> bool {
}
}
/// Converts a `Hotkey` from [`iced_native`] to a [`winit`] Hotkey.
///
/// [`winit`]: https://github.com/rust-windowing/winit
/// [`iced_native`]: https://github.com/hecrj/iced/tree/master/native
fn hotkey(hotkey: keyboard::Hotkey) -> winit::window::Hotkey {
use winit::event::ModifiersState;
let mut modifiers = ModifiersState::empty();
modifiers.set(ModifiersState::CTRL, hotkey.modifiers.control());
modifiers.set(ModifiersState::SHIFT, hotkey.modifiers.shift());
modifiers.set(ModifiersState::ALT, hotkey.modifiers.alt());
modifiers.set(ModifiersState::LOGO, hotkey.modifiers.logo());
winit::window::Hotkey::new(modifiers, to_virtual_keycode(hotkey.key))
}
/// Converts a `Menu` from [`iced_native`] to a [`winit`] menu.
///
/// [`winit`]: https://github.com/rust-windowing/winit
/// [`iced_native`]: https://github.com/hecrj/iced/tree/master/native
pub fn menu<Message>(menu: &Menu<Message>) -> winit::window::Menu {
fn menu_i<Message>(
converted: &mut winit::window::Menu,
starting_id: u16,
menu: &Menu<Message>,
) -> u16 {
let mut id = starting_id;
for item in menu.iter() {
match item {
menu::Entry::Item { title, hotkey, .. } => {
converted.add_item(id, title, hotkey.map(self::hotkey));
id += 1;
}
menu::Entry::Dropdown { title, submenu } => {
let mut converted_submenu = winit::window::Menu::new();
let n_children =
menu_i(&mut converted_submenu, id, submenu);
converted.add_dropdown(title, converted_submenu);
id += n_children;
}
menu::Entry::Separator => {
converted.add_separator();
}
}
}
id - starting_id
}
let mut converted = winit::window::Menu::default();
let _ = menu_i(&mut converted, 0, menu);
converted
}
/// Given a [`Menu`] and an identifier of a [`menu::Entry`], it returns the
/// `Message` that should be produced when that entry is activated.
pub fn menu_message<Message>(menu: &Menu<Message>, id: u16) -> Option<Message>
where
Message: Clone,
{
fn find_message<Message>(
target: u16,
starting_id: u16,
menu: &Menu<Message>,
) -> Result<Message, u16>
where
Message: Clone,
{
let mut id = starting_id;
for entry in menu.iter() {
match entry {
menu::Entry::Item { on_activation, .. } => {
if id == target {
return Ok(on_activation.clone());
}
id += 1;
}
menu::Entry::Dropdown { submenu, .. } => {
match find_message(target, id, submenu) {
Ok(message) => {
return Ok(message);
}
Err(n_children) => {
id += n_children;
}
}
}
menu::Entry::Separator => {}
}
}
Err(id - starting_id)
}
find_message(id, 0, menu).ok()
}
/// Converts a `MouseCursor` from [`iced_native`] to a [`winit`] cursor icon.
///
/// [`winit`]: https://github.com/rust-windowing/winit
@ -408,183 +303,6 @@ pub fn touch_event(
}
}
/// Converts a `KeyCode` from [`iced_native`] to an [`winit`] key code.
///
/// [`winit`]: https://github.com/rust-windowing/winit
/// [`iced_native`]: https://github.com/hecrj/iced/tree/master/native
fn to_virtual_keycode(
keycode: keyboard::KeyCode,
) -> winit::event::VirtualKeyCode {
use keyboard::KeyCode;
use winit::event::VirtualKeyCode;
match keycode {
KeyCode::Key1 => VirtualKeyCode::Key1,
KeyCode::Key2 => VirtualKeyCode::Key2,
KeyCode::Key3 => VirtualKeyCode::Key3,
KeyCode::Key4 => VirtualKeyCode::Key4,
KeyCode::Key5 => VirtualKeyCode::Key5,
KeyCode::Key6 => VirtualKeyCode::Key6,
KeyCode::Key7 => VirtualKeyCode::Key7,
KeyCode::Key8 => VirtualKeyCode::Key8,
KeyCode::Key9 => VirtualKeyCode::Key9,
KeyCode::Key0 => VirtualKeyCode::Key0,
KeyCode::A => VirtualKeyCode::A,
KeyCode::B => VirtualKeyCode::B,
KeyCode::C => VirtualKeyCode::C,
KeyCode::D => VirtualKeyCode::D,
KeyCode::E => VirtualKeyCode::E,
KeyCode::F => VirtualKeyCode::F,
KeyCode::G => VirtualKeyCode::G,
KeyCode::H => VirtualKeyCode::H,
KeyCode::I => VirtualKeyCode::I,
KeyCode::J => VirtualKeyCode::J,
KeyCode::K => VirtualKeyCode::K,
KeyCode::L => VirtualKeyCode::L,
KeyCode::M => VirtualKeyCode::M,
KeyCode::N => VirtualKeyCode::N,
KeyCode::O => VirtualKeyCode::O,
KeyCode::P => VirtualKeyCode::P,
KeyCode::Q => VirtualKeyCode::Q,
KeyCode::R => VirtualKeyCode::R,
KeyCode::S => VirtualKeyCode::S,
KeyCode::T => VirtualKeyCode::T,
KeyCode::U => VirtualKeyCode::U,
KeyCode::V => VirtualKeyCode::V,
KeyCode::W => VirtualKeyCode::W,
KeyCode::X => VirtualKeyCode::X,
KeyCode::Y => VirtualKeyCode::Y,
KeyCode::Z => VirtualKeyCode::Z,
KeyCode::Escape => VirtualKeyCode::Escape,
KeyCode::F1 => VirtualKeyCode::F1,
KeyCode::F2 => VirtualKeyCode::F2,
KeyCode::F3 => VirtualKeyCode::F3,
KeyCode::F4 => VirtualKeyCode::F4,
KeyCode::F5 => VirtualKeyCode::F5,
KeyCode::F6 => VirtualKeyCode::F6,
KeyCode::F7 => VirtualKeyCode::F7,
KeyCode::F8 => VirtualKeyCode::F8,
KeyCode::F9 => VirtualKeyCode::F9,
KeyCode::F10 => VirtualKeyCode::F10,
KeyCode::F11 => VirtualKeyCode::F11,
KeyCode::F12 => VirtualKeyCode::F12,
KeyCode::F13 => VirtualKeyCode::F13,
KeyCode::F14 => VirtualKeyCode::F14,
KeyCode::F15 => VirtualKeyCode::F15,
KeyCode::F16 => VirtualKeyCode::F16,
KeyCode::F17 => VirtualKeyCode::F17,
KeyCode::F18 => VirtualKeyCode::F18,
KeyCode::F19 => VirtualKeyCode::F19,
KeyCode::F20 => VirtualKeyCode::F20,
KeyCode::F21 => VirtualKeyCode::F21,
KeyCode::F22 => VirtualKeyCode::F22,
KeyCode::F23 => VirtualKeyCode::F23,
KeyCode::F24 => VirtualKeyCode::F24,
KeyCode::Snapshot => VirtualKeyCode::Snapshot,
KeyCode::Scroll => VirtualKeyCode::Scroll,
KeyCode::Pause => VirtualKeyCode::Pause,
KeyCode::Insert => VirtualKeyCode::Insert,
KeyCode::Home => VirtualKeyCode::Home,
KeyCode::Delete => VirtualKeyCode::Delete,
KeyCode::End => VirtualKeyCode::End,
KeyCode::PageDown => VirtualKeyCode::PageDown,
KeyCode::PageUp => VirtualKeyCode::PageUp,
KeyCode::Left => VirtualKeyCode::Left,
KeyCode::Up => VirtualKeyCode::Up,
KeyCode::Right => VirtualKeyCode::Right,
KeyCode::Down => VirtualKeyCode::Down,
KeyCode::Backspace => VirtualKeyCode::Back,
KeyCode::Enter => VirtualKeyCode::Return,
KeyCode::Space => VirtualKeyCode::Space,
KeyCode::Compose => VirtualKeyCode::Compose,
KeyCode::Caret => VirtualKeyCode::Caret,
KeyCode::Numlock => VirtualKeyCode::Numlock,
KeyCode::Numpad0 => VirtualKeyCode::Numpad0,
KeyCode::Numpad1 => VirtualKeyCode::Numpad1,
KeyCode::Numpad2 => VirtualKeyCode::Numpad2,
KeyCode::Numpad3 => VirtualKeyCode::Numpad3,
KeyCode::Numpad4 => VirtualKeyCode::Numpad4,
KeyCode::Numpad5 => VirtualKeyCode::Numpad5,
KeyCode::Numpad6 => VirtualKeyCode::Numpad6,
KeyCode::Numpad7 => VirtualKeyCode::Numpad7,
KeyCode::Numpad8 => VirtualKeyCode::Numpad8,
KeyCode::Numpad9 => VirtualKeyCode::Numpad9,
KeyCode::AbntC1 => VirtualKeyCode::AbntC1,
KeyCode::AbntC2 => VirtualKeyCode::AbntC2,
KeyCode::NumpadAdd => VirtualKeyCode::NumpadAdd,
KeyCode::Plus => VirtualKeyCode::Plus,
KeyCode::Apostrophe => VirtualKeyCode::Apostrophe,
KeyCode::Apps => VirtualKeyCode::Apps,
KeyCode::At => VirtualKeyCode::At,
KeyCode::Ax => VirtualKeyCode::Ax,
KeyCode::Backslash => VirtualKeyCode::Backslash,
KeyCode::Calculator => VirtualKeyCode::Calculator,
KeyCode::Capital => VirtualKeyCode::Capital,
KeyCode::Colon => VirtualKeyCode::Colon,
KeyCode::Comma => VirtualKeyCode::Comma,
KeyCode::Convert => VirtualKeyCode::Convert,
KeyCode::NumpadDecimal => VirtualKeyCode::NumpadDecimal,
KeyCode::NumpadDivide => VirtualKeyCode::NumpadDivide,
KeyCode::Equals => VirtualKeyCode::Equals,
KeyCode::Grave => VirtualKeyCode::Grave,
KeyCode::Kana => VirtualKeyCode::Kana,
KeyCode::Kanji => VirtualKeyCode::Kanji,
KeyCode::LAlt => VirtualKeyCode::LAlt,
KeyCode::LBracket => VirtualKeyCode::LBracket,
KeyCode::LControl => VirtualKeyCode::LControl,
KeyCode::LShift => VirtualKeyCode::LShift,
KeyCode::LWin => VirtualKeyCode::LWin,
KeyCode::Mail => VirtualKeyCode::Mail,
KeyCode::MediaSelect => VirtualKeyCode::MediaSelect,
KeyCode::MediaStop => VirtualKeyCode::MediaStop,
KeyCode::Minus => VirtualKeyCode::Minus,
KeyCode::NumpadMultiply => VirtualKeyCode::NumpadMultiply,
KeyCode::Mute => VirtualKeyCode::Mute,
KeyCode::MyComputer => VirtualKeyCode::MyComputer,
KeyCode::NavigateForward => VirtualKeyCode::NavigateForward,
KeyCode::NavigateBackward => VirtualKeyCode::NavigateBackward,
KeyCode::NextTrack => VirtualKeyCode::NextTrack,
KeyCode::NoConvert => VirtualKeyCode::NoConvert,
KeyCode::NumpadComma => VirtualKeyCode::NumpadComma,
KeyCode::NumpadEnter => VirtualKeyCode::NumpadEnter,
KeyCode::NumpadEquals => VirtualKeyCode::NumpadEquals,
KeyCode::OEM102 => VirtualKeyCode::OEM102,
KeyCode::Period => VirtualKeyCode::Period,
KeyCode::PlayPause => VirtualKeyCode::PlayPause,
KeyCode::Power => VirtualKeyCode::Power,
KeyCode::PrevTrack => VirtualKeyCode::PrevTrack,
KeyCode::RAlt => VirtualKeyCode::RAlt,
KeyCode::RBracket => VirtualKeyCode::RBracket,
KeyCode::RControl => VirtualKeyCode::RControl,
KeyCode::RShift => VirtualKeyCode::RShift,
KeyCode::RWin => VirtualKeyCode::RWin,
KeyCode::Semicolon => VirtualKeyCode::Semicolon,
KeyCode::Slash => VirtualKeyCode::Slash,
KeyCode::Sleep => VirtualKeyCode::Sleep,
KeyCode::Stop => VirtualKeyCode::Stop,
KeyCode::NumpadSubtract => VirtualKeyCode::NumpadSubtract,
KeyCode::Sysrq => VirtualKeyCode::Sysrq,
KeyCode::Tab => VirtualKeyCode::Tab,
KeyCode::Underline => VirtualKeyCode::Underline,
KeyCode::Unlabeled => VirtualKeyCode::Unlabeled,
KeyCode::VolumeDown => VirtualKeyCode::VolumeDown,
KeyCode::VolumeUp => VirtualKeyCode::VolumeUp,
KeyCode::Wake => VirtualKeyCode::Wake,
KeyCode::WebBack => VirtualKeyCode::WebBack,
KeyCode::WebFavorites => VirtualKeyCode::WebFavorites,
KeyCode::WebForward => VirtualKeyCode::WebForward,
KeyCode::WebHome => VirtualKeyCode::WebHome,
KeyCode::WebRefresh => VirtualKeyCode::WebRefresh,
KeyCode::WebSearch => VirtualKeyCode::WebSearch,
KeyCode::WebStop => VirtualKeyCode::WebStop,
KeyCode::Yen => VirtualKeyCode::Yen,
KeyCode::Copy => VirtualKeyCode::Copy,
KeyCode::Paste => VirtualKeyCode::Paste,
KeyCode::Cut => VirtualKeyCode::Cut,
KeyCode::Asterisk => VirtualKeyCode::Asterisk,
}
}
/// Converts a `VirtualKeyCode` from [`winit`] to an [`iced_native`] key code.
///
/// [`winit`]: https://github.com/rust-windowing/winit