jellyflow_runtime/runtime/drag/
pointer_gesture.rs1use jellyflow_core::core::CanvasPoint;
2use serde::{Deserialize, Serialize};
3
4use crate::runtime::selection::{
5 SelectionPointerClaim, SelectionPointerClaimInput, resolve_selection_pointer_claim,
6};
7
8use super::activation::{NodeDragActivationInput, node_drag_threshold_met};
9
10#[derive(Debug, Clone, Copy, PartialEq)]
12pub struct PointerGestureClaimInput {
13 pub screen_delta: CanvasPoint,
14 pub selection_key_pressed: bool,
15 pub user_selection_active: bool,
16 pub connection_in_progress: bool,
17 pub pane_click_distance: f32,
18 pub node_drag_threshold: f32,
19}
20
21impl PointerGestureClaimInput {
22 pub fn new(
23 screen_delta: CanvasPoint,
24 selection_key_pressed: bool,
25 user_selection_active: bool,
26 connection_in_progress: bool,
27 pane_click_distance: f32,
28 node_drag_threshold: f32,
29 ) -> Self {
30 Self {
31 screen_delta,
32 selection_key_pressed,
33 user_selection_active,
34 connection_in_progress,
35 pane_click_distance,
36 node_drag_threshold,
37 }
38 }
39}
40
41#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
43#[serde(rename_all = "snake_case")]
44pub enum PointerGestureClaim {
45 None,
46 Selection,
47 Connection,
48 NodeDrag,
49}
50
51pub fn resolve_pointer_gesture_claim(input: PointerGestureClaimInput) -> PointerGestureClaim {
52 if input.connection_in_progress {
53 return PointerGestureClaim::Connection;
54 }
55
56 match resolve_selection_pointer_claim(SelectionPointerClaimInput::new(
57 input.screen_delta,
58 input.pane_click_distance,
59 input.selection_key_pressed,
60 input.user_selection_active,
61 )) {
62 SelectionPointerClaim::SelectionOwnsDrag | SelectionPointerClaim::SelectionMayClaimDrag => {
63 PointerGestureClaim::Selection
64 }
65 SelectionPointerClaim::Unclaimed => {
66 if node_drag_threshold_met(NodeDragActivationInput::new(
67 input.screen_delta,
68 input.node_drag_threshold,
69 )) {
70 PointerGestureClaim::NodeDrag
71 } else {
72 PointerGestureClaim::None
73 }
74 }
75 }
76}