web_event/mouse_event/click/
mod.rs

1use js_sys::Array;
2use std::fmt::{Debug, Formatter};
3use wasm_bindgen::JsCast;
4use web_sys::{Event, PointerEvent};
5
6/// - Bubbles: Yes
7/// - Cancelable: Yes
8/// - Event type: [`Event`] :> [`UiEvent`] :> [`MouseEvent`] :> [`PointerEvent`]
9/// - Supported HTML tags: All HTML elements, EXCEPT: `<base>`, `<bdo>`, `<br>`, `<head>`, `<html>`,
10///   `<iframe>`, `<meta>`, `<param>`, `<script>`, `<style>`, `<title>`
11#[derive(Clone)]
12pub struct OnClick {
13    inner: PointerEvent,
14}
15
16impl Debug for OnClick {
17    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
18        f.write_str("OnClickEvent")
19    }
20}
21
22impl From<Event> for OnClick {
23    fn from(e: Event) -> Self {
24        Self { inner: e.unchecked_into() }
25    }
26}
27
28/// methods inherit from [`PointerEvent`]
29impl OnClick {
30    /// Getter for the `pointerId` field of this object.
31    ///
32    /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/pointerId)
33    #[inline]
34    pub fn pointer_id(&self) -> i32 {
35        self.inner.pointer_id()
36    }
37    /// Getter for the `width` field of this object.
38    ///
39    /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/width)
40    #[inline]
41    pub fn width(&self) -> i32 {
42        self.inner.width()
43    }
44    /// Getter for the `height` field of this object.
45    ///
46    /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/height)
47    #[inline]
48    pub fn height(&self) -> i32 {
49        self.inner.height()
50    }
51    /// Getter for the `pressure` field of this object.
52    ///
53    /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/pressure)
54    #[inline]
55    pub fn pressure(&self) -> f32 {
56        self.inner.pressure()
57    }
58    /// Getter for the `tangentialPressure` field of this object.
59    ///
60    /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/tangentialPressure)
61    #[inline]
62    pub fn tangential_pressure(&self) -> f32 {
63        self.inner.tangential_pressure()
64    }
65    /// Getter for the `tiltX` field of this object.
66    ///
67    /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/tiltX)
68    #[inline]
69    pub fn tilt_x(&self) -> i32 {
70        self.inner.tilt_x()
71    }
72    /// Getter for the `tiltY` field of this object.
73    ///
74    /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/tiltY)
75    #[inline]
76    pub fn tilt_y(&self) -> i32 {
77        self.inner.tilt_y()
78    }
79    /// Getter for the `twist` field of this object.
80    ///
81    /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/twist)
82    #[inline]
83    pub fn twist(&self) -> i32 {
84        self.inner.twist()
85    }
86    /// Getter for the `pointerType` field of this object.
87    ///
88    /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/pointerType)
89    #[inline]
90    pub fn pointer_type(&self) -> String {
91        self.inner.pointer_type()
92    }
93    /// Getter for the `isPrimary` field of this object.
94    ///
95    /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/isPrimary)
96    #[inline]
97    pub fn is_primary(&self) -> bool {
98        self.inner.is_primary()
99    }
100    /// The `getCoalescedEvents()` method.
101    ///
102    /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/getCoalescedEvents)
103    #[inline]
104    pub fn get_coalesced_events(&self) -> Array {
105        self.inner.get_coalesced_events()
106    }
107}