jellyflow_runtime/runtime/drag/
types.rs1use serde::{Deserialize, Serialize};
2
3use jellyflow_core::core::{CanvasPoint, NodeId};
4use jellyflow_core::ops::GraphTransaction;
5
6pub const NODE_DRAG_TRANSACTION_LABEL: &str = "node drag";
8
9pub const NODE_NUDGE_TRANSACTION_LABEL: &str = "node nudge";
11
12#[derive(Debug, Clone, Copy, PartialEq)]
17pub struct NodeDragRequest {
18 pub node: NodeId,
20 pub to: CanvasPoint,
22}
23
24#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
26#[serde(rename_all = "snake_case")]
27pub enum NodeNudgeDirection {
28 Up,
29 Down,
30 Left,
31 Right,
32}
33
34impl NodeNudgeDirection {
35 pub fn unit_delta(self) -> CanvasPoint {
36 match self {
37 Self::Up => CanvasPoint { x: 0.0, y: -1.0 },
38 Self::Down => CanvasPoint { x: 0.0, y: 1.0 },
39 Self::Left => CanvasPoint { x: -1.0, y: 0.0 },
40 Self::Right => CanvasPoint { x: 1.0, y: 0.0 },
41 }
42 }
43}
44
45#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
47pub struct NodeNudgeRequest {
48 pub direction: NodeNudgeDirection,
49 pub fast: bool,
50}
51
52#[derive(Debug, Clone, Copy, PartialEq)]
54pub struct NodeDragItem {
55 pub node: NodeId,
57 pub from: CanvasPoint,
59 pub to: CanvasPoint,
61}
62
63#[derive(Debug, Clone)]
65pub struct NodeDragPlan {
66 pub node: NodeId,
68 pub from: CanvasPoint,
70 pub to: CanvasPoint,
72 items: Vec<NodeDragItem>,
73 transaction: GraphTransaction,
74}
75
76#[derive(Debug, Clone)]
78pub struct NodeNudgePlan {
79 pub direction: NodeNudgeDirection,
81 pub delta: CanvasPoint,
83 items: Vec<NodeDragItem>,
84 transaction: GraphTransaction,
85}
86
87impl NodeDragPlan {
88 pub(super) fn new(
89 node: NodeId,
90 from: CanvasPoint,
91 to: CanvasPoint,
92 items: Vec<NodeDragItem>,
93 transaction: GraphTransaction,
94 ) -> Self {
95 Self {
96 node,
97 from,
98 to,
99 items,
100 transaction,
101 }
102 }
103
104 pub fn items(&self) -> &[NodeDragItem] {
106 &self.items
107 }
108
109 pub fn transaction(&self) -> &GraphTransaction {
111 &self.transaction
112 }
113
114 pub fn into_transaction(self) -> GraphTransaction {
116 self.transaction
117 }
118}
119
120impl NodeNudgePlan {
121 pub(super) fn new(
122 direction: NodeNudgeDirection,
123 delta: CanvasPoint,
124 items: Vec<NodeDragItem>,
125 transaction: GraphTransaction,
126 ) -> Self {
127 Self {
128 direction,
129 delta,
130 items,
131 transaction,
132 }
133 }
134
135 pub fn items(&self) -> &[NodeDragItem] {
137 &self.items
138 }
139
140 pub fn transaction(&self) -> &GraphTransaction {
142 &self.transaction
143 }
144
145 pub fn into_transaction(self) -> GraphTransaction {
147 self.transaction
148 }
149}