diff options
author | 2021-07-12 22:28:18 +0200 | |
---|---|---|
committer | 2021-07-12 22:28:18 +0200 | |
commit | 31997d255f263a0f47f5af0d8560f3d5bd37f077 (patch) | |
tree | 0413f22ec8052f0a1e310b12a4f5c4dedb883e81 /core | |
parent | b3ff522c182590ffcd03113b5147fa4599559059 (diff) | |
download | iced-31997d255f263a0f47f5af0d8560f3d5bd37f077.tar.gz iced-31997d255f263a0f47f5af0d8560f3d5bd37f077.tar.bz2 iced-31997d255f263a0f47f5af0d8560f3d5bd37f077.zip |
Store and synchronize `Menu` in `application::State`
Diffstat (limited to 'core')
-rw-r--r-- | core/src/menu.rs | 40 |
1 files changed, 36 insertions, 4 deletions
diff --git a/core/src/menu.rs b/core/src/menu.rs index fe770216..52186140 100644 --- a/core/src/menu.rs +++ b/core/src/menu.rs @@ -4,11 +4,17 @@ use crate::keyboard::Hotkey; /// Menu representation. /// /// This can be used by `shell` implementations to create a menu. -#[derive(Debug, Clone, PartialEq)] +#[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 { @@ -27,13 +33,13 @@ impl<Message> Menu<Message> { } /// Returns a [`MenuEntry`] iterator. - pub fn iter(self) -> impl Iterator<Item = Entry<Message>> { - self.entries.into_iter() + pub fn iter(&self) -> impl Iterator<Item = &Entry<Message>> { + self.entries.iter() } } /// Represents one of the possible entries used to build a [`Menu`]. -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone)] pub enum Entry<Message> { /// Item for a [`Menu`] Item { @@ -82,3 +88,29 @@ impl<Message> Entry<Message> { Entry::Dropdown { content, submenu } } } + +impl<Message> PartialEq for Entry<Message> { + fn eq(&self, other: &Self) -> bool { + match (self, other) { + ( + Entry::Item { + content, hotkey, .. + }, + Entry::Item { + content: other_content, + hotkey: other_hotkey, + .. + }, + ) => content == other_content && hotkey == other_hotkey, + ( + Entry::Dropdown { content, submenu }, + Entry::Dropdown { + content: other_content, + submenu: other_submenu, + }, + ) => content == other_content && submenu == other_submenu, + (Entry::Separator, Entry::Separator) => true, + _ => false, + } + } +} |