multiwindow.rs 959 B

1234567891011121314151617181920212223242526272829303132
  1. //! Multiwindow example
  2. //!
  3. //! This example shows how to implement a simple multiwindow application using dioxus.
  4. //! This works by spawning a new window when the user clicks a button. We have to build a new virtualdom which has its
  5. //! own context, root elements, etc.
  6. use dioxus::prelude::*;
  7. use dioxus::{desktop::Config, desktop::WindowCloseBehaviour};
  8. fn main() {
  9. dioxus::LaunchBuilder::desktop()
  10. // We can choose the close behavior of the last window to hide. See WindowCloseBehaviour for more options.
  11. .with_cfg(Config::new().with_close_behaviour(WindowCloseBehaviour::LastWindowHides))
  12. .launch(app);
  13. }
  14. fn app() -> Element {
  15. let onclick = move |_| {
  16. let dom = VirtualDom::new(popup);
  17. dioxus::desktop::window().new_window(dom, Default::default());
  18. };
  19. rsx! {
  20. button { onclick, "New Window" }
  21. }
  22. }
  23. fn popup() -> Element {
  24. rsx! {
  25. div { "This is a popup window!" }
  26. }
  27. }