Skip to content

Commit

Permalink
chore(example): add support for native icons in submenu items
Browse files Browse the repository at this point in the history
Introduce a new method `set_native_icon` to allow changing the menu
item icon to a native image. This method currently supports macOS,
while remaining unsupported on Windows and Linux platforms.
The addition enhances the customization options for submenu items.
  • Loading branch information
s00d committed Feb 26, 2025
1 parent b1adc81 commit 959aa7b
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/items/submenu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use std::{cell::RefCell, mem, rc::Rc};

use crate::{dpi::Position, sealed::IsMenuItemBase, util::AddOp, ContextMenu, Icon, IsMenuItem, MenuId, MenuItemKind};
use crate::{dpi::Position, sealed::IsMenuItemBase, util::AddOp, ContextMenu, Icon, IsMenuItem, MenuId, MenuItemKind, NativeIcon};

/// A menu that can be added to a [`Menu`] or another [`Submenu`].
///
Expand Down Expand Up @@ -210,6 +210,16 @@ impl Submenu {
pub fn set_icon(&self, icon: Option<Icon>) {
self.inner.borrow_mut().set_icon(icon)
}

/// Change this menu item icon to a native image or remove it.
///
/// ## Platform-specific:
///
/// - **Windows / Linux**: Unsupported.
pub fn set_native_icon(&self, _icon: Option<NativeIcon>) {
#[cfg(target_os = "macos")]
self.inner.borrow_mut().set_native_icon(_icon)
}
}

impl ContextMenu for Submenu {
Expand Down

0 comments on commit 959aa7b

Please sign in to comment.