Add a menu bar option to the desktop config (#2107)
* add an option to set a custom menu in the desktop config * Fix rename issue --------- Co-authored-by: Jonathan Kelley <jkelleyrtp@gmail.com>
This commit is contained in:
1 parent
10d361a44e
commit
d442dac168
11 files changed
+152
-95
No files matched your search
@@ -0,0 +1,35 @@
|
||||
//! This example shows how to use a custom menu bar with Dioxus desktop.
|
||||
//! This example is not supported on the mobile or web renderers.
|
||||
|
||||
use dioxus::desktop::muda::*;
|
||||
use dioxus::prelude::*;
|
||||
|
||||
fn main() {
|
||||
// Create a menu bar that only contains the edit menu
|
||||
let menu = Menu::new();
|
||||
let edit_menu = Submenu::new("Edit", true);
|
||||
|
||||
edit_menu
|
||||
.append_items(&[
|
||||
&PredefinedMenuItem::undo(None),
|
||||
&PredefinedMenuItem::redo(None),
|
||||
&PredefinedMenuItem::separator(),
|
||||
&PredefinedMenuItem::cut(None),
|
||||
&PredefinedMenuItem::copy(None),
|
||||
&PredefinedMenuItem::paste(None),
|
||||
&PredefinedMenuItem::select_all(None),
|
||||
])
|
||||
.unwrap();
|
||||
|
||||
menu.append(&edit_menu).unwrap();
|
||||
|
||||
// Create a desktop config that overrides the default menu with the custom menu
|
||||
let config = dioxus::desktop::Config::new().with_menu(menu);
|
||||
|
||||
// Launch the app with the custom menu
|
||||
LaunchBuilder::new().with_cfg(config).launch(app)
|
||||
}
|
||||
|
||||
fn app() -> Element {
|
||||
rsx! {"Hello World!"}
|
||||
}
|
||||
@@ -8,12 +8,12 @@
|
||||
use dioxus::desktop::tao::event::Event as WryEvent;
|
||||
use dioxus::desktop::tao::event::WindowEvent;
|
||||
use dioxus::desktop::use_wry_event_handler;
|
||||
use dioxus::desktop::{Config, WindowCloseBehaviour};
|
||||
use dioxus::desktop::{Config, WindowCloseBehavior};
|
||||
use dioxus::prelude::*;
|
||||
|
||||
fn main() {
|
||||
LaunchBuilder::desktop()
|
||||
.with_cfg(Config::new().with_close_behaviour(WindowCloseBehaviour::CloseWindow))
|
||||
.with_cfg(Config::new().with_close_behaviour(WindowCloseBehavior::CloseWindow))
|
||||
.launch(app)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user