jellyflow_runtime/runtime/policy/
node.rs1use crate::io::NodeGraphInteractionState;
2use jellyflow_core::core::{Node, NodeExtent};
3
4#[derive(Debug, Clone, Copy, PartialEq)]
5pub struct NodeGraphNodeInteractionPolicy {
6 pub selectable: bool,
7 pub focusable: bool,
8 pub draggable: bool,
9 pub connectable: bool,
10 pub deletable: bool,
11 pub extent: Option<NodeExtent>,
12 pub expand_parent: bool,
13}
14
15impl NodeGraphNodeInteractionPolicy {
16 pub fn can_delete(self) -> bool {
17 self.deletable
18 }
19}
20
21pub fn resolve_node_interaction_policy(
22 node: &Node,
23 state: &NodeGraphInteractionState,
24) -> NodeGraphNodeInteractionPolicy {
25 let selection = state.selection_interaction();
26 let keyboard = state.keyboard_interaction();
27 let node_drag = state.node_drag_interaction();
28 let connection = state.connection_interaction();
29 let delete = state.delete_interaction();
30
31 NodeGraphNodeInteractionPolicy {
32 selectable: node.selectable.unwrap_or(selection.elements_selectable),
33 focusable: node.focusable.unwrap_or(keyboard.nodes_focusable),
34 draggable: node.draggable.unwrap_or(node_drag.nodes_draggable),
35 connectable: node.connectable.unwrap_or(connection.nodes_connectable),
36 deletable: node.deletable.unwrap_or(delete.nodes_deletable),
37 extent: node
38 .extent
39 .or_else(|| node_drag.node_extent.map(|rect| NodeExtent::Rect { rect })),
40 expand_parent: node.expand_parent.unwrap_or(false),
41 }
42}