Merge pull request #2076 from Nisatru/run-web

Get web examples running again
This commit is contained in:
Héctor Ramón 2023-09-09 23:24:54 +02:00 committed by GitHub
commit a3489e4af9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 43 additions and 3 deletions

View file

@ -7,3 +7,7 @@ publish = false
[dependencies]
iced.workspace = true
[target.'cfg(target_arch = "wasm32")'.dependencies]
iced.workspace = true
iced.features = ["webgl"]

View file

@ -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/

View file

@ -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"] }

View file

@ -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));

View file

@ -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

View file

@ -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/

View file

@ -9,4 +9,12 @@ publish = false
iced.workspace = true
iced.features = ["image", "debug"]
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
tracing-subscriber = "0.3"
[target.'cfg(target_arch = "wasm32")'.dependencies]
iced.workspace = true
iced.features = ["image", "debug", "webgl"]
console_error_panic_hook = "0.1"
console_log = "1.0"

View file

@ -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())