pub struct CanvasApp { /* private fields */ }Expand description
The main canvas application for WASM.
Implementations§
Source§impl CanvasApp
impl CanvasApp
Sourcepub fn new(canvas_id: &str) -> Result<CanvasApp, JsValue>
pub fn new(canvas_id: &str) -> Result<CanvasApp, JsValue>
Create a new canvas application attached to the given canvas element ID.
§Errors
Returns an error if the canvas element is not found or 2D context fails.
Sourcepub fn handle_touch(&mut self, x: f32, y: f32, phase: &str) -> Option<String>
pub fn handle_touch(&mut self, x: f32, y: f32, phase: &str) -> Option<String>
Handle a touch event at the given coordinates.
Sourcepub fn handle_click(&mut self, x: f32, y: f32) -> Option<String>
pub fn handle_click(&mut self, x: f32, y: f32) -> Option<String>
Handle a mouse click at the given coordinates.
Sourcepub fn get_scene_json(&self) -> String
pub fn get_scene_json(&self) -> String
Get the current scene as JSON.
Sourcepub fn apply_scene_document(&mut self, json: &str) -> Result<(), JsValue>
pub fn apply_scene_document(&mut self, json: &str) -> Result<(), JsValue>
Apply a canonical scene document serialized as JSON.
§Errors
Returns an error if the JSON is invalid or the scene cannot be converted.
Sourcepub fn element_count(&self) -> usize
pub fn element_count(&self) -> usize
Get the number of elements in the scene.
Sourcepub fn frame_count(&self) -> u64
pub fn frame_count(&self) -> u64
Get the current frame count.
Sourcepub fn set_background_color(&mut self, color: &str)
pub fn set_background_color(&mut self, color: &str)
Set the background color (CSS color string).
Sourcepub fn is_connected(&self) -> bool
pub fn is_connected(&self) -> bool
Check if connected to AI backend.
Sourcepub fn update_video_frame(
&mut self,
stream_id: &str,
data: &[u8],
width: u32,
height: u32,
timestamp: f64,
)
pub fn update_video_frame( &mut self, stream_id: &str, data: &[u8], width: u32, height: u32, timestamp: f64, )
The data should be RGBA bytes.
Sourcepub fn remove_video_stream(&mut self, stream_id: &str)
pub fn remove_video_stream(&mut self, stream_id: &str)
Remove a video stream from the cache.
Sourcepub fn get_video_stream_ids(&self) -> Vec<String>
pub fn get_video_stream_ids(&self) -> Vec<String>
Get the list of registered video stream IDs.
Sourcepub fn has_video_frame(&self, stream_id: &str) -> bool
pub fn has_video_frame(&self, stream_id: &str) -> bool
Check if a video stream has a cached frame.
Sourcepub fn get_video_frame_timestamp(&self, stream_id: &str) -> f64
pub fn get_video_frame_timestamp(&self, stream_id: &str) -> f64
Get the timestamp of the last frame for a video stream. Returns 0.0 if the stream doesn’t exist.
Sourcepub fn set_holographic_config(&mut self, preset: &str) -> Result<(), JsValue>
pub fn set_holographic_config(&mut self, preset: &str) -> Result<(), JsValue>
Enable holographic mode with a preset configuration.
Supported presets: “portrait”, “4k” Pass an empty string or “off” to disable holographic mode.
§Errors
Returns an error if the preset is not recognized.
Sourcepub fn is_holographic_mode(&self) -> bool
pub fn is_holographic_mode(&self) -> bool
Check if holographic mode is currently enabled.
Sourcepub fn get_quilt_dimensions(&self) -> JsValue
pub fn get_quilt_dimensions(&self) -> JsValue
Get the quilt dimensions for the current holographic configuration.
Returns a JS object: { width, height, views, columns, rows } Returns null if holographic mode is not enabled.
Sourcepub fn render_quilt(&mut self) -> Result<Vec<u8>, JsValue>
pub fn render_quilt(&mut self) -> Result<Vec<u8>, JsValue>
Render the current scene as a holographic quilt.
Returns the quilt as RGBA pixel data (Vec<u8>).
The dimensions can be obtained from getQuiltDimensions().
§Errors
Returns an error if holographic mode is not enabled.
Sourcepub fn set_holographic_camera(
&mut self,
pos_x: f32,
pos_y: f32,
pos_z: f32,
target_x: f32,
target_y: f32,
target_z: f32,
)
pub fn set_holographic_camera( &mut self, pos_x: f32, pos_y: f32, pos_z: f32, target_x: f32, target_y: f32, target_z: f32, )
Set the holographic camera position and target.
§Arguments
pos_x,pos_y,pos_z- Camera position in world spacetarget_x,target_y,target_z- Point the camera looks at
Sourcepub fn get_holographic_preset(&self) -> String
pub fn get_holographic_preset(&self) -> String
Get the current holographic configuration preset name.
Returns “portrait”, “4k”, or “none” if holographic mode is disabled.
Sourcepub fn get_quilt_view_info(&self, view_index: u32) -> JsValue
pub fn get_quilt_view_info(&self, view_index: u32) -> JsValue
Get information about a specific quilt view.
Returns a JS object with view offset, dimensions, and camera position, or null if the view index is out of range or holographic mode is disabled.
Sourcepub fn get_holographic_stats(&self) -> JsValue
pub fn get_holographic_stats(&self) -> JsValue
Get statistics from the holographic renderer.
Returns a JS object with: framesRendered, avgRenderTimeMs, peakRenderTimeMs, totalViewsRendered Returns null if holographic mode is not enabled.
Sourcepub fn reset_holographic_stats(&mut self)
pub fn reset_holographic_stats(&mut self)
Reset holographic rendering statistics.
Sourcepub fn process_voice(
&mut self,
transcript: String,
confidence: f32,
is_final: bool,
timestamp: f64,
) -> JsValue
pub fn process_voice( &mut self, transcript: String, confidence: f32, is_final: bool, timestamp: f64, ) -> JsValue
Process a voice recognition result.
This method handles speech recognition results from the Web Speech API. If a touch event is pending within the fusion window, it will create a fused intent combining the voice command with the touch location.
§Arguments
transcript- The recognized speech textconfidence- Confidence score (0.0 to 1.0)is_final- Whether this is a final (committed) resulttimestamp- Timestamp when the speech was recognized (ms since epoch)
§Returns
JSON-encoded fusion result if fusion occurs, or null if no fusion.
Sourcepub fn has_pending_touch(&self) -> bool
pub fn has_pending_touch(&self) -> bool
Check if there’s a pending touch waiting for voice fusion.
Returns true if a touch event is stored and still within the fusion window.
Sourcepub fn fusion_time_remaining(&self) -> u32
pub fn fusion_time_remaining(&self) -> u32
Get the remaining time in the fusion window for a pending touch.
Returns the time in milliseconds, or 0 if no pending touch or expired.
Sourcepub fn set_fusion_window(&mut self, window_ms: u32)
pub fn set_fusion_window(&mut self, window_ms: u32)
Configure the fusion time window.
Sets how long a touch event waits for a voice command before expiring.
§Arguments
window_ms- Time window in milliseconds (default: 2000)
Sourcepub fn clear_pending_touch(&mut self)
pub fn clear_pending_touch(&mut self)
Clear any pending touch event.
Call this to cancel touch+voice fusion if the user cancels the operation.
Sourcepub fn get_fusion_window(&self) -> u32
pub fn get_fusion_window(&self) -> u32
Get the current fusion window configuration in milliseconds.
Sourcepub fn get_min_voice_confidence(&self) -> f32
pub fn get_min_voice_confidence(&self) -> f32
Get the minimum confidence threshold for voice recognition.
Sourcepub fn set_min_voice_confidence(&mut self, confidence: f32)
pub fn set_min_voice_confidence(&mut self, confidence: f32)
Set the minimum confidence threshold for voice recognition.
Voice events with confidence below this threshold will be ignored.
§Arguments
confidence- Minimum confidence (0.0 to 1.0, default: 0.5)
Trait Implementations§
Source§impl FromWasmAbi for CanvasApp
impl FromWasmAbi for CanvasApp
Source§impl IntoWasmAbi for CanvasApp
impl IntoWasmAbi for CanvasApp
Source§impl LongRefFromWasmAbi for CanvasApp
impl LongRefFromWasmAbi for CanvasApp
Source§impl OptionFromWasmAbi for CanvasApp
impl OptionFromWasmAbi for CanvasApp
Source§impl OptionIntoWasmAbi for CanvasApp
impl OptionIntoWasmAbi for CanvasApp
Source§impl RefFromWasmAbi for CanvasApp
impl RefFromWasmAbi for CanvasApp
Source§impl RefMutFromWasmAbi for CanvasApp
impl RefMutFromWasmAbi for CanvasApp
Source§impl TryFromJsValue for CanvasApp
impl TryFromJsValue for CanvasApp
Source§impl VectorFromWasmAbi for CanvasApp
impl VectorFromWasmAbi for CanvasApp
Source§impl VectorIntoWasmAbi for CanvasApp
impl VectorIntoWasmAbi for CanvasApp
impl SupportsConstructor for CanvasApp
impl SupportsInstanceProperty for CanvasApp
impl SupportsStaticProperty for CanvasApp
Auto Trait Implementations§
impl Freeze for CanvasApp
impl !RefUnwindSafe for CanvasApp
impl !Send for CanvasApp
impl !Sync for CanvasApp
impl Unpin for CanvasApp
impl !UnwindSafe for CanvasApp
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
Source§type Abi = <T as IntoWasmAbi>::Abi
type Abi = <T as IntoWasmAbi>::Abi
IntoWasmAbi::AbiSource§fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
IntoWasmAbi::into_abi, except that it may throw and never
return in the case of Err.