From 9c2ad457d80e8254955396ad034df0dd5f2b59b3 Mon Sep 17 00:00:00 2001 From: Thomas Date: Sat, 9 Sep 2023 13:59:18 +0200 Subject: Add webgl feature for web examples --- examples/counter/Cargo.toml | 4 ++++ examples/integration/Cargo.toml | 3 +++ examples/todos/Cargo.toml | 3 +++ examples/tour/Cargo.toml | 4 ++++ 4 files changed, 14 insertions(+) diff --git a/examples/counter/Cargo.toml b/examples/counter/Cargo.toml index 1e9bba6b..22f86064 100644 --- a/examples/counter/Cargo.toml +++ b/examples/counter/Cargo.toml @@ -7,3 +7,7 @@ publish = false [dependencies] iced.workspace = true + +[target.'cfg(target_arch = "wasm32")'.dependencies] +iced.workspace = true +iced.features = ["webgl"] diff --git a/examples/integration/Cargo.toml b/examples/integration/Cargo.toml index 032cc75e..bf70a619 100644 --- a/examples/integration/Cargo.toml +++ b/examples/integration/Cargo.toml @@ -13,6 +13,9 @@ iced_widget.workspace = true 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 diff --git a/examples/todos/Cargo.toml b/examples/todos/Cargo.toml index fea20375..3334d84f 100644 --- a/examples/todos/Cargo.toml +++ b/examples/todos/Cargo.toml @@ -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 diff --git a/examples/tour/Cargo.toml b/examples/tour/Cargo.toml index 21206ecb..9de017ce 100644 --- a/examples/tour/Cargo.toml +++ b/examples/tour/Cargo.toml @@ -10,3 +10,7 @@ iced.workspace = true iced.features = ["image", "debug"] tracing-subscriber = "0.3" + +[target.'cfg(target_arch = "wasm32")'.dependencies] +iced.workspace = true +iced.features = ["image", "debug", "webgl"] -- cgit From e562544807b196dafac9195ea8137958698755e5 Mon Sep 17 00:00:00 2001 From: Thomas Date: Sat, 9 Sep 2023 14:09:48 +0200 Subject: Add logging for web in tour example --- examples/tour/Cargo.toml | 5 +++++ examples/tour/src/main.rs | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/examples/tour/Cargo.toml b/examples/tour/Cargo.toml index 9de017ce..11920e0d 100644 --- a/examples/tour/Cargo.toml +++ b/examples/tour/Cargo.toml @@ -9,8 +9,13 @@ 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" +log.workspace = true diff --git a/examples/tour/src/main.rs b/examples/tour/src/main.rs index af508206..f0e3c0cd 100644 --- a/examples/tour/src/main.rs +++ b/examples/tour/src/main.rs @@ -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_with_level(log::Level::Debug).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()) -- cgit From 52da89ac531cdf93b0e74afdd5bf6ad366551f82 Mon Sep 17 00:00:00 2001 From: Thomas Date: Sat, 9 Sep 2023 14:11:40 +0200 Subject: Add instructions to run web examples --- examples/counter/README.md | 8 ++++++++ examples/todos/README.md | 9 ++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/examples/counter/README.md b/examples/counter/README.md index 53243c24..18761bba 100644 --- a/examples/counter/README.md +++ b/examples/counter/README.md @@ -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/ diff --git a/examples/todos/README.md b/examples/todos/README.md index 852dd88d..5e42f166 100644 --- a/examples/todos/README.md +++ b/examples/todos/README.md @@ -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/ -- cgit From 052fe0edaeb0d6ce096375751eec02b953faf2a1 Mon Sep 17 00:00:00 2001 From: Thomas Date: Sat, 9 Sep 2023 14:15:11 +0200 Subject: Dont use tracing-subscriber dependency on web --- examples/integration/Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/integration/Cargo.toml b/examples/integration/Cargo.toml index bf70a619..6b9fcc57 100644 --- a/examples/integration/Cargo.toml +++ b/examples/integration/Cargo.toml @@ -10,6 +10,7 @@ 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] -- cgit From fbc9ef74c406b2a58bb2a093262323e346faf485 Mon Sep 17 00:00:00 2001 From: Thomas Date: Sat, 9 Sep 2023 22:42:41 +0200 Subject: Change init_with_level to init in examples --- examples/integration/Cargo.toml | 1 - examples/integration/src/main.rs | 2 +- examples/tour/Cargo.toml | 1 - examples/tour/src/main.rs | 2 +- 4 files changed, 2 insertions(+), 4 deletions(-) diff --git a/examples/integration/Cargo.toml b/examples/integration/Cargo.toml index 6b9fcc57..a4a961f8 100644 --- a/examples/integration/Cargo.toml +++ b/examples/integration/Cargo.toml @@ -19,6 +19,5 @@ 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"] } diff --git a/examples/integration/src/main.rs b/examples/integration/src/main.rs index af48af5f..d0b2d891 100644 --- a/examples/integration/src/main.rs +++ b/examples/integration/src/main.rs @@ -29,7 +29,7 @@ use winit::platform::web::WindowBuilderExtWebSys; pub fn main() -> Result<(), Box> { #[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)); diff --git a/examples/tour/Cargo.toml b/examples/tour/Cargo.toml index 11920e0d..9e984ad1 100644 --- a/examples/tour/Cargo.toml +++ b/examples/tour/Cargo.toml @@ -18,4 +18,3 @@ iced.features = ["image", "debug", "webgl"] console_error_panic_hook = "0.1" console_log = "1.0" -log.workspace = true diff --git a/examples/tour/src/main.rs b/examples/tour/src/main.rs index f0e3c0cd..3387b481 100644 --- a/examples/tour/src/main.rs +++ b/examples/tour/src/main.rs @@ -10,7 +10,7 @@ use iced::{Color, Element, Font, Length, Renderer, Sandbox, Settings}; pub fn main() -> iced::Result { #[cfg(target_arch = "wasm32")] { - console_log::init_with_level(log::Level::Debug).expect("Initialize logger"); + console_log::init().expect("Initialize logger"); std::panic::set_hook(Box::new(console_error_panic_hook::hook)); } -- cgit