changeset 16: |
af615d1895cb |
author: |
ellis <ellis@rwest.io> |
date: |
Fri, 26 May 2023 21:59:40 -0400 |
permissions: |
-rw-r--r-- |
description: |
refactoring, ui stuff (goin with slint for DSL power) |
1 #[cfg(target_arch="wasm32")] 2 use wasm_bindgen::prelude::*; 5 event_loop::{ControlFlow, EventLoop}, 9 #[cfg_attr(target_arch="wasm32", wasm_bindgen(start))] 12 if #[cfg(target_arch = "wasm32")] { 13 std::panic::set_hook(Box::new(console_error_panic_hook::hook)); 14 console_log::init_with_level(log::Level::Warn).expect("Couldn't initialize logger"); 19 let event_loop = EventLoop::new(); 20 let window = WindowBuilder::new().build(&event_loop).unwrap(); 22 #[cfg(target_arch = "wasm32")] 24 // Winit prevents sizing with CSS, so we have to set 25 // the size manually when on web. 26 use winit::dpi::PhysicalSize; 27 window.set_inner_size(PhysicalSize::new(450, 400)); 29 use winit::platform::web::WindowExtWebSys; 31 .and_then(|win| win.document()) 33 let dst = doc.get_element_by_id("wasm-example")?; 34 let canvas = web_sys::Element::from(window.canvas()); 35 dst.append_child(&canvas).ok()?; 38 .expect("Couldn't append canvas to document body."); 40 event_loop.run(move |event, _, control_flow| match event { 44 } if window_id == window.id() => match event { 45 WindowEvent::CloseRequested 46 | WindowEvent::KeyboardInput { 49 state: ElementState::Pressed, 50 virtual_keycode: Some(VirtualKeyCode::Escape), 54 } => *control_flow = ControlFlow::Exit,