Table of Contents

Interface IBehavior

Namespace
FlowGraph.Core.Input
Assembly
FlowGraph.Core.dll

A behavior that can observe and optionally intercept graph input events.

public interface IBehavior

Remarks

Behaviors provide an extensibility mechanism for customizing graph interactions without modifying the core input handling logic. They are inspired by the Behavior pattern from Blazor.Diagrams.

Lifecycle:

  1. Before core processing: OnBeforePointerPressed(IGraphInputEvent) etc.
  2. Core processing (InputProcessor) runs if not suppressed
  3. After core processing: OnAfterPointerPressed(IGraphInputEvent) etc.

Performance (Gemini Optimization): Behaviors can specify which states they're active in via ActiveInStates. The dispatcher skips behaviors that aren't relevant to the current state, avoiding iteration overhead on high-frequency events like PointerMoved.

Use Cases:

  • Custom selection modes (marquee, lasso)
  • Snap-to-grid visualization
  • Connection validation feedback
  • Accessibility enhancements
  • Analytics/logging

Properties

ActiveInStates

The input state names this behavior is active in. If null or empty, the behavior is active in all states.

IReadOnlySet<string>? ActiveInStates { get; }

Property Value

IReadOnlySet<string>

Remarks

Gemini Optimization: Behaviors that are only relevant in specific states (e.g., a selection box behavior only during Idle or BoxSelecting) should specify those states here. The dispatcher will skip the behavior entirely in other states, avoiding unnecessary method calls on high-frequency events.

State names match IInputState.Name (e.g., "Idle", "Dragging", "Panning").

IsEnabled

Whether this behavior is currently active. Disabled behaviors receive no events.

bool IsEnabled { get; set; }

Property Value

bool

Name

Display name for debugging and UI purposes.

string Name { get; }

Property Value

string

Priority

Priority relative to other behaviors. Higher = called first. Default behaviors use 0. Use negative for "always last" behaviors.

int Priority { get; }

Property Value

int

Methods

IsActiveInState(string)

Checks if this behavior should be invoked for the given state. Default: active in all states if ActiveInStates is null/empty.

bool IsActiveInState(string stateName)

Parameters

stateName string

Returns

bool

OnAfterKeyDown(IGraphInputEvent)

Called after key down has been processed.

void OnAfterKeyDown(IGraphInputEvent e)

Parameters

e IGraphInputEvent

OnAfterPointerMoved(IGraphInputEvent)

Called after pointer moved has been processed.

void OnAfterPointerMoved(IGraphInputEvent e)

Parameters

e IGraphInputEvent

OnAfterPointerPressed(IGraphInputEvent)

Called after pointer pressed has been processed.

void OnAfterPointerPressed(IGraphInputEvent e)

Parameters

e IGraphInputEvent

OnAfterPointerReleased(IGraphInputEvent)

Called after pointer released has been processed.

void OnAfterPointerReleased(IGraphInputEvent e)

Parameters

e IGraphInputEvent

OnAfterPointerWheel(IGraphInputEvent)

Called after wheel/scroll has been processed.

void OnAfterPointerWheel(IGraphInputEvent e)

Parameters

e IGraphInputEvent

OnAttached(Graph)

Called when the behavior is attached to a graph canvas.

void OnAttached(Graph graph)

Parameters

graph Graph

OnBeforeKeyDown(IGraphInputEvent)

Called before key down is processed.

BehaviorResult OnBeforeKeyDown(IGraphInputEvent e)

Parameters

e IGraphInputEvent

Returns

BehaviorResult

OnBeforePointerMoved(IGraphInputEvent)

Called before pointer moved is processed.

BehaviorResult OnBeforePointerMoved(IGraphInputEvent e)

Parameters

e IGraphInputEvent

Returns

BehaviorResult

OnBeforePointerPressed(IGraphInputEvent)

Called before pointer pressed is processed. Return HandledSuppress to prevent default handling.

BehaviorResult OnBeforePointerPressed(IGraphInputEvent e)

Parameters

e IGraphInputEvent

Returns

BehaviorResult

OnBeforePointerReleased(IGraphInputEvent)

Called before pointer released is processed.

BehaviorResult OnBeforePointerReleased(IGraphInputEvent e)

Parameters

e IGraphInputEvent

Returns

BehaviorResult

OnBeforePointerWheel(IGraphInputEvent)

Called before wheel/scroll is processed.

BehaviorResult OnBeforePointerWheel(IGraphInputEvent e)

Parameters

e IGraphInputEvent

Returns

BehaviorResult

OnDetached()

Called when the behavior is detached from a graph canvas.

void OnDetached()