Add a WASM build of the plotters example

... which uses an intermediate drawing backend to skip the text on the axis, as
that requires TrueType fonts form the filesystem.
This commit is contained in:
Simon Hausmann 2021-08-11 16:14:54 +02:00
parent 0ebd92c253
commit 8903adb584
5 changed files with 154 additions and 2 deletions

View file

@ -14,6 +14,9 @@ use sixtyfps::SharedPixelBuffer;
#[cfg(target_arch = "wasm32")]
use wasm_bindgen::prelude::*;
#[cfg(target_arch = "wasm32")]
mod wasm_backend;
sixtyfps::sixtyfps! {
import { MainWindow } from "plotter.60";
}
@ -31,7 +34,14 @@ fn render_plot(pitch: f32) -> sixtyfps::Image {
let mut pixel_buffer = SharedPixelBuffer::new(640, 480);
let size = (pixel_buffer.width() as u32, pixel_buffer.height() as u32);
let root = BitMapBackend::with_buffer(pixel_buffer.make_mut_bytes(), size).into_drawing_area();
let backend = BitMapBackend::with_buffer(pixel_buffer.make_mut_bytes(), size);
// Plotters requires TrueType fonts from the file system to draw axis text - we skip that for
// WASM for now.
#[cfg(target_arch = "wasm32")]
let backend = wasm_backend::BackendWithoutText { backend };
let root = backend.into_drawing_area();
root.fill(&WHITE).expect("error filling drawing area");