lapce / floem

A native Rust UI library with fine-grained reactivity

Home Page:https://docs.rs/floem

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support for global menus

dominikwilkowski opened this issue · comments

It looks like there is an issue with the winit implementation since the menu code is commented out in the code base right now.
Possibly related to #17?
I figured I add an issue to track this.

We should have support for:

Application::new()
	.window(
		|_| {
			app_view().window_title(|| String::from("Title")).window_menu(|| {
				Menu::new("Foobar")
					.entry(MenuItem::new("Menu item"))
					.entry(MenuItem::new("Menu item with something on the\tright"))
			})
		},
		Some(WindowConfig::default().size(Size::new(800.0, 350.0)).title("Vault")),
	)
	.run();

The window_handle.rs function can be made to compile like this:

fn update_window_menu(&mut self, mut menu: Menu) {
    if let Some(action) = menu.item.action.take() {
        self.app_state
            .window_menu
            .insert(menu.item.id as usize, action);
    }
    for child in menu.children {
        match child {
            crate::menu::MenuEntry::Separator => {}
            crate::menu::MenuEntry::Item(mut item) => {
                if let Some(action) = item.action.take() {
                    self.app_state.window_menu.insert(item.id as usize, action);
                }
            }
            crate::menu::MenuEntry::SubMenu(m) => {
                self.update_window_menu(m);
            }
        }
    }
}

Which would result in a global menu much like this one in macos:
image