Skip to main content

jellyflow_runtime/io/config/state/
mod.rs

1use serde::{Deserialize, Serialize};
2
3use jellyflow_core::core::{CanvasRect, CanvasSize};
4use jellyflow_core::interaction::{
5    NodeGraphConnectionMode, NodeGraphDragHandleMode, NodeGraphModifierKey,
6};
7
8use crate::io::tuning::{
9    NodeGraphAutoPanTuning, NodeGraphPaintCachePruneTuning, NodeGraphPanInertiaTuning,
10    NodeGraphSpatialIndexTuning,
11};
12use crate::runtime::geometry::EdgeHitTestOptions;
13
14use super::keys::{NodeGraphDeleteKey, NodeGraphKeyCode};
15use super::types::{
16    NodeGraphBoxSelectEdges, NodeGraphNodeOrigin, NodeGraphNudgeStepMode,
17    NodeGraphPanOnDragButtons, NodeGraphPanOnScrollMode, NodeGraphSelectionMode,
18    NodeGraphViewportEase,
19};
20
21mod default_impl;
22mod split;
23mod views;
24
25pub use views::{
26    NodeGraphConnectionInteraction, NodeGraphDeleteInteraction, NodeGraphFrameViewInteraction,
27    NodeGraphKeyboardInteraction, NodeGraphNodeDragInteraction, NodeGraphPanInteraction,
28    NodeGraphRenderingInteraction, NodeGraphSelectionInteraction, NodeGraphZoomInteraction,
29};
30
31/// Resolved runtime interaction state assembled from persisted config and runtime tuning.
32#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
33pub struct NodeGraphInteractionState {
34    pub elements_selectable: bool,
35    pub nodes_draggable: bool,
36    pub nodes_connectable: bool,
37    pub nodes_deletable: bool,
38    pub nodes_focusable: bool,
39    pub edges_selectable: bool,
40    pub edges_deletable: bool,
41    pub edges_focusable: bool,
42    pub edges_reconnectable: bool,
43    pub connection_mode: NodeGraphConnectionMode,
44    pub connection_radius: f32,
45    pub reconnect_radius: f32,
46    pub reconnect_on_drop_empty: bool,
47    pub edge_interaction_width: f32,
48    pub bezier_hit_test_steps: u8,
49    pub spatial_index: NodeGraphSpatialIndexTuning,
50    pub only_render_visible_elements: bool,
51    pub elevate_nodes_on_select: bool,
52    pub elevate_edges_on_select: bool,
53    pub paint_cache_prune: NodeGraphPaintCachePruneTuning,
54    pub snap_to_grid: bool,
55    pub snap_grid: CanvasSize,
56    pub snaplines: bool,
57    pub snaplines_threshold: f32,
58    pub pan_on_scroll: bool,
59    pub pan_on_drag: NodeGraphPanOnDragButtons,
60    pub selection_on_drag: bool,
61    pub select_nodes_on_drag: bool,
62    pub selection_mode: NodeGraphSelectionMode,
63    pub box_select_edges: NodeGraphBoxSelectEdges,
64    pub selection_key: NodeGraphModifierKey,
65    pub multi_selection_key: NodeGraphModifierKey,
66    pub delete_key: NodeGraphDeleteKey,
67    pub nudge_step_mode: NodeGraphNudgeStepMode,
68    pub nudge_step_px: f32,
69    pub nudge_fast_step_px: f32,
70    pub disable_keyboard_a11y: bool,
71    pub pane_click_distance: f32,
72    pub pan_activation_key_code: Option<NodeGraphKeyCode>,
73    pub space_to_pan: bool,
74    pub pan_on_scroll_speed: f32,
75    pub pan_on_scroll_mode: NodeGraphPanOnScrollMode,
76    pub pan_inertia: NodeGraphPanInertiaTuning,
77    pub zoom_on_scroll: bool,
78    pub zoom_on_scroll_speed: f32,
79    pub zoom_on_pinch: bool,
80    pub zoom_on_pinch_speed: f32,
81    pub zoom_on_double_click: bool,
82    pub frame_view_duration_ms: u32,
83    pub frame_view_ease: NodeGraphViewportEase,
84    pub frame_view_padding: f32,
85    pub reroute_on_edge_double_click: bool,
86    pub edge_insert_on_alt_drag: bool,
87    pub zoom_activation_key: NodeGraphModifierKey,
88    pub node_drag_threshold: f32,
89    pub node_drag_handle_mode: NodeGraphDragHandleMode,
90    pub node_click_distance: f32,
91    pub connection_drag_threshold: f32,
92    pub connect_on_click: bool,
93    pub auto_pan: NodeGraphAutoPanTuning,
94    pub translate_extent: Option<CanvasRect>,
95    pub node_extent: Option<CanvasRect>,
96    pub node_origin: NodeGraphNodeOrigin,
97}
98
99impl NodeGraphInteractionState {
100    pub fn edge_hit_test_options(&self) -> EdgeHitTestOptions {
101        EdgeHitTestOptions::new(
102            self.edge_interaction_width,
103            usize::from(self.bezier_hit_test_steps),
104        )
105    }
106}