Delegate interface for snap-to behavior during node drag operations.
Implement this interface to provide custom snapping logic, such as alignment guides, grid snapping, or magnetic snapping to other nodes.
Position Model
The snapping system uses two positions:
- position: The user's intended position (freeform, raw movement)
- visualPosition: The displayed position (snapped)
Snap delegates transform position → visualPosition. The delegate
receives the intended position and returns the snapped visual position.
Usage
class MySnapDelegate implements SnapDelegate {
@override
SnapResult snapPosition({
required Set<String> draggedNodeIds,
required Offset intendedPosition,
required Rect visibleBounds,
}) {
// Calculate snapped position
final snapped = calculateSnap(intendedPosition);
return SnapResult(
position: snapped,
snappingX: snapped.dx != intendedPosition.dx,
snappingY: snapped.dy != intendedPosition.dy,
);
}
@override
void onDragStart(Set<String> nodeIds) {
// Prepare for snapping
}
@override
void onDragEnd() {
// Clean up snap state
}
}
- Implementers
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
onDragEnd(
) → void - Called when the drag operation ends.
-
onDragStart(
Set< String> nodeIds) → void - Called when a node drag operation starts.
-
snapPosition(
{required Set< String> draggedNodeIds, required Offset intendedPosition, required Rect visibleBounds}) → SnapResult - Calculate the snapped visual position from the intended position.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited