Skip to main content

jellyflow_runtime/io/config/state/views/
viewport.rs

1use jellyflow_core::core::CanvasRect;
2use jellyflow_core::interaction::NodeGraphModifierKey;
3
4use crate::io::config::keys::NodeGraphKeyCode;
5use crate::io::config::types::{
6    NodeGraphPanOnDragButtons, NodeGraphPanOnScrollMode, NodeGraphViewportEase,
7};
8use crate::io::tuning::NodeGraphPanInertiaTuning;
9
10use super::super::NodeGraphInteractionState;
11
12/// Canvas pan behaviour resolved for runtime use.
13#[derive(Debug, Clone, Copy, PartialEq)]
14pub struct NodeGraphPanInteraction<'a> {
15    pub pan_on_scroll: bool,
16    pub pan_on_drag: NodeGraphPanOnDragButtons,
17    pub pane_click_distance: f32,
18    pub pan_activation_key_code: Option<NodeGraphKeyCode>,
19    pub space_to_pan: bool,
20    pub pan_on_scroll_speed: f32,
21    pub pan_on_scroll_mode: NodeGraphPanOnScrollMode,
22    pub pan_inertia: &'a NodeGraphPanInertiaTuning,
23    pub translate_extent: Option<CanvasRect>,
24}
25
26/// Viewport zoom behaviour resolved for runtime use.
27#[derive(Debug, Clone, Copy, PartialEq)]
28pub struct NodeGraphZoomInteraction {
29    pub zoom_on_scroll: bool,
30    pub zoom_on_scroll_speed: f32,
31    pub zoom_on_pinch: bool,
32    pub zoom_on_pinch_speed: f32,
33    pub zoom_on_double_click: bool,
34    pub zoom_activation_key: NodeGraphModifierKey,
35}
36
37/// Programmatic viewport framing behaviour resolved for runtime use.
38#[derive(Debug, Clone, Copy, PartialEq)]
39pub struct NodeGraphFrameViewInteraction {
40    pub duration_ms: u32,
41    pub ease: NodeGraphViewportEase,
42    pub padding: f32,
43}
44
45impl NodeGraphInteractionState {
46    pub fn pan_interaction(&self) -> NodeGraphPanInteraction<'_> {
47        NodeGraphPanInteraction {
48            pan_on_scroll: self.pan_on_scroll,
49            pan_on_drag: self.pan_on_drag,
50            pane_click_distance: self.pane_click_distance,
51            pan_activation_key_code: self.pan_activation_key_code,
52            space_to_pan: self.space_to_pan,
53            pan_on_scroll_speed: self.pan_on_scroll_speed,
54            pan_on_scroll_mode: self.pan_on_scroll_mode,
55            pan_inertia: &self.pan_inertia,
56            translate_extent: self.translate_extent,
57        }
58    }
59
60    pub fn zoom_interaction(&self) -> NodeGraphZoomInteraction {
61        NodeGraphZoomInteraction {
62            zoom_on_scroll: self.zoom_on_scroll,
63            zoom_on_scroll_speed: self.zoom_on_scroll_speed,
64            zoom_on_pinch: self.zoom_on_pinch,
65            zoom_on_pinch_speed: self.zoom_on_pinch_speed,
66            zoom_on_double_click: self.zoom_on_double_click,
67            zoom_activation_key: self.zoom_activation_key,
68        }
69    }
70
71    pub fn frame_view_interaction(&self) -> NodeGraphFrameViewInteraction {
72        NodeGraphFrameViewInteraction {
73            duration_ms: self.frame_view_duration_ms,
74            ease: self.frame_view_ease,
75            padding: self.frame_view_padding,
76        }
77    }
78}