moly_kit/utils/makepad/
hits.rs1use makepad_widgets::*;
4
5pub trait HitExt {
6 fn primary_pointer_action_pos(&self) -> Option<DVec2>;
8 fn secondary_pointer_action_pos(&self) -> Option<DVec2>;
10 fn is_primary_pointer_action(&self) -> bool;
12 fn is_secondary_pointer_action(&self) -> bool;
14}
15
16impl HitExt for Hit {
17 fn primary_pointer_action_pos(&self) -> Option<DVec2> {
18 match self {
19 Hit::FingerUp(fu)
20 if fu.was_tap()
21 && ((fu.is_mouse() && fu.mouse_button().unwrap().is_primary())
22 || fu.is_touch()) =>
23 {
24 Some(fu.abs)
25 }
26 _ => None,
27 }
28 }
29
30 fn secondary_pointer_action_pos(&self) -> Option<DVec2> {
31 match self {
32 Hit::FingerUp(fu)
33 if fu.was_tap() && fu.is_mouse() && fu.mouse_button().unwrap().is_secondary() =>
34 {
35 Some(fu.abs)
36 }
37 Hit::FingerLongPress(flp) => Some(flp.abs),
38 _ => None,
39 }
40 }
41
42 fn is_primary_pointer_action(&self) -> bool {
43 self.primary_pointer_action_pos().is_some()
44 }
45
46 fn is_secondary_pointer_action(&self) -> bool {
47 self.secondary_pointer_action_pos().is_some()
48 }
49}