tauri_plugin_prevent_default/shortcut/
pointer.rs

1use crate::display;
2use std::fmt;
3use strum::{Display as EnumDisplay, EnumIs, EnumString};
4
5#[non_exhaustive]
6#[derive(Clone, Copy, Debug, PartialEq, Eq, EnumDisplay, EnumIs, EnumString)]
7#[strum(serialize_all = "lowercase")]
8pub enum PointerEvent {
9  ContextMenu,
10}
11
12#[derive(Debug)]
13pub struct PointerShortcut {
14  event: PointerEvent,
15}
16
17impl PointerShortcut {
18  pub fn new(event: PointerEvent) -> Self {
19    Self { event }
20  }
21
22  /// Initialize a new pointer shortcut builder with the specified event.
23  pub fn builder(event: PointerEvent) -> PointerShortcutBuilder {
24    PointerShortcutBuilder::new(event)
25  }
26
27  /// The event of the shortcut.
28  pub fn event(&self) -> PointerEvent {
29    self.event
30  }
31}
32
33impl fmt::Display for PointerShortcut {
34  fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
35    write!(f, "{}", display::pointer(self.event))
36  }
37}
38
39#[derive(Debug)]
40pub struct PointerShortcutBuilder {
41  event: PointerEvent,
42}
43
44impl PointerShortcutBuilder {
45  pub fn new(event: PointerEvent) -> Self {
46    Self { event }
47  }
48
49  /// Build the pointer shortcut.
50  pub fn build(self) -> PointerShortcut {
51    PointerShortcut { event: self.event }
52  }
53}