1use crate::{Error, Orientation};
3#[derive(Clone, Copy, Debug, PartialEq, Eq)]
4pub struct SwipeCapture {
5 pub axis: Orientation,
6 pub revision: u64,
7}
8impl SwipeCapture {
9 pub fn axis_name(self) -> &'static str {
10 match self.axis {
11 Orientation::Horizontal => "horizontal",
12 Orientation::Vertical => "vertical",
13 }
14 }
15}
16pub(crate) fn revision(old: Option<SwipeCapture>, next: Option<SwipeCapture>) -> Result<(), Error> {
17 if let (Some(old), Some(next)) = (old, next) {
18 if next.revision < old.revision {
19 return Err(Error::InputRevision {
20 current: old.revision,
21 incoming: next.revision,
22 });
23 }
24 if next.revision == old.revision && next.axis != old.axis {
25 return Err(Error::InvalidProps(
26 "equal swipe revision requires equal configuration",
27 ));
28 }
29 }
30 Ok(())
31}
32#[derive(Clone, Debug)]
33pub(crate) struct State {
34 pub revision: u64,
35}
36impl State {
37 pub fn new(capture: SwipeCapture) -> Box<Self> {
38 Box::new(Self {
39 revision: capture.revision,
40 })
41 }
42}