Skip to content

Commit a3489e4

Browse files
authored
Merge pull request #2076 from Nisatru/run-web
Get web examples running again
2 parents e3aa8f7 + fbc9ef7 commit a3489e4

8 files changed

Lines changed: 43 additions & 3 deletions

File tree

examples/counter/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@ publish = false
77

88
[dependencies]
99
iced.workspace = true
10+
11+
[target.'cfg(target_arch = "wasm32")'.dependencies]
12+
iced.workspace = true
13+
iced.features = ["webgl"]

examples/counter/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,12 @@ You can run it with `cargo run`:
1313
cargo run --package counter
1414
```
1515

16+
The web version can be run with [`trunk`]:
17+
18+
```
19+
cd examples/counter
20+
trunk serve
21+
```
22+
1623
[`main`]: src/main.rs
24+
[`trunk`]: https://trunkrs.dev/

examples/integration/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,14 @@ iced_winit.workspace = true
1010
iced_wgpu.workspace = true
1111
iced_widget.workspace = true
1212

13+
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
1314
tracing-subscriber = "0.3"
1415

1516
[target.'cfg(target_arch = "wasm32")'.dependencies]
17+
iced_wgpu.workspace = true
18+
iced_wgpu.features = ["webgl"]
19+
1620
console_error_panic_hook = "0.1"
1721
console_log = "1.0"
18-
log.workspace = true
1922
wasm-bindgen = "0.2"
2023
web-sys = { version = "0.3", features = ["Element", "HtmlCanvasElement", "Window", "Document"] }

examples/integration/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use winit::platform::web::WindowBuilderExtWebSys;
2929
pub fn main() -> Result<(), Box<dyn std::error::Error>> {
3030
#[cfg(target_arch = "wasm32")]
3131
let canvas_element = {
32-
console_log::init_with_level(log::Level::Debug)?;
32+
console_log::init().expect("Initialize logger");
3333

3434
std::panic::set_hook(Box::new(console_error_panic_hook::hook));
3535

examples/todos/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ async-std.workspace = true
1818
directories-next = "2.0"
1919

2020
[target.'cfg(target_arch = "wasm32")'.dependencies]
21+
iced.workspace = true
22+
iced.features = ["debug", "webgl"]
23+
2124
web-sys = { workspace = true, features = ["Window", "Storage"] }
2225
wasm-timer.workspace = true
2326

examples/todos/README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,14 @@ You can run the native version with `cargo run`:
1414
```
1515
cargo run --package todos
1616
```
17-
We have not yet implemented a `LocalStorage` version of the auto-save feature. Therefore, it does not work on web _yet_!
17+
18+
The web version can be run with [`trunk`]:
19+
20+
```
21+
cd examples/todos
22+
trunk serve
23+
```
1824

1925
[`main`]: src/main.rs
2026
[TodoMVC]: http://todomvc.com/
27+
[`trunk`]: https://trunkrs.dev/

examples/tour/Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,12 @@ publish = false
99
iced.workspace = true
1010
iced.features = ["image", "debug"]
1111

12+
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
1213
tracing-subscriber = "0.3"
14+
15+
[target.'cfg(target_arch = "wasm32")'.dependencies]
16+
iced.workspace = true
17+
iced.features = ["image", "debug", "webgl"]
18+
19+
console_error_panic_hook = "0.1"
20+
console_log = "1.0"

examples/tour/src/main.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ use iced::widget::{Button, Column, Container, Slider};
88
use iced::{Color, Element, Font, Length, Renderer, Sandbox, Settings};
99

1010
pub fn main() -> iced::Result {
11+
#[cfg(target_arch = "wasm32")]
12+
{
13+
console_log::init().expect("Initialize logger");
14+
std::panic::set_hook(Box::new(console_error_panic_hook::hook));
15+
}
16+
17+
#[cfg(not(target_arch = "wasm32"))]
1118
tracing_subscriber::fmt::init();
1219

1320
Tour::run(Settings::default())

0 commit comments

Comments
 (0)