1
0

custom_menu.rs 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. //! This example shows how to use a custom menu bar with Dioxus desktop.
  2. //! This example is not supported on the mobile or web renderers.
  3. use dioxus::desktop::muda::*;
  4. use dioxus::prelude::*;
  5. fn main() {
  6. // Create a menu bar that only contains the edit menu
  7. let menu = Menu::new();
  8. let edit_menu = Submenu::new("Edit", true);
  9. edit_menu
  10. .append_items(&[
  11. &PredefinedMenuItem::undo(None),
  12. &PredefinedMenuItem::redo(None),
  13. &PredefinedMenuItem::separator(),
  14. &PredefinedMenuItem::cut(None),
  15. &PredefinedMenuItem::copy(None),
  16. &PredefinedMenuItem::paste(None),
  17. &PredefinedMenuItem::select_all(None),
  18. ])
  19. .unwrap();
  20. menu.append(&edit_menu).unwrap();
  21. // Create a desktop config that overrides the default menu with the custom menu
  22. let config = dioxus::desktop::Config::new().with_menu(menu);
  23. // Launch the app with the custom menu
  24. LaunchBuilder::new().with_cfg(config).launch(app)
  25. }
  26. fn app() -> Element {
  27. rsx! {"Hello World!"}
  28. }