Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get web examples running again #2076

Merged
merged 5 commits into from
Sep 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions examples/counter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ publish = false

[dependencies]
iced.workspace = true

[target.'cfg(target_arch = "wasm32")'.dependencies]
iced.workspace = true
iced.features = ["webgl"]
8 changes: 8 additions & 0 deletions examples/counter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,12 @@ You can run it with `cargo run`:
cargo run --package counter
```

The web version can be run with [`trunk`]:

```
cd examples/counter
trunk serve
```

[`main`]: src/main.rs
[`trunk`]: https://trunkrs.dev/
5 changes: 4 additions & 1 deletion examples/integration/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ iced_winit.workspace = true
iced_wgpu.workspace = true
iced_widget.workspace = true

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

[target.'cfg(target_arch = "wasm32")'.dependencies]
iced_wgpu.workspace = true
iced_wgpu.features = ["webgl"]

console_error_panic_hook = "0.1"
console_log = "1.0"
log.workspace = true
wasm-bindgen = "0.2"
web-sys = { version = "0.3", features = ["Element", "HtmlCanvasElement", "Window", "Document"] }
2 changes: 1 addition & 1 deletion examples/integration/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use winit::platform::web::WindowBuilderExtWebSys;
pub fn main() -> Result<(), Box<dyn std::error::Error>> {
#[cfg(target_arch = "wasm32")]
let canvas_element = {
console_log::init_with_level(log::Level::Debug)?;
console_log::init().expect("Initialize logger");

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

Expand Down
3 changes: 3 additions & 0 deletions examples/todos/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ async-std.workspace = true
directories-next = "2.0"

[target.'cfg(target_arch = "wasm32")'.dependencies]
iced.workspace = true
iced.features = ["debug", "webgl"]

web-sys = { workspace = true, features = ["Window", "Storage"] }
wasm-timer.workspace = true

Expand Down
9 changes: 8 additions & 1 deletion examples/todos/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,14 @@ You can run the native version with `cargo run`:
```
cargo run --package todos
```
We have not yet implemented a `LocalStorage` version of the auto-save feature. Therefore, it does not work on web _yet_!

The web version can be run with [`trunk`]:

```
cd examples/todos
trunk serve
```

[`main`]: src/main.rs
[TodoMVC]: http://todomvc.com/
[`trunk`]: https://trunkrs.dev/
8 changes: 8 additions & 0 deletions examples/tour/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,12 @@ publish = false
iced.workspace = true
iced.features = ["image", "debug"]

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
tracing-subscriber = "0.3"
hecrj marked this conversation as resolved.
Show resolved Hide resolved

[target.'cfg(target_arch = "wasm32")'.dependencies]
iced.workspace = true
iced.features = ["image", "debug", "webgl"]

console_error_panic_hook = "0.1"
console_log = "1.0"
7 changes: 7 additions & 0 deletions examples/tour/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ use iced::widget::{Button, Column, Container, Slider};
use iced::{Color, Element, Font, Length, Renderer, Sandbox, Settings};

pub fn main() -> iced::Result {
#[cfg(target_arch = "wasm32")]
{
console_log::init().expect("Initialize logger");
std::panic::set_hook(Box::new(console_error_panic_hook::hook));
}

#[cfg(not(target_arch = "wasm32"))]
tracing_subscriber::fmt::init();

Tour::run(Settings::default())
Expand Down
Loading