You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.8 KiB

type _ t =
| Keyboard : Jv.t -> [> `Keyboard ] t
| Mouse : Jv.t -> [> `Mouse ] t
| Error : Jv.t -> [> `Error ] t
| Basic : Jv.t -> [> `Basic ] t
type _ sub =
| Click : [> `Mouse ] sub
| Move_end : [> `Basic ] sub
| Zoom_end : [> `Basic ] sub
let of_jv : type kind. kind sub -> Jv.t -> kind t =
fun tag e ->
match tag with Click -> Mouse e | Move_end -> Basic e | Zoom_end -> Basic e
let sub_to_string : type kind. kind sub -> string = function
| Click -> "click"
| Move_end -> "moveend"
| Zoom_end -> "zoomend"
(** Basic events *)
let get_type : type kind. kind t -> string = function
| Keyboard e | Mouse e | Error e | Basic e -> Jv.get e "type" |> Jv.to_string
let target : type kind. kind t -> Brr.Ev.target = function
| Keyboard e | Mouse e | Error e | Basic e ->
Jv.get e "target" |> Brr.Ev.target_of_jv
let source_target : type kind. kind t -> Brr.Ev.target = function
| Keyboard e | Mouse e | Error e | Basic e ->
Jv.get e "sourceTarget" |> Brr.Ev.target_of_jv
let propagated_from : type kind. kind t -> Jv.t = function
| Keyboard e | Mouse e | Error e | Basic e -> Jv.get e "propagatedFrom"
(** Keyboard & Mouse events *)
let original_event : [ `Keyboard | `Mouse ] t -> Jv.t = function
| Keyboard e | Mouse e -> Jv.get e "originalEvent"
(** Mouse events *)
let container_point : [ `Mouse ] t -> Jv.t = function
| Mouse e -> Jv.get e "containerPoint"
let layer_point : [ `Mouse ] t -> Jv.t = function
| Mouse e -> Jv.get e "layerPoint"
let latlng : [ `Mouse ] t -> Latlng.t = function
| Mouse e -> Jv.get e "latlng" |> Latlng.of_jv
(** Error events *)
let code : [ `Error ] t -> int = function
| Error e -> Jv.get e "code" |> Jv.to_int
let message : [ `Error ] t -> string = function
| Error e -> Jv.get e "message" |> Jv.to_string