Add web support

A limitation of this implementation is that it can't coexist with anything which creates a canvas context other than `CanvasRenderingContext2D`, since only one context can exist per canvas.
This commit is contained in:
Liam Murphy 2022-02-12 20:24:18 +11:00
parent bc900e69e7
commit d735510f72
7 changed files with 155 additions and 0 deletions

View file

@ -9,6 +9,21 @@ const BUFFER_HEIGHT: usize = 128;
fn main() {
let event_loop = EventLoop::new();
let window = WindowBuilder::new().build(&event_loop).unwrap();
#[cfg(target_arch = "wasm32")]
{
use winit::platform::web::WindowExtWebSys;
web_sys::window()
.unwrap()
.document()
.unwrap()
.body()
.unwrap()
.append_child(&window.canvas())
.unwrap();
}
let mut graphics_context = unsafe { GraphicsContext::new(window) }.unwrap();
event_loop.run(move |event, _, control_flow| {