qualia_app_contract/
gesture.rs1use crate::error::ContractError;
4use crate::id::DecimalU64;
5use crate::target::{CommandTarget, PointerHit};
6use serde::{Deserialize, Serialize};
7
8#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10pub struct GestureSession {
11 pub gesture_id: String,
12 pub session_id: String,
13 pub tool_id: String,
14 pub start_revision: DecimalU64,
15 pub initial_point: PointerHit,
16 #[serde(default, skip_serializing_if = "Vec::is_empty")]
17 pub samples: Vec<PointerHit>,
18 pub is_cancelled: bool,
19}
20
21impl GestureSession {
22 pub fn new(
24 gesture_id: impl Into<String>,
25 session_id: impl Into<String>,
26 tool_id: impl Into<String>,
27 start_revision: DecimalU64,
28 initial_point: PointerHit,
29 ) -> Self {
30 Self {
31 gesture_id: gesture_id.into(),
32 session_id: session_id.into(),
33 tool_id: tool_id.into(),
34 start_revision,
35 initial_point,
36 samples: Vec::new(),
37 is_cancelled: false,
38 }
39 }
40
41 pub fn push_sample(&mut self, sample: PointerHit) -> Result<(), ContractError> {
43 if self.is_cancelled {
44 return Err(ContractError::MalformedParams("cannot push sample to cancelled gesture".into()));
45 }
46 self.samples.push(sample);
47 Ok(())
48 }
49
50 pub fn cancel(&mut self) {
52 self.is_cancelled = true;
53 }
54}
55
56#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
58pub struct GestureUpdate {
59 pub gesture_id: String,
60 pub samples: Vec<PointerHit>,
61}
62
63#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
65pub struct GestureCommit {
66 pub gesture_id: String,
67 pub target: CommandTarget,
68 pub final_point: PointerHit,
69}
70
71#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
73pub struct GestureCancel {
74 pub gesture_id: String,
75 pub reason: String,
76}