Skip to main content

jellyflow_runtime/runtime/conformance/scenario/action/
viewport.rs

1use crate::runtime::auto_pan::{AutoPanRequest, SelectionAutoPanRequest};
2use crate::runtime::viewport::{
3    ViewportAnimationFrame, ViewportAnimationPlan, ViewportAnimationRequest,
4    ViewportDoubleClickZoomInput, ViewportDragPanInput, ViewportGestureContext,
5    ViewportGestureRejection, ViewportPanInertiaFrame, ViewportPanInertiaRequest,
6    ViewportPanRequest, ViewportScrollInput, ViewportZoomRequest,
7};
8use jellyflow_core::core::CanvasSize;
9
10use super::ConformanceAction;
11
12pub(super) fn kind(action: &ConformanceAction) -> Option<&'static str> {
13    Some(match action {
14        ConformanceAction::ApplyAutoPan { .. } => "apply_auto_pan",
15        ConformanceAction::ApplySelectionAutoPan { .. } => "apply_selection_auto_pan",
16        ConformanceAction::ApplyViewportPan { .. } => "apply_viewport_pan",
17        ConformanceAction::ApplyViewportPanConstrained { .. } => "apply_viewport_pan_constrained",
18        ConformanceAction::ApplyViewportZoom { .. } => "apply_viewport_zoom",
19        ConformanceAction::ApplyViewportZoomConstrained { .. } => "apply_viewport_zoom_constrained",
20        ConformanceAction::ApplyViewportAnimationFrame { .. } => "apply_viewport_animation_frame",
21        ConformanceAction::ApplyViewportAnimationFrames { .. } => "apply_viewport_animation_frames",
22        ConformanceAction::AssertViewportAnimationFrame { .. } => "assert_viewport_animation_frame",
23        ConformanceAction::ApplyViewportPanInertiaFrame { .. } => {
24            "apply_viewport_pan_inertia_frame"
25        }
26        ConformanceAction::ApplyViewportPanInertiaFrames { .. } => {
27            "apply_viewport_pan_inertia_frames"
28        }
29        ConformanceAction::AssertViewportPanInertiaFrame { .. } => {
30            "assert_viewport_pan_inertia_frame"
31        }
32        ConformanceAction::ExpectViewportPanInertiaRejected { .. } => {
33            "expect_viewport_pan_inertia_rejected"
34        }
35        ConformanceAction::AssertViewportDoubleClickZoom { .. } => {
36            "assert_viewport_double_click_zoom"
37        }
38        ConformanceAction::ApplyViewportScrollGesture { .. } => "apply_viewport_scroll_gesture",
39        ConformanceAction::ApplyViewportDragPanGesture { .. } => "apply_viewport_drag_pan_gesture",
40        ConformanceAction::ApplyViewportDragPanSession { .. } => "apply_viewport_drag_pan_session",
41        _ => return None,
42    })
43}
44
45impl ConformanceAction {
46    pub fn apply_auto_pan(request: AutoPanRequest) -> Self {
47        Self::ApplyAutoPan { request }
48    }
49
50    pub fn apply_selection_auto_pan(request: SelectionAutoPanRequest) -> Self {
51        Self::ApplySelectionAutoPan { request }
52    }
53
54    pub fn apply_viewport_pan(request: ViewportPanRequest) -> Self {
55        Self::ApplyViewportPan { request }
56    }
57
58    pub fn apply_viewport_pan_constrained(
59        request: ViewportPanRequest,
60        viewport_size: CanvasSize,
61    ) -> Self {
62        Self::ApplyViewportPanConstrained {
63            request,
64            viewport_size,
65        }
66    }
67
68    pub fn apply_viewport_zoom(request: ViewportZoomRequest) -> Self {
69        Self::ApplyViewportZoom { request }
70    }
71
72    pub fn apply_viewport_zoom_constrained(
73        request: ViewportZoomRequest,
74        viewport_size: CanvasSize,
75    ) -> Self {
76        Self::ApplyViewportZoomConstrained {
77            request,
78            viewport_size,
79        }
80    }
81
82    pub fn apply_viewport_animation_frame(
83        request: ViewportAnimationRequest,
84        elapsed_seconds: f32,
85    ) -> Self {
86        Self::ApplyViewportAnimationFrame {
87            request,
88            elapsed_seconds,
89        }
90    }
91
92    pub fn apply_viewport_animation_frames(
93        request: ViewportAnimationRequest,
94        elapsed_seconds: impl IntoIterator<Item = f32>,
95    ) -> Self {
96        Self::ApplyViewportAnimationFrames {
97            request,
98            elapsed_seconds: elapsed_seconds.into_iter().collect(),
99        }
100    }
101
102    pub fn assert_viewport_animation_frame(
103        request: ViewportAnimationRequest,
104        elapsed_seconds: f32,
105        expected: ViewportAnimationFrame,
106    ) -> Self {
107        Self::AssertViewportAnimationFrame {
108            request,
109            elapsed_seconds,
110            expected,
111        }
112    }
113
114    pub fn apply_viewport_pan_inertia_frame(
115        request: ViewportPanInertiaRequest,
116        elapsed_seconds: f32,
117    ) -> Self {
118        Self::ApplyViewportPanInertiaFrame {
119            request,
120            elapsed_seconds,
121        }
122    }
123
124    pub fn apply_viewport_pan_inertia_frames(
125        request: ViewportPanInertiaRequest,
126        elapsed_seconds: impl IntoIterator<Item = f32>,
127    ) -> Self {
128        Self::ApplyViewportPanInertiaFrames {
129            request,
130            elapsed_seconds: elapsed_seconds.into_iter().collect(),
131        }
132    }
133
134    pub fn assert_viewport_pan_inertia_frame(
135        request: ViewportPanInertiaRequest,
136        elapsed_seconds: f32,
137        expected: ViewportPanInertiaFrame,
138    ) -> Self {
139        Self::AssertViewportPanInertiaFrame {
140            request,
141            elapsed_seconds,
142            expected,
143        }
144    }
145
146    pub fn expect_viewport_pan_inertia_rejected(request: ViewportPanInertiaRequest) -> Self {
147        Self::ExpectViewportPanInertiaRejected { request }
148    }
149
150    pub fn assert_viewport_double_click_zoom(
151        input: ViewportDoubleClickZoomInput,
152        expected: ViewportAnimationPlan,
153    ) -> Self {
154        Self::AssertViewportDoubleClickZoom {
155            input,
156            expected: Some(expected),
157            expect_rejection: None,
158        }
159    }
160
161    pub fn expect_viewport_double_click_zoom_rejected(
162        input: ViewportDoubleClickZoomInput,
163        rejection: ViewportGestureRejection,
164    ) -> Self {
165        Self::AssertViewportDoubleClickZoom {
166            input,
167            expected: None,
168            expect_rejection: Some(rejection),
169        }
170    }
171
172    pub fn apply_viewport_scroll_gesture(
173        context: ViewportGestureContext,
174        input: ViewportScrollInput,
175    ) -> Self {
176        Self::ApplyViewportScrollGesture {
177            context,
178            input,
179            expect_rejection: None,
180        }
181    }
182
183    pub fn expect_viewport_scroll_gesture_rejected(
184        context: ViewportGestureContext,
185        input: ViewportScrollInput,
186        rejection: ViewportGestureRejection,
187    ) -> Self {
188        Self::ApplyViewportScrollGesture {
189            context,
190            input,
191            expect_rejection: Some(rejection),
192        }
193    }
194
195    pub fn apply_viewport_drag_pan_gesture(
196        context: ViewportGestureContext,
197        input: ViewportDragPanInput,
198    ) -> Self {
199        Self::ApplyViewportDragPanGesture {
200            context,
201            input,
202            expect_rejection: None,
203        }
204    }
205
206    pub fn expect_viewport_drag_pan_gesture_rejected(
207        context: ViewportGestureContext,
208        input: ViewportDragPanInput,
209        rejection: ViewportGestureRejection,
210    ) -> Self {
211        Self::ApplyViewportDragPanGesture {
212            context,
213            input,
214            expect_rejection: Some(rejection),
215        }
216    }
217
218    pub fn apply_viewport_drag_pan_session(
219        context: ViewportGestureContext,
220        input: ViewportDragPanInput,
221    ) -> Self {
222        Self::ApplyViewportDragPanSession {
223            context,
224            input,
225            expect_rejection: None,
226        }
227    }
228
229    pub fn expect_viewport_drag_pan_session_rejected(
230        context: ViewportGestureContext,
231        input: ViewportDragPanInput,
232        rejection: ViewportGestureRejection,
233    ) -> Self {
234        Self::ApplyViewportDragPanSession {
235            context,
236            input,
237            expect_rejection: Some(rejection),
238        }
239    }
240}