1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//! Viewport gesture and binding types for the new input pipeline.
use super::action::Action;
use super::binding::{KeyCode, Modifiers, MouseButton};
/// Modifier matching policy for viewport gestures.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum ModifiersMatch {
/// All specified modifier bits must match exactly — no extras.
Exact(Modifiers),
/// All specified modifier bits must be set; extras are allowed.
Contains(Modifiers),
/// Any modifier state is accepted.
Any,
}
impl ModifiersMatch {
/// Test whether the given modifier state satisfies this policy.
pub fn matches(&self, mods: Modifiers) -> bool {
match self {
ModifiersMatch::Exact(required) => mods == *required,
ModifiersMatch::Contains(required) => {
// every set bit in `required` must also be set in `mods`
(!required.alt || mods.alt)
&& (!required.shift || mods.shift)
&& (!required.ctrl || mods.ctrl)
}
ModifiersMatch::Any => true,
}
}
}
/// A viewport gesture — the richer gesture vocabulary used by the new pipeline.
#[derive(Debug, Clone)]
pub enum ViewportGesture {
/// A mouse drag with a specific button and modifier policy.
Drag {
/// Which button must be held to drag.
button: MouseButton,
/// Required modifier state.
modifiers: ModifiersMatch,
},
/// Vertical wheel delta with a modifier policy.
///
/// Produces a single scalar output (the `y` component of the wheel delta).
WheelY {
/// Required modifier state.
modifiers: ModifiersMatch,
},
/// Full two-axis wheel delta with a modifier policy.
///
/// Produces a [`glam::Vec2`] output.
WheelXY {
/// Required modifier state.
modifiers: ModifiersMatch,
},
/// A single key press — fires once on the initial press, not on repeat.
KeyPress {
/// The key that must be pressed.
key: KeyCode,
/// Required modifier state.
modifiers: ModifiersMatch,
},
/// A key held down — fires every frame while the key is held.
KeyHold {
/// The key that must be held.
key: KeyCode,
/// Required modifier state.
modifiers: ModifiersMatch,
},
}
/// Binds an [`Action`] to a [`ViewportGesture`].
#[derive(Debug, Clone)]
pub struct ViewportBinding {
/// The action this binding fires.
pub action: Action,
/// The gesture that activates it.
pub gesture: ViewportGesture,
}
impl ViewportBinding {
/// Convenience constructor.
pub fn new(action: Action, gesture: ViewportGesture) -> Self {
Self { action, gesture }
}
}