Skip to main content

WebRenderer

Trait WebRenderer 

Source
pub trait WebRenderer {
    // Required methods
    fn draw_web<F>(self, render_callback: F)
       where F: FnMut(&mut Frame<'_>) + 'static;
    fn on_key_event<F>(&mut self, callback: F) -> Result<(), Error>
       where F: FnMut(KeyEvent) + 'static;
    fn on_mouse_event<F>(&mut self, callback: F) -> Result<(), Error>
       where F: FnMut(MouseEvent) + 'static;

    // Provided method
    fn request_animation_frame(f: &Closure<dyn FnMut()>) { ... }
}
Expand description

Trait for rendering on the web.

It provides all the necessary methods to render the terminal on the web and also interact with the browser such as handling key and mouse events.

Required Methods§

Source

fn draw_web<F>(self, render_callback: F)
where F: FnMut(&mut Frame<'_>) + 'static,

Renders the terminal on the web.

This method takes a closure that will be called on every update that the browser makes during requestAnimationFrame calls.

Source

fn on_key_event<F>(&mut self, callback: F) -> Result<(), Error>
where F: FnMut(KeyEvent) + 'static,

Handles key events.

This method takes a closure that will be called on every keydown event.

§Errors

Returns an error if the backend does not support key events or if event listener attachment fails.

Source

fn on_mouse_event<F>(&mut self, callback: F) -> Result<(), Error>
where F: FnMut(MouseEvent) + 'static,

Handles mouse events.

This method takes a closure that will be called on mouse events. The callback receives MouseEvents with terminal grid coordinates (col, row) instead of raw pixel coordinates.

§Errors

Returns an error if event listener attachment fails.

Provided Methods§

Source

fn request_animation_frame(f: &Closure<dyn FnMut()>)

Requests an animation frame.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<T> WebRenderer for Terminal<T>
where T: Backend + WebEventHandler + 'static,

Implement WebRenderer for Ratatui’s Terminal.

This implementation delegates event handling to the backend’s WebEventHandler implementation.

Source§

fn draw_web<F>(self, render_callback: F)
where F: FnMut(&mut Frame<'_>) + 'static,

Source§

fn on_key_event<F>(&mut self, callback: F) -> Result<(), Error>
where F: FnMut(KeyEvent) + 'static,

Source§

fn on_mouse_event<F>(&mut self, callback: F) -> Result<(), Error>
where F: FnMut(MouseEvent) + 'static,

Implementors§