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
impl TerminalMouseHandler
Sourcepub fn new<F>(
canvas: &HtmlCanvasElement,
grid: Rc<RefCell<TerminalGrid>>,
event_handler: F,
) -> Result<Self, Error>
pub fn new<F>( canvas: &HtmlCanvasElement, grid: Rc<RefCell<TerminalGrid>>, event_handler: F, ) -> Result<Self, Error>
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 togrid- The terminal grid for coordinate calculationsevent_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();Sourcepub fn cleanup(&self)
pub fn cleanup(&self)
Removes all event listeners from the canvas.
Called automatically on drop. Safe to call multiple times.
Sourcepub fn update_metrics(
&mut self,
cols: u16,
rows: u16,
cell_width: f32,
cell_height: f32,
)
pub fn update_metrics( &mut self, cols: u16, rows: u16, cell_width: f32, cell_height: f32, )
Updates the cached terminal metrics.
Should be called when the terminal is resized or the font atlas is replaced to ensure accurate pixel-to-cell coordinate conversion.
§Arguments
cols- New column countrows- New row countcell_width- New cell width in CSS pixels (can be fractional)cell_height- New cell height in CSS pixels (can be fractional)