TerminalMouseHandler

Struct TerminalMouseHandler 

Source
pub struct TerminalMouseHandler { /* private fields */ }
Expand description

Handles mouse input events for a terminal grid.

Converts browser mouse events into terminal grid coordinates and manages event handlers for mouse interactions. Maintains terminal dimensions for accurate coordinate mapping.

Implementations§

Source§

impl TerminalMouseHandler

Source

pub fn new<F>( canvas: &HtmlCanvasElement, grid: Rc<RefCell<TerminalGrid>>, event_handler: F, ) -> Result<Self, Error>
where F: FnMut(TerminalMouseEvent, &TerminalGrid) + 'static,

Creates a new mouse handler for the given canvas and terminal grid.

Sets up mouse event listeners on the canvas and converts pixel coordinates to terminal cell coordinates before invoking the provided event handler.

§Arguments
  • canvas - The HTML canvas element to attach mouse listeners to
  • grid - The terminal grid for coordinate calculations
  • event_handler - Callback invoked for each mouse event
§Errors

Returns Error::Callback if event listeners cannot be attached to the canvas.

§Example
use beamterm_renderer::mouse::TerminalMouseHandler;
use std::{cell::RefCell, rc::Rc};

let canvas = unimplemented!("canvas");
let grid: Rc<RefCell<()>> = unimplemented!("TerminalGrid");

// In real code, this would be TerminalGrid
// let handler = TerminalMouseHandler::new(
//     &canvas,
//     grid.clone(),
//     |event, grid| {
//         println!("Click at ({}, {})", event.col, event.row);
//     }
// ).unwrap();
Source

pub fn cleanup(&self)

Removes all event listeners from the canvas.

Called automatically on drop. Safe to call multiple times.

Source

pub fn update_dimensions(&mut self, cols: u16, rows: u16)

Updates the cached terminal dimensions.

Should be called when the terminal is resized to ensure accurate coordinate conversion.

§Arguments
  • cols - New column count
  • rows - New row count

Trait Implementations§

Source§

impl Debug for TerminalMouseHandler

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for TerminalMouseHandler

Source§

fn drop(&mut self)

Automatically removes event listeners when handler is dropped.

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> 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<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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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.