mirror of
https://github.com/tauri-apps/muda.git
synced 2026-01-31 00:45:18 +01:00
Fix: Windows submenu icons support (#308)
This commit is contained in:
5
.changes/refactor-simplify-internal-id-usage.md
Normal file
5
.changes/refactor-simplify-internal-id-usage.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"muda": patch
|
||||
---
|
||||
|
||||
On Windows, fix icon of `Submenu` not visible when added to a root `Menu`
|
||||
@@ -78,10 +78,15 @@ fn main() {
|
||||
]);
|
||||
}
|
||||
|
||||
let path = concat!(env!("CARGO_MANIFEST_DIR"), "/examples/icon.png");
|
||||
let icon = load_icon(std::path::Path::new(path));
|
||||
|
||||
let file_m = Submenu::new("&File", true);
|
||||
let edit_m = Submenu::new("&Edit", true);
|
||||
let window_m = Submenu::new("&Window", true);
|
||||
|
||||
window_m.set_icon(Some(icon.clone()));
|
||||
|
||||
menu_bar.append_items(&[&file_m, &edit_m, &window_m]);
|
||||
|
||||
let custom_i_1 = MenuItem::with_id(
|
||||
@@ -91,8 +96,6 @@ fn main() {
|
||||
Some(Accelerator::new(Some(Modifiers::ALT), Code::KeyC)),
|
||||
);
|
||||
|
||||
let path = concat!(env!("CARGO_MANIFEST_DIR"), "/examples/icon.png");
|
||||
let icon = load_icon(std::path::Path::new(path));
|
||||
let image_item = IconMenuItem::with_id(
|
||||
"image-custom-1",
|
||||
"Image custom 1",
|
||||
|
||||
@@ -77,6 +77,9 @@ fn main() {
|
||||
Some(Accelerator::new(Some(Modifiers::ALT), Code::KeyC)),
|
||||
);
|
||||
|
||||
let path = concat!(env!("CARGO_MANIFEST_DIR"), "/examples/icon.png");
|
||||
let icon = load_icon(std::path::Path::new(path));
|
||||
|
||||
let image_item = IconMenuItem::new("Image Custom 1", true, Some(icon), None);
|
||||
|
||||
let check_custom_i_1 = CheckMenuItem::new("Check Custom 1", true, true, None);
|
||||
|
||||
@@ -186,10 +186,15 @@ impl AppMenu {
|
||||
menu_bar.append(&app_menu);
|
||||
}
|
||||
|
||||
let path = concat!(env!("CARGO_MANIFEST_DIR"), "/examples/icon.png");
|
||||
let icon = load_icon(std::path::Path::new(path));
|
||||
|
||||
let file_menu = Submenu::new("&File", true);
|
||||
let edit_menu = Submenu::new("&Edit", true);
|
||||
let window_menu = Submenu::new("&Window", true);
|
||||
|
||||
window_menu.set_icon(Some(icon.clone()));
|
||||
|
||||
menu_bar.append_items(&[&file_menu, &edit_menu, &window_menu]);
|
||||
|
||||
let custom_i_1 = MenuItem::new(
|
||||
@@ -198,8 +203,6 @@ impl AppMenu {
|
||||
Some(Accelerator::new(Some(Modifiers::ALT), Code::KeyC)),
|
||||
);
|
||||
|
||||
let path = concat!(env!("CARGO_MANIFEST_DIR"), "/examples/icon.png");
|
||||
let icon = load_icon(std::path::Path::new(path));
|
||||
let image_item = IconMenuItem::new("Image Custom 1", true, Some(icon), None);
|
||||
|
||||
let check_custom_i_1 = CheckMenuItem::new("Check Custom 1", true, true, None);
|
||||
|
||||
@@ -86,10 +86,15 @@ fn main() -> wry::Result<()> {
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
let path = concat!(env!("CARGO_MANIFEST_DIR"), "/examples/icon.png");
|
||||
let icon = load_icon(std::path::Path::new(path));
|
||||
|
||||
let file_m = Submenu::new("&File", true);
|
||||
let edit_m = Submenu::new("&Edit", true);
|
||||
let window_m = Submenu::new("&Window", true);
|
||||
|
||||
window_m.set_icon(Some(icon.clone()));
|
||||
|
||||
menu_bar
|
||||
.append_items(&[&file_m, &edit_m, &window_m])
|
||||
.unwrap();
|
||||
@@ -100,8 +105,6 @@ fn main() -> wry::Result<()> {
|
||||
Some(Accelerator::new(Some(Modifiers::ALT), Code::KeyC)),
|
||||
);
|
||||
|
||||
let path = concat!(env!("CARGO_MANIFEST_DIR"), "/examples/icon.png");
|
||||
let icon = load_icon(std::path::Path::new(path));
|
||||
let image_item = IconMenuItem::new(
|
||||
"Image custom 1",
|
||||
true,
|
||||
|
||||
@@ -235,17 +235,19 @@ impl Menu {
|
||||
let child_ = child.borrow();
|
||||
let item_type = child_.item_type();
|
||||
|
||||
// Set icons for both regular menu items and submenus
|
||||
if matches!(item_type, MenuItemType::Icon | MenuItemType::Submenu) {
|
||||
let hbitmap = child_
|
||||
.icon
|
||||
.as_ref()
|
||||
.map(|i| unsafe { i.inner.to_hbitmap() })
|
||||
.unwrap_or(std::ptr::null_mut());
|
||||
|
||||
let info = create_icon_item_info(hbitmap);
|
||||
|
||||
unsafe {
|
||||
SetMenuItemInfoW(self.hmenu, child_.internal_id, FALSE, &info);
|
||||
SetMenuItemInfoW(self.hpopupmenu, child_.internal_id, FALSE, &info);
|
||||
SetMenuItemInfoW(self.hmenu, child_.internal_id(), FALSE, &info);
|
||||
SetMenuItemInfoW(self.hpopupmenu, child_.internal_id(), FALSE, &info);
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -795,7 +797,9 @@ impl MenuChild {
|
||||
let hbitmap = icon
|
||||
.map(|i| unsafe { i.inner.to_hbitmap() })
|
||||
.unwrap_or(std::ptr::null_mut());
|
||||
|
||||
let info = create_icon_item_info(hbitmap);
|
||||
|
||||
for (parent, menu_bars) in &self.parents_hemnu {
|
||||
unsafe { SetMenuItemInfoW(*parent, self.internal_id(), FALSE, &info) };
|
||||
|
||||
|
||||
Reference in New Issue
Block a user