From c0ab9888426b7d1f2606afafc9dba06eed7f9419 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 15 Sep 2021 15:31:40 +0700 Subject: Revert system menus support The current implementation has some important issues on Windows. We will reintroduce the feature once we figure them out! I have kept some of the changes in #945, like the new `keyboard::Modifiers` powered by `bitflags`. --- core/src/keyboard.rs | 2 - core/src/keyboard/hotkey.rs | 18 ------ core/src/lib.rs | 2 - core/src/menu.rs | 145 -------------------------------------------- 4 files changed, 167 deletions(-) delete mode 100644 core/src/keyboard/hotkey.rs delete mode 100644 core/src/menu.rs (limited to 'core') diff --git a/core/src/keyboard.rs b/core/src/keyboard.rs index 6827a4db..4c6ca08d 100644 --- a/core/src/keyboard.rs +++ b/core/src/keyboard.rs @@ -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; diff --git a/core/src/keyboard/hotkey.rs b/core/src/keyboard/hotkey.rs deleted file mode 100644 index 310ef286..00000000 --- a/core/src/keyboard/hotkey.rs +++ /dev/null @@ -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 } - } -} diff --git a/core/src/lib.rs b/core/src/lib.rs index a0decdab..e937264d 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -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; diff --git a/core/src/menu.rs b/core/src/menu.rs deleted file mode 100644 index 8a679085..00000000 --- a/core/src/menu.rs +++ /dev/null @@ -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 { - entries: Vec>, -} - -impl PartialEq for Menu { - fn eq(&self, other: &Self) -> bool { - self.entries == other.entries - } -} - -impl Menu { - /// 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>) -> Self { - Self { entries } - } - - /// Returns a [`MenuEntry`] iterator. - pub fn iter(&self) -> impl Iterator> { - self.entries.iter() - } - - /// Adds an [`Entry`] to the [`Menu`]. - pub fn push(mut self, entry: Entry) -> 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(self, f: impl Fn(Message) -> B + Copy) -> Menu { - // 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 { - /// Item for a [`Menu`] - Item { - /// The title of the item - title: String, - /// The [`Hotkey`] to activate the item, if any - hotkey: Option, - /// 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, - }, - /// Separator for a [`Menu`] - Separator, -} - -impl Entry { - /// Creates an [`Entry::Item`]. - pub fn item>( - title: S, - hotkey: impl Into>, - 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>(title: S, submenu: Menu) -> Self { - let title = title.into(); - - Self::Dropdown { title, submenu } - } - - fn map(self, f: impl Fn(Message) -> B + Copy) -> Entry { - 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 PartialEq for Entry { - 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, - } - } -} -- cgit