-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
Copy pathmultiwindow.rs
35 lines (30 loc) · 1.01 KB
/
multiwindow.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//! Multiwindow example
//!
//! This example shows how to implement a simple multiwindow application using dioxus.
//! 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.
use dioxus::prelude::*;
use dioxus::{desktop::Config, desktop::DefaultWindowCloseBehaviour};
fn main() {
dioxus::LaunchBuilder::desktop()
// We can choose the close behavior of the last window to hide. See DefaultWindowCloseBehaviour for more options.
.with_cfg(
Config::new()
.with_default_window_close_behaviour(DefaultWindowCloseBehaviour::LastWindowHides),
)
.launch(app);
}
fn app() -> Element {
let onclick = move |_| {
let dom = VirtualDom::new(popup);
dioxus::desktop::window().new_window(dom, Default::default());
};
rsx! {
button { onclick, "New Window" }
}
}
fn popup() -> Element {
rsx! {
div { "This is a popup window!" }
}
}