dioxus/examples/multiwindow.rs

29 lines
655 B
Rust
Raw Normal View History

2024-02-14 20:33:07 +00:00
//! Multiwindow example
//!
//! This example shows how to implement a simple multiwindow application using dioxus.
2024-02-14 20:33:07 +00:00
//! This works by spawning a new window when the user clicks a button. We have to build a new virtualdom which has its
//! own context, root elements, etc.
2022-12-31 03:05:15 +00:00
use dioxus::prelude::*;
fn main() {
launch_desktop(app);
2022-12-31 03:05:15 +00:00
}
fn app() -> Element {
2024-01-20 08:11:55 +00:00
let onclick = move |_| {
let dom = VirtualDom::new(popup);
dioxus::desktop::window().new_window(dom, Default::default());
};
2024-01-16 19:18:46 +00:00
rsx! {
2024-01-20 08:11:55 +00:00
button { onclick, "New Window" }
2024-01-14 05:12:21 +00:00
}
2022-12-31 03:05:15 +00:00
}
fn popup() -> Element {
2024-01-16 19:18:46 +00:00
rsx! {
2024-01-20 08:11:55 +00:00
div { "This is a popup window!" }
2024-01-14 05:12:21 +00:00
}
2022-12-31 03:05:15 +00:00
}