From 735cfb790813c44852612400e31c0190b9c641a6 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Mon, 12 Jul 2021 21:44:01 +0200 Subject: Move `menu` module from `iced_native` to `iced_core` --- native/src/lib.rs | 6 ++-- native/src/menu.rs | 84 ------------------------------------------------------ 2 files changed, 2 insertions(+), 88 deletions(-) delete mode 100644 native/src/menu.rs (limited to 'native') diff --git a/native/src/lib.rs b/native/src/lib.rs index 564f2514..cbb02506 100644 --- a/native/src/lib.rs +++ b/native/src/lib.rs @@ -37,7 +37,6 @@ pub mod clipboard; pub mod event; pub mod keyboard; pub mod layout; -pub mod menu; pub mod mouse; pub mod overlay; pub mod program; @@ -62,8 +61,8 @@ mod debug; mod debug; pub use iced_core::{ - Align, Background, Color, Font, HorizontalAlignment, Length, Padding, - Point, Rectangle, Size, Vector, VerticalAlignment, + menu, Align, Background, Color, Font, HorizontalAlignment, Length, Menu, + Padding, Point, Rectangle, Size, Vector, VerticalAlignment, }; pub use iced_futures::{executor, futures, Command}; @@ -76,7 +75,6 @@ pub use element::Element; pub use event::Event; pub use hasher::Hasher; pub use layout::Layout; -pub use menu::Menu; pub use overlay::Overlay; pub use program::Program; pub use renderer::Renderer; diff --git a/native/src/menu.rs b/native/src/menu.rs deleted file mode 100644 index fe770216..00000000 --- a/native/src/menu.rs +++ /dev/null @@ -1,84 +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, PartialEq)] -pub struct Menu { - entries: Vec>, -} - -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 } - } - - /// Adds an [`Entry`] to the [`Menu`]. - pub fn push(mut self, entry: Entry) -> Self { - self.entries.push(entry); - self - } - - /// Returns a [`MenuEntry`] iterator. - pub fn iter(self) -> impl Iterator> { - self.entries.into_iter() - } -} - -/// Represents one of the possible entries used to build a [`Menu`]. -#[derive(Debug, Clone, PartialEq)] -pub enum Entry { - /// Item for a [`Menu`] - Item { - /// The title of the item - content: 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 - content: String, - /// The submenu of the dropdown - submenu: Menu, - }, - /// Separator for a [`Menu`] - Separator, -} - -impl Entry { - /// Creates an [`Entry::Item`]. - pub fn item>( - content: S, - hotkey: impl Into>, - on_activation: Message, - ) -> Self { - let content = content.into(); - let hotkey = hotkey.into(); - - Entry::Item { - content, - hotkey, - on_activation, - } - } - - /// Creates an [`Entry::Dropdown`]. - pub fn dropdown>( - content: S, - submenu: Menu, - ) -> Self { - let content = content.into(); - - Entry::Dropdown { content, submenu } - } -} -- cgit