diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/README.md | 14 | ||||
-rw-r--r-- | examples/tour.html | 5 | ||||
-rw-r--r-- | examples/tour.rs | 38 |
3 files changed, 45 insertions, 12 deletions
diff --git a/examples/README.md b/examples/README.md index fe69b34a..0a06a012 100644 --- a/examples/README.md +++ b/examples/README.md @@ -37,7 +37,7 @@ __update logic__ and __view logic__. [`wgpu`]: https://github.com/gfx-rs/wgpu-rs #### Running the native version -Simply use [Cargo](https://doc.rust-lang.org/cargo/reference/manifest.html#examples) +Use [Cargo](https://doc.rust-lang.org/cargo/reference/manifest.html#examples) to run the example: ``` @@ -45,10 +45,20 @@ cargo run --example tour ``` #### Running the web version +Build using the `wasm32-unknown-unknown` target and use the [`wasm-bindgen`] CLI +to generate appropriate bindings in a `tour` directory. + ``` -TODO +cd examples +cargo build --example tour --target wasm32-unknown-unknown +wasm-bindgen ../target/wasm32-unknown-unknown/debug/examples/tour.wasm --out-dir tour --web ``` +Finally, serve the `examples` directory using an HTTP server and access the +`tour.html` file. + +[`wasm-bindgen`]: https://github.com/rustwasm/wasm-bindgen + ## [Coffee] diff --git a/examples/tour.html b/examples/tour.html index b17ac4a2..35360e59 100644 --- a/examples/tour.html +++ b/examples/tour.html @@ -6,8 +6,9 @@ </head> <body> <script type="module"> - import init from "./pkg/iced_tour.js"; - init("./pkg/iced_tour_bg.wasm"); + import init from "./tour/tour.js"; + + init('./tour/tour_bg.wasm'); </script> </body> </html> diff --git a/examples/tour.rs b/examples/tour.rs index f77dc241..59a8c525 100644 --- a/examples/tour.rs +++ b/examples/tour.rs @@ -74,7 +74,7 @@ impl Application for Tour { } let element: Element<_> = Column::new() - .max_width(Length::Units(500)) + .max_width(Length::Units(540)) .spacing(20) .padding(20) .push(steps.view(self.debug).map(Message::StepMessage)) @@ -308,7 +308,7 @@ impl<'a> Step { that can be easily implemented on top of Iced.", )) .push(Text::new( - "Iced is a renderer-agnostic GUI library for Rust focused on \ + "Iced is a cross-platform GUI library for Rust focused on \ simplicity and type-safety. It is heavily inspired by Elm.", )) .push(Text::new( @@ -316,9 +316,9 @@ impl<'a> Step { 2D game engine for Rust.", )) .push(Text::new( - "Iced does not provide a built-in renderer. On native \ - platforms, this example runs on a fairly simple renderer \ - built on top of ggez, another game library.", + "On native platforms, Iced provides by default a renderer \ + built on top of wgpu, a graphics library supporting Vulkan, \ + Metal, DX11, and DX12.", )) .push(Text::new( "Additionally, this tour can also run on WebAssembly thanks \ @@ -503,9 +503,18 @@ impl<'a> Step { Self::container("Image") .push(Text::new("An image that tries to keep its aspect ratio.")) .push( - Image::new("resources/ferris.png") - .width(Length::Units(width)) - .align_self(Align::Center), + // This should go away once we unify resource loading on native + // platforms + if cfg!(target_arch = "wasm32") { + Image::new("resources/ferris.png") + } else { + Image::new(format!( + "{}/examples/resources/ferris.png", + env!("CARGO_MANIFEST_DIR") + )) + } + .width(Length::Units(width)) + .align_self(Align::Center), ) .push(Slider::new( slider, @@ -625,3 +634,16 @@ pub enum Layout { Row, Column, } + +// This should be gracefully handled by Iced in the future. Probably using our +// own proc macro, or maybe the whole process is streamlined by `wasm-pack` at +// some point. +#[cfg(target_arch = "wasm32")] +mod wasm { + use wasm_bindgen::prelude::*; + + #[wasm_bindgen(start)] + pub fn run() { + super::main() + } +} |