Skip to main content

jellyflow_runtime/runtime/viewport/gesture/
click_distance.rs

1/// Input for resolving the effective pane click distance used by viewport adapters.
2#[derive(Debug, Clone, Copy, PartialEq)]
3pub struct PaneClickDistanceInput {
4    pub pane_click_distance: f32,
5    pub selection_on_drag: bool,
6}
7
8impl PaneClickDistanceInput {
9    pub fn new(pane_click_distance: f32, selection_on_drag: bool) -> Self {
10        Self {
11            pane_click_distance,
12            selection_on_drag,
13        }
14    }
15}
16
17/// Resolves XyFlow-compatible pane click-distance suppression.
18///
19/// When selection-on-drag is active, XyFlow sets the pane click distance to infinity so selection
20/// gestures do not also produce pane clicks. Otherwise non-numeric or negative distances become
21/// zero before reaching the viewport adapter.
22pub fn resolve_pane_click_distance(input: PaneClickDistanceInput) -> f32 {
23    if input.selection_on_drag {
24        return f32::INFINITY;
25    }
26    if !input.pane_click_distance.is_finite() || input.pane_click_distance < 0.0 {
27        return 0.0;
28    }
29
30    input.pane_click_distance
31}