accelerometer/orientation.rs
1//! Orientation tracking for accelerometer-equipped devices.
2
3mod tracker;
4
5pub use self::tracker::Tracker;
6
7/// Device orientation as computed from accelerometer data
8#[derive(Copy, Clone, Debug, Eq, PartialEq)]
9pub enum Orientation {
10 /// Unable to determine the orientation from current data
11 Unknown,
12
13 /// Device is in portrait mode in whatever way is considered "up"
14 PortraitUp,
15
16 /// Device is in portrait mode in whatever way is considered "down"
17 PortraitDown,
18
19 /// Device is in landscape mode in whatever way is considered "up"
20 LandscapeUp,
21
22 /// Device is in landscape mode in whatever way is considered "down"
23 LandscapeDown,
24
25 /// Device is parallel to the ground, facing up
26 FaceUp,
27
28 /// Device is parallel to the ground, facing down
29 FaceDown,
30}
31
32impl Orientation {
33 /// Is this orientation considered to be flat?
34 pub fn is_flat(self) -> bool {
35 match self {
36 Orientation::FaceUp | Orientation::FaceDown => true,
37 _ => false,
38 }
39 }
40
41 /// Is the device in a landscape orientation?
42 pub fn is_landscape(self) -> bool {
43 match self {
44 Orientation::LandscapeUp | Orientation::LandscapeDown => true,
45 _ => false,
46 }
47 }
48
49 /// Is the device in a portrait orientation?
50 pub fn is_portrait(self) -> bool {
51 match self {
52 Orientation::PortraitUp | Orientation::PortraitDown => true,
53 _ => false,
54 }
55 }
56}