Repository navigation
Expand file tree
/
Copy pathinput.rs
More file actions
54 lines (46 loc) · 1.4 KB
/
Copy pathinput.rs
File metadata and controls
54 lines (46 loc) · 1.4 KB
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
// SPDX-License-Identifier: BSD-3-Clause
//! Device-independent D-pad / X / B / Y / A / Select / Start input.
use crate::igui::Action;
pub const INPUT_DIR: &str = "/dev/input";
pub const ACTIONS: [Action; crate::input_metrics::LOGICAL_EDGE_COUNT] = [
Action::Up,
Action::Down,
Action::Left,
Action::Right,
// Process a focus shortcut before confirmation pressed in the same frame.
Action::Filters,
Action::LowerFilters,
Action::Activate,
Action::Favourite,
Action::Trash,
Action::Start,
];
#[derive(Clone, Copy, Default, Debug, PartialEq, Eq)]
pub struct Buttons(u16);
impl Buttons {
/// Set or clear one logical button in this snapshot.
pub fn set(&mut self, action: Action, down: bool) {
let bit = 1 << action as u8;
if down {
self.0 |= bit;
} else {
self.0 &= !bit;
}
}
/// Report whether a particular logical button is held.
pub fn down(self, action: Action) -> bool {
self.0 & (1 << action as u8) != 0
}
/// Report whether at least one logical button is held.
pub fn any(self) -> bool {
self.0 != 0
}
/// Return only buttons held in both snapshots.
pub fn intersect(self, other: Self) -> Self {
Self(self.0 & other.0)
}
/// Return buttons held in either snapshot.
pub fn union(self, other: Self) -> Self {
Self(self.0 | other.0)
}
}