Skip to main content

jellyflow_runtime/runtime/selection/
activation.rs

1use jellyflow_core::core::CanvasPoint;
2
3/// Screen-space input for deciding whether a marquee selection drag should activate.
4///
5/// XyFlow evaluates the pane drag threshold in client/screen coordinates so zoom does not change
6/// when selection starts. When the selection key is held, `paneClickDistance` is bypassed and any
7/// positive movement can start the marquee gesture.
8#[derive(Debug, Clone, Copy, PartialEq)]
9pub struct SelectionDragActivationInput {
10    pub screen_delta: CanvasPoint,
11    pub pane_click_distance: f32,
12    pub selection_key_pressed: bool,
13}
14
15impl SelectionDragActivationInput {
16    pub fn new(
17        screen_delta: CanvasPoint,
18        pane_click_distance: f32,
19        selection_key_pressed: bool,
20    ) -> Self {
21        Self {
22            screen_delta,
23            pane_click_distance,
24            selection_key_pressed,
25        }
26    }
27}
28
29/// Returns whether pointer movement should start a marquee selection drag.
30///
31/// This mirrors XyFlow's threshold shape: the Euclidean screen-space distance must be strictly
32/// greater than the required distance. Holding the selection key makes the required distance zero.
33pub fn selection_drag_threshold_met(input: SelectionDragActivationInput) -> bool {
34    if !input.screen_delta.is_finite() {
35        return false;
36    }
37
38    let required_distance = if input.selection_key_pressed {
39        0.0
40    } else if input.pane_click_distance.is_finite() {
41        input.pane_click_distance.max(0.0)
42    } else {
43        return false;
44    };
45
46    input.screen_delta.x.hypot(input.screen_delta.y) > required_distance
47}