pub struct CydWasm { /* private fields */ }Expand description
A CYD device rendered to an HTML canvas with browser-supplied touch input.
CydWasm implements the portable Cyd interface used by the hardware
implementations. Write normal application code against the
cyd module and its CydDisplay drawing APIs; only browser
setup and input plumbing need WASM-specific types.
Browser pointer handlers feed touch input through CydTouchWasmSource,
where it is calibrated and oriented like hardware touch input.
CydFrameWasm::flush presents the current frame and awaits the next
browser animation frame for frame pacing.
§See CYD in action
Linkage Blaze demonstrates animated clocks, mechanisms, and figures built
with Device Envoy’s portable CYD display APIs. Explore the examples in the
interactive Linkage Blaze gallery.
§Example
use device_envoy_core::{
cyd::display::Orientation,
wasm::{CydTouchWasmSource, CydWasm},
};
use embedded_graphics::{
mono_font::ascii::FONT_6X10,
pixelcolor::{Rgb888, RgbColor},
};
use wasm_bindgen::{JsCast, JsValue};
use web_sys::{CanvasRenderingContext2d, HtmlCanvasElement};
fn create_cyd(canvas: HtmlCanvasElement) -> Result<CydWasm, JsValue> {
let orientation = Orientation::Landscape;
canvas.set_width(orientation.width());
canvas.set_height(orientation.height());
let context = canvas
.get_context("2d")?
.ok_or_else(|| JsValue::from_str("2D canvas context unavailable"))?
.dyn_into::<CanvasRenderingContext2d>()?;
Ok(CydWasm::new(
context,
orientation,
Rgb888::BLACK,
Rgb888::WHITE,
&FONT_6X10,
CydTouchWasmSource::new(),
))
}Implementations§
Source§impl CydWasm
impl CydWasm
Sourcepub fn new(
context: CanvasRenderingContext2d,
orientation: Orientation,
background_color: Rgb888,
foreground_color: Rgb888,
font: &'static MonoFont<'static>,
touch_source: CydTouchWasmSource,
) -> Self
pub fn new( context: CanvasRenderingContext2d, orientation: Orientation, background_color: Rgb888, foreground_color: Rgb888, font: &'static MonoFont<'static>, touch_source: CydTouchWasmSource, ) -> Self
Construct a simulated CYD that presents frames onto context.
orientation determines the logical display size and touch mapping. The
caller should size the context’s canvas to match. Colors and font
configure the portable CydDisplay helpers, and touch_source
receives input from the browser’s pointer handlers.
Sourcepub fn touch_source(&self) -> CydTouchWasmSource
pub fn touch_source(&self) -> CydTouchWasmSource
Clone the input source that feeds browser pointer events to this device.
Sourcepub fn display(&self) -> CydDisplayWasm
pub fn display(&self) -> CydDisplayWasm
Clone the HTML-canvas display component.
Sourcepub fn owned_parts(&self) -> (CydDisplayWasm, CydTouchWasm)
pub fn owned_parts(&self) -> (CydDisplayWasm, CydTouchWasm)
Return owned display and calibrated touch handles.
The handles share the same browser canvas and touch-event state as this device.