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_dimensions(&mut self, cols: u16, rows: u16)
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 countrows- New row count
Trait Implementations§
Source§impl Debug for TerminalMouseHandler
impl Debug for TerminalMouseHandler
Auto Trait Implementations§
impl Freeze for TerminalMouseHandler
impl !RefUnwindSafe for TerminalMouseHandler
impl !Send for TerminalMouseHandler
impl !Sync for TerminalMouseHandler
impl Unpin for TerminalMouseHandler
impl !UnwindSafe for TerminalMouseHandler
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
Mutably borrows from an owned value. Read more