Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/refactor-simplify-internal-id-usage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"muda": patch
---

On Windows, fix icon of `Submenu` not visible when added to a root `Menu`
7 changes: 5 additions & 2 deletions examples/tao.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions examples/windows-common-controls-v6/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 5 additions & 2 deletions examples/winit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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);
Expand Down
7 changes: 5 additions & 2 deletions examples/wry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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,
Expand Down
8 changes: 6 additions & 2 deletions src/platform_impl/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
}
}
Expand Down Expand Up @@ -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) };

Expand Down
Loading