Skip to content
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ dioxus-asset-resolver = { version = "0.7.3" }
manganis = { version = "0.7.3" }
dioxus-document = { version = "0.7.3" }
dioxus-history = { version = "0.7.3" }
futures-channel = "0.3"

# Dioxus hot reload
dioxus-devtools = { version = "0.7.3" }
Expand Down Expand Up @@ -231,6 +232,7 @@ blitz-net = { workspace = true }
blitz = { workspace = true, features = ["net"] }
dioxus = { workspace = true }
dioxus-native = { workspace = true, features = ["vello", "floats", "svg", "prelude"] }
dioxus-native-dom = { workspace = true }
euclid = { workspace = true }
reqwest = { workspace = true }
tokio = { workspace = true, features = ["macros"] }
Expand All @@ -239,6 +241,7 @@ png = { workspace = true }
peniko = { workspace = true }
env_logger = "0.11"
tracing-subscriber = "0.3"
winit = { workspace = true }

# [patch.crates-io]
# anyrender = { path = "../anyrender/crates/anyrender" }
Expand All @@ -255,4 +258,4 @@ tracing-subscriber = "0.3"

# [patch."https://github.com/nicoburns/parley"]
# parley = { path = "../parley/parley" }
# fontique = { path = "../parley/fontique" }
# fontique = { path = "../parley/fontique" }
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ Check out the [roadmap issue](https://github.com/DioxusLabs/blitz/issues/119) fo
cargo run --release --package wgpu_texture
```

- multi-window demo
```sh
cargo run --example multi_window
```

Other examples are available in the [examples/](./examples/) folder.

## Goals
Expand Down
83 changes: 83 additions & 0 deletions examples/multi_window.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
//! Demonstrate opening additional windows from a pure Dioxus app.

use blitz_traits::shell::ShellProvider;
use dioxus::prelude::*;
use dioxus_native::DioxusNativeProvider;
use std::sync::Arc;
use std::sync::Weak;
use winit::window::Window;
use winit::window::WindowId;
use winit::window::{WindowAttributes, WindowButtons};

fn main() {
// Demonstrate how to pass custom WindowAttributes (title, size, decorations).
let attrs = WindowAttributes::default()
.with_title("Multi-window Demo")
.with_inner_size(winit::dpi::LogicalSize::new(600.0, 800.0))
.with_enabled_buttons(WindowButtons::all());
dioxus_native::launch_cfg(app, vec![], vec![Box::new(attrs)]);
}

fn app() -> Element {
let provider = use_context::<DioxusNativeProvider>();
let mut counter = use_signal(|| 0u32);
let spawned_windows = use_signal(Vec::<(WindowId, Weak<Window>)>::new);

rsx! {
main {
h1 { "Blitz multi-window" }
p { "Click the button to open another RSX window." }
div {
button {
onclick: move |_| {
let vdom = VirtualDom::new(secondary_window);
let title = format!("window#{}", counter());
let attributes = WindowAttributes::default()
.with_title(title)
.with_inner_size(winit::dpi::LogicalSize::new(400.0, 300.0));
let config = dioxus_native::Config::new().with_window_attributes(attributes);
let pending = provider.new_window(vdom, config);
let mut spawned_windows = spawned_windows;
spawn(async move {
let (window_id, window) = pending.await;
let mut next = spawned_windows();
next.push((window_id, Arc::downgrade(&window)));
spawned_windows.set(next);
});
counter += 1;
},
"Open secondary window"
}
}

h2 { "Spawned windows" }
ul {
{spawned_windows().into_iter().map(|(id, window)| match window.upgrade() {
Some(window) => {
let title = window.title();
let title = if title.is_empty() { String::from("<unsupported>") } else { title };
rsx! { li { "{title} (ID: {id:?})" } }
}
None => rsx! { li { "<closed> (ID: {id:?})" } },
})}
}
}
}
}

fn secondary_window() -> Element {
let shell_provider = use_context::<Arc<dyn ShellProvider>>();

rsx! {
main {
h1 { "Secondary window" }
p { "This content comes from another RSX function." }
button {
onclick: move |_| {
shell_provider.set_window_title(format!("Time: {:?}", std::time::SystemTime::now()))
},
"click to update title",
}
}
}
}
5 changes: 3 additions & 2 deletions packages/dioxus-native/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ vello-cpu-base = ["alt-renderer", "dep:anyrender_vello_cpu"]
alt-renderer = []

# Other features
net = ["dep:tokio", "dep:blitz-net"]
net = ["dep:blitz-net", "dep:tokio"]
html = ["dep:blitz-html"]

# Dev
Expand Down Expand Up @@ -94,8 +94,9 @@ manganis = { workspace = true, features = ["dioxus"], optional = true }
winit = { workspace = true }
keyboard-types = { workspace = true }

# IO & Networking
# Runtime + channels
tokio = { workspace = true, features = ["rt-multi-thread"], optional = true }
futures-channel = { workspace = true }
webbrowser = { workspace = true }

# Other dependencies
Expand Down
Loading
Loading