feat: add MenuItemKind::id (#113)

This commit is contained in:
Amr Bashir 2023-08-31 18:13:41 +03:00 committed by GitHub
parent 9c4d6bb14e
commit bce7540bba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 0 deletions

View file

@ -0,0 +1,5 @@
---
"muda": "patch"
---
Add `MenuItemKind::id` convenient method to get access to the inner kind id.

View file

@ -166,6 +166,17 @@ pub enum MenuItemKind {
}
impl MenuItemKind {
/// Returns the id associated with this menu item.
pub fn id(&self) -> &MenuId {
match self {
MenuItemKind::MenuItem(i) => i.id(),
MenuItemKind::Submenu(i) => i.id(),
MenuItemKind::Predefined(i) => i.id(),
MenuItemKind::Check(i) => i.id(),
MenuItemKind::Icon(i) => i.id(),
}
}
/// Casts this item to a [`MenuItem`], and returns `None` if it wasn't.
pub fn as_menuitem(&self) -> Option<&MenuItem> {
match self {
@ -267,6 +278,7 @@ pub(crate) enum MenuItemType {
Check,
Icon,
}
impl Default for MenuItemType {
fn default() -> Self {
Self::MenuItem