package miaou-core
Install
dune-project
Dependency
Authors
Maintainers
Sources
md5=60a3b9f181f24572a06a9492532bfdda
sha512=fcc35a275066be2900e6201782faf47503076fa4640f08cf78067835a6f447b74613009e55b2ac799adb7ca46f1bffa261fc5971753f2cc3c6bef327511c7ef6
doc/miaou-core.helpers/Miaou_helpers/Mouse/index.html
Module Miaou_helpers.MouseSource
Mouse event parsing utilities for widgets.
Provides helpers to parse mouse key strings dispatched by drivers (e.g., "Mouse:5:10", "MouseDrag:3:7", "WheelUp", "WheelDown").
Usage
let handle_key t ~key =
if Mouse.is_wheel_up key then
scroll_up t Mouse.wheel_scroll_lines
else if Mouse.is_wheel_down key then
scroll_down t Mouse.wheel_scroll_lines
else
match Mouse.parse_click key with
| Some {row; col} -> handle_click t ~row ~col
| None -> (* not a mouse event *) tMouse click/drag event with terminal coordinates (1-indexed).
Parse a "Mouse:row:col", "DoubleClick:row:col", "TripleClick:row:col", or "MouseDrag:row:col" key string.
Check if key is a mouse click event ("Mouse:...").
Check if key is a double-click event ("DoubleClick:...").
Check if key is a triple-click event ("TripleClick:...").
Check if key is a mouse drag event ("MouseDrag:...").
Check if key is a wheel up event ("WheelUp").
Check if key is a wheel down event ("WheelDown").
Check if key is any wheel event (up or down).
Check if key is any mouse-related event (click, drag, or wheel).
Default scroll amount for wheel events (number of lines). Currently set to 3.
Translate mouse coordinates by subtracting offsets. Used to convert screen-absolute coordinates to widget-relative coordinates. For click/drag events: subtracts row_offset from row and col_offset from col. For non-mouse or wheel events: returns the key unchanged.
Example
(* Modal is at row 5, col 10 on screen *)
let modal_row = 5 in
let modal_col = 10 in
(* Screen click at row 8, col 15 becomes widget-relative row 3, col 5 *)
let relative_key = Mouse.translate_key ~row_offset:modal_row ~col_offset:modal_col "Mouse:8:15" in
(* relative_key = "Mouse:3:5" *)