Skip to main content

CydWasm

Struct CydWasm 

Source
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. Linkage Blaze gallery showing CYD applications

§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

Source

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.

Source

pub fn touch_source(&self) -> CydTouchWasmSource

Clone the input source that feeds browser pointer events to this device.

Source

pub fn display(&self) -> CydDisplayWasm

Clone the HTML-canvas display component.

Source

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.

Trait Implementations§

Source§

impl Cyd for CydWasm

Source§

type Error = !

Browser CYD display and touch operations are infallible.

Source§

type Display = CydDisplayWasm

Source§

type Touch = CydTouchWasm

Source§

fn parts(&mut self) -> (&mut Self::Display, &mut Self::Touch)

Borrow the display and calibrated touch components at once. Read more
Source§

fn orientation(&self) -> Orientation

Return the logical orientation of this complete device. Read more
Source§

fn display(&mut self) -> &mut Self::Display

Borrow the display component. Read more
Source§

fn touch(&mut self) -> &mut Self::Touch

Borrow the calibrated touch component. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> StrictAs for T

Source§

fn strict_as<Dst>(self) -> Dst
where T: StrictCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> StrictCastFrom<Src> for Dst
where Src: StrictCast<Dst>,

Source§

fn strict_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more
Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.