ragnarok/
name.rs

1use std::collections::HashSet;
2
3pub trait NameOfEvent:
4    Clone + PartialEq + Eq + std::hash::Hash + Copy + std::fmt::Debug + Eq + Ord
5{
6    /// Check if this event means that the pointer device as moved while hovering a node.
7    fn is_moved(&self) -> bool;
8    /// Check if this event means that the pointer device started hovering a node.
9    fn is_enter(&self) -> bool;
10    /// Check if this enter event should only fire on the deepest (most specific) node,
11    /// not on all nodes under the cursor simultaneously.
12    fn is_exclusive_enter(&self) -> bool {
13        false
14    }
15    /// Check if this event means that the pointer device was pressed while hovering a node.
16    fn is_pressed(&self) -> bool;
17    /// Check if this event means that the pointer device was released while hovering and hovering a node.
18    fn is_released(&self) -> bool;
19    /// Check if this event is global, where global means that an event will be emitted to every node independently of where they are or how they are.
20    fn is_global(&self) -> bool;
21
22    /// Check if this event bubbles, where bubbling means that an ancestor of the event node will be called with the same event unless the event node stops the bubbling.
23    fn does_bubble(&self) -> bool;
24    /// Check if this event can go through solid surfaces, e.g keyboard events.
25    fn does_go_through_solid(&self) -> bool;
26
27    /// Check if this leave event corresponds to an exclusive enter
28    fn is_exclusive_leave(&self) -> bool {
29        false
30    }
31
32    /// Create a new event that means the pointer device left a hovering node.
33    fn new_leave() -> Self;
34    /// Create a new exclusive leave event for when the deepest (entered) node changes
35    /// without the node necessarily leaving the cursor area entirely.
36    fn new_exclusive_leave() -> Self;
37    /// Create a new exclusive leave event for when the deepest (entered) node changes
38    /// without the node necessarily leaving the cursor area entirely.
39    fn new_exclusive_enter() -> Self;
40
41    /// Get a set of events derived from this event. For example, mouse movement derives into mouse movement + mouse enter.
42    fn get_derived_events(&self) -> HashSet<Self>;
43    /// Get a set of global events derived from this event.
44    fn get_global_events(&self) -> HashSet<Self> {
45        HashSet::new()
46    }
47    /// Get a set of events that will be discarded once this event is cancelled.
48    fn get_cancellable_events(&self) -> HashSet<Self> {
49        HashSet::from([*self])
50    }
51}