From 31997d255f263a0f47f5af0d8560f3d5bd37f077 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Mon, 12 Jul 2021 22:28:18 +0200 Subject: Store and synchronize `Menu` in `application::State` --- core/src/menu.rs | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) (limited to 'core') 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 { 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 { @@ -27,13 +33,13 @@ impl Menu { } /// Returns a [`MenuEntry`] iterator. - pub fn iter(self) -> impl Iterator> { - self.entries.into_iter() + pub fn iter(&self) -> impl Iterator> { + self.entries.iter() } } /// Represents one of the possible entries used to build a [`Menu`]. -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone)] pub enum Entry { /// Item for a [`Menu`] Item { @@ -82,3 +88,29 @@ impl Entry { Entry::Dropdown { content, submenu } } } + +impl PartialEq for Entry { + 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, + } + } +} -- cgit