mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-11-21 19:53:04 +00:00
20d146d9bd
* improve documentation for the fullstack server context * Add a section about axum integration to the crate root docs * make serve_dioxus_application accept the cfg builder directly * remove unused server_fn module * improve fullstack config docs * improve documentation for the server function macro * fix axum router extension link * Fix doc tests * Fix launch builder * Simplify the launch builder * don't re-export launch in the prelude * refactor fullstack launch * Fix fullstack launch builder * Update static generation with the new builder api * fix some formatting/overly broad launch replacements * fix custom menu example * fix fullstack/static generation examples * Fix static generation launch * A few small formatting fixes * Fix a few doc tests * implement LaunchConfig for serve configs * fix fullstack launch with separate web and server launch methods * fix check with all features * dont expose inner core module * clippy and check * fix readme --------- Co-authored-by: Jonathan Kelley <jkelleyrtp@gmail.com>
49 lines
1.5 KiB
Rust
49 lines
1.5 KiB
Rust
//! 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_muda_event_handler};
|
|
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),
|
|
&MenuItem::with_id("switch-text", "Switch text", true, 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
|
|
dioxus::LaunchBuilder::new().with_cfg(config).launch(app)
|
|
}
|
|
|
|
fn app() -> Element {
|
|
let mut text = use_signal(String::new);
|
|
// You can use the `use_muda_event_handler` hook to run code when a menu event is triggered.
|
|
use_muda_event_handler(move |muda_event| {
|
|
if muda_event.id() == "switch-text" {
|
|
text.set("Switched to text".to_string());
|
|
}
|
|
});
|
|
|
|
rsx! {
|
|
div {
|
|
h1 { "Custom Menu" }
|
|
p { "Text: {text}" }
|
|
}
|
|
}
|
|
}
|